@portabletext/editor 7.10.8-crx.0 → 7.10.9
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/_chunks-es/selector.is-at-the-start-of-block.js +12 -2
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/index.js +89 -85
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.d.ts +6 -3
- package/lib/selectors/index.d.ts.map +1 -1
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -11042,12 +11042,13 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
11042
11042
|
}), preventOverlappingAnnotations = defineBehavior({
|
|
11043
11043
|
// Given an `annotation.add` event
|
|
11044
11044
|
on: "annotation.add",
|
|
11045
|
-
// When the annotation
|
|
11045
|
+
// When the raised `annotation.remove` would strip the annotation from at
|
|
11046
|
+
// least one span
|
|
11046
11047
|
guard: ({
|
|
11047
11048
|
snapshot,
|
|
11048
11049
|
event
|
|
11049
11050
|
}) => {
|
|
11050
|
-
const at = event.at
|
|
11051
|
+
const at = resolveEffectiveSelection(snapshot, event.at);
|
|
11051
11052
|
if (!at)
|
|
11052
11053
|
return !1;
|
|
11053
11054
|
const adjustedSnapshot = {
|
|
@@ -11114,7 +11115,22 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
11114
11115
|
marks: activeDecorators
|
|
11115
11116
|
}
|
|
11116
11117
|
}), forward(event)]]
|
|
11117
|
-
}), coreAnnotationBehaviors = [addAnnotationOnCollapsedSelection, preventOverlappingAnnotations, stripAnnotationsOnFullSpanDeletion]
|
|
11118
|
+
}), coreAnnotationBehaviors = [addAnnotationOnCollapsedSelection, preventOverlappingAnnotations, stripAnnotationsOnFullSpanDeletion];
|
|
11119
|
+
function resolveEffectiveSelection(snapshot, at) {
|
|
11120
|
+
if (!at)
|
|
11121
|
+
return snapshot.context.selection;
|
|
11122
|
+
const resolvedAt = resolveSelection({
|
|
11123
|
+
snapshot
|
|
11124
|
+
}, at);
|
|
11125
|
+
return resolvedAt ? {
|
|
11126
|
+
anchor: resolvedAt.anchor,
|
|
11127
|
+
focus: resolvedAt.focus,
|
|
11128
|
+
// Resolving can move either point, so `at.backward` may no longer
|
|
11129
|
+
// match; derive the direction from the resolved points instead.
|
|
11130
|
+
backward: isBackwardRange(resolvedAt, snapshot.context)
|
|
11131
|
+
} : snapshot.context.selection;
|
|
11132
|
+
}
|
|
11133
|
+
const defaultKeyboardShortcuts = {
|
|
11118
11134
|
arrowDown: createKeyboardShortcut({
|
|
11119
11135
|
default: [{
|
|
11120
11136
|
key: "ArrowDown",
|
|
@@ -16704,7 +16720,21 @@ function isCustomBehaviorEvent(event) {
|
|
|
16704
16720
|
function eventCategory(event) {
|
|
16705
16721
|
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
16706
16722
|
}
|
|
16707
|
-
|
|
16723
|
+
const maxEventDepth = 100, eventDepths = /* @__PURE__ */ new WeakMap();
|
|
16724
|
+
function performEvent(args) {
|
|
16725
|
+
const depth = (eventDepths.get(args.editor) ?? 0) + 1;
|
|
16726
|
+
if (depth > maxEventDepth) {
|
|
16727
|
+
console.error(new Error(`Performing "${args.event.type}" was aborted because the event chain exceeded a depth of ${maxEventDepth}. This usually means Behaviors keep raising events in a cycle.`));
|
|
16728
|
+
return;
|
|
16729
|
+
}
|
|
16730
|
+
eventDepths.set(args.editor, depth);
|
|
16731
|
+
try {
|
|
16732
|
+
performEventInternal(args);
|
|
16733
|
+
} finally {
|
|
16734
|
+
eventDepths.set(args.editor, depth - 1);
|
|
16735
|
+
}
|
|
16736
|
+
}
|
|
16737
|
+
function performEventInternal({
|
|
16708
16738
|
mode,
|
|
16709
16739
|
behaviors,
|
|
16710
16740
|
remainingEventBehaviors,
|
|
@@ -18471,81 +18501,65 @@ async function updateValue({
|
|
|
18471
18501
|
}) {
|
|
18472
18502
|
let doneSyncing = !1, isChanged = !1, isValid = !0;
|
|
18473
18503
|
const hadSelection = !!editorEngine.snapshot.context.selection;
|
|
18474
|
-
|
|
18475
|
-
|
|
18476
|
-
|
|
18477
|
-
|
|
18478
|
-
|
|
18479
|
-
|
|
18480
|
-
|
|
18481
|
-
|
|
18482
|
-
resolve();
|
|
18483
|
-
return;
|
|
18484
|
-
}
|
|
18485
|
-
isChanged = removeExtraBlocks({
|
|
18486
|
-
editorEngine,
|
|
18487
|
-
value
|
|
18488
|
-
}), (async () => {
|
|
18489
|
-
try {
|
|
18490
|
-
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
18491
|
-
value
|
|
18492
|
-
})) {
|
|
18493
|
-
const {
|
|
18494
|
-
blockChanged,
|
|
18495
|
-
blockValid
|
|
18496
|
-
} = syncBlock({
|
|
18497
|
-
context,
|
|
18498
|
-
sendBack,
|
|
18499
|
-
block: currentBlock,
|
|
18500
|
-
index: currentBlockIndex,
|
|
18501
|
-
editorEngine,
|
|
18502
|
-
value
|
|
18503
|
-
});
|
|
18504
|
-
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
18505
|
-
break;
|
|
18506
|
-
}
|
|
18507
|
-
resolve();
|
|
18508
|
-
} catch (error) {
|
|
18509
|
-
reject(error);
|
|
18510
|
-
}
|
|
18511
|
-
})();
|
|
18512
|
-
});
|
|
18513
|
-
else {
|
|
18514
|
-
if (doneSyncing)
|
|
18504
|
+
if ((!value || value.length === 0) && (clearEditor({
|
|
18505
|
+
editorEngine,
|
|
18506
|
+
doneSyncing
|
|
18507
|
+
}), isChanged = !0), value && value.length > 0)
|
|
18508
|
+
if (streamBlocks)
|
|
18509
|
+
await new Promise((resolve) => {
|
|
18510
|
+
if (doneSyncing) {
|
|
18511
|
+
resolve();
|
|
18515
18512
|
return;
|
|
18513
|
+
}
|
|
18516
18514
|
isChanged = removeExtraBlocks({
|
|
18517
18515
|
editorEngine,
|
|
18518
18516
|
value
|
|
18519
|
-
})
|
|
18520
|
-
|
|
18521
|
-
for (const block of value) {
|
|
18522
|
-
const {
|
|
18523
|
-
blockChanged,
|
|
18524
|
-
blockValid
|
|
18525
|
-
} = syncBlock({
|
|
18526
|
-
context,
|
|
18527
|
-
sendBack,
|
|
18528
|
-
block,
|
|
18529
|
-
index,
|
|
18530
|
-
editorEngine,
|
|
18517
|
+
}), (async () => {
|
|
18518
|
+
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
18531
18519
|
value
|
|
18532
|
-
})
|
|
18533
|
-
|
|
18534
|
-
|
|
18535
|
-
|
|
18536
|
-
|
|
18520
|
+
})) {
|
|
18521
|
+
const {
|
|
18522
|
+
blockChanged,
|
|
18523
|
+
blockValid
|
|
18524
|
+
} = syncBlock({
|
|
18525
|
+
context,
|
|
18526
|
+
sendBack,
|
|
18527
|
+
block: currentBlock,
|
|
18528
|
+
index: currentBlockIndex,
|
|
18529
|
+
editorEngine,
|
|
18530
|
+
value
|
|
18531
|
+
});
|
|
18532
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
18533
|
+
break;
|
|
18534
|
+
}
|
|
18535
|
+
resolve();
|
|
18536
|
+
})();
|
|
18537
|
+
});
|
|
18538
|
+
else {
|
|
18539
|
+
if (doneSyncing)
|
|
18540
|
+
return;
|
|
18541
|
+
isChanged = removeExtraBlocks({
|
|
18542
|
+
editorEngine,
|
|
18543
|
+
value
|
|
18544
|
+
});
|
|
18545
|
+
let index = 0;
|
|
18546
|
+
for (const block of value) {
|
|
18547
|
+
const {
|
|
18548
|
+
blockChanged,
|
|
18549
|
+
blockValid
|
|
18550
|
+
} = syncBlock({
|
|
18551
|
+
context,
|
|
18552
|
+
sendBack,
|
|
18553
|
+
block,
|
|
18554
|
+
index,
|
|
18555
|
+
editorEngine,
|
|
18556
|
+
value
|
|
18557
|
+
});
|
|
18558
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
|
|
18559
|
+
break;
|
|
18560
|
+
index++;
|
|
18537
18561
|
}
|
|
18538
|
-
|
|
18539
|
-
console.error(err), sendBack({
|
|
18540
|
-
type: "invalid value",
|
|
18541
|
-
resolution: null,
|
|
18542
|
-
value
|
|
18543
|
-
}), doneSyncing = !0, sendBack({
|
|
18544
|
-
type: "done syncing",
|
|
18545
|
-
value
|
|
18546
|
-
});
|
|
18547
|
-
return;
|
|
18548
|
-
}
|
|
18562
|
+
}
|
|
18549
18563
|
if (!isValid) {
|
|
18550
18564
|
debug.syncValue("Invalid value, returning"), doneSyncing = !0, sendBack({
|
|
18551
18565
|
type: "done syncing",
|
|
@@ -18794,10 +18808,6 @@ function updateBlock({
|
|
|
18794
18808
|
const childNode = oldEngineBlock.children[childIndex];
|
|
18795
18809
|
if (!childNode)
|
|
18796
18810
|
return;
|
|
18797
|
-
if (!liveBlockHasChildKey(editorEngine, oldEngineBlock._key, childNode._key)) {
|
|
18798
|
-
debug.syncValue("Skipping superfluous-child unset; _key not present in live children", childNode._key);
|
|
18799
|
-
return;
|
|
18800
|
-
}
|
|
18801
18811
|
editorEngine.apply({
|
|
18802
18812
|
type: "unset",
|
|
18803
18813
|
path: [{
|
|
@@ -18848,14 +18858,14 @@ function updateBlock({
|
|
|
18848
18858
|
const oldChild = oldEngineBlock.children[currentBlockChildIndex];
|
|
18849
18859
|
if (!oldChild)
|
|
18850
18860
|
return;
|
|
18851
|
-
|
|
18861
|
+
editorEngine.apply({
|
|
18852
18862
|
type: "unset",
|
|
18853
18863
|
path: [{
|
|
18854
18864
|
_key: oldEngineBlock._key
|
|
18855
18865
|
}, "children", {
|
|
18856
18866
|
_key: oldChild._key
|
|
18857
18867
|
}]
|
|
18858
|
-
})
|
|
18868
|
+
});
|
|
18859
18869
|
const prevSibling = currentBlockChildIndex > 0 ? engineBlock.children[currentBlockChildIndex - 1] : void 0;
|
|
18860
18870
|
prevSibling ? editorEngine.apply({
|
|
18861
18871
|
type: "insert",
|
|
@@ -18899,12 +18909,6 @@ function updateBlock({
|
|
|
18899
18909
|
});
|
|
18900
18910
|
}
|
|
18901
18911
|
}
|
|
18902
|
-
function liveBlockHasChildKey(editorEngine, blockKey, childKey) {
|
|
18903
|
-
const liveBlock = editorEngine.snapshot.context.value.find((node) => node._key === blockKey);
|
|
18904
|
-
return !liveBlock || !isTextBlock({
|
|
18905
|
-
schema: editorEngine.snapshot.context.schema
|
|
18906
|
-
}, liveBlock) ? !1 : liveBlock.children.some((child) => child._key === childKey);
|
|
18907
|
-
}
|
|
18908
18912
|
function createInternalEditor(config) {
|
|
18909
18913
|
debug.setup("creating new editor instance");
|
|
18910
18914
|
const subscriptions = [], editorActor = createActor(editorMachine, {
|