@makeswift/runtime 0.8.6 → 0.8.7

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 (87) hide show
  1. package/dist/LiveProvider.cjs.js +4 -3
  2. package/dist/LiveProvider.cjs.js.map +1 -1
  3. package/dist/LiveProvider.es.js +5 -4
  4. package/dist/LiveProvider.es.js.map +1 -1
  5. package/dist/PreviewProvider.cjs.js +4 -3
  6. package/dist/PreviewProvider.cjs.js.map +1 -1
  7. package/dist/PreviewProvider.es.js +5 -4
  8. package/dist/PreviewProvider.es.js.map +1 -1
  9. package/dist/actions.es.js +1 -1
  10. package/dist/constants.cjs.js +6 -2
  11. package/dist/constants.cjs.js.map +1 -1
  12. package/dist/constants.es.js +8 -4
  13. package/dist/constants.es.js.map +1 -1
  14. package/dist/index.cjs.js +83 -50
  15. package/dist/index.cjs.js.map +1 -1
  16. package/dist/index.cjs5.js +260 -106
  17. package/dist/index.cjs5.js.map +1 -1
  18. package/dist/index.cjs7.js.map +1 -1
  19. package/dist/index.es.js +86 -52
  20. package/dist/index.es.js.map +1 -1
  21. package/dist/index.es5.js +260 -106
  22. package/dist/index.es5.js.map +1 -1
  23. package/dist/index.es7.js +1 -1
  24. package/dist/index.es7.js.map +1 -1
  25. package/dist/leaf.es.js +1 -1
  26. package/dist/next.es.js +1 -1
  27. package/dist/state/breakpoints.cjs.js +2 -2
  28. package/dist/state/breakpoints.cjs.js.map +1 -1
  29. package/dist/state/breakpoints.es.js +2 -2
  30. package/dist/state/breakpoints.es.js.map +1 -1
  31. package/dist/types/src/next/api-handler/handlers/manifest.d.ts +1 -0
  32. package/dist/types/src/next/api-handler/handlers/manifest.d.ts.map +1 -1
  33. package/dist/types/src/next/client.d.ts +4 -1
  34. package/dist/types/src/next/client.d.ts.map +1 -1
  35. package/dist/types/src/next/index.d.ts +3 -1
  36. package/dist/types/src/next/index.d.ts.map +1 -1
  37. package/dist/types/src/runtimes/react/components/LiveProvider.d.ts +3 -1
  38. package/dist/types/src/runtimes/react/components/LiveProvider.d.ts.map +1 -1
  39. package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts +3 -1
  40. package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts.map +1 -1
  41. package/dist/types/src/runtimes/react/index.d.ts +19 -5
  42. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  43. package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts +2 -2
  44. package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts.map +1 -1
  45. package/dist/types/src/slate/BlockPlugin/index.d.ts +4 -0
  46. package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -1
  47. package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts +7 -4
  48. package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts.map +1 -1
  49. package/dist/types/src/slate/BlockPlugin/types.d.ts +2 -2
  50. package/dist/types/src/slate/BlockPlugin/types.d.ts.map +1 -1
  51. package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts +4 -0
  52. package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts.map +1 -0
  53. package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts +4 -0
  54. package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts.map +1 -0
  55. package/dist/types/src/slate/ListPlugin/toggleList.d.ts +2 -1
  56. package/dist/types/src/slate/ListPlugin/toggleList.d.ts.map +1 -1
  57. package/dist/types/src/slate/ListPlugin/unwrapList.d.ts +6 -2
  58. package/dist/types/src/slate/ListPlugin/unwrapList.d.ts.map +1 -1
  59. package/dist/types/src/slate/ListPlugin/utils/getSelectedListItems.d.ts +0 -1
  60. package/dist/types/src/slate/ListPlugin/utils/getSelectedListItems.d.ts.map +1 -1
  61. package/dist/types/src/slate/ListPlugin/wrapList.d.ts +2 -1
  62. package/dist/types/src/slate/ListPlugin/wrapList.d.ts.map +1 -1
  63. package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts +6 -2
  64. package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts.map +1 -1
  65. package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts +6 -2
  66. package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts.map +1 -1
  67. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts +6 -2
  68. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts.map +1 -1
  69. package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
  70. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts +6 -2
  71. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts.map +1 -1
  72. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts +6 -2
  73. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -1
  74. package/dist/types/src/slate/selectors.d.ts +19 -0
  75. package/dist/types/src/slate/selectors.d.ts.map +1 -0
  76. package/dist/types/src/slate/utils/editor.d.ts.map +1 -1
  77. package/dist/types/src/slate/utils/element.d.ts +2 -1
  78. package/dist/types/src/slate/utils/element.d.ts.map +1 -1
  79. package/dist/types/src/slate/utils/unhangRange.d.ts +10 -0
  80. package/dist/types/src/slate/utils/unhangRange.d.ts.map +1 -0
  81. package/dist/types/src/state/modules/breakpoints.d.ts +1 -1
  82. package/dist/types/src/state/modules/breakpoints.d.ts.map +1 -1
  83. package/dist/types/src/state/react-page.d.ts +2 -1
  84. package/dist/types/src/state/react-page.d.ts.map +1 -1
  85. package/dist/types/src/utils/isNonNullable.d.ts +2 -0
  86. package/dist/types/src/utils/isNonNullable.d.ts.map +1 -0
  87. package/package.json +1 -1
package/dist/index.es5.js CHANGED
@@ -25,11 +25,14 @@ import { findBreakpointOverride } from "./state/breakpoints.es.js";
25
25
  const LIST_ITEM_CHILD_POSITION = 0;
26
26
  const LIST_ITEM_LIST_POSITION = 1;
27
27
  const ElementUtils = {
28
+ isRootBlock(node) {
29
+ 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));
30
+ },
28
31
  isBlock(node) {
29
- 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));
32
+ return Element.isElement(node) && (this.isRootBlock(node) || Element.isElementType(node, BlockType.ListItem) || Element.isElementType(node, BlockType.ListItemChild));
30
33
  },
31
34
  isInline(node) {
32
- return Element.isElement(node) && (Element.isElementType(node, InlineType.Link) || Element.isElementType(node, InlineType.Link) || Element.isElementType(node, InlineType.SubScript) || Element.isElementType(node, InlineType.SuperScript));
35
+ return Element.isElementType(node, InlineType.Code) || Element.isElementType(node, InlineType.Link) || Element.isElementType(node, InlineType.SubScript) || Element.isElementType(node, InlineType.SuperScript);
33
36
  },
34
37
  isConvertibleToListTextNode(node) {
35
38
  return !this.isList(node) && !this.isListItem(node) && !this.isListItemChild(node);
@@ -60,7 +63,7 @@ const ElementUtils = {
60
63
  },
61
64
  createListItem() {
62
65
  return {
63
- children: [this.createText()],
66
+ children: [this.createListItemChild()],
64
67
  type: BlockType.ListItem
65
68
  };
66
69
  },
@@ -73,18 +76,26 @@ const ElementUtils = {
73
76
  };
74
77
  const EditorUtils = {
75
78
  getFirstAncestorList(editor, path) {
76
- const parentList = Editor.above(editor, {
77
- at: path,
78
- match: (node) => ElementUtils.isList(node)
79
- });
80
- return parentList != null ? parentList : null;
79
+ try {
80
+ const parentList = Editor.above(editor, {
81
+ at: path,
82
+ match: (node) => ElementUtils.isList(node)
83
+ });
84
+ return parentList != null ? parentList : null;
85
+ } catch (e) {
86
+ return null;
87
+ }
81
88
  },
82
89
  getFirstAncestorListItem(editor, path) {
83
- const parentListItem = Editor.above(editor, {
84
- at: path,
85
- match: (node) => ElementUtils.isListItem(node)
86
- });
87
- return parentListItem != null ? parentListItem : null;
90
+ try {
91
+ const parentListItem = Editor.above(editor, {
92
+ at: path,
93
+ match: (node) => ElementUtils.isListItem(node)
94
+ });
95
+ return parentListItem != null ? parentListItem : null;
96
+ } catch (e) {
97
+ return null;
98
+ }
88
99
  }
89
100
  };
90
101
  function filterForSubtreeRoots(entries) {
@@ -208,10 +219,17 @@ function unwrapPath(editor, listItemPath) {
208
219
  }
209
220
  });
210
221
  }
211
- function unwrapList(editor) {
212
- if (!editor.selection)
222
+ function unwrapList(editor, options) {
223
+ var _a;
224
+ const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
225
+ if (!at)
213
226
  return;
214
- const listItems = getSelectedListItems(editor);
227
+ const listItems = Array.from(Editor.nodes(editor, {
228
+ at,
229
+ match: (node) => {
230
+ return Element.isElement(node) && ElementUtils.isListItem(node);
231
+ }
232
+ }));
215
233
  const subRoots = filterForSubtreeRoots(listItems);
216
234
  const refs = subRoots.map(([_, path]) => Editor.pathRef(editor, path));
217
235
  refs.forEach((ref) => {
@@ -222,10 +240,12 @@ function unwrapList(editor) {
222
240
  });
223
241
  }
224
242
  function wrapList(editor, options = { type: BlockType.UnorderedList }) {
225
- if (!editor.selection)
243
+ var _a;
244
+ const at = (_a = options.at) != null ? _a : editor.selection;
245
+ if (!at)
226
246
  return;
227
247
  const nonListEntries = Array.from(Editor.nodes(editor, {
228
- at: editor.selection,
248
+ at,
229
249
  match: (node) => {
230
250
  return Element.isElement(node) && ElementUtils.isConvertibleToListTextNode(node);
231
251
  }
@@ -239,6 +259,7 @@ function wrapList(editor, options = { type: BlockType.UnorderedList }) {
239
259
  at: path
240
260
  });
241
261
  Transforms.wrapNodes(editor, ElementUtils.createListItem(), {
262
+ match: (node) => ElementUtils.isListItemChild(node),
242
263
  at: path
243
264
  });
244
265
  Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {
@@ -250,18 +271,20 @@ function wrapList(editor, options = { type: BlockType.UnorderedList }) {
250
271
  });
251
272
  }
252
273
  function toggleList(editor, options = { type: BlockType.UnorderedList }) {
253
- if (!editor.selection)
274
+ var _a;
275
+ const at = (_a = options.at) != null ? _a : editor.selection;
276
+ if (at == null)
254
277
  return;
255
- const start = LocationUtils.getStartPath(editor.selection);
278
+ const start = LocationUtils.getStartPath(at);
256
279
  const ancestorPath = Path.ancestors(start).at(1);
257
280
  if (!ancestorPath || !Node.has(editor, ancestorPath))
258
281
  return;
259
282
  const ancestor = Node.get(editor, ancestorPath);
260
283
  if (!ElementUtils.isList(ancestor)) {
261
- return wrapList(editor, { type: options.type });
284
+ return wrapList(editor, { type: options.type, at });
262
285
  }
263
286
  if (ancestor.type === options.type) {
264
- unwrapList(editor);
287
+ unwrapList(editor, { at });
265
288
  } else {
266
289
  Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
267
290
  }
@@ -372,10 +395,10 @@ function withList(editor) {
372
395
  const nodeChildren = Array.from(Node.children(editor, nodePath));
373
396
  const childrenToBeMerged = Array.from(Node.children(editor, nodeToBeMergedPath));
374
397
  Editor.withoutNormalizing(editor, () => {
375
- childrenToBeMerged.forEach(([_, childPath], index) => {
398
+ childrenToBeMerged.reverse().forEach(([_, childPath]) => {
376
399
  Transforms.moveNodes(editor, {
377
400
  at: childPath,
378
- to: [...nodePath, nodeChildren.length + index]
401
+ to: [...nodePath, nodeChildren.length]
379
402
  });
380
403
  });
381
404
  Transforms.removeNodes(editor, { at: nodeToBeMergedPath });
@@ -390,94 +413,168 @@ function withList(editor) {
390
413
  };
391
414
  return editor;
392
415
  }
393
- function clearActiveTypographyStyle(editor) {
394
- if (!editor.selection)
395
- return;
396
- const textNodes = Editor.nodes(editor, {
397
- at: editor.selection,
398
- match: (node) => Text.isText(node)
399
- });
400
- for (const [node, path] of textNodes) {
401
- if (Text.isText(node)) {
402
- const typography = __spreadProps(__spreadValues({}, node.typography), {
403
- style: []
404
- });
416
+ function clearActiveTypographyStyle(editor, options) {
417
+ Editor.withoutNormalizing(editor, () => {
418
+ var _a;
419
+ const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
420
+ if (!at)
421
+ return;
422
+ const atRef = Editor.rangeRef(editor, at);
423
+ if (atRef.current) {
405
424
  Transforms.setNodes(editor, {
406
- typography
407
- }, { at: path });
425
+ slice: true
426
+ }, {
427
+ at: atRef.current,
428
+ match: (node) => Text.isText(node),
429
+ split: Range.isExpanded(atRef.current)
430
+ });
408
431
  }
409
- }
410
- }
411
- function clearDeviceActiveTypography(editor, currentDeviceId) {
412
- var _a, _b;
413
- if (!editor.selection)
414
- return;
415
- const textNodes = Editor.nodes(editor, {
416
- at: editor.selection,
417
- match: (node) => Text.isText(node)
432
+ if (atRef.current) {
433
+ const textNodes = Array.from(Editor.nodes(editor, {
434
+ at: atRef.current,
435
+ match: (node) => Text.isText(node) && node.slice === true
436
+ }));
437
+ for (const [node, path] of textNodes) {
438
+ if (Text.isText(node)) {
439
+ const typography = __spreadProps(__spreadValues({}, node.typography), {
440
+ style: []
441
+ });
442
+ Transforms.setNodes(editor, {
443
+ typography
444
+ }, { at: path });
445
+ }
446
+ }
447
+ }
448
+ atRef.unref();
418
449
  });
419
- for (const [node, path] of textNodes) {
420
- if (Text.isText(node)) {
421
- const typography = __spreadProps(__spreadValues({}, node.typography), {
422
- style: (_b = (_a = node == null ? void 0 : node.typography) == null ? void 0 : _a.style.filter(({ deviceId }) => deviceId !== currentDeviceId)) != null ? _b : []
423
- });
450
+ }
451
+ function clearDeviceActiveTypography(editor, currentDeviceId, options) {
452
+ Editor.withoutNormalizing(editor, () => {
453
+ var _a, _b, _c;
454
+ const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
455
+ if (!at)
456
+ return;
457
+ const atRef = Editor.rangeRef(editor, at);
458
+ if (atRef.current) {
424
459
  Transforms.setNodes(editor, {
425
- typography
426
- }, { at: path });
460
+ slice: true
461
+ }, {
462
+ at: atRef.current,
463
+ match: (node) => Text.isText(node),
464
+ split: Range.isExpanded(atRef.current)
465
+ });
427
466
  }
428
- }
467
+ if (atRef.current) {
468
+ const textNodes = Array.from(Editor.nodes(editor, {
469
+ at: atRef.current,
470
+ match: (node) => Text.isText(node) && node.slice === true
471
+ }));
472
+ for (const [node, path] of textNodes) {
473
+ if (Text.isText(node)) {
474
+ const typography = __spreadProps(__spreadValues({}, node.typography), {
475
+ style: (_c = (_b = node == null ? void 0 : node.typography) == null ? void 0 : _b.style.filter(({ deviceId }) => deviceId !== currentDeviceId)) != null ? _c : []
476
+ });
477
+ Transforms.setNodes(editor, {
478
+ typography
479
+ }, { at: path });
480
+ }
481
+ }
482
+ }
483
+ atRef.unref();
484
+ });
429
485
  }
430
- function detachActiveTypography(editor, value) {
431
- if (!editor.selection)
432
- return;
433
- const textNodes = Array.from(Editor.nodes(editor, {
434
- at: editor.selection,
435
- match: (node) => Text.isText(node)
436
- }));
437
- textNodes.forEach(([node, path]) => {
438
- if (Text.isText(node)) {
486
+ function detachActiveTypography(editor, value, options) {
487
+ Editor.withoutNormalizing(editor, () => {
488
+ var _a;
489
+ const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
490
+ if (!at)
491
+ return;
492
+ const atRef = Editor.rangeRef(editor, at);
493
+ if (atRef.current) {
439
494
  Transforms.setNodes(editor, {
440
- typography: {
441
- style: value
495
+ slice: true
496
+ }, {
497
+ at: atRef.current,
498
+ match: (node) => Text.isText(node),
499
+ split: Range.isExpanded(atRef.current)
500
+ });
501
+ }
502
+ if (atRef.current) {
503
+ const textNodes = Array.from(Editor.nodes(editor, {
504
+ at: atRef.current,
505
+ match: (node) => Text.isText(node) && node.slice === true
506
+ }));
507
+ for (const [node, path] of textNodes) {
508
+ if (Text.isText(node)) {
509
+ Transforms.setNodes(editor, {
510
+ typography: {
511
+ style: value
512
+ }
513
+ }, { at: path });
442
514
  }
443
- }, { at: path });
515
+ }
444
516
  }
517
+ atRef.unref();
445
518
  });
446
519
  }
447
- function setActiveTypographyId(editor, id) {
520
+ function setActiveTypographyId(editor, id, options) {
521
+ var _a;
522
+ const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
523
+ if (!at)
524
+ return;
448
525
  Transforms.setNodes(editor, {
449
526
  typography: {
450
527
  id,
451
528
  style: []
452
529
  }
453
530
  }, {
454
- match: (node) => Text.isText(node)
531
+ at,
532
+ match: (node) => Text.isText(node),
533
+ split: Range.isExpanded(at)
455
534
  });
456
535
  }
457
- function setActiveTypographyStyle(editor, breakpoints, deviceId, prop, value) {
458
- var _a, _b;
459
- if (!editor.selection)
460
- return;
461
- const textNodes = Editor.nodes(editor, {
462
- at: editor.selection,
463
- match: (node) => Text.isText(node)
464
- });
465
- for (const [node, path] of textNodes) {
466
- if (Text.isText(node)) {
467
- const deviceOverrides = (_b = (_a = node == null ? void 0 : node.typography) == null ? void 0 : _a.style) != null ? _b : [];
468
- const deviceStyle = findBreakpointOverride(breakpoints, deviceOverrides, deviceId, (v) => v) || { value: {} };
469
- const nextDeviceStyle = {
470
- deviceId,
471
- value: __spreadProps(__spreadValues({}, deviceStyle.value), { [prop]: value })
472
- };
473
- const nextTypography = __spreadProps(__spreadValues({}, node.typography), {
474
- style: [...deviceOverrides.filter((v) => v.deviceId !== deviceId), nextDeviceStyle]
475
- });
536
+ function setActiveTypographyStyle(editor, breakpoints, deviceId, prop, value, options) {
537
+ Editor.withoutNormalizing(editor, () => {
538
+ var _a, _b, _c;
539
+ const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
540
+ if (!at)
541
+ return;
542
+ const atRef = Editor.rangeRef(editor, at);
543
+ if (atRef.current) {
476
544
  Transforms.setNodes(editor, {
477
- typography: nextTypography
478
- }, { at: path });
545
+ slice: true
546
+ }, {
547
+ at: atRef.current,
548
+ match: (node) => Text.isText(node),
549
+ split: Range.isExpanded(atRef.current)
550
+ });
479
551
  }
480
- }
552
+ if (atRef.current) {
553
+ const textNodes = Array.from(Editor.nodes(editor, {
554
+ at: atRef.current,
555
+ match: (node) => Text.isText(node) && node.slice === true
556
+ }));
557
+ for (const [node, path] of textNodes) {
558
+ if (Text.isText(node)) {
559
+ const deviceOverrides = (_c = (_b = node == null ? void 0 : node.typography) == null ? void 0 : _b.style) != null ? _c : [];
560
+ const deviceStyle = findBreakpointOverride(breakpoints, deviceOverrides, deviceId, (v) => v) || {
561
+ value: {}
562
+ };
563
+ const nextDeviceStyle = {
564
+ deviceId,
565
+ value: __spreadProps(__spreadValues({}, deviceStyle.value), { [prop]: value })
566
+ };
567
+ const nextTypography = __spreadProps(__spreadValues({}, node.typography), {
568
+ style: [...deviceOverrides.filter((v) => v.deviceId !== deviceId), nextDeviceStyle]
569
+ });
570
+ Transforms.setNodes(editor, {
571
+ typography: nextTypography
572
+ }, { at: path });
573
+ }
574
+ }
575
+ }
576
+ atRef.unref();
577
+ });
481
578
  }
482
579
  const Typography = {
483
580
  setActiveTypographyId,
@@ -495,21 +592,66 @@ function withTypography(editor) {
495
592
  Transforms.unsetNodes(editor, "typography", { at: normalizationPath });
496
593
  return;
497
594
  }
595
+ if (Text.isText(normalizationNode) && (normalizationNode == null ? void 0 : normalizationNode.slice) != null) {
596
+ Transforms.unsetNodes(editor, "slice", { at: normalizationPath });
597
+ return;
598
+ }
498
599
  normalizeNode(entry);
499
600
  };
500
601
  return editor;
501
602
  }
502
- function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value) {
503
- var _a;
504
- if (!editor.selection)
505
- return;
506
- const rootElements = Editor.nodes(editor, {
507
- match: (_, path) => path.length === 1,
508
- at: Editor.unhangRange(editor, editor.selection)
603
+ function unhangRange(editor, range) {
604
+ let [start, end] = Range.edges(range);
605
+ if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range)) {
606
+ return range;
607
+ }
608
+ const endBlock = Editor.above(editor, {
609
+ at: end,
610
+ match: (n) => Element.isElement(n) && Editor.isBlock(editor, n)
509
611
  });
612
+ const blockPath = endBlock ? endBlock[1] : [];
613
+ const first = Editor.start(editor, start);
614
+ const before = { anchor: first, focus: end };
615
+ let skip = true;
616
+ for (const [node, path] of Editor.nodes(editor, {
617
+ at: before,
618
+ match: Text.isText,
619
+ reverse: true
620
+ })) {
621
+ if (skip) {
622
+ skip = false;
623
+ continue;
624
+ }
625
+ if (node.text !== "" || Path.isBefore(path, blockPath)) {
626
+ end = { path, offset: node.text.length };
627
+ break;
628
+ }
629
+ }
630
+ return { anchor: start, focus: end };
631
+ }
632
+ function getSelection(editor) {
633
+ if (editor.selection)
634
+ return unhangRange(editor, editor.selection);
635
+ return {
636
+ anchor: Editor.start(editor, []),
637
+ focus: Editor.end(editor, [])
638
+ };
639
+ }
640
+ function getBlocksInSelection(editor) {
641
+ return Array.from(Editor.nodes(editor, {
642
+ at: getSelection(editor),
643
+ match: (node) => ElementUtils.isRootBlock(node)
644
+ })).filter((entry) => ElementUtils.isRootBlock(entry[0]));
645
+ }
646
+ function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value, options) {
647
+ var _a, _b;
648
+ const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
649
+ if (!at)
650
+ return;
651
+ const rootElements = getBlocksInSelection(editor);
510
652
  for (const [node, path] of rootElements) {
511
653
  if (ElementUtils.isBlock(node)) {
512
- const deviceValues = (_a = node[key]) != null ? _a : [];
654
+ const deviceValues = (_b = node[key]) != null ? _b : [];
513
655
  const currentDeviceValue = findBreakpointOverride(breakpoints, deviceValues, deviceId, (v) => v);
514
656
  const nextDeviceValue = __spreadProps(__spreadValues({}, currentDeviceValue), {
515
657
  deviceId,
@@ -523,12 +665,7 @@ function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value) {
523
665
  }
524
666
  function clearBlockKeyForDevice(editor, deviceId, key) {
525
667
  var _a;
526
- if (!editor.selection)
527
- return;
528
- const rootElements = Editor.nodes(editor, {
529
- match: (_, path) => path.length === 1,
530
- at: Editor.unhangRange(editor, editor.selection)
531
- });
668
+ const rootElements = getBlocksInSelection(editor);
532
669
  for (const [node, path] of rootElements) {
533
670
  if (ElementUtils.isBlock(node)) {
534
671
  const deviceOverrides = (_a = node[key]) != null ? _a : [];
@@ -538,12 +675,29 @@ function clearBlockKeyForDevice(editor, deviceId, key) {
538
675
  }
539
676
  }
540
677
  }
678
+ function wrapInline(editor, inline) {
679
+ Transforms.wrapNodes(editor, inline, {
680
+ at: getSelection(editor),
681
+ split: true
682
+ });
683
+ }
684
+ function unwrapInline(editor, type) {
685
+ Transforms.unwrapNodes(editor, {
686
+ match: (node) => ElementUtils.isInline(node) && node.type === type,
687
+ at: getSelection(editor)
688
+ });
689
+ }
541
690
  const Block = {
542
691
  setBlockKeyForDevice,
543
- clearBlockKeyForDevice
692
+ clearBlockKeyForDevice,
693
+ wrapInline,
694
+ unwrapInline
544
695
  };
545
696
  function withBlock(editor) {
546
697
  const { normalizeNode } = editor;
698
+ editor.isInline = (entry) => {
699
+ return ElementUtils.isInline(entry);
700
+ };
547
701
  editor.normalizeNode = (entry) => {
548
702
  var _a;
549
703
  const [normalizationNode, normalizationPath] = entry;