@quadrats/common 0.6.7 → 0.7.0
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/blockquote/createBlockquote.d.ts +1 -1
- package/blockquote/createBlockquote.js +33 -33
- package/blockquote/index.cjs.js +32 -34
- package/bold/createBold.d.ts +2 -1
- package/bold/createBold.js +6 -4
- package/bold/index.cjs.js +6 -6
- package/divider/createDivider.d.ts +1 -1
- package/divider/createDivider.js +29 -29
- package/divider/index.cjs.js +29 -31
- package/embed/createEmbed.js +40 -40
- package/embed/deserializeEmbedElementToData.js +6 -6
- package/embed/index.cjs.js +54 -56
- package/embed/serializeEmbedCode.js +8 -8
- package/embed/strategies/facebook/index.cjs.js +45 -47
- package/embed/strategies/facebook/index.d.ts +5 -5
- package/embed/strategies/facebook/index.js +45 -45
- package/embed/strategies/instagram/index.cjs.js +29 -31
- package/embed/strategies/instagram/index.d.ts +3 -3
- package/embed/strategies/instagram/index.js +29 -29
- package/embed/strategies/podcast-apple/index.cjs.js +16 -18
- package/embed/strategies/podcast-apple/index.d.ts +4 -4
- package/embed/strategies/podcast-apple/index.js +16 -16
- package/embed/strategies/spotify/index.cjs.js +14 -16
- package/embed/strategies/spotify/index.d.ts +4 -4
- package/embed/strategies/spotify/index.js +14 -14
- package/embed/strategies/twitter/index.cjs.js +41 -43
- package/embed/strategies/twitter/index.d.ts +4 -4
- package/embed/strategies/twitter/index.js +41 -41
- package/embed/strategies/vimeo/index.cjs.js +14 -16
- package/embed/strategies/vimeo/index.d.ts +3 -3
- package/embed/strategies/vimeo/index.js +14 -14
- package/embed/strategies/youtube/index.cjs.js +14 -16
- package/embed/strategies/youtube/index.d.ts +3 -3
- package/embed/strategies/youtube/index.js +14 -14
- package/embed/typings.d.ts +1 -1
- package/file-uploader/_virtual/_tslib.js +3 -1
- package/file-uploader/createFileUploader.js +76 -76
- package/file-uploader/getFilesFromInput.js +24 -24
- package/file-uploader/index.cjs.js +102 -102
- package/file-uploader/typings.d.ts +6 -6
- package/footnote/createFootnote.d.ts +1 -1
- package/footnote/createFootnote.js +65 -65
- package/footnote/index.cjs.js +65 -67
- package/footnote/typings.d.ts +1 -1
- package/heading/constants.js +1 -1
- package/heading/createHeading.d.ts +1 -1
- package/heading/createHeading.js +45 -45
- package/heading/index.cjs.js +46 -48
- package/heading/typings.d.ts +1 -1
- package/highlight/createHighlight.d.ts +2 -1
- package/highlight/createHighlight.js +6 -4
- package/highlight/index.cjs.js +6 -6
- package/image/constants.js +4 -4
- package/image/createImage.js +195 -195
- package/image/getImageElementCommonProps.js +6 -6
- package/image/getImageFigureElementCommonProps.js +5 -5
- package/image/index.cjs.js +211 -213
- package/image/isHostingNotRequired.js +2 -2
- package/image/typings.d.ts +8 -8
- package/input-block/createInputBlock.js +37 -37
- package/input-block/index.cjs.js +37 -39
- package/input-widget/typings.d.ts +1 -1
- package/italic/createItalic.d.ts +2 -1
- package/italic/createItalic.js +6 -4
- package/italic/index.cjs.js +6 -6
- package/link/createLink.js +147 -147
- package/link/index.cjs.js +146 -148
- package/link/typings.d.ts +2 -2
- package/list/constants.js +4 -4
- package/list/createList.js +185 -185
- package/list/index.cjs.js +188 -190
- package/list/typings.d.ts +4 -4
- package/package.json +4 -4
- package/read-more/createReadMore.d.ts +1 -1
- package/read-more/createReadMore.js +51 -51
- package/read-more/index.cjs.js +50 -52
- package/strikethrough/createStrikethrough.d.ts +2 -1
- package/strikethrough/createStrikethrough.js +6 -4
- package/strikethrough/index.cjs.js +6 -6
- package/toggle-mark/createToggleMarkCreator.d.ts +4 -4
- package/toggle-mark/createToggleMarkCreator.js +36 -36
- package/toggle-mark/index.cjs.js +36 -38
- package/underline/createUnderline.d.ts +2 -1
- package/underline/createUnderline.js +6 -4
- package/underline/index.cjs.js +6 -6
package/list/index.cjs.js
CHANGED
|
@@ -1,199 +1,197 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var core = require('@quadrats/core');
|
|
6
4
|
|
|
7
|
-
const LIST_TYPES = {
|
|
8
|
-
ol: 'ol',
|
|
9
|
-
ul: 'ul',
|
|
10
|
-
li: 'li',
|
|
5
|
+
const LIST_TYPES = {
|
|
6
|
+
ol: 'ol',
|
|
7
|
+
ul: 'ul',
|
|
8
|
+
li: 'li',
|
|
11
9
|
};
|
|
12
10
|
|
|
13
|
-
function createList(options = {}) {
|
|
14
|
-
const types = Object.assign(Object.assign({}, LIST_TYPES), options.types);
|
|
15
|
-
const isListElement = (node) => [types.ol, types.ul].includes(node.type);
|
|
16
|
-
const isListItemElement = (node) => node.type === types.li;
|
|
17
|
-
const isSelectionInList = (editor, listTypeKey) => core.isNodesTypeIn(editor, [types[listTypeKey]]);
|
|
18
|
-
const getAboveListAndItem = (editor, options = {}) => {
|
|
19
|
-
const { at = editor.selection } = options;
|
|
20
|
-
/**
|
|
21
|
-
* (ul|ol) > li > p
|
|
22
|
-
*/
|
|
23
|
-
if (at && core.isNodesTypeIn(editor, [types.li])) {
|
|
24
|
-
const parentEntry = core.getAboveByTypes(editor, [types.li]) || core.getParent(editor, at);
|
|
25
|
-
if (parentEntry && isListItemElement(parentEntry[0])) {
|
|
26
|
-
const [, listItemPath] = parentEntry;
|
|
27
|
-
const parentOfListItemEntry = core.getParent(editor, listItemPath);
|
|
28
|
-
if (parentOfListItemEntry && isListElement(parentOfListItemEntry[0])) {
|
|
29
|
-
return {
|
|
30
|
-
list: parentOfListItemEntry,
|
|
31
|
-
listItem: parentEntry,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const unwrapList = (editor) => {
|
|
38
|
-
core.unwrapNodesByTypes(editor, [types.li]);
|
|
39
|
-
core.unwrapNodesByTypes(editor, [types.ol, types.ul], { split: true });
|
|
40
|
-
};
|
|
41
|
-
const toggleList = (editor, listTypeKey, defaultType = core.PARAGRAPH_TYPE) => {
|
|
42
|
-
if (!editor.selection) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const isActive = isSelectionInList(editor, listTypeKey);
|
|
46
|
-
unwrapList(editor);
|
|
47
|
-
core.Transforms.setNodes(editor, {
|
|
48
|
-
type: defaultType,
|
|
49
|
-
});
|
|
50
|
-
if (!isActive) {
|
|
51
|
-
core.wrapNodesWithUnhangRange(editor, { type: types[listTypeKey], children: [] });
|
|
52
|
-
const nodeEntries = core.getNodesByTypes(editor, [defaultType]);
|
|
53
|
-
const listItem = { type: types.li, children: [] };
|
|
54
|
-
for (const [, path] of nodeEntries) {
|
|
55
|
-
core.wrapNodesWithUnhangRange(editor, listItem, {
|
|
56
|
-
at: path,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const increaseListItemDepth = (editor, entries) => {
|
|
62
|
-
var _a, _b, _c, _d, _e;
|
|
63
|
-
const { list: [listNode], listItem: [, listItemPath], } = entries;
|
|
64
|
-
if (!core.isFirstChild(listItemPath)) {
|
|
65
|
-
const previousEntry = core.Editor.node(editor, core.Path.previous(listItemPath));
|
|
66
|
-
if (previousEntry) {
|
|
67
|
-
const [previousNode, previousPath] = previousEntry;
|
|
68
|
-
const lastNodeOfPreviousNode = ((_a = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _a !== void 0 ? _a : [])[((_b = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _b !== void 0 ? _b : []).length - 1];
|
|
69
|
-
/**
|
|
70
|
-
* Move list item next to the last node of previous node of list item.
|
|
71
|
-
*/
|
|
72
|
-
if (isListElement(lastNodeOfPreviousNode)) {
|
|
73
|
-
core.Transforms.moveNodes(editor, {
|
|
74
|
-
at: listItemPath,
|
|
75
|
-
to: [
|
|
76
|
-
...previousPath,
|
|
77
|
-
((_c = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _c !== void 0 ? _c : []).length - 1,
|
|
78
|
-
((_d = lastNodeOfPreviousNode === null || lastNodeOfPreviousNode === void 0 ? void 0 : lastNodeOfPreviousNode.children) !== null && _d !== void 0 ? _d : []).length,
|
|
79
|
-
],
|
|
80
|
-
});
|
|
81
|
-
/**
|
|
82
|
-
* Wrap list item by a new list and move the new list next to the last node of previous node.
|
|
83
|
-
*/
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
const newSubListElement = { type: listNode.type, children: [] };
|
|
87
|
-
core.Transforms.wrapNodes(editor, newSubListElement, { at: listItemPath });
|
|
88
|
-
core.Transforms.moveNodes(editor, {
|
|
89
|
-
at: listItemPath,
|
|
90
|
-
to: [...previousPath, ((_e = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _e !== void 0 ? _e : []).length],
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const decreaseListItemDepth = (editor, entries) => {
|
|
97
|
-
var _a, _b, _c;
|
|
98
|
-
const { list: [listNode, listPath], listItem: [listItemNode, listItemPath], } = entries;
|
|
99
|
-
const [listParentNode, listParentPath] = core.Editor.parent(editor, listPath);
|
|
100
|
-
/**
|
|
101
|
-
* Decreasable if parent of list is list item.
|
|
102
|
-
*/
|
|
103
|
-
if (!isListItemElement(listParentNode)) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const newListItemPath = core.Path.next(listParentPath);
|
|
107
|
-
const listItemIndex = listItemPath[listItemPath.length - 1];
|
|
108
|
-
const nextSiblingListItems = ((_a = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _a !== void 0 ? _a : []).slice(listItemIndex + 1, ((_b = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _b !== void 0 ? _b : []).length);
|
|
109
|
-
core.Transforms.moveNodes(editor, {
|
|
110
|
-
at: listItemPath,
|
|
111
|
-
to: newListItemPath,
|
|
112
|
-
});
|
|
113
|
-
/**
|
|
114
|
-
* After list item moved to parent list, if there are some sibling list items next to list item, move them to a new list in list item.
|
|
115
|
-
*/
|
|
116
|
-
if (nextSiblingListItems.length) {
|
|
117
|
-
const newSubListElement = { type: listNode.type, children: [] };
|
|
118
|
-
const newSubListPath = [...newListItemPath, ((_c = listItemNode === null || listItemNode === void 0 ? void 0 : listItemNode.children) !== null && _c !== void 0 ? _c : []).length];
|
|
119
|
-
core.Transforms.insertNodes(editor, newSubListElement, { at: newSubListPath });
|
|
120
|
-
nextSiblingListItems.forEach((_, index) => {
|
|
121
|
-
core.Transforms.moveNodes(editor, {
|
|
122
|
-
/**
|
|
123
|
-
* Path of each nextSiblingListItems is the same as listItemPath.
|
|
124
|
-
* Since each time list item moved, path of next list item will be unshifted.
|
|
125
|
-
*/
|
|
126
|
-
at: listItemPath,
|
|
127
|
-
to: [...newSubListPath, index],
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Remove the stale sublist if there are no previous sibling list items.
|
|
133
|
-
*/
|
|
134
|
-
if (listItemIndex <= 0) {
|
|
135
|
-
core.Transforms.removeNodes(editor, {
|
|
136
|
-
at: listPath,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
const decreaseListItemDepthOrUnwrapIfNeed = (editor, entries) => {
|
|
141
|
-
const { list: [, listPath], } = entries;
|
|
142
|
-
const [listParentNode] = core.Editor.parent(editor, listPath);
|
|
143
|
-
if (listParentNode.type !== types.li) {
|
|
144
|
-
unwrapList(editor);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
decreaseListItemDepth(editor, entries);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
return {
|
|
151
|
-
types,
|
|
152
|
-
isListElement,
|
|
153
|
-
isListItemElement,
|
|
154
|
-
isSelectionInList,
|
|
155
|
-
getAboveListAndItem,
|
|
156
|
-
unwrapList,
|
|
157
|
-
toggleList,
|
|
158
|
-
increaseListItemDepth,
|
|
159
|
-
decreaseListItemDepth,
|
|
160
|
-
decreaseListItemDepthOrUnwrapIfNeed,
|
|
161
|
-
with(editor) {
|
|
162
|
-
const { deleteBackward, insertBreak } = editor;
|
|
163
|
-
editor.deleteBackward = (unit) => {
|
|
164
|
-
const { selection } = editor;
|
|
165
|
-
if (selection && core.Range.isCollapsed(selection)) {
|
|
166
|
-
const entries = getAboveListAndItem(editor);
|
|
167
|
-
if (entries && core.isSelectionAtBlockEdge(editor) === 'start') {
|
|
168
|
-
decreaseListItemDepthOrUnwrapIfNeed(editor, entries);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
deleteBackward(unit);
|
|
173
|
-
};
|
|
174
|
-
editor.insertBreak = () => {
|
|
175
|
-
var _a;
|
|
176
|
-
const entries = getAboveListAndItem(editor);
|
|
177
|
-
if (entries) {
|
|
178
|
-
core.deleteSelectionFragmentIfExpanded(editor);
|
|
179
|
-
if (core.isAboveBlockEmpty(editor, { match: isListItemElement })) {
|
|
180
|
-
decreaseListItemDepthOrUnwrapIfNeed(editor, entries);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
core.Transforms.splitNodes(editor, {
|
|
184
|
-
at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.focus,
|
|
185
|
-
match: isListItemElement,
|
|
186
|
-
always: true,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
insertBreak();
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
return editor;
|
|
195
|
-
},
|
|
196
|
-
};
|
|
11
|
+
function createList(options = {}) {
|
|
12
|
+
const types = Object.assign(Object.assign({}, LIST_TYPES), options.types);
|
|
13
|
+
const isListElement = (node) => [types.ol, types.ul].includes(node.type);
|
|
14
|
+
const isListItemElement = (node) => node.type === types.li;
|
|
15
|
+
const isSelectionInList = (editor, listTypeKey) => core.isNodesTypeIn(editor, [types[listTypeKey]]);
|
|
16
|
+
const getAboveListAndItem = (editor, options = {}) => {
|
|
17
|
+
const { at = editor.selection } = options;
|
|
18
|
+
/**
|
|
19
|
+
* (ul|ol) > li > p
|
|
20
|
+
*/
|
|
21
|
+
if (at && core.isNodesTypeIn(editor, [types.li])) {
|
|
22
|
+
const parentEntry = core.getAboveByTypes(editor, [types.li]) || core.getParent(editor, at);
|
|
23
|
+
if (parentEntry && isListItemElement(parentEntry[0])) {
|
|
24
|
+
const [, listItemPath] = parentEntry;
|
|
25
|
+
const parentOfListItemEntry = core.getParent(editor, listItemPath);
|
|
26
|
+
if (parentOfListItemEntry && isListElement(parentOfListItemEntry[0])) {
|
|
27
|
+
return {
|
|
28
|
+
list: parentOfListItemEntry,
|
|
29
|
+
listItem: parentEntry,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const unwrapList = (editor) => {
|
|
36
|
+
core.unwrapNodesByTypes(editor, [types.li]);
|
|
37
|
+
core.unwrapNodesByTypes(editor, [types.ol, types.ul], { split: true });
|
|
38
|
+
};
|
|
39
|
+
const toggleList = (editor, listTypeKey, defaultType = core.PARAGRAPH_TYPE) => {
|
|
40
|
+
if (!editor.selection) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const isActive = isSelectionInList(editor, listTypeKey);
|
|
44
|
+
unwrapList(editor);
|
|
45
|
+
core.Transforms.setNodes(editor, {
|
|
46
|
+
type: defaultType,
|
|
47
|
+
});
|
|
48
|
+
if (!isActive) {
|
|
49
|
+
core.wrapNodesWithUnhangRange(editor, { type: types[listTypeKey], children: [] });
|
|
50
|
+
const nodeEntries = core.getNodesByTypes(editor, [defaultType]);
|
|
51
|
+
const listItem = { type: types.li, children: [] };
|
|
52
|
+
for (const [, path] of nodeEntries) {
|
|
53
|
+
core.wrapNodesWithUnhangRange(editor, listItem, {
|
|
54
|
+
at: path,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const increaseListItemDepth = (editor, entries) => {
|
|
60
|
+
var _a, _b, _c, _d, _e;
|
|
61
|
+
const { list: [listNode], listItem: [, listItemPath], } = entries;
|
|
62
|
+
if (!core.isFirstChild(listItemPath)) {
|
|
63
|
+
const previousEntry = core.Editor.node(editor, core.Path.previous(listItemPath));
|
|
64
|
+
if (previousEntry) {
|
|
65
|
+
const [previousNode, previousPath] = previousEntry;
|
|
66
|
+
const lastNodeOfPreviousNode = ((_a = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _a !== void 0 ? _a : [])[((_b = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _b !== void 0 ? _b : []).length - 1];
|
|
67
|
+
/**
|
|
68
|
+
* Move list item next to the last node of previous node of list item.
|
|
69
|
+
*/
|
|
70
|
+
if (isListElement(lastNodeOfPreviousNode)) {
|
|
71
|
+
core.Transforms.moveNodes(editor, {
|
|
72
|
+
at: listItemPath,
|
|
73
|
+
to: [
|
|
74
|
+
...previousPath,
|
|
75
|
+
((_c = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _c !== void 0 ? _c : []).length - 1,
|
|
76
|
+
((_d = lastNodeOfPreviousNode === null || lastNodeOfPreviousNode === void 0 ? void 0 : lastNodeOfPreviousNode.children) !== null && _d !== void 0 ? _d : []).length,
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Wrap list item by a new list and move the new list next to the last node of previous node.
|
|
81
|
+
*/
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const newSubListElement = { type: listNode.type, children: [] };
|
|
85
|
+
core.Transforms.wrapNodes(editor, newSubListElement, { at: listItemPath });
|
|
86
|
+
core.Transforms.moveNodes(editor, {
|
|
87
|
+
at: listItemPath,
|
|
88
|
+
to: [...previousPath, ((_e = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _e !== void 0 ? _e : []).length],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const decreaseListItemDepth = (editor, entries) => {
|
|
95
|
+
var _a, _b, _c;
|
|
96
|
+
const { list: [listNode, listPath], listItem: [listItemNode, listItemPath], } = entries;
|
|
97
|
+
const [listParentNode, listParentPath] = core.Editor.parent(editor, listPath);
|
|
98
|
+
/**
|
|
99
|
+
* Decreasable if parent of list is list item.
|
|
100
|
+
*/
|
|
101
|
+
if (!isListItemElement(listParentNode)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const newListItemPath = core.Path.next(listParentPath);
|
|
105
|
+
const listItemIndex = listItemPath[listItemPath.length - 1];
|
|
106
|
+
const nextSiblingListItems = ((_a = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _a !== void 0 ? _a : []).slice(listItemIndex + 1, ((_b = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _b !== void 0 ? _b : []).length);
|
|
107
|
+
core.Transforms.moveNodes(editor, {
|
|
108
|
+
at: listItemPath,
|
|
109
|
+
to: newListItemPath,
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* After list item moved to parent list, if there are some sibling list items next to list item, move them to a new list in list item.
|
|
113
|
+
*/
|
|
114
|
+
if (nextSiblingListItems.length) {
|
|
115
|
+
const newSubListElement = { type: listNode.type, children: [] };
|
|
116
|
+
const newSubListPath = [...newListItemPath, ((_c = listItemNode === null || listItemNode === void 0 ? void 0 : listItemNode.children) !== null && _c !== void 0 ? _c : []).length];
|
|
117
|
+
core.Transforms.insertNodes(editor, newSubListElement, { at: newSubListPath });
|
|
118
|
+
nextSiblingListItems.forEach((_, index) => {
|
|
119
|
+
core.Transforms.moveNodes(editor, {
|
|
120
|
+
/**
|
|
121
|
+
* Path of each nextSiblingListItems is the same as listItemPath.
|
|
122
|
+
* Since each time list item moved, path of next list item will be unshifted.
|
|
123
|
+
*/
|
|
124
|
+
at: listItemPath,
|
|
125
|
+
to: [...newSubListPath, index],
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Remove the stale sublist if there are no previous sibling list items.
|
|
131
|
+
*/
|
|
132
|
+
if (listItemIndex <= 0) {
|
|
133
|
+
core.Transforms.removeNodes(editor, {
|
|
134
|
+
at: listPath,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const decreaseListItemDepthOrUnwrapIfNeed = (editor, entries) => {
|
|
139
|
+
const { list: [, listPath], } = entries;
|
|
140
|
+
const [listParentNode] = core.Editor.parent(editor, listPath);
|
|
141
|
+
if (listParentNode.type !== types.li) {
|
|
142
|
+
unwrapList(editor);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
decreaseListItemDepth(editor, entries);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
types,
|
|
150
|
+
isListElement,
|
|
151
|
+
isListItemElement,
|
|
152
|
+
isSelectionInList,
|
|
153
|
+
getAboveListAndItem,
|
|
154
|
+
unwrapList,
|
|
155
|
+
toggleList,
|
|
156
|
+
increaseListItemDepth,
|
|
157
|
+
decreaseListItemDepth,
|
|
158
|
+
decreaseListItemDepthOrUnwrapIfNeed,
|
|
159
|
+
with(editor) {
|
|
160
|
+
const { deleteBackward, insertBreak } = editor;
|
|
161
|
+
editor.deleteBackward = (unit) => {
|
|
162
|
+
const { selection } = editor;
|
|
163
|
+
if (selection && core.Range.isCollapsed(selection)) {
|
|
164
|
+
const entries = getAboveListAndItem(editor);
|
|
165
|
+
if (entries && core.isSelectionAtBlockEdge(editor) === 'start') {
|
|
166
|
+
decreaseListItemDepthOrUnwrapIfNeed(editor, entries);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
deleteBackward(unit);
|
|
171
|
+
};
|
|
172
|
+
editor.insertBreak = () => {
|
|
173
|
+
var _a;
|
|
174
|
+
const entries = getAboveListAndItem(editor);
|
|
175
|
+
if (entries) {
|
|
176
|
+
core.deleteSelectionFragmentIfExpanded(editor);
|
|
177
|
+
if (core.isAboveBlockEmpty(editor, { match: isListItemElement })) {
|
|
178
|
+
decreaseListItemDepthOrUnwrapIfNeed(editor, entries);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
core.Transforms.splitNodes(editor, {
|
|
182
|
+
at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.focus,
|
|
183
|
+
match: isListItemElement,
|
|
184
|
+
always: true,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
insertBreak();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
return editor;
|
|
193
|
+
},
|
|
194
|
+
};
|
|
197
195
|
}
|
|
198
196
|
|
|
199
197
|
exports.LIST_TYPES = LIST_TYPES;
|
package/list/typings.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Editor, QuadratsElement, Location, Node, NodeEntry, Withable, WithElementType } from '@quadrats/core';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
2
|
+
export type ListRootTypeKey = 'ol' | 'ul';
|
|
3
|
+
export type ListItemTypeKey = 'li';
|
|
4
|
+
export type ListTypeKey = ListRootTypeKey | ListItemTypeKey;
|
|
5
|
+
export type ListTypes = Record<ListTypeKey, string>;
|
|
6
6
|
export interface ListElement extends QuadratsElement, WithElementType {
|
|
7
7
|
}
|
|
8
8
|
export interface ListAboveListAndItem {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadrats/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Rytass",
|
|
6
6
|
"homepage": "https://github.com/Quadrats/quadrats#readme",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"url": "https://github.com/Quadrats/quadrats/issues"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@quadrats/core": "^0.
|
|
22
|
-
"@quadrats/locales": "^0.
|
|
23
|
-
"@quadrats/utils": "^0.
|
|
21
|
+
"@quadrats/core": "^0.7.0",
|
|
22
|
+
"@quadrats/locales": "^0.7.0",
|
|
23
|
+
"@quadrats/utils": "^0.7.0"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { WithElementType } from '@quadrats/core';
|
|
2
2
|
import { ReadMore } from './typings';
|
|
3
|
-
export
|
|
3
|
+
export type CreateReadMoreOptions = Partial<WithElementType>;
|
|
4
4
|
export declare function createReadMore(options?: CreateReadMoreOptions): ReadMore;
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { Element, normalizeVoidElementChildren, normalizeOnlyAtRoot,
|
|
1
|
+
import { Element, normalizeVoidElementChildren, normalizeOnlyAtRoot, Path, Transforms, getNodesByTypes, deleteSelectionFragmentIfExpanded, createParagraphElement } from '@quadrats/core';
|
|
2
2
|
import { READ_MORE_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
|
-
function createReadMore(options = {}) {
|
|
5
|
-
const { type = READ_MORE_TYPE } = options;
|
|
6
|
-
const getReadMoresAtRoot = (editor) => getNodesByTypes(editor, [type], {
|
|
7
|
-
at: [],
|
|
8
|
-
mode: 'highest',
|
|
9
|
-
});
|
|
10
|
-
const createReadMoreElement = () => ({ type, children: [{ text: '' }] });
|
|
11
|
-
const insertReadMore = (editor) => {
|
|
12
|
-
deleteSelectionFragmentIfExpanded(editor);
|
|
13
|
-
const { selection } = editor;
|
|
14
|
-
if (!selection) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const [alreadyExistReadMore] = getReadMoresAtRoot(editor);
|
|
18
|
-
if (!alreadyExistReadMore && selection.focus) {
|
|
19
|
-
const at = [selection.focus.path[0] + 1];
|
|
20
|
-
Transforms.insertNodes(editor, [createReadMoreElement(), createParagraphElement()], {
|
|
21
|
-
at,
|
|
22
|
-
});
|
|
23
|
-
Transforms.select(editor, Path.next(at));
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
return {
|
|
27
|
-
type,
|
|
28
|
-
createReadMoreElement,
|
|
29
|
-
insertReadMore,
|
|
30
|
-
with(editor) {
|
|
31
|
-
const { isVoid, normalizeNode } = editor;
|
|
32
|
-
editor.isVoid = element => element.type === type || isVoid(element);
|
|
33
|
-
editor.normalizeNode = (entry) => {
|
|
34
|
-
const [node, path] = entry;
|
|
35
|
-
if (Element.isElement(node) && node.type === type) {
|
|
36
|
-
if (normalizeVoidElementChildren(editor, [node, path]) || normalizeOnlyAtRoot(editor, entry)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Only accept single read more element.
|
|
41
|
-
*/
|
|
42
|
-
for (const [, readMorePath] of getReadMoresAtRoot(editor)) {
|
|
43
|
-
if (Path.isAfter(path, readMorePath)) {
|
|
44
|
-
Transforms.removeNodes(editor, { at: path });
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
normalizeNode(entry);
|
|
50
|
-
};
|
|
51
|
-
return editor;
|
|
52
|
-
},
|
|
53
|
-
};
|
|
4
|
+
function createReadMore(options = {}) {
|
|
5
|
+
const { type = READ_MORE_TYPE } = options;
|
|
6
|
+
const getReadMoresAtRoot = (editor) => getNodesByTypes(editor, [type], {
|
|
7
|
+
at: [],
|
|
8
|
+
mode: 'highest',
|
|
9
|
+
});
|
|
10
|
+
const createReadMoreElement = () => ({ type, children: [{ text: '' }] });
|
|
11
|
+
const insertReadMore = (editor) => {
|
|
12
|
+
deleteSelectionFragmentIfExpanded(editor);
|
|
13
|
+
const { selection } = editor;
|
|
14
|
+
if (!selection) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const [alreadyExistReadMore] = getReadMoresAtRoot(editor);
|
|
18
|
+
if (!alreadyExistReadMore && selection.focus) {
|
|
19
|
+
const at = [selection.focus.path[0] + 1];
|
|
20
|
+
Transforms.insertNodes(editor, [createReadMoreElement(), createParagraphElement()], {
|
|
21
|
+
at,
|
|
22
|
+
});
|
|
23
|
+
Transforms.select(editor, Path.next(at));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
type,
|
|
28
|
+
createReadMoreElement,
|
|
29
|
+
insertReadMore,
|
|
30
|
+
with(editor) {
|
|
31
|
+
const { isVoid, normalizeNode } = editor;
|
|
32
|
+
editor.isVoid = element => element.type === type || isVoid(element);
|
|
33
|
+
editor.normalizeNode = (entry) => {
|
|
34
|
+
const [node, path] = entry;
|
|
35
|
+
if (Element.isElement(node) && node.type === type) {
|
|
36
|
+
if (normalizeVoidElementChildren(editor, [node, path]) || normalizeOnlyAtRoot(editor, entry)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Only accept single read more element.
|
|
41
|
+
*/
|
|
42
|
+
for (const [, readMorePath] of getReadMoresAtRoot(editor)) {
|
|
43
|
+
if (Path.isAfter(path, readMorePath)) {
|
|
44
|
+
Transforms.removeNodes(editor, { at: path });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
normalizeNode(entry);
|
|
50
|
+
};
|
|
51
|
+
return editor;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export { createReadMore };
|
package/read-more/index.cjs.js
CHANGED
|
@@ -1,61 +1,59 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var core = require('@quadrats/core');
|
|
6
4
|
|
|
7
5
|
const READ_MORE_TYPE = 'read_more';
|
|
8
6
|
|
|
9
|
-
function createReadMore(options = {}) {
|
|
10
|
-
const { type = READ_MORE_TYPE } = options;
|
|
11
|
-
const getReadMoresAtRoot = (editor) => core.getNodesByTypes(editor, [type], {
|
|
12
|
-
at: [],
|
|
13
|
-
mode: 'highest',
|
|
14
|
-
});
|
|
15
|
-
const createReadMoreElement = () => ({ type, children: [{ text: '' }] });
|
|
16
|
-
const insertReadMore = (editor) => {
|
|
17
|
-
core.deleteSelectionFragmentIfExpanded(editor);
|
|
18
|
-
const { selection } = editor;
|
|
19
|
-
if (!selection) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const [alreadyExistReadMore] = getReadMoresAtRoot(editor);
|
|
23
|
-
if (!alreadyExistReadMore && selection.focus) {
|
|
24
|
-
const at = [selection.focus.path[0] + 1];
|
|
25
|
-
core.Transforms.insertNodes(editor, [createReadMoreElement(), core.createParagraphElement()], {
|
|
26
|
-
at,
|
|
27
|
-
});
|
|
28
|
-
core.Transforms.select(editor, core.Path.next(at));
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
return {
|
|
32
|
-
type,
|
|
33
|
-
createReadMoreElement,
|
|
34
|
-
insertReadMore,
|
|
35
|
-
with(editor) {
|
|
36
|
-
const { isVoid, normalizeNode } = editor;
|
|
37
|
-
editor.isVoid = element => element.type === type || isVoid(element);
|
|
38
|
-
editor.normalizeNode = (entry) => {
|
|
39
|
-
const [node, path] = entry;
|
|
40
|
-
if (core.Element.isElement(node) && node.type === type) {
|
|
41
|
-
if (core.normalizeVoidElementChildren(editor, [node, path]) || core.normalizeOnlyAtRoot(editor, entry)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Only accept single read more element.
|
|
46
|
-
*/
|
|
47
|
-
for (const [, readMorePath] of getReadMoresAtRoot(editor)) {
|
|
48
|
-
if (core.Path.isAfter(path, readMorePath)) {
|
|
49
|
-
core.Transforms.removeNodes(editor, { at: path });
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
normalizeNode(entry);
|
|
55
|
-
};
|
|
56
|
-
return editor;
|
|
57
|
-
},
|
|
58
|
-
};
|
|
7
|
+
function createReadMore(options = {}) {
|
|
8
|
+
const { type = READ_MORE_TYPE } = options;
|
|
9
|
+
const getReadMoresAtRoot = (editor) => core.getNodesByTypes(editor, [type], {
|
|
10
|
+
at: [],
|
|
11
|
+
mode: 'highest',
|
|
12
|
+
});
|
|
13
|
+
const createReadMoreElement = () => ({ type, children: [{ text: '' }] });
|
|
14
|
+
const insertReadMore = (editor) => {
|
|
15
|
+
core.deleteSelectionFragmentIfExpanded(editor);
|
|
16
|
+
const { selection } = editor;
|
|
17
|
+
if (!selection) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const [alreadyExistReadMore] = getReadMoresAtRoot(editor);
|
|
21
|
+
if (!alreadyExistReadMore && selection.focus) {
|
|
22
|
+
const at = [selection.focus.path[0] + 1];
|
|
23
|
+
core.Transforms.insertNodes(editor, [createReadMoreElement(), core.createParagraphElement()], {
|
|
24
|
+
at,
|
|
25
|
+
});
|
|
26
|
+
core.Transforms.select(editor, core.Path.next(at));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
type,
|
|
31
|
+
createReadMoreElement,
|
|
32
|
+
insertReadMore,
|
|
33
|
+
with(editor) {
|
|
34
|
+
const { isVoid, normalizeNode } = editor;
|
|
35
|
+
editor.isVoid = element => element.type === type || isVoid(element);
|
|
36
|
+
editor.normalizeNode = (entry) => {
|
|
37
|
+
const [node, path] = entry;
|
|
38
|
+
if (core.Element.isElement(node) && node.type === type) {
|
|
39
|
+
if (core.normalizeVoidElementChildren(editor, [node, path]) || core.normalizeOnlyAtRoot(editor, entry)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Only accept single read more element.
|
|
44
|
+
*/
|
|
45
|
+
for (const [, readMorePath] of getReadMoresAtRoot(editor)) {
|
|
46
|
+
if (core.Path.isAfter(path, readMorePath)) {
|
|
47
|
+
core.Transforms.removeNodes(editor, { at: path });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
normalizeNode(entry);
|
|
53
|
+
};
|
|
54
|
+
return editor;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
exports.READ_MORE_TYPE = READ_MORE_TYPE;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Editor } from '@quadrats/core';
|
|
2
|
+
export declare function createStrikethrough<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
|