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