@makeswift/runtime 0.7.15 → 0.7.17
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/LiveProvider.es.js +1 -1
- package/dist/PreviewProvider.es.js +1 -1
- package/dist/Text.cjs.js +1 -1
- package/dist/Text.es.js +1 -1
- package/dist/controls.es.js +1 -1
- package/dist/index.cjs.js +23 -17
- package/dist/index.cjs.js.map +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 +23 -17
- package/dist/index.es.js.map +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/leaf.cjs.js +1 -0
- package/dist/leaf.cjs.js.map +1 -1
- package/dist/leaf.es.js +2 -2
- package/dist/rich-text.cjs.js +76 -49
- package/dist/rich-text.cjs.js.map +1 -1
- package/dist/rich-text.es.js +77 -50
- package/dist/rich-text.es.js.map +1 -1
- 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/controls/control.d.ts +4 -3
- package/dist/types/src/controls/control.d.ts.map +1 -1
- package/dist/types/src/controls/list.d.ts +1 -1
- package/dist/types/src/controls/list.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/rich-text/rich-text.d.ts +1 -1
- package/dist/types/src/controls/rich-text/rich-text.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/slot.d.ts +1 -1
- package/dist/types/src/controls/slot.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/package.json +5 -4
- package/slate.js +1 -0
package/dist/index.cjs6.js
CHANGED
|
@@ -1,63 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
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 __objRest = (source, exclude) => {
|
|
22
|
-
var target = {};
|
|
23
|
-
for (var prop in source)
|
|
24
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
if (source != null && __getOwnPropSymbols)
|
|
27
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
}
|
|
31
|
-
return target;
|
|
32
|
-
};
|
|
33
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
34
|
-
var
|
|
35
|
-
var slate = require("slate");
|
|
36
|
-
var slateReact = require("slate-react");
|
|
37
|
-
var css = require("@emotion/css");
|
|
38
|
-
var boxModels = require("./box-models.cjs.js");
|
|
39
|
-
var richText = require("./rich-text.cjs.js");
|
|
40
|
-
var leaf = require("./leaf.cjs.js");
|
|
41
|
-
var next = require("./index.cjs.js");
|
|
42
|
-
var jsxRuntime = require("react/jsx-runtime");
|
|
43
|
-
var index = require("./index.cjs3.js");
|
|
44
|
-
var isHotkey = require("is-hotkey");
|
|
45
|
-
require("use-sync-external-store/shim");
|
|
46
|
-
require("@emotion/serialize");
|
|
47
|
-
require("@emotion/utils");
|
|
48
|
-
require("css-box-model");
|
|
49
|
-
require("./actions.cjs.js");
|
|
50
|
-
require("./introspection.cjs.js");
|
|
51
|
-
require("use-sync-external-store/shim/with-selector");
|
|
3
|
+
var Text = require("./Text.cjs.js");
|
|
52
4
|
require("next/dynamic");
|
|
5
|
+
require("react");
|
|
6
|
+
require("./index.cjs.js");
|
|
7
|
+
require("use-sync-external-store/shim/with-selector");
|
|
53
8
|
require("./constants.cjs.js");
|
|
54
9
|
require("redux");
|
|
55
10
|
require("redux-thunk");
|
|
11
|
+
require("./actions.cjs.js");
|
|
12
|
+
require("./rich-text.cjs.js");
|
|
13
|
+
require("slate");
|
|
14
|
+
require("slate-react");
|
|
15
|
+
require("./introspection.cjs.js");
|
|
16
|
+
require("@emotion/css");
|
|
17
|
+
require("@emotion/serialize");
|
|
18
|
+
require("@emotion/utils");
|
|
19
|
+
require("react/jsx-runtime");
|
|
56
20
|
require("./text-input.cjs.js");
|
|
57
21
|
require("./combobox.cjs.js");
|
|
22
|
+
require("use-sync-external-store/shim");
|
|
58
23
|
require("./types.cjs.js");
|
|
59
24
|
require("color");
|
|
60
25
|
require("scroll-into-view-if-needed");
|
|
26
|
+
require("./box-models.cjs.js");
|
|
27
|
+
require("css-box-model");
|
|
61
28
|
require("react-dom");
|
|
62
29
|
require("html-react-parser");
|
|
63
30
|
require("next/head");
|
|
@@ -69,652 +36,5 @@ require("http-proxy");
|
|
|
69
36
|
require("set-cookie-parser");
|
|
70
37
|
require("uuid");
|
|
71
38
|
require("corporate-ipsum");
|
|
72
|
-
|
|
73
|
-
function _interopDefaultLegacy(e) {
|
|
74
|
-
return e && typeof e === "object" && "default" in e ? e : { "default": e };
|
|
75
|
-
}
|
|
76
|
-
var isHotkey__default = /* @__PURE__ */ _interopDefaultLegacy(isHotkey);
|
|
77
|
-
function BlockElement({
|
|
78
|
-
element,
|
|
79
|
-
attributes,
|
|
80
|
-
children
|
|
81
|
-
}) {
|
|
82
|
-
const blockStyles = [next.useStyle({
|
|
83
|
-
margin: 0
|
|
84
|
-
}), next.useStyle(next.responsiveStyle([element.textAlign], ([textAlign = "left"]) => ({
|
|
85
|
-
textAlign
|
|
86
|
-
})))];
|
|
87
|
-
switch (element.type) {
|
|
88
|
-
case richText.BlockType.Paragraph:
|
|
89
|
-
return /* @__PURE__ */ jsxRuntime.jsx("p", __spreadProps(__spreadValues({}, attributes), {
|
|
90
|
-
className: css.cx(...blockStyles),
|
|
91
|
-
children
|
|
92
|
-
}));
|
|
93
|
-
case richText.BlockType.Heading1:
|
|
94
|
-
return /* @__PURE__ */ jsxRuntime.jsx("h1", __spreadProps(__spreadValues({}, attributes), {
|
|
95
|
-
className: css.cx(...blockStyles),
|
|
96
|
-
children
|
|
97
|
-
}));
|
|
98
|
-
case richText.BlockType.Heading2:
|
|
99
|
-
return /* @__PURE__ */ jsxRuntime.jsx("h2", __spreadProps(__spreadValues({}, attributes), {
|
|
100
|
-
className: css.cx(...blockStyles),
|
|
101
|
-
children
|
|
102
|
-
}));
|
|
103
|
-
case richText.BlockType.Heading3:
|
|
104
|
-
return /* @__PURE__ */ jsxRuntime.jsx("h3", __spreadProps(__spreadValues({}, attributes), {
|
|
105
|
-
className: css.cx(...blockStyles),
|
|
106
|
-
children
|
|
107
|
-
}));
|
|
108
|
-
case richText.BlockType.Heading4:
|
|
109
|
-
return /* @__PURE__ */ jsxRuntime.jsx("h4", __spreadProps(__spreadValues({}, attributes), {
|
|
110
|
-
className: css.cx(...blockStyles),
|
|
111
|
-
children
|
|
112
|
-
}));
|
|
113
|
-
case richText.BlockType.Heading5:
|
|
114
|
-
return /* @__PURE__ */ jsxRuntime.jsx("h5", __spreadProps(__spreadValues({}, attributes), {
|
|
115
|
-
className: css.cx(...blockStyles),
|
|
116
|
-
children
|
|
117
|
-
}));
|
|
118
|
-
case richText.BlockType.Heading6:
|
|
119
|
-
return /* @__PURE__ */ jsxRuntime.jsx("h6", __spreadProps(__spreadValues({}, attributes), {
|
|
120
|
-
className: css.cx(...blockStyles),
|
|
121
|
-
children
|
|
122
|
-
}));
|
|
123
|
-
case richText.BlockType.BlockQuote:
|
|
124
|
-
return /* @__PURE__ */ jsxRuntime.jsx("blockquote", __spreadProps(__spreadValues({}, attributes), {
|
|
125
|
-
className: css.cx(...blockStyles, next.useStyle({
|
|
126
|
-
padding: "0.5em 10px",
|
|
127
|
-
fontSize: "1.25em",
|
|
128
|
-
fontWeight: "300",
|
|
129
|
-
borderLeft: "5px solid rgba(0, 0, 0, 0.1)"
|
|
130
|
-
})),
|
|
131
|
-
children
|
|
132
|
-
}));
|
|
133
|
-
case richText.BlockType.OrderedList:
|
|
134
|
-
return /* @__PURE__ */ jsxRuntime.jsx("ol", __spreadProps(__spreadValues({}, attributes), {
|
|
135
|
-
className: css.cx(...blockStyles),
|
|
136
|
-
style: {
|
|
137
|
-
listStylePosition: "inside"
|
|
138
|
-
},
|
|
139
|
-
children
|
|
140
|
-
}));
|
|
141
|
-
case richText.BlockType.UnorderedList:
|
|
142
|
-
return /* @__PURE__ */ jsxRuntime.jsx("ul", __spreadProps(__spreadValues({}, attributes), {
|
|
143
|
-
className: css.cx(...blockStyles),
|
|
144
|
-
style: {
|
|
145
|
-
listStylePosition: "inside"
|
|
146
|
-
},
|
|
147
|
-
children
|
|
148
|
-
}));
|
|
149
|
-
case richText.BlockType.ListItem:
|
|
150
|
-
return /* @__PURE__ */ jsxRuntime.jsx("li", __spreadProps(__spreadValues({}, attributes), {
|
|
151
|
-
className: css.cx(...blockStyles),
|
|
152
|
-
children
|
|
153
|
-
}));
|
|
154
|
-
case richText.BlockType.ListItemChild:
|
|
155
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, attributes), {
|
|
156
|
-
className: css.cx(...blockStyles),
|
|
157
|
-
children
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function StyledLink(_a) {
|
|
162
|
-
var _b = _a, {
|
|
163
|
-
className
|
|
164
|
-
} = _b, restOfProps = __objRest(_b, [
|
|
165
|
-
"className"
|
|
166
|
-
]);
|
|
167
|
-
return /* @__PURE__ */ jsxRuntime.jsx(index.Link, __spreadProps(__spreadValues({}, restOfProps), {
|
|
168
|
-
className: css.cx(next.useStyle({
|
|
169
|
-
textDecoration: "none"
|
|
170
|
-
}), className)
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
173
|
-
function InlineElement({
|
|
174
|
-
element,
|
|
175
|
-
attributes,
|
|
176
|
-
children
|
|
177
|
-
}) {
|
|
178
|
-
switch (element.type) {
|
|
179
|
-
case richText.InlineType.Code:
|
|
180
|
-
return /* @__PURE__ */ jsxRuntime.jsx("code", __spreadProps(__spreadValues({}, attributes), {
|
|
181
|
-
children
|
|
182
|
-
}));
|
|
183
|
-
case richText.InlineType.SuperScript:
|
|
184
|
-
return /* @__PURE__ */ jsxRuntime.jsx("sup", __spreadProps(__spreadValues({}, attributes), {
|
|
185
|
-
children
|
|
186
|
-
}));
|
|
187
|
-
case richText.InlineType.SubScript:
|
|
188
|
-
return /* @__PURE__ */ jsxRuntime.jsx("sub", __spreadProps(__spreadValues({}, attributes), {
|
|
189
|
-
children
|
|
190
|
-
}));
|
|
191
|
-
case richText.InlineType.Link:
|
|
192
|
-
return /* @__PURE__ */ jsxRuntime.jsx(StyledLink, __spreadProps(__spreadValues({}, attributes), {
|
|
193
|
-
link: element.link,
|
|
194
|
-
children
|
|
195
|
-
}));
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function Element(_c) {
|
|
199
|
-
var _d = _c, {
|
|
200
|
-
element
|
|
201
|
-
} = _d, props = __objRest(_d, [
|
|
202
|
-
"element"
|
|
203
|
-
]);
|
|
204
|
-
switch (element.type) {
|
|
205
|
-
case richText.InlineType.Code:
|
|
206
|
-
case richText.InlineType.SuperScript:
|
|
207
|
-
case richText.InlineType.SubScript:
|
|
208
|
-
case richText.InlineType.Link:
|
|
209
|
-
return /* @__PURE__ */ jsxRuntime.jsx(InlineElement, __spreadValues({
|
|
210
|
-
element
|
|
211
|
-
}, props));
|
|
212
|
-
case richText.BlockType.Paragraph:
|
|
213
|
-
case richText.BlockType.Heading1:
|
|
214
|
-
case richText.BlockType.Heading2:
|
|
215
|
-
case richText.BlockType.Heading3:
|
|
216
|
-
case richText.BlockType.BlockQuote:
|
|
217
|
-
case richText.BlockType.OrderedList:
|
|
218
|
-
case richText.BlockType.UnorderedList:
|
|
219
|
-
case richText.BlockType.ListItem:
|
|
220
|
-
case richText.BlockType.ListItemChild:
|
|
221
|
-
return /* @__PURE__ */ jsxRuntime.jsx(BlockElement, __spreadValues({
|
|
222
|
-
element
|
|
223
|
-
}, props));
|
|
224
|
-
default:
|
|
225
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps(__spreadValues({}, props.attributes), {
|
|
226
|
-
children: props.children
|
|
227
|
-
}));
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const COMMIT_DEBOUNCE_DELAY = 500;
|
|
231
|
-
function useSyncWithBuilder(editor, text) {
|
|
232
|
-
const [shouldCommit, setShouldCommit] = React.useState(true);
|
|
233
|
-
React.useEffect(() => {
|
|
234
|
-
if (shouldCommit && text) {
|
|
235
|
-
const nextValue = richText.richTextDTOtoDAO(text);
|
|
236
|
-
const nextSelection = richText.richTextDTOtoSelection(text);
|
|
237
|
-
if (!next.deepEqual(editor.children, nextValue) || !next.deepEqual(editor.selection, nextSelection)) {
|
|
238
|
-
editor.children = nextValue;
|
|
239
|
-
editor.selection = nextSelection;
|
|
240
|
-
editor.onChange();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}, [editor, shouldCommit, text]);
|
|
244
|
-
React.useEffect(() => {
|
|
245
|
-
if (shouldCommit)
|
|
246
|
-
return;
|
|
247
|
-
const timeoutId = window.setTimeout(() => {
|
|
248
|
-
setShouldCommit(true);
|
|
249
|
-
}, COMMIT_DEBOUNCE_DELAY);
|
|
250
|
-
return () => {
|
|
251
|
-
window.clearTimeout(timeoutId);
|
|
252
|
-
};
|
|
253
|
-
}, [shouldCommit]);
|
|
254
|
-
return React.useCallback(() => setShouldCommit(false), []);
|
|
255
|
-
}
|
|
256
|
-
const LIST_ITEM_CHILD_POSITION = 0;
|
|
257
|
-
const LIST_ITEM_LIST_POSITION = 1;
|
|
258
|
-
const ElementUtils = {
|
|
259
|
-
isBlock(node) {
|
|
260
|
-
return slate.Element.isElement(node) && (slate.Element.isElementType(node, richText.BlockType.Paragraph) || slate.Element.isElementType(node, richText.BlockType.Heading1) || slate.Element.isElementType(node, richText.BlockType.Heading2) || slate.Element.isElementType(node, richText.BlockType.Heading3) || slate.Element.isElementType(node, richText.BlockType.Heading3) || slate.Element.isElementType(node, richText.BlockType.Heading4) || slate.Element.isElementType(node, richText.BlockType.Heading5) || slate.Element.isElementType(node, richText.BlockType.Heading6) || slate.Element.isElementType(node, richText.BlockType.BlockQuote) || slate.Element.isElementType(node, richText.BlockType.UnorderedList) || slate.Element.isElementType(node, richText.BlockType.OrderedList) || slate.Element.isElementType(node, richText.BlockType.ListItem) || slate.Element.isElementType(node, richText.BlockType.ListItemChild));
|
|
261
|
-
},
|
|
262
|
-
isInline(node) {
|
|
263
|
-
return slate.Element.isElement(node) && (slate.Element.isElementType(node, richText.InlineType.Link) || slate.Element.isElementType(node, richText.InlineType.Link) || slate.Element.isElementType(node, richText.InlineType.SubScript) || slate.Element.isElementType(node, richText.InlineType.SuperScript));
|
|
264
|
-
},
|
|
265
|
-
isConvertibleToListTextNode(node) {
|
|
266
|
-
return !this.isList(node) && !this.isListItem(node) && !this.isListItemChild(node);
|
|
267
|
-
},
|
|
268
|
-
isParagraph(node) {
|
|
269
|
-
return slate.Element.isElementType(node, richText.BlockType.Paragraph);
|
|
270
|
-
},
|
|
271
|
-
isList(node) {
|
|
272
|
-
return slate.Element.isElementType(node, richText.BlockType.OrderedList) || slate.Element.isElementType(node, richText.BlockType.UnorderedList);
|
|
273
|
-
},
|
|
274
|
-
isListItem(node) {
|
|
275
|
-
return slate.Element.isElementType(node, richText.BlockType.ListItem);
|
|
276
|
-
},
|
|
277
|
-
isListItemChild(node) {
|
|
278
|
-
return slate.Element.isElementType(node, richText.BlockType.ListItemChild);
|
|
279
|
-
},
|
|
280
|
-
createText() {
|
|
281
|
-
return { text: "" };
|
|
282
|
-
},
|
|
283
|
-
createParagraph() {
|
|
284
|
-
return {
|
|
285
|
-
children: [this.createText()],
|
|
286
|
-
type: richText.BlockType.Paragraph
|
|
287
|
-
};
|
|
288
|
-
},
|
|
289
|
-
createList(type = richText.BlockType.UnorderedList) {
|
|
290
|
-
return { children: [this.createText()], type };
|
|
291
|
-
},
|
|
292
|
-
createListItem() {
|
|
293
|
-
return {
|
|
294
|
-
children: [this.createListItemChild()],
|
|
295
|
-
type: richText.BlockType.ListItem
|
|
296
|
-
};
|
|
297
|
-
},
|
|
298
|
-
createListItemChild() {
|
|
299
|
-
return {
|
|
300
|
-
children: [this.createText()],
|
|
301
|
-
type: richText.BlockType.ListItemChild
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
const EditorUtils = {
|
|
306
|
-
getFirstAncestorList(editor, path) {
|
|
307
|
-
const parentList = slate.Editor.above(editor, {
|
|
308
|
-
at: path,
|
|
309
|
-
match: (node) => ElementUtils.isList(node)
|
|
310
|
-
});
|
|
311
|
-
return parentList != null ? parentList : null;
|
|
312
|
-
},
|
|
313
|
-
getFirstAncestorListItem(editor, path) {
|
|
314
|
-
const parentListItem = slate.Editor.above(editor, {
|
|
315
|
-
at: path,
|
|
316
|
-
match: (node) => ElementUtils.isListItem(node)
|
|
317
|
-
});
|
|
318
|
-
return parentListItem != null ? parentListItem : null;
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
function filterForSubtreeRoots(entries) {
|
|
322
|
-
return entries.filter(([, nodePath]) => !slate.Path.ancestors(nodePath).some((ancestor) => {
|
|
323
|
-
return entries.some(([, path]) => slate.Path.equals(path, ancestor));
|
|
324
|
-
}));
|
|
325
|
-
}
|
|
326
|
-
const LocationUtils = {
|
|
327
|
-
getStartPath(location) {
|
|
328
|
-
if (slate.Range.isRange(location))
|
|
329
|
-
return slate.Range.start(location).path;
|
|
330
|
-
if (slate.Point.isPoint(location))
|
|
331
|
-
return location.path;
|
|
332
|
-
return location;
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
function getSelectedListItems(editor) {
|
|
336
|
-
var _a, _b;
|
|
337
|
-
if (!editor.selection)
|
|
338
|
-
return [];
|
|
339
|
-
const start = LocationUtils.getStartPath(editor.selection);
|
|
340
|
-
const listItems = slate.Editor.nodes(editor, {
|
|
341
|
-
at: editor.selection,
|
|
342
|
-
match: (node) => ElementUtils.isListItem(node)
|
|
343
|
-
});
|
|
344
|
-
const firstAncestorPath = (_b = (_a = EditorUtils.getFirstAncestorListItem(editor, start)) == null ? void 0 : _a[1]) != null ? _b : [];
|
|
345
|
-
return Array.from(listItems).filter((node) => slate.Path.isDescendant(start, node[1]) ? slate.Path.equals(node[1], firstAncestorPath) : !slate.Path.isAfter(start, node[1]));
|
|
346
|
-
}
|
|
347
|
-
function indentPath(editor, path) {
|
|
348
|
-
const parent = slate.Node.parent(editor, path);
|
|
349
|
-
if (!path || !slate.Path.hasPrevious(path) || !ElementUtils.isList(parent))
|
|
350
|
-
return;
|
|
351
|
-
const previosPath = slate.Path.previous(path);
|
|
352
|
-
const previousChildListPath = [...previosPath, LIST_ITEM_LIST_POSITION];
|
|
353
|
-
const previousHasChildList = slate.Node.has(editor, previousChildListPath);
|
|
354
|
-
slate.Editor.withoutNormalizing(editor, () => {
|
|
355
|
-
if (!previousHasChildList) {
|
|
356
|
-
slate.Transforms.insertNodes(editor, ElementUtils.createList(parent.type), {
|
|
357
|
-
at: previousChildListPath
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
const previousChildList = slate.Node.get(editor, previousChildListPath);
|
|
361
|
-
if (ElementUtils.isList(previousChildList)) {
|
|
362
|
-
const index2 = previousHasChildList ? previousChildList.children.length : 0;
|
|
363
|
-
slate.Transforms.moveNodes(editor, {
|
|
364
|
-
at: path,
|
|
365
|
-
to: [...previousChildListPath, index2]
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
function indent(editor) {
|
|
371
|
-
if (!editor.selection)
|
|
372
|
-
return;
|
|
373
|
-
const listItems = getSelectedListItems(editor);
|
|
374
|
-
const subRoots = filterForSubtreeRoots(listItems);
|
|
375
|
-
const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
|
|
376
|
-
refs.forEach((ref) => {
|
|
377
|
-
if (ref.current) {
|
|
378
|
-
indentPath(editor, ref.current);
|
|
379
|
-
}
|
|
380
|
-
ref.unref();
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
function dedentPath(editor, listItemPath) {
|
|
384
|
-
const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
|
|
385
|
-
const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
|
|
386
|
-
if (!parentList || !listItemContainingParentList)
|
|
387
|
-
return;
|
|
388
|
-
const [parentListNode, parentListPath] = parentList;
|
|
389
|
-
const [_, listItemContainingParentListPath] = listItemContainingParentList;
|
|
390
|
-
const listItemPosition = listItemPath[listItemPath.length - 1];
|
|
391
|
-
const previousSiblings = parentListNode.children.slice(0, listItemPosition);
|
|
392
|
-
const nextSiblings = parentListNode.children.slice(listItemPosition + 1);
|
|
393
|
-
slate.Editor.withoutNormalizing(editor, () => {
|
|
394
|
-
nextSiblings.forEach(() => {
|
|
395
|
-
const nextSiblingPath = [...parentListPath, listItemPosition + 1];
|
|
396
|
-
indentPath(editor, nextSiblingPath);
|
|
397
|
-
});
|
|
398
|
-
slate.Transforms.moveNodes(editor, {
|
|
399
|
-
at: listItemPath,
|
|
400
|
-
to: slate.Path.next(listItemContainingParentListPath)
|
|
401
|
-
});
|
|
402
|
-
if (previousSiblings.length === 0) {
|
|
403
|
-
slate.Transforms.removeNodes(editor, { at: parentListPath });
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
function dedent(editor) {
|
|
408
|
-
if (!editor.selection)
|
|
409
|
-
return;
|
|
410
|
-
const listItems = getSelectedListItems(editor);
|
|
411
|
-
const subRoots = filterForSubtreeRoots(listItems);
|
|
412
|
-
const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
|
|
413
|
-
refs.forEach((ref) => {
|
|
414
|
-
if (ref.current) {
|
|
415
|
-
dedentPath(editor, ref.current);
|
|
416
|
-
}
|
|
417
|
-
ref.unref();
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
function unwrapPath(editor, listItemPath) {
|
|
421
|
-
const parentList = EditorUtils.getFirstAncestorList(editor, listItemPath);
|
|
422
|
-
const listItemContainingParentList = EditorUtils.getFirstAncestorListItem(editor, listItemPath);
|
|
423
|
-
if (!parentList || listItemContainingParentList)
|
|
424
|
-
return;
|
|
425
|
-
slate.Editor.withoutNormalizing(editor, () => {
|
|
426
|
-
const listItemTextPath = [...listItemPath, LIST_ITEM_CHILD_POSITION];
|
|
427
|
-
const listItemNestedListPath = [...listItemPath, LIST_ITEM_LIST_POSITION];
|
|
428
|
-
if (slate.Node.has(editor, listItemNestedListPath)) {
|
|
429
|
-
slate.Transforms.setNodes(editor, { type: parentList[0].type }, { at: listItemNestedListPath });
|
|
430
|
-
slate.Transforms.liftNodes(editor, { at: listItemNestedListPath });
|
|
431
|
-
slate.Transforms.liftNodes(editor, { at: slate.Path.next(listItemPath) });
|
|
432
|
-
}
|
|
433
|
-
if (slate.Node.has(editor, listItemTextPath)) {
|
|
434
|
-
slate.Transforms.setNodes(editor, { type: richText.BlockType.Paragraph }, {
|
|
435
|
-
at: listItemTextPath
|
|
436
|
-
});
|
|
437
|
-
slate.Transforms.liftNodes(editor, { at: listItemTextPath });
|
|
438
|
-
slate.Transforms.liftNodes(editor, { at: listItemPath });
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
function unwrapList(editor) {
|
|
443
|
-
if (!editor.selection)
|
|
444
|
-
return;
|
|
445
|
-
const listItems = getSelectedListItems(editor);
|
|
446
|
-
const subRoots = filterForSubtreeRoots(listItems);
|
|
447
|
-
const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
|
|
448
|
-
refs.forEach((ref) => {
|
|
449
|
-
if (ref.current) {
|
|
450
|
-
unwrapPath(editor, ref.current);
|
|
451
|
-
}
|
|
452
|
-
ref.unref();
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
function wrapList(editor, options = { type: richText.BlockType.UnorderedList }) {
|
|
456
|
-
if (!editor.selection)
|
|
457
|
-
return;
|
|
458
|
-
const nonListEntries = Array.from(slate.Editor.nodes(editor, {
|
|
459
|
-
at: editor.selection,
|
|
460
|
-
match: (node) => {
|
|
461
|
-
return slate.Element.isElement(node) && ElementUtils.isConvertibleToListTextNode(node);
|
|
462
|
-
}
|
|
463
|
-
}));
|
|
464
|
-
const refs = nonListEntries.map(([_, path]) => slate.Editor.pathRef(editor, path));
|
|
465
|
-
refs.forEach((ref) => {
|
|
466
|
-
const path = ref.current;
|
|
467
|
-
if (path) {
|
|
468
|
-
slate.Editor.withoutNormalizing(editor, () => {
|
|
469
|
-
slate.Transforms.setNodes(editor, { type: richText.BlockType.ListItemChild }, {
|
|
470
|
-
at: path
|
|
471
|
-
});
|
|
472
|
-
slate.Transforms.wrapNodes(editor, ElementUtils.createListItem(), {
|
|
473
|
-
at: path
|
|
474
|
-
});
|
|
475
|
-
slate.Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {
|
|
476
|
-
at: path
|
|
477
|
-
});
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
ref.unref();
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
function toggleList(editor, options = { type: richText.BlockType.UnorderedList }) {
|
|
484
|
-
if (!editor.selection)
|
|
485
|
-
return;
|
|
486
|
-
const start = LocationUtils.getStartPath(editor.selection);
|
|
487
|
-
const ancestorPath = slate.Path.ancestors(start).at(1);
|
|
488
|
-
if (!ancestorPath || !slate.Node.has(editor, ancestorPath))
|
|
489
|
-
return;
|
|
490
|
-
const ancestor = slate.Node.get(editor, ancestorPath);
|
|
491
|
-
if (!ElementUtils.isList(ancestor)) {
|
|
492
|
-
return wrapList(editor, { type: options.type });
|
|
493
|
-
}
|
|
494
|
-
if (ancestor.type === options.type) {
|
|
495
|
-
unwrapList(editor);
|
|
496
|
-
} else {
|
|
497
|
-
slate.Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
const List = {
|
|
501
|
-
unwrapList,
|
|
502
|
-
wrapList,
|
|
503
|
-
indent,
|
|
504
|
-
dedent,
|
|
505
|
-
toggleList
|
|
506
|
-
};
|
|
507
|
-
function onKeyDown(e, editor) {
|
|
508
|
-
if (!editor.selection || Array.from(slate.Editor.nodes(editor, { match: (node) => ElementUtils.isListItem(node) })).length === 0)
|
|
509
|
-
return;
|
|
510
|
-
if (isHotkey__default["default"]("shift+tab", e)) {
|
|
511
|
-
e.preventDefault();
|
|
512
|
-
List.dedent(editor);
|
|
513
|
-
}
|
|
514
|
-
if (isHotkey__default["default"]("tab", e)) {
|
|
515
|
-
e.preventDefault();
|
|
516
|
-
List.indent(editor);
|
|
517
|
-
}
|
|
518
|
-
if (isHotkey__default["default"]("backspace", e)) {
|
|
519
|
-
if (!editor.selection)
|
|
520
|
-
return;
|
|
521
|
-
if (slate.Range.isExpanded(editor.selection))
|
|
522
|
-
return;
|
|
523
|
-
const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
|
|
524
|
-
if (editor.selection.anchor.offset === 0 && listItem) {
|
|
525
|
-
e.preventDefault();
|
|
526
|
-
const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
|
|
527
|
-
const list = EditorUtils.getFirstAncestorList(editor, listItem[1]);
|
|
528
|
-
if (parentListItem) {
|
|
529
|
-
List.dedent(editor);
|
|
530
|
-
} else if (list) {
|
|
531
|
-
List.unwrapList(editor);
|
|
532
|
-
}
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
if (isHotkey__default["default"]("enter", e)) {
|
|
537
|
-
e.preventDefault();
|
|
538
|
-
if (!editor.selection)
|
|
539
|
-
return;
|
|
540
|
-
if (slate.Range.isExpanded(editor.selection)) {
|
|
541
|
-
slate.Transforms.delete(editor);
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
const listItem = EditorUtils.getFirstAncestorListItem(editor, editor.selection.anchor.path);
|
|
545
|
-
if (editor.selection.anchor.offset === 0 && listItem && slate.Editor.string(editor, listItem[1]) === "") {
|
|
546
|
-
const parentListItem = EditorUtils.getFirstAncestorListItem(editor, listItem[1]);
|
|
547
|
-
if (parentListItem) {
|
|
548
|
-
List.dedent(editor);
|
|
549
|
-
} else {
|
|
550
|
-
List.unwrapList(editor);
|
|
551
|
-
}
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
slate.Transforms.splitNodes(editor, {
|
|
555
|
-
at: editor.selection,
|
|
556
|
-
always: true,
|
|
557
|
-
match: (node) => ElementUtils.isListItem(node)
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
if (isHotkey__default["default"]("shift+enter", e)) {
|
|
561
|
-
e.preventDefault();
|
|
562
|
-
editor.insertText("\n");
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
function withList(editor) {
|
|
566
|
-
const { normalizeNode } = editor;
|
|
567
|
-
editor.normalizeNode = (entry) => {
|
|
568
|
-
const [normalizationNode, normalizationPath] = entry;
|
|
569
|
-
if (ElementUtils.isListItem(normalizationNode)) {
|
|
570
|
-
const pathToListItemText = [...normalizationPath, LIST_ITEM_CHILD_POSITION];
|
|
571
|
-
if (slate.Node.has(editor, pathToListItemText)) {
|
|
572
|
-
const nodeInListItemTextPosition = slate.Node.get(editor, pathToListItemText);
|
|
573
|
-
if (ElementUtils.isParagraph(nodeInListItemTextPosition)) {
|
|
574
|
-
slate.Transforms.setNodes(editor, { type: richText.BlockType.ListItemChild }, {
|
|
575
|
-
at: pathToListItemText
|
|
576
|
-
});
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
} else {
|
|
580
|
-
slate.Transforms.insertNodes(editor, ElementUtils.createListItem(), {
|
|
581
|
-
at: pathToListItemText
|
|
582
|
-
});
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
if (!slate.Text.isText(normalizationNode)) {
|
|
587
|
-
const mergeableChildren = Array.from(slate.Node.children(editor, normalizationPath)).map((child, index2, children) => {
|
|
588
|
-
const potentialNodeToBeMerged = children.at(index2 + 1);
|
|
589
|
-
if (!potentialNodeToBeMerged || !ElementUtils.isList(potentialNodeToBeMerged[0]) || !ElementUtils.isList(child[0]) || potentialNodeToBeMerged[0].type !== child[0].type) {
|
|
590
|
-
return null;
|
|
591
|
-
}
|
|
592
|
-
return [
|
|
593
|
-
slate.Editor.pathRef(editor, child[1]),
|
|
594
|
-
slate.Editor.pathRef(editor, potentialNodeToBeMerged[1])
|
|
595
|
-
];
|
|
596
|
-
}).filter((mergeableNodes) => Boolean(mergeableNodes));
|
|
597
|
-
if (mergeableChildren.length !== 0) {
|
|
598
|
-
mergeableChildren.reverse().forEach(([nodePathRef, nodeToBeMergedPathRef]) => {
|
|
599
|
-
const nodePath = nodePathRef.current;
|
|
600
|
-
const nodeToBeMergedPath = nodeToBeMergedPathRef.current;
|
|
601
|
-
if (nodePath == null || nodeToBeMergedPath == null)
|
|
602
|
-
return;
|
|
603
|
-
const nodeChildren = Array.from(slate.Node.children(editor, nodePath));
|
|
604
|
-
const childrenToBeMerged = Array.from(slate.Node.children(editor, nodeToBeMergedPath));
|
|
605
|
-
slate.Editor.withoutNormalizing(editor, () => {
|
|
606
|
-
childrenToBeMerged.forEach(([_, childPath], index2) => {
|
|
607
|
-
slate.Transforms.moveNodes(editor, {
|
|
608
|
-
at: childPath,
|
|
609
|
-
to: [...nodePath, nodeChildren.length + index2]
|
|
610
|
-
});
|
|
611
|
-
});
|
|
612
|
-
slate.Transforms.removeNodes(editor, { at: nodeToBeMergedPath });
|
|
613
|
-
});
|
|
614
|
-
nodePathRef.unref();
|
|
615
|
-
nodeToBeMergedPathRef.unref();
|
|
616
|
-
});
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
normalizeNode(entry);
|
|
621
|
-
};
|
|
622
|
-
return editor;
|
|
623
|
-
}
|
|
624
|
-
function withTypography(editor) {
|
|
625
|
-
const { normalizeNode } = editor;
|
|
626
|
-
editor.normalizeNode = (entry) => {
|
|
627
|
-
var _a, _b;
|
|
628
|
-
const [normalizationNode, normalizationPath] = entry;
|
|
629
|
-
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) {
|
|
630
|
-
slate.Transforms.unsetNodes(editor, "typography", { at: normalizationPath });
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
normalizeNode(entry);
|
|
634
|
-
};
|
|
635
|
-
return editor;
|
|
636
|
-
}
|
|
637
|
-
function withBlock(editor) {
|
|
638
|
-
const { normalizeNode } = editor;
|
|
639
|
-
editor.normalizeNode = (entry) => {
|
|
640
|
-
var _a;
|
|
641
|
-
const [normalizationNode, normalizationPath] = entry;
|
|
642
|
-
if (ElementUtils.isBlock(normalizationNode) && ((_a = normalizationNode == null ? void 0 : normalizationNode.textAlign) == null ? void 0 : _a.length) == 0) {
|
|
643
|
-
slate.Transforms.unsetNodes(editor, "textAlign", { at: normalizationPath });
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
normalizeNode(entry);
|
|
647
|
-
};
|
|
648
|
-
return editor;
|
|
649
|
-
}
|
|
650
|
-
const defaultText = [{
|
|
651
|
-
type: richText.BlockType.Paragraph,
|
|
652
|
-
children: [{
|
|
653
|
-
text: ""
|
|
654
|
-
}]
|
|
655
|
-
}];
|
|
656
|
-
const EditableText = React.forwardRef(function EditableText2({
|
|
657
|
-
id,
|
|
658
|
-
text,
|
|
659
|
-
width,
|
|
660
|
-
margin
|
|
661
|
-
}, ref) {
|
|
662
|
-
const [editor] = React.useState(() => withBlock(withTypography(withList(slateReact.withReact(slate.createEditor())))));
|
|
663
|
-
const delaySync = useSyncWithBuilder(editor, text);
|
|
664
|
-
const editMode = next.useBuilderEditMode();
|
|
665
|
-
const [propControllers, setPropControllers] = React.useState(null);
|
|
666
|
-
const controller = propControllers == null ? void 0 : propControllers.text;
|
|
667
|
-
React.useEffect(() => {
|
|
668
|
-
if (controller == null)
|
|
669
|
-
return;
|
|
670
|
-
const element = slateReact.ReactEditor.toDOMNode(editor, editor);
|
|
671
|
-
return next.pollBoxModel({
|
|
672
|
-
element,
|
|
673
|
-
onBoxModelChange: (boxModel) => controller.changeBoxModel(boxModel)
|
|
674
|
-
});
|
|
675
|
-
}, [editor, controller]);
|
|
676
|
-
React.useImperativeHandle(ref, () => ({
|
|
677
|
-
getDomNode() {
|
|
678
|
-
return slateReact.ReactEditor.toDOMNode(editor, editor);
|
|
679
|
-
},
|
|
680
|
-
getBoxModel() {
|
|
681
|
-
return boxModels.getBox(slateReact.ReactEditor.toDOMNode(editor, editor));
|
|
682
|
-
},
|
|
683
|
-
setPropControllers
|
|
684
|
-
}), [editor, setPropControllers]);
|
|
685
|
-
const initialValue = React.useMemo(() => text ? richText.richTextDTOtoDAO(text) : defaultText, [text]);
|
|
686
|
-
React.useEffect(() => {
|
|
687
|
-
controller == null ? void 0 : controller.setSlateEditor(editor);
|
|
688
|
-
}, [controller, editor]);
|
|
689
|
-
const handleFocus = React.useCallback(() => {
|
|
690
|
-
controller == null ? void 0 : controller.focus();
|
|
691
|
-
}, [controller]);
|
|
692
|
-
const handleKeyDown = React.useCallback((e) => {
|
|
693
|
-
if (isHotkey__default["default"]("mod+shift+z", e))
|
|
694
|
-
return controller == null ? void 0 : controller.redo();
|
|
695
|
-
if (isHotkey__default["default"]("mod+z", e))
|
|
696
|
-
return controller == null ? void 0 : controller.undo();
|
|
697
|
-
if (isHotkey__default["default"]("escape")(e))
|
|
698
|
-
return controller == null ? void 0 : controller.blur();
|
|
699
|
-
onKeyDown(e, editor);
|
|
700
|
-
}, [controller, editor]);
|
|
701
|
-
return /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, {
|
|
702
|
-
editor,
|
|
703
|
-
value: initialValue,
|
|
704
|
-
onChange: delaySync,
|
|
705
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Editable, {
|
|
706
|
-
id,
|
|
707
|
-
renderLeaf: leaf.Leaf,
|
|
708
|
-
renderElement: Element,
|
|
709
|
-
onKeyDown: handleKeyDown,
|
|
710
|
-
onFocus: handleFocus,
|
|
711
|
-
className: css.cx(width, margin),
|
|
712
|
-
readOnly: editMode === richText.BuilderEditMode.INTERACT,
|
|
713
|
-
placeholder: "Write some text..."
|
|
714
|
-
})
|
|
715
|
-
});
|
|
716
|
-
});
|
|
717
|
-
var EditableText$1 = EditableText;
|
|
718
|
-
exports.EditableText = EditableText;
|
|
719
|
-
exports["default"] = EditableText$1;
|
|
39
|
+
exports["default"] = Text["default"];
|
|
720
40
|
//# sourceMappingURL=index.cjs6.js.map
|