@makeswift/runtime 0.8.6 → 0.8.8
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 +44 -10
- package/dist/state/breakpoints.cjs.js.map +1 -1
- package/dist/state/breakpoints.es.js +44 -10
- package/dist/state/breakpoints.es.js.map +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +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 +3 -4
- package/dist/types/src/state/modules/breakpoints.d.ts.map +1 -1
- package/dist/types/src/state/modules/breakpoints.test.d.ts +2 -0
- package/dist/types/src/state/modules/breakpoints.test.d.ts.map +1 -0
- 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.cjs5.js
CHANGED
|
@@ -30,11 +30,14 @@ var isHotkey__default = /* @__PURE__ */ _interopDefaultLegacy(isHotkey);
|
|
|
30
30
|
const LIST_ITEM_CHILD_POSITION = 0;
|
|
31
31
|
const LIST_ITEM_LIST_POSITION = 1;
|
|
32
32
|
const ElementUtils = {
|
|
33
|
+
isRootBlock(node) {
|
|
34
|
+
return slate.Element.isElement(node) && (slate.Element.isElementType(node, descriptors.BlockType.Paragraph) || slate.Element.isElementType(node, descriptors.BlockType.Heading1) || slate.Element.isElementType(node, descriptors.BlockType.Heading2) || slate.Element.isElementType(node, descriptors.BlockType.Heading3) || slate.Element.isElementType(node, descriptors.BlockType.Heading3) || slate.Element.isElementType(node, descriptors.BlockType.Heading4) || slate.Element.isElementType(node, descriptors.BlockType.Heading5) || slate.Element.isElementType(node, descriptors.BlockType.Heading6) || slate.Element.isElementType(node, descriptors.BlockType.BlockQuote) || slate.Element.isElementType(node, descriptors.BlockType.UnorderedList) || slate.Element.isElementType(node, descriptors.BlockType.OrderedList));
|
|
35
|
+
},
|
|
33
36
|
isBlock(node) {
|
|
34
|
-
return slate.Element.isElement(node) && (
|
|
37
|
+
return slate.Element.isElement(node) && (this.isRootBlock(node) || slate.Element.isElementType(node, descriptors.BlockType.ListItem) || slate.Element.isElementType(node, descriptors.BlockType.ListItemChild));
|
|
35
38
|
},
|
|
36
39
|
isInline(node) {
|
|
37
|
-
return slate.Element.
|
|
40
|
+
return slate.Element.isElementType(node, descriptors.InlineType.Code) || slate.Element.isElementType(node, descriptors.InlineType.Link) || slate.Element.isElementType(node, descriptors.InlineType.SubScript) || slate.Element.isElementType(node, descriptors.InlineType.SuperScript);
|
|
38
41
|
},
|
|
39
42
|
isConvertibleToListTextNode(node) {
|
|
40
43
|
return !this.isList(node) && !this.isListItem(node) && !this.isListItemChild(node);
|
|
@@ -65,7 +68,7 @@ const ElementUtils = {
|
|
|
65
68
|
},
|
|
66
69
|
createListItem() {
|
|
67
70
|
return {
|
|
68
|
-
children: [this.
|
|
71
|
+
children: [this.createListItemChild()],
|
|
69
72
|
type: descriptors.BlockType.ListItem
|
|
70
73
|
};
|
|
71
74
|
},
|
|
@@ -78,18 +81,26 @@ const ElementUtils = {
|
|
|
78
81
|
};
|
|
79
82
|
const EditorUtils = {
|
|
80
83
|
getFirstAncestorList(editor, path) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
try {
|
|
85
|
+
const parentList = slate.Editor.above(editor, {
|
|
86
|
+
at: path,
|
|
87
|
+
match: (node) => ElementUtils.isList(node)
|
|
88
|
+
});
|
|
89
|
+
return parentList != null ? parentList : null;
|
|
90
|
+
} catch (e) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
86
93
|
},
|
|
87
94
|
getFirstAncestorListItem(editor, path) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
try {
|
|
96
|
+
const parentListItem = slate.Editor.above(editor, {
|
|
97
|
+
at: path,
|
|
98
|
+
match: (node) => ElementUtils.isListItem(node)
|
|
99
|
+
});
|
|
100
|
+
return parentListItem != null ? parentListItem : null;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
93
104
|
}
|
|
94
105
|
};
|
|
95
106
|
function filterForSubtreeRoots(entries) {
|
|
@@ -213,10 +224,17 @@ function unwrapPath(editor, listItemPath) {
|
|
|
213
224
|
}
|
|
214
225
|
});
|
|
215
226
|
}
|
|
216
|
-
function unwrapList(editor) {
|
|
217
|
-
|
|
227
|
+
function unwrapList(editor, options) {
|
|
228
|
+
var _a;
|
|
229
|
+
const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
|
|
230
|
+
if (!at)
|
|
218
231
|
return;
|
|
219
|
-
const listItems =
|
|
232
|
+
const listItems = Array.from(slate.Editor.nodes(editor, {
|
|
233
|
+
at,
|
|
234
|
+
match: (node) => {
|
|
235
|
+
return slate.Element.isElement(node) && ElementUtils.isListItem(node);
|
|
236
|
+
}
|
|
237
|
+
}));
|
|
220
238
|
const subRoots = filterForSubtreeRoots(listItems);
|
|
221
239
|
const refs = subRoots.map(([_, path]) => slate.Editor.pathRef(editor, path));
|
|
222
240
|
refs.forEach((ref) => {
|
|
@@ -227,10 +245,12 @@ function unwrapList(editor) {
|
|
|
227
245
|
});
|
|
228
246
|
}
|
|
229
247
|
function wrapList(editor, options = { type: descriptors.BlockType.UnorderedList }) {
|
|
230
|
-
|
|
248
|
+
var _a;
|
|
249
|
+
const at = (_a = options.at) != null ? _a : editor.selection;
|
|
250
|
+
if (!at)
|
|
231
251
|
return;
|
|
232
252
|
const nonListEntries = Array.from(slate.Editor.nodes(editor, {
|
|
233
|
-
at
|
|
253
|
+
at,
|
|
234
254
|
match: (node) => {
|
|
235
255
|
return slate.Element.isElement(node) && ElementUtils.isConvertibleToListTextNode(node);
|
|
236
256
|
}
|
|
@@ -244,6 +264,7 @@ function wrapList(editor, options = { type: descriptors.BlockType.UnorderedList
|
|
|
244
264
|
at: path
|
|
245
265
|
});
|
|
246
266
|
slate.Transforms.wrapNodes(editor, ElementUtils.createListItem(), {
|
|
267
|
+
match: (node) => ElementUtils.isListItemChild(node),
|
|
247
268
|
at: path
|
|
248
269
|
});
|
|
249
270
|
slate.Transforms.wrapNodes(editor, ElementUtils.createList(options.type), {
|
|
@@ -255,18 +276,20 @@ function wrapList(editor, options = { type: descriptors.BlockType.UnorderedList
|
|
|
255
276
|
});
|
|
256
277
|
}
|
|
257
278
|
function toggleList(editor, options = { type: descriptors.BlockType.UnorderedList }) {
|
|
258
|
-
|
|
279
|
+
var _a;
|
|
280
|
+
const at = (_a = options.at) != null ? _a : editor.selection;
|
|
281
|
+
if (at == null)
|
|
259
282
|
return;
|
|
260
|
-
const start = LocationUtils.getStartPath(
|
|
283
|
+
const start = LocationUtils.getStartPath(at);
|
|
261
284
|
const ancestorPath = slate.Path.ancestors(start).at(1);
|
|
262
285
|
if (!ancestorPath || !slate.Node.has(editor, ancestorPath))
|
|
263
286
|
return;
|
|
264
287
|
const ancestor = slate.Node.get(editor, ancestorPath);
|
|
265
288
|
if (!ElementUtils.isList(ancestor)) {
|
|
266
|
-
return wrapList(editor, { type: options.type });
|
|
289
|
+
return wrapList(editor, { type: options.type, at });
|
|
267
290
|
}
|
|
268
291
|
if (ancestor.type === options.type) {
|
|
269
|
-
unwrapList(editor);
|
|
292
|
+
unwrapList(editor, { at });
|
|
270
293
|
} else {
|
|
271
294
|
slate.Transforms.setNodes(editor, { type: options.type }, { at: ancestorPath });
|
|
272
295
|
}
|
|
@@ -377,10 +400,10 @@ function withList(editor) {
|
|
|
377
400
|
const nodeChildren = Array.from(slate.Node.children(editor, nodePath));
|
|
378
401
|
const childrenToBeMerged = Array.from(slate.Node.children(editor, nodeToBeMergedPath));
|
|
379
402
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
380
|
-
childrenToBeMerged.forEach(([_, childPath]
|
|
403
|
+
childrenToBeMerged.reverse().forEach(([_, childPath]) => {
|
|
381
404
|
slate.Transforms.moveNodes(editor, {
|
|
382
405
|
at: childPath,
|
|
383
|
-
to: [...nodePath, nodeChildren.length
|
|
406
|
+
to: [...nodePath, nodeChildren.length]
|
|
384
407
|
});
|
|
385
408
|
});
|
|
386
409
|
slate.Transforms.removeNodes(editor, { at: nodeToBeMergedPath });
|
|
@@ -395,94 +418,168 @@ function withList(editor) {
|
|
|
395
418
|
};
|
|
396
419
|
return editor;
|
|
397
420
|
}
|
|
398
|
-
function clearActiveTypographyStyle(editor) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
at
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
if (slate.Text.isText(node)) {
|
|
407
|
-
const typography = __spreadProps(__spreadValues({}, node.typography), {
|
|
408
|
-
style: []
|
|
409
|
-
});
|
|
421
|
+
function clearActiveTypographyStyle(editor, options) {
|
|
422
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
423
|
+
var _a;
|
|
424
|
+
const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
|
|
425
|
+
if (!at)
|
|
426
|
+
return;
|
|
427
|
+
const atRef = slate.Editor.rangeRef(editor, at);
|
|
428
|
+
if (atRef.current) {
|
|
410
429
|
slate.Transforms.setNodes(editor, {
|
|
411
|
-
|
|
412
|
-
}, {
|
|
430
|
+
slice: true
|
|
431
|
+
}, {
|
|
432
|
+
at: atRef.current,
|
|
433
|
+
match: (node) => slate.Text.isText(node),
|
|
434
|
+
split: slate.Range.isExpanded(atRef.current)
|
|
435
|
+
});
|
|
413
436
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
437
|
+
if (atRef.current) {
|
|
438
|
+
const textNodes = Array.from(slate.Editor.nodes(editor, {
|
|
439
|
+
at: atRef.current,
|
|
440
|
+
match: (node) => slate.Text.isText(node) && node.slice === true
|
|
441
|
+
}));
|
|
442
|
+
for (const [node, path] of textNodes) {
|
|
443
|
+
if (slate.Text.isText(node)) {
|
|
444
|
+
const typography = __spreadProps(__spreadValues({}, node.typography), {
|
|
445
|
+
style: []
|
|
446
|
+
});
|
|
447
|
+
slate.Transforms.setNodes(editor, {
|
|
448
|
+
typography
|
|
449
|
+
}, { at: path });
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
atRef.unref();
|
|
423
454
|
});
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
455
|
+
}
|
|
456
|
+
function clearDeviceActiveTypography(editor, currentDeviceId, options) {
|
|
457
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
458
|
+
var _a, _b, _c;
|
|
459
|
+
const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
|
|
460
|
+
if (!at)
|
|
461
|
+
return;
|
|
462
|
+
const atRef = slate.Editor.rangeRef(editor, at);
|
|
463
|
+
if (atRef.current) {
|
|
429
464
|
slate.Transforms.setNodes(editor, {
|
|
430
|
-
|
|
431
|
-
}, {
|
|
465
|
+
slice: true
|
|
466
|
+
}, {
|
|
467
|
+
at: atRef.current,
|
|
468
|
+
match: (node) => slate.Text.isText(node),
|
|
469
|
+
split: slate.Range.isExpanded(atRef.current)
|
|
470
|
+
});
|
|
432
471
|
}
|
|
433
|
-
|
|
472
|
+
if (atRef.current) {
|
|
473
|
+
const textNodes = Array.from(slate.Editor.nodes(editor, {
|
|
474
|
+
at: atRef.current,
|
|
475
|
+
match: (node) => slate.Text.isText(node) && node.slice === true
|
|
476
|
+
}));
|
|
477
|
+
for (const [node, path] of textNodes) {
|
|
478
|
+
if (slate.Text.isText(node)) {
|
|
479
|
+
const typography = __spreadProps(__spreadValues({}, node.typography), {
|
|
480
|
+
style: (_c = (_b = node == null ? void 0 : node.typography) == null ? void 0 : _b.style.filter(({ deviceId }) => deviceId !== currentDeviceId)) != null ? _c : []
|
|
481
|
+
});
|
|
482
|
+
slate.Transforms.setNodes(editor, {
|
|
483
|
+
typography
|
|
484
|
+
}, { at: path });
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
atRef.unref();
|
|
489
|
+
});
|
|
434
490
|
}
|
|
435
|
-
function detachActiveTypography(editor, value) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
at
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (slate.Text.isText(node)) {
|
|
491
|
+
function detachActiveTypography(editor, value, options) {
|
|
492
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
493
|
+
var _a;
|
|
494
|
+
const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
|
|
495
|
+
if (!at)
|
|
496
|
+
return;
|
|
497
|
+
const atRef = slate.Editor.rangeRef(editor, at);
|
|
498
|
+
if (atRef.current) {
|
|
444
499
|
slate.Transforms.setNodes(editor, {
|
|
445
|
-
|
|
446
|
-
|
|
500
|
+
slice: true
|
|
501
|
+
}, {
|
|
502
|
+
at: atRef.current,
|
|
503
|
+
match: (node) => slate.Text.isText(node),
|
|
504
|
+
split: slate.Range.isExpanded(atRef.current)
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
if (atRef.current) {
|
|
508
|
+
const textNodes = Array.from(slate.Editor.nodes(editor, {
|
|
509
|
+
at: atRef.current,
|
|
510
|
+
match: (node) => slate.Text.isText(node) && node.slice === true
|
|
511
|
+
}));
|
|
512
|
+
for (const [node, path] of textNodes) {
|
|
513
|
+
if (slate.Text.isText(node)) {
|
|
514
|
+
slate.Transforms.setNodes(editor, {
|
|
515
|
+
typography: {
|
|
516
|
+
style: value
|
|
517
|
+
}
|
|
518
|
+
}, { at: path });
|
|
447
519
|
}
|
|
448
|
-
}
|
|
520
|
+
}
|
|
449
521
|
}
|
|
522
|
+
atRef.unref();
|
|
450
523
|
});
|
|
451
524
|
}
|
|
452
|
-
function setActiveTypographyId(editor, id) {
|
|
525
|
+
function setActiveTypographyId(editor, id, options) {
|
|
526
|
+
var _a;
|
|
527
|
+
const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
|
|
528
|
+
if (!at)
|
|
529
|
+
return;
|
|
453
530
|
slate.Transforms.setNodes(editor, {
|
|
454
531
|
typography: {
|
|
455
532
|
id,
|
|
456
533
|
style: []
|
|
457
534
|
}
|
|
458
535
|
}, {
|
|
459
|
-
|
|
536
|
+
at,
|
|
537
|
+
match: (node) => slate.Text.isText(node),
|
|
538
|
+
split: slate.Range.isExpanded(at)
|
|
460
539
|
});
|
|
461
540
|
}
|
|
462
|
-
function setActiveTypographyStyle(editor, breakpoints, deviceId, prop, value) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
for (const [node, path] of textNodes) {
|
|
471
|
-
if (slate.Text.isText(node)) {
|
|
472
|
-
const deviceOverrides = (_b = (_a = node == null ? void 0 : node.typography) == null ? void 0 : _a.style) != null ? _b : [];
|
|
473
|
-
const deviceStyle = state_breakpoints.findBreakpointOverride(breakpoints, deviceOverrides, deviceId, (v) => v) || { value: {} };
|
|
474
|
-
const nextDeviceStyle = {
|
|
475
|
-
deviceId,
|
|
476
|
-
value: __spreadProps(__spreadValues({}, deviceStyle.value), { [prop]: value })
|
|
477
|
-
};
|
|
478
|
-
const nextTypography = __spreadProps(__spreadValues({}, node.typography), {
|
|
479
|
-
style: [...deviceOverrides.filter((v) => v.deviceId !== deviceId), nextDeviceStyle]
|
|
480
|
-
});
|
|
541
|
+
function setActiveTypographyStyle(editor, breakpoints, deviceId, prop, value, options) {
|
|
542
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
543
|
+
var _a, _b, _c;
|
|
544
|
+
const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
|
|
545
|
+
if (!at)
|
|
546
|
+
return;
|
|
547
|
+
const atRef = slate.Editor.rangeRef(editor, at);
|
|
548
|
+
if (atRef.current) {
|
|
481
549
|
slate.Transforms.setNodes(editor, {
|
|
482
|
-
|
|
483
|
-
}, {
|
|
550
|
+
slice: true
|
|
551
|
+
}, {
|
|
552
|
+
at: atRef.current,
|
|
553
|
+
match: (node) => slate.Text.isText(node),
|
|
554
|
+
split: slate.Range.isExpanded(atRef.current)
|
|
555
|
+
});
|
|
484
556
|
}
|
|
485
|
-
|
|
557
|
+
if (atRef.current) {
|
|
558
|
+
const textNodes = Array.from(slate.Editor.nodes(editor, {
|
|
559
|
+
at: atRef.current,
|
|
560
|
+
match: (node) => slate.Text.isText(node) && node.slice === true
|
|
561
|
+
}));
|
|
562
|
+
for (const [node, path] of textNodes) {
|
|
563
|
+
if (slate.Text.isText(node)) {
|
|
564
|
+
const deviceOverrides = (_c = (_b = node == null ? void 0 : node.typography) == null ? void 0 : _b.style) != null ? _c : [];
|
|
565
|
+
const deviceStyle = state_breakpoints.findBreakpointOverride(breakpoints, deviceOverrides, deviceId, (v) => v) || {
|
|
566
|
+
value: {}
|
|
567
|
+
};
|
|
568
|
+
const nextDeviceStyle = {
|
|
569
|
+
deviceId,
|
|
570
|
+
value: __spreadProps(__spreadValues({}, deviceStyle.value), { [prop]: value })
|
|
571
|
+
};
|
|
572
|
+
const nextTypography = __spreadProps(__spreadValues({}, node.typography), {
|
|
573
|
+
style: [...deviceOverrides.filter((v) => v.deviceId !== deviceId), nextDeviceStyle]
|
|
574
|
+
});
|
|
575
|
+
slate.Transforms.setNodes(editor, {
|
|
576
|
+
typography: nextTypography
|
|
577
|
+
}, { at: path });
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
atRef.unref();
|
|
582
|
+
});
|
|
486
583
|
}
|
|
487
584
|
const Typography = {
|
|
488
585
|
setActiveTypographyId,
|
|
@@ -500,21 +597,66 @@ function withTypography(editor) {
|
|
|
500
597
|
slate.Transforms.unsetNodes(editor, "typography", { at: normalizationPath });
|
|
501
598
|
return;
|
|
502
599
|
}
|
|
600
|
+
if (slate.Text.isText(normalizationNode) && (normalizationNode == null ? void 0 : normalizationNode.slice) != null) {
|
|
601
|
+
slate.Transforms.unsetNodes(editor, "slice", { at: normalizationPath });
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
503
604
|
normalizeNode(entry);
|
|
504
605
|
};
|
|
505
606
|
return editor;
|
|
506
607
|
}
|
|
507
|
-
function
|
|
508
|
-
|
|
509
|
-
if (
|
|
510
|
-
return;
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
at:
|
|
608
|
+
function unhangRange(editor, range) {
|
|
609
|
+
let [start, end] = slate.Range.edges(range);
|
|
610
|
+
if (start.offset !== 0 || end.offset !== 0 || slate.Range.isCollapsed(range)) {
|
|
611
|
+
return range;
|
|
612
|
+
}
|
|
613
|
+
const endBlock = slate.Editor.above(editor, {
|
|
614
|
+
at: end,
|
|
615
|
+
match: (n) => slate.Element.isElement(n) && slate.Editor.isBlock(editor, n)
|
|
514
616
|
});
|
|
617
|
+
const blockPath = endBlock ? endBlock[1] : [];
|
|
618
|
+
const first = slate.Editor.start(editor, start);
|
|
619
|
+
const before = { anchor: first, focus: end };
|
|
620
|
+
let skip = true;
|
|
621
|
+
for (const [node, path] of slate.Editor.nodes(editor, {
|
|
622
|
+
at: before,
|
|
623
|
+
match: slate.Text.isText,
|
|
624
|
+
reverse: true
|
|
625
|
+
})) {
|
|
626
|
+
if (skip) {
|
|
627
|
+
skip = false;
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
if (node.text !== "" || slate.Path.isBefore(path, blockPath)) {
|
|
631
|
+
end = { path, offset: node.text.length };
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return { anchor: start, focus: end };
|
|
636
|
+
}
|
|
637
|
+
function getSelection(editor) {
|
|
638
|
+
if (editor.selection)
|
|
639
|
+
return unhangRange(editor, editor.selection);
|
|
640
|
+
return {
|
|
641
|
+
anchor: slate.Editor.start(editor, []),
|
|
642
|
+
focus: slate.Editor.end(editor, [])
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
function getBlocksInSelection(editor) {
|
|
646
|
+
return Array.from(slate.Editor.nodes(editor, {
|
|
647
|
+
at: getSelection(editor),
|
|
648
|
+
match: (node) => ElementUtils.isRootBlock(node)
|
|
649
|
+
})).filter((entry) => ElementUtils.isRootBlock(entry[0]));
|
|
650
|
+
}
|
|
651
|
+
function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value, options) {
|
|
652
|
+
var _a, _b;
|
|
653
|
+
const at = (_a = options == null ? void 0 : options.at) != null ? _a : editor.selection;
|
|
654
|
+
if (!at)
|
|
655
|
+
return;
|
|
656
|
+
const rootElements = getBlocksInSelection(editor);
|
|
515
657
|
for (const [node, path] of rootElements) {
|
|
516
658
|
if (ElementUtils.isBlock(node)) {
|
|
517
|
-
const deviceValues = (
|
|
659
|
+
const deviceValues = (_b = node[key]) != null ? _b : [];
|
|
518
660
|
const currentDeviceValue = state_breakpoints.findBreakpointOverride(breakpoints, deviceValues, deviceId, (v) => v);
|
|
519
661
|
const nextDeviceValue = __spreadProps(__spreadValues({}, currentDeviceValue), {
|
|
520
662
|
deviceId,
|
|
@@ -528,12 +670,7 @@ function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value) {
|
|
|
528
670
|
}
|
|
529
671
|
function clearBlockKeyForDevice(editor, deviceId, key) {
|
|
530
672
|
var _a;
|
|
531
|
-
|
|
532
|
-
return;
|
|
533
|
-
const rootElements = slate.Editor.nodes(editor, {
|
|
534
|
-
match: (_, path) => path.length === 1,
|
|
535
|
-
at: slate.Editor.unhangRange(editor, editor.selection)
|
|
536
|
-
});
|
|
673
|
+
const rootElements = getBlocksInSelection(editor);
|
|
537
674
|
for (const [node, path] of rootElements) {
|
|
538
675
|
if (ElementUtils.isBlock(node)) {
|
|
539
676
|
const deviceOverrides = (_a = node[key]) != null ? _a : [];
|
|
@@ -543,12 +680,29 @@ function clearBlockKeyForDevice(editor, deviceId, key) {
|
|
|
543
680
|
}
|
|
544
681
|
}
|
|
545
682
|
}
|
|
683
|
+
function wrapInline(editor, inline) {
|
|
684
|
+
slate.Transforms.wrapNodes(editor, inline, {
|
|
685
|
+
at: getSelection(editor),
|
|
686
|
+
split: true
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
function unwrapInline(editor, type) {
|
|
690
|
+
slate.Transforms.unwrapNodes(editor, {
|
|
691
|
+
match: (node) => ElementUtils.isInline(node) && node.type === type,
|
|
692
|
+
at: getSelection(editor)
|
|
693
|
+
});
|
|
694
|
+
}
|
|
546
695
|
const Block = {
|
|
547
696
|
setBlockKeyForDevice,
|
|
548
|
-
clearBlockKeyForDevice
|
|
697
|
+
clearBlockKeyForDevice,
|
|
698
|
+
wrapInline,
|
|
699
|
+
unwrapInline
|
|
549
700
|
};
|
|
550
701
|
function withBlock(editor) {
|
|
551
702
|
const { normalizeNode } = editor;
|
|
703
|
+
editor.isInline = (entry) => {
|
|
704
|
+
return ElementUtils.isInline(entry);
|
|
705
|
+
};
|
|
552
706
|
editor.normalizeNode = (entry) => {
|
|
553
707
|
var _a;
|
|
554
708
|
const [normalizationNode, normalizationPath] = entry;
|