@portabletext/editor 7.10.11 → 7.10.13

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.js CHANGED
@@ -15093,7 +15093,10 @@ const abstractAnnotationBehaviors = [defineBehavior({
15093
15093
  ...snapshot.context,
15094
15094
  selection: at
15095
15095
  }
15096
- }, focusTextBlock = getFocusTextBlock(adjustedSnapshot);
15096
+ };
15097
+ if (!isSelectionCollapsed$1(adjustedSnapshot))
15098
+ return !1;
15099
+ const focusTextBlock = getFocusTextBlock(adjustedSnapshot);
15097
15100
  if (!focusTextBlock)
15098
15101
  return !1;
15099
15102
  const nextSibling = getSibling(adjustedSnapshot, focusTextBlock.path, {
@@ -18647,9 +18650,9 @@ function clearEditor({
18647
18650
  editorEngine,
18648
18651
  doneSyncing
18649
18652
  }) {
18650
- withoutNormalizing(editorEngine, () => {
18651
- pluginWithoutHistory(editorEngine, () => {
18652
- withRemoteChanges(editorEngine, () => {
18653
+ withRemoteChanges(editorEngine, () => {
18654
+ withoutNormalizing(editorEngine, () => {
18655
+ pluginWithoutHistory(editorEngine, () => {
18653
18656
  withoutPatching(editorEngine, () => {
18654
18657
  if (doneSyncing)
18655
18658
  return;
@@ -18673,8 +18676,8 @@ function removeExtraBlocks({
18673
18676
  value
18674
18677
  }) {
18675
18678
  let isChanged = !1;
18676
- return withoutNormalizing(editorEngine, () => {
18677
- withRemoteChanges(editorEngine, () => {
18679
+ return withRemoteChanges(editorEngine, () => {
18680
+ withoutNormalizing(editorEngine, () => {
18678
18681
  withoutPatching(editorEngine, () => {
18679
18682
  const childrenLength = editorEngine.snapshot.context.value.length;
18680
18683
  if (value.length < childrenLength) {
@@ -18705,11 +18708,11 @@ function syncBlock({
18705
18708
  if (!oldEngineBlock || !oldBlock) {
18706
18709
  const validation2 = validateValue([block], context.schema, context.keyGenerator);
18707
18710
  if (debug.syncValue("Validating and inserting new block in the end of the value", block), validation2.valid || validation2.resolution?.autoResolve) {
18708
- const engineBlock = toEngineBlock(block, {
18711
+ const repairedBlock = applyAutoResolution(validation2, [block], block), engineBlock = toEngineBlock(repairedBlock, {
18709
18712
  schemaTypes: context.schema
18710
18713
  });
18711
- return withoutNormalizing(editorEngine, () => {
18712
- withRemoteChanges(editorEngine, () => {
18714
+ return withRemoteChanges(editorEngine, () => {
18715
+ withoutNormalizing(editorEngine, () => {
18713
18716
  withoutPatching(editorEngine, () => {
18714
18717
  editorEngine.apply({
18715
18718
  type: "insert",
@@ -18744,46 +18747,53 @@ function syncBlock({
18744
18747
  blockChanged: !1,
18745
18748
  blockValid: !0
18746
18749
  };
18747
- const validation = validateValue([blockToValidate], context.schema, context.keyGenerator);
18748
- return !validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${blockToValidate._key}'. ${validation.resolution?.description}`), validation.resolution.patches.forEach((patch) => {
18750
+ const validationValue = [blockToValidate], validation = validateValue(validationValue, context.schema, context.keyGenerator);
18751
+ if (!validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${blockToValidate._key}'. ${validation.resolution?.description}`), validation.resolution.patches.forEach((patch) => {
18749
18752
  sendBack({
18750
18753
  type: "patch",
18751
18754
  patch
18752
18755
  });
18753
- })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key && oldBlock._type === block._type ? (debug.syncValue("Updating block", oldBlock, block), withoutNormalizing(editorEngine, () => {
18754
- withRemoteChanges(editorEngine, () => {
18755
- withoutPatching(editorEngine, () => {
18756
- updateBlock({
18757
- context,
18758
- editorEngine,
18759
- oldEngineBlock,
18760
- block,
18761
- index
18756
+ })), validation.valid || validation.resolution?.autoResolve) {
18757
+ const repairedBlock = applyAutoResolution(validation, validationValue, block);
18758
+ return oldBlock._key === block._key && oldBlock._type === block._type ? (debug.syncValue("Updating block", oldBlock, repairedBlock), withRemoteChanges(editorEngine, () => {
18759
+ withoutNormalizing(editorEngine, () => {
18760
+ withoutPatching(editorEngine, () => {
18761
+ updateBlock({
18762
+ context,
18763
+ editorEngine,
18764
+ oldEngineBlock,
18765
+ block: repairedBlock,
18766
+ index
18767
+ });
18762
18768
  });
18763
18769
  });
18764
- });
18765
- })) : (debug.syncValue("Replacing block", oldBlock, block), withoutNormalizing(editorEngine, () => {
18766
- withRemoteChanges(editorEngine, () => {
18767
- withoutPatching(editorEngine, () => {
18768
- replaceBlock({
18769
- context,
18770
- editorEngine,
18771
- block,
18772
- index
18770
+ })) : (debug.syncValue("Replacing block", oldBlock, repairedBlock), withRemoteChanges(editorEngine, () => {
18771
+ withoutNormalizing(editorEngine, () => {
18772
+ withoutPatching(editorEngine, () => {
18773
+ replaceBlock({
18774
+ context,
18775
+ editorEngine,
18776
+ block: repairedBlock,
18777
+ index
18778
+ });
18773
18779
  });
18774
18780
  });
18775
- });
18776
- })), {
18777
- blockChanged: !0,
18778
- blockValid: !0
18779
- }) : (sendBack({
18780
- type: "invalid value",
18781
- resolution: validation.resolution,
18782
- value
18783
- }), {
18784
- blockChanged: !1,
18785
- blockValid: !1
18786
- });
18781
+ })), {
18782
+ blockChanged: !0,
18783
+ blockValid: !0
18784
+ };
18785
+ } else
18786
+ return sendBack({
18787
+ type: "invalid value",
18788
+ resolution: validation.resolution,
18789
+ value
18790
+ }), {
18791
+ blockChanged: !1,
18792
+ blockValid: !1
18793
+ };
18794
+ }
18795
+ function applyAutoResolution(validation, validationValue, block) {
18796
+ return !validation.valid && validation.resolution?.autoResolve ? applyAll(validationValue, validation.resolution.patches).at(0) ?? block : block;
18787
18797
  }
18788
18798
  function replaceBlock({
18789
18799
  context,