@portabletext/editor 1.39.1 → 1.40.1
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 +131 -109
- 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 +125 -103
- 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 +198 -195
- 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 +205 -202
- 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/converters/converter.portable-text.ts +9 -0
- package/src/converters/converter.text-plain.test.ts +5 -5
- package/src/converters/converter.text-plain.ts +12 -19
- 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 +2 -9
- 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/create-with-event-listeners.ts +2 -5
- 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
|
@@ -5,7 +5,7 @@ import { ReactEditor, withReact, Slate } from "slate-react";
|
|
|
5
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
6
6
|
import debug$e from "debug";
|
|
7
7
|
import isEqual from "lodash/isEqual.js";
|
|
8
|
-
import { Editor, Element, Range, Point, Text, Operation, Transforms, Path, insertText, Node, createEditor
|
|
8
|
+
import { Editor, Element, Range, Point, Text, Operation, Transforms, Path, insertText, Node, createEditor } from "slate";
|
|
9
9
|
import { setup, stateIn, fromCallback, assign, enqueueActions, emit, assertEvent, and, not, createActor } from "xstate";
|
|
10
10
|
import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
|
|
11
11
|
import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
|
|
@@ -13,8 +13,8 @@ import flatten from "lodash/flatten.js";
|
|
|
13
13
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
14
14
|
import uniq from "lodash/uniq.js";
|
|
15
15
|
import getRandomValues from "get-random-values-esm";
|
|
16
|
-
import { parseBlock, blockOffsetsToSelection, isTextBlock, parseBlocks } from "./
|
|
17
|
-
import { sliceBlocks, blockOffsetToSpanSelectionPoint,
|
|
16
|
+
import { parseBlock, selectionPointToBlockOffset, blockOffsetsToSelection, isTextBlock, parseBlocks } from "./util.selection-point-to-block-offset.js";
|
|
17
|
+
import { sliceBlocks, blockOffsetToSpanSelectionPoint, isKeyedSegment as isKeyedSegment$1 } from "./util.slice-blocks.js";
|
|
18
18
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
19
19
|
import { toHTML } from "@portabletext/to-html";
|
|
20
20
|
import { Schema } from "@sanity/schema";
|
|
@@ -243,12 +243,7 @@ function toSlateValue(value, {
|
|
|
243
243
|
_type,
|
|
244
244
|
_key,
|
|
245
245
|
...rest
|
|
246
|
-
} = block
|
|
247
|
-
_key: VOID_CHILD_KEY,
|
|
248
|
-
_type: "span",
|
|
249
|
-
text: "",
|
|
250
|
-
marks: []
|
|
251
|
-
}];
|
|
246
|
+
} = block;
|
|
252
247
|
if (block && block._type === schemaTypes.block.name) {
|
|
253
248
|
const textBlock = block;
|
|
254
249
|
let hasInlines = !1;
|
|
@@ -261,7 +256,12 @@ function toSlateValue(value, {
|
|
|
261
256
|
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
262
257
|
_type: cType,
|
|
263
258
|
_key: cKey,
|
|
264
|
-
children:
|
|
259
|
+
children: [{
|
|
260
|
+
_key: VOID_CHILD_KEY,
|
|
261
|
+
_type: "span",
|
|
262
|
+
text: "",
|
|
263
|
+
marks: []
|
|
264
|
+
}],
|
|
265
265
|
value: cRest,
|
|
266
266
|
__inline: !0
|
|
267
267
|
}, keyMap)) : child;
|
|
@@ -276,7 +276,12 @@ function toSlateValue(value, {
|
|
|
276
276
|
return keepObjectEquality({
|
|
277
277
|
_type,
|
|
278
278
|
_key,
|
|
279
|
-
children:
|
|
279
|
+
children: [{
|
|
280
|
+
_key: VOID_CHILD_KEY,
|
|
281
|
+
_type: "span",
|
|
282
|
+
text: "",
|
|
283
|
+
marks: []
|
|
284
|
+
}],
|
|
280
285
|
value: rest
|
|
281
286
|
}, keyMap);
|
|
282
287
|
}) : [];
|
|
@@ -332,65 +337,7 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
332
337
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
333
338
|
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && 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 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
334
339
|
}
|
|
335
|
-
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 = createContext({})
|
|
336
|
-
function getActiveDecorators({
|
|
337
|
-
schema,
|
|
338
|
-
slateEditorInstance
|
|
339
|
-
}) {
|
|
340
|
-
const decorators = schema.decorators.map((decorator) => decorator.value);
|
|
341
|
-
return ({
|
|
342
|
-
...Editor.marks(slateEditorInstance) ?? {}
|
|
343
|
-
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
344
|
-
}
|
|
345
|
-
function getValue({
|
|
346
|
-
editorActorSnapshot,
|
|
347
|
-
slateEditorInstance
|
|
348
|
-
}) {
|
|
349
|
-
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
350
|
-
}
|
|
351
|
-
function defaultCompare(a, b) {
|
|
352
|
-
return a === b;
|
|
353
|
-
}
|
|
354
|
-
function useEditorSelector(editor, selector, t0) {
|
|
355
|
-
const $ = c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
356
|
-
let t1;
|
|
357
|
-
return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
358
|
-
const snapshot = getEditorSnapshot({
|
|
359
|
-
editorActorSnapshot,
|
|
360
|
-
slateEditorInstance: editor._internal.slateEditor.instance
|
|
361
|
-
});
|
|
362
|
-
return selector(snapshot);
|
|
363
|
-
}, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], useSelector(editor._internal.editorActor, t1, compare);
|
|
364
|
-
}
|
|
365
|
-
function getEditorSnapshot({
|
|
366
|
-
editorActorSnapshot,
|
|
367
|
-
slateEditorInstance
|
|
368
|
-
}) {
|
|
369
|
-
return {
|
|
370
|
-
context: {
|
|
371
|
-
converters: [...editorActorSnapshot.context.converters],
|
|
372
|
-
activeDecorators: getActiveDecorators({
|
|
373
|
-
schema: editorActorSnapshot.context.schema,
|
|
374
|
-
slateEditorInstance
|
|
375
|
-
}),
|
|
376
|
-
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
377
|
-
readOnly: editorActorSnapshot.matches({
|
|
378
|
-
"edit mode": "read only"
|
|
379
|
-
}),
|
|
380
|
-
schema: editorActorSnapshot.context.schema,
|
|
381
|
-
selection: editorActorSnapshot.context.selection,
|
|
382
|
-
value: getValue({
|
|
383
|
-
editorActorSnapshot,
|
|
384
|
-
slateEditorInstance
|
|
385
|
-
})
|
|
386
|
-
},
|
|
387
|
-
beta: {
|
|
388
|
-
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
389
|
-
internalDrag: editorActorSnapshot.context.internalDrag
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
const PortableTextEditorContext = createContext(null), usePortableTextEditor = () => {
|
|
340
|
+
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 = createContext({}), PortableTextEditorContext = createContext(null), usePortableTextEditor = () => {
|
|
394
341
|
const editor = useContext(PortableTextEditorContext);
|
|
395
342
|
if (!editor)
|
|
396
343
|
throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
|
|
@@ -2496,7 +2443,12 @@ const converterJson = {
|
|
|
2496
2443
|
blocks: snapshot.context.value,
|
|
2497
2444
|
selection
|
|
2498
2445
|
});
|
|
2499
|
-
return {
|
|
2446
|
+
return blocks.length === 0 ? {
|
|
2447
|
+
type: "serialization.failure",
|
|
2448
|
+
mimeType: "application/x-portable-text",
|
|
2449
|
+
reason: "No blocks serialized",
|
|
2450
|
+
originEvent: event.originEvent
|
|
2451
|
+
} : {
|
|
2500
2452
|
type: "serialization.success",
|
|
2501
2453
|
data: JSON.stringify(blocks),
|
|
2502
2454
|
mimeType: "application/x-portable-text",
|
|
@@ -2605,7 +2557,7 @@ const converterJson = {
|
|
|
2605
2557
|
data: sliceBlocks({
|
|
2606
2558
|
blocks: snapshot.context.value,
|
|
2607
2559
|
selection
|
|
2608
|
-
}).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text :
|
|
2560
|
+
}).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : "").join("") : "").filter((block) => block !== "").join(`
|
|
2609
2561
|
|
|
2610
2562
|
`),
|
|
2611
2563
|
mimeType: "text/plain",
|
|
@@ -3095,10 +3047,10 @@ const decoratorAddActionImplementation = ({
|
|
|
3095
3047
|
} : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
|
|
3096
3048
|
if (!selection)
|
|
3097
3049
|
return;
|
|
3098
|
-
const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ?
|
|
3050
|
+
const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ? selectionPointToBlockOffset({
|
|
3099
3051
|
value,
|
|
3100
3052
|
selectionPoint: editorSelection.anchor
|
|
3101
|
-
}) : void 0, focusOffset = editorSelection ?
|
|
3053
|
+
}) : void 0, focusOffset = editorSelection ? selectionPointToBlockOffset({
|
|
3102
3054
|
value,
|
|
3103
3055
|
selectionPoint: editorSelection.focus
|
|
3104
3056
|
}) : void 0;
|
|
@@ -3150,6 +3102,11 @@ const decoratorAddActionImplementation = ({
|
|
|
3150
3102
|
});
|
|
3151
3103
|
}
|
|
3152
3104
|
} else {
|
|
3105
|
+
if (!Array.from(Editor.nodes(editor, {
|
|
3106
|
+
at: selection,
|
|
3107
|
+
match: (node) => editor.isTextSpan(node)
|
|
3108
|
+
}))?.at(0))
|
|
3109
|
+
return;
|
|
3153
3110
|
const [block, blockPath] = Editor.node(editor, selection, {
|
|
3154
3111
|
depth: 1
|
|
3155
3112
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
@@ -3650,8 +3607,7 @@ const toggleDecoratorActionImplementation = ({
|
|
|
3650
3607
|
}) : decoratorAddActionImplementation({
|
|
3651
3608
|
context,
|
|
3652
3609
|
action: {
|
|
3653
|
-
|
|
3654
|
-
decorator: action.decorator
|
|
3610
|
+
...action
|
|
3655
3611
|
}
|
|
3656
3612
|
});
|
|
3657
3613
|
}, debug$8 = debugWithName("API:editable");
|
|
@@ -5340,12 +5296,9 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5340
5296
|
editorActor.send({
|
|
5341
5297
|
type: "behavior event",
|
|
5342
5298
|
behaviorEvent: {
|
|
5343
|
-
type: "
|
|
5299
|
+
type: "input.*",
|
|
5344
5300
|
originEvent: {
|
|
5345
|
-
|
|
5346
|
-
originEvent: {
|
|
5347
|
-
dataTransfer
|
|
5348
|
-
}
|
|
5301
|
+
dataTransfer
|
|
5349
5302
|
}
|
|
5350
5303
|
},
|
|
5351
5304
|
editor
|
|
@@ -6110,7 +6063,7 @@ function createSlateEditor(config) {
|
|
|
6110
6063
|
if (existingSlateEditor)
|
|
6111
6064
|
return debug$2("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
|
|
6112
6065
|
debug$2("Creating new Slate editor instance", config.editorActor.id);
|
|
6113
|
-
const unsubscriptions = [], subscriptions = [], instance = withPlugins(withReact(createEditor
|
|
6066
|
+
const unsubscriptions = [], subscriptions = [], instance = withPlugins(withReact(createEditor()), {
|
|
6114
6067
|
editorActor: config.editorActor,
|
|
6115
6068
|
subscriptions
|
|
6116
6069
|
});
|
|
@@ -6176,12 +6129,24 @@ const keyIs = {
|
|
|
6176
6129
|
guard: ({
|
|
6177
6130
|
snapshot,
|
|
6178
6131
|
event
|
|
6179
|
-
}) =>
|
|
6132
|
+
}) => {
|
|
6133
|
+
const manualSelection = event.offsets ? blockOffsetsToSelection({
|
|
6134
|
+
value: snapshot.context.value,
|
|
6135
|
+
offsets: event.offsets
|
|
6136
|
+
}) : null;
|
|
6137
|
+
return manualSelection ? !isActiveDecorator(event.decorator)({
|
|
6138
|
+
...snapshot,
|
|
6139
|
+
context: {
|
|
6140
|
+
...snapshot.context,
|
|
6141
|
+
selection: manualSelection
|
|
6142
|
+
}
|
|
6143
|
+
}) : !isActiveDecorator(event.decorator)(snapshot);
|
|
6144
|
+
},
|
|
6180
6145
|
actions: [({
|
|
6181
6146
|
event
|
|
6182
6147
|
}) => [raise({
|
|
6183
|
-
|
|
6184
|
-
|
|
6148
|
+
...event,
|
|
6149
|
+
type: "decorator.add"
|
|
6185
6150
|
})]]
|
|
6186
6151
|
}), toggleListItemOff = defineBehavior({
|
|
6187
6152
|
on: "list item.toggle",
|
|
@@ -6413,17 +6378,17 @@ const keyIs = {
|
|
|
6413
6378
|
draggedBlocks,
|
|
6414
6379
|
dragOrigin,
|
|
6415
6380
|
originEvent
|
|
6416
|
-
}) => [raise({
|
|
6417
|
-
type: "insert.blocks",
|
|
6418
|
-
blocks: event.data,
|
|
6419
|
-
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
6420
|
-
}), ...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
|
|
6381
|
+
}) => [...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
|
|
6421
6382
|
type: "delete.block",
|
|
6422
6383
|
blockPath: block.path
|
|
6423
6384
|
})) : [raise({
|
|
6424
6385
|
type: "delete",
|
|
6425
6386
|
selection: dragOrigin.selection
|
|
6426
|
-
})]
|
|
6387
|
+
})], raise({
|
|
6388
|
+
type: "insert.blocks",
|
|
6389
|
+
blocks: event.data,
|
|
6390
|
+
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
6391
|
+
})]]
|
|
6427
6392
|
}), defineBehavior({
|
|
6428
6393
|
on: "deserialization.success",
|
|
6429
6394
|
actions: [({
|
|
@@ -6468,6 +6433,15 @@ const keyIs = {
|
|
|
6468
6433
|
originEvent: event
|
|
6469
6434
|
})]]
|
|
6470
6435
|
}), toggleAnnotationOff, toggleAnnotationOn, toggleDecoratorOff, toggleDecoratorOn, toggleListItemOff, toggleListItemOn, toggleStyleOff, toggleStyleOn, raiseDeserializationSuccessOrFailure, raiseSerializationSuccessOrFailure, raiseInsertSoftBreak];
|
|
6436
|
+
function getActiveDecorators({
|
|
6437
|
+
schema,
|
|
6438
|
+
slateEditorInstance
|
|
6439
|
+
}) {
|
|
6440
|
+
const decorators = schema.decorators.map((decorator) => decorator.value);
|
|
6441
|
+
return ({
|
|
6442
|
+
...Editor.marks(slateEditorInstance) ?? {}
|
|
6443
|
+
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
6444
|
+
}
|
|
6471
6445
|
function createEditorSnapshot({
|
|
6472
6446
|
converters,
|
|
6473
6447
|
editor,
|
|
@@ -7063,13 +7037,61 @@ const editorMachine = setup({
|
|
|
7063
7037
|
}
|
|
7064
7038
|
}
|
|
7065
7039
|
});
|
|
7066
|
-
function
|
|
7040
|
+
function getValue({
|
|
7041
|
+
editorActorSnapshot,
|
|
7042
|
+
slateEditorInstance
|
|
7043
|
+
}) {
|
|
7044
|
+
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
7045
|
+
}
|
|
7046
|
+
function defaultCompare(a, b) {
|
|
7047
|
+
return a === b;
|
|
7048
|
+
}
|
|
7049
|
+
function useEditorSelector(editor, selector, t0) {
|
|
7050
|
+
const $ = c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
7051
|
+
let t1;
|
|
7052
|
+
return $[0] !== editor || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
7053
|
+
const snapshot = getEditorSnapshot({
|
|
7054
|
+
editorActorSnapshot,
|
|
7055
|
+
slateEditorInstance: editor._internal.slateEditor.instance
|
|
7056
|
+
});
|
|
7057
|
+
return selector(snapshot);
|
|
7058
|
+
}, $[0] = editor, $[1] = selector, $[2] = t1) : t1 = $[2], useSelector(editor._internal.editorActor, t1, compare);
|
|
7059
|
+
}
|
|
7060
|
+
function getEditorSnapshot({
|
|
7061
|
+
editorActorSnapshot,
|
|
7062
|
+
slateEditorInstance
|
|
7063
|
+
}) {
|
|
7064
|
+
return {
|
|
7065
|
+
context: {
|
|
7066
|
+
converters: [...editorActorSnapshot.context.converters],
|
|
7067
|
+
activeDecorators: getActiveDecorators({
|
|
7068
|
+
schema: editorActorSnapshot.context.schema,
|
|
7069
|
+
slateEditorInstance
|
|
7070
|
+
}),
|
|
7071
|
+
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
7072
|
+
readOnly: editorActorSnapshot.matches({
|
|
7073
|
+
"edit mode": "read only"
|
|
7074
|
+
}),
|
|
7075
|
+
schema: editorActorSnapshot.context.schema,
|
|
7076
|
+
selection: editorActorSnapshot.context.selection,
|
|
7077
|
+
value: getValue({
|
|
7078
|
+
editorActorSnapshot,
|
|
7079
|
+
slateEditorInstance
|
|
7080
|
+
})
|
|
7081
|
+
},
|
|
7082
|
+
beta: {
|
|
7083
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
7084
|
+
internalDrag: editorActorSnapshot.context.internalDrag
|
|
7085
|
+
}
|
|
7086
|
+
};
|
|
7087
|
+
}
|
|
7088
|
+
function createInternalEditor(config) {
|
|
7067
7089
|
const editorActor = createActor(editorMachine, {
|
|
7068
7090
|
input: editorConfigToMachineInput(config)
|
|
7069
7091
|
});
|
|
7070
|
-
return editorActor.start(),
|
|
7092
|
+
return editorActor.start(), createInternalEditorFromActor(editorActor);
|
|
7071
7093
|
}
|
|
7072
|
-
function
|
|
7094
|
+
function useCreateInternalEditor(config) {
|
|
7073
7095
|
const $ = c(6);
|
|
7074
7096
|
let t0;
|
|
7075
7097
|
$[0] !== config ? (t0 = editorConfigToMachineInput(config), $[0] = config, $[1] = t0) : t0 = $[1];
|
|
@@ -7079,7 +7101,7 @@ function useCreateEditor(config) {
|
|
|
7079
7101
|
}, $[2] = t0, $[3] = t1) : t1 = $[3];
|
|
7080
7102
|
const editorActor = useActorRef(editorMachine, t1);
|
|
7081
7103
|
let t2, t3;
|
|
7082
|
-
return $[4] !== editorActor ? (t3 =
|
|
7104
|
+
return $[4] !== editorActor ? (t3 = createInternalEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
7083
7105
|
}
|
|
7084
7106
|
function editorConfigToMachineInput(config) {
|
|
7085
7107
|
return {
|
|
@@ -7092,7 +7114,7 @@ function editorConfigToMachineInput(config) {
|
|
|
7092
7114
|
value: config.initialValue
|
|
7093
7115
|
};
|
|
7094
7116
|
}
|
|
7095
|
-
function
|
|
7117
|
+
function createInternalEditorFromActor(editorActor) {
|
|
7096
7118
|
const slateEditor = createSlateEditor({
|
|
7097
7119
|
editorActor
|
|
7098
7120
|
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
@@ -7179,7 +7201,7 @@ class PortableTextEditor extends Component {
|
|
|
7179
7201
|
* The editor API (currently implemented with Slate).
|
|
7180
7202
|
*/
|
|
7181
7203
|
constructor(props) {
|
|
7182
|
-
super(props), props.editor ? this.editor = props.editor : this.editor =
|
|
7204
|
+
super(props), props.editor ? this.editor = props.editor : this.editor = createInternalEditor({
|
|
7183
7205
|
keyGenerator: props.keyGenerator ?? defaultKeyGenerator,
|
|
7184
7206
|
schema: props.schemaType,
|
|
7185
7207
|
initialValue: props.value,
|
|
@@ -7671,11 +7693,11 @@ function RouteEventsToChanges(props) {
|
|
|
7671
7693
|
}
|
|
7672
7694
|
const EditorContext = React.createContext(void 0);
|
|
7673
7695
|
function EditorProvider(props) {
|
|
7674
|
-
const $ = c(28),
|
|
7696
|
+
const $ = c(28), internalEditor = useCreateInternalEditor(props.initialConfig), editorActor = internalEditor._internal.editorActor, slateEditor = internalEditor._internal.slateEditor;
|
|
7675
7697
|
let t0, t1;
|
|
7676
|
-
$[0] !==
|
|
7677
|
-
editor
|
|
7678
|
-
}), $[0] =
|
|
7698
|
+
$[0] !== internalEditor ? (t1 = new PortableTextEditor({
|
|
7699
|
+
editor: internalEditor
|
|
7700
|
+
}), $[0] = internalEditor, $[1] = t1) : t1 = $[1], t0 = t1;
|
|
7679
7701
|
const portableTextEditor = t0;
|
|
7680
7702
|
let t2;
|
|
7681
7703
|
$[2] !== portableTextEditor.change$ ? (t2 = (change) => {
|
|
@@ -7694,11 +7716,11 @@ function EditorProvider(props) {
|
|
|
7694
7716
|
let t8;
|
|
7695
7717
|
$[20] !== editorActor || $[21] !== t7 ? (t8 = /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: editorActor, children: t7 }), $[20] = editorActor, $[21] = t7, $[22] = t8) : t8 = $[22];
|
|
7696
7718
|
let t9;
|
|
7697
|
-
return $[23] !==
|
|
7719
|
+
return $[23] !== internalEditor || $[24] !== t3 || $[25] !== t4 || $[26] !== t8 ? (t9 = /* @__PURE__ */ jsxs(EditorContext.Provider, { value: internalEditor, children: [
|
|
7698
7720
|
t3,
|
|
7699
7721
|
t4,
|
|
7700
7722
|
t8
|
|
7701
|
-
] }), $[23] =
|
|
7723
|
+
] }), $[23] = internalEditor, $[24] = t3, $[25] = t4, $[26] = t8, $[27] = t9) : t9 = $[27], t9;
|
|
7702
7724
|
}
|
|
7703
7725
|
function useEditor() {
|
|
7704
7726
|
const editor = React.useContext(EditorContext);
|