Socket
Socket
Sign inDemoInstall

@udecode/slate

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@udecode/slate - npm Package Compare versions

Comparing version 24.3.6 to 25.0.0

108

dist/index.d.ts

@@ -880,3 +880,61 @@ import { UnknownObject, Simplify, UnionToIntersection, Modify } from '@udecode/utils';

/**
* Filter nodes.
*/
interface QueryNodeOptions {
/**
* Query the node entry.
*/
filter?: <N extends TNode>(entry: TNodeEntry<N>) => boolean;
/**
* List of types that are valid. If empty or undefined - allow all.
*/
allow?: string[] | string | null;
/**
* List of types that are invalid.
*/
exclude?: string[] | string | null;
/**
* Valid path levels.
*/
level?: number[] | number | null;
/**
* Paths above that value are invalid.
*/
maxLevel?: number | null;
}
/**
* Query the editor state.
*/
interface QueryEditorOptions<V extends Value = Value, E extends TEditor<V> = TEditor<V>> extends Pick<QueryNodeOptions, 'allow' | 'exclude'> {
/**
* Query the editor.
*/
filter?: (editor: E) => boolean;
/**
* Location from where to lookup the node types (bottom-up)
*/
at?: Location;
/**
* When the selection is at the start of the block above.
*/
selectionAtBlockStart?: boolean;
/**
* When the selection is at the end of the block above.
*/
selectionAtBlockEnd?: boolean;
}
type InsertNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.insertNodes>[2]>, NodeMatchOption<V>> & {
/**
* Remove the currect block if empty before inserting. Only applies to
* paragraphs by default, but can be customized by passing a
* QueryNodeOptions object.
*/
removeEmpty?: boolean | QueryNodeOptions;
/**
* Insert the nodes after the currect block. Does not apply if the
* removeEmpty option caused the current block to be removed.
*/
nextBlock?: boolean;

@@ -887,3 +945,3 @@ };

*/
declare const insertNodes: <N extends EElementOrText<V>, V extends Value = Value>(editor: TEditor<V>, nodes: N | N[], options?: InsertNodesOptions<V> | undefined) => void;
declare const insertNodes: <N extends EElementOrText<V>, V extends Value = Value>(editor: TEditor<V>, nodes: N | N[], { nextBlock, removeEmpty, ...options }?: InsertNodesOptions<V>) => void;

@@ -1019,50 +1077,2 @@ /**

/**
* Filter nodes.
*/
interface QueryNodeOptions {
/**
* Query the node entry.
*/
filter?: <N extends TNode>(entry: TNodeEntry<N>) => boolean;
/**
* List of types that are valid. If empty or undefined - allow all.
*/
allow?: string[] | string | null;
/**
* List of types that are invalid.
*/
exclude?: string[] | string | null;
/**
* Valid path levels.
*/
level?: number[] | number | null;
/**
* Paths above that value are invalid.
*/
maxLevel?: number | null;
}
/**
* Query the editor state.
*/
interface QueryEditorOptions<V extends Value = Value, E extends TEditor<V> = TEditor<V>> extends Pick<QueryNodeOptions, 'allow' | 'exclude'> {
/**
* Query the editor.
*/
filter?: (editor: E) => boolean;
/**
* Location from where to lookup the node types (bottom-up)
*/
at?: Location;
/**
* When the selection is at the start of the block above.
*/
selectionAtBlockStart?: boolean;
/**
* When the selection is at the end of the block above.
*/
selectionAtBlockEnd?: boolean;
}
/**
* Query the node entry.

@@ -1069,0 +1079,0 @@ */

@@ -904,18 +904,78 @@ "use strict";

var import_slate94 = require("slate");
var insertNodes = (editor, nodes, options) => {
if (options == null ? void 0 : options.nextBlock) {
const at = (options == null ? void 0 : options.at) || editor.selection;
if (at) {
const endPoint = getEndPoint(editor, at);
const blockEntry = getAboveNode(editor, {
at: endPoint,
block: true
});
// src/utils/queryNode.ts
function castArray2(value) {
return Array.isArray(value) ? value : [value];
}
var queryNode = (entry, { filter, allow, exclude, level, maxLevel } = {}) => {
if (!entry)
return false;
const [node, path] = entry;
if (level) {
const levels = castArray2(level);
if (!levels.includes(path.length)) {
return false;
}
}
if (maxLevel && path.length > maxLevel) {
return false;
}
if (filter && !filter(entry)) {
return false;
}
if (allow) {
const allows = castArray2(allow);
if (allows.length > 0 && !allows.includes(node.type)) {
return false;
}
}
if (exclude) {
const excludes = castArray2(exclude);
if (excludes.length > 0 && excludes.includes(node.type)) {
return false;
}
}
return true;
};
// src/interfaces/transforms/insertNodes.ts
var insertNodes = (editor, nodes, _a = {}) => {
var _b = _a, { nextBlock, removeEmpty } = _b, options = __objRest(_b, ["nextBlock", "removeEmpty"]);
(0, import_slate94.withoutNormalizing)(editor, () => {
if (removeEmpty) {
const blockEntry = getAboveNode(editor, { at: options.at });
if (blockEntry) {
const nextPath = import_slate94.Path.next(blockEntry[1]);
options.at = nextPath;
const queryNodeOptions = removeEmpty === true ? {
allow: ["p"]
} : removeEmpty;
const { filter } = queryNodeOptions;
queryNodeOptions.filter = ([node, path]) => {
if (getNodeString(node))
return false;
const children = node.children;
if (children.some((n) => isInline(editor, n)))
return false;
return !filter || filter([node, path]);
};
if (queryNode(blockEntry, queryNodeOptions)) {
(0, import_slate94.removeNodes)(editor, { at: blockEntry[1] });
nextBlock = false;
}
}
}
}
import_slate94.Transforms.insertNodes(editor, nodes, options);
if (nextBlock) {
const { at = editor.selection } = options;
if (at) {
const endPoint = getEndPoint(editor, at);
const blockEntry = getAboveNode(editor, {
at: endPoint,
block: true
});
if (blockEntry) {
options.at = import_slate94.Path.next(blockEntry[1]);
}
}
}
import_slate94.Transforms.insertNodes(editor, nodes, options);
});
};

@@ -978,37 +1038,2 @@

// src/utils/queryNode.ts
function castArray2(value) {
return Array.isArray(value) ? value : [value];
}
var queryNode = (entry, { filter, allow, exclude, level, maxLevel } = {}) => {
if (!entry)
return false;
const [node, path] = entry;
if (level) {
const levels = castArray2(level);
if (!levels.includes(path.length)) {
return false;
}
}
if (maxLevel && path.length > maxLevel) {
return false;
}
if (filter && !filter(entry)) {
return false;
}
if (allow) {
const allows = castArray2(allow);
if (allows.length > 0 && !allows.includes(node.type)) {
return false;
}
}
if (exclude) {
const excludes = castArray2(exclude);
if (excludes.length > 0 && excludes.includes(node.type)) {
return false;
}
}
return true;
};
// src/queries/findNode.ts

@@ -1015,0 +1040,0 @@ var findNode = (editor, options = {}) => {

{
"name": "@udecode/slate",
"version": "24.3.6",
"version": "25.0.0",
"description": "Slate extension",

@@ -5,0 +5,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc