@seafile/sea-email-editor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/assets/icons/align-center.svg +1 -0
- package/dist/assets/icons/align-left.svg +1 -0
- package/dist/assets/icons/align-right.svg +1 -0
- package/dist/assets/icons/arrow-down.svg +1 -0
- package/dist/assets/icons/arrow-right.svg +1 -0
- package/dist/assets/icons/arrow-up.svg +1 -0
- package/dist/assets/icons/bold.svg +1 -0
- package/dist/assets/icons/callout-color.svg +1 -0
- package/dist/assets/icons/check-mark-option.svg +3 -0
- package/dist/assets/icons/check-square.svg +1 -0
- package/dist/assets/icons/clear-format.svg +1 -0
- package/dist/assets/icons/close.svg +3 -0
- package/dist/assets/icons/code-block.svg +1 -0
- package/dist/assets/icons/image.svg +1 -0
- package/dist/assets/icons/inline-code.svg +1 -0
- package/dist/assets/icons/insert.svg +1 -0
- package/dist/assets/icons/italic.svg +1 -0
- package/dist/assets/icons/link.svg +1 -0
- package/dist/assets/icons/more.svg +1 -0
- package/dist/assets/icons/ol.svg +1 -0
- package/dist/assets/icons/quote.svg +1 -0
- package/dist/assets/icons/rename.svg +4 -0
- package/dist/assets/icons/strikethrough.svg +1 -0
- package/dist/assets/icons/table.svg +1 -0
- package/dist/assets/icons/ul.svg +1 -0
- package/dist/assets/icons/underline.svg +1 -0
- package/dist/assets/icons/unlink.svg +1 -0
- package/dist/components/browser-tip/index.css +18 -0
- package/dist/components/browser-tip/index.js +28 -0
- package/dist/components/centered-loading.js +23 -0
- package/dist/components/icon/index.css +7 -0
- package/dist/components/icon/index.js +30 -0
- package/dist/components/icon-button/index.css +33 -0
- package/dist/components/icon-button/index.js +71 -0
- package/dist/components/index.js +92 -0
- package/dist/components/loading/index.css +54 -0
- package/dist/components/loading/index.js +15 -0
- package/dist/components/modal/index.css +0 -0
- package/dist/components/modal/index.js +27 -0
- package/dist/components/modal-header/index.css +22 -0
- package/dist/components/modal-header/index.js +36 -0
- package/dist/components/option/index.css +20 -0
- package/dist/components/option/index.js +39 -0
- package/dist/components/options-editor/container/index.css +49 -0
- package/dist/components/options-editor/container/index.js +122 -0
- package/dist/components/options-editor/index.css +26 -0
- package/dist/components/options-editor/index.js +70 -0
- package/dist/components/options-editor/options/index.css +5 -0
- package/dist/components/options-editor/options/index.js +138 -0
- package/dist/components/options-editor/options/option/index.css +54 -0
- package/dist/components/options-editor/options/option/index.js +138 -0
- package/dist/components/popover/index.js +85 -0
- package/dist/components/popover/utils.js +76 -0
- package/dist/components/search-input/index.css +52 -0
- package/dist/components/search-input/index.js +148 -0
- package/dist/components/selector-display/index.css +86 -0
- package/dist/components/selector-display/index.js +66 -0
- package/dist/components/toolbar/index.js +20 -0
- package/dist/components/toolbar/toolbar-group/index.css +13 -0
- package/dist/components/toolbar/toolbar-group/index.js +22 -0
- package/dist/components/toolbar/toolbar-item/index.css +3 -0
- package/dist/components/toolbar/toolbar-item/index.js +53 -0
- package/dist/components/tooltip/index.css +68 -0
- package/dist/components/tooltip/index.js +46 -0
- package/dist/components/tooltip/shortcut-key/index.css +7 -0
- package/dist/components/tooltip/shortcut-key/index.js +20 -0
- package/dist/constants/event-types.js +25 -0
- package/dist/constants/index.js +40 -0
- package/dist/constants/key-codes.js +104 -0
- package/dist/editor/index.css +44 -0
- package/dist/editor/index.js +50 -0
- package/dist/editor/main/index.css +19 -0
- package/dist/editor/main/index.js +166 -0
- package/dist/editor/with-props-editor.js +20 -0
- package/dist/extension/commons/dropdown-menu-item/index.css +52 -0
- package/dist/extension/commons/dropdown-menu-item/index.js +62 -0
- package/dist/extension/commons/index.js +5 -0
- package/dist/extension/commons/insert-element-dialog/index.js +91 -0
- package/dist/extension/commons/menu/index.js +3 -0
- package/dist/extension/commons/menu/menu-drop-down.js +98 -0
- package/dist/extension/commons/menu-shortcut-indicator/index.js +24 -0
- package/dist/extension/commons/menu-shortcut-indicator/style.css +18 -0
- package/dist/extension/constants/element-default-style.js +78 -0
- package/dist/extension/constants/element-types.js +33 -0
- package/dist/extension/constants/index.js +63 -0
- package/dist/extension/constants/keyboard.js +33 -0
- package/dist/extension/constants/menus-config.js +142 -0
- package/dist/extension/core/index.js +38 -0
- package/dist/extension/core/queries/index.js +507 -0
- package/dist/extension/core/transforms/focus-editor.js +18 -0
- package/dist/extension/core/transforms/index.js +49 -0
- package/dist/extension/core/transforms/move-children.js +35 -0
- package/dist/extension/core/transforms/remove-node-children.js +19 -0
- package/dist/extension/core/transforms/replace-node-children.js +24 -0
- package/dist/extension/core/utils/index.js +120 -0
- package/dist/extension/event-transfer/get-event-transfer.js +38 -0
- package/dist/extension/event-transfer/set-event-transfer.js +36 -0
- package/dist/extension/highlight/index.js +20 -0
- package/dist/extension/highlight/normalize-tokens.js +94 -0
- package/dist/extension/highlight/prismjs.js +27 -0
- package/dist/extension/highlight/set-node-decorations.js +81 -0
- package/dist/extension/highlight/use-highlight.js +20 -0
- package/dist/extension/index.js +67 -0
- package/dist/extension/plugins/blockquote/helpers.js +68 -0
- package/dist/extension/plugins/blockquote/index.js +18 -0
- package/dist/extension/plugins/blockquote/menu/index.js +35 -0
- package/dist/extension/plugins/blockquote/plugin.js +154 -0
- package/dist/extension/plugins/blockquote/render-elem.js +29 -0
- package/dist/extension/plugins/check-list/helper.js +34 -0
- package/dist/extension/plugins/check-list/index.js +19 -0
- package/dist/extension/plugins/check-list/menu/index.js +39 -0
- package/dist/extension/plugins/check-list/plugin.js +92 -0
- package/dist/extension/plugins/check-list/render-elem.js +61 -0
- package/dist/extension/plugins/clear-format/helpers.js +51 -0
- package/dist/extension/plugins/clear-format/menu/index.js +35 -0
- package/dist/extension/plugins/code-block/helpers.js +140 -0
- package/dist/extension/plugins/code-block/index.js +20 -0
- package/dist/extension/plugins/code-block/menu/index.js +59 -0
- package/dist/extension/plugins/code-block/plugin.js +288 -0
- package/dist/extension/plugins/code-block/render-elem/constant.js +22 -0
- package/dist/extension/plugins/code-block/render-elem/index.js +89 -0
- package/dist/extension/plugins/code-block/render-elem/language-selector/index.css +18 -0
- package/dist/extension/plugins/code-block/render-elem/language-selector/index.js +38 -0
- package/dist/extension/plugins/formula/formula.css +22 -0
- package/dist/extension/plugins/formula/helper.js +80 -0
- package/dist/extension/plugins/formula/index.js +19 -0
- package/dist/extension/plugins/formula/menu/formula-modal.js +98 -0
- package/dist/extension/plugins/formula/menu/index.js +35 -0
- package/dist/extension/plugins/formula/plugin.js +22 -0
- package/dist/extension/plugins/formula/render-elem.js +64 -0
- package/dist/extension/plugins/header/helper.js +55 -0
- package/dist/extension/plugins/header/index.js +19 -0
- package/dist/extension/plugins/header/menu/index.js +72 -0
- package/dist/extension/plugins/header/plugin.js +155 -0
- package/dist/extension/plugins/header/render-elem.js +39 -0
- package/dist/extension/plugins/html/index.js +13 -0
- package/dist/extension/plugins/html/plugin.js +69 -0
- package/dist/extension/plugins/image/helper.js +131 -0
- package/dist/extension/plugins/image/index.js +19 -0
- package/dist/extension/plugins/image/menu/image-menu-dialog.js +92 -0
- package/dist/extension/plugins/image/menu/index.css +3 -0
- package/dist/extension/plugins/image/menu/index.js +103 -0
- package/dist/extension/plugins/image/plugin.js +56 -0
- package/dist/extension/plugins/image/render-element/image-previewer.js +89 -0
- package/dist/extension/plugins/image/render-element/index.js +141 -0
- package/dist/extension/plugins/image/render-element/style.css +68 -0
- package/dist/extension/plugins/index.js +116 -0
- package/dist/extension/plugins/link/helper.js +258 -0
- package/dist/extension/plugins/link/index.js +19 -0
- package/dist/extension/plugins/link/menu/index.js +92 -0
- package/dist/extension/plugins/link/menu/link-modal.js +169 -0
- package/dist/extension/plugins/link/plugin.js +172 -0
- package/dist/extension/plugins/link/render-elem/index.css +12 -0
- package/dist/extension/plugins/link/render-elem/index.js +103 -0
- package/dist/extension/plugins/link/render-elem/link-op-menu/index.css +33 -0
- package/dist/extension/plugins/link/render-elem/link-op-menu/index.js +89 -0
- package/dist/extension/plugins/list/constant.js +8 -0
- package/dist/extension/plugins/list/helpers.js +102 -0
- package/dist/extension/plugins/list/index.js +19 -0
- package/dist/extension/plugins/list/menu/index.js +41 -0
- package/dist/extension/plugins/list/plugin/index.js +80 -0
- package/dist/extension/plugins/list/plugin/insert-break-list.js +29 -0
- package/dist/extension/plugins/list/plugin/insert-fragment-list.js +179 -0
- package/dist/extension/plugins/list/plugin/normalize-list.js +79 -0
- package/dist/extension/plugins/list/plugin/on-tab-handle.js +63 -0
- package/dist/extension/plugins/list/plugin/shortcut.js +69 -0
- package/dist/extension/plugins/list/queries/index.js +52 -0
- package/dist/extension/plugins/list/render-elem/index.js +68 -0
- package/dist/extension/plugins/list/transforms/index.js +75 -0
- package/dist/extension/plugins/list/transforms/insert-list-item.js +98 -0
- package/dist/extension/plugins/list/transforms/move-list-item-down.js +50 -0
- package/dist/extension/plugins/list/transforms/move-list-item-up.js +124 -0
- package/dist/extension/plugins/list/transforms/move-list-items-to-list.js +63 -0
- package/dist/extension/plugins/list/transforms/move-list-items.js +73 -0
- package/dist/extension/plugins/list/transforms/normalize-list-item.js +110 -0
- package/dist/extension/plugins/list/transforms/normalize-nested-list.js +38 -0
- package/dist/extension/plugins/list/transforms/remove-first-list-item.js +24 -0
- package/dist/extension/plugins/list/transforms/transforms-to-list.js +131 -0
- package/dist/extension/plugins/list/transforms/unwrap-list.js +48 -0
- package/dist/extension/plugins/markdown/index.js +12 -0
- package/dist/extension/plugins/markdown/plugin.js +257 -0
- package/dist/extension/plugins/node-id/constants.js +24 -0
- package/dist/extension/plugins/node-id/helpers.js +78 -0
- package/dist/extension/plugins/node-id/index.js +12 -0
- package/dist/extension/plugins/node-id/with-node-id.js +37 -0
- package/dist/extension/plugins/p/helper.js +17 -0
- package/dist/extension/plugins/p/index.js +17 -0
- package/dist/extension/plugins/p/plugin.js +141 -0
- package/dist/extension/plugins/p/render-elem.js +29 -0
- package/dist/extension/plugins/paragraph/helper.js +17 -0
- package/dist/extension/plugins/paragraph/index.js +17 -0
- package/dist/extension/plugins/paragraph/plugin.js +141 -0
- package/dist/extension/plugins/paragraph/render-elem.js +29 -0
- package/dist/extension/plugins/table/constant.js +24 -0
- package/dist/extension/plugins/table/context-menu/horizontal-align-popover/index.css +3 -0
- package/dist/extension/plugins/table/context-menu/horizontal-align-popover/index.js +64 -0
- package/dist/extension/plugins/table/context-menu/index.css +13 -0
- package/dist/extension/plugins/table/context-menu/index.js +152 -0
- package/dist/extension/plugins/table/context-menu/insert-table-element/index.css +27 -0
- package/dist/extension/plugins/table/context-menu/insert-table-element/index.js +113 -0
- package/dist/extension/plugins/table/helper.js +333 -0
- package/dist/extension/plugins/table/index.js +21 -0
- package/dist/extension/plugins/table/menu/index.js +61 -0
- package/dist/extension/plugins/table/menu/table-operator.js +97 -0
- package/dist/extension/plugins/table/menu/table-size-selector/index.css +27 -0
- package/dist/extension/plugins/table/menu/table-size-selector/index.js +98 -0
- package/dist/extension/plugins/table/model.js +102 -0
- package/dist/extension/plugins/table/plugin.js +351 -0
- package/dist/extension/plugins/table/render-elem/index.css +64 -0
- package/dist/extension/plugins/table/render-elem/index.js +252 -0
- package/dist/extension/plugins/table/table-operations.js +323 -0
- package/dist/extension/plugins/text-style/helpers.js +57 -0
- package/dist/extension/plugins/text-style/index.js +17 -0
- package/dist/extension/plugins/text-style/menu/index.js +37 -0
- package/dist/extension/plugins/text-style/plugin.js +38 -0
- package/dist/extension/plugins/text-style/render-elem.js +63 -0
- package/dist/extension/render/render-element.js +115 -0
- package/dist/extension/render/render-leaf.js +22 -0
- package/dist/extension/toolbar/index.css +16 -0
- package/dist/extension/toolbar/index.js +89 -0
- package/dist/extension/toolbar/insert-toolbar.js +78 -0
- package/dist/hooks/use-attachments.js +38 -0
- package/dist/hooks/use-container-style.js +50 -0
- package/dist/hooks/use-mathjax.js +46 -0
- package/dist/hooks/use-scroll-context.js +20 -0
- package/dist/hooks/use-selection-update.js +20 -0
- package/dist/hooks/user-link-click.js +52 -0
- package/dist/index.js +9 -0
- package/dist/intl/ReactIntlUniversal.js +310 -0
- package/dist/intl/constants.js +21 -0
- package/dist/intl/index.js +33 -0
- package/dist/locale/index.js +11 -0
- package/dist/locale/lang/en.json +83 -0
- package/dist/slate-convert/html-to-slate/constants.js +146 -0
- package/dist/slate-convert/html-to-slate/helper.js +106 -0
- package/dist/slate-convert/html-to-slate/index.js +138 -0
- package/dist/slate-convert/html-to-slate/rules/blockquote.js +26 -0
- package/dist/slate-convert/html-to-slate/rules/br.js +29 -0
- package/dist/slate-convert/html-to-slate/rules/check-list.js +29 -0
- package/dist/slate-convert/html-to-slate/rules/code-block.js +95 -0
- package/dist/slate-convert/html-to-slate/rules/header.js +26 -0
- package/dist/slate-convert/html-to-slate/rules/image.js +31 -0
- package/dist/slate-convert/html-to-slate/rules/index.js +20 -0
- package/dist/slate-convert/html-to-slate/rules/link.js +31 -0
- package/dist/slate-convert/html-to-slate/rules/list.js +74 -0
- package/dist/slate-convert/html-to-slate/rules/p.js +37 -0
- package/dist/slate-convert/html-to-slate/rules/paragraph.js +37 -0
- package/dist/slate-convert/html-to-slate/rules/table.js +64 -0
- package/dist/slate-convert/html-to-slate/rules/text.js +71 -0
- package/dist/slate-convert/index.js +20 -0
- package/dist/slate-convert/slate-to-html/index.js +143 -0
- package/dist/utils/common.js +46 -0
- package/dist/utils/deserialize-html.js +219 -0
- package/dist/utils/dom-utils.js +57 -0
- package/dist/utils/dom.js +133 -0
- package/dist/utils/event-bus.js +40 -0
- package/dist/utils/event-handler.js +44 -0
- package/dist/utils/get-browser-Info.js +35 -0
- package/dist/utils/hotkey.js +45 -0
- package/dist/utils/is-punctuation-mark.js +50 -0
- package/dist/utils/object-utils.js +56 -0
- package/dist/utils/search.js +20 -0
- package/dist/utils/translate.js +18 -0
- package/dist/utils/type-detection.js +42 -0
- package/package.json +177 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeAcrossBlocks = exports.isLastNode = exports.isLastChild = exports.isFirstNode = exports.isFirstChild = exports.isEndPoint = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getSelectedNodeEntryByTypes = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getParentNode = exports.getNodesByType = exports.getNodes = exports.getNodeType = exports.getNodePathById = exports.getNodeEntries = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getInlineNodes = exports.getEditorString = exports.getDeepInlineChildren = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
8
|
+
var _slate = require("slate");
|
|
9
|
+
var _slateReact = require("slate-react");
|
|
10
|
+
var _slugid = _interopRequireDefault(require("slugid"));
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
var _elementTypes = require("../../constants/element-types");
|
|
13
|
+
// options
|
|
14
|
+
const getQueryOptions = (editor, options) => {
|
|
15
|
+
const {
|
|
16
|
+
match: _match,
|
|
17
|
+
block
|
|
18
|
+
} = options;
|
|
19
|
+
let newMatch = undefined;
|
|
20
|
+
if (_match || block) {
|
|
21
|
+
newMatch = (n, path) => (0, _utils.match)(n, path, _match) && (!block || _slate.Editor.isBlock(editor, n));
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
...options,
|
|
25
|
+
match: newMatch
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.getQueryOptions = getQueryOptions;
|
|
29
|
+
const findPath = (editor, node, defaultPath) => {
|
|
30
|
+
try {
|
|
31
|
+
return _slateReact.ReactEditor.findPath(editor, node);
|
|
32
|
+
} catch {
|
|
33
|
+
return defaultPath;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// get node
|
|
38
|
+
exports.findPath = findPath;
|
|
39
|
+
const getNode = (editor, path) => {
|
|
40
|
+
let node = null;
|
|
41
|
+
try {
|
|
42
|
+
node = _slate.Node.get(editor, path);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
node = null;
|
|
45
|
+
}
|
|
46
|
+
return node;
|
|
47
|
+
};
|
|
48
|
+
exports.getNode = getNode;
|
|
49
|
+
const getNodesByType = function () {
|
|
50
|
+
let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
51
|
+
let type = arguments.length > 1 ? arguments[1] : undefined;
|
|
52
|
+
let nodes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
53
|
+
Array.isArray(target) && target.forEach(n => {
|
|
54
|
+
if (n.type === type) {
|
|
55
|
+
nodes.push(n);
|
|
56
|
+
} else {
|
|
57
|
+
if (Array.isArray(n.children) && n.children.length > 0) {
|
|
58
|
+
getNodesByType(n, type, nodes);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return nodes;
|
|
63
|
+
};
|
|
64
|
+
exports.getNodesByType = getNodesByType;
|
|
65
|
+
const getNodeType = node => {
|
|
66
|
+
return _slate.Element.isElement(node) ? node.type : '';
|
|
67
|
+
};
|
|
68
|
+
exports.getNodeType = getNodeType;
|
|
69
|
+
const getParentNode = (nodes, nodeId) => {
|
|
70
|
+
let parentNode;
|
|
71
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
72
|
+
const node = nodes[i];
|
|
73
|
+
const {
|
|
74
|
+
children: childrenNodes
|
|
75
|
+
} = node;
|
|
76
|
+
if (!Array.isArray(childrenNodes)) continue;
|
|
77
|
+
if (childrenNodes.find(node => node.id === nodeId)) {
|
|
78
|
+
parentNode = node;
|
|
79
|
+
} else {
|
|
80
|
+
parentNode = getParentNode(childrenNodes, nodeId);
|
|
81
|
+
}
|
|
82
|
+
if (!parentNode) continue;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
return parentNode;
|
|
86
|
+
};
|
|
87
|
+
exports.getParentNode = getParentNode;
|
|
88
|
+
const getNodes = (node, options) => {
|
|
89
|
+
return _slate.Node.nodes(node, options);
|
|
90
|
+
};
|
|
91
|
+
exports.getNodes = getNodes;
|
|
92
|
+
const getCommonNode = (root, path, ancestor) => {
|
|
93
|
+
return _slate.Node.common(root, path, ancestor);
|
|
94
|
+
};
|
|
95
|
+
exports.getCommonNode = getCommonNode;
|
|
96
|
+
const getSelectedNodeByType = (editor, type) => {
|
|
97
|
+
const match = n => getNodeType(n) === type;
|
|
98
|
+
const [nodeEntry] = _slate.Editor.nodes(editor, {
|
|
99
|
+
match,
|
|
100
|
+
universal: true
|
|
101
|
+
});
|
|
102
|
+
return nodeEntry ? nodeEntry[0] : null;
|
|
103
|
+
};
|
|
104
|
+
exports.getSelectedNodeByType = getSelectedNodeByType;
|
|
105
|
+
const getSelectedNodeByTypes = (editor, types) => {
|
|
106
|
+
const match = n => types.includes(getNodeType(n));
|
|
107
|
+
const [nodeEntry] = _slate.Editor.nodes(editor, {
|
|
108
|
+
match,
|
|
109
|
+
universal: true
|
|
110
|
+
});
|
|
111
|
+
return nodeEntry ? nodeEntry[0] : null;
|
|
112
|
+
};
|
|
113
|
+
exports.getSelectedNodeByTypes = getSelectedNodeByTypes;
|
|
114
|
+
const getSelectedNodeEntryByType = (editor, type) => {
|
|
115
|
+
const match = n => getNodeType(n) === type;
|
|
116
|
+
const [nodeEntry] = _slate.Editor.nodes(editor, {
|
|
117
|
+
match,
|
|
118
|
+
universal: false
|
|
119
|
+
});
|
|
120
|
+
return nodeEntry ? nodeEntry : null;
|
|
121
|
+
};
|
|
122
|
+
exports.getSelectedNodeEntryByType = getSelectedNodeEntryByType;
|
|
123
|
+
const getSelectedNodeEntryByTypes = (editor, types) => {
|
|
124
|
+
const match = n => types.includes(getNodeType(n));
|
|
125
|
+
const [nodeEntry] = _slate.Editor.nodes(editor, {
|
|
126
|
+
match,
|
|
127
|
+
universal: false
|
|
128
|
+
});
|
|
129
|
+
return nodeEntry ? nodeEntry : null;
|
|
130
|
+
};
|
|
131
|
+
exports.getSelectedNodeEntryByTypes = getSelectedNodeEntryByTypes;
|
|
132
|
+
const getNodeEntries = (editor, options) => {
|
|
133
|
+
return _slate.Editor.nodes(editor, getQueryOptions(editor, options));
|
|
134
|
+
};
|
|
135
|
+
exports.getNodeEntries = getNodeEntries;
|
|
136
|
+
const getEditorString = (editor, at, options) => {
|
|
137
|
+
if (!at) return '';
|
|
138
|
+
try {
|
|
139
|
+
return _slate.Editor.string(editor, at, options);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
return '';
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// children & child
|
|
146
|
+
exports.getEditorString = getEditorString;
|
|
147
|
+
const getChildren = nodeEntry => {
|
|
148
|
+
const [node, path] = nodeEntry;
|
|
149
|
+
if (_slate.Element.isAncestor(node)) {
|
|
150
|
+
const {
|
|
151
|
+
children
|
|
152
|
+
} = node;
|
|
153
|
+
return children.map((child, index) => {
|
|
154
|
+
const childPath = path.concat([index]);
|
|
155
|
+
return [child, childPath];
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return [];
|
|
159
|
+
};
|
|
160
|
+
exports.getChildren = getChildren;
|
|
161
|
+
const getLastChild = nodeEntry => {
|
|
162
|
+
const [node, path] = nodeEntry;
|
|
163
|
+
if (_slate.Text.isText(node)) return null;
|
|
164
|
+
if (!node.children.length) return null;
|
|
165
|
+
const children = node.children;
|
|
166
|
+
return [children[children.length - 1], path.concat([children.length - 1])];
|
|
167
|
+
};
|
|
168
|
+
exports.getLastChild = getLastChild;
|
|
169
|
+
const getDeepInlineChildren = (editor, _ref) => {
|
|
170
|
+
let {
|
|
171
|
+
children
|
|
172
|
+
} = _ref;
|
|
173
|
+
const inlineChildren = [];
|
|
174
|
+
for (let child of children) {
|
|
175
|
+
if (_slate.Editor.isBlock(editor, child[0])) {
|
|
176
|
+
inlineChildren.push(...getDeepInlineChildren(editor, {
|
|
177
|
+
children: getChildren(child)
|
|
178
|
+
}));
|
|
179
|
+
} else {
|
|
180
|
+
inlineChildren.push(child);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return inlineChildren;
|
|
184
|
+
};
|
|
185
|
+
exports.getDeepInlineChildren = getDeepInlineChildren;
|
|
186
|
+
const getLastChildPath = nodeEntry => {
|
|
187
|
+
const lastChild = getLastChild(nodeEntry);
|
|
188
|
+
if (!lastChild) return nodeEntry[1].concat([-1]);
|
|
189
|
+
return lastChild[1];
|
|
190
|
+
};
|
|
191
|
+
exports.getLastChildPath = getLastChildPath;
|
|
192
|
+
const getPreviousPath = path => {
|
|
193
|
+
if (path.length === 0) return;
|
|
194
|
+
const last = path[path.length - 1];
|
|
195
|
+
if (last <= 0) return;
|
|
196
|
+
return path.slice(0, -1).concat(last - 1);
|
|
197
|
+
};
|
|
198
|
+
exports.getPreviousPath = getPreviousPath;
|
|
199
|
+
const isFirstChild = (nodeEntry, childPath) => {
|
|
200
|
+
const children = getChildren(nodeEntry);
|
|
201
|
+
const firstChild = children[0] || [];
|
|
202
|
+
const firstChildPath = firstChild[1];
|
|
203
|
+
return _slate.Path.equals(firstChildPath, childPath);
|
|
204
|
+
};
|
|
205
|
+
exports.isFirstChild = isFirstChild;
|
|
206
|
+
const isLastChild = (nodeEntry, childPath) => {
|
|
207
|
+
const lastChildPath = getLastChildPath(nodeEntry);
|
|
208
|
+
return _slate.Path.equals(lastChildPath, childPath);
|
|
209
|
+
};
|
|
210
|
+
exports.isLastChild = isLastChild;
|
|
211
|
+
const getSelectedElems = editor => {
|
|
212
|
+
const elems = [];
|
|
213
|
+
const nodeEntries = _slate.Editor.nodes(editor, {
|
|
214
|
+
universal: true
|
|
215
|
+
});
|
|
216
|
+
for (let nodeEntry of nodeEntries) {
|
|
217
|
+
const [node] = nodeEntry;
|
|
218
|
+
if (_slate.Element.isElement(node)) elems.push(node);
|
|
219
|
+
}
|
|
220
|
+
return elems;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// siblings
|
|
224
|
+
exports.getSelectedElems = getSelectedElems;
|
|
225
|
+
const getNextSiblingNodes = (ancestorEntry, path) => {
|
|
226
|
+
const [ancestor, ancestorPath] = ancestorEntry;
|
|
227
|
+
const leafIndex = path[ancestorPath.length];
|
|
228
|
+
const siblings = [];
|
|
229
|
+
const ancestorChildren = ancestor.children;
|
|
230
|
+
if (leafIndex + 1 < ancestor.children.length) {
|
|
231
|
+
for (let i = leafIndex + 1; i < ancestor.children.length; i++) {
|
|
232
|
+
siblings.push(ancestorChildren[i]);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return siblings;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// parent
|
|
239
|
+
exports.getNextSiblingNodes = getNextSiblingNodes;
|
|
240
|
+
const getAboveNode = (editor, options) => {
|
|
241
|
+
return _slate.Editor.above(editor, getQueryOptions(editor, options));
|
|
242
|
+
};
|
|
243
|
+
exports.getAboveNode = getAboveNode;
|
|
244
|
+
const getAboveBlockNode = (editor, options) => {
|
|
245
|
+
return getAboveNode(editor, {
|
|
246
|
+
...options,
|
|
247
|
+
block: true
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
exports.getAboveBlockNode = getAboveBlockNode;
|
|
251
|
+
const getPrevNode = editor => {
|
|
252
|
+
const [lowerNode, lowerPath] = getAboveNode(editor, {
|
|
253
|
+
mode: 'lowest',
|
|
254
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n)
|
|
255
|
+
});
|
|
256
|
+
const [heightNode, heightPath] = getAboveNode(editor, {
|
|
257
|
+
mode: 'highest',
|
|
258
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n)
|
|
259
|
+
});
|
|
260
|
+
let prevNode = null;
|
|
261
|
+
try {
|
|
262
|
+
prevNode = _slate.Editor.previous(editor, {
|
|
263
|
+
at: lowerPath,
|
|
264
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n)
|
|
265
|
+
});
|
|
266
|
+
} catch (error) {
|
|
267
|
+
prevNode = null;
|
|
268
|
+
}
|
|
269
|
+
if (lowerNode.id !== heightNode.id && !prevNode) {
|
|
270
|
+
try {
|
|
271
|
+
prevNode = _slate.Editor.previous(editor, {
|
|
272
|
+
at: heightPath,
|
|
273
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n)
|
|
274
|
+
});
|
|
275
|
+
} catch (error) {
|
|
276
|
+
prevNode = null;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return prevNode;
|
|
280
|
+
};
|
|
281
|
+
exports.getPrevNode = getPrevNode;
|
|
282
|
+
const getNextNode = editor => {
|
|
283
|
+
const [lowerNode, lowerPath] = getAboveNode(editor, {
|
|
284
|
+
mode: 'lowest',
|
|
285
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n)
|
|
286
|
+
});
|
|
287
|
+
const [heightNode, heightPath] = getAboveNode(editor, {
|
|
288
|
+
mode: 'highest',
|
|
289
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n)
|
|
290
|
+
});
|
|
291
|
+
let nextNode = null;
|
|
292
|
+
try {
|
|
293
|
+
nextNode = _slate.Editor.next(editor, {
|
|
294
|
+
at: lowerPath,
|
|
295
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n)
|
|
296
|
+
});
|
|
297
|
+
} catch (error) {
|
|
298
|
+
nextNode = null;
|
|
299
|
+
}
|
|
300
|
+
if (lowerNode.id !== heightNode.id && !nextNode) {
|
|
301
|
+
try {
|
|
302
|
+
nextNode = _slate.Editor.next(editor, {
|
|
303
|
+
at: heightPath,
|
|
304
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n)
|
|
305
|
+
});
|
|
306
|
+
} catch (error) {
|
|
307
|
+
nextNode = null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return nextNode;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// find node
|
|
314
|
+
exports.getNextNode = getNextNode;
|
|
315
|
+
const findNode = (editor, options) => {
|
|
316
|
+
const nodeEntries = _slate.Editor.nodes(editor, {
|
|
317
|
+
at: editor.selection || [],
|
|
318
|
+
...getQueryOptions(editor, options)
|
|
319
|
+
});
|
|
320
|
+
const _nodeEntries = Array.from(nodeEntries);
|
|
321
|
+
if (_nodeEntries[0]) {
|
|
322
|
+
return _nodeEntries[0];
|
|
323
|
+
}
|
|
324
|
+
return undefined;
|
|
325
|
+
};
|
|
326
|
+
exports.findNode = findNode;
|
|
327
|
+
const findDescendant = (editor, options) => {
|
|
328
|
+
const {
|
|
329
|
+
at = editor.selection,
|
|
330
|
+
reverse = false,
|
|
331
|
+
voids = false,
|
|
332
|
+
match: _match
|
|
333
|
+
} = options;
|
|
334
|
+
if (!at) return;
|
|
335
|
+
let from;
|
|
336
|
+
let to;
|
|
337
|
+
if (_slate.Span.isSpan(at)) {
|
|
338
|
+
[from, to] = at;
|
|
339
|
+
} else if (_slate.Range.isRange(at)) {
|
|
340
|
+
const first = _slate.Editor.first(editor, at);
|
|
341
|
+
const last = _slate.Editor.last(editor, at);
|
|
342
|
+
from = reverse ? last : first;
|
|
343
|
+
to = reverse ? first : last;
|
|
344
|
+
}
|
|
345
|
+
let root = [editor, []];
|
|
346
|
+
if (_slate.Path.isPath(at)) {
|
|
347
|
+
root = _slate.Editor.node(editor, at);
|
|
348
|
+
}
|
|
349
|
+
const nodeEntries = _slate.Node.descendants(root[0], {
|
|
350
|
+
from,
|
|
351
|
+
to,
|
|
352
|
+
reverse,
|
|
353
|
+
pass: _ref2 => {
|
|
354
|
+
let [n] = _ref2;
|
|
355
|
+
return voids ? false : _slate.Editor.isVoid(editor, n);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
for (const [node, path] of nodeEntries) {
|
|
359
|
+
if ((0, _utils.match)(node, path, _match)) {
|
|
360
|
+
return [node, at.concat(path)];
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return undefined;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// is
|
|
367
|
+
exports.findDescendant = findDescendant;
|
|
368
|
+
const isStartPoint = (editor, point, at) => {
|
|
369
|
+
return !!point && _slate.Editor.isStart(editor, point, at);
|
|
370
|
+
};
|
|
371
|
+
exports.isStartPoint = isStartPoint;
|
|
372
|
+
const isEndPoint = (editor, point, at) => {
|
|
373
|
+
return !!point && _slate.Editor.isEnd(editor, point, at);
|
|
374
|
+
};
|
|
375
|
+
exports.isEndPoint = isEndPoint;
|
|
376
|
+
const isBlockTextEmptyAfterSelection = editor => {
|
|
377
|
+
if (!editor.selection) return false;
|
|
378
|
+
const blockAbove = _slate.Editor.above(editor, {
|
|
379
|
+
block: true
|
|
380
|
+
});
|
|
381
|
+
if (!blockAbove) return false;
|
|
382
|
+
const cursor = editor.selection.focus;
|
|
383
|
+
const selectionParentEntry = _slate.Editor.parent(editor, editor.selection);
|
|
384
|
+
if (!selectionParentEntry) return false;
|
|
385
|
+
const [, selectionParentPath] = selectionParentEntry;
|
|
386
|
+
if (!isEndPoint(editor, cursor, selectionParentPath)) return false;
|
|
387
|
+
const siblingNodes = getNextSiblingNodes(blockAbove, cursor.path);
|
|
388
|
+
if (siblingNodes.length) {
|
|
389
|
+
// 子节点包含 文本节点
|
|
390
|
+
for (const siblingNode of siblingNodes) {
|
|
391
|
+
if (_slate.Text.isText(siblingNode) && siblingNode.text) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
} else {
|
|
396
|
+
return isEndPoint(editor, cursor, blockAbove[1]);
|
|
397
|
+
}
|
|
398
|
+
return true;
|
|
399
|
+
};
|
|
400
|
+
exports.isBlockTextEmptyAfterSelection = isBlockTextEmptyAfterSelection;
|
|
401
|
+
const isRangeAcrossBlocks = function (editor) {
|
|
402
|
+
let {
|
|
403
|
+
at,
|
|
404
|
+
...options
|
|
405
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
406
|
+
if (!at) at = editor.selection;
|
|
407
|
+
if (!at) return;
|
|
408
|
+
const [start, end] = _slate.Range.edges(at);
|
|
409
|
+
const startBlock = getAboveBlockNode(editor, {
|
|
410
|
+
at: start,
|
|
411
|
+
...options
|
|
412
|
+
});
|
|
413
|
+
const endBlock = getAboveBlockNode(editor, {
|
|
414
|
+
at: end,
|
|
415
|
+
...options
|
|
416
|
+
});
|
|
417
|
+
if (!startBlock && !endBlock) return;
|
|
418
|
+
if (!startBlock || !endBlock) return true;
|
|
419
|
+
return !_slate.Path.equals(startBlock[1], endBlock[1]);
|
|
420
|
+
};
|
|
421
|
+
exports.isRangeAcrossBlocks = isRangeAcrossBlocks;
|
|
422
|
+
const isAncestorEmpty = (editor, node) => {
|
|
423
|
+
return !_slate.Node.string(node) && !node.children.some(n => _slate.Editor.isInline(editor, n));
|
|
424
|
+
};
|
|
425
|
+
exports.isAncestorEmpty = isAncestorEmpty;
|
|
426
|
+
const isBlockAboveEmpty = editor => {
|
|
427
|
+
var _getAboveBlockNode;
|
|
428
|
+
const block = (_getAboveBlockNode = getAboveBlockNode(editor)) === null || _getAboveBlockNode === void 0 ? void 0 : _getAboveBlockNode[0];
|
|
429
|
+
if (!block) return false;
|
|
430
|
+
return isAncestorEmpty(editor, block);
|
|
431
|
+
};
|
|
432
|
+
exports.isBlockAboveEmpty = isBlockAboveEmpty;
|
|
433
|
+
const isSelectionAtBlockStart = (editor, options) => {
|
|
434
|
+
var _getAboveBlockNode2;
|
|
435
|
+
const {
|
|
436
|
+
selection
|
|
437
|
+
} = editor;
|
|
438
|
+
if (!selection) return false;
|
|
439
|
+
const path = (_getAboveBlockNode2 = getAboveBlockNode(editor, options)) === null || _getAboveBlockNode2 === void 0 ? void 0 : _getAboveBlockNode2[1];
|
|
440
|
+
if (!path) return false;
|
|
441
|
+
return isStartPoint(editor, selection.focus, path) || _slate.Range.isExpanded(editor.selection) && isStartPoint(editor, selection.anchor, path);
|
|
442
|
+
};
|
|
443
|
+
exports.isSelectionAtBlockStart = isSelectionAtBlockStart;
|
|
444
|
+
const isSelectionAtBlockEnd = (editor, options) => {
|
|
445
|
+
var _getAboveBlockNode3, _editor$selection;
|
|
446
|
+
const path = (_getAboveBlockNode3 = getAboveBlockNode(editor, options)) === null || _getAboveBlockNode3 === void 0 ? void 0 : _getAboveBlockNode3[1];
|
|
447
|
+
return !!path && isEndPoint(editor, (_editor$selection = editor.selection) === null || _editor$selection === void 0 ? void 0 : _editor$selection.focus, path);
|
|
448
|
+
};
|
|
449
|
+
exports.isSelectionAtBlockEnd = isSelectionAtBlockEnd;
|
|
450
|
+
const isFirstNode = (editor, node) => {
|
|
451
|
+
const editorChildren = editor.children || [];
|
|
452
|
+
return editorChildren[0] === node;
|
|
453
|
+
};
|
|
454
|
+
exports.isFirstNode = isFirstNode;
|
|
455
|
+
const isLastNode = (editor, node) => {
|
|
456
|
+
const editorChildren = editor.children || [];
|
|
457
|
+
const editorChildrenLength = editorChildren.length;
|
|
458
|
+
return editorChildren[editorChildrenLength - 1] === node;
|
|
459
|
+
};
|
|
460
|
+
exports.isLastNode = isLastNode;
|
|
461
|
+
const isTextNode = node => {
|
|
462
|
+
if (!node) return false;
|
|
463
|
+
if (Reflect.has(node, 'children')) return false;
|
|
464
|
+
};
|
|
465
|
+
exports.isTextNode = isTextNode;
|
|
466
|
+
const getInlineNodes = node => {
|
|
467
|
+
if (!node.type) return [node];
|
|
468
|
+
// image
|
|
469
|
+
if (node.type === _elementTypes.IMAGE) return [node];
|
|
470
|
+
// link
|
|
471
|
+
if (node.type === _elementTypes.LINK) return [node];
|
|
472
|
+
const {
|
|
473
|
+
children
|
|
474
|
+
} = node;
|
|
475
|
+
const defaultNode = {
|
|
476
|
+
id: _slugid.default.nice(),
|
|
477
|
+
text: ''
|
|
478
|
+
};
|
|
479
|
+
if (!children) return [defaultNode];
|
|
480
|
+
const result = children.map(item => {
|
|
481
|
+
// text
|
|
482
|
+
if (!item.type) return item;
|
|
483
|
+
// image
|
|
484
|
+
if (item.type === _elementTypes.IMAGE) return item;
|
|
485
|
+
// link
|
|
486
|
+
if (item.type === _elementTypes.LINK) return item;
|
|
487
|
+
return getInlineNodes(node);
|
|
488
|
+
});
|
|
489
|
+
return result.flat();
|
|
490
|
+
};
|
|
491
|
+
exports.getInlineNodes = getInlineNodes;
|
|
492
|
+
const getNodePathById = function (rootNode, nodeId) {
|
|
493
|
+
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
494
|
+
if (rootNode.id === nodeId) return path;
|
|
495
|
+
const {
|
|
496
|
+
children = []
|
|
497
|
+
} = rootNode;
|
|
498
|
+
for (let i = 0; i < children.length; i++) {
|
|
499
|
+
const child = children[i];
|
|
500
|
+
path.push(i);
|
|
501
|
+
const nodePath = getNodePathById(child, nodeId, path);
|
|
502
|
+
if (nodePath) return nodePath;
|
|
503
|
+
path.pop();
|
|
504
|
+
}
|
|
505
|
+
return null;
|
|
506
|
+
};
|
|
507
|
+
exports.getNodePathById = getNodePathById;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.focusEditor = void 0;
|
|
7
|
+
var _slate = require("slate");
|
|
8
|
+
var _slateReact = require("slate-react");
|
|
9
|
+
const focusEditor = (editor, target) => {
|
|
10
|
+
if (target) {
|
|
11
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
12
|
+
_slate.Transforms.deselect(editor);
|
|
13
|
+
_slate.Transforms.select(editor, target);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_slateReact.ReactEditor.focus(editor);
|
|
17
|
+
};
|
|
18
|
+
exports.focusEditor = focusEditor;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _moveChildren = require("./move-children");
|
|
7
|
+
Object.keys(_moveChildren).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _moveChildren[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _moveChildren[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _removeNodeChildren = require("./remove-node-children");
|
|
18
|
+
Object.keys(_removeNodeChildren).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _removeNodeChildren[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _removeNodeChildren[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _focusEditor = require("./focus-editor");
|
|
29
|
+
Object.keys(_focusEditor).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _focusEditor[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _focusEditor[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _replaceNodeChildren = require("./replace-node-children");
|
|
40
|
+
Object.keys(_replaceNodeChildren).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _replaceNodeChildren[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _replaceNodeChildren[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.moveChildren = void 0;
|
|
7
|
+
var _slate = require("slate");
|
|
8
|
+
var _queries = require("../queries");
|
|
9
|
+
const moveChildren = (editor, _ref) => {
|
|
10
|
+
let {
|
|
11
|
+
at,
|
|
12
|
+
to,
|
|
13
|
+
match,
|
|
14
|
+
fromStartIndex = 0
|
|
15
|
+
} = _ref;
|
|
16
|
+
let moved = 0;
|
|
17
|
+
const parentPath = _slate.Path.isPath(at) ? at : at[1];
|
|
18
|
+
const parentNode = _slate.Path.isPath(at) ? (0, _queries.getNode)(editor, parentPath) : at[0];
|
|
19
|
+
if (!parentNode) return moved;
|
|
20
|
+
// There have none children in a not block element
|
|
21
|
+
if (!_slate.Editor.isBlock(editor, parentNode)) return moved;
|
|
22
|
+
for (let i = parentNode.children.length - 1; i >= fromStartIndex; i--) {
|
|
23
|
+
const childPath = [...parentPath, i];
|
|
24
|
+
const childNode = (0, _queries.getNode)(editor, childPath);
|
|
25
|
+
if (!match || childNode && match([childNode, childPath])) {
|
|
26
|
+
_slate.Transforms.moveNodes(editor, {
|
|
27
|
+
at: childPath,
|
|
28
|
+
to
|
|
29
|
+
});
|
|
30
|
+
moved++;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return moved;
|
|
34
|
+
};
|
|
35
|
+
exports.moveChildren = moveChildren;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeNodeChildren = void 0;
|
|
7
|
+
var _slate = require("slate");
|
|
8
|
+
const removeNodeChildren = (editor, path, options) => {
|
|
9
|
+
const nodeChildren = _slate.Node.children(editor, path, {
|
|
10
|
+
reverse: true
|
|
11
|
+
});
|
|
12
|
+
for (const [, childPath] of nodeChildren) {
|
|
13
|
+
_slate.Transforms.removeNodes(editor, {
|
|
14
|
+
...options,
|
|
15
|
+
at: childPath
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.removeNodeChildren = removeNodeChildren;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.replaceNodeChildren = void 0;
|
|
7
|
+
var _slate = require("slate");
|
|
8
|
+
var _removeNodeChildren = require("./remove-node-children");
|
|
9
|
+
const replaceNodeChildren = (editor, _ref) => {
|
|
10
|
+
let {
|
|
11
|
+
at,
|
|
12
|
+
nodes,
|
|
13
|
+
insertOptions,
|
|
14
|
+
removeOptions
|
|
15
|
+
} = _ref;
|
|
16
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
17
|
+
(0, _removeNodeChildren.removeNodeChildren)(editor, at, removeOptions);
|
|
18
|
+
_slate.Transforms.insertNodes(editor, nodes, {
|
|
19
|
+
...insertOptions,
|
|
20
|
+
at: at.concat([0])
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.replaceNodeChildren = replaceNodeChildren;
|