@portabletext/editor 1.52.1 → 1.52.3
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/lib/index.cjs +42 -68
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +43 -69
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/Editable.tsx +13 -12
- package/src/editor/plugins/with-plugins.ts +10 -15
- package/src/internal-utils/create-placeholder-block.ts +2 -1
- package/src/operations/behavior.operation.delete.ts +6 -1
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +0 -51
package/lib/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$g = require("debug"), slateDom = require("slate-dom"), selectionPoint = require("./_chunks-cjs/selection-point.cjs"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$
|
|
7
|
+
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$g), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
|
|
8
8
|
function EditorEventListener(props) {
|
|
9
9
|
const $ = reactCompilerRuntime.c(5), editor = useEditor.useEditor(), on = useEffectEvent.useEffectEvent(props.on);
|
|
10
10
|
let t0;
|
|
@@ -1483,7 +1483,7 @@ function getEditorSnapshot({
|
|
|
1483
1483
|
}
|
|
1484
1484
|
};
|
|
1485
1485
|
}
|
|
1486
|
-
const debug$
|
|
1486
|
+
const debug$f = debugWithName("plugin:withPortableTextMarkModel");
|
|
1487
1487
|
function createWithPortableTextMarkModel(editorActor) {
|
|
1488
1488
|
return function(editor) {
|
|
1489
1489
|
const {
|
|
@@ -1497,7 +1497,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1497
1497
|
for (const [child, childPath] of children) {
|
|
1498
1498
|
const nextNode = node.children[childPath[1] + 1];
|
|
1499
1499
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
1500
|
-
debug$
|
|
1500
|
+
debug$f("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
1501
1501
|
type: "normalizing"
|
|
1502
1502
|
}), slate.Transforms.mergeNodes(editor, {
|
|
1503
1503
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -1510,7 +1510,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1510
1510
|
}
|
|
1511
1511
|
}
|
|
1512
1512
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
1513
|
-
debug$
|
|
1513
|
+
debug$f("Adding .markDefs to block node"), editorActor.send({
|
|
1514
1514
|
type: "normalizing"
|
|
1515
1515
|
}), slate.Transforms.setNodes(editor, {
|
|
1516
1516
|
markDefs: []
|
|
@@ -1522,7 +1522,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1522
1522
|
return;
|
|
1523
1523
|
}
|
|
1524
1524
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
1525
|
-
debug$
|
|
1525
|
+
debug$f("Adding .marks to span node"), editorActor.send({
|
|
1526
1526
|
type: "normalizing"
|
|
1527
1527
|
}), slate.Transforms.setNodes(editor, {
|
|
1528
1528
|
marks: []
|
|
@@ -1536,7 +1536,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1536
1536
|
if (editor.isTextSpan(node)) {
|
|
1537
1537
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
1538
1538
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
1539
|
-
debug$
|
|
1539
|
+
debug$f("Removing annotations from empty span node"), editorActor.send({
|
|
1540
1540
|
type: "normalizing"
|
|
1541
1541
|
}), slate.Transforms.setNodes(editor, {
|
|
1542
1542
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -1554,7 +1554,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1554
1554
|
if (editor.isTextSpan(child)) {
|
|
1555
1555
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
1556
1556
|
if (orphanedAnnotations.length > 0) {
|
|
1557
|
-
debug$
|
|
1557
|
+
debug$f("Removing orphaned annotations from span node"), editorActor.send({
|
|
1558
1558
|
type: "normalizing"
|
|
1559
1559
|
}), slate.Transforms.setNodes(editor, {
|
|
1560
1560
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1572,7 +1572,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1572
1572
|
if (editor.isTextBlock(block)) {
|
|
1573
1573
|
const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
1574
1574
|
if (orphanedAnnotations.length > 0) {
|
|
1575
|
-
debug$
|
|
1575
|
+
debug$f("Removing orphaned annotations from span node"), editorActor.send({
|
|
1576
1576
|
type: "normalizing"
|
|
1577
1577
|
}), slate.Transforms.setNodes(editor, {
|
|
1578
1578
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1590,7 +1590,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1590
1590
|
for (const markDef of markDefs)
|
|
1591
1591
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
1592
1592
|
if (markDefs.length !== newMarkDefs.length) {
|
|
1593
|
-
debug$
|
|
1593
|
+
debug$f("Removing duplicate markDefs"), editorActor.send({
|
|
1594
1594
|
type: "normalizing"
|
|
1595
1595
|
}), slate.Transforms.setNodes(editor, {
|
|
1596
1596
|
markDefs: newMarkDefs
|
|
@@ -1605,7 +1605,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1605
1605
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
1606
1606
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
1607
1607
|
if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
|
|
1608
|
-
debug$
|
|
1608
|
+
debug$f("Removing markDef not in use"), editorActor.send({
|
|
1609
1609
|
type: "normalizing"
|
|
1610
1610
|
}), slate.Transforms.setNodes(editor, {
|
|
1611
1611
|
markDefs: newMarkDefs
|
|
@@ -1758,7 +1758,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1758
1758
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
1759
1759
|
if (editor.isTextBlock(targetBlock)) {
|
|
1760
1760
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
1761
|
-
debug$
|
|
1761
|
+
debug$f("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
|
|
1762
1762
|
markDefs: newMarkDefs
|
|
1763
1763
|
}, {
|
|
1764
1764
|
at: targetPath,
|
|
@@ -2468,7 +2468,7 @@ function withUndoStep(editor, fn) {
|
|
|
2468
2468
|
function getCurrentUndoStepId(editor) {
|
|
2469
2469
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
2470
2470
|
}
|
|
2471
|
-
const debug$
|
|
2471
|
+
const debug$e = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2472
2472
|
const state = SAVING.get(editor);
|
|
2473
2473
|
return state === void 0 ? !0 : state;
|
|
2474
2474
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -2481,7 +2481,7 @@ function createWithUndoRedo(options) {
|
|
|
2481
2481
|
const remotePatches = getRemotePatches(editor);
|
|
2482
2482
|
let previousUndoStepId = getCurrentUndoStepId(editor);
|
|
2483
2483
|
options.subscriptions.push(() => {
|
|
2484
|
-
debug$
|
|
2484
|
+
debug$e("Subscribing to patches");
|
|
2485
2485
|
const sub = editorActor.on("patches", ({
|
|
2486
2486
|
patches: patches2,
|
|
2487
2487
|
snapshot
|
|
@@ -2490,7 +2490,7 @@ function createWithUndoRedo(options) {
|
|
|
2490
2490
|
patches2.forEach((patch) => {
|
|
2491
2491
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2492
2492
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2493
|
-
debug$
|
|
2493
|
+
debug$e("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
2494
2494
|
undos: [],
|
|
2495
2495
|
redos: []
|
|
2496
2496
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -2506,7 +2506,7 @@ function createWithUndoRedo(options) {
|
|
|
2506
2506
|
}), previousSnapshot = snapshot;
|
|
2507
2507
|
});
|
|
2508
2508
|
return () => {
|
|
2509
|
-
debug$
|
|
2509
|
+
debug$e("Unsubscribing to patches"), sub.unsubscribe();
|
|
2510
2510
|
};
|
|
2511
2511
|
}), editor.history = {
|
|
2512
2512
|
undos: [],
|
|
@@ -2545,7 +2545,7 @@ function createWithUndoRedo(options) {
|
|
|
2545
2545
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
2546
2546
|
timestamp: /* @__PURE__ */ new Date()
|
|
2547
2547
|
};
|
|
2548
|
-
undos.push(newStep), debug$
|
|
2548
|
+
undos.push(newStep), debug$e("Created new undo step", step);
|
|
2549
2549
|
}
|
|
2550
2550
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
2551
2551
|
undos.shift();
|
|
@@ -2563,7 +2563,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2563
2563
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2564
2564
|
if (undos.length > 0) {
|
|
2565
2565
|
const step = undos[undos.length - 1];
|
|
2566
|
-
if (debug$
|
|
2566
|
+
if (debug$e("Undoing", step), step.operations.length > 0) {
|
|
2567
2567
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2568
2568
|
let transformedOperations = step.operations;
|
|
2569
2569
|
otherPatches.forEach((item) => {
|
|
@@ -2581,7 +2581,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2581
2581
|
});
|
|
2582
2582
|
});
|
|
2583
2583
|
} catch (err) {
|
|
2584
|
-
debug$
|
|
2584
|
+
debug$e("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
2585
2585
|
undos: [],
|
|
2586
2586
|
redos: []
|
|
2587
2587
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -2598,7 +2598,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2598
2598
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2599
2599
|
if (redos.length > 0) {
|
|
2600
2600
|
const step = redos[redos.length - 1];
|
|
2601
|
-
if (debug$
|
|
2601
|
+
if (debug$e("Redoing", step), step.operations.length > 0) {
|
|
2602
2602
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2603
2603
|
let transformedOperations = step.operations;
|
|
2604
2604
|
otherPatches.forEach((item) => {
|
|
@@ -2615,7 +2615,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2615
2615
|
});
|
|
2616
2616
|
});
|
|
2617
2617
|
} catch (err) {
|
|
2618
|
-
debug$
|
|
2618
|
+
debug$e("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
2619
2619
|
undos: [],
|
|
2620
2620
|
redos: []
|
|
2621
2621
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -2633,16 +2633,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2633
2633
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2634
2634
|
_key: blk._key
|
|
2635
2635
|
}, patch.path[0]));
|
|
2636
|
-
return debug$
|
|
2636
|
+
return debug$e(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2637
2637
|
}
|
|
2638
2638
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2639
2639
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2640
2640
|
_key: blk._key
|
|
2641
2641
|
}, patch.path[0]));
|
|
2642
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
2642
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$e("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
2643
2643
|
}
|
|
2644
2644
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2645
|
-
return debug$
|
|
2645
|
+
return debug$e(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2646
2646
|
if (patch.type === "diffMatchPatch") {
|
|
2647
2647
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2648
2648
|
return !operationTargetBlock || !isEqual__default.default({
|
|
@@ -3092,6 +3092,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
3092
3092
|
};
|
|
3093
3093
|
}
|
|
3094
3094
|
}, deleteOperationImplementation = ({
|
|
3095
|
+
context,
|
|
3095
3096
|
operation
|
|
3096
3097
|
}) => {
|
|
3097
3098
|
const anchorBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(operation.at.anchor), focusBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(operation.at.focus), anchorBlockPath = anchorBlockKey !== void 0 ? getBlockPath({
|
|
@@ -3104,7 +3105,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
3104
3105
|
if (operation.at.anchor.path.length === 1 && operation.at.focus.path.length === 1 && anchorBlockPath && focusBlockPath && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
3105
3106
|
slate.Transforms.removeNodes(operation.editor, {
|
|
3106
3107
|
at: [anchorBlockPath[0]]
|
|
3107
|
-
});
|
|
3108
|
+
}), operation.editor.children.length === 0 && slate.Transforms.insertNodes(operation.editor, createPlaceholderBlock(context));
|
|
3108
3109
|
return;
|
|
3109
3110
|
}
|
|
3110
3111
|
const range = toSlateRange(operation.at, operation.editor);
|
|
@@ -4407,7 +4408,7 @@ function withoutPatching(editor, fn) {
|
|
|
4407
4408
|
function isPatching(editor) {
|
|
4408
4409
|
return PATCHING.get(editor);
|
|
4409
4410
|
}
|
|
4410
|
-
const debug$
|
|
4411
|
+
const debug$d = debugWithName("plugin:withPatches");
|
|
4411
4412
|
function createWithPatches({
|
|
4412
4413
|
editorActor,
|
|
4413
4414
|
relayActor,
|
|
@@ -4432,7 +4433,7 @@ function createWithPatches({
|
|
|
4432
4433
|
withoutPatching(editor, () => {
|
|
4433
4434
|
withoutSaving(editor, () => {
|
|
4434
4435
|
for (const patch of patches2) {
|
|
4435
|
-
debug$
|
|
4436
|
+
debug$d.enabled && debug$d(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
4436
4437
|
try {
|
|
4437
4438
|
changed = applyPatch(editor, patch);
|
|
4438
4439
|
} catch (error) {
|
|
@@ -4450,10 +4451,10 @@ function createWithPatches({
|
|
|
4450
4451
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
4451
4452
|
};
|
|
4452
4453
|
return subscriptions.push(() => {
|
|
4453
|
-
debug$
|
|
4454
|
+
debug$d("Subscribing to remote patches");
|
|
4454
4455
|
const sub = editorActor.on("patches", handlePatches);
|
|
4455
4456
|
return () => {
|
|
4456
|
-
debug$
|
|
4457
|
+
debug$d("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
4457
4458
|
};
|
|
4458
4459
|
}), editor.apply = (operation) => {
|
|
4459
4460
|
let patches$1 = [];
|
|
@@ -4507,7 +4508,7 @@ function createWithPatches({
|
|
|
4507
4508
|
}, editor;
|
|
4508
4509
|
};
|
|
4509
4510
|
}
|
|
4510
|
-
const debug$
|
|
4511
|
+
const debug$c = debugWithName("plugin:withPlaceholderBlock");
|
|
4511
4512
|
function createWithPlaceholderBlock(editorActor) {
|
|
4512
4513
|
return function(editor) {
|
|
4513
4514
|
const {
|
|
@@ -4532,7 +4533,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4532
4533
|
const node = op.node;
|
|
4533
4534
|
if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
|
|
4534
4535
|
const nextPath = slate.Path.next(op.path);
|
|
4535
|
-
editor.children[nextPath[0]] || (debug$
|
|
4536
|
+
editor.children[nextPath[0]] || (debug$c("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
4536
4537
|
decorators: []
|
|
4537
4538
|
})));
|
|
4538
4539
|
}
|
|
@@ -4541,36 +4542,6 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4541
4542
|
}, editor;
|
|
4542
4543
|
};
|
|
4543
4544
|
}
|
|
4544
|
-
const debug$c = debugWithName("plugin:withPortableTextBlockStyle");
|
|
4545
|
-
function createWithPortableTextBlockStyle(editorActor) {
|
|
4546
|
-
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
|
|
4547
|
-
return function(editor) {
|
|
4548
|
-
const {
|
|
4549
|
-
normalizeNode
|
|
4550
|
-
} = editor;
|
|
4551
|
-
return editor.normalizeNode = (nodeEntry) => {
|
|
4552
|
-
const [, path] = nodeEntry;
|
|
4553
|
-
for (const op of editor.operations)
|
|
4554
|
-
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !slate.Path.equals(path, op.path)) {
|
|
4555
|
-
const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
|
|
4556
|
-
if (slate.Text.isText(child) && child.text === "") {
|
|
4557
|
-
debug$c(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
4558
|
-
type: "normalizing"
|
|
4559
|
-
}), slate.Transforms.setNodes(editor, {
|
|
4560
|
-
style: defaultStyle
|
|
4561
|
-
}, {
|
|
4562
|
-
at: [op.path[0] + 1],
|
|
4563
|
-
voids: !1
|
|
4564
|
-
}), editorActor.send({
|
|
4565
|
-
type: "done normalizing"
|
|
4566
|
-
});
|
|
4567
|
-
return;
|
|
4568
|
-
}
|
|
4569
|
-
}
|
|
4570
|
-
normalizeNode(nodeEntry);
|
|
4571
|
-
}, editor;
|
|
4572
|
-
};
|
|
4573
|
-
}
|
|
4574
4545
|
debugWithName("plugin:withPortableTextSelections");
|
|
4575
4546
|
function createWithPortableTextSelections(editorActor) {
|
|
4576
4547
|
let prevSelection = null;
|
|
@@ -5063,10 +5034,10 @@ const withPlugins = (editor, options) => {
|
|
|
5063
5034
|
}), withMaxBlocks = createWithMaxBlocks(editorActor), withUndoRedo = createWithUndoRedo({
|
|
5064
5035
|
editorActor,
|
|
5065
5036
|
subscriptions: options.subscriptions
|
|
5066
|
-
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor),
|
|
5037
|
+
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5067
5038
|
editorActor
|
|
5068
5039
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
5069
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(
|
|
5040
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, e))))))))))));
|
|
5070
5041
|
}, debug$a = debugWithName("setup");
|
|
5071
5042
|
function createSlateEditor(config) {
|
|
5072
5043
|
debug$a("Creating new Slate editor instance");
|
|
@@ -10749,18 +10720,21 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
10749
10720
|
debug("No result from custom paste handler, pasting normally");
|
|
10750
10721
|
}, [editorActor, onPaste, portableTextEditor, relayActor, slateEditor]), handleOnFocus = React.useCallback((event_2) => {
|
|
10751
10722
|
if (onFocus && onFocus(event_2), !event_2.isDefaultPrevented()) {
|
|
10752
|
-
|
|
10753
|
-
selection_3 === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), relayActor.send({
|
|
10723
|
+
relayActor.send({
|
|
10754
10724
|
type: "focused",
|
|
10755
10725
|
event: event_2
|
|
10756
10726
|
});
|
|
10757
|
-
const
|
|
10758
|
-
|
|
10727
|
+
const selection_3 = slateEditor.selection ? slateRangeToSelection({
|
|
10728
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
10729
|
+
editor: slateEditor,
|
|
10730
|
+
range: slateEditor.selection
|
|
10731
|
+
}) : null;
|
|
10732
|
+
selection_3 && editorActor.send({
|
|
10759
10733
|
type: "update selection",
|
|
10760
10734
|
selection: selection_3
|
|
10761
10735
|
});
|
|
10762
10736
|
}
|
|
10763
|
-
}, [editorActor, onFocus, slateEditor,
|
|
10737
|
+
}, [editorActor, onFocus, slateEditor, relayActor]), handleClick = React.useCallback((event_3) => {
|
|
10764
10738
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
10765
10739
|
return;
|
|
10766
10740
|
const position_3 = getEventPosition({
|