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