@seafile/seafile-editor 1.0.2 → 1.0.4
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/dist/constants/event-types.js +2 -8
- package/dist/constants/hot-keys.js +1 -7
- package/dist/containers/article-info/index.js +24 -34
- package/dist/containers/custom/get-event-transfer.js +10 -16
- package/dist/containers/custom/set-event-transfer.js +10 -16
- package/dist/containers/hotkeys-helper/classify-hotkeys.js +20 -25
- package/dist/containers/hotkeys-helper/index.js +32 -35
- package/dist/containers/loading/index.js +11 -32
- package/dist/containers/outline/index.js +41 -51
- package/dist/containers/outline/outline-item.js +15 -21
- package/dist/editors/plain-markdown-editor/code-mirror.js +51 -75
- package/dist/editors/plain-markdown-editor/index.js +90 -107
- package/dist/editors/simple-slate-editor /index.js +43 -57
- package/dist/editors/simple-slate-editor /with-props-editor.js +4 -10
- package/dist/editors/slate-editor/editor-help/index.js +24 -37
- package/dist/editors/slate-editor/index.js +50 -64
- package/dist/editors/slate-editor/with-props-editor.js +4 -10
- package/dist/editors/slate-viewer/index.js +25 -31
- package/dist/extension/commons/element-popover/index.js +30 -55
- package/dist/extension/commons/index.js +3 -26
- package/dist/extension/commons/menu/index.js +4 -21
- package/dist/extension/commons/menu/menu-drop-down.js +50 -63
- package/dist/extension/commons/menu/menu-group.js +4 -11
- package/dist/extension/commons/menu/menu-item.js +25 -30
- package/dist/extension/commons/tooltip/index.js +14 -19
- package/dist/extension/constants/element-types.js +22 -28
- package/dist/extension/constants/index.js +15 -37
- package/dist/extension/constants/keyboard.js +3 -9
- package/dist/extension/constants/menus-config.js +118 -105
- package/dist/extension/core/index.js +3 -38
- package/dist/extension/core/queries/index.js +209 -304
- package/dist/extension/core/transforms/focus-editor.js +7 -13
- package/dist/extension/core/transforms/index.js +4 -49
- package/dist/extension/core/transforms/move-children.js +18 -25
- package/dist/extension/core/transforms/remove-node-children.js +8 -27
- package/dist/extension/core/transforms/replace-node-children.js +14 -19
- package/dist/extension/core/utils/index.js +36 -44
- package/dist/extension/editor.js +8 -15
- package/dist/extension/index.js +7 -48
- package/dist/extension/plugins/blockquote/helpers.js +38 -57
- package/dist/extension/plugins/blockquote/index.js +8 -15
- package/dist/extension/plugins/blockquote/menu/index.js +20 -25
- package/dist/extension/plugins/blockquote/plugin.js +35 -41
- package/dist/extension/plugins/blockquote/render-elem.js +9 -14
- package/dist/extension/plugins/check-list/helper.js +14 -24
- package/dist/extension/plugins/check-list/index.js +10 -17
- package/dist/extension/plugins/check-list/menu/index.js +21 -29
- package/dist/extension/plugins/check-list/plugin.js +24 -26
- package/dist/extension/plugins/check-list/render-elem.js +22 -28
- package/dist/extension/plugins/clear-format/helpers.js +25 -47
- package/dist/extension/plugins/clear-format/menu/index.js +22 -29
- package/dist/extension/plugins/code-block/helpers.js +74 -126
- package/dist/extension/plugins/code-block/index.js +10 -18
- package/dist/extension/plugins/code-block/menu/index.js +20 -27
- package/dist/extension/plugins/code-block/plugin.js +123 -144
- package/dist/extension/plugins/code-block/render-elem/constant.js +15 -11
- package/dist/extension/plugins/code-block/render-elem/index.js +30 -39
- package/dist/extension/plugins/code-block/render-elem/language-selector.js +19 -27
- package/dist/extension/plugins/formula/helper.js +39 -45
- package/dist/extension/plugins/formula/index.js +10 -17
- package/dist/extension/plugins/formula/menu/formula-modal.js +37 -52
- package/dist/extension/plugins/formula/menu/index.js +34 -50
- package/dist/extension/plugins/formula/plugin.js +12 -14
- package/dist/extension/plugins/formula/render-elem.js +27 -33
- package/dist/extension/plugins/header/helper.js +35 -48
- package/dist/extension/plugins/header/index.js +10 -17
- package/dist/extension/plugins/header/menu/index.js +52 -66
- package/dist/extension/plugins/header/plugin.js +72 -83
- package/dist/extension/plugins/header/render-elem.js +15 -20
- package/dist/extension/plugins/image/helper.js +28 -37
- package/dist/extension/plugins/image/index.js +10 -17
- package/dist/extension/plugins/image/menu/image-menu-dialog.js +31 -42
- package/dist/extension/plugins/image/menu/image-menu-popover.js +35 -67
- package/dist/extension/plugins/image/menu/index.js +24 -34
- package/dist/extension/plugins/image/plugin.js +18 -18
- package/dist/extension/plugins/image/render-element/image-previewer.js +32 -42
- package/dist/extension/plugins/image/render-element/index.js +58 -74
- package/dist/extension/plugins/index.js +18 -94
- package/dist/extension/plugins/link/helper.js +102 -139
- package/dist/extension/plugins/link/index.js +10 -17
- package/dist/extension/plugins/link/menu/index.js +46 -62
- package/dist/extension/plugins/link/menu/link-modal.js +67 -87
- package/dist/extension/plugins/link/plugin.js +52 -56
- package/dist/extension/plugins/link/render-elem/index.js +39 -54
- package/dist/extension/plugins/link/render-elem/link-popover.js +38 -42
- package/dist/extension/plugins/list/constant.js +2 -8
- package/dist/extension/plugins/list/helpers.js +40 -54
- package/dist/extension/plugins/list/index.js +10 -17
- package/dist/extension/plugins/list/menu/index.js +23 -33
- package/dist/extension/plugins/list/plugin/index.js +28 -31
- package/dist/extension/plugins/list/plugin/insert-break-list.js +9 -15
- package/dist/extension/plugins/list/plugin/insert-fragment-list.js +86 -109
- package/dist/extension/plugins/list/plugin/normalize-list.js +31 -42
- package/dist/extension/plugins/list/plugin/on-tab-handle.js +35 -34
- package/dist/extension/plugins/list/queries/index.js +22 -30
- package/dist/extension/plugins/list/render-elem/index.js +27 -27
- package/dist/extension/plugins/list/transforms/index.js +11 -75
- package/dist/extension/plugins/list/transforms/insert-list-item.js +38 -47
- package/dist/extension/plugins/list/transforms/move-list-item-down.js +22 -32
- package/dist/extension/plugins/list/transforms/move-list-item-up.js +45 -56
- package/dist/extension/plugins/list/transforms/move-list-items-to-list.js +25 -31
- package/dist/extension/plugins/list/transforms/move-list-items.js +37 -44
- package/dist/extension/plugins/list/transforms/normalize-list-item.js +57 -81
- package/dist/extension/plugins/list/transforms/normalize-nested-list.js +17 -26
- package/dist/extension/plugins/list/transforms/remove-first-list-item.js +12 -19
- package/dist/extension/plugins/list/transforms/transforms-to-list.js +60 -84
- package/dist/extension/plugins/list/transforms/unwrap-list.js +20 -29
- package/dist/extension/plugins/node-id/constants.js +9 -15
- package/dist/extension/plugins/node-id/helpers.js +33 -35
- package/dist/extension/plugins/node-id/index.js +4 -11
- package/dist/extension/plugins/node-id/with-node-id.js +18 -26
- package/dist/extension/plugins/paragraph/helper.js +7 -13
- package/dist/extension/plugins/paragraph/index.js +8 -15
- package/dist/extension/plugins/paragraph/plugin.js +25 -27
- package/dist/extension/plugins/paragraph/render-elem.js +9 -14
- package/dist/extension/plugins/table/constant.js +3 -9
- package/dist/extension/plugins/table/helper.js +133 -154
- package/dist/extension/plugins/table/index.js +11 -19
- package/dist/extension/plugins/table/menu/index.js +26 -38
- package/dist/extension/plugins/table/menu/table-operator.js +62 -77
- package/dist/extension/plugins/table/menu/table-size-selector.js +41 -62
- package/dist/extension/plugins/table/model.js +39 -41
- package/dist/extension/plugins/table/plugin.js +95 -102
- package/dist/extension/plugins/table/render-elem/context-menu.js +42 -65
- package/dist/extension/plugins/table/render-elem/index.js +85 -93
- package/dist/extension/plugins/table/table-operations.js +101 -118
- package/dist/extension/plugins/text-style/helpers.js +18 -28
- package/dist/extension/plugins/text-style/index.js +8 -15
- package/dist/extension/plugins/text-style/menu/index.js +19 -25
- package/dist/extension/plugins/text-style/plugin.js +16 -21
- package/dist/extension/plugins/text-style/render-elem.js +28 -33
- package/dist/extension/render/render-element.js +26 -47
- package/dist/extension/render/render-leaf.js +9 -18
- package/dist/extension/toolbar/header-toolbar/index.js +66 -84
- package/dist/extension/toolbar/index.js +2 -13
- package/dist/extension/toolbar/user-help/shortcut-dialog.js +108 -131
- package/dist/hooks/use-mathjax.js +9 -20
- package/dist/hooks/use-scroll-context.js +7 -12
- package/dist/hooks/use-selection-update.js +9 -21
- package/dist/index.js +9 -80
- package/dist/pages/markdown-editor.js +30 -43
- package/dist/pages/markdown-view.js +25 -37
- package/dist/pages/rich-markdown-editor.js +54 -67
- package/dist/pages/simple-editor.js +29 -42
- package/dist/slate-convert/html-to-slate/constants.js +26 -32
- package/dist/slate-convert/html-to-slate/helper.js +1 -7
- package/dist/slate-convert/html-to-slate/index.js +44 -51
- package/dist/slate-convert/html-to-slate/rules/blockquote.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/check-list.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/code-block.js +40 -51
- package/dist/slate-convert/html-to-slate/rules/header.js +11 -16
- package/dist/slate-convert/html-to-slate/rules/image.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/index.js +11 -18
- package/dist/slate-convert/html-to-slate/rules/link.js +11 -16
- package/dist/slate-convert/html-to-slate/rules/list.js +21 -26
- package/dist/slate-convert/html-to-slate/rules/paragraph.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/table.js +14 -19
- package/dist/slate-convert/html-to-slate/rules/text.js +14 -19
- package/dist/slate-convert/index.js +8 -34
- package/dist/slate-convert/md-to-html/index.js +26 -31
- package/dist/slate-convert/md-to-html/sanitize-schema.js +5 -12
- package/dist/slate-convert/md-to-slate/index.js +17 -23
- package/dist/slate-convert/md-to-slate/transform.js +183 -175
- package/dist/slate-convert/slate-to-md/index.js +14 -20
- package/dist/slate-convert/slate-to-md/transform.js +76 -87
- package/dist/utils/common.js +8 -15
- package/dist/utils/deserialize-html.js +118 -166
- package/dist/utils/dom-utils.js +18 -22
- package/dist/utils/event-bus.js +27 -47
- package/dist/utils/event-handler.js +29 -38
- package/dist/utils/object-utils.js +39 -62
- package/package.json +5 -4
|
@@ -1,188 +1,165 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
|
|
9
|
-
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toArray"));
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
11
|
-
var _slate = require("slate");
|
|
12
|
-
var _slugid = _interopRequireDefault(require("slugid"));
|
|
13
|
-
var _core = require("../../../core");
|
|
14
|
-
var _constant = require("../constant");
|
|
15
|
-
var _elementTypes = require("../../../constants/element-types");
|
|
16
|
-
var isListRoot = function isListRoot(node) {
|
|
17
|
-
return _slate.Element.isElement(node) && _constant.LIST_TYPES.includes(node.type);
|
|
1
|
+
import { Element, Path, Transforms, Node, Editor, insertFragment } from 'slate';
|
|
2
|
+
import slugid from 'slugid';
|
|
3
|
+
import { findNode, generateDefaultText, getCommonNode, getNode, getNodes } from '../../../core';
|
|
4
|
+
import { LIST_TYPES } from '../constant';
|
|
5
|
+
import { LIST_ITEM, PARAGRAPH } from '../../../constants/element-types';
|
|
6
|
+
const isListRoot = node => {
|
|
7
|
+
return Element.isElement(node) && LIST_TYPES.includes(node.type);
|
|
18
8
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
const getFirstAncestorOfType = (root, entry, _ref) => {
|
|
10
|
+
let {
|
|
11
|
+
type
|
|
12
|
+
} = _ref;
|
|
13
|
+
let ancestor = Path.parent(entry[1]);
|
|
14
|
+
while (getNode(root, ancestor).type !== type) {
|
|
15
|
+
ancestor = Path.parent(ancestor);
|
|
24
16
|
}
|
|
25
|
-
return [
|
|
17
|
+
return [getNode(root, ancestor), ancestor];
|
|
26
18
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
while (isListRoot(node) || node.type ===
|
|
19
|
+
const findListItemsWithContent = first => {
|
|
20
|
+
let prev = null;
|
|
21
|
+
let node = first;
|
|
22
|
+
while (isListRoot(node) || node.type === LIST_ITEM && node.children[0].type !== PARAGRAPH) {
|
|
31
23
|
prev = node;
|
|
32
|
-
|
|
33
|
-
node = _node$children[0];
|
|
24
|
+
[node] = node.children;
|
|
34
25
|
}
|
|
35
26
|
return prev ? prev.children : [node];
|
|
36
27
|
};
|
|
37
|
-
|
|
28
|
+
const trimList = listRoot => {
|
|
38
29
|
if (!isListRoot(listRoot)) {
|
|
39
30
|
return [listRoot];
|
|
40
31
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return
|
|
32
|
+
const _texts = Node.texts(listRoot);
|
|
33
|
+
const textEntries = Array.from(_texts);
|
|
34
|
+
const commonAncestorEntry = textEntries.reduce((commonAncestor, textEntry) => {
|
|
35
|
+
return Path.isAncestor(commonAncestor[1], textEntry[1]) ? commonAncestor : getCommonNode(listRoot, textEntry[1], commonAncestor[1]);
|
|
45
36
|
}, getFirstAncestorOfType(listRoot, textEntries[0], {
|
|
46
|
-
type:
|
|
37
|
+
type: LIST_ITEM
|
|
47
38
|
}));
|
|
48
39
|
|
|
49
40
|
// is ul/ol: return children
|
|
50
41
|
// is not ul/ol
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
first = _ref3[0],
|
|
54
|
-
rest = _ref3.slice(1);
|
|
55
|
-
return [].concat((0, _toConsumableArray2.default)(findListItemsWithContent(first)), (0, _toConsumableArray2.default)(rest));
|
|
42
|
+
const [first, ...rest] = isListRoot(commonAncestorEntry[0]) ? commonAncestorEntry[0].children : [commonAncestorEntry[0]];
|
|
43
|
+
return [...findListItemsWithContent(first), ...rest];
|
|
56
44
|
};
|
|
57
|
-
|
|
58
|
-
return node.type ===
|
|
59
|
-
id:
|
|
60
|
-
type:
|
|
45
|
+
const wrapNodeIntoListItem = node => {
|
|
46
|
+
return node.type === LIST_ITEM ? node : {
|
|
47
|
+
id: slugid.nice(),
|
|
48
|
+
type: LIST_ITEM,
|
|
61
49
|
children: [node]
|
|
62
50
|
};
|
|
63
51
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return isFragmentOnlyListRoot &&
|
|
52
|
+
const isSingleLic = fragment => {
|
|
53
|
+
const isFragmentOnlyListRoot = fragment.length === 1 && isListRoot(fragment[0]);
|
|
54
|
+
return isFragmentOnlyListRoot && [...getNodes({
|
|
67
55
|
children: fragment
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var _ref5 = (0, _slicedToArray2.default)(_ref4, 1),
|
|
72
|
-
node = _ref5[0];
|
|
73
|
-
return node.type === _elementTypes.PARAGRAPH;
|
|
56
|
+
})].filter(entry => Element.isElement(entry[0])).filter(_ref2 => {
|
|
57
|
+
let [node] = _ref2;
|
|
58
|
+
return node.type === PARAGRAPH;
|
|
74
59
|
}).length === 1;
|
|
75
60
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
licNode = _licEntry[0],
|
|
81
|
-
licPath = _licEntry[1];
|
|
82
|
-
var isEmptyNode = !_slate.Node.string(licNode);
|
|
61
|
+
export const getTextAndListItemNodes = (editor, fragment, liEntry, licEntry) => {
|
|
62
|
+
const [, liPath] = liEntry;
|
|
63
|
+
const [licNode, licPath] = licEntry;
|
|
64
|
+
const isEmptyNode = !Node.string(licNode);
|
|
83
65
|
// format copied fragment
|
|
84
66
|
// first: lic, path: [...liPath, 0, 0]
|
|
85
67
|
// rest: children, path: [...liPath, 1, 0]
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
rest = _fragment$flatMap$map2.slice(1);
|
|
90
|
-
var textNode = null;
|
|
91
|
-
var listItemNodes = [];
|
|
68
|
+
const [first, ...rest] = fragment.flatMap(trimList).map(wrapNodeIntoListItem);
|
|
69
|
+
let textNode = null;
|
|
70
|
+
let listItemNodes = [];
|
|
92
71
|
if (isListRoot(fragment[0])) {
|
|
93
72
|
if (isSingleLic(fragment)) {
|
|
94
73
|
textNode = first;
|
|
95
74
|
listItemNodes = rest;
|
|
96
75
|
} else if (isEmptyNode) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
currentSubLists = _li$children.slice(1); // old
|
|
76
|
+
const li = getNode(editor, liPath);
|
|
77
|
+
const [, ...currentSubLists] = li.children; // old
|
|
100
78
|
|
|
101
|
-
|
|
102
|
-
newLic = _first$children[0],
|
|
103
|
-
newSubLists = _first$children.slice(1); // copied
|
|
79
|
+
const [newLic, ...newSubLists] = first.children; // copied
|
|
104
80
|
// insert copied contents
|
|
105
|
-
|
|
106
|
-
at:
|
|
81
|
+
Transforms.insertNodes(editor, newLic, {
|
|
82
|
+
at: Path.next(licPath),
|
|
107
83
|
select: true
|
|
108
84
|
});
|
|
109
|
-
|
|
85
|
+
Transforms.removeNodes(editor, {
|
|
110
86
|
at: licPath
|
|
111
87
|
});
|
|
112
88
|
if (newSubLists.length) {
|
|
113
89
|
if (currentSubLists.length) {
|
|
114
|
-
|
|
115
|
-
|
|
90
|
+
const path = [...liPath, 1, 0];
|
|
91
|
+
Transforms.insertNodes(editor, newSubLists[0].children, {
|
|
116
92
|
at: path,
|
|
117
93
|
select: true
|
|
118
94
|
});
|
|
119
95
|
} else {
|
|
120
|
-
|
|
121
|
-
at:
|
|
96
|
+
Transforms.insertNodes(editor, newSubLists, {
|
|
97
|
+
at: Path.next(licPath),
|
|
122
98
|
select: true
|
|
123
99
|
});
|
|
124
100
|
}
|
|
125
101
|
}
|
|
126
|
-
textNode =
|
|
102
|
+
textNode = generateDefaultText();
|
|
127
103
|
listItemNodes = rest;
|
|
128
104
|
} else {
|
|
129
|
-
textNode =
|
|
130
|
-
listItemNodes = [first
|
|
105
|
+
textNode = generateDefaultText();
|
|
106
|
+
listItemNodes = [first, ...rest];
|
|
131
107
|
}
|
|
132
108
|
} else {
|
|
133
109
|
textNode = first;
|
|
134
110
|
listItemNodes = rest;
|
|
135
111
|
return {
|
|
136
|
-
textNode
|
|
137
|
-
listItemNodes
|
|
112
|
+
textNode,
|
|
113
|
+
listItemNodes
|
|
138
114
|
};
|
|
139
115
|
}
|
|
140
116
|
return {
|
|
141
|
-
textNode
|
|
142
|
-
listItemNodes
|
|
117
|
+
textNode,
|
|
118
|
+
listItemNodes
|
|
143
119
|
};
|
|
144
120
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
121
|
+
export const insertFragmentList = editor => {
|
|
122
|
+
const {
|
|
123
|
+
insertFragment: _insertFragment
|
|
124
|
+
} = editor;
|
|
125
|
+
return fragment => {
|
|
126
|
+
Editor.withoutNormalizing(editor, () => {
|
|
127
|
+
let liEntry = findNode(editor, {
|
|
150
128
|
match: {
|
|
151
|
-
type:
|
|
129
|
+
type: LIST_ITEM
|
|
152
130
|
},
|
|
153
131
|
mode: 'lowest'
|
|
154
132
|
});
|
|
155
133
|
if (!liEntry) {
|
|
156
|
-
|
|
134
|
+
const nodes = isListRoot(fragment) ? [generateDefaultText(), ...fragment] : fragment;
|
|
157
135
|
return _insertFragment(nodes);
|
|
158
136
|
}
|
|
159
|
-
|
|
137
|
+
insertFragment(editor, [generateDefaultText()]); // need ' '
|
|
160
138
|
|
|
161
|
-
liEntry =
|
|
139
|
+
liEntry = findNode(editor, {
|
|
162
140
|
match: {
|
|
163
|
-
type:
|
|
141
|
+
type: LIST_ITEM
|
|
164
142
|
},
|
|
165
143
|
mode: 'lowest'
|
|
166
144
|
});
|
|
167
|
-
|
|
145
|
+
const licEntry = findNode(editor, {
|
|
168
146
|
match: {
|
|
169
|
-
type:
|
|
147
|
+
type: PARAGRAPH
|
|
170
148
|
},
|
|
171
149
|
mode: 'lowest'
|
|
172
150
|
});
|
|
173
151
|
if (!licEntry) {
|
|
174
|
-
|
|
175
|
-
return _insertFragment(
|
|
152
|
+
const nodes = isListRoot(fragment) ? [generateDefaultText(), ...fragment] : fragment;
|
|
153
|
+
return _insertFragment(nodes);
|
|
176
154
|
}
|
|
177
|
-
|
|
178
|
-
textNode
|
|
179
|
-
listItemNodes
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
at: _slate.Path.next(liPath),
|
|
155
|
+
const {
|
|
156
|
+
textNode,
|
|
157
|
+
listItemNodes
|
|
158
|
+
} = getTextAndListItemNodes(editor, fragment, liEntry, licEntry);
|
|
159
|
+
insertFragment(editor, [textNode]);
|
|
160
|
+
const [, liPath] = liEntry;
|
|
161
|
+
return Transforms.insertNodes(editor, listItemNodes, {
|
|
162
|
+
at: Path.next(liPath),
|
|
186
163
|
select: true
|
|
187
164
|
});
|
|
188
165
|
});
|
|
@@ -1,76 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var _constant = require("../constant");
|
|
14
|
-
var normalizeList = exports.normalizeList = function normalizeList(editor) {
|
|
15
|
-
var normalizeNode = editor.normalizeNode;
|
|
16
|
-
return function (_ref) {
|
|
17
|
-
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
18
|
-
node = _ref2[0],
|
|
19
|
-
path = _ref2[1];
|
|
20
|
-
if (!_slate.Element.isElement(node)) {
|
|
1
|
+
import { Element, Transforms, Path } from 'slate';
|
|
2
|
+
import { moveListItemsToList, normalizeListItem, normalizeNestedList } from '../transforms';
|
|
3
|
+
import { LIST_ITEM } from '../../../constants/element-types';
|
|
4
|
+
import { generateElement, getChildren, getNode, getPreviousPath, match } from '../../../core';
|
|
5
|
+
import { LIST_TYPES } from '../constant';
|
|
6
|
+
export const normalizeList = editor => {
|
|
7
|
+
const {
|
|
8
|
+
normalizeNode
|
|
9
|
+
} = editor;
|
|
10
|
+
return _ref => {
|
|
11
|
+
let [node, path] = _ref;
|
|
12
|
+
if (!Element.isElement(node)) {
|
|
21
13
|
return normalizeNode([node, path]);
|
|
22
14
|
}
|
|
23
15
|
|
|
24
16
|
// root
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return child.type !== _elementTypes.LIST_ITEM;
|
|
17
|
+
if (LIST_TYPES.includes(node.type)) {
|
|
18
|
+
const children = getChildren([node, path]);
|
|
19
|
+
const nonLiChild = children.find(_ref2 => {
|
|
20
|
+
let [child] = _ref2;
|
|
21
|
+
return child.type !== LIST_ITEM;
|
|
31
22
|
});
|
|
32
23
|
if (nonLiChild) {
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
const listItem = generateElement(LIST_ITEM, []);
|
|
25
|
+
Transforms.wrapNodes(editor, listItem, {
|
|
35
26
|
at: nonLiChild[1]
|
|
36
27
|
});
|
|
37
28
|
return;
|
|
38
29
|
}
|
|
39
30
|
}
|
|
40
|
-
if (
|
|
41
|
-
type:
|
|
31
|
+
if (match(node, [], {
|
|
32
|
+
type: LIST_TYPES
|
|
42
33
|
})) {
|
|
43
|
-
if (!node.children.length || !node.children.find(
|
|
44
|
-
|
|
45
|
-
})) {
|
|
46
|
-
_slate.Transforms.removeNodes(editor, {
|
|
34
|
+
if (!node.children.length || !node.children.find(item => item.type === LIST_ITEM)) {
|
|
35
|
+
Transforms.removeNodes(editor, {
|
|
47
36
|
at: path
|
|
48
37
|
});
|
|
49
38
|
return;
|
|
50
39
|
}
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
const nextPath = Path.next(path);
|
|
41
|
+
const nextNode = getNode(editor, nextPath);
|
|
53
42
|
if ((nextNode === null || nextNode === void 0 ? void 0 : nextNode.type) === node.type) {
|
|
54
|
-
|
|
43
|
+
moveListItemsToList(editor, {
|
|
55
44
|
fromList: [nextNode, nextPath],
|
|
56
45
|
toList: [node, path],
|
|
57
46
|
deleteFromList: true
|
|
58
47
|
});
|
|
59
48
|
}
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
const prevPath = getPreviousPath(path);
|
|
50
|
+
const prevNode = getNode(editor, prevPath);
|
|
62
51
|
if ((prevNode === null || prevNode === void 0 ? void 0 : prevNode.type) === node.type) {
|
|
63
52
|
editor.normalizeNode([prevNode, prevPath]);
|
|
64
53
|
return;
|
|
65
54
|
}
|
|
66
|
-
if (
|
|
55
|
+
if (normalizeNestedList(editor, {
|
|
67
56
|
nestedListItem: [node, path]
|
|
68
57
|
})) {
|
|
69
58
|
return;
|
|
70
59
|
}
|
|
71
60
|
}
|
|
72
|
-
if (node.type ===
|
|
73
|
-
if (
|
|
61
|
+
if (node.type === LIST_ITEM) {
|
|
62
|
+
if (normalizeListItem(editor, {
|
|
74
63
|
listItem: [node, path]
|
|
75
64
|
})) {
|
|
76
65
|
return;
|
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _isHotkey = _interopRequireDefault(require("is-hotkey"));
|
|
11
|
-
var _core = require("../../../core");
|
|
12
|
-
var _elementTypes = require("../../../constants/element-types");
|
|
13
|
-
var _transforms = require("../transforms");
|
|
14
|
-
var handleTab = exports.handleTab = function handleTab(editor, event) {
|
|
15
|
-
var selection = editor.selection;
|
|
1
|
+
import { Editor, Range, Transforms } from 'slate';
|
|
2
|
+
import isHotkey from 'is-hotkey';
|
|
3
|
+
import { findNode } from '../../../core';
|
|
4
|
+
import { LIST_ITEM } from '../../../constants/element-types';
|
|
5
|
+
import { moveListItems } from '../transforms';
|
|
6
|
+
export const handleTab = (editor, event) => {
|
|
7
|
+
const {
|
|
8
|
+
selection
|
|
9
|
+
} = editor;
|
|
16
10
|
if (!selection) return;
|
|
17
|
-
|
|
18
|
-
type: [
|
|
11
|
+
const selectedList = findNode(editor, {
|
|
12
|
+
type: [LIST_ITEM]
|
|
19
13
|
});
|
|
20
14
|
if (!selectedList) return;
|
|
21
|
-
|
|
22
|
-
if (!
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
15
|
+
let workRange = editor.selection;
|
|
16
|
+
if (!Range.isCollapsed(selection)) {
|
|
17
|
+
let {
|
|
18
|
+
anchor,
|
|
19
|
+
focus
|
|
20
|
+
} = selection;
|
|
21
|
+
if (Range.isBackward(selection)) {
|
|
22
|
+
({
|
|
23
|
+
anchor,
|
|
24
|
+
focus
|
|
25
|
+
} = {
|
|
26
|
+
anchor: {
|
|
27
|
+
...selection.focus
|
|
28
|
+
},
|
|
29
|
+
focus: {
|
|
30
|
+
...selection.anchor
|
|
31
|
+
}
|
|
32
|
+
});
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
anchor
|
|
35
|
-
focus
|
|
34
|
+
const unHungRange = Editor.unhangRange(editor, {
|
|
35
|
+
anchor,
|
|
36
|
+
focus
|
|
36
37
|
});
|
|
37
38
|
if (unHungRange) {
|
|
38
39
|
workRange = unHungRange;
|
|
39
|
-
|
|
40
|
+
Transforms.select(editor, unHungRange);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
+
const isIncrease = isHotkey('shift+tab', event) ? false : true;
|
|
43
44
|
if (workRange && selectedList) {
|
|
44
45
|
event.preventDefault();
|
|
45
|
-
|
|
46
|
+
moveListItems(editor, {
|
|
46
47
|
at: workRange,
|
|
47
48
|
increase: isIncrease,
|
|
48
49
|
enableResetOnShiftTab: true
|
|
@@ -1,51 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var getListItemEntry = exports.getListItemEntry = function getListItemEntry(editor) {
|
|
11
|
-
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
12
|
-
_ref$at = _ref.at,
|
|
13
|
-
at = _ref$at === void 0 ? editor.selection : _ref$at;
|
|
14
|
-
var _at = null;
|
|
15
|
-
if (_slate.Range.isRange(at) && !_slate.Range.isCollapsed(at)) {
|
|
1
|
+
import { Editor, Element, Range, Node } from 'slate';
|
|
2
|
+
import { LIST_ITEM } from '../../../constants/element-types';
|
|
3
|
+
import { LIST_TYPES } from '../constant';
|
|
4
|
+
export const getListItemEntry = function (editor) {
|
|
5
|
+
let {
|
|
6
|
+
at = editor.selection
|
|
7
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8
|
+
let _at = null;
|
|
9
|
+
if (Range.isRange(at) && !Range.isCollapsed(at)) {
|
|
16
10
|
_at = at.focus.path;
|
|
17
|
-
} else if (
|
|
11
|
+
} else if (Range.isRange(at)) {
|
|
18
12
|
_at = at.anchor.path;
|
|
19
13
|
} else {
|
|
20
14
|
_at = at;
|
|
21
15
|
}
|
|
22
16
|
if (_at) {
|
|
23
|
-
|
|
17
|
+
const node = Node.get(editor, _at);
|
|
24
18
|
if (node) {
|
|
25
|
-
|
|
19
|
+
const listItem = Editor.above(editor, {
|
|
26
20
|
at: _at,
|
|
27
|
-
match:
|
|
28
|
-
return _slate.Element.isElement(n) && n.type === _elementTypes.LIST_ITEM;
|
|
29
|
-
}
|
|
21
|
+
match: n => Element.isElement(n) && n.type === LIST_ITEM
|
|
30
22
|
});
|
|
31
23
|
if (listItem) {
|
|
32
|
-
|
|
24
|
+
const list = Editor.parent(editor, listItem[1]);
|
|
33
25
|
return {
|
|
34
|
-
list
|
|
35
|
-
listItem
|
|
26
|
+
list,
|
|
27
|
+
listItem
|
|
36
28
|
};
|
|
37
29
|
}
|
|
38
30
|
}
|
|
39
31
|
}
|
|
40
32
|
return null;
|
|
41
33
|
};
|
|
42
|
-
|
|
43
|
-
return node.children.some(
|
|
44
|
-
return
|
|
34
|
+
export const hasListChild = node => {
|
|
35
|
+
return node.children.some(n => {
|
|
36
|
+
return Element.isElement(n) && LIST_TYPES.includes(n.type);
|
|
45
37
|
});
|
|
46
38
|
};
|
|
47
|
-
|
|
39
|
+
export const isListNested = (editor, listPath) => {
|
|
48
40
|
var _Editor$parent;
|
|
49
|
-
|
|
50
|
-
return (listParentNode === null || listParentNode === void 0 ? void 0 : listParentNode.type) ===
|
|
41
|
+
const listParentNode = (_Editor$parent = Editor.parent(editor, listPath)) === null || _Editor$parent === void 0 ? void 0 : _Editor$parent[0];
|
|
42
|
+
return (listParentNode === null || listParentNode === void 0 ? void 0 : listParentNode.type) === LIST_ITEM;
|
|
51
43
|
};
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var attributes = props.attributes,
|
|
13
|
-
children = props.children,
|
|
14
|
-
node = props.element;
|
|
15
|
-
var Tag = node.type === _elementTypes.ORDERED_LIST ? 'ol' : 'ul';
|
|
16
|
-
return /*#__PURE__*/_react.default.createElement(Tag, Object.assign({
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ORDERED_LIST } from '../../../constants/element-types';
|
|
3
|
+
import './style.css';
|
|
4
|
+
const renderList = (props, editor) => {
|
|
5
|
+
const {
|
|
6
|
+
attributes,
|
|
7
|
+
children,
|
|
8
|
+
element: node
|
|
9
|
+
} = props;
|
|
10
|
+
const Tag = node.type === ORDERED_LIST ? 'ol' : 'ul';
|
|
11
|
+
return /*#__PURE__*/React.createElement(Tag, Object.assign({
|
|
17
12
|
"data-id": node.id,
|
|
18
13
|
"data-root": "true",
|
|
19
14
|
className: "sf-list-line"
|
|
20
15
|
}, attributes), children);
|
|
21
16
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const renderListItem = (props, editor) => {
|
|
18
|
+
const {
|
|
19
|
+
attributes,
|
|
20
|
+
children,
|
|
21
|
+
element
|
|
22
|
+
} = props;
|
|
23
|
+
return /*#__PURE__*/React.createElement("li", Object.assign({
|
|
27
24
|
"data-id": element.id,
|
|
28
25
|
"data-root": "true"
|
|
29
26
|
}, attributes), children);
|
|
30
27
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
const renderListLic = (props, editor) => {
|
|
29
|
+
const {
|
|
30
|
+
attributes,
|
|
31
|
+
children,
|
|
32
|
+
element
|
|
33
|
+
} = props;
|
|
34
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
36
35
|
"data-id": element.id
|
|
37
36
|
}, attributes), children);
|
|
38
|
-
};
|
|
37
|
+
};
|
|
38
|
+
export { renderList, renderListItem, renderListLic };
|