@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.
- package/dist/LiveProvider.cjs.js +4 -3
- package/dist/LiveProvider.cjs.js.map +1 -1
- package/dist/LiveProvider.es.js +5 -4
- package/dist/LiveProvider.es.js.map +1 -1
- package/dist/PreviewProvider.cjs.js +4 -3
- package/dist/PreviewProvider.cjs.js.map +1 -1
- package/dist/PreviewProvider.es.js +5 -4
- package/dist/PreviewProvider.es.js.map +1 -1
- package/dist/actions.es.js +1 -1
- package/dist/constants.cjs.js +6 -2
- package/dist/constants.cjs.js.map +1 -1
- package/dist/constants.es.js +8 -4
- package/dist/constants.es.js.map +1 -1
- package/dist/index.cjs.js +83 -50
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs5.js +260 -106
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.cjs7.js.map +1 -1
- package/dist/index.es.js +86 -52
- package/dist/index.es.js.map +1 -1
- package/dist/index.es5.js +260 -106
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es7.js +1 -1
- package/dist/index.es7.js.map +1 -1
- package/dist/leaf.es.js +1 -1
- package/dist/next.es.js +1 -1
- package/dist/state/breakpoints.cjs.js +2 -2
- package/dist/state/breakpoints.cjs.js.map +1 -1
- package/dist/state/breakpoints.es.js +2 -2
- package/dist/state/breakpoints.es.js.map +1 -1
- package/dist/types/src/next/api-handler/handlers/manifest.d.ts +1 -0
- package/dist/types/src/next/api-handler/handlers/manifest.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +4 -1
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/dist/types/src/next/index.d.ts +3 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/components/LiveProvider.d.ts +3 -1
- package/dist/types/src/runtimes/react/components/LiveProvider.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts +3 -1
- package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/index.d.ts +19 -5
- package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
- package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts +2 -2
- package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts.map +1 -1
- package/dist/types/src/slate/BlockPlugin/index.d.ts +4 -0
- package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts +7 -4
- package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts.map +1 -1
- package/dist/types/src/slate/BlockPlugin/types.d.ts +2 -2
- package/dist/types/src/slate/BlockPlugin/types.d.ts.map +1 -1
- package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts +4 -0
- package/dist/types/src/slate/BlockPlugin/unwrapInline.d.ts.map +1 -0
- package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts +4 -0
- package/dist/types/src/slate/BlockPlugin/wrapInline.d.ts.map +1 -0
- package/dist/types/src/slate/ListPlugin/toggleList.d.ts +2 -1
- package/dist/types/src/slate/ListPlugin/toggleList.d.ts.map +1 -1
- package/dist/types/src/slate/ListPlugin/unwrapList.d.ts +6 -2
- package/dist/types/src/slate/ListPlugin/unwrapList.d.ts.map +1 -1
- package/dist/types/src/slate/ListPlugin/utils/getSelectedListItems.d.ts +0 -1
- package/dist/types/src/slate/ListPlugin/utils/getSelectedListItems.d.ts.map +1 -1
- package/dist/types/src/slate/ListPlugin/wrapList.d.ts +2 -1
- package/dist/types/src/slate/ListPlugin/wrapList.d.ts.map +1 -1
- package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts +6 -2
- package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts.map +1 -1
- package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts +6 -2
- package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts.map +1 -1
- package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts +6 -2
- package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts.map +1 -1
- package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts +6 -2
- package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts.map +1 -1
- package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts +6 -2
- package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -1
- package/dist/types/src/slate/selectors.d.ts +19 -0
- package/dist/types/src/slate/selectors.d.ts.map +1 -0
- package/dist/types/src/slate/utils/editor.d.ts.map +1 -1
- package/dist/types/src/slate/utils/element.d.ts +2 -1
- package/dist/types/src/slate/utils/element.d.ts.map +1 -1
- package/dist/types/src/slate/utils/unhangRange.d.ts +10 -0
- package/dist/types/src/slate/utils/unhangRange.d.ts.map +1 -0
- package/dist/types/src/state/modules/breakpoints.d.ts +1 -1
- package/dist/types/src/state/modules/breakpoints.d.ts.map +1 -1
- package/dist/types/src/state/react-page.d.ts +2 -1
- package/dist/types/src/state/react-page.d.ts.map +1 -1
- package/dist/types/src/utils/isNonNullable.d.ts +2 -0
- package/dist/types/src/utils/isNonNullable.d.ts.map +1 -0
- 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) && (
|
|
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.
|
|
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.
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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(
|
|
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]
|
|
398
|
+
childrenToBeMerged.reverse().forEach(([_, childPath]) => {
|
|
376
399
|
Transforms.moveNodes(editor, {
|
|
377
400
|
at: childPath,
|
|
378
|
-
to: [...nodePath, nodeChildren.length
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
at
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
-
|
|
407
|
-
}, {
|
|
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
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
-
|
|
426
|
-
}, {
|
|
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
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
at
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
441
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
|
|
478
|
-
}, {
|
|
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
|
|
503
|
-
|
|
504
|
-
if (
|
|
505
|
-
return;
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
at:
|
|
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 = (
|
|
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
|
-
|
|
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;
|