@makeswift/runtime 0.7.16 → 0.7.18
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/Box.cjs.js +1 -1
- package/dist/Box.es.js +1 -1
- package/dist/Button.cjs.js +2 -2
- package/dist/Button.es.js +2 -2
- package/dist/Carousel.cjs.js +3 -3
- package/dist/Carousel.es.js +3 -3
- package/dist/Countdown.cjs.js +3 -3
- package/dist/Countdown.es.js +3 -3
- package/dist/Divider.cjs.js +3 -3
- package/dist/Divider.es.js +3 -3
- package/dist/Embed.cjs.js +3 -3
- package/dist/Embed.es.js +3 -3
- package/dist/Form.cjs.js +1 -1
- package/dist/Form.es.js +1 -1
- package/dist/Image.cjs.js +3 -3
- package/dist/Image.es.js +3 -3
- package/dist/LiveProvider.cjs.js +3 -3
- package/dist/LiveProvider.es.js +4 -4
- package/dist/Navigation.cjs.js +3 -3
- package/dist/Navigation.es.js +3 -3
- package/dist/PreviewProvider.cjs.js +8 -8
- package/dist/PreviewProvider.cjs.js.map +1 -1
- package/dist/PreviewProvider.es.js +2 -2
- package/dist/ReadOnlyText.cjs.js +55 -55
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +3 -3
- package/dist/Root.cjs.js +3 -3
- package/dist/Root.es.js +3 -3
- package/dist/SocialLinks.cjs.js +2 -2
- package/dist/SocialLinks.es.js +2 -2
- package/dist/Text.cjs.js +4 -4
- package/dist/Text.es.js +4 -4
- package/dist/Video.cjs.js +3 -3
- package/dist/Video.es.js +3 -3
- package/dist/builder.cjs.js +2 -2
- package/dist/builder.es.js +2 -2
- package/dist/components.cjs.js +1 -1
- package/dist/components.es.js +1 -1
- package/dist/constants.cjs.js +14 -14
- package/dist/constants.cjs.js.map +1 -1
- package/dist/constants.es.js +1 -1
- package/dist/control-serialization.cjs.js +41 -41
- package/dist/control-serialization.cjs.js.map +1 -1
- package/dist/control-serialization.es.js +1 -1
- package/dist/controls.cjs.js +46 -44
- package/dist/controls.cjs.js.map +1 -1
- package/dist/controls.es.js +2 -2
- package/dist/{rich-text.cjs.js → descriptors.cjs.js} +476 -459
- package/dist/descriptors.cjs.js.map +1 -0
- package/dist/{rich-text.es.js → descriptors.es.js} +467 -452
- package/dist/descriptors.es.js.map +1 -0
- package/dist/index.cjs.js +242 -211
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs2.js +1 -1
- package/dist/index.cjs5.js +568 -37
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.cjs6.js +17 -697
- package/dist/index.cjs6.js.map +1 -1
- package/dist/index.cjs7.js +327 -0
- package/dist/index.cjs7.js.map +1 -0
- package/dist/index.es.js +46 -15
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js +1 -1
- package/dist/index.es5.js +558 -35
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es6.js +16 -692
- package/dist/index.es6.js.map +1 -1
- package/dist/index.es7.js +320 -0
- package/dist/index.es7.js.map +1 -0
- package/dist/introspection.cjs.js +22 -22
- package/dist/introspection.cjs.js.map +1 -1
- package/dist/introspection.es.js +1 -1
- package/dist/leaf.cjs.js +1 -0
- package/dist/leaf.cjs.js.map +1 -1
- package/dist/leaf.es.js +2 -2
- package/dist/main.cjs.js +1 -1
- package/dist/main.es.js +1 -1
- package/dist/next.cjs.js +3 -3
- package/dist/next.es.js +3 -3
- package/dist/prop-controllers.cjs.js +5 -5
- package/dist/prop-controllers.es.js +2 -2
- package/dist/react.cjs.js +3 -3
- package/dist/react.es.js +3 -3
- package/dist/slate.cjs.js +48 -0
- package/dist/slate.cjs.js.map +1 -0
- package/dist/slate.es.js +39 -0
- package/dist/slate.es.js.map +1 -0
- package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
- package/dist/types/src/controls/control.d.ts +3 -2
- package/dist/types/src/controls/control.d.ts.map +1 -1
- package/dist/types/src/controls/rich-text/dto-types.d.ts +1 -2
- package/dist/types/src/controls/rich-text/dto-types.d.ts.map +1 -1
- package/dist/types/src/controls/shape.d.ts +1 -1
- package/dist/types/src/controls/shape.d.ts.map +1 -1
- package/dist/types/src/controls/style.d.ts +17 -0
- package/dist/types/src/controls/style.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/descriptors.d.ts +1 -2
- package/dist/types/src/prop-controllers/descriptors.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/instances.d.ts +3 -3
- package/dist/types/src/prop-controllers/instances.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/control.d.ts +3 -2
- package/dist/types/src/runtimes/react/controls/control.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/style.d.ts +2 -2
- package/dist/types/src/runtimes/react/controls/style.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls.d.ts.map +1 -1
- package/package.json +5 -4
- package/slate.js +1 -0
- package/dist/rich-text.cjs.js.map +0 -1
- package/dist/rich-text.es.js.map +0 -1
package/dist/index.cjs2.js
CHANGED
|
@@ -33,7 +33,7 @@ var __objRest = (source, exclude) => {
|
|
|
33
33
|
var React = require("react");
|
|
34
34
|
var next = require("./index.cjs.js");
|
|
35
35
|
require("use-sync-external-store/shim");
|
|
36
|
-
require("./
|
|
36
|
+
require("./descriptors.cjs.js");
|
|
37
37
|
require("slate");
|
|
38
38
|
require("slate-react");
|
|
39
39
|
var css = require("@emotion/css");
|
package/dist/index.cjs5.js
CHANGED
|
@@ -1,40 +1,571 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var slate = require("slate");
|
|
22
|
+
var isHotkey = require("is-hotkey");
|
|
23
|
+
var descriptors = require("./descriptors.cjs.js");
|
|
14
24
|
require("slate-react");
|
|
15
|
-
require("./
|
|
16
|
-
require("
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
var leaf = require("./leaf.cjs.js");
|
|
26
|
+
var next = require("./index.cjs.js");
|
|
27
|
+
function _interopDefaultLegacy(e) {
|
|
28
|
+
return e && typeof e === "object" && "default" in e ? e : { "default": e };
|
|
29
|
+
}
|
|
30
|
+
var isHotkey__default = /* @__PURE__ */ _interopDefaultLegacy(isHotkey);
|
|
31
|
+
const LIST_ITEM_CHILD_POSITION = 0;
|
|
32
|
+
const LIST_ITEM_LIST_POSITION = 1;
|
|
33
|
+
const ElementUtils = {
|
|
34
|
+
isBlock(node) {
|
|
35
|
+
return slate.Element.isElement(node) && (slate.Element.isElementType(node, descriptors.BlockType.Paragraph) || slate.Element.isElementType(node, descriptors.BlockType.Heading1) || slate.Element.isElementType(node, descriptors.BlockType.Heading2) || slate.Element.isElementType(node, descriptors.BlockType.Heading3) || slate.Element.isElementType(node, descriptors.BlockType.Heading3) || slate.Element.isElementType(node, descriptors.BlockType.Heading4) || slate.Element.isElementType(node, descriptors.BlockType.Heading5) || slate.Element.isElementType(node, descriptors.BlockType.Heading6) || slate.Element.isElementType(node, descriptors.BlockType.BlockQuote) || slate.Element.isElementType(node, descriptors.BlockType.UnorderedList) || slate.Element.isElementType(node, descriptors.BlockType.OrderedList) || slate.Element.isElementType(node, descriptors.BlockType.ListItem) || slate.Element.isElementType(node, descriptors.BlockType.ListItemChild));
|
|
36
|
+
},
|
|
37
|
+
isInline(node) {
|
|
38
|
+
return slate.Element.isElement(node) && (slate.Element.isElementType(node, descriptors.InlineType.Link) || slate.Element.isElementType(node, descriptors.InlineType.Link) || slate.Element.isElementType(node, descriptors.InlineType.SubScript) || slate.Element.isElementType(node, descriptors.InlineType.SuperScript));
|
|
39
|
+
},
|
|
40
|
+
isConvertibleToListTextNode(node) {
|
|
41
|
+
return !this.isList(node) && !this.isListItem(node) && !this.isListItemChild(node);
|
|
42
|
+
},
|
|
43
|
+
isParagraph(node) {
|
|
44
|
+
return slate.Element.isElementType(node, descriptors.BlockType.Paragraph);
|
|
45
|
+
},
|
|
46
|
+
isList(node) {
|
|
47
|
+
return slate.Element.isElementType(node, descriptors.BlockType.OrderedList) || slate.Element.isElementType(node, descriptors.BlockType.UnorderedList);
|
|
48
|
+
},
|
|
49
|
+
isListItem(node) {
|
|
50
|
+
return slate.Element.isElementType(node, descriptors.BlockType.ListItem);
|
|
51
|
+
},
|
|
52
|
+
isListItemChild(node) {
|
|
53
|
+
return slate.Element.isElementType(node, descriptors.BlockType.ListItemChild);
|
|
54
|
+
},
|
|
55
|
+
createText() {
|
|
56
|
+
return { text: "" };
|
|
57
|
+
},
|
|
58
|
+
createParagraph() {
|
|
59
|
+
return {
|
|
60
|
+
children: [this.createText()],
|
|
61
|
+
type: descriptors.BlockType.Paragraph
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
createList(type = descriptors.BlockType.UnorderedList) {
|
|
65
|
+
return { children: [this.createText()], type };
|
|
66
|
+
},
|
|
67
|
+
createListItem() {
|
|
68
|
+
return {
|
|
69
|
+
children: [this.createListItemChild()],
|
|
70
|
+
type: descriptors.BlockType.ListItem
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
createListItemChild() {
|
|
74
|
+
return {
|
|
75
|
+
children: [this.createText()],
|
|
76
|
+
type: descriptors.BlockType.ListItemChild
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const EditorUtils = {
|
|
81
|
+
getFirstAncestorList(editor, path) {
|
|
82
|
+
const parentList = slate.Editor.above(editor, {
|
|
83
|
+
at: path,
|
|
84
|
+
match: (node) => ElementUtils.isList(node)
|
|
85
|
+
});
|
|
86
|
+
return parentList != null ? parentList : null;
|
|
87
|
+
},
|
|
88
|
+
getFirstAncestorListItem(editor, path) {
|
|
89
|
+
const parentListItem = slate.Editor.above(editor, {
|
|
90
|
+
at: path,
|
|
91
|
+
match: (node) => ElementUtils.isListItem(node)
|
|
92
|
+
});
|
|
93
|
+
return parentListItem != null ? parentListItem : null;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
function filterForSubtreeRoots(entries) {
|
|
97
|
+
return entries.filter(([, nodePath]) => !slate.Path.ancestors(nodePath).some((ancestor) => {
|
|
98
|
+
return entries.some(([, path]) => slate.Path.equals(path, ancestor));
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
const LocationUtils = {
|
|
102
|
+
getStartPath(location) {
|
|
103
|
+
if (slate.Range.isRange(location))
|
|
104
|
+
return slate.Range.start(location).path;
|
|
105
|
+
if (slate.Point.isPoint(location))
|
|
106
|
+
return location.path;
|
|
107
|
+
return location;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
function getSelectedListItems(editor) {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
if (!editor.selection)
|
|
113
|
+
return [];
|
|
114
|
+
const start = LocationUtils.getStartPath(editor.selection);
|
|
115
|
+
const listItems = slate.Editor.nodes(editor, {
|
|
116
|
+
at: editor.selection,
|
|
117
|
+
match: (node) => ElementUtils.isListItem(node)
|
|
118
|
+
});
|
|
119
|
+
const firstAncestorPath = (_b = (_a = EditorUtils.getFirstAncestorListItem(editor, start)) == null ? void 0 : _a[1]) != null ? _b : [];
|
|
120
|
+
return Array.from(listItems).filter((node) => slate.Path.isDescendant(start, node[1]) ? slate.Path.equals(node[1], firstAncestorPath) : !slate.Path.isAfter(start, node[1]));
|
|
121
|
+
}
|
|
122
|
+
function indentPath(editor, path) {
|
|
123
|
+
const parent = slate.Node.parent(editor, path);
|
|
124
|
+
if (!path || !slate.Path.hasPrevious(path) || !ElementUtils.isList(parent))
|
|
125
|
+
return;
|
|
126
|
+
const previosPath = slate.Path.previous(path);
|
|
127
|
+
const previousChildListPath = [...previosPath, LIST_ITEM_LIST_POSITION];
|
|
128
|
+
const previousHasChildList = slate.Node.has(editor, previousChildListPath);
|
|
129
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
130
|
+
if (!previousHasChildList) {
|
|
131
|
+
slate.Transforms.insertNodes(editor, ElementUtils.createList(parent.type), {
|
|
132
|
+
at: previousChildListPath
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const previousChildList = slate.Node.get(editor, previousChildListPath);
|
|
136
|
+
if (ElementUtils.isList(previousChildList)) {
|
|
137
|
+
const index = previousHasChildList ? previousChildList.children.length : 0;
|
|
138
|
+
slate.Transforms.moveNodes(editor, {
|
|
139
|
+
at: path,
|
|
140
|
+
to: [...previousChildListPath, index]
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function indent(editor) {
|
|
146
|
+
if (!editor.selection)
|
|
147
|
+
return;
|
|
148
|
+
const listItems = getSelectedListItems(editor);
|
|
149
|
+
const subRoots = filterForSubtreeRoots(listItems);
|
|
150
|
+
const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
|
|
151
|
+
refs.forEach((ref) => {
|
|
152
|
+
if (ref.current) {
|
|
153
|
+
indentPath(editor, ref.current);
|
|
154
|
+
}
|
|
155
|
+
ref.unref();
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function dedentPath(editor, listItemPath) {
|
|
159
|
+
const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
|
|
160
|
+
const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
|
|
161
|
+
if (!parentList || !listItemContainingParentList)
|
|
162
|
+
return;
|
|
163
|
+
const [parentListNode, parentListPath] = parentList;
|
|
164
|
+
const [_, listItemContainingParentListPath] = listItemContainingParentList;
|
|
165
|
+
const listItemPosition = listItemPath[listItemPath.length - 1];
|
|
166
|
+
const previousSiblings = parentListNode.children.slice(0, listItemPosition);
|
|
167
|
+
const nextSiblings = parentListNode.children.slice(listItemPosition + 1);
|
|
168
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
169
|
+
nextSiblings.forEach(() => {
|
|
170
|
+
const nextSiblingPath = [...parentListPath, listItemPosition + 1];
|
|
171
|
+
indentPath(editor, nextSiblingPath);
|
|
172
|
+
});
|
|
173
|
+
slate.Transforms.moveNodes(editor, {
|
|
174
|
+
at: listItemPath,
|
|
175
|
+
to: slate.Path.next(listItemContainingParentListPath)
|
|
176
|
+
});
|
|
177
|
+
if (previousSiblings.length === 0) {
|
|
178
|
+
slate.Transforms.removeNodes(editor, { at: parentListPath });
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
function dedent(editor) {
|
|
183
|
+
if (!editor.selection)
|
|
184
|
+
return;
|
|
185
|
+
const listItems = getSelectedListItems(editor);
|
|
186
|
+
const subRoots = filterForSubtreeRoots(listItems);
|
|
187
|
+
const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
|
|
188
|
+
refs.forEach((ref) => {
|
|
189
|
+
if (ref.current) {
|
|
190
|
+
dedentPath(editor, ref.current);
|
|
191
|
+
}
|
|
192
|
+
ref.unref();
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
function unwrapPath(editor, listItemPath) {
|
|
196
|
+
const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
|
|
197
|
+
const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
|
|
198
|
+
if (!parentList || listItemContainingParentList)
|
|
199
|
+
return;
|
|
200
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
201
|
+
const listItemTextPath = [...listItemPath, LIST_ITEM_CHILD_POSITION];
|
|
202
|
+
const listItemNestedListPath = [...listItemPath, LIST_ITEM_LIST_POSITION];
|
|
203
|
+
if (slate.Node.has(editor, listItemNestedListPath)) {
|
|
204
|
+
slate.Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath });
|
|
205
|
+
slate.Transforms.liftNodes(editor, { at: listItemNestedListPath });
|
|
206
|
+
slate.Transforms.liftNodes(editor, { at: slate.Path.next(listItemPath) });
|
|
207
|
+
}
|
|
208
|
+
if (slate.Node.has(editor, listItemTextPath)) {
|
|
209
|
+
slate.Transforms.setNodes(editor, { type: descriptors.BlockType.Paragraph }, {
|
|
210
|
+
at: listItemTextPath
|
|
211
|
+
});
|
|
212
|
+
slate.Transforms.liftNodes(editor, { at: listItemTextPath });
|
|
213
|
+
slate.Transforms.liftNodes(editor, { at: listItemPath });
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function unwrapList(editor) {
|
|
218
|
+
if (!editor.selection)
|
|
219
|
+
return;
|
|
220
|
+
const listItems = getSelectedListItems(editor);
|
|
221
|
+
const subRoots = filterForSubtreeRoots(listItems);
|
|
222
|
+
const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
|
|
223
|
+
refs.forEach((ref) => {
|
|
224
|
+
if (ref.current) {
|
|
225
|
+
unwrapPath(editor, ref.current);
|
|
226
|
+
}
|
|
227
|
+
ref.unref();
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function wrapList(editor, options = { type: descriptors.BlockType.UnorderedList }) {
|
|
231
|
+
if (!editor.selection)
|
|
232
|
+
return;
|
|
233
|
+
const nonListEntries = Array.from(slate.Editor.nodes(editor, {
|
|
234
|
+
at: editor.selection,
|
|
235
|
+
match: (node) => {
|
|
236
|
+
return slate.Element.isElement(node) && ElementUtils.isConvertibleToListTextNode(node);
|
|
237
|
+
}
|
|
238
|
+
}));
|
|
239
|
+
const refs = nonListEntries.map(([_, path]) => slate.Editor.pathRef(editor, path));
|
|
240
|
+
refs.forEach((ref) => {
|
|
241
|
+
const path = ref.current;
|
|
242
|
+
if (path) {
|
|
243
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
244
|
+
slate.Transforms.setNodes(editor, { type: descriptors.BlockType.ListItemChild }, {
|
|
245
|
+
at: path
|
|
246
|
+
});
|
|
247
|
+
slate.Transforms.wrapNodes(editor, ElementUtils.createListItem(), {
|
|
248
|
+
at: path
|
|
249
|
+
});
|
|
250
|
+
slate.Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {
|
|
251
|
+
at: path
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
ref.unref();
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
function toggleList(editor, options = { type: descriptors.BlockType.UnorderedList }) {
|
|
259
|
+
if (!editor.selection)
|
|
260
|
+
return;
|
|
261
|
+
const start = LocationUtils.getStartPath(editor.selection);
|
|
262
|
+
const ancestorPath = slate.Path.ancestors(start).at(1);
|
|
263
|
+
if (!ancestorPath || !slate.Node.has(editor, ancestorPath))
|
|
264
|
+
return;
|
|
265
|
+
const ancestor = slate.Node.get(editor, ancestorPath);
|
|
266
|
+
if (!ElementUtils.isList(ancestor)) {
|
|
267
|
+
return wrapList(editor, { type: options.type });
|
|
268
|
+
}
|
|
269
|
+
if (ancestor.type === options.type) {
|
|
270
|
+
unwrapList(editor);
|
|
271
|
+
} else {
|
|
272
|
+
slate.Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const List = {
|
|
276
|
+
unwrapList,
|
|
277
|
+
wrapList,
|
|
278
|
+
indent,
|
|
279
|
+
dedent,
|
|
280
|
+
toggleList
|
|
281
|
+
};
|
|
282
|
+
function onKeyDown(e, editor) {
|
|
283
|
+
if (!editor.selection || Array.from(slate.Editor.nodes(editor, { match: (node) => ElementUtils.isListItem(node) })).length === 0)
|
|
284
|
+
return;
|
|
285
|
+
if (isHotkey__default["default"]("shift+tab", e)) {
|
|
286
|
+
e.preventDefault();
|
|
287
|
+
List.dedent(editor);
|
|
288
|
+
}
|
|
289
|
+
if (isHotkey__default["default"]("tab", e)) {
|
|
290
|
+
e.preventDefault();
|
|
291
|
+
List.indent(editor);
|
|
292
|
+
}
|
|
293
|
+
if (isHotkey__default["default"]("backspace", e)) {
|
|
294
|
+
if (!editor.selection)
|
|
295
|
+
return;
|
|
296
|
+
if (slate.Range.isExpanded(editor.selection))
|
|
297
|
+
return;
|
|
298
|
+
const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
|
|
299
|
+
if (editor.selection.anchor.offset === 0 && listItem) {
|
|
300
|
+
e.preventDefault();
|
|
301
|
+
const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
|
|
302
|
+
const list = EditorUtils.getFirstAncestorList(editor, listItem[1]);
|
|
303
|
+
if (parentListItem) {
|
|
304
|
+
List.dedent(editor);
|
|
305
|
+
} else if (list) {
|
|
306
|
+
List.unwrapList(editor);
|
|
307
|
+
}
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (isHotkey__default["default"]("enter", e)) {
|
|
312
|
+
e.preventDefault();
|
|
313
|
+
if (!editor.selection)
|
|
314
|
+
return;
|
|
315
|
+
if (slate.Range.isExpanded(editor.selection)) {
|
|
316
|
+
slate.Transforms.delete(editor);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
|
|
320
|
+
if (editor.selection.anchor.offset === 0 && listItem && slate.Editor.string(editor, listItem[1]) === "") {
|
|
321
|
+
const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
|
|
322
|
+
if (parentListItem) {
|
|
323
|
+
List.dedent(editor);
|
|
324
|
+
} else {
|
|
325
|
+
List.unwrapList(editor);
|
|
326
|
+
}
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
slate.Transforms.splitNodes(editor, {
|
|
330
|
+
at: editor.selection,
|
|
331
|
+
always: true,
|
|
332
|
+
match: (node) => ElementUtils.isListItem(node)
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (isHotkey__default["default"]("shift+enter", e)) {
|
|
336
|
+
e.preventDefault();
|
|
337
|
+
editor.insertText("\n");
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function withList(editor) {
|
|
341
|
+
const { normalizeNode } = editor;
|
|
342
|
+
editor.normalizeNode = (entry) => {
|
|
343
|
+
const [normalizationNode, normalizationPath] = entry;
|
|
344
|
+
if (ElementUtils.isListItem(normalizationNode)) {
|
|
345
|
+
const pathToListItemText = [...normalizationPath, LIST_ITEM_CHILD_POSITION];
|
|
346
|
+
if (slate.Node.has(editor, pathToListItemText)) {
|
|
347
|
+
const nodeInListItemTextPosition = slate.Node.get(editor, pathToListItemText);
|
|
348
|
+
if (ElementUtils.isParagraph(nodeInListItemTextPosition)) {
|
|
349
|
+
slate.Transforms.setNodes(editor, { type: descriptors.BlockType.ListItemChild }, {
|
|
350
|
+
at: pathToListItemText
|
|
351
|
+
});
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
slate.Transforms.insertNodes(editor, ElementUtils.createListItem(), {
|
|
356
|
+
at: pathToListItemText
|
|
357
|
+
});
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (!slate.Text.isText(normalizationNode)) {
|
|
362
|
+
const mergeableChildren = Array.from(slate.Node.children(editor, normalizationPath)).map((child, index, children) => {
|
|
363
|
+
const potentialNodeToBeMerged = children.at(index + 1);
|
|
364
|
+
if (!potentialNodeToBeMerged || !ElementUtils.isList(potentialNodeToBeMerged[0]) || !ElementUtils.isList(child[0]) || potentialNodeToBeMerged[0].type !== child[0].type) {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
return [
|
|
368
|
+
slate.Editor.pathRef(editor, child[1]),
|
|
369
|
+
slate.Editor.pathRef(editor, potentialNodeToBeMerged[1])
|
|
370
|
+
];
|
|
371
|
+
}).filter((mergeableNodes) => Boolean(mergeableNodes));
|
|
372
|
+
if (mergeableChildren.length !== 0) {
|
|
373
|
+
mergeableChildren.reverse().forEach(([nodePathRef, nodeToBeMergedPathRef]) => {
|
|
374
|
+
const nodePath = nodePathRef.current;
|
|
375
|
+
const nodeToBeMergedPath = nodeToBeMergedPathRef.current;
|
|
376
|
+
if (nodePath == null || nodeToBeMergedPath == null)
|
|
377
|
+
return;
|
|
378
|
+
const nodeChildren = Array.from(slate.Node.children(editor, nodePath));
|
|
379
|
+
const childrenToBeMerged = Array.from(slate.Node.children(editor, nodeToBeMergedPath));
|
|
380
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
381
|
+
childrenToBeMerged.forEach(([_, childPath], index) => {
|
|
382
|
+
slate.Transforms.moveNodes(editor, {
|
|
383
|
+
at: childPath,
|
|
384
|
+
to: [...nodePath, nodeChildren.length + index]
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
slate.Transforms.removeNodes(editor, { at: nodeToBeMergedPath });
|
|
388
|
+
});
|
|
389
|
+
nodePathRef.unref();
|
|
390
|
+
nodeToBeMergedPathRef.unref();
|
|
391
|
+
});
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
normalizeNode(entry);
|
|
396
|
+
};
|
|
397
|
+
return editor;
|
|
398
|
+
}
|
|
399
|
+
function clearActiveTypographyStyle(editor) {
|
|
400
|
+
if (!editor.selection)
|
|
401
|
+
return;
|
|
402
|
+
const textNodes = slate.Editor.nodes(editor, {
|
|
403
|
+
at: editor.selection,
|
|
404
|
+
match: (node) => slate.Text.isText(node)
|
|
405
|
+
});
|
|
406
|
+
for (const [node, path] of textNodes) {
|
|
407
|
+
if (slate.Text.isText(node)) {
|
|
408
|
+
const typography = __spreadProps(__spreadValues({}, node.typography), {
|
|
409
|
+
style: []
|
|
410
|
+
});
|
|
411
|
+
slate.Transforms.setNodes(editor, {
|
|
412
|
+
typography
|
|
413
|
+
}, { at: path });
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function clearDeviceActiveTypography(editor, currentDeviceId) {
|
|
418
|
+
var _a, _b;
|
|
419
|
+
if (!editor.selection)
|
|
420
|
+
return;
|
|
421
|
+
const textNodes = slate.Editor.nodes(editor, {
|
|
422
|
+
at: editor.selection,
|
|
423
|
+
match: (node) => slate.Text.isText(node)
|
|
424
|
+
});
|
|
425
|
+
for (const [node, path] of textNodes) {
|
|
426
|
+
if (slate.Text.isText(node)) {
|
|
427
|
+
const typography = __spreadProps(__spreadValues({}, node.typography), {
|
|
428
|
+
style: (_b = (_a = node == null ? void 0 : node.typography) == null ? void 0 : _a.style.filter(({ deviceId }) => deviceId !== currentDeviceId)) != null ? _b : []
|
|
429
|
+
});
|
|
430
|
+
slate.Transforms.setNodes(editor, {
|
|
431
|
+
typography
|
|
432
|
+
}, { at: path });
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
function detachActiveTypography(editor, value) {
|
|
437
|
+
if (!editor.selection)
|
|
438
|
+
return;
|
|
439
|
+
const textNodes = Array.from(slate.Editor.nodes(editor, {
|
|
440
|
+
at: editor.selection,
|
|
441
|
+
match: (node) => slate.Text.isText(node)
|
|
442
|
+
}));
|
|
443
|
+
textNodes.forEach(([node, path]) => {
|
|
444
|
+
if (slate.Text.isText(node)) {
|
|
445
|
+
slate.Transforms.setNodes(editor, {
|
|
446
|
+
typography: {
|
|
447
|
+
style: value
|
|
448
|
+
}
|
|
449
|
+
}, { at: path });
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
function setActiveTypographyId(editor, id) {
|
|
454
|
+
slate.Transforms.setNodes(editor, {
|
|
455
|
+
typography: {
|
|
456
|
+
id,
|
|
457
|
+
style: []
|
|
458
|
+
}
|
|
459
|
+
}, {
|
|
460
|
+
match: (node) => slate.Text.isText(node)
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
function setActiveTypographyStyle(editor, deviceId, prop, value) {
|
|
464
|
+
var _a, _b;
|
|
465
|
+
if (!editor.selection)
|
|
466
|
+
return;
|
|
467
|
+
const textNodes = slate.Editor.nodes(editor, {
|
|
468
|
+
at: editor.selection,
|
|
469
|
+
match: (node) => slate.Text.isText(node)
|
|
470
|
+
});
|
|
471
|
+
for (const [node, path] of textNodes) {
|
|
472
|
+
if (slate.Text.isText(node)) {
|
|
473
|
+
const deviceOverrides = (_b = (_a = node == null ? void 0 : node.typography) == null ? void 0 : _a.style.filter(leaf.isDeviceOverride)) != null ? _b : [];
|
|
474
|
+
const deviceStyle = next.findDeviceOverride(deviceOverrides, deviceId, (v) => v) || { value: {} };
|
|
475
|
+
const nextDeviceStyle = {
|
|
476
|
+
deviceId,
|
|
477
|
+
value: __spreadProps(__spreadValues({}, deviceStyle.value), { [prop]: value })
|
|
478
|
+
};
|
|
479
|
+
const nextTypography = __spreadProps(__spreadValues({}, node.typography), {
|
|
480
|
+
style: [...deviceOverrides.filter((v) => v.deviceId !== deviceId), nextDeviceStyle]
|
|
481
|
+
});
|
|
482
|
+
slate.Transforms.setNodes(editor, {
|
|
483
|
+
typography: nextTypography
|
|
484
|
+
}, { at: path });
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
const Typography = {
|
|
489
|
+
setActiveTypographyId,
|
|
490
|
+
setActiveTypographyStyle,
|
|
491
|
+
clearActiveTypographyStyle,
|
|
492
|
+
clearDeviceActiveTypography,
|
|
493
|
+
detachActiveTypography
|
|
494
|
+
};
|
|
495
|
+
function withTypography(editor) {
|
|
496
|
+
const { normalizeNode } = editor;
|
|
497
|
+
editor.normalizeNode = (entry) => {
|
|
498
|
+
var _a, _b;
|
|
499
|
+
const [normalizationNode, normalizationPath] = entry;
|
|
500
|
+
if (slate.Text.isText(normalizationNode) && ((_a = normalizationNode == null ? void 0 : normalizationNode.typography) == null ? void 0 : _a.id) == null && ((_b = normalizationNode == null ? void 0 : normalizationNode.typography) == null ? void 0 : _b.style.length) === 0) {
|
|
501
|
+
slate.Transforms.unsetNodes(editor, "typography", { at: normalizationPath });
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
normalizeNode(entry);
|
|
505
|
+
};
|
|
506
|
+
return editor;
|
|
507
|
+
}
|
|
508
|
+
function setBlockKeyForDevice(editor, deviceId, key, value) {
|
|
509
|
+
var _a;
|
|
510
|
+
if (!editor.selection)
|
|
511
|
+
return;
|
|
512
|
+
const rootElements = slate.Editor.nodes(editor, {
|
|
513
|
+
match: (_, path) => path.length === 1,
|
|
514
|
+
at: slate.Editor.unhangRange(editor, editor.selection)
|
|
515
|
+
});
|
|
516
|
+
for (const [node, path] of rootElements) {
|
|
517
|
+
if (ElementUtils.isBlock(node)) {
|
|
518
|
+
const deviceValues = (_a = node[key]) != null ? _a : [];
|
|
519
|
+
const currentDeviceValue = next.findDeviceOverride(deviceValues, deviceId, (v) => v);
|
|
520
|
+
const nextDeviceValue = __spreadProps(__spreadValues({}, currentDeviceValue), {
|
|
521
|
+
deviceId,
|
|
522
|
+
value
|
|
523
|
+
});
|
|
524
|
+
slate.Transforms.setNodes(editor, {
|
|
525
|
+
[key]: [...deviceValues.filter((v) => v.deviceId !== deviceId), nextDeviceValue]
|
|
526
|
+
}, { at: path });
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function clearBlockKeyForDevice(editor, deviceId, key) {
|
|
531
|
+
var _a;
|
|
532
|
+
if (!editor.selection)
|
|
533
|
+
return;
|
|
534
|
+
const rootElements = slate.Editor.nodes(editor, {
|
|
535
|
+
match: (_, path) => path.length === 1,
|
|
536
|
+
at: slate.Editor.unhangRange(editor, editor.selection)
|
|
537
|
+
});
|
|
538
|
+
for (const [node, path] of rootElements) {
|
|
539
|
+
if (ElementUtils.isBlock(node)) {
|
|
540
|
+
const deviceOverrides = (_a = node[key]) != null ? _a : [];
|
|
541
|
+
slate.Transforms.setNodes(editor, {
|
|
542
|
+
[key]: deviceOverrides.filter((v) => v.deviceId !== deviceId)
|
|
543
|
+
}, { at: path });
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
const Block = {
|
|
548
|
+
setBlockKeyForDevice,
|
|
549
|
+
clearBlockKeyForDevice
|
|
550
|
+
};
|
|
551
|
+
function withBlock(editor) {
|
|
552
|
+
const { normalizeNode } = editor;
|
|
553
|
+
editor.normalizeNode = (entry) => {
|
|
554
|
+
var _a;
|
|
555
|
+
const [normalizationNode, normalizationPath] = entry;
|
|
556
|
+
if (ElementUtils.isBlock(normalizationNode) && ((_a = normalizationNode == null ? void 0 : normalizationNode.textAlign) == null ? void 0 : _a.length) == 0) {
|
|
557
|
+
slate.Transforms.unsetNodes(editor, "textAlign", { at: normalizationPath });
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
normalizeNode(entry);
|
|
561
|
+
};
|
|
562
|
+
return editor;
|
|
563
|
+
}
|
|
564
|
+
exports.Block = Block;
|
|
565
|
+
exports.List = List;
|
|
566
|
+
exports.Typography = Typography;
|
|
567
|
+
exports.onKeyDown = onKeyDown;
|
|
568
|
+
exports.withBlock = withBlock;
|
|
569
|
+
exports.withList = withList;
|
|
570
|
+
exports.withTypography = withTypography;
|
|
40
571
|
//# sourceMappingURL=index.cjs5.js.map
|