@portabletext/editor 1.3.1 → 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.mjs 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) {
@@ -715,305 +955,64 @@ function DefaultAnnotation(props) {
715
955
  }
716
956
  DefaultAnnotation.displayName = "DefaultAnnotation";
717
957
  function getPortableTextMemberSchemaTypes(portableTextType) {
718
- if (!portableTextType)
719
- throw new Error("Parameter 'portabletextType' missing (required)");
720
- const blockType = portableTextType.of?.find(findBlockType);
721
- if (!blockType)
722
- throw new Error("Block type is not defined in this schema (required)");
723
- const childrenField = blockType.fields?.find((field) => field.name === "children");
724
- if (!childrenField)
725
- throw new Error("Children field for block type found in schema (required)");
726
- const ofType = childrenField.type.of;
727
- if (!ofType)
728
- throw new Error("Valid types for block children not found in schema (required)");
729
- const spanType = ofType.find((memberType) => memberType.name === "span");
730
- if (!spanType)
731
- throw new Error("Span type not found in schema (required)");
732
- const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
733
- return {
734
- styles: resolveEnabledStyles(blockType),
735
- decorators: resolveEnabledDecorators(spanType),
736
- lists: resolveEnabledListItems(blockType),
737
- block: blockType,
738
- span: spanType,
739
- portableText: portableTextType,
740
- inlineObjects: inlineObjectTypes,
741
- blockObjects: blockObjectTypes,
742
- annotations: spanType.annotations
743
- };
744
- }
745
- function resolveEnabledStyles(blockType) {
746
- const styleField = blockType.fields?.find((btField) => btField.name === "style");
747
- if (!styleField)
748
- throw new Error("A field with name 'style' is not defined in the block type (required).");
749
- const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
750
- if (!textStyles || textStyles.length === 0)
751
- throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
752
- return textStyles;
753
- }
754
- function resolveEnabledDecorators(spanType) {
755
- return spanType.decorators;
756
- }
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");
958
+ if (!portableTextType)
959
+ throw new Error("Parameter 'portabletextType' missing (required)");
960
+ const blockType = portableTextType.of?.find(findBlockType);
961
+ if (!blockType)
962
+ throw new Error("Block type is not defined in this schema (required)");
963
+ const childrenField = blockType.fields?.find((field) => field.name === "children");
964
+ if (!childrenField)
965
+ throw new Error("Children field for block type found in schema (required)");
966
+ const ofType = childrenField.type.of;
967
+ if (!ofType)
968
+ throw new Error("Valid types for block children not found in schema (required)");
969
+ const spanType = ofType.find((memberType) => memberType.name === "span");
970
+ if (!spanType)
971
+ throw new Error("Span type not found in schema (required)");
972
+ const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
973
+ return {
974
+ styles: resolveEnabledStyles(blockType),
975
+ decorators: resolveEnabledDecorators(spanType),
976
+ lists: resolveEnabledListItems(blockType),
977
+ block: blockType,
978
+ span: spanType,
979
+ portableText: portableTextType,
980
+ inlineObjects: inlineObjectTypes,
981
+ blockObjects: blockObjectTypes,
982
+ annotations: spanType.annotations
983
+ };
984
+ }
985
+ function resolveEnabledStyles(blockType) {
986
+ const styleField = blockType.fields?.find((btField) => btField.name === "style");
987
+ if (!styleField)
988
+ throw new Error("A field with name 'style' is not defined in the block type (required).");
989
+ const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
990
+ if (!textStyles || textStyles.length === 0)
991
+ throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
992
+ return textStyles;
993
+ }
994
+ function resolveEnabledDecorators(spanType) {
995
+ return spanType.decorators;
996
+ }
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,
@@ -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
@@ -4017,10 +4016,10 @@ function validateValue(value, types, keyGenerator) {
4017
4016
  }
4018
4017
  },
4019
4018
  value
4020
- } : (value.some((blk, index) => {
4019
+ } : (value.some((blk, index2) => {
4021
4020
  if (!isPlainObject(blk))
4022
4021
  return resolution = {
4023
- patches: [unset([index])],
4022
+ patches: [unset([index2])],
4024
4023
  description: `Block must be an object, got ${String(blk)}`,
4025
4024
  action: "Unset invalid item",
4026
4025
  item: blk,
@@ -4028,7 +4027,7 @@ function validateValue(value, types, keyGenerator) {
4028
4027
  description: "inputs.portable-text.invalid-value.not-an-object.description",
4029
4028
  action: "inputs.portable-text.invalid-value.not-an-object.action",
4030
4029
  values: {
4031
- index
4030
+ index: index2
4032
4031
  }
4033
4032
  }
4034
4033
  }, !0;
@@ -4037,15 +4036,15 @@ function validateValue(value, types, keyGenerator) {
4037
4036
  patches: [set({
4038
4037
  ...blk,
4039
4038
  _key: keyGenerator()
4040
- }, [index])],
4041
- description: `Block at index ${index} is missing required _key.`,
4039
+ }, [index2])],
4040
+ description: `Block at index ${index2} is missing required _key.`,
4042
4041
  action: "Set the block with a random _key value",
4043
4042
  item: blk,
4044
4043
  i18n: {
4045
4044
  description: "inputs.portable-text.invalid-value.missing-key.description",
4046
4045
  action: "inputs.portable-text.invalid-value.missing-key.action",
4047
4046
  values: {
4048
- index
4047
+ index: index2
4049
4048
  }
4050
4049
  }
4051
4050
  }, !0;
@@ -4677,9 +4676,9 @@ function useSyncValue(props) {
4677
4676
  withoutPatching(slateEditor, () => {
4678
4677
  hadSelection && Transforms.deselect(slateEditor);
4679
4678
  const childrenLength = slateEditor.children.length;
4680
- slateEditor.children.forEach((_, index) => {
4679
+ slateEditor.children.forEach((_, index2) => {
4681
4680
  Transforms.removeNodes(slateEditor, {
4682
- at: [childrenLength - 1 - index]
4681
+ at: [childrenLength - 1 - index2]
4683
4682
  });
4684
4683
  }), Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
4685
4684
  decorators: []
@@ -4784,8 +4783,8 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
4784
4783
  at: [currentBlockIndex]
4785
4784
  }), slateEditor.isTextBlock(currentBlock) && slateEditor.isTextBlock(oldBlock)) {
4786
4785
  const oldBlockChildrenLength = oldBlock.children.length;
4787
- currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
4788
- 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;
4789
4788
  childIndex > 0 && (debug$5("Removing child"), Transforms.removeNodes(slateEditor, {
4790
4789
  at: [currentBlockIndex, childIndex]
4791
4790
  }));
@@ -5282,7 +5281,137 @@ function performDefaultAction({
5282
5281
  });
5283
5282
  }
5284
5283
  }
5285
- 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(({
5286
5415
  sendBack
5287
5416
  }) => {
5288
5417
  const onlineHandler = () => {
@@ -5305,6 +5434,11 @@ const networkLogic = fromCallback(({
5305
5434
  input: {}
5306
5435
  },
5307
5436
  actions: {
5437
+ "assign behaviors": assign({
5438
+ behaviors: ({
5439
+ event
5440
+ }) => (assertEvent(event, "update behaviors"), [...coreBehaviors, ...event.behaviors])
5441
+ }),
5308
5442
  "assign schema": assign({
5309
5443
  schema: ({
5310
5444
  event
@@ -5397,7 +5531,7 @@ const networkLogic = fromCallback(({
5397
5531
  context: ({
5398
5532
  input
5399
5533
  }) => ({
5400
- behaviors: input.behaviors,
5534
+ behaviors: input.behaviors ? [...coreBehaviors, ...input.behaviors] : coreBehaviors,
5401
5535
  keyGenerator: input.keyGenerator,
5402
5536
  pendingEvents: [],
5403
5537
  schema: input.schema
@@ -5472,6 +5606,9 @@ const networkLogic = fromCallback(({
5472
5606
  type: "done loading"
5473
5607
  })
5474
5608
  },
5609
+ "update behaviors": {
5610
+ actions: "assign behaviors"
5611
+ },
5475
5612
  "update schema": {
5476
5613
  actions: "assign schema"
5477
5614
  },
@@ -5582,18 +5719,21 @@ class PortableTextEditor extends Component {
5582
5719
  * The editor API (currently implemented with Slate).
5583
5720
  */
5584
5721
  constructor(props) {
5585
- if (super(props), !props.schemaType)
5586
- throw new Error('PortableTextEditor: missing "schemaType" property');
5587
- 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, {
5588
- input: {
5589
- behaviors: coreBehaviors,
5590
- keyGenerator: props.keyGenerator || defaultKeyGenerator,
5591
- schema: this.schemaTypes
5592
- }
5593
- }), 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
+ }
5594
5734
  }
5595
5735
  componentDidUpdate(prevProps) {
5596
- 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({
5597
5737
  type: "update schema",
5598
5738
  schema: this.schemaTypes
5599
5739
  })), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this);
@@ -5609,19 +5749,14 @@ class PortableTextEditor extends Component {
5609
5749
  return this.editable.getValue();
5610
5750
  };
5611
5751
  render() {
5612
- const {
5613
- value,
5614
- children,
5615
- patches$,
5616
- incomingPatches$
5617
- } = 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;
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$;
5618
5753
  return /* @__PURE__ */ jsxs(Fragment, { children: [
5619
- _patches$ ? /* @__PURE__ */ jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editorActor, patches$: _patches$ }) : null,
5754
+ legacyPatches ? /* @__PURE__ */ jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editorActor, patches$: legacyPatches }) : null,
5620
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: [
5621
5756
  /* @__PURE__ */ jsx(Synchronizer, { editorActor: this.editorActor, getValue: this.getValue, onChange: (change) => {
5622
- this.props.onChange(change), this.change$.next(change);
5623
- }, value }),
5624
- children
5757
+ this.props.editor || this.props.onChange(change), this.change$.next(change);
5758
+ }, value: this.props.value }),
5759
+ this.props.children
5625
5760
  ] }) }) }) }) })
5626
5761
  ] });
5627
5762
  }
@@ -6079,11 +6214,334 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6079
6214
  ) : null;
6080
6215
  });
6081
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
+ }
6082
6537
  export {
6083
6538
  PortableTextEditable,
6084
6539
  PortableTextEditor,
6540
+ createMarkdownBehaviors,
6541
+ defineBehavior,
6085
6542
  editorMachine,
6086
6543
  defaultKeyGenerator as keyGenerator,
6544
+ useEditor,
6087
6545
  usePortableTextEditor,
6088
6546
  usePortableTextEditorSelection
6089
6547
  };