@portabletext/editor 1.49.5 → 1.49.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/lib/index.cjs CHANGED
@@ -2992,11 +2992,13 @@ async function updateValue({
2992
2992
  streamBlocks,
2993
2993
  value
2994
2994
  }) {
2995
- let isChanged = !1, isValid = !0;
2995
+ let doneSyncing = !1, isChanged = !1, isValid = !0;
2996
2996
  const hadSelection = !!slateEditor.selection;
2997
2997
  if ((!value || value.length === 0) && (debug$g("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
2998
2998
  withoutSaving(slateEditor, () => {
2999
2999
  withoutPatching(slateEditor, () => {
3000
+ if (doneSyncing)
3001
+ return;
3000
3002
  hadSelection && slate.Transforms.deselect(slateEditor);
3001
3003
  const childrenLength = slateEditor.children.length;
3002
3004
  slateEditor.children.forEach((_, index) => {
@@ -3017,34 +3019,41 @@ async function updateValue({
3017
3019
  streamBlocks ? await new Promise((resolve) => {
3018
3020
  slate.Editor.withoutNormalizing(slateEditor, () => {
3019
3021
  withRemoteChanges(slateEditor, () => {
3020
- withoutPatching(slateEditor, async () => {
3022
+ withoutPatching(slateEditor, () => {
3023
+ if (doneSyncing) {
3024
+ resolve();
3025
+ return;
3026
+ }
3021
3027
  isChanged = removeExtraBlocks({
3022
3028
  slateEditor,
3023
3029
  slateValueFromProps
3024
- });
3025
- for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
3026
- slateValue: slateValueFromProps
3027
- })) {
3028
- const {
3029
- blockChanged,
3030
- blockValid
3031
- } = syncBlock({
3032
- context,
3033
- sendBack,
3034
- block: currentBlock,
3035
- index: currentBlockIndex,
3036
- slateEditor,
3037
- value
3038
- });
3039
- isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
3040
- }
3041
- resolve();
3030
+ }), (async () => {
3031
+ for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
3032
+ slateValue: slateValueFromProps
3033
+ })) {
3034
+ const {
3035
+ blockChanged,
3036
+ blockValid
3037
+ } = syncBlock({
3038
+ context,
3039
+ sendBack,
3040
+ block: currentBlock,
3041
+ index: currentBlockIndex,
3042
+ slateEditor,
3043
+ value
3044
+ });
3045
+ isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
3046
+ }
3047
+ resolve();
3048
+ })();
3042
3049
  });
3043
3050
  });
3044
3051
  });
3045
3052
  }) : slate.Editor.withoutNormalizing(slateEditor, () => {
3046
3053
  withRemoteChanges(slateEditor, () => {
3047
3054
  withoutPatching(slateEditor, () => {
3055
+ if (doneSyncing)
3056
+ return;
3048
3057
  isChanged = removeExtraBlocks({
3049
3058
  slateEditor,
3050
3059
  slateValueFromProps
@@ -3069,7 +3078,7 @@ async function updateValue({
3069
3078
  });
3070
3079
  }
3071
3080
  if (!isValid) {
3072
- debug$g("Invalid value, returning"), sendBack({
3081
+ debug$g("Invalid value, returning"), doneSyncing = !0, sendBack({
3073
3082
  type: "done syncing",
3074
3083
  value
3075
3084
  });
@@ -3084,7 +3093,7 @@ async function updateValue({
3084
3093
  type: "invalid value",
3085
3094
  resolution: null,
3086
3095
  value
3087
- }), sendBack({
3096
+ }), doneSyncing = !0, sendBack({
3088
3097
  type: "done syncing",
3089
3098
  value
3090
3099
  });
@@ -3105,7 +3114,7 @@ async function updateValue({
3105
3114
  });
3106
3115
  } else
3107
3116
  debug$g("Server value and editor value is equal, no need to sync.");
3108
- sendBack({
3117
+ doneSyncing = !0, sendBack({
3109
3118
  type: "done syncing",
3110
3119
  value
3111
3120
  });