@portabletext/editor 1.3.0 → 1.4.0

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.esm.js CHANGED
@@ -1,16 +1,16 @@
1
+ import { isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isKeySegment, isPortableTextListBlock } from "@sanity/types";
1
2
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
2
3
  import isEqual from "lodash/isEqual.js";
3
4
  import noop from "lodash/noop.js";
4
- import { useRef, useState, useEffect, useMemo, createContext, useContext, useCallback, startTransition, Component, forwardRef, useImperativeHandle } from "react";
5
+ import require$$0, { useRef, useState, useEffect, useMemo, createContext, useContext, useCallback, startTransition, Component, forwardRef, useImperativeHandle, useLayoutEffect } from "react";
5
6
  import { Editor, Element as Element$1, Range, Point, Text, Path, Transforms, Node, Operation, createEditor, deleteBackward, deleteForward, insertText } from "slate";
6
7
  import { useSlateStatic, ReactEditor, useSelected, withReact, Slate, useSlate, Editable } from "slate-react";
7
8
  import debug$m from "debug";
8
- import { isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
9
9
  import { c } from "react-compiler-runtime";
10
10
  import { styled } from "styled-components";
11
11
  import uniq from "lodash/uniq.js";
12
12
  import { Subject } from "rxjs";
13
- import { fromCallback, setup, assign, assertEvent, emit, enqueueActions, createActor } from "xstate";
13
+ import { fromCallback, setup, assign, assertEvent, emit, enqueueActions, createActor, toObserver } from "xstate";
14
14
  import { Schema } from "@sanity/schema";
15
15
  import { diffMatchPatch as diffMatchPatch$1, set, insert, setIfMissing, unset, applyAll } from "@portabletext/patches";
16
16
  import get from "lodash/get.js";
@@ -24,6 +24,246 @@ import throttle from "lodash/throttle.js";
24
24
  import { useEffectEvent } from "use-effect-event";
25
25
  import debounce from "lodash/debounce.js";
26
26
  import { randomKey } from "@sanity/util/content";
27
+ function defineBehavior(behavior) {
28
+ return behavior;
29
+ }
30
+ function selectionIsCollapsed(context) {
31
+ return context.selection?.anchor.path.join() === context.selection?.focus.path.join() && context.selection?.anchor.offset === context.selection?.focus.offset;
32
+ }
33
+ function getFocusBlock(context) {
34
+ const key = context.selection && isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
35
+ return node && key ? {
36
+ node,
37
+ path: [{
38
+ _key: key
39
+ }]
40
+ } : void 0;
41
+ }
42
+ function getFocusTextBlock(context) {
43
+ const focusBlock = getFocusBlock(context);
44
+ return focusBlock && isPortableTextTextBlock(focusBlock.node) ? {
45
+ node: focusBlock.node,
46
+ path: focusBlock.path
47
+ } : void 0;
48
+ }
49
+ function getFocusBlockObject(context) {
50
+ const focusBlock = getFocusBlock(context);
51
+ return focusBlock && !isPortableTextTextBlock(focusBlock.node) ? {
52
+ node: focusBlock.node,
53
+ path: focusBlock.path
54
+ } : void 0;
55
+ }
56
+ function getFocusChild(context) {
57
+ const focusBlock = getFocusTextBlock(context);
58
+ if (!focusBlock)
59
+ return;
60
+ const key = context.selection && isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
61
+ return node && key ? {
62
+ node,
63
+ path: [...focusBlock.path, "children", {
64
+ _key: key
65
+ }]
66
+ } : void 0;
67
+ }
68
+ function getFocusSpan(context) {
69
+ const focusChild = getFocusChild(context);
70
+ return focusChild && isPortableTextSpan$1(focusChild.node) ? {
71
+ node: focusChild.node,
72
+ path: focusChild.path
73
+ } : void 0;
74
+ }
75
+ function getSelectionStartBlock(context) {
76
+ const key = context.selection.backward ? isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
77
+ return node && key ? {
78
+ node,
79
+ path: [{
80
+ _key: key
81
+ }]
82
+ } : void 0;
83
+ }
84
+ function getSelectionEndBlock(context) {
85
+ const key = context.selection.backward ? isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
86
+ return node && key ? {
87
+ node,
88
+ path: [{
89
+ _key: key
90
+ }]
91
+ } : void 0;
92
+ }
93
+ function getPreviousBlock(context) {
94
+ let previousBlock;
95
+ const selectionStartBlock = getSelectionStartBlock(context);
96
+ if (!selectionStartBlock)
97
+ return;
98
+ let foundSelectionStartBlock = !1;
99
+ for (const block of context.value) {
100
+ if (block._key === selectionStartBlock.node._key) {
101
+ foundSelectionStartBlock = !0;
102
+ break;
103
+ }
104
+ previousBlock = {
105
+ node: block,
106
+ path: [{
107
+ _key: block._key
108
+ }]
109
+ };
110
+ }
111
+ if (foundSelectionStartBlock && previousBlock)
112
+ return previousBlock;
113
+ }
114
+ function getNextBlock(context) {
115
+ let nextBlock;
116
+ const selectionEndBlock = getSelectionEndBlock(context);
117
+ if (!selectionEndBlock)
118
+ return;
119
+ let foundSelectionEndBlock = !1;
120
+ for (const block of context.value) {
121
+ if (block._key === selectionEndBlock.node._key) {
122
+ foundSelectionEndBlock = !0;
123
+ continue;
124
+ }
125
+ if (foundSelectionEndBlock) {
126
+ nextBlock = {
127
+ node: block,
128
+ path: [{
129
+ _key: block._key
130
+ }]
131
+ };
132
+ break;
133
+ }
134
+ }
135
+ if (foundSelectionEndBlock && nextBlock)
136
+ return nextBlock;
137
+ }
138
+ function isEmptyTextBlock(block) {
139
+ return block.children.length === 1 && block.children[0].text === "";
140
+ }
141
+ function createMarkdownBehaviors(config) {
142
+ const automaticStyleOnSpace = {
143
+ on: "insert text",
144
+ guard: ({
145
+ context,
146
+ event
147
+ }) => {
148
+ if (event.text !== " ")
149
+ return !1;
150
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
151
+ if (!selectionCollapsed || !focusTextBlock || !focusSpan)
152
+ return !1;
153
+ const looksLikeMarkdownHeading = /^#+/.test(focusSpan.node.text), headingStyle = config.mapHeadingStyle(context.schema, focusSpan.node.text.length), looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle(context.schema);
154
+ return looksLikeMarkdownHeading && headingStyle !== void 0 ? {
155
+ focusTextBlock,
156
+ focusSpan,
157
+ style: headingStyle
158
+ } : looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
159
+ focusTextBlock,
160
+ focusSpan,
161
+ style: blockquoteStyle
162
+ } : !1;
163
+ },
164
+ actions: [() => [{
165
+ type: "insert text",
166
+ text: " "
167
+ }], (_, {
168
+ focusTextBlock,
169
+ focusSpan,
170
+ style
171
+ }) => [{
172
+ type: "set block",
173
+ style,
174
+ paths: [focusTextBlock.path]
175
+ }, {
176
+ type: "delete",
177
+ selection: {
178
+ anchor: {
179
+ path: focusSpan.path,
180
+ offset: 0
181
+ },
182
+ focus: {
183
+ path: focusSpan.path,
184
+ offset: focusSpan.node.text.length + 1
185
+ }
186
+ }
187
+ }]]
188
+ }, clearStyleOnBackspace = {
189
+ on: "delete backward",
190
+ guard: ({
191
+ context
192
+ }) => {
193
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
194
+ if (!selectionCollapsed || !focusTextBlock || !focusSpan)
195
+ return !1;
196
+ const defaultStyle = config.mapDefaultStyle(context.schema);
197
+ return defaultStyle && focusTextBlock.node.children.length === 1 && focusTextBlock.node.style !== config.mapDefaultStyle(context.schema) && focusSpan.node.text === "" ? {
198
+ defaultStyle,
199
+ focusTextBlock
200
+ } : !1;
201
+ },
202
+ actions: [(_, {
203
+ defaultStyle,
204
+ focusTextBlock
205
+ }) => [{
206
+ type: "set block",
207
+ style: defaultStyle,
208
+ paths: [focusTextBlock.path]
209
+ }]]
210
+ }, automaticListOnSpace = {
211
+ on: "insert text",
212
+ guard: ({
213
+ context,
214
+ event
215
+ }) => {
216
+ if (event.text !== " ")
217
+ return !1;
218
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
219
+ if (!selectionCollapsed || !focusTextBlock || !focusSpan)
220
+ return !1;
221
+ const looksLikeUnorderedList = /^-/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle(context.schema);
222
+ if (looksLikeUnorderedList && unorderedListStyle !== void 0)
223
+ return {
224
+ focusTextBlock,
225
+ focusSpan,
226
+ listItem: unorderedListStyle
227
+ };
228
+ const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle(context.schema);
229
+ return looksLikeOrderedList && orderedListStyle !== void 0 ? {
230
+ focusTextBlock,
231
+ focusSpan,
232
+ listItem: orderedListStyle
233
+ } : !1;
234
+ },
235
+ actions: [() => [{
236
+ type: "insert text",
237
+ text: " "
238
+ }], (_, {
239
+ focusTextBlock,
240
+ focusSpan,
241
+ listItem
242
+ }) => [{
243
+ type: "unset block",
244
+ props: ["style"],
245
+ paths: [focusTextBlock.path]
246
+ }, {
247
+ type: "set block",
248
+ listItem,
249
+ level: 1,
250
+ paths: [focusTextBlock.path]
251
+ }, {
252
+ type: "delete",
253
+ selection: {
254
+ anchor: {
255
+ path: focusSpan.path,
256
+ offset: 0
257
+ },
258
+ focus: {
259
+ path: focusSpan.path,
260
+ offset: focusSpan.node.text.length + 1
261
+ }
262
+ }
263
+ }]]
264
+ };
265
+ return [automaticStyleOnSpace, clearStyleOnBackspace, automaticListOnSpace];
266
+ }
27
267
  const rootName = "sanity-pte:";
28
268
  debug$m(rootName);
29
269
  function debugWithName(name) {
@@ -754,266 +994,25 @@ function resolveEnabledStyles(blockType) {
754
994
  function resolveEnabledDecorators(spanType) {
755
995
  return spanType.decorators;
756
996
  }
757
- function resolveEnabledListItems(blockType) {
758
- const listField = blockType.fields?.find((btField) => btField.name === "listItem");
759
- if (!listField)
760
- throw new Error("A field with name 'listItem' is not defined in the block type (required).");
761
- const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
762
- if (!listItems)
763
- throw new Error("The list field need at least to be an empty array");
764
- return listItems;
765
- }
766
- function findBlockType(type) {
767
- return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
768
- }
769
- function compileType(rawType) {
770
- return Schema.compile({
771
- name: "blockTypeSchema",
772
- types: [rawType]
773
- }).get(rawType.name);
774
- }
775
- function selectionIsCollapsed(context) {
776
- return context.selection?.anchor.path.join() === context.selection?.focus.path.join() && context.selection?.anchor.offset === context.selection?.focus.offset;
777
- }
778
- function getFocusBlock(context) {
779
- const key = context.selection && isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
780
- return node && key ? {
781
- node,
782
- path: [{
783
- _key: key
784
- }]
785
- } : void 0;
786
- }
787
- function getFocusTextBlock(context) {
788
- const focusBlock = getFocusBlock(context);
789
- return focusBlock && isPortableTextTextBlock(focusBlock.node) ? {
790
- node: focusBlock.node,
791
- path: focusBlock.path
792
- } : void 0;
793
- }
794
- function getFocusBlockObject(context) {
795
- const focusBlock = getFocusBlock(context);
796
- return focusBlock && !isPortableTextTextBlock(focusBlock.node) ? {
797
- node: focusBlock.node,
798
- path: focusBlock.path
799
- } : void 0;
800
- }
801
- function getFocusChild(context) {
802
- const focusBlock = getFocusTextBlock(context);
803
- if (!focusBlock)
804
- return;
805
- const key = context.selection && isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
806
- return node && key ? {
807
- node,
808
- path: [...focusBlock.path, "children", {
809
- _key: key
810
- }]
811
- } : void 0;
812
- }
813
- function getFocusSpan(context) {
814
- const focusChild = getFocusChild(context);
815
- return focusChild && isPortableTextSpan$1(focusChild.node) ? {
816
- node: focusChild.node,
817
- path: focusChild.path
818
- } : void 0;
819
- }
820
- function getSelectionStartBlock(context) {
821
- const key = context.selection.backward ? isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
822
- return node && key ? {
823
- node,
824
- path: [{
825
- _key: key
826
- }]
827
- } : void 0;
828
- }
829
- function getSelectionEndBlock(context) {
830
- const key = context.selection.backward ? isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
831
- return node && key ? {
832
- node,
833
- path: [{
834
- _key: key
835
- }]
836
- } : void 0;
837
- }
838
- function getPreviousBlock(context) {
839
- let previousBlock;
840
- const selectionStartBlock = getSelectionStartBlock(context);
841
- if (!selectionStartBlock)
842
- return;
843
- let foundSelectionStartBlock = !1;
844
- for (const block of context.value) {
845
- if (block._key === selectionStartBlock.node._key) {
846
- foundSelectionStartBlock = !0;
847
- break;
848
- }
849
- previousBlock = {
850
- node: block,
851
- path: [{
852
- _key: block._key
853
- }]
854
- };
855
- }
856
- if (foundSelectionStartBlock && previousBlock)
857
- return previousBlock;
858
- }
859
- function getNextBlock(context) {
860
- let nextBlock;
861
- const selectionEndBlock = getSelectionEndBlock(context);
862
- if (!selectionEndBlock)
863
- return;
864
- let foundSelectionEndBlock = !1;
865
- for (const block of context.value) {
866
- if (block._key === selectionEndBlock.node._key) {
867
- foundSelectionEndBlock = !0;
868
- continue;
869
- }
870
- if (foundSelectionEndBlock) {
871
- nextBlock = {
872
- node: block,
873
- path: [{
874
- _key: block._key
875
- }]
876
- };
877
- break;
878
- }
879
- }
880
- if (foundSelectionEndBlock && nextBlock)
881
- return nextBlock;
882
- }
883
- function isEmptyTextBlock(block) {
884
- return block.children.length === 1 && block.children[0].text === "";
885
- }
886
- const breakingVoidBlock = {
887
- on: "insert break",
888
- guard: ({
889
- context
890
- }) => !!getFocusBlockObject(context),
891
- actions: [() => [{
892
- type: "insert text block",
893
- decorators: []
894
- }]]
895
- }, deletingEmptyTextBlockAfterBlockObject = {
896
- on: "delete backward",
897
- guard: ({
898
- context
899
- }) => {
900
- const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
901
- return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(previousBlock.node) ? {
902
- focusTextBlock,
903
- previousBlock
904
- } : !1;
905
- },
906
- actions: [(_, {
907
- focusTextBlock,
908
- previousBlock
909
- }) => [{
910
- type: "delete",
911
- selection: {
912
- anchor: {
913
- path: focusTextBlock.path,
914
- offset: 0
915
- },
916
- focus: {
917
- path: focusTextBlock.path,
918
- offset: 0
919
- }
920
- }
921
- }, {
922
- type: "select",
923
- selection: {
924
- anchor: {
925
- path: previousBlock.path,
926
- offset: 0
927
- },
928
- focus: {
929
- path: previousBlock.path,
930
- offset: 0
931
- }
932
- }
933
- }]]
934
- }, deletingEmptyTextBlockBeforeBlockObject = {
935
- on: "delete forward",
936
- guard: ({
937
- context
938
- }) => {
939
- const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
940
- return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(nextBlock.node) ? {
941
- focusTextBlock,
942
- nextBlock
943
- } : !1;
944
- },
945
- actions: [(_, {
946
- focusTextBlock,
947
- nextBlock
948
- }) => [{
949
- type: "delete",
950
- selection: {
951
- anchor: {
952
- path: focusTextBlock.path,
953
- offset: 0
954
- },
955
- focus: {
956
- path: focusTextBlock.path,
957
- offset: 0
958
- }
959
- }
960
- }, {
961
- type: "select",
962
- selection: {
963
- anchor: {
964
- path: nextBlock.path,
965
- offset: 0
966
- },
967
- focus: {
968
- path: nextBlock.path,
969
- offset: 0
970
- }
971
- }
972
- }]]
973
- }, coreBlockObjectBehaviors = [breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], clearListOnBackspace = {
974
- on: "delete backward",
975
- guard: ({
976
- context
977
- }) => {
978
- const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
979
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
980
- focusTextBlock
981
- } : !1;
982
- },
983
- actions: [(_, {
984
- focusTextBlock
985
- }) => [{
986
- type: "unset block",
987
- props: ["listItem", "level"],
988
- paths: [focusTextBlock.path]
989
- }]]
990
- }, unindentListOnBackspace = {
991
- on: "delete backward",
992
- guard: ({
993
- context
994
- }) => {
995
- const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
996
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
997
- focusTextBlock,
998
- level: focusTextBlock.node.level - 1
999
- } : !1;
1000
- },
1001
- actions: [(_, {
1002
- focusTextBlock,
1003
- level
1004
- }) => [{
1005
- type: "set block",
1006
- level,
1007
- paths: [focusTextBlock.path]
1008
- }]]
1009
- }, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
1010
- on: "insert soft break",
1011
- actions: [() => [{
1012
- type: "insert text",
1013
- text: `
1014
- `
1015
- }]]
1016
- }, coreBehaviors = [softReturn, ...coreBlockObjectBehaviors, ...coreListBehaviors], debug$k = debugWithName("operationToPatches");
997
+ function resolveEnabledListItems(blockType) {
998
+ const listField = blockType.fields?.find((btField) => btField.name === "listItem");
999
+ if (!listField)
1000
+ throw new Error("A field with name 'listItem' is not defined in the block type (required).");
1001
+ const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
1002
+ if (!listItems)
1003
+ throw new Error("The list field need at least to be an empty array");
1004
+ return listItems;
1005
+ }
1006
+ function findBlockType(type) {
1007
+ return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
1008
+ }
1009
+ function compileType(rawType) {
1010
+ return Schema.compile({
1011
+ name: "blockTypeSchema",
1012
+ types: [rawType]
1013
+ }).get(rawType.name);
1014
+ }
1015
+ const debug$k = debugWithName("operationToPatches");
1017
1016
  function createOperationToPatches(types) {
1018
1017
  const textBlockName = types.block.name;
1019
1018
  function insertTextPatch(editor, operation, beforeValue) {
@@ -2700,9 +2699,9 @@ function debugState(editor, stateName) {
2700
2699
  }
2701
2700
  function findBlockFromPath(editor, path) {
2702
2701
  let blockIndex = -1;
2703
- const block = editor.children.find((node, index) => {
2704
- const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
2705
- return isMatch && (blockIndex = index), isMatch;
2702
+ const block = editor.children.find((node, index2) => {
2703
+ const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key : index2 === path[0];
2704
+ return isMatch && (blockIndex = index2), isMatch;
2706
2705
  });
2707
2706
  return block ? {
2708
2707
  block,
@@ -2722,9 +2721,9 @@ function findBlockAndChildFromPath(editor, path) {
2722
2721
  childPath: void 0
2723
2722
  };
2724
2723
  let childIndex = -1;
2725
- const child = block.children.find((node, index) => {
2726
- const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
2727
- return isMatch && (childIndex = index), isMatch;
2724
+ const child = block.children.find((node, index2) => {
2725
+ const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index2 === path[2];
2726
+ return isMatch && (childIndex = index2), isMatch;
2728
2727
  });
2729
2728
  return child ? {
2730
2729
  block,
@@ -2752,16 +2751,16 @@ const debug$h = debugWithName("plugin:withUndoRedo"), debugVerbose$3 = debug$h.e
2752
2751
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
2753
2752
  function createWithUndoRedo(options) {
2754
2753
  const {
2754
+ editorActor,
2755
2755
  readOnly,
2756
- patches$,
2757
2756
  blockSchemaType
2758
2757
  } = options;
2759
2758
  return (editor) => {
2760
2759
  let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
2761
2760
  const remotePatches = getRemotePatches(editor);
2762
- patches$ && editor.subscriptions.push(() => {
2761
+ editor.subscriptions.push(() => {
2763
2762
  debug$h("Subscribing to patches");
2764
- const sub = patches$.subscribe(({
2763
+ const sub = editorActor.on("patches", ({
2765
2764
  patches,
2766
2765
  snapshot
2767
2766
  }) => {
@@ -2921,9 +2920,9 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
2921
2920
  const {
2922
2921
  diffs
2923
2922
  } = diffPatch;
2924
- if (diffs.forEach((diff2, index) => {
2923
+ if (diffs.forEach((diff2, index2) => {
2925
2924
  const [diffType, text] = diff2;
2926
- diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
2925
+ diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index2).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
2927
2926
  }), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
2928
2927
  const currentFocus = transformedOperation.properties?.focus ? {
2929
2928
  ...transformedOperation.properties.focus
@@ -3001,7 +3000,6 @@ function findOperationTargetBlock(editor, operation) {
3001
3000
  const debug$g = debugWithName("plugin:withPatches");
3002
3001
  function createWithPatches({
3003
3002
  editorActor,
3004
- patches$,
3005
3003
  patchFunctions,
3006
3004
  readOnly,
3007
3005
  schemaTypes
@@ -3037,11 +3035,11 @@ function createWithPatches({
3037
3035
  const remotePatches = patches.filter((p) => p.origin !== "local");
3038
3036
  remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
3039
3037
  };
3040
- return patches$ && editor.subscriptions.push(() => {
3041
- debug$g("Subscribing to patches$");
3042
- const sub = patches$.subscribe(handlePatches);
3038
+ return editor.subscriptions.push(() => {
3039
+ debug$g("Subscribing to remote patches");
3040
+ const sub = editorActor.on("patches", handlePatches);
3043
3041
  return () => {
3044
- debug$g("Unsubscribing to patches$"), sub.unsubscribe();
3042
+ debug$g("Unsubscribing to remote patches"), sub.unsubscribe();
3045
3043
  };
3046
3044
  }), editor.apply = (operation) => {
3047
3045
  if (readOnly)
@@ -4018,10 +4016,10 @@ function validateValue(value, types, keyGenerator) {
4018
4016
  }
4019
4017
  },
4020
4018
  value
4021
- } : (value.some((blk, index) => {
4019
+ } : (value.some((blk, index2) => {
4022
4020
  if (!isPlainObject(blk))
4023
4021
  return resolution = {
4024
- patches: [unset([index])],
4022
+ patches: [unset([index2])],
4025
4023
  description: `Block must be an object, got ${String(blk)}`,
4026
4024
  action: "Unset invalid item",
4027
4025
  item: blk,
@@ -4029,7 +4027,7 @@ function validateValue(value, types, keyGenerator) {
4029
4027
  description: "inputs.portable-text.invalid-value.not-an-object.description",
4030
4028
  action: "inputs.portable-text.invalid-value.not-an-object.action",
4031
4029
  values: {
4032
- index
4030
+ index: index2
4033
4031
  }
4034
4032
  }
4035
4033
  }, !0;
@@ -4038,15 +4036,15 @@ function validateValue(value, types, keyGenerator) {
4038
4036
  patches: [set({
4039
4037
  ...blk,
4040
4038
  _key: keyGenerator()
4041
- }, [index])],
4042
- description: `Block at index ${index} is missing required _key.`,
4039
+ }, [index2])],
4040
+ description: `Block at index ${index2} is missing required _key.`,
4043
4041
  action: "Set the block with a random _key value",
4044
4042
  item: blk,
4045
4043
  i18n: {
4046
4044
  description: "inputs.portable-text.invalid-value.missing-key.description",
4047
4045
  action: "inputs.portable-text.invalid-value.missing-key.action",
4048
4046
  values: {
4049
- index
4047
+ index: index2
4050
4048
  }
4051
4049
  }
4052
4050
  }, !0;
@@ -4530,7 +4528,6 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
4530
4528
  const e = editor, {
4531
4529
  editorActor,
4532
4530
  portableTextEditor,
4533
- patches$,
4534
4531
  readOnly,
4535
4532
  maxBlocks
4536
4533
  } = options, {
@@ -4546,13 +4543,12 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
4546
4543
  schemaTypes
4547
4544
  }), withEditableAPI = createWithEditableAPI(editorActor, portableTextEditor, schemaTypes), withPatches = createWithPatches({
4548
4545
  editorActor,
4549
- patches$,
4550
4546
  patchFunctions: operationToPatches,
4551
4547
  readOnly,
4552
4548
  schemaTypes
4553
4549
  }), withMaxBlocks = createWithMaxBlocks(maxBlocks || -1), withPortableTextLists = createWithPortableTextLists(schemaTypes), withUndoRedo = createWithUndoRedo({
4550
+ editorActor,
4554
4551
  readOnly,
4555
- patches$,
4556
4552
  blockSchemaType: schemaTypes.block
4557
4553
  }), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor, schemaTypes), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor, schemaTypes), withPlaceholderBlock = createWithPlaceholderBlock(), withUtils = createWithUtils({
4558
4554
  editorActor,
@@ -4585,15 +4581,14 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
4585
4581
  };
4586
4582
  }, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer");
4587
4583
  function SlateContainer(props) {
4588
- const $ = c(28), {
4584
+ const $ = c(26), {
4589
4585
  editorActor,
4590
- patches$,
4591
4586
  portableTextEditor,
4592
4587
  readOnly,
4593
4588
  maxBlocks
4594
4589
  } = props;
4595
4590
  let t0;
4596
- $[0] !== editorActor || $[1] !== maxBlocks || $[2] !== patches$ || $[3] !== portableTextEditor || $[4] !== readOnly ? (t0 = () => {
4591
+ $[0] !== editorActor || $[1] !== maxBlocks || $[2] !== portableTextEditor || $[3] !== readOnly ? (t0 = () => {
4597
4592
  debug$6("Creating new Slate editor instance");
4598
4593
  const {
4599
4594
  editor,
@@ -4601,43 +4596,41 @@ function SlateContainer(props) {
4601
4596
  } = withPlugins(withReact(createEditor()), {
4602
4597
  editorActor,
4603
4598
  maxBlocks,
4604
- patches$,
4605
4599
  portableTextEditor,
4606
4600
  readOnly
4607
4601
  });
4608
4602
  return KEY_TO_VALUE_ELEMENT.set(editor, {}), KEY_TO_SLATE_ELEMENT.set(editor, {}), [editor, _sub];
4609
- }, $[0] = editorActor, $[1] = maxBlocks, $[2] = patches$, $[3] = portableTextEditor, $[4] = readOnly, $[5] = t0) : t0 = $[5];
4603
+ }, $[0] = editorActor, $[1] = maxBlocks, $[2] = portableTextEditor, $[3] = readOnly, $[4] = t0) : t0 = $[4];
4610
4604
  const [t1] = useState(t0), [slateEditor, subscribe] = t1;
4611
4605
  let t2, t3;
4612
- $[6] !== subscribe ? (t2 = () => {
4606
+ $[5] !== subscribe ? (t2 = () => {
4613
4607
  const unsubscribe = subscribe();
4614
4608
  return () => {
4615
4609
  unsubscribe();
4616
4610
  };
4617
- }, t3 = [subscribe], $[6] = subscribe, $[7] = t2, $[8] = t3) : (t2 = $[7], t3 = $[8]), useEffect(t2, t3);
4611
+ }, t3 = [subscribe], $[5] = subscribe, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3);
4618
4612
  let t4, t5;
4619
- $[9] !== slateEditor || $[10] !== editorActor || $[11] !== maxBlocks || $[12] !== patches$ || $[13] !== portableTextEditor || $[14] !== readOnly ? (t4 = () => {
4613
+ $[8] !== slateEditor || $[9] !== editorActor || $[10] !== maxBlocks || $[11] !== portableTextEditor || $[12] !== readOnly ? (t4 = () => {
4620
4614
  debug$6("Re-initializing plugin chain"), withPlugins(slateEditor, {
4621
4615
  editorActor,
4622
4616
  maxBlocks,
4623
- patches$,
4624
4617
  portableTextEditor,
4625
4618
  readOnly
4626
4619
  });
4627
- }, t5 = [editorActor, portableTextEditor, maxBlocks, readOnly, patches$, slateEditor], $[9] = slateEditor, $[10] = editorActor, $[11] = maxBlocks, $[12] = patches$, $[13] = portableTextEditor, $[14] = readOnly, $[15] = t4, $[16] = t5) : (t4 = $[15], t5 = $[16]), useEffect(t4, t5);
4620
+ }, t5 = [editorActor, portableTextEditor, maxBlocks, readOnly, slateEditor], $[8] = slateEditor, $[9] = editorActor, $[10] = maxBlocks, $[11] = portableTextEditor, $[12] = readOnly, $[13] = t4, $[14] = t5) : (t4 = $[13], t5 = $[14]), useEffect(t4, t5);
4628
4621
  let t6, t7;
4629
- $[17] !== slateEditor ? (t7 = slateEditor.pteCreateTextBlock({
4622
+ $[15] !== slateEditor ? (t7 = slateEditor.pteCreateTextBlock({
4630
4623
  decorators: []
4631
- }), $[17] = slateEditor, $[18] = t7) : t7 = $[18];
4624
+ }), $[15] = slateEditor, $[16] = t7) : t7 = $[16];
4632
4625
  let t8;
4633
- $[19] !== t7 ? (t8 = [t7], $[19] = t7, $[20] = t8) : t8 = $[20], t6 = t8;
4626
+ $[17] !== t7 ? (t8 = [t7], $[17] = t7, $[18] = t8) : t8 = $[18], t6 = t8;
4634
4627
  const initialValue = t6;
4635
4628
  let t9, t10;
4636
- $[21] !== slateEditor ? (t9 = () => () => {
4629
+ $[19] !== slateEditor ? (t9 = () => () => {
4637
4630
  debug$6("Destroying Slate editor"), slateEditor.destroy();
4638
- }, t10 = [slateEditor], $[21] = slateEditor, $[22] = t9, $[23] = t10) : (t9 = $[22], t10 = $[23]), useEffect(t9, t10);
4631
+ }, t10 = [slateEditor], $[19] = slateEditor, $[20] = t9, $[21] = t10) : (t9 = $[20], t10 = $[21]), useEffect(t9, t10);
4639
4632
  let t11;
4640
- return $[24] !== slateEditor || $[25] !== initialValue || $[26] !== props.children ? (t11 = /* @__PURE__ */ jsx(Slate, { editor: slateEditor, initialValue, children: props.children }), $[24] = slateEditor, $[25] = initialValue, $[26] = props.children, $[27] = t11) : t11 = $[27], t11;
4633
+ return $[22] !== slateEditor || $[23] !== initialValue || $[24] !== props.children ? (t11 = /* @__PURE__ */ jsx(Slate, { editor: slateEditor, initialValue, children: props.children }), $[22] = slateEditor, $[23] = initialValue, $[24] = props.children, $[25] = t11) : t11 = $[25], t11;
4641
4634
  }
4642
4635
  SlateContainer.displayName = "SlateContainer";
4643
4636
  const PortableTextEditorReadOnlyContext = createContext(!1), usePortableTextEditorReadOnlyStatus = () => {
@@ -4683,9 +4676,9 @@ function useSyncValue(props) {
4683
4676
  withoutPatching(slateEditor, () => {
4684
4677
  hadSelection && Transforms.deselect(slateEditor);
4685
4678
  const childrenLength = slateEditor.children.length;
4686
- slateEditor.children.forEach((_, index) => {
4679
+ slateEditor.children.forEach((_, index2) => {
4687
4680
  Transforms.removeNodes(slateEditor, {
4688
- at: [childrenLength - 1 - index]
4681
+ at: [childrenLength - 1 - index2]
4689
4682
  });
4690
4683
  }), Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
4691
4684
  decorators: []
@@ -4790,8 +4783,8 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
4790
4783
  at: [currentBlockIndex]
4791
4784
  }), slateEditor.isTextBlock(currentBlock) && slateEditor.isTextBlock(oldBlock)) {
4792
4785
  const oldBlockChildrenLength = oldBlock.children.length;
4793
- currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
4794
- const childIndex = oldBlockChildrenLength - 1 - index;
4786
+ currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index2) => {
4787
+ const childIndex = oldBlockChildrenLength - 1 - index2;
4795
4788
  childIndex > 0 && (debug$5("Removing child"), Transforms.removeNodes(slateEditor, {
4796
4789
  at: [currentBlockIndex, childIndex]
4797
4790
  }));
@@ -4834,20 +4827,28 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
4834
4827
  }
4835
4828
  const debug$4 = debugWithName("component:PortableTextEditor:Synchronizer"), debugVerbose$1 = debug$4.enabled && !1, FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3;
4836
4829
  function Synchronizer(props) {
4837
- const portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), {
4830
+ const $ = c(35), portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), {
4838
4831
  editorActor,
4839
4832
  getValue,
4840
4833
  onChange,
4841
4834
  value
4842
- } = props, pendingPatches = useRef([]), syncValue = useSyncValue({
4835
+ } = props;
4836
+ let t0;
4837
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
4838
+ const pendingPatches = useRef(t0);
4839
+ let t1;
4840
+ $[1] !== editorActor || $[2] !== portableTextEditor || $[3] !== readOnly ? (t1 = {
4843
4841
  editorActor,
4844
4842
  portableTextEditor,
4845
4843
  readOnly
4846
- }), slateEditor = useSlate();
4847
- useEffect(() => {
4844
+ }, $[1] = editorActor, $[2] = portableTextEditor, $[3] = readOnly, $[4] = t1) : t1 = $[4];
4845
+ const syncValue = useSyncValue(t1), slateEditor = useSlate();
4846
+ let t2, t3;
4847
+ $[5] !== slateEditor ? (t2 = () => {
4848
4848
  IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
4849
- }, [slateEditor]);
4850
- const onFlushPendingPatches = useCallback(() => {
4849
+ }, t3 = [slateEditor], $[5] = slateEditor, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3);
4850
+ let t4;
4851
+ $[8] !== getValue || $[9] !== editorActor || $[10] !== slateEditor ? (t4 = () => {
4851
4852
  if (pendingPatches.current.length > 0) {
4852
4853
  debug$4("Flushing pending patches"), debugVerbose$1 && debug$4(`Patches:
4853
4854
  ${JSON.stringify(pendingPatches.current, null, 2)}`);
@@ -4859,61 +4860,68 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
4859
4860
  }), pendingPatches.current = [];
4860
4861
  }
4861
4862
  IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
4862
- }, [editorActor, slateEditor, getValue]), onFlushPendingPatchesThrottled = useMemo(() => throttle(() => {
4863
- if (Editor.isNormalizing(slateEditor)) {
4864
- onFlushPendingPatches();
4865
- return;
4866
- }
4867
- onFlushPendingPatchesThrottled();
4868
- }, FLUSH_PATCHES_THROTTLED_MS, {
4869
- leading: !1,
4870
- trailing: !0
4871
- }), [onFlushPendingPatches, slateEditor]);
4872
- useEffect(() => () => {
4863
+ }, $[8] = getValue, $[9] = editorActor, $[10] = slateEditor, $[11] = t4) : t4 = $[11];
4864
+ const onFlushPendingPatches = t4;
4865
+ let t5, t6;
4866
+ $[12] !== onFlushPendingPatches ? (t5 = () => () => {
4873
4867
  onFlushPendingPatches();
4874
- }, [onFlushPendingPatches]);
4875
- const handleChange = useEffectEvent((change) => onChange(change));
4876
- useEffect(() => {
4868
+ }, t6 = [onFlushPendingPatches], $[12] = onFlushPendingPatches, $[13] = t5, $[14] = t6) : (t5 = $[13], t6 = $[14]), useEffect(t5, t6);
4869
+ let t7;
4870
+ $[15] !== onChange ? (t7 = (change) => onChange(change), $[15] = onChange, $[16] = t7) : t7 = $[16];
4871
+ const handleChange = useEffectEvent(t7);
4872
+ let t8, t9;
4873
+ $[17] !== slateEditor || $[18] !== onFlushPendingPatches || $[19] !== editorActor || $[20] !== handleChange ? (t8 = () => {
4874
+ const onFlushPendingPatchesThrottled = throttle(() => {
4875
+ if (Editor.isNormalizing(slateEditor)) {
4876
+ onFlushPendingPatches();
4877
+ return;
4878
+ }
4879
+ onFlushPendingPatchesThrottled();
4880
+ }, FLUSH_PATCHES_THROTTLED_MS, {
4881
+ leading: !1,
4882
+ trailing: !0
4883
+ });
4877
4884
  debug$4("Subscribing to editor changes");
4878
4885
  const sub = editorActor.on("*", (event) => {
4879
- switch (event.type) {
4880
- case "patch":
4886
+ bb18: switch (event.type) {
4887
+ case "patch": {
4881
4888
  IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !0), pendingPatches.current.push(event.patch), onFlushPendingPatchesThrottled(), handleChange(event);
4882
- break;
4889
+ break bb18;
4890
+ }
4883
4891
  case "loading": {
4884
4892
  handleChange({
4885
4893
  type: "loading",
4886
4894
  isLoading: !0
4887
4895
  });
4888
- break;
4896
+ break bb18;
4889
4897
  }
4890
4898
  case "done loading": {
4891
4899
  handleChange({
4892
4900
  type: "loading",
4893
4901
  isLoading: !1
4894
4902
  });
4895
- break;
4903
+ break bb18;
4896
4904
  }
4897
4905
  case "offline": {
4898
4906
  handleChange({
4899
4907
  type: "connection",
4900
4908
  value: "offline"
4901
4909
  });
4902
- break;
4910
+ break bb18;
4903
4911
  }
4904
4912
  case "online": {
4905
4913
  handleChange({
4906
4914
  type: "connection",
4907
4915
  value: "online"
4908
4916
  });
4909
- break;
4917
+ break bb18;
4910
4918
  }
4911
4919
  case "value changed": {
4912
4920
  handleChange({
4913
4921
  type: "value",
4914
4922
  value: event.value
4915
4923
  });
4916
- break;
4924
+ break bb18;
4917
4925
  }
4918
4926
  case "invalid value": {
4919
4927
  handleChange({
@@ -4921,15 +4929,17 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
4921
4929
  resolution: event.resolution,
4922
4930
  value: event.value
4923
4931
  });
4924
- break;
4932
+ break bb18;
4925
4933
  }
4926
4934
  case "error": {
4927
4935
  handleChange({
4928
4936
  ...event,
4929
4937
  level: "warning"
4930
4938
  });
4931
- break;
4939
+ break bb18;
4932
4940
  }
4941
+ case "patches":
4942
+ break bb18;
4933
4943
  default:
4934
4944
  handleChange(event);
4935
4945
  }
@@ -4937,24 +4947,26 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
4937
4947
  return () => {
4938
4948
  debug$4("Unsubscribing to changes"), sub.unsubscribe();
4939
4949
  };
4940
- }, [handleChange, editorActor, onFlushPendingPatchesThrottled, slateEditor]);
4941
- const handleOnline = useCallback(() => {
4950
+ }, t9 = [editorActor, handleChange, onFlushPendingPatches, slateEditor], $[17] = slateEditor, $[18] = onFlushPendingPatches, $[19] = editorActor, $[20] = handleChange, $[21] = t8, $[22] = t9) : (t8 = $[21], t9 = $[22]), useEffect(t8, t9);
4951
+ let t10;
4952
+ $[23] !== syncValue || $[24] !== value ? (t10 = () => {
4942
4953
  debug$4("Editor is online, syncing from props.value"), syncValue(value);
4943
- }, [syncValue, value]);
4944
- useEffect(() => {
4945
- const subscription = editorActor.on("online", () => {
4946
- portableTextEditor.props.patches$ && handleOnline();
4947
- });
4954
+ }, $[23] = syncValue, $[24] = value, $[25] = t10) : t10 = $[25];
4955
+ const handleOnline = t10;
4956
+ let t11, t12;
4957
+ $[26] !== editorActor || $[27] !== handleOnline ? (t11 = () => {
4958
+ const subscription = editorActor.on("online", handleOnline);
4948
4959
  return () => {
4949
4960
  subscription.unsubscribe();
4950
4961
  };
4951
- }, [handleOnline, editorActor, portableTextEditor.props.patches$]);
4962
+ }, t12 = [handleOnline, editorActor], $[26] = editorActor, $[27] = handleOnline, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), useEffect(t11, t12);
4952
4963
  const isInitialValueFromProps = useRef(!0);
4953
- return useEffect(() => {
4964
+ let t13, t14;
4965
+ return $[30] !== syncValue || $[31] !== value || $[32] !== editorActor ? (t13 = () => {
4954
4966
  debug$4("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (editorActor.send({
4955
4967
  type: "ready"
4956
4968
  }), isInitialValueFromProps.current = !1);
4957
- }, [editorActor, syncValue, value]), null;
4969
+ }, t14 = [editorActor, syncValue, value], $[30] = syncValue, $[31] = value, $[32] = editorActor, $[33] = t13, $[34] = t14) : (t13 = $[33], t14 = $[34]), useEffect(t13, t14), null;
4958
4970
  }
4959
4971
  Synchronizer.displayName = "Synchronizer";
4960
4972
  const EditorActorContext = createContext({}), insertBreakActionImplementation = ({
@@ -5269,7 +5281,137 @@ function performDefaultAction({
5269
5281
  });
5270
5282
  }
5271
5283
  }
5272
- const networkLogic = fromCallback(({
5284
+ const breakingVoidBlock = {
5285
+ on: "insert break",
5286
+ guard: ({
5287
+ context
5288
+ }) => !!getFocusBlockObject(context),
5289
+ actions: [() => [{
5290
+ type: "insert text block",
5291
+ decorators: []
5292
+ }]]
5293
+ }, deletingEmptyTextBlockAfterBlockObject = {
5294
+ on: "delete backward",
5295
+ guard: ({
5296
+ context
5297
+ }) => {
5298
+ const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
5299
+ return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(previousBlock.node) ? {
5300
+ focusTextBlock,
5301
+ previousBlock
5302
+ } : !1;
5303
+ },
5304
+ actions: [(_, {
5305
+ focusTextBlock,
5306
+ previousBlock
5307
+ }) => [{
5308
+ type: "delete",
5309
+ selection: {
5310
+ anchor: {
5311
+ path: focusTextBlock.path,
5312
+ offset: 0
5313
+ },
5314
+ focus: {
5315
+ path: focusTextBlock.path,
5316
+ offset: 0
5317
+ }
5318
+ }
5319
+ }, {
5320
+ type: "select",
5321
+ selection: {
5322
+ anchor: {
5323
+ path: previousBlock.path,
5324
+ offset: 0
5325
+ },
5326
+ focus: {
5327
+ path: previousBlock.path,
5328
+ offset: 0
5329
+ }
5330
+ }
5331
+ }]]
5332
+ }, deletingEmptyTextBlockBeforeBlockObject = {
5333
+ on: "delete forward",
5334
+ guard: ({
5335
+ context
5336
+ }) => {
5337
+ const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
5338
+ return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(nextBlock.node) ? {
5339
+ focusTextBlock,
5340
+ nextBlock
5341
+ } : !1;
5342
+ },
5343
+ actions: [(_, {
5344
+ focusTextBlock,
5345
+ nextBlock
5346
+ }) => [{
5347
+ type: "delete",
5348
+ selection: {
5349
+ anchor: {
5350
+ path: focusTextBlock.path,
5351
+ offset: 0
5352
+ },
5353
+ focus: {
5354
+ path: focusTextBlock.path,
5355
+ offset: 0
5356
+ }
5357
+ }
5358
+ }, {
5359
+ type: "select",
5360
+ selection: {
5361
+ anchor: {
5362
+ path: nextBlock.path,
5363
+ offset: 0
5364
+ },
5365
+ focus: {
5366
+ path: nextBlock.path,
5367
+ offset: 0
5368
+ }
5369
+ }
5370
+ }]]
5371
+ }, coreBlockObjectBehaviors = [breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], clearListOnBackspace = {
5372
+ on: "delete backward",
5373
+ guard: ({
5374
+ context
5375
+ }) => {
5376
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
5377
+ return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
5378
+ focusTextBlock
5379
+ } : !1;
5380
+ },
5381
+ actions: [(_, {
5382
+ focusTextBlock
5383
+ }) => [{
5384
+ type: "unset block",
5385
+ props: ["listItem", "level"],
5386
+ paths: [focusTextBlock.path]
5387
+ }]]
5388
+ }, unindentListOnBackspace = {
5389
+ on: "delete backward",
5390
+ guard: ({
5391
+ context
5392
+ }) => {
5393
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
5394
+ return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
5395
+ focusTextBlock,
5396
+ level: focusTextBlock.node.level - 1
5397
+ } : !1;
5398
+ },
5399
+ actions: [(_, {
5400
+ focusTextBlock,
5401
+ level
5402
+ }) => [{
5403
+ type: "set block",
5404
+ level,
5405
+ paths: [focusTextBlock.path]
5406
+ }]]
5407
+ }, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
5408
+ on: "insert soft break",
5409
+ actions: [() => [{
5410
+ type: "insert text",
5411
+ text: `
5412
+ `
5413
+ }]]
5414
+ }, coreBehaviors = [softReturn, ...coreBlockObjectBehaviors, ...coreListBehaviors], networkLogic = fromCallback(({
5273
5415
  sendBack
5274
5416
  }) => {
5275
5417
  const onlineHandler = () => {
@@ -5292,6 +5434,11 @@ const networkLogic = fromCallback(({
5292
5434
  input: {}
5293
5435
  },
5294
5436
  actions: {
5437
+ "assign behaviors": assign({
5438
+ behaviors: ({
5439
+ event
5440
+ }) => (assertEvent(event, "update behaviors"), [...coreBehaviors, ...event.behaviors])
5441
+ }),
5295
5442
  "assign schema": assign({
5296
5443
  schema: ({
5297
5444
  event
@@ -5384,7 +5531,7 @@ const networkLogic = fromCallback(({
5384
5531
  context: ({
5385
5532
  input
5386
5533
  }) => ({
5387
- behaviors: input.behaviors,
5534
+ behaviors: input.behaviors ? [...coreBehaviors, ...input.behaviors] : coreBehaviors,
5388
5535
  keyGenerator: input.keyGenerator,
5389
5536
  pendingEvents: [],
5390
5537
  schema: input.schema
@@ -5449,11 +5596,19 @@ const networkLogic = fromCallback(({
5449
5596
  type: "loading"
5450
5597
  })
5451
5598
  },
5599
+ patches: {
5600
+ actions: emit(({
5601
+ event
5602
+ }) => event)
5603
+ },
5452
5604
  "done loading": {
5453
5605
  actions: emit({
5454
5606
  type: "done loading"
5455
5607
  })
5456
5608
  },
5609
+ "update behaviors": {
5610
+ actions: "assign behaviors"
5611
+ },
5457
5612
  "update schema": {
5458
5613
  actions: "assign schema"
5459
5614
  },
@@ -5564,18 +5719,21 @@ class PortableTextEditor extends Component {
5564
5719
  * The editor API (currently implemented with Slate).
5565
5720
  */
5566
5721
  constructor(props) {
5567
- if (super(props), !props.schemaType)
5568
- throw new Error('PortableTextEditor: missing "schemaType" property');
5569
- props.incomingPatches$ && console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"), this.schemaTypes = getPortableTextMemberSchemaTypes(props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)), this.editorActor = createActor(editorMachine, {
5570
- input: {
5571
- behaviors: coreBehaviors,
5572
- keyGenerator: props.keyGenerator || defaultKeyGenerator,
5573
- schema: this.schemaTypes
5574
- }
5575
- }), this.editorActor.start();
5722
+ if (super(props), props.editor)
5723
+ this.editorActor = props.editor, this.editorActor.start(), this.schemaTypes = this.editorActor.getSnapshot().context.schema;
5724
+ else {
5725
+ if (!props.schemaType)
5726
+ throw new Error('PortableTextEditor: missing "schemaType" property');
5727
+ props.incomingPatches$ && console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"), this.schemaTypes = getPortableTextMemberSchemaTypes(props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)), this.editorActor = props.editor ?? createActor(editorMachine, {
5728
+ input: {
5729
+ keyGenerator: props.keyGenerator || defaultKeyGenerator,
5730
+ schema: this.schemaTypes
5731
+ }
5732
+ }), this.editorActor.start();
5733
+ }
5576
5734
  }
5577
5735
  componentDidUpdate(prevProps) {
5578
- this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editorActor.send({
5736
+ !this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editorActor.send({
5579
5737
  type: "update schema",
5580
5738
  schema: this.schemaTypes
5581
5739
  })), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this);
@@ -5591,18 +5749,16 @@ class PortableTextEditor extends Component {
5591
5749
  return this.editable.getValue();
5592
5750
  };
5593
5751
  render() {
5594
- const {
5595
- value,
5596
- children,
5597
- patches$,
5598
- incomingPatches$
5599
- } = this.props, _patches$ = incomingPatches$ || patches$, maxBlocks = typeof this.props.maxBlocks > "u" ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly;
5600
- return /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editorActor, children: /* @__PURE__ */ jsx(SlateContainer, { editorActor: this.editorActor, maxBlocks, patches$: _patches$, portableTextEditor: this, readOnly, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsx(PortableTextEditorReadOnlyContext.Provider, { value: readOnly, children: /* @__PURE__ */ jsxs(PortableTextEditorSelectionProvider, { editorActor: this.editorActor, children: [
5601
- /* @__PURE__ */ jsx(Synchronizer, { editorActor: this.editorActor, getValue: this.getValue, onChange: (change) => {
5602
- this.props.onChange(change), this.change$.next(change);
5603
- }, value }),
5604
- children
5605
- ] }) }) }) }) });
5752
+ const maxBlocks = this.props.editor || typeof this.props.maxBlocks > "u" ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly, legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
5753
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
5754
+ legacyPatches ? /* @__PURE__ */ jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editorActor, patches$: legacyPatches }) : null,
5755
+ /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editorActor, children: /* @__PURE__ */ jsx(SlateContainer, { editorActor: this.editorActor, maxBlocks, portableTextEditor: this, readOnly, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsx(PortableTextEditorReadOnlyContext.Provider, { value: readOnly, children: /* @__PURE__ */ jsxs(PortableTextEditorSelectionProvider, { editorActor: this.editorActor, children: [
5756
+ /* @__PURE__ */ jsx(Synchronizer, { editorActor: this.editorActor, getValue: this.getValue, onChange: (change) => {
5757
+ this.props.editor || this.props.onChange(change), this.change$.next(change);
5758
+ }, value: this.props.value }),
5759
+ this.props.children
5760
+ ] }) }) }) }) })
5761
+ ] });
5606
5762
  }
5607
5763
  // Static API methods
5608
5764
  static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
@@ -5654,6 +5810,21 @@ class PortableTextEditor extends Component {
5654
5810
  };
5655
5811
  static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
5656
5812
  }
5813
+ function RoutePatchesObservableToEditorActor(props) {
5814
+ const $ = c(4);
5815
+ let t0, t1;
5816
+ return $[0] !== props.patches$ || $[1] !== props.editorActor ? (t0 = () => {
5817
+ const subscription = props.patches$.subscribe((payload) => {
5818
+ props.editorActor.send({
5819
+ type: "patches",
5820
+ ...payload
5821
+ });
5822
+ });
5823
+ return () => {
5824
+ subscription.unsubscribe();
5825
+ };
5826
+ }, t1 = [props.editorActor, props.patches$], $[0] = props.patches$, $[1] = props.editorActor, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1), null;
5827
+ }
5657
5828
  const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
5658
5829
  const {
5659
5830
  editorActor,
@@ -6043,11 +6214,334 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6043
6214
  ) : null;
6044
6215
  });
6045
6216
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
6217
+ var index = typeof document < "u" ? useLayoutEffect : useEffect, withSelector = { exports: {} }, withSelector_production_min = {}, shim = { exports: {} }, useSyncExternalStoreShim_production_min = {};
6218
+ /**
6219
+ * @license React
6220
+ * use-sync-external-store-shim.production.min.js
6221
+ *
6222
+ * Copyright (c) Facebook, Inc. and its affiliates.
6223
+ *
6224
+ * This source code is licensed under the MIT license found in the
6225
+ * LICENSE file in the root directory of this source tree.
6226
+ */
6227
+ var hasRequiredUseSyncExternalStoreShim_production_min;
6228
+ function requireUseSyncExternalStoreShim_production_min() {
6229
+ if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
6230
+ hasRequiredUseSyncExternalStoreShim_production_min = 1;
6231
+ var e = require$$0;
6232
+ function h(a, b) {
6233
+ return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
6234
+ }
6235
+ var k = typeof Object.is == "function" ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue;
6236
+ function q(a, b) {
6237
+ var d = b(), f = l({
6238
+ inst: {
6239
+ value: d,
6240
+ getSnapshot: b
6241
+ }
6242
+ }), c2 = f[0].inst, g = f[1];
6243
+ return n(function() {
6244
+ c2.value = d, c2.getSnapshot = b, r(c2) && g({
6245
+ inst: c2
6246
+ });
6247
+ }, [a, d, b]), m(function() {
6248
+ return r(c2) && g({
6249
+ inst: c2
6250
+ }), a(function() {
6251
+ r(c2) && g({
6252
+ inst: c2
6253
+ });
6254
+ });
6255
+ }, [a]), p(d), d;
6256
+ }
6257
+ function r(a) {
6258
+ var b = a.getSnapshot;
6259
+ a = a.value;
6260
+ try {
6261
+ var d = b();
6262
+ return !k(a, d);
6263
+ } catch {
6264
+ return !0;
6265
+ }
6266
+ }
6267
+ function t(a, b) {
6268
+ return b();
6269
+ }
6270
+ var u = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? t : q;
6271
+ return useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : u, useSyncExternalStoreShim_production_min;
6272
+ }
6273
+ var useSyncExternalStoreShim_development = {};
6274
+ /**
6275
+ * @license React
6276
+ * use-sync-external-store-shim.development.js
6277
+ *
6278
+ * Copyright (c) Facebook, Inc. and its affiliates.
6279
+ *
6280
+ * This source code is licensed under the MIT license found in the
6281
+ * LICENSE file in the root directory of this source tree.
6282
+ */
6283
+ var hasRequiredUseSyncExternalStoreShim_development;
6284
+ function requireUseSyncExternalStoreShim_development() {
6285
+ return hasRequiredUseSyncExternalStoreShim_development || (hasRequiredUseSyncExternalStoreShim_development = 1, process.env.NODE_ENV !== "production" && function() {
6286
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
6287
+ var React = require$$0, ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
6288
+ function error(format) {
6289
+ {
6290
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++)
6291
+ args[_key2 - 1] = arguments[_key2];
6292
+ printWarning("error", format, args);
6293
+ }
6294
+ }
6295
+ function printWarning(level, format, args) {
6296
+ {
6297
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame, stack = ReactDebugCurrentFrame.getStackAddendum();
6298
+ stack !== "" && (format += "%s", args = args.concat([stack]));
6299
+ var argsWithFormat = args.map(function(item) {
6300
+ return String(item);
6301
+ });
6302
+ argsWithFormat.unshift("Warning: " + format), Function.prototype.apply.call(console[level], console, argsWithFormat);
6303
+ }
6304
+ }
6305
+ function is(x, y) {
6306
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
6307
+ }
6308
+ var objectIs = typeof Object.is == "function" ? Object.is : is, useState2 = React.useState, useEffect2 = React.useEffect, useLayoutEffect2 = React.useLayoutEffect, useDebugValue = React.useDebugValue, didWarnOld18Alpha = !1, didWarnUncachedGetSnapshot = !1;
6309
+ function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
6310
+ didWarnOld18Alpha || React.startTransition !== void 0 && (didWarnOld18Alpha = !0, error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));
6311
+ var value = getSnapshot();
6312
+ if (!didWarnUncachedGetSnapshot) {
6313
+ var cachedValue = getSnapshot();
6314
+ objectIs(value, cachedValue) || (error("The result of getSnapshot should be cached to avoid an infinite loop"), didWarnUncachedGetSnapshot = !0);
6315
+ }
6316
+ var _useState = useState2({
6317
+ inst: {
6318
+ value,
6319
+ getSnapshot
6320
+ }
6321
+ }), inst = _useState[0].inst, forceUpdate = _useState[1];
6322
+ return useLayoutEffect2(function() {
6323
+ inst.value = value, inst.getSnapshot = getSnapshot, checkIfSnapshotChanged(inst) && forceUpdate({
6324
+ inst
6325
+ });
6326
+ }, [subscribe, value, getSnapshot]), useEffect2(function() {
6327
+ checkIfSnapshotChanged(inst) && forceUpdate({
6328
+ inst
6329
+ });
6330
+ var handleStoreChange = function() {
6331
+ checkIfSnapshotChanged(inst) && forceUpdate({
6332
+ inst
6333
+ });
6334
+ };
6335
+ return subscribe(handleStoreChange);
6336
+ }, [subscribe]), useDebugValue(value), value;
6337
+ }
6338
+ function checkIfSnapshotChanged(inst) {
6339
+ var latestGetSnapshot = inst.getSnapshot, prevValue = inst.value;
6340
+ try {
6341
+ var nextValue = latestGetSnapshot();
6342
+ return !objectIs(prevValue, nextValue);
6343
+ } catch {
6344
+ return !0;
6345
+ }
6346
+ }
6347
+ function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
6348
+ return getSnapshot();
6349
+ }
6350
+ var canUseDOM = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", isServerEnvironment = !canUseDOM, shim2 = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore, useSyncExternalStore$2 = React.useSyncExternalStore !== void 0 ? React.useSyncExternalStore : shim2;
6351
+ useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
6352
+ }()), useSyncExternalStoreShim_development;
6353
+ }
6354
+ var hasRequiredShim;
6355
+ function requireShim() {
6356
+ return hasRequiredShim || (hasRequiredShim = 1, process.env.NODE_ENV === "production" ? shim.exports = requireUseSyncExternalStoreShim_production_min() : shim.exports = requireUseSyncExternalStoreShim_development()), shim.exports;
6357
+ }
6358
+ /**
6359
+ * @license React
6360
+ * use-sync-external-store-shim/with-selector.production.min.js
6361
+ *
6362
+ * Copyright (c) Facebook, Inc. and its affiliates.
6363
+ *
6364
+ * This source code is licensed under the MIT license found in the
6365
+ * LICENSE file in the root directory of this source tree.
6366
+ */
6367
+ var hasRequiredWithSelector_production_min;
6368
+ function requireWithSelector_production_min() {
6369
+ if (hasRequiredWithSelector_production_min) return withSelector_production_min;
6370
+ hasRequiredWithSelector_production_min = 1;
6371
+ var h = require$$0, n = requireShim();
6372
+ function p(a, b) {
6373
+ return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
6374
+ }
6375
+ var q = typeof Object.is == "function" ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
6376
+ return withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
6377
+ var c2 = t(null);
6378
+ if (c2.current === null) {
6379
+ var f = {
6380
+ hasValue: !1,
6381
+ value: null
6382
+ };
6383
+ c2.current = f;
6384
+ } else f = c2.current;
6385
+ c2 = v(function() {
6386
+ function a2(a3) {
6387
+ if (!c3) {
6388
+ if (c3 = !0, d2 = a3, a3 = l(a3), g !== void 0 && f.hasValue) {
6389
+ var b2 = f.value;
6390
+ if (g(b2, a3)) return k = b2;
6391
+ }
6392
+ return k = a3;
6393
+ }
6394
+ if (b2 = k, q(d2, a3)) return b2;
6395
+ var e2 = l(a3);
6396
+ return g !== void 0 && g(b2, e2) ? b2 : (d2 = a3, k = e2);
6397
+ }
6398
+ var c3 = !1, d2, k, m = e === void 0 ? null : e;
6399
+ return [function() {
6400
+ return a2(b());
6401
+ }, m === null ? void 0 : function() {
6402
+ return a2(m());
6403
+ }];
6404
+ }, [b, e, l, g]);
6405
+ var d = r(a, c2[0], c2[1]);
6406
+ return u(function() {
6407
+ f.hasValue = !0, f.value = d;
6408
+ }, [d]), w(d), d;
6409
+ }, withSelector_production_min;
6410
+ }
6411
+ var withSelector_development = {};
6412
+ /**
6413
+ * @license React
6414
+ * use-sync-external-store-shim/with-selector.development.js
6415
+ *
6416
+ * Copyright (c) Facebook, Inc. and its affiliates.
6417
+ *
6418
+ * This source code is licensed under the MIT license found in the
6419
+ * LICENSE file in the root directory of this source tree.
6420
+ */
6421
+ var hasRequiredWithSelector_development;
6422
+ function requireWithSelector_development() {
6423
+ return hasRequiredWithSelector_development || (hasRequiredWithSelector_development = 1, process.env.NODE_ENV !== "production" && function() {
6424
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
6425
+ var React = require$$0, shim2 = requireShim();
6426
+ function is(x, y) {
6427
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
6428
+ }
6429
+ var objectIs = typeof Object.is == "function" ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo2 = React.useMemo, useDebugValue = React.useDebugValue;
6430
+ function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual2) {
6431
+ var instRef = useRef2(null), inst;
6432
+ instRef.current === null ? (inst = {
6433
+ hasValue: !1,
6434
+ value: null
6435
+ }, instRef.current = inst) : inst = instRef.current;
6436
+ var _useMemo = useMemo2(function() {
6437
+ var hasMemo = !1, memoizedSnapshot, memoizedSelection, memoizedSelector = function(nextSnapshot) {
6438
+ if (!hasMemo) {
6439
+ hasMemo = !0, memoizedSnapshot = nextSnapshot;
6440
+ var _nextSelection = selector(nextSnapshot);
6441
+ if (isEqual2 !== void 0 && inst.hasValue) {
6442
+ var currentSelection = inst.value;
6443
+ if (isEqual2(currentSelection, _nextSelection))
6444
+ return memoizedSelection = currentSelection, currentSelection;
6445
+ }
6446
+ return memoizedSelection = _nextSelection, _nextSelection;
6447
+ }
6448
+ var prevSnapshot = memoizedSnapshot, prevSelection = memoizedSelection;
6449
+ if (objectIs(prevSnapshot, nextSnapshot))
6450
+ return prevSelection;
6451
+ var nextSelection = selector(nextSnapshot);
6452
+ return isEqual2 !== void 0 && isEqual2(prevSelection, nextSelection) ? prevSelection : (memoizedSnapshot = nextSnapshot, memoizedSelection = nextSelection, nextSelection);
6453
+ }, maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot, getSnapshotWithSelector = function() {
6454
+ return memoizedSelector(getSnapshot());
6455
+ }, getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
6456
+ return memoizedSelector(maybeGetServerSnapshot());
6457
+ };
6458
+ return [getSnapshotWithSelector, getServerSnapshotWithSelector];
6459
+ }, [getSnapshot, getServerSnapshot, selector, isEqual2]), getSelection = _useMemo[0], getServerSelection = _useMemo[1], value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
6460
+ return useEffect2(function() {
6461
+ inst.hasValue = !0, inst.value = value;
6462
+ }, [value]), useDebugValue(value), value;
6463
+ }
6464
+ withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
6465
+ }()), withSelector_development;
6466
+ }
6467
+ var hasRequiredWithSelector;
6468
+ function requireWithSelector() {
6469
+ return hasRequiredWithSelector || (hasRequiredWithSelector = 1, process.env.NODE_ENV === "production" ? withSelector.exports = requireWithSelector_production_min() : withSelector.exports = requireWithSelector_development()), withSelector.exports;
6470
+ }
6471
+ requireWithSelector();
6472
+ requireShim();
6473
+ const forEachActor = (actorRef, callback) => {
6474
+ callback(actorRef);
6475
+ const children = actorRef.getSnapshot().children;
6476
+ children && Object.values(children).forEach((child) => {
6477
+ forEachActor(child, callback);
6478
+ });
6479
+ };
6480
+ function stopRootWithRehydration(actorRef) {
6481
+ const persistedSnapshots = [];
6482
+ forEachActor(actorRef, (ref) => {
6483
+ persistedSnapshots.push([ref, ref.getSnapshot()]), ref.observers = /* @__PURE__ */ new Set();
6484
+ });
6485
+ const systemSnapshot = actorRef.system.getSnapshot?.();
6486
+ actorRef.stop(), actorRef.system._snapshot = systemSnapshot, persistedSnapshots.forEach(([ref, snapshot]) => {
6487
+ ref._processingStatus = 0, ref._snapshot = snapshot;
6488
+ });
6489
+ }
6490
+ function useIdleActorRef(logic, ...[options]) {
6491
+ let [[currentConfig, actorRef], setCurrent] = useState(() => {
6492
+ const actorRef2 = createActor(logic, options);
6493
+ return [logic.config, actorRef2];
6494
+ });
6495
+ if (logic.config !== currentConfig) {
6496
+ const newActorRef = createActor(logic, {
6497
+ ...options,
6498
+ snapshot: actorRef.getPersistedSnapshot({
6499
+ __unsafeAllowInlineActors: !0
6500
+ })
6501
+ });
6502
+ setCurrent([logic.config, newActorRef]), actorRef = newActorRef;
6503
+ }
6504
+ return index(() => {
6505
+ actorRef.logic.implementations = logic.implementations;
6506
+ }), actorRef;
6507
+ }
6508
+ function useActorRef(machine, ...[options, observerOrListener]) {
6509
+ const actorRef = useIdleActorRef(machine, options);
6510
+ return useEffect(() => {
6511
+ if (!observerOrListener)
6512
+ return;
6513
+ let sub = actorRef.subscribe(toObserver(observerOrListener));
6514
+ return () => {
6515
+ sub.unsubscribe();
6516
+ };
6517
+ }, [observerOrListener]), useEffect(() => (actorRef.start(), () => {
6518
+ stopRootWithRehydration(actorRef);
6519
+ }), [actorRef]), actorRef;
6520
+ }
6521
+ function useEditor(config) {
6522
+ const $ = c(8);
6523
+ let t0;
6524
+ $[0] !== config.schema ? (t0 = config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema), $[0] = config.schema, $[1] = t0) : t0 = $[1];
6525
+ let t1;
6526
+ $[2] !== t0 ? (t1 = getPortableTextMemberSchemaTypes(t0), $[2] = t0, $[3] = t1) : t1 = $[3];
6527
+ const schema = t1, t2 = config.keyGenerator ?? defaultKeyGenerator;
6528
+ let t3;
6529
+ return $[4] !== config.behaviors || $[5] !== t2 || $[6] !== schema ? (t3 = {
6530
+ input: {
6531
+ behaviors: config.behaviors,
6532
+ keyGenerator: t2,
6533
+ schema
6534
+ }
6535
+ }, $[4] = config.behaviors, $[5] = t2, $[6] = schema, $[7] = t3) : t3 = $[7], useActorRef(editorMachine, t3);
6536
+ }
6046
6537
  export {
6047
6538
  PortableTextEditable,
6048
6539
  PortableTextEditor,
6540
+ createMarkdownBehaviors,
6541
+ defineBehavior,
6049
6542
  editorMachine,
6050
6543
  defaultKeyGenerator as keyGenerator,
6544
+ useEditor,
6051
6545
  usePortableTextEditor,
6052
6546
  usePortableTextEditorSelection
6053
6547
  };