@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,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformsToList = void 0;
|
|
7
|
+
var _slate = require("slate");
|
|
8
|
+
var _core = require("../../../core");
|
|
9
|
+
var _queries = require("../queries");
|
|
10
|
+
var _constant = require("../constant");
|
|
11
|
+
var _elementTypes = require("../../../constants/element-types");
|
|
12
|
+
var _unwrapList = require("./unwrap-list");
|
|
13
|
+
const wrapLineList = (editor, type) => {
|
|
14
|
+
const emptyList = (0, _core.generateElement)(type, {
|
|
15
|
+
childrenOrText: []
|
|
16
|
+
});
|
|
17
|
+
_slate.Transforms.wrapNodes(editor, emptyList);
|
|
18
|
+
const paragraphEntry = (0, _core.getSelectedNodeEntryByType)(editor, _elementTypes.PARAGRAPH);
|
|
19
|
+
if (!paragraphEntry) return;
|
|
20
|
+
const [, paragraphPath] = paragraphEntry;
|
|
21
|
+
const emptyListItem = (0, _core.generateElement)(_elementTypes.LIST_ITEM, {
|
|
22
|
+
childrenOrText: []
|
|
23
|
+
});
|
|
24
|
+
_slate.Transforms.wrapNodes(editor, emptyListItem, {
|
|
25
|
+
at: paragraphPath
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const wrapRangeList = (editor, type) => {
|
|
29
|
+
const [startPoint, endPoint] = _slate.Range.edges(editor.selection);
|
|
30
|
+
const [commonAncestorNode, commonAncestorPath] = _slate.Node.common(editor, startPoint.path, endPoint.path);
|
|
31
|
+
|
|
32
|
+
// If common anchestor is of list,order list, unordered list, list of items,wrap or un wrap it
|
|
33
|
+
if ([..._constant.LIST_TYPES, _elementTypes.LIST_ITEM].includes(commonAncestorNode.type)) {
|
|
34
|
+
// Change to another list type, if select different depth of list,set the shallowest depth to the given type
|
|
35
|
+
if (commonAncestorNode.type !== type) {
|
|
36
|
+
const options = {
|
|
37
|
+
at: startPoint,
|
|
38
|
+
match: {
|
|
39
|
+
type: _constant.LIST_TYPES
|
|
40
|
+
},
|
|
41
|
+
mode: 'lowest'
|
|
42
|
+
};
|
|
43
|
+
const startListEntry = (0, _core.findNode)(editor, options);
|
|
44
|
+
const endListEntry = (0, _core.findNode)(editor, {
|
|
45
|
+
...options,
|
|
46
|
+
at: endPoint
|
|
47
|
+
});
|
|
48
|
+
const selectDepth = Math.min(startListEntry[1].length, endListEntry[1].length);
|
|
49
|
+
_slate.Transforms.setNodes(editor, {
|
|
50
|
+
type
|
|
51
|
+
}, {
|
|
52
|
+
match: (node, path) => _slate.Element.isElement(node) && _constant.LIST_TYPES.includes(node.type) && path.length >= selectDepth,
|
|
53
|
+
mode: 'all'
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
(0, _unwrapList.unwrapList)(editor);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const commonAncestorDepth = commonAncestorPath.length;
|
|
61
|
+
const selectedNodeEntries = _slate.Editor.nodes(editor, {
|
|
62
|
+
mode: 'all'
|
|
63
|
+
});
|
|
64
|
+
// Filter out all the child node of selected node.
|
|
65
|
+
const nodeEntryList = Array.from(selectedNodeEntries).filter(_ref => {
|
|
66
|
+
let [node, path] = _ref;
|
|
67
|
+
return path.length === commonAncestorDepth + 1;
|
|
68
|
+
});
|
|
69
|
+
nodeEntryList.forEach(_ref2 => {
|
|
70
|
+
let [node, path] = _ref2;
|
|
71
|
+
if (_constant.LIST_TYPES.includes(node.type)) {
|
|
72
|
+
_slate.Transforms.setNodes(editor, {
|
|
73
|
+
type
|
|
74
|
+
}, {
|
|
75
|
+
at: path,
|
|
76
|
+
match: n => _slate.Element.isElement(n) && _elementTypes.LIST_ITEM.includes(n.type),
|
|
77
|
+
mode: 'all'
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
const emptyListItem = (0, _core.generateElement)(_elementTypes.LIST_ITEM, {
|
|
81
|
+
childrenOrText: []
|
|
82
|
+
});
|
|
83
|
+
_slate.Transforms.wrapNodes(editor, emptyListItem, {
|
|
84
|
+
at: path
|
|
85
|
+
});
|
|
86
|
+
const emptyList = (0, _core.generateElement)(type, {
|
|
87
|
+
childrenOrText: []
|
|
88
|
+
});
|
|
89
|
+
_slate.Transforms.wrapNodes(editor, emptyList, {
|
|
90
|
+
at: path
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {object} editor
|
|
98
|
+
* @param {keyof LIST_TYPES} type
|
|
99
|
+
*/
|
|
100
|
+
const transformsToList = (editor, type) => {
|
|
101
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
102
|
+
const {
|
|
103
|
+
selection
|
|
104
|
+
} = editor;
|
|
105
|
+
if (!selection) return false;
|
|
106
|
+
if (_slate.Range.isCollapsed(selection) || !(0, _core.isRangeAcrossBlocks)(editor)) {
|
|
107
|
+
const res = (0, _queries.getListItemEntry)(editor);
|
|
108
|
+
// Unwrap list if `res` exist which means selected in list,or wrap it
|
|
109
|
+
if (res) {
|
|
110
|
+
const {
|
|
111
|
+
list
|
|
112
|
+
} = res;
|
|
113
|
+
const setListType = (editor, type) => _slate.Transforms.setNodes(editor, {
|
|
114
|
+
type
|
|
115
|
+
}, {
|
|
116
|
+
match: node => _constant.LIST_TYPES.includes((0, _core.getNodeType)(node)),
|
|
117
|
+
mode: 'lowest',
|
|
118
|
+
at: editor.selection
|
|
119
|
+
});
|
|
120
|
+
// Change list type to another, if list type is different from the given type
|
|
121
|
+
list[0].type !== type ? setListType(editor, type) : (0, _unwrapList.unwrapList)(editor);
|
|
122
|
+
} else {
|
|
123
|
+
wrapLineList(editor, type);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// Selection is a range
|
|
128
|
+
wrapRangeList(editor, type);
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
exports.transformsToList = transformsToList;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unwrapList = void 0;
|
|
7
|
+
var _slate = require("slate");
|
|
8
|
+
var _core = require("../../../core");
|
|
9
|
+
var _constant = require("../constant");
|
|
10
|
+
var _elementTypes = require("../../../constants/element-types");
|
|
11
|
+
const unwrapList = function (editor) {
|
|
12
|
+
let {
|
|
13
|
+
at
|
|
14
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
|
+
const ancestorListTypeCheck = () => {
|
|
16
|
+
if ((0, _core.getAboveNode)(editor, {
|
|
17
|
+
match: {
|
|
18
|
+
type: _constant.LIST_TYPES
|
|
19
|
+
}
|
|
20
|
+
})) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// The selection's common node might be a list type
|
|
25
|
+
if (!at && editor.selection) {
|
|
26
|
+
const commonNode = _slate.Node.common(editor, editor.selection.anchor.path, editor.selection.focus.path);
|
|
27
|
+
if (_slate.Element.isElement(commonNode[0]) && _constant.LIST_TYPES.includes(commonNode[0].type)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
};
|
|
33
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
34
|
+
do {
|
|
35
|
+
_slate.Transforms.unwrapNodes(editor, {
|
|
36
|
+
at,
|
|
37
|
+
match: n => (0, _core.getNodeType)(n) === _elementTypes.LIST_ITEM,
|
|
38
|
+
split: true
|
|
39
|
+
});
|
|
40
|
+
_slate.Transforms.unwrapNodes(editor, {
|
|
41
|
+
at,
|
|
42
|
+
match: n => _constant.LIST_TYPES.includes((0, _core.getNodeType)(n)),
|
|
43
|
+
split: true
|
|
44
|
+
});
|
|
45
|
+
} while (ancestorListTypeCheck());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
exports.unwrapList = unwrapList;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
9
|
+
const MarkDownPlugin = {
|
|
10
|
+
editorPlugin: _plugin.default
|
|
11
|
+
};
|
|
12
|
+
var _default = exports.default = MarkDownPlugin;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _slate = require("slate");
|
|
8
|
+
var _transforms = require("../list/transforms");
|
|
9
|
+
var _core = require("../../core");
|
|
10
|
+
var _constants = require("../../constants");
|
|
11
|
+
var _elementTypes = require("../../constants/element-types");
|
|
12
|
+
var _helpers = require("../blockquote/helpers");
|
|
13
|
+
var _helpers2 = require("../code-block/helpers");
|
|
14
|
+
const KEY_TO_TYPE_FOR_SPACE = {
|
|
15
|
+
// Title shortcut
|
|
16
|
+
'#': _elementTypes.HEADER1,
|
|
17
|
+
'##': _elementTypes.HEADER2,
|
|
18
|
+
'###': _elementTypes.HEADER3,
|
|
19
|
+
'####': _elementTypes.HEADER4,
|
|
20
|
+
'#####': _elementTypes.HEADER5,
|
|
21
|
+
'######': _elementTypes.HEADER6,
|
|
22
|
+
// List shortcut
|
|
23
|
+
'*': _elementTypes.UNORDERED_LIST,
|
|
24
|
+
'-': _elementTypes.UNORDERED_LIST,
|
|
25
|
+
// Reference shortcut key
|
|
26
|
+
'>': _elementTypes.BLOCKQUOTE,
|
|
27
|
+
'```': _elementTypes.CODE_BLOCK
|
|
28
|
+
};
|
|
29
|
+
const KEY_TO_INLINE_TYPE_FOR_SPACE = {
|
|
30
|
+
// Inline shortcut keys
|
|
31
|
+
'**': _constants.TEXT_STYLE_MAP.BOLD,
|
|
32
|
+
'*': _constants.TEXT_STYLE_MAP.ITALIC,
|
|
33
|
+
'***': _constants.TEXT_STYLE_MAP.BOLD_ITALIC,
|
|
34
|
+
'__': _constants.TEXT_STYLE_MAP.BOLD,
|
|
35
|
+
'_': _constants.TEXT_STYLE_MAP.ITALIC,
|
|
36
|
+
'___': _constants.TEXT_STYLE_MAP.BOLD_ITALIC,
|
|
37
|
+
'`': _constants.TEXT_STYLE_MAP.CODE
|
|
38
|
+
};
|
|
39
|
+
const getBeforeText = editor => {
|
|
40
|
+
const {
|
|
41
|
+
selection
|
|
42
|
+
} = editor;
|
|
43
|
+
if (selection == null) return {
|
|
44
|
+
beforeText: '',
|
|
45
|
+
range: null
|
|
46
|
+
};
|
|
47
|
+
const {
|
|
48
|
+
anchor
|
|
49
|
+
} = selection;
|
|
50
|
+
const range = {
|
|
51
|
+
anchor,
|
|
52
|
+
focus: {
|
|
53
|
+
path: selection.focus.path,
|
|
54
|
+
offset: 0
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const beforeText = _slate.Editor.string(editor, range) || '';
|
|
58
|
+
return {
|
|
59
|
+
beforeText,
|
|
60
|
+
range
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const withMarkDown = editor => {
|
|
64
|
+
const {
|
|
65
|
+
insertText
|
|
66
|
+
} = editor;
|
|
67
|
+
const newEditor = editor;
|
|
68
|
+
|
|
69
|
+
// When entering a space, convert markdown
|
|
70
|
+
newEditor.insertText = text => {
|
|
71
|
+
const {
|
|
72
|
+
selection
|
|
73
|
+
} = editor;
|
|
74
|
+
if (selection == null) return insertText(text);
|
|
75
|
+
if (_slate.Range.isExpanded(selection)) return insertText(text);
|
|
76
|
+
if ((0, _core.getSelectedNodeByType)(editor, _elementTypes.PARAGRAPH) == null) return insertText(text); // It must be in paragraph
|
|
77
|
+
if (text !== ' ') return insertText(text); // The value must be an input space
|
|
78
|
+
|
|
79
|
+
// Gets the text before the space
|
|
80
|
+
const {
|
|
81
|
+
beforeText,
|
|
82
|
+
range
|
|
83
|
+
} = getBeforeText(editor);
|
|
84
|
+
if (!beforeText || !range) return insertText(text);
|
|
85
|
+
|
|
86
|
+
// Based on the keyword, find the type of element you want to convert
|
|
87
|
+
const type = KEY_TO_TYPE_FOR_SPACE[beforeText.trim()];
|
|
88
|
+
const italicAndBoldType = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-3)];
|
|
89
|
+
const boldType = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-2)];
|
|
90
|
+
const italicType = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-1)];
|
|
91
|
+
const inlineCode = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-1)];
|
|
92
|
+
if (!type && !boldType && !italicType && !italicAndBoldType) return insertText(text);
|
|
93
|
+
if (italicAndBoldType === _constants.TEXT_STYLE_MAP.BOLD_ITALIC) {
|
|
94
|
+
const SYMBOL = beforeText.slice(-3);
|
|
95
|
+
const restStr = beforeText === null || beforeText === void 0 ? void 0 : beforeText.slice(0, beforeText.length - 3);
|
|
96
|
+
const startOffset = restStr === null || restStr === void 0 ? void 0 : restStr.lastIndexOf(SYMBOL);
|
|
97
|
+
const endOffset = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf(SYMBOL)) + 3;
|
|
98
|
+
if (startOffset === -1) {
|
|
99
|
+
return insertText(text);
|
|
100
|
+
}
|
|
101
|
+
if (startOffset !== -3) {
|
|
102
|
+
_slate.Transforms.delete(editor, {
|
|
103
|
+
at: {
|
|
104
|
+
anchor: {
|
|
105
|
+
path: range.focus.path,
|
|
106
|
+
offset: startOffset
|
|
107
|
+
},
|
|
108
|
+
focus: {
|
|
109
|
+
...selection.focus
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
voids: true
|
|
113
|
+
});
|
|
114
|
+
const newText = beforeText.slice(startOffset + 3, endOffset - 3);
|
|
115
|
+
_slate.Editor.addMark(editor, _constants.TEXT_STYLE_MAP.BOLD, true);
|
|
116
|
+
_slate.Editor.addMark(editor, _constants.TEXT_STYLE_MAP.ITALIC, true);
|
|
117
|
+
insertText(newText);
|
|
118
|
+
_slate.Editor.removeMark(editor, _constants.TEXT_STYLE_MAP.BOLD);
|
|
119
|
+
_slate.Editor.removeMark(editor, _constants.TEXT_STYLE_MAP.ITALIC);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (boldType === _constants.TEXT_STYLE_MAP.BOLD) {
|
|
125
|
+
const SYMBOL = beforeText.slice(-2);
|
|
126
|
+
const restStr = beforeText.slice(0, beforeText.length - 2);
|
|
127
|
+
const startOffset = restStr.lastIndexOf(SYMBOL);
|
|
128
|
+
const endOffset = beforeText.lastIndexOf(SYMBOL) + 2;
|
|
129
|
+
if (startOffset === -1) {
|
|
130
|
+
return insertText(text);
|
|
131
|
+
}
|
|
132
|
+
_slate.Transforms.delete(editor, {
|
|
133
|
+
at: {
|
|
134
|
+
anchor: {
|
|
135
|
+
path: range.focus.path,
|
|
136
|
+
offset: startOffset
|
|
137
|
+
},
|
|
138
|
+
focus: {
|
|
139
|
+
...selection.focus
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
voids: true
|
|
143
|
+
});
|
|
144
|
+
const newType = boldType.toLowerCase();
|
|
145
|
+
const newText = beforeText.slice(startOffset + 2, endOffset - 2);
|
|
146
|
+
_slate.Editor.addMark(editor, newType, true);
|
|
147
|
+
insertText(newText);
|
|
148
|
+
_slate.Editor.removeMark(editor, newType);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// demos
|
|
153
|
+
// 1 '*'
|
|
154
|
+
// 2 'acd * add *'
|
|
155
|
+
if (italicType === _constants.TEXT_STYLE_MAP.ITALIC) {
|
|
156
|
+
const SYMBOL = beforeText.slice(-1);
|
|
157
|
+
const restStr = beforeText === null || beforeText === void 0 ? void 0 : beforeText.slice(0, beforeText.length - 1);
|
|
158
|
+
const startOffset = restStr === null || restStr === void 0 ? void 0 : restStr.lastIndexOf(SYMBOL);
|
|
159
|
+
const endOffset = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf(SYMBOL)) + 1;
|
|
160
|
+
|
|
161
|
+
// start: restStr = '`' | ' `'
|
|
162
|
+
if (restStr === '' || restStr === '_') {
|
|
163
|
+
return insertText(text);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// end: restStr = ' _' | 'aaaaa_'
|
|
167
|
+
if (startOffset + 1 === restStr.length) {
|
|
168
|
+
return insertText(text);
|
|
169
|
+
}
|
|
170
|
+
if (startOffset === -1 && restStr.length > 0) {
|
|
171
|
+
return insertText(text);
|
|
172
|
+
}
|
|
173
|
+
if (startOffset !== -1) {
|
|
174
|
+
_slate.Transforms.delete(editor, {
|
|
175
|
+
at: {
|
|
176
|
+
anchor: {
|
|
177
|
+
path: range.focus.path,
|
|
178
|
+
offset: startOffset
|
|
179
|
+
},
|
|
180
|
+
focus: {
|
|
181
|
+
...selection.focus
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
voids: true
|
|
185
|
+
});
|
|
186
|
+
const newType = italicType.toLowerCase();
|
|
187
|
+
const newText = beforeText.slice(startOffset + 1, endOffset - 1);
|
|
188
|
+
_slate.Editor.addMark(editor, newType, true);
|
|
189
|
+
insertText(newText);
|
|
190
|
+
_slate.Editor.removeMark(editor, newType);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (type !== _elementTypes.CODE_BLOCK && inlineCode === _constants.TEXT_STYLE_MAP.CODE) {
|
|
195
|
+
const restStr = beforeText === null || beforeText === void 0 ? void 0 : beforeText.slice(0, beforeText.length - 1);
|
|
196
|
+
const startOffset = restStr === null || restStr === void 0 ? void 0 : restStr.lastIndexOf('`');
|
|
197
|
+
const endOffset = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf('`')) + 1;
|
|
198
|
+
|
|
199
|
+
// start: restStr = '`' | ' `'
|
|
200
|
+
if (restStr === '' || restStr === '`') {
|
|
201
|
+
return insertText(text);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// end: restStr = ' `' | 'aaaaa`'
|
|
205
|
+
if (startOffset + 1 === restStr.length) {
|
|
206
|
+
return insertText(text);
|
|
207
|
+
}
|
|
208
|
+
if (startOffset === -1 && restStr.length > 0) {
|
|
209
|
+
return insertText(text);
|
|
210
|
+
}
|
|
211
|
+
if (startOffset !== -1) {
|
|
212
|
+
_slate.Transforms.delete(editor, {
|
|
213
|
+
at: {
|
|
214
|
+
anchor: {
|
|
215
|
+
path: range.focus.path,
|
|
216
|
+
offset: startOffset
|
|
217
|
+
},
|
|
218
|
+
focus: {
|
|
219
|
+
...selection.focus
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
voids: true
|
|
223
|
+
});
|
|
224
|
+
const newType = inlineCode.toLowerCase();
|
|
225
|
+
const newText = beforeText.slice(startOffset + 1, endOffset - 1);
|
|
226
|
+
_slate.Editor.addMark(editor, newType, true);
|
|
227
|
+
insertText(newText);
|
|
228
|
+
|
|
229
|
+
// add space with inline code
|
|
230
|
+
_slate.Editor.removeMark(editor, newType);
|
|
231
|
+
insertText(' ');
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Delete element
|
|
237
|
+
_slate.Transforms.select(editor, range);
|
|
238
|
+
_slate.Transforms.delete(editor);
|
|
239
|
+
if (type === _elementTypes.UNORDERED_LIST) {
|
|
240
|
+
(0, _transforms.transformsToList)(editor, type);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (type === _elementTypes.BLOCKQUOTE) {
|
|
244
|
+
(0, _helpers.setBlockQuoteType)(editor, false);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (type === _elementTypes.CODE_BLOCK) {
|
|
248
|
+
(0, _helpers2.transformToCodeBlock)(editor);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
_slate.Transforms.setNodes(editor, {
|
|
252
|
+
type
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
return newEditor;
|
|
256
|
+
};
|
|
257
|
+
var _default = exports.default = withMarkDown;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SPLIT_NODE = exports.SET_SELECTION = exports.SET_NODE = exports.REMOVE_TEXT = exports.REMOVE_NODE = exports.MOVE_NODE = exports.MERGE_NODE = exports.INSERT_TEXT = exports.INSERT_NODE = void 0;
|
|
7
|
+
// insert_node & remove_node
|
|
8
|
+
const INSERT_TEXT = exports.INSERT_TEXT = 'insert_text';
|
|
9
|
+
const REMOVE_TEXT = exports.REMOVE_TEXT = 'remove_text';
|
|
10
|
+
|
|
11
|
+
// insert_node & remove_node
|
|
12
|
+
const INSERT_NODE = exports.INSERT_NODE = 'insert_node';
|
|
13
|
+
const REMOVE_NODE = exports.REMOVE_NODE = 'remove_node';
|
|
14
|
+
|
|
15
|
+
// merge_node & split_node
|
|
16
|
+
const MERGE_NODE = exports.MERGE_NODE = 'merge_node';
|
|
17
|
+
const SPLIT_NODE = exports.SPLIT_NODE = 'split_node';
|
|
18
|
+
|
|
19
|
+
// set_node & move_node
|
|
20
|
+
const SET_NODE = exports.SET_NODE = 'set_node';
|
|
21
|
+
const MOVE_NODE = exports.MOVE_NODE = 'move_node';
|
|
22
|
+
|
|
23
|
+
// set_selection
|
|
24
|
+
const SET_SELECTION = exports.SET_SELECTION = 'set_selection';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.replacePastedDataId = exports.replaceNodeId = exports.decorateOperation = void 0;
|
|
9
|
+
var _deepCopy = _interopRequireDefault(require("deep-copy"));
|
|
10
|
+
var _slugid = _interopRequireDefault(require("slugid"));
|
|
11
|
+
var OPERATION = _interopRequireWildcard(require("./constants"));
|
|
12
|
+
var _objectUtils = _interopRequireDefault(require("../../../utils/object-utils"));
|
|
13
|
+
const decorateOperation = operation => {
|
|
14
|
+
let newOperation = (0, _deepCopy.default)(operation);
|
|
15
|
+
const {
|
|
16
|
+
type
|
|
17
|
+
} = newOperation;
|
|
18
|
+
switch (type) {
|
|
19
|
+
case OPERATION.INSERT_NODE:
|
|
20
|
+
{
|
|
21
|
+
let {
|
|
22
|
+
node
|
|
23
|
+
} = newOperation;
|
|
24
|
+
if (!node.id) node.id = _slugid.default.nice(); // generate an id for insert node
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case OPERATION.SPLIT_NODE:
|
|
28
|
+
{
|
|
29
|
+
// child: split [7, 0] -> [[7, 0],[7, 1]]
|
|
30
|
+
// parent: split [[7, 0], [7, 1]] -> [[7], [8]]
|
|
31
|
+
const {
|
|
32
|
+
properties = {}
|
|
33
|
+
} = newOperation;
|
|
34
|
+
// need generate a new id for new node
|
|
35
|
+
properties.id = _slugid.default.nice();
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
default:
|
|
39
|
+
{
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return newOperation;
|
|
44
|
+
};
|
|
45
|
+
exports.decorateOperation = decorateOperation;
|
|
46
|
+
const replaceNodeId = node => {
|
|
47
|
+
if (!_objectUtils.default.isObject(node)) return node;
|
|
48
|
+
if (_objectUtils.default.hasProperty(node, 'children')) {
|
|
49
|
+
return {
|
|
50
|
+
...node,
|
|
51
|
+
id: _slugid.default.nice(),
|
|
52
|
+
children: replacePastedDataId(node.children)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
...node,
|
|
57
|
+
id: _slugid.default.nice()
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
exports.replaceNodeId = replaceNodeId;
|
|
61
|
+
const replacePastedDataId = pastedData => {
|
|
62
|
+
// If children is malformed, return a list of correct child nodes
|
|
63
|
+
if (_objectUtils.default.isObject(pastedData)) {
|
|
64
|
+
return replaceNodeId(pastedData);
|
|
65
|
+
}
|
|
66
|
+
if (!Array.isArray(pastedData)) return [{
|
|
67
|
+
id: _slugid.default.nice(),
|
|
68
|
+
text: ''
|
|
69
|
+
}];
|
|
70
|
+
return pastedData.map(item => {
|
|
71
|
+
item.id = _slugid.default.nice();
|
|
72
|
+
if (item.children) {
|
|
73
|
+
item.children = replacePastedDataId(item.children);
|
|
74
|
+
}
|
|
75
|
+
return item;
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
exports.replacePastedDataId = replacePastedDataId;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _withNodeId = _interopRequireDefault(require("./with-node-id"));
|
|
9
|
+
const NodeIdPlugin = {
|
|
10
|
+
editorPlugin: _withNodeId.default
|
|
11
|
+
};
|
|
12
|
+
var _default = exports.default = NodeIdPlugin;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _helpers = require("./helpers");
|
|
8
|
+
const catchSlateFragment = /data-slate-fragment="(.+?)"/m;
|
|
9
|
+
const getSlateFragmentAttribute = dataTransfer => {
|
|
10
|
+
const htmlData = dataTransfer.getData('text/html');
|
|
11
|
+
const [, fragment] = htmlData.match(catchSlateFragment) || [];
|
|
12
|
+
return fragment;
|
|
13
|
+
};
|
|
14
|
+
const withNodeId = editor => {
|
|
15
|
+
const {
|
|
16
|
+
apply
|
|
17
|
+
} = editor;
|
|
18
|
+
const newEditor = editor;
|
|
19
|
+
newEditor.apply = op => {
|
|
20
|
+
const newOp = (0, _helpers.decorateOperation)(op);
|
|
21
|
+
apply(newOp);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// rewrite insert fragment data
|
|
25
|
+
newEditor.insertFragmentData = data => {
|
|
26
|
+
const fragment = data.getData('application/x-slate-fragment') || getSlateFragmentAttribute(data);
|
|
27
|
+
if (fragment) {
|
|
28
|
+
const decoded = decodeURIComponent(window.atob(fragment));
|
|
29
|
+
const parsed = JSON.parse(decoded);
|
|
30
|
+
const newData = (0, _helpers.replacePastedDataId)(parsed);
|
|
31
|
+
newEditor.insertFragment(newData);
|
|
32
|
+
return newEditor;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return newEditor;
|
|
36
|
+
};
|
|
37
|
+
var _default = exports.default = withNodeId;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformToParagraph = void 0;
|
|
7
|
+
var _slate = require("slate");
|
|
8
|
+
var _elementTypes = require("../../constants/element-types");
|
|
9
|
+
var _core = require("../../core");
|
|
10
|
+
const transformToParagraph = (editor, focusLocation) => {
|
|
11
|
+
if (!editor.selection) return;
|
|
12
|
+
_slate.Transforms.setNodes(editor, {
|
|
13
|
+
type: _elementTypes.PARAGRAPH
|
|
14
|
+
});
|
|
15
|
+
(0, _core.focusEditor)(editor, focusLocation);
|
|
16
|
+
};
|
|
17
|
+
exports.transformToParagraph = transformToParagraph;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _elementTypes = require("../../constants/element-types");
|
|
9
|
+
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
10
|
+
var _renderElem = _interopRequireDefault(require("./render-elem"));
|
|
11
|
+
const PPlugin = {
|
|
12
|
+
type: _elementTypes.P,
|
|
13
|
+
nodeType: 'element',
|
|
14
|
+
editorPlugin: _plugin.default,
|
|
15
|
+
renderElements: [_renderElem.default]
|
|
16
|
+
};
|
|
17
|
+
var _default = exports.default = PPlugin;
|