@portabletext/editor 1.39.1 → 1.40.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/_chunks-cjs/behavior.core.cjs +12 -4
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +122 -102
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/{parse-blocks.cjs → util.selection-point-to-block-offset.cjs} +74 -4
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.split-text-block.cjs +68 -0
- package/lib/_chunks-cjs/util.split-text-block.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js +12 -4
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +116 -96
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/{parse-blocks.js → util.selection-point-to-block-offset.js} +76 -5
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +2 -2
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/_chunks-es/util.split-text-block.js +70 -0
- package/lib/_chunks-es/util.split-text-block.js.map +1 -0
- package/lib/behaviors/index.d.cts +383 -111
- package/lib/behaviors/index.d.ts +383 -111
- package/lib/index.cjs +197 -194
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +345 -90
- package/lib/index.d.ts +345 -90
- package/lib/index.js +204 -201
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +11 -11
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +335 -93
- package/lib/plugins/index.d.ts +335 -93
- package/lib/plugins/index.js +2 -2
- package/lib/selectors/index.d.cts +333 -81
- package/lib/selectors/index.d.ts +333 -81
- package/lib/utils/index.cjs +15 -87
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +386 -84
- package/lib/utils/index.d.ts +386 -84
- package/lib/utils/index.js +13 -86
- package/lib/utils/index.js.map +1 -1
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action.decorator.add.ts +13 -2
- package/src/behaviors/behavior.core.block-objects.ts +32 -2
- package/src/behaviors/behavior.default.ts +38 -14
- package/src/behaviors/behavior.types.ts +5 -4
- package/src/editor/Editable.tsx +122 -68
- package/src/editor/PortableTextEditor.tsx +8 -8
- package/src/editor/__tests__/self-solving.test.tsx +1 -1
- package/src/editor/components/Element.tsx +1 -3
- package/src/editor/create-editor.ts +13 -5
- package/src/editor/editor-machine.ts +6 -2
- package/src/editor/editor-provider.tsx +11 -7
- package/src/editor/editor-selector.ts +4 -3
- package/src/editor/editor-snapshot.ts +2 -2
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -2
- package/src/internal-utils/block-keys.ts +9 -0
- package/src/internal-utils/collapse-selection.ts +36 -0
- package/src/internal-utils/compound-client-rect.ts +28 -0
- package/src/internal-utils/drag-selection.test.ts +507 -0
- package/src/internal-utils/drag-selection.ts +66 -0
- package/src/internal-utils/editor-selection.test.ts +40 -0
- package/src/internal-utils/editor-selection.ts +60 -0
- package/src/internal-utils/event-position.ts +55 -80
- package/src/internal-utils/inline-object-selection.ts +115 -0
- package/src/internal-utils/selection-block-keys.ts +20 -0
- package/src/internal-utils/selection-elements.ts +61 -0
- package/src/internal-utils/selection-focus-text.ts +38 -0
- package/src/internal-utils/selection-text.test.ts +23 -0
- package/src/internal-utils/selection-text.ts +90 -0
- package/src/internal-utils/split-string.ts +12 -0
- package/src/internal-utils/string-overlap.test.ts +14 -0
- package/src/internal-utils/string-overlap.ts +28 -0
- package/src/internal-utils/string-utils.ts +7 -0
- package/src/internal-utils/terse-pt.test.ts +60 -0
- package/src/internal-utils/terse-pt.ts +36 -0
- package/src/internal-utils/text-block-key.test.ts +30 -0
- package/src/internal-utils/text-block-key.ts +30 -0
- package/src/internal-utils/text-marks.test.ts +33 -0
- package/src/internal-utils/text-marks.ts +26 -0
- package/src/internal-utils/text-selection.test.ts +175 -0
- package/src/internal-utils/text-selection.ts +122 -0
- package/src/internal-utils/value-annotations.ts +31 -0
- package/src/internal-utils/values.ts +16 -5
- package/src/utils/index.ts +5 -0
- package/src/utils/util.block-offset-to-block-selection-point.ts +28 -0
- package/src/utils/util.block-offset-to-selection-point.ts +33 -0
- package/src/utils/util.block-offsets-to-selection.ts +3 -3
- package/src/utils/util.is-equal-selections.ts +20 -0
- package/src/utils/util.is-selection-collapsed.ts +15 -0
- package/src/utils/util.reverse-selection.ts +9 -5
- package/src/utils/util.selection-point-to-block-offset.ts +31 -0
- package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
- package/lib/_chunks-es/parse-blocks.js.map +0 -1
- package/src/editor/components/use-draggable.ts +0 -123
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$e = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"),
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$e = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), omit = require("lodash/omit.js"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
@@ -218,12 +218,7 @@ function toSlateValue(value, {
|
|
|
218
218
|
_type,
|
|
219
219
|
_key,
|
|
220
220
|
...rest
|
|
221
|
-
} = block
|
|
222
|
-
_key: VOID_CHILD_KEY,
|
|
223
|
-
_type: "span",
|
|
224
|
-
text: "",
|
|
225
|
-
marks: []
|
|
226
|
-
}];
|
|
221
|
+
} = block;
|
|
227
222
|
if (block && block._type === schemaTypes.block.name) {
|
|
228
223
|
const textBlock = block;
|
|
229
224
|
let hasInlines = !1;
|
|
@@ -236,7 +231,12 @@ function toSlateValue(value, {
|
|
|
236
231
|
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
237
232
|
_type: cType,
|
|
238
233
|
_key: cKey,
|
|
239
|
-
children:
|
|
234
|
+
children: [{
|
|
235
|
+
_key: VOID_CHILD_KEY,
|
|
236
|
+
_type: "span",
|
|
237
|
+
text: "",
|
|
238
|
+
marks: []
|
|
239
|
+
}],
|
|
240
240
|
value: cRest,
|
|
241
241
|
__inline: !0
|
|
242
242
|
}, keyMap)) : child;
|
|
@@ -251,7 +251,12 @@ function toSlateValue(value, {
|
|
|
251
251
|
return keepObjectEquality({
|
|
252
252
|
_type,
|
|
253
253
|
_key,
|
|
254
|
-
children:
|
|
254
|
+
children: [{
|
|
255
|
+
_key: VOID_CHILD_KEY,
|
|
256
|
+
_type: "span",
|
|
257
|
+
text: "",
|
|
258
|
+
marks: []
|
|
259
|
+
}],
|
|
255
260
|
value: rest
|
|
256
261
|
}, keyMap);
|
|
257
262
|
}) : [];
|
|
@@ -307,65 +312,7 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
307
312
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
308
313
|
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
309
314
|
}
|
|
310
|
-
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), EditorActorContext = React.createContext({})
|
|
311
|
-
function getActiveDecorators({
|
|
312
|
-
schema: schema2,
|
|
313
|
-
slateEditorInstance
|
|
314
|
-
}) {
|
|
315
|
-
const decorators = schema2.decorators.map((decorator) => decorator.value);
|
|
316
|
-
return ({
|
|
317
|
-
...slate.Editor.marks(slateEditorInstance) ?? {}
|
|
318
|
-
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
319
|
-
}
|
|
320
|
-
function getValue({
|
|
321
|
-
editorActorSnapshot,
|
|
322
|
-
slateEditorInstance
|
|
323
|
-
}) {
|
|
324
|
-
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
325
|
-
}
|
|
326
|
-
function defaultCompare(a, b) {
|
|
327
|
-
return a === b;
|
|
328
|
-
}
|
|
329
|
-
function useEditorSelector(editor, selector, t0) {
|
|
330
|
-
const $ = reactCompilerRuntime.c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
331
|
-
let t1;
|
|
332
|
-
return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
333
|
-
const snapshot = getEditorSnapshot({
|
|
334
|
-
editorActorSnapshot,
|
|
335
|
-
slateEditorInstance: editor._internal.slateEditor.instance
|
|
336
|
-
});
|
|
337
|
-
return selector(snapshot);
|
|
338
|
-
}, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], react.useSelector(editor._internal.editorActor, t1, compare);
|
|
339
|
-
}
|
|
340
|
-
function getEditorSnapshot({
|
|
341
|
-
editorActorSnapshot,
|
|
342
|
-
slateEditorInstance
|
|
343
|
-
}) {
|
|
344
|
-
return {
|
|
345
|
-
context: {
|
|
346
|
-
converters: [...editorActorSnapshot.context.converters],
|
|
347
|
-
activeDecorators: getActiveDecorators({
|
|
348
|
-
schema: editorActorSnapshot.context.schema,
|
|
349
|
-
slateEditorInstance
|
|
350
|
-
}),
|
|
351
|
-
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
352
|
-
readOnly: editorActorSnapshot.matches({
|
|
353
|
-
"edit mode": "read only"
|
|
354
|
-
}),
|
|
355
|
-
schema: editorActorSnapshot.context.schema,
|
|
356
|
-
selection: editorActorSnapshot.context.selection,
|
|
357
|
-
value: getValue({
|
|
358
|
-
editorActorSnapshot,
|
|
359
|
-
slateEditorInstance
|
|
360
|
-
})
|
|
361
|
-
},
|
|
362
|
-
beta: {
|
|
363
|
-
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
364
|
-
internalDrag: editorActorSnapshot.context.internalDrag
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
const PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
|
|
315
|
+
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), EditorActorContext = React.createContext({}), PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
|
|
369
316
|
const editor = React.useContext(PortableTextEditorContext);
|
|
370
317
|
if (!editor)
|
|
371
318
|
throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
|
|
@@ -2490,7 +2437,7 @@ const converterJson = {
|
|
|
2490
2437
|
reason: "Data is not an array"
|
|
2491
2438
|
};
|
|
2492
2439
|
const parsedBlocks = blocks.flatMap((block) => {
|
|
2493
|
-
const parsedBlock =
|
|
2440
|
+
const parsedBlock = util_selectionPointToBlockOffset.parseBlock({
|
|
2494
2441
|
context: snapshot.context,
|
|
2495
2442
|
block,
|
|
2496
2443
|
options: {
|
|
@@ -3070,10 +3017,10 @@ const decoratorAddActionImplementation = ({
|
|
|
3070
3017
|
} : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
|
|
3071
3018
|
if (!selection)
|
|
3072
3019
|
return;
|
|
3073
|
-
const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ?
|
|
3020
|
+
const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
|
|
3074
3021
|
value,
|
|
3075
3022
|
selectionPoint: editorSelection.anchor
|
|
3076
|
-
}) : void 0, focusOffset = editorSelection ?
|
|
3023
|
+
}) : void 0, focusOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
|
|
3077
3024
|
value,
|
|
3078
3025
|
selectionPoint: editorSelection.focus
|
|
3079
3026
|
}) : void 0;
|
|
@@ -3086,7 +3033,7 @@ const decoratorAddActionImplementation = ({
|
|
|
3086
3033
|
split: !0,
|
|
3087
3034
|
hanging: !0
|
|
3088
3035
|
});
|
|
3089
|
-
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection =
|
|
3036
|
+
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
3090
3037
|
value: newValue,
|
|
3091
3038
|
offsets: {
|
|
3092
3039
|
anchor: anchorOffset,
|
|
@@ -3125,6 +3072,11 @@ const decoratorAddActionImplementation = ({
|
|
|
3125
3072
|
});
|
|
3126
3073
|
}
|
|
3127
3074
|
} else {
|
|
3075
|
+
if (!Array.from(slate.Editor.nodes(editor, {
|
|
3076
|
+
at: selection,
|
|
3077
|
+
match: (node) => editor.isTextSpan(node)
|
|
3078
|
+
}))?.at(0))
|
|
3079
|
+
return;
|
|
3128
3080
|
const [block, blockPath] = slate.Editor.node(editor, selection, {
|
|
3129
3081
|
depth: 1
|
|
3130
3082
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
@@ -3625,8 +3577,7 @@ const toggleDecoratorActionImplementation = ({
|
|
|
3625
3577
|
}) : decoratorAddActionImplementation({
|
|
3626
3578
|
context,
|
|
3627
3579
|
action: {
|
|
3628
|
-
|
|
3629
|
-
decorator: action.decorator
|
|
3580
|
+
...action
|
|
3630
3581
|
}
|
|
3631
3582
|
});
|
|
3632
3583
|
}, debug$8 = debugWithName("API:editable");
|
|
@@ -4151,7 +4102,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4151
4102
|
const {
|
|
4152
4103
|
_type,
|
|
4153
4104
|
...filteredProps
|
|
4154
|
-
} = action.props, updatedBlock =
|
|
4105
|
+
} = action.props, updatedBlock = util_selectionPointToBlockOffset.parseBlock({
|
|
4155
4106
|
context,
|
|
4156
4107
|
block: {
|
|
4157
4108
|
...parsedBlock,
|
|
@@ -4195,8 +4146,8 @@ const addAnnotationActionImplementation = ({
|
|
|
4195
4146
|
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
|
|
4196
4147
|
if (!parsedBlock)
|
|
4197
4148
|
throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
|
|
4198
|
-
if (
|
|
4199
|
-
const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock =
|
|
4149
|
+
if (util_selectionPointToBlockOffset.isTextBlock(context.schema, parsedBlock)) {
|
|
4150
|
+
const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_selectionPointToBlockOffset.parseBlock({
|
|
4200
4151
|
context,
|
|
4201
4152
|
block: omit__default.default(parsedBlock, propsToRemove),
|
|
4202
4153
|
options: {
|
|
@@ -4213,7 +4164,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4213
4164
|
});
|
|
4214
4165
|
return;
|
|
4215
4166
|
}
|
|
4216
|
-
const updatedBlockObject =
|
|
4167
|
+
const updatedBlockObject = util_selectionPointToBlockOffset.parseBlock({
|
|
4217
4168
|
context,
|
|
4218
4169
|
block: omit__default.default(parsedBlock, action.props.filter((prop) => prop !== "_type")),
|
|
4219
4170
|
options: {
|
|
@@ -4283,7 +4234,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4283
4234
|
context,
|
|
4284
4235
|
action
|
|
4285
4236
|
}) => {
|
|
4286
|
-
const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), selection =
|
|
4237
|
+
const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), selection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
4287
4238
|
value,
|
|
4288
4239
|
offsets: {
|
|
4289
4240
|
anchor: action.anchor,
|
|
@@ -4348,7 +4299,7 @@ const insertBlockActionImplementation = ({
|
|
|
4348
4299
|
context,
|
|
4349
4300
|
action
|
|
4350
4301
|
}) => {
|
|
4351
|
-
const parsedBlock =
|
|
4302
|
+
const parsedBlock = util_selectionPointToBlockOffset.parseBlock({
|
|
4352
4303
|
block: action.block,
|
|
4353
4304
|
context,
|
|
4354
4305
|
options: {
|
|
@@ -4547,7 +4498,7 @@ const selectActionImplementation = ({
|
|
|
4547
4498
|
context,
|
|
4548
4499
|
action
|
|
4549
4500
|
}) => {
|
|
4550
|
-
const parsedBlocks =
|
|
4501
|
+
const parsedBlocks = util_selectionPointToBlockOffset.parseBlocks({
|
|
4551
4502
|
context,
|
|
4552
4503
|
blocks: action.blocks,
|
|
4553
4504
|
options: {
|
|
@@ -6151,12 +6102,24 @@ const keyIs = {
|
|
|
6151
6102
|
guard: ({
|
|
6152
6103
|
snapshot,
|
|
6153
6104
|
event
|
|
6154
|
-
}) =>
|
|
6105
|
+
}) => {
|
|
6106
|
+
const manualSelection = event.offsets ? util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
6107
|
+
value: snapshot.context.value,
|
|
6108
|
+
offsets: event.offsets
|
|
6109
|
+
}) : null;
|
|
6110
|
+
return manualSelection ? !selector_isOverlappingSelection.isActiveDecorator(event.decorator)({
|
|
6111
|
+
...snapshot,
|
|
6112
|
+
context: {
|
|
6113
|
+
...snapshot.context,
|
|
6114
|
+
selection: manualSelection
|
|
6115
|
+
}
|
|
6116
|
+
}) : !selector_isOverlappingSelection.isActiveDecorator(event.decorator)(snapshot);
|
|
6117
|
+
},
|
|
6155
6118
|
actions: [({
|
|
6156
6119
|
event
|
|
6157
6120
|
}) => [behavior_core.raise({
|
|
6158
|
-
|
|
6159
|
-
|
|
6121
|
+
...event,
|
|
6122
|
+
type: "decorator.add"
|
|
6160
6123
|
})]]
|
|
6161
6124
|
}), toggleListItemOff = behavior_core.defineBehavior({
|
|
6162
6125
|
on: "list item.toggle",
|
|
@@ -6388,17 +6351,17 @@ const keyIs = {
|
|
|
6388
6351
|
draggedBlocks,
|
|
6389
6352
|
dragOrigin,
|
|
6390
6353
|
originEvent
|
|
6391
|
-
}) => [behavior_core.raise({
|
|
6392
|
-
type: "insert.blocks",
|
|
6393
|
-
blocks: event.data,
|
|
6394
|
-
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
6395
|
-
}), ...draggingEntireBlocks ? draggedBlocks.map((block) => behavior_core.raise({
|
|
6354
|
+
}) => [...draggingEntireBlocks ? draggedBlocks.map((block) => behavior_core.raise({
|
|
6396
6355
|
type: "delete.block",
|
|
6397
6356
|
blockPath: block.path
|
|
6398
6357
|
})) : [behavior_core.raise({
|
|
6399
6358
|
type: "delete",
|
|
6400
6359
|
selection: dragOrigin.selection
|
|
6401
|
-
})]
|
|
6360
|
+
})], behavior_core.raise({
|
|
6361
|
+
type: "insert.blocks",
|
|
6362
|
+
blocks: event.data,
|
|
6363
|
+
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
6364
|
+
})]]
|
|
6402
6365
|
}), behavior_core.defineBehavior({
|
|
6403
6366
|
on: "deserialization.success",
|
|
6404
6367
|
actions: [({
|
|
@@ -6443,6 +6406,15 @@ const keyIs = {
|
|
|
6443
6406
|
originEvent: event
|
|
6444
6407
|
})]]
|
|
6445
6408
|
}), toggleAnnotationOff, toggleAnnotationOn, toggleDecoratorOff, toggleDecoratorOn, toggleListItemOff, toggleListItemOn, toggleStyleOff, toggleStyleOn, raiseDeserializationSuccessOrFailure, raiseSerializationSuccessOrFailure, raiseInsertSoftBreak];
|
|
6409
|
+
function getActiveDecorators({
|
|
6410
|
+
schema: schema2,
|
|
6411
|
+
slateEditorInstance
|
|
6412
|
+
}) {
|
|
6413
|
+
const decorators = schema2.decorators.map((decorator) => decorator.value);
|
|
6414
|
+
return ({
|
|
6415
|
+
...slate.Editor.marks(slateEditorInstance) ?? {}
|
|
6416
|
+
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
6417
|
+
}
|
|
6446
6418
|
function createEditorSnapshot({
|
|
6447
6419
|
converters,
|
|
6448
6420
|
editor,
|
|
@@ -7038,13 +7010,61 @@ const editorMachine = xstate.setup({
|
|
|
7038
7010
|
}
|
|
7039
7011
|
}
|
|
7040
7012
|
});
|
|
7041
|
-
function
|
|
7013
|
+
function getValue({
|
|
7014
|
+
editorActorSnapshot,
|
|
7015
|
+
slateEditorInstance
|
|
7016
|
+
}) {
|
|
7017
|
+
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
7018
|
+
}
|
|
7019
|
+
function defaultCompare(a, b) {
|
|
7020
|
+
return a === b;
|
|
7021
|
+
}
|
|
7022
|
+
function useEditorSelector(editor, selector, t0) {
|
|
7023
|
+
const $ = reactCompilerRuntime.c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
7024
|
+
let t1;
|
|
7025
|
+
return $[0] !== editor || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
7026
|
+
const snapshot = getEditorSnapshot({
|
|
7027
|
+
editorActorSnapshot,
|
|
7028
|
+
slateEditorInstance: editor._internal.slateEditor.instance
|
|
7029
|
+
});
|
|
7030
|
+
return selector(snapshot);
|
|
7031
|
+
}, $[0] = editor, $[1] = selector, $[2] = t1) : t1 = $[2], react.useSelector(editor._internal.editorActor, t1, compare);
|
|
7032
|
+
}
|
|
7033
|
+
function getEditorSnapshot({
|
|
7034
|
+
editorActorSnapshot,
|
|
7035
|
+
slateEditorInstance
|
|
7036
|
+
}) {
|
|
7037
|
+
return {
|
|
7038
|
+
context: {
|
|
7039
|
+
converters: [...editorActorSnapshot.context.converters],
|
|
7040
|
+
activeDecorators: getActiveDecorators({
|
|
7041
|
+
schema: editorActorSnapshot.context.schema,
|
|
7042
|
+
slateEditorInstance
|
|
7043
|
+
}),
|
|
7044
|
+
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
7045
|
+
readOnly: editorActorSnapshot.matches({
|
|
7046
|
+
"edit mode": "read only"
|
|
7047
|
+
}),
|
|
7048
|
+
schema: editorActorSnapshot.context.schema,
|
|
7049
|
+
selection: editorActorSnapshot.context.selection,
|
|
7050
|
+
value: getValue({
|
|
7051
|
+
editorActorSnapshot,
|
|
7052
|
+
slateEditorInstance
|
|
7053
|
+
})
|
|
7054
|
+
},
|
|
7055
|
+
beta: {
|
|
7056
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
7057
|
+
internalDrag: editorActorSnapshot.context.internalDrag
|
|
7058
|
+
}
|
|
7059
|
+
};
|
|
7060
|
+
}
|
|
7061
|
+
function createInternalEditor(config) {
|
|
7042
7062
|
const editorActor = xstate.createActor(editorMachine, {
|
|
7043
7063
|
input: editorConfigToMachineInput(config)
|
|
7044
7064
|
});
|
|
7045
|
-
return editorActor.start(),
|
|
7065
|
+
return editorActor.start(), createInternalEditorFromActor(editorActor);
|
|
7046
7066
|
}
|
|
7047
|
-
function
|
|
7067
|
+
function useCreateInternalEditor(config) {
|
|
7048
7068
|
const $ = reactCompilerRuntime.c(6);
|
|
7049
7069
|
let t0;
|
|
7050
7070
|
$[0] !== config ? (t0 = editorConfigToMachineInput(config), $[0] = config, $[1] = t0) : t0 = $[1];
|
|
@@ -7054,7 +7074,7 @@ function useCreateEditor(config) {
|
|
|
7054
7074
|
}, $[2] = t0, $[3] = t1) : t1 = $[3];
|
|
7055
7075
|
const editorActor = react.useActorRef(editorMachine, t1);
|
|
7056
7076
|
let t2, t3;
|
|
7057
|
-
return $[4] !== editorActor ? (t3 =
|
|
7077
|
+
return $[4] !== editorActor ? (t3 = createInternalEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
7058
7078
|
}
|
|
7059
7079
|
function editorConfigToMachineInput(config) {
|
|
7060
7080
|
return {
|
|
@@ -7067,7 +7087,7 @@ function editorConfigToMachineInput(config) {
|
|
|
7067
7087
|
value: config.initialValue
|
|
7068
7088
|
};
|
|
7069
7089
|
}
|
|
7070
|
-
function
|
|
7090
|
+
function createInternalEditorFromActor(editorActor) {
|
|
7071
7091
|
const slateEditor = createSlateEditor({
|
|
7072
7092
|
editorActor
|
|
7073
7093
|
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
@@ -7154,7 +7174,7 @@ class PortableTextEditor extends React.Component {
|
|
|
7154
7174
|
* The editor API (currently implemented with Slate).
|
|
7155
7175
|
*/
|
|
7156
7176
|
constructor(props) {
|
|
7157
|
-
super(props), props.editor ? this.editor = props.editor : this.editor =
|
|
7177
|
+
super(props), props.editor ? this.editor = props.editor : this.editor = createInternalEditor({
|
|
7158
7178
|
keyGenerator: props.keyGenerator ?? defaultKeyGenerator,
|
|
7159
7179
|
schema: props.schemaType,
|
|
7160
7180
|
initialValue: props.value,
|
|
@@ -7646,11 +7666,11 @@ function RouteEventsToChanges(props) {
|
|
|
7646
7666
|
}
|
|
7647
7667
|
const EditorContext = React__default.default.createContext(void 0);
|
|
7648
7668
|
function EditorProvider(props) {
|
|
7649
|
-
const $ = reactCompilerRuntime.c(28),
|
|
7669
|
+
const $ = reactCompilerRuntime.c(28), internalEditor = useCreateInternalEditor(props.initialConfig), editorActor = internalEditor._internal.editorActor, slateEditor = internalEditor._internal.slateEditor;
|
|
7650
7670
|
let t0, t1;
|
|
7651
|
-
$[0] !==
|
|
7652
|
-
editor
|
|
7653
|
-
}), $[0] =
|
|
7671
|
+
$[0] !== internalEditor ? (t1 = new PortableTextEditor({
|
|
7672
|
+
editor: internalEditor
|
|
7673
|
+
}), $[0] = internalEditor, $[1] = t1) : t1 = $[1], t0 = t1;
|
|
7654
7674
|
const portableTextEditor = t0;
|
|
7655
7675
|
let t2;
|
|
7656
7676
|
$[2] !== portableTextEditor.change$ ? (t2 = (change) => {
|
|
@@ -7669,11 +7689,11 @@ function EditorProvider(props) {
|
|
|
7669
7689
|
let t8;
|
|
7670
7690
|
$[20] !== editorActor || $[21] !== t7 ? (t8 = /* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: editorActor, children: t7 }), $[20] = editorActor, $[21] = t7, $[22] = t8) : t8 = $[22];
|
|
7671
7691
|
let t9;
|
|
7672
|
-
return $[23] !==
|
|
7692
|
+
return $[23] !== internalEditor || $[24] !== t3 || $[25] !== t4 || $[26] !== t8 ? (t9 = /* @__PURE__ */ jsxRuntime.jsxs(EditorContext.Provider, { value: internalEditor, children: [
|
|
7673
7693
|
t3,
|
|
7674
7694
|
t4,
|
|
7675
7695
|
t8
|
|
7676
|
-
] }), $[23] =
|
|
7696
|
+
] }), $[23] = internalEditor, $[24] = t3, $[25] = t4, $[26] = t8, $[27] = t9) : t9 = $[27], t9;
|
|
7677
7697
|
}
|
|
7678
7698
|
function useEditor() {
|
|
7679
7699
|
const editor = React__default.default.useContext(EditorContext);
|