@portabletext/editor 1.46.0 → 1.47.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 +7 -7
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +411 -327
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +4 -4
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +7 -7
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +412 -328
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +4 -4
- package/lib/_chunks-es/parse-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +590 -28
- package/lib/behaviors/index.d.ts +590 -28
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +4 -4
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +71 -3
- package/lib/index.d.ts +71 -3
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +78 -23
- package/lib/plugins/index.d.ts +78 -23
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +79 -27
- package/lib/selectors/index.d.ts +79 -27
- package/lib/utils/index.d.cts +84 -29
- package/lib/utils/index.d.ts +84 -29
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action.insert.block.ts +1 -1
- package/src/behavior-actions/behavior.action.move.backward.ts +12 -0
- package/src/behavior-actions/behavior.action.move.forward.ts +11 -0
- package/src/behavior-actions/behavior.action.split.block.ts +1 -1
- package/src/behavior-actions/behavior.actions.ts +18 -0
- package/src/behavior-actions/behavior.guards.ts +1 -1
- package/src/behaviors/behavior.core.decorators.ts +4 -4
- package/src/behaviors/behavior.core.insert-break.ts +4 -4
- package/src/behaviors/behavior.decorator-pair.ts +1 -1
- package/src/behaviors/behavior.links.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +1 -1
- package/src/behaviors/behavior.perform-event.ts +1 -1
- package/src/behaviors/behavior.types.event.ts +10 -0
- package/src/converters/converter.portable-text.deserialize.test.ts +2 -3
- package/src/converters/converter.text-html.deserialize.test.ts +62 -5
- package/src/converters/converter.text-html.serialize.test.ts +9 -5
- package/src/converters/converter.text-html.ts +66 -64
- package/src/converters/converter.text-plain.test.ts +9 -4
- package/src/converters/converter.text-plain.ts +91 -87
- package/src/converters/converters.core.ts +13 -8
- package/src/editor/Editable.tsx +10 -5
- package/src/editor/PortableTextEditor.tsx +5 -5
- package/src/editor/__tests__/PortableTextEditorTester.tsx +4 -3
- package/src/editor/__tests__/insert-block.test.tsx +10 -10
- package/src/editor/__tests__/self-solving.test.tsx +2 -2
- package/src/editor/components/Synchronizer.tsx +1 -1
- package/src/editor/create-editor.ts +51 -18
- package/src/editor/editor-machine.ts +1 -1
- package/src/editor/{define-schema.ts → editor-schema.ts} +114 -5
- package/src/editor/editor-snapshot.ts +1 -1
- package/src/editor/get-active-decorators.ts +2 -2
- package/src/editor/{create-editor-schema.ts → legacy-schema.ts} +3 -3
- package/src/editor/mutation-machine.ts +1 -1
- package/src/editor/plugins/createWithObjectKeys.ts +6 -9
- package/src/editor/plugins/createWithPatches.ts +12 -11
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +2 -6
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +15 -12
- package/src/editor/plugins/createWithSchemaTypes.ts +24 -16
- package/src/editor/plugins/createWithUndoRedo.ts +3 -4
- package/src/editor/plugins/createWithUtils.ts +12 -10
- package/src/editor/plugins/with-plugins.ts +5 -15
- package/src/editor/range-decorations-machine.ts +1 -1
- package/src/editor/sync-machine.ts +1 -1
- package/src/index.ts +2 -2
- package/src/internal-utils/__tests__/operationToPatches.test.ts +12 -10
- package/src/internal-utils/__tests__/patchToOperations.test.ts +3 -2
- package/src/internal-utils/__tests__/values.test.ts +3 -2
- package/src/internal-utils/applyPatch.ts +7 -9
- package/src/internal-utils/create-test-snapshot.ts +1 -1
- package/src/internal-utils/drag-selection.test.ts +1 -1
- package/src/internal-utils/operationToPatches.ts +4 -6
- package/src/internal-utils/parse-blocks.test.ts +1 -1
- package/src/internal-utils/parse-blocks.ts +8 -7
- package/src/internal-utils/slate-children-to-blocks.ts +1 -1
- package/src/internal-utils/slate-utils.ts +1 -1
- package/src/internal-utils/validateValue.ts +4 -6
- package/src/internal-utils/values.ts +5 -5
- package/src/plugins/plugin.decorator-shortcut.ts +1 -1
- package/src/plugins/plugin.markdown.test.tsx +1 -1
- package/src/plugins/plugin.markdown.tsx +1 -1
- package/src/selectors/selector.get-selection-text.test.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
|
-
import React, { useEffect, createContext, useContext, useState, startTransition, Component } from "react";
|
|
3
|
+
import React, { useEffect, useMemo, createContext, useContext, useState, startTransition, Component } from "react";
|
|
4
4
|
import { ReactEditor, withReact, Slate } from "slate-react";
|
|
5
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
6
6
|
import debug$g from "debug";
|
|
@@ -25,9 +25,9 @@ import omit from "lodash/omit.js";
|
|
|
25
25
|
import { selectionPointToBlockOffset, blockOffsetsToSelection } from "./util.selection-point-to-block-offset.js";
|
|
26
26
|
import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, isSelectingEntireBlocks, getActiveAnnotations } from "./selector.is-selecting-entire-blocks.js";
|
|
27
27
|
import { DOMEditor } from "slate-dom";
|
|
28
|
-
import startCase from "lodash.startcase";
|
|
29
28
|
import { defineBehavior, raise, coreBehaviors } from "./behavior.core.js";
|
|
30
29
|
import { getFocusTextBlock, getPreviousBlock, getNextBlock, getFocusSpan, isSelectionCollapsed, isOverlappingSelection, getSelectedBlocks, isSelectionExpanded } from "./selector.is-overlapping-selection.js";
|
|
30
|
+
import startCase from "lodash.startcase";
|
|
31
31
|
import { Subject } from "rxjs";
|
|
32
32
|
import { useEffectEvent } from "use-effect-event";
|
|
33
33
|
const rootName = "sanity-pte:";
|
|
@@ -72,7 +72,7 @@ function toSlateValue(value, {
|
|
|
72
72
|
__inline: !0
|
|
73
73
|
}, keyMap)) : child;
|
|
74
74
|
});
|
|
75
|
-
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].
|
|
75
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].name), keepObjectEquality({
|
|
76
76
|
_type,
|
|
77
77
|
_key,
|
|
78
78
|
...rest,
|
|
@@ -141,7 +141,7 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
143
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
144
|
-
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].
|
|
144
|
+
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].name && !("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 === "";
|
|
145
145
|
}
|
|
146
146
|
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(), mutationMachine = setup({
|
|
147
147
|
types: {
|
|
@@ -502,7 +502,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
502
502
|
}
|
|
503
503
|
}, !0;
|
|
504
504
|
}
|
|
505
|
-
const orphanedMarks = allUsedMarks.filter((mark) => !types.decorators.map((dec) => dec.
|
|
505
|
+
const orphanedMarks = allUsedMarks.filter((mark) => !types.decorators.map((dec) => dec.name).includes(mark)).filter((mark) => textBlock.markDefs === void 0 || !textBlock.markDefs.find((def) => def._key === mark));
|
|
506
506
|
if (orphanedMarks.length > 0) {
|
|
507
507
|
const spanChildren = textBlock.children.filter((cld) => cld._type === types.span.name && Array.isArray(cld.marks) && cld.marks.some((mark) => orphanedMarks.includes(mark)));
|
|
508
508
|
if (spanChildren) {
|
|
@@ -1355,11 +1355,10 @@ const debug$f = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ n
|
|
|
1355
1355
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
1356
1356
|
function createWithUndoRedo(options) {
|
|
1357
1357
|
const {
|
|
1358
|
-
editorActor
|
|
1359
|
-
blockSchemaType
|
|
1358
|
+
editorActor
|
|
1360
1359
|
} = options;
|
|
1361
1360
|
return (editor) => {
|
|
1362
|
-
let previousSnapshot = fromSlateValue(editor.children,
|
|
1361
|
+
let previousSnapshot = fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name);
|
|
1363
1362
|
const remotePatches = getRemotePatches(editor);
|
|
1364
1363
|
let previousBehaviorActionSetId = getCurrentBehaviorActionSetId(editor);
|
|
1365
1364
|
options.subscriptions.push(() => {
|
|
@@ -2085,7 +2084,7 @@ function Synchronizer(props) {
|
|
|
2085
2084
|
}, $[6] = slateEditor, $[7] = t0.context.keyGenerator, $[8] = t2, $[9] = t3.context.schema, $[10] = t4) : t4 = $[10];
|
|
2086
2085
|
const syncActorRef = useActorRef(syncMachine, t4);
|
|
2087
2086
|
let t5;
|
|
2088
|
-
$[11] !== editorActor ? (t5 = editorActor.getSnapshot(), $[11] = editorActor, $[12] = t5) : t5 = $[12];
|
|
2087
|
+
$[11] !== props.editorActor ? (t5 = props.editorActor.getSnapshot(), $[11] = props.editorActor, $[12] = t5) : t5 = $[12];
|
|
2089
2088
|
let t6;
|
|
2090
2089
|
$[13] !== slateEditor || $[14] !== t5.context.schema ? (t6 = {
|
|
2091
2090
|
input: {
|
|
@@ -2288,121 +2287,128 @@ const converterJson = {
|
|
|
2288
2287
|
mimeType: "application/x-portable-text"
|
|
2289
2288
|
};
|
|
2290
2289
|
}
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2290
|
+
};
|
|
2291
|
+
function createConverterTextHtml(legacySchema) {
|
|
2292
|
+
return {
|
|
2293
|
+
mimeType: "text/html",
|
|
2294
|
+
serialize: ({
|
|
2295
|
+
snapshot,
|
|
2296
|
+
event
|
|
2297
|
+
}) => {
|
|
2298
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2299
|
+
if (!selection)
|
|
2300
|
+
return {
|
|
2301
|
+
type: "serialization.failure",
|
|
2302
|
+
mimeType: "text/html",
|
|
2303
|
+
originEvent: event.originEvent,
|
|
2304
|
+
reason: "No selection"
|
|
2305
|
+
};
|
|
2306
|
+
const blocks = sliceBlocks({
|
|
2307
|
+
blocks: snapshot.context.value,
|
|
2308
|
+
selection
|
|
2309
|
+
}), html = toHTML(blocks, {
|
|
2310
|
+
onMissingComponent: !1,
|
|
2311
|
+
components: {
|
|
2312
|
+
unknownType: ({
|
|
2313
|
+
children
|
|
2314
|
+
}) => children !== void 0 ? `${children}` : ""
|
|
2315
|
+
}
|
|
2316
|
+
});
|
|
2317
|
+
return html === "" ? {
|
|
2300
2318
|
type: "serialization.failure",
|
|
2301
2319
|
mimeType: "text/html",
|
|
2302
2320
|
originEvent: event.originEvent,
|
|
2303
|
-
reason: "
|
|
2321
|
+
reason: "Serialized HTML is empty"
|
|
2322
|
+
} : {
|
|
2323
|
+
type: "serialization.success",
|
|
2324
|
+
data: html,
|
|
2325
|
+
mimeType: "text/html",
|
|
2326
|
+
originEvent: event.originEvent
|
|
2304
2327
|
};
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
type: "serialization.success",
|
|
2323
|
-
data: html,
|
|
2324
|
-
mimeType: "text/html",
|
|
2325
|
-
originEvent: event.originEvent
|
|
2326
|
-
};
|
|
2327
|
-
},
|
|
2328
|
-
deserialize: ({
|
|
2329
|
-
snapshot,
|
|
2330
|
-
event
|
|
2331
|
-
}) => {
|
|
2332
|
-
const parsedBlocks = htmlToBlocks(event.data, snapshot.context.schema.portableText, {
|
|
2333
|
-
keyGenerator: snapshot.context.keyGenerator,
|
|
2334
|
-
unstable_whitespaceOnPasteMode: snapshot.context.schema.block.options.unstable_whitespaceOnPasteMode
|
|
2335
|
-
}).flatMap((block) => {
|
|
2336
|
-
const parsedBlock = parseBlock({
|
|
2337
|
-
context: snapshot.context,
|
|
2338
|
-
block,
|
|
2339
|
-
options: {
|
|
2340
|
-
refreshKeys: !1
|
|
2341
|
-
}
|
|
2328
|
+
},
|
|
2329
|
+
deserialize: ({
|
|
2330
|
+
snapshot,
|
|
2331
|
+
event
|
|
2332
|
+
}) => {
|
|
2333
|
+
const parsedBlocks = htmlToBlocks(event.data, legacySchema.portableText, {
|
|
2334
|
+
keyGenerator: snapshot.context.keyGenerator,
|
|
2335
|
+
unstable_whitespaceOnPasteMode: legacySchema.block.options.unstable_whitespaceOnPasteMode
|
|
2336
|
+
}).flatMap((block) => {
|
|
2337
|
+
const parsedBlock = parseBlock({
|
|
2338
|
+
context: snapshot.context,
|
|
2339
|
+
block,
|
|
2340
|
+
options: {
|
|
2341
|
+
refreshKeys: !1
|
|
2342
|
+
}
|
|
2343
|
+
});
|
|
2344
|
+
return parsedBlock ? [parsedBlock] : [];
|
|
2342
2345
|
});
|
|
2343
|
-
return
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2346
|
+
return parsedBlocks.length === 0 ? {
|
|
2347
|
+
type: "deserialization.failure",
|
|
2348
|
+
mimeType: "text/html",
|
|
2349
|
+
reason: "No blocks deserialized"
|
|
2350
|
+
} : {
|
|
2351
|
+
type: "deserialization.success",
|
|
2352
|
+
data: parsedBlocks,
|
|
2353
|
+
mimeType: "text/html"
|
|
2354
|
+
};
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
function createConverterTextPlain(legacySchema) {
|
|
2359
|
+
return {
|
|
2360
|
+
mimeType: "text/plain",
|
|
2361
|
+
serialize: ({
|
|
2362
|
+
snapshot,
|
|
2363
|
+
event
|
|
2364
|
+
}) => {
|
|
2365
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2366
|
+
return selection ? {
|
|
2367
|
+
type: "serialization.success",
|
|
2368
|
+
data: sliceBlocks({
|
|
2369
|
+
blocks: snapshot.context.value,
|
|
2370
|
+
selection
|
|
2371
|
+
}).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
|
|
2368
2372
|
|
|
2369
2373
|
`),
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2374
|
+
mimeType: "text/plain",
|
|
2375
|
+
originEvent: event.originEvent
|
|
2376
|
+
} : {
|
|
2377
|
+
type: "serialization.failure",
|
|
2378
|
+
mimeType: "text/plain",
|
|
2379
|
+
originEvent: event.originEvent,
|
|
2380
|
+
reason: "No selection"
|
|
2381
|
+
};
|
|
2382
|
+
},
|
|
2383
|
+
deserialize: ({
|
|
2384
|
+
snapshot,
|
|
2385
|
+
event
|
|
2386
|
+
}) => {
|
|
2387
|
+
const textToHtml = `<html><body>${escapeHtml(event.data).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`, parsedBlocks = htmlToBlocks(textToHtml, legacySchema.portableText, {
|
|
2388
|
+
keyGenerator: snapshot.context.keyGenerator
|
|
2389
|
+
}).flatMap((block) => {
|
|
2390
|
+
const parsedBlock = parseBlock({
|
|
2391
|
+
context: snapshot.context,
|
|
2392
|
+
block,
|
|
2393
|
+
options: {
|
|
2394
|
+
refreshKeys: !1
|
|
2395
|
+
}
|
|
2396
|
+
});
|
|
2397
|
+
return parsedBlock ? [parsedBlock] : [];
|
|
2392
2398
|
});
|
|
2393
|
-
return
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2399
|
+
return parsedBlocks.length === 0 ? {
|
|
2400
|
+
type: "deserialization.failure",
|
|
2401
|
+
mimeType: "text/plain",
|
|
2402
|
+
reason: "No blocks deserialized"
|
|
2403
|
+
} : {
|
|
2404
|
+
type: "deserialization.success",
|
|
2405
|
+
data: parsedBlocks,
|
|
2406
|
+
mimeType: "text/plain"
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
};
|
|
2410
|
+
}
|
|
2411
|
+
const entityMap = {
|
|
2406
2412
|
"&": "&",
|
|
2407
2413
|
"<": "<",
|
|
2408
2414
|
">": ">",
|
|
@@ -2415,68 +2421,18 @@ const converterJson = {
|
|
|
2415
2421
|
function escapeHtml(str) {
|
|
2416
2422
|
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
2417
2423
|
}
|
|
2418
|
-
|
|
2424
|
+
function createCoreConverters(legacySchema) {
|
|
2425
|
+
return [converterJson, converterPortableText, createConverterTextHtml(legacySchema), createConverterTextPlain(legacySchema)];
|
|
2426
|
+
}
|
|
2419
2427
|
function compileType(rawType) {
|
|
2420
2428
|
return Schema.compile({
|
|
2421
2429
|
name: "blockTypeSchema",
|
|
2422
2430
|
types: [rawType]
|
|
2423
2431
|
}).get(rawType.name);
|
|
2424
2432
|
}
|
|
2425
|
-
function createEditorSchema(portableTextType) {
|
|
2426
|
-
if (!portableTextType)
|
|
2427
|
-
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
2428
|
-
const blockType = portableTextType.of?.find(findBlockType);
|
|
2429
|
-
if (!blockType)
|
|
2430
|
-
throw new Error("Block type is not defined in this schema (required)");
|
|
2431
|
-
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
2432
|
-
if (!childrenField)
|
|
2433
|
-
throw new Error("Children field for block type found in schema (required)");
|
|
2434
|
-
const ofType = childrenField.type.of;
|
|
2435
|
-
if (!ofType)
|
|
2436
|
-
throw new Error("Valid types for block children not found in schema (required)");
|
|
2437
|
-
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
2438
|
-
if (!spanType)
|
|
2439
|
-
throw new Error("Span type not found in schema (required)");
|
|
2440
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
2441
|
-
return {
|
|
2442
|
-
styles: resolveEnabledStyles(blockType),
|
|
2443
|
-
decorators: resolveEnabledDecorators(spanType),
|
|
2444
|
-
lists: resolveEnabledListItems(blockType),
|
|
2445
|
-
block: blockType,
|
|
2446
|
-
span: spanType,
|
|
2447
|
-
portableText: portableTextType,
|
|
2448
|
-
inlineObjects: inlineObjectTypes,
|
|
2449
|
-
blockObjects: blockObjectTypes,
|
|
2450
|
-
annotations: spanType.annotations
|
|
2451
|
-
};
|
|
2452
|
-
}
|
|
2453
|
-
function resolveEnabledStyles(blockType) {
|
|
2454
|
-
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
2455
|
-
if (!styleField)
|
|
2456
|
-
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
2457
|
-
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
2458
|
-
if (!textStyles || textStyles.length === 0)
|
|
2459
|
-
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
2460
|
-
return textStyles;
|
|
2461
|
-
}
|
|
2462
|
-
function resolveEnabledDecorators(spanType) {
|
|
2463
|
-
return spanType.decorators;
|
|
2464
|
-
}
|
|
2465
|
-
function resolveEnabledListItems(blockType) {
|
|
2466
|
-
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
2467
|
-
if (!listField)
|
|
2468
|
-
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
2469
|
-
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
2470
|
-
if (!listItems)
|
|
2471
|
-
throw new Error("The list field need at least to be an empty array");
|
|
2472
|
-
return listItems;
|
|
2473
|
-
}
|
|
2474
|
-
function findBlockType(type) {
|
|
2475
|
-
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
2476
|
-
}
|
|
2477
2433
|
const debug$c = debugWithName("operationToPatches");
|
|
2478
|
-
function createOperationToPatches(
|
|
2479
|
-
const textBlockName =
|
|
2434
|
+
function createOperationToPatches(editorActor) {
|
|
2435
|
+
const textBlockName = editorActor.getSnapshot().context.schema.block.name;
|
|
2480
2436
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
2481
2437
|
debug$c.enabled && debug$c("Operation", JSON.stringify(operation, null, 2));
|
|
2482
2438
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
@@ -2745,12 +2701,12 @@ function getNextSpan({
|
|
|
2745
2701
|
return nextSpan;
|
|
2746
2702
|
}
|
|
2747
2703
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
2748
|
-
function createWithPortableTextMarkModel(editorActor
|
|
2704
|
+
function createWithPortableTextMarkModel(editorActor) {
|
|
2749
2705
|
return function(editor) {
|
|
2750
2706
|
const {
|
|
2751
2707
|
apply: apply2,
|
|
2752
2708
|
normalizeNode
|
|
2753
|
-
} = editor, decorators =
|
|
2709
|
+
} = editor, decorators = editorActor.getSnapshot().context.schema.decorators.map((t) => t.name);
|
|
2754
2710
|
return editor.normalizeNode = (nodeEntry) => {
|
|
2755
2711
|
const [node, path] = nodeEntry;
|
|
2756
2712
|
if (editor.isTextBlock(node)) {
|
|
@@ -2795,7 +2751,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
2795
2751
|
return;
|
|
2796
2752
|
}
|
|
2797
2753
|
if (editor.isTextSpan(node)) {
|
|
2798
|
-
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 =
|
|
2754
|
+
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
2799
2755
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
2800
2756
|
debug$b("Removing annotations from empty span node"), editorActor.send({
|
|
2801
2757
|
type: "normalizing"
|
|
@@ -2810,7 +2766,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
2810
2766
|
}
|
|
2811
2767
|
}
|
|
2812
2768
|
if (editor.isTextBlock(node)) {
|
|
2813
|
-
const decorators2 =
|
|
2769
|
+
const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name);
|
|
2814
2770
|
for (const [child, childPath] of Node.children(editor, path))
|
|
2815
2771
|
if (editor.isTextSpan(child)) {
|
|
2816
2772
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
@@ -2831,7 +2787,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
2831
2787
|
if (editor.isTextSpan(node)) {
|
|
2832
2788
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath);
|
|
2833
2789
|
if (editor.isTextBlock(block)) {
|
|
2834
|
-
const decorators2 =
|
|
2790
|
+
const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
2835
2791
|
if (orphanedAnnotations.length > 0) {
|
|
2836
2792
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
2837
2793
|
type: "normalizing"
|
|
@@ -3082,7 +3038,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3082
3038
|
}
|
|
3083
3039
|
}
|
|
3084
3040
|
}
|
|
3085
|
-
if (op.type === "merge_node" && op.path.length === 1 && "markDefs" in op.properties && op.properties._type ===
|
|
3041
|
+
if (op.type === "merge_node" && op.path.length === 1 && "markDefs" in op.properties && op.properties._type === editorActor.getSnapshot().context.schema.block.name && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] - 1 >= 0) {
|
|
3086
3042
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
3087
3043
|
if (editor.isTextBlock(targetBlock)) {
|
|
3088
3044
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
@@ -4010,7 +3966,15 @@ function insertBlock({
|
|
|
4010
3966
|
}
|
|
4011
3967
|
}
|
|
4012
3968
|
}
|
|
4013
|
-
const
|
|
3969
|
+
const moveBackwardActionImplementation = ({
|
|
3970
|
+
action
|
|
3971
|
+
}) => {
|
|
3972
|
+
Transforms.move(action.editor, {
|
|
3973
|
+
unit: "character",
|
|
3974
|
+
distance: action.distance,
|
|
3975
|
+
reverse: !0
|
|
3976
|
+
});
|
|
3977
|
+
}, moveBlockActionImplementation = ({
|
|
4014
3978
|
action
|
|
4015
3979
|
}) => {
|
|
4016
3980
|
const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
|
|
@@ -4019,6 +3983,13 @@ const moveBlockActionImplementation = ({
|
|
|
4019
3983
|
to,
|
|
4020
3984
|
mode: "highest"
|
|
4021
3985
|
});
|
|
3986
|
+
}, moveForwardActionImplementation = ({
|
|
3987
|
+
action
|
|
3988
|
+
}) => {
|
|
3989
|
+
Transforms.move(action.editor, {
|
|
3990
|
+
unit: "character",
|
|
3991
|
+
distance: action.distance
|
|
3992
|
+
});
|
|
4022
3993
|
}, noopActionImplementation = () => {
|
|
4023
3994
|
}, selectActionImplementation = ({
|
|
4024
3995
|
action
|
|
@@ -4064,7 +4035,7 @@ const moveBlockActionImplementation = ({
|
|
|
4064
4035
|
continue;
|
|
4065
4036
|
const marks = child.marks ?? [];
|
|
4066
4037
|
for (const mark of marks)
|
|
4067
|
-
schema.decorators.some((decorator) => decorator.
|
|
4038
|
+
schema.decorators.some((decorator) => decorator.name === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
4068
4039
|
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
4069
4040
|
isEqual(marks, newMarks) || Transforms.setNodes(editor, {
|
|
4070
4041
|
marks: newMarks
|
|
@@ -4108,7 +4079,9 @@ const moveBlockActionImplementation = ({
|
|
|
4108
4079
|
"insert.span": insertSpanActionImplementation,
|
|
4109
4080
|
"insert.text": insertTextActionImplementation,
|
|
4110
4081
|
effect: effectActionImplementation,
|
|
4082
|
+
"move.backward": moveBackwardActionImplementation,
|
|
4111
4083
|
"move.block": moveBlockActionImplementation,
|
|
4084
|
+
"move.forward": moveForwardActionImplementation,
|
|
4112
4085
|
noop: noopActionImplementation,
|
|
4113
4086
|
select: selectActionImplementation,
|
|
4114
4087
|
"split.block": splitBlockActionImplementation
|
|
@@ -4251,6 +4224,13 @@ function performAction({
|
|
|
4251
4224
|
});
|
|
4252
4225
|
break;
|
|
4253
4226
|
}
|
|
4227
|
+
case "move.backward": {
|
|
4228
|
+
behaviorActionImplementations["move.backward"]({
|
|
4229
|
+
context,
|
|
4230
|
+
action
|
|
4231
|
+
});
|
|
4232
|
+
break;
|
|
4233
|
+
}
|
|
4254
4234
|
case "move.block": {
|
|
4255
4235
|
behaviorActionImplementations["move.block"]({
|
|
4256
4236
|
context,
|
|
@@ -4258,6 +4238,13 @@ function performAction({
|
|
|
4258
4238
|
});
|
|
4259
4239
|
break;
|
|
4260
4240
|
}
|
|
4241
|
+
case "move.forward": {
|
|
4242
|
+
behaviorActionImplementations["move.forward"]({
|
|
4243
|
+
context,
|
|
4244
|
+
action
|
|
4245
|
+
});
|
|
4246
|
+
break;
|
|
4247
|
+
}
|
|
4261
4248
|
case "noop":
|
|
4262
4249
|
break;
|
|
4263
4250
|
case "split.block": {
|
|
@@ -4469,7 +4456,7 @@ function createWithMaxBlocks(editorActor) {
|
|
|
4469
4456
|
}, editor;
|
|
4470
4457
|
};
|
|
4471
4458
|
}
|
|
4472
|
-
function createWithObjectKeys(editorActor
|
|
4459
|
+
function createWithObjectKeys(editorActor) {
|
|
4473
4460
|
return function(editor) {
|
|
4474
4461
|
const {
|
|
4475
4462
|
apply: apply2,
|
|
@@ -4509,7 +4496,7 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
4509
4496
|
apply2(operation);
|
|
4510
4497
|
}, editor.normalizeNode = (entry) => {
|
|
4511
4498
|
const [node, path] = entry;
|
|
4512
|
-
if (Element.isElement(node) && node._type ===
|
|
4499
|
+
if (Element.isElement(node) && node._type === editorActor.getSnapshot().context.schema.block.name) {
|
|
4513
4500
|
if (!node._key) {
|
|
4514
4501
|
editorActor.send({
|
|
4515
4502
|
type: "normalizing"
|
|
@@ -4541,7 +4528,7 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
4541
4528
|
};
|
|
4542
4529
|
}
|
|
4543
4530
|
const debug$9 = debugWithName("applyPatches"), debugVerbose = debug$9.enabled && !0;
|
|
4544
|
-
function createApplyPatch(
|
|
4531
|
+
function createApplyPatch(schema) {
|
|
4545
4532
|
return (editor, patch) => {
|
|
4546
4533
|
let changed = !1;
|
|
4547
4534
|
debugVerbose && (debug$9(`
|
|
@@ -4550,7 +4537,7 @@ NEW PATCH =============================================================`), debug
|
|
|
4550
4537
|
try {
|
|
4551
4538
|
switch (patch.type) {
|
|
4552
4539
|
case "insert":
|
|
4553
|
-
changed = insertPatch(editor, patch,
|
|
4540
|
+
changed = insertPatch(editor, patch, schema);
|
|
4554
4541
|
break;
|
|
4555
4542
|
case "unset":
|
|
4556
4543
|
changed = unsetPatch(editor, patch);
|
|
@@ -4601,7 +4588,7 @@ function diffMatchPatch(editor, patch) {
|
|
|
4601
4588
|
}) : op === DIFF_EQUAL && (offset += text.length);
|
|
4602
4589
|
return debugState(editor, "after"), !0;
|
|
4603
4590
|
}
|
|
4604
|
-
function insertPatch(editor, patch,
|
|
4591
|
+
function insertPatch(editor, patch, schema) {
|
|
4605
4592
|
const {
|
|
4606
4593
|
block: targetBlock,
|
|
4607
4594
|
child: targetChild,
|
|
@@ -4617,7 +4604,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
4617
4604
|
items: items2,
|
|
4618
4605
|
position: position2
|
|
4619
4606
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
4620
|
-
schemaTypes
|
|
4607
|
+
schemaTypes: schema
|
|
4621
4608
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
4622
4609
|
return debug$9(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
|
|
4623
4610
|
at: [normalizedIdx2]
|
|
@@ -4633,7 +4620,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
4633
4620
|
...targetBlock,
|
|
4634
4621
|
children: items
|
|
4635
4622
|
}], {
|
|
4636
|
-
schemaTypes
|
|
4623
|
+
schemaTypes: schema
|
|
4637
4624
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
4638
4625
|
return debug$9(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
4639
4626
|
at: childInsertPath
|
|
@@ -4811,11 +4798,10 @@ const debug$8 = debugWithName("plugin:withPatches");
|
|
|
4811
4798
|
function createWithPatches({
|
|
4812
4799
|
editorActor,
|
|
4813
4800
|
patchFunctions,
|
|
4814
|
-
schemaTypes,
|
|
4815
4801
|
subscriptions
|
|
4816
4802
|
}) {
|
|
4817
4803
|
let previousChildren;
|
|
4818
|
-
const applyPatch = createApplyPatch(
|
|
4804
|
+
const applyPatch = createApplyPatch(editorActor.getSnapshot().context.schema);
|
|
4819
4805
|
return function(editor) {
|
|
4820
4806
|
IS_PROCESSING_REMOTE_CHANGES.set(editor, !1), PATCHING.set(editor, !0), previousChildren = [...editor.children];
|
|
4821
4807
|
const {
|
|
@@ -4854,9 +4840,9 @@ function createWithPatches({
|
|
|
4854
4840
|
}), editor.apply = (operation) => {
|
|
4855
4841
|
let patches = [];
|
|
4856
4842
|
previousChildren = editor.children;
|
|
4857
|
-
const editorWasEmpty = isEqualToEmptyEditor(previousChildren,
|
|
4843
|
+
const editorWasEmpty = isEqualToEmptyEditor(previousChildren, editorActor.getSnapshot().context.schema);
|
|
4858
4844
|
apply2(operation);
|
|
4859
|
-
const editorIsEmpty = isEqualToEmptyEditor(editor.children,
|
|
4845
|
+
const editorIsEmpty = isEqualToEmptyEditor(editor.children, editorActor.getSnapshot().context.schema);
|
|
4860
4846
|
if (!isPatching(editor))
|
|
4861
4847
|
return editor;
|
|
4862
4848
|
switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches.push(insert(previousChildren, "before", [0])), operation.type) {
|
|
@@ -4887,7 +4873,7 @@ function createWithPatches({
|
|
|
4887
4873
|
}
|
|
4888
4874
|
if (!editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches = [...patches, unset([])], editorActor.send({
|
|
4889
4875
|
type: "notify.unset",
|
|
4890
|
-
previousValue: fromSlateValue(previousChildren,
|
|
4876
|
+
previousValue: fromSlateValue(previousChildren, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
|
|
4891
4877
|
})), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0)
|
|
4892
4878
|
for (const patch of patches)
|
|
4893
4879
|
editorActor.send({
|
|
@@ -4897,7 +4883,7 @@ function createWithPatches({
|
|
|
4897
4883
|
origin: "local"
|
|
4898
4884
|
},
|
|
4899
4885
|
actionId: getCurrentActionId(editor),
|
|
4900
|
-
value: fromSlateValue(editor.children,
|
|
4886
|
+
value: fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
|
|
4901
4887
|
});
|
|
4902
4888
|
return editor;
|
|
4903
4889
|
}, editor;
|
|
@@ -4938,8 +4924,8 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4938
4924
|
};
|
|
4939
4925
|
}
|
|
4940
4926
|
const debug$6 = debugWithName("plugin:withPortableTextBlockStyle");
|
|
4941
|
-
function createWithPortableTextBlockStyle(editorActor
|
|
4942
|
-
const defaultStyle =
|
|
4927
|
+
function createWithPortableTextBlockStyle(editorActor) {
|
|
4928
|
+
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
|
|
4943
4929
|
return function(editor) {
|
|
4944
4930
|
const {
|
|
4945
4931
|
normalizeNode
|
|
@@ -5003,11 +4989,10 @@ function createWithPortableTextSelections(editorActor) {
|
|
|
5003
4989
|
}
|
|
5004
4990
|
const debug$5 = debugWithName("plugin:withSchemaTypes");
|
|
5005
4991
|
function createWithSchemaTypes({
|
|
5006
|
-
editorActor
|
|
5007
|
-
schemaTypes
|
|
4992
|
+
editorActor
|
|
5008
4993
|
}) {
|
|
5009
4994
|
return function(editor) {
|
|
5010
|
-
editor.isTextBlock = (value) => isPortableTextTextBlock(value) && value._type ===
|
|
4995
|
+
editor.isTextBlock = (value) => isPortableTextTextBlock(value) && value._type === editorActor.getSnapshot().context.schema.block.name, editor.isTextSpan = (value) => isPortableTextSpan$1(value) && value._type === editorActor.getSnapshot().context.schema.span.name, editor.isListBlock = (value) => isPortableTextListBlock(value) && value._type === editorActor.getSnapshot().context.schema.block.name, editor.isVoid = (element) => editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
5011
4996
|
const {
|
|
5012
4997
|
normalizeNode
|
|
5013
4998
|
} = editor;
|
|
@@ -5020,7 +5005,7 @@ function createWithSchemaTypes({
|
|
|
5020
5005
|
type: "normalizing"
|
|
5021
5006
|
}), Transforms.setNodes(editor, {
|
|
5022
5007
|
...span,
|
|
5023
|
-
_type:
|
|
5008
|
+
_type: editorActor.getSnapshot().context.schema.span.name,
|
|
5024
5009
|
_key: key
|
|
5025
5010
|
}, {
|
|
5026
5011
|
at: path
|
|
@@ -5048,14 +5033,13 @@ function createWithSchemaTypes({
|
|
|
5048
5033
|
};
|
|
5049
5034
|
}
|
|
5050
5035
|
function createWithUtils({
|
|
5051
|
-
editorActor
|
|
5052
|
-
schemaTypes
|
|
5036
|
+
editorActor
|
|
5053
5037
|
}) {
|
|
5054
5038
|
return function(editor) {
|
|
5055
5039
|
return editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
5056
|
-
_type:
|
|
5040
|
+
_type: editorActor.getSnapshot().context.schema.block.name,
|
|
5057
5041
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5058
|
-
style:
|
|
5042
|
+
style: editorActor.getSnapshot().context.schema.styles[0].name || "normal",
|
|
5059
5043
|
...options.listItem ? {
|
|
5060
5044
|
listItem: options.listItem
|
|
5061
5045
|
} : {},
|
|
@@ -5067,33 +5051,29 @@ function createWithUtils({
|
|
|
5067
5051
|
_type: "span",
|
|
5068
5052
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5069
5053
|
text: "",
|
|
5070
|
-
marks: options.decorators.filter((decorator) =>
|
|
5071
|
-
|
|
5072
|
-
}) =>
|
|
5054
|
+
marks: options.decorators.filter((decorator) => editorActor.getSnapshot().context.schema.decorators.find(({
|
|
5055
|
+
name
|
|
5056
|
+
}) => name === decorator))
|
|
5073
5057
|
}]
|
|
5074
5058
|
}], {
|
|
5075
|
-
schemaTypes
|
|
5059
|
+
schemaTypes: editorActor.getSnapshot().context.schema
|
|
5076
5060
|
})[0], editor;
|
|
5077
5061
|
};
|
|
5078
5062
|
}
|
|
5079
5063
|
const withPlugins = (editor, options) => {
|
|
5080
5064
|
const e = editor, {
|
|
5081
5065
|
editorActor
|
|
5082
|
-
} = options,
|
|
5083
|
-
editorActor
|
|
5084
|
-
schemaTypes
|
|
5066
|
+
} = options, operationToPatches = createOperationToPatches(editorActor), withObjectKeys = createWithObjectKeys(editorActor), withSchemaTypes = createWithSchemaTypes({
|
|
5067
|
+
editorActor
|
|
5085
5068
|
}), withPatches = createWithPatches({
|
|
5086
5069
|
editorActor,
|
|
5087
5070
|
patchFunctions: operationToPatches,
|
|
5088
|
-
schemaTypes,
|
|
5089
5071
|
subscriptions: options.subscriptions
|
|
5090
5072
|
}), withMaxBlocks = createWithMaxBlocks(editorActor), withUndoRedo = createWithUndoRedo({
|
|
5091
5073
|
editorActor,
|
|
5092
|
-
blockSchemaType: schemaTypes.block,
|
|
5093
5074
|
subscriptions: options.subscriptions
|
|
5094
|
-
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor
|
|
5095
|
-
editorActor
|
|
5096
|
-
schemaTypes
|
|
5075
|
+
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5076
|
+
editorActor
|
|
5097
5077
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
5098
5078
|
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5099
5079
|
}, debug$4 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
@@ -5117,100 +5097,6 @@ function createSlateEditor(config) {
|
|
|
5117
5097
|
};
|
|
5118
5098
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
5119
5099
|
}
|
|
5120
|
-
function defineSchema(definition) {
|
|
5121
|
-
return definition;
|
|
5122
|
-
}
|
|
5123
|
-
const temporaryImageName = `tmp-${defaultKeyGenerator()}-image`, temporaryUrlName = `tmp-${defaultKeyGenerator()}-url`, temporaryObjectNames = {
|
|
5124
|
-
image: temporaryImageName,
|
|
5125
|
-
url: temporaryUrlName
|
|
5126
|
-
}, objectNames = {
|
|
5127
|
-
[temporaryImageName]: "image",
|
|
5128
|
-
[temporaryUrlName]: "url"
|
|
5129
|
-
}, defaultObjectTitles = {
|
|
5130
|
-
image: "Image",
|
|
5131
|
-
url: "URL"
|
|
5132
|
-
};
|
|
5133
|
-
function compileSchemaDefinition(definition) {
|
|
5134
|
-
const blockObjects = definition?.blockObjects?.map((blockObject) => defineType({
|
|
5135
|
-
type: "object",
|
|
5136
|
-
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5137
|
-
// fields to objects with certain names.
|
|
5138
|
-
name: temporaryObjectNames[blockObject.name] ?? blockObject.name,
|
|
5139
|
-
title: blockObject.title === void 0 ? (
|
|
5140
|
-
// This avoids the default title which is a title case of the object name
|
|
5141
|
-
defaultObjectTitles[blockObject.name]
|
|
5142
|
-
) : blockObject.title,
|
|
5143
|
-
fields: blockObject.fields?.map((field) => ({
|
|
5144
|
-
name: field.name,
|
|
5145
|
-
type: field.type
|
|
5146
|
-
})) ?? []
|
|
5147
|
-
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => defineType({
|
|
5148
|
-
type: "object",
|
|
5149
|
-
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5150
|
-
// fields to objects with certain names.
|
|
5151
|
-
name: temporaryObjectNames[inlineObject.name] ?? inlineObject.name,
|
|
5152
|
-
title: inlineObject.title === void 0 ? (
|
|
5153
|
-
// This avoids the default title which is a title case of the object name
|
|
5154
|
-
defaultObjectTitles[inlineObject.name]
|
|
5155
|
-
) : inlineObject.title,
|
|
5156
|
-
fields: inlineObject.fields?.map((field) => ({
|
|
5157
|
-
name: field.name,
|
|
5158
|
-
type: field.type
|
|
5159
|
-
})) ?? []
|
|
5160
|
-
})) ?? [], portableTextSchema = defineField({
|
|
5161
|
-
type: "array",
|
|
5162
|
-
name: "portable-text",
|
|
5163
|
-
of: [...blockObjects.map((blockObject) => ({
|
|
5164
|
-
type: blockObject.name
|
|
5165
|
-
})), {
|
|
5166
|
-
type: "block",
|
|
5167
|
-
name: "block",
|
|
5168
|
-
of: inlineObjects.map((inlineObject) => ({
|
|
5169
|
-
type: inlineObject.name
|
|
5170
|
-
})),
|
|
5171
|
-
marks: {
|
|
5172
|
-
decorators: definition?.decorators?.map((decorator) => ({
|
|
5173
|
-
title: decorator.title ?? startCase(decorator.name),
|
|
5174
|
-
value: decorator.name
|
|
5175
|
-
})) ?? [],
|
|
5176
|
-
annotations: definition?.annotations?.map((annotation) => ({
|
|
5177
|
-
name: annotation.name,
|
|
5178
|
-
type: "object",
|
|
5179
|
-
title: annotation.title,
|
|
5180
|
-
fields: annotation.fields?.map((field) => ({
|
|
5181
|
-
name: field.name,
|
|
5182
|
-
type: field.type
|
|
5183
|
-
})) ?? []
|
|
5184
|
-
})) ?? []
|
|
5185
|
-
},
|
|
5186
|
-
lists: definition?.lists?.map((list) => ({
|
|
5187
|
-
value: list.name,
|
|
5188
|
-
title: list.title ?? startCase(list.name)
|
|
5189
|
-
})) ?? [],
|
|
5190
|
-
styles: definition?.styles?.map((style) => ({
|
|
5191
|
-
value: style.name,
|
|
5192
|
-
title: style.title ?? startCase(style.name)
|
|
5193
|
-
})) ?? []
|
|
5194
|
-
}]
|
|
5195
|
-
}), schema = Schema.compile({
|
|
5196
|
-
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
5197
|
-
}).get("portable-text"), pteSchema = createEditorSchema(schema);
|
|
5198
|
-
return {
|
|
5199
|
-
...pteSchema,
|
|
5200
|
-
blockObjects: pteSchema.blockObjects.map((blockObject) => objectNames[blockObject.name] !== void 0 ? {
|
|
5201
|
-
...blockObject,
|
|
5202
|
-
name: objectNames[blockObject.name],
|
|
5203
|
-
type: {
|
|
5204
|
-
...blockObject.type,
|
|
5205
|
-
name: objectNames[blockObject.name]
|
|
5206
|
-
}
|
|
5207
|
-
} : blockObject),
|
|
5208
|
-
inlineObjects: pteSchema.inlineObjects.map((inlineObject) => objectNames[inlineObject.name] !== void 0 ? {
|
|
5209
|
-
...inlineObject,
|
|
5210
|
-
name: objectNames[inlineObject.name]
|
|
5211
|
-
} : inlineObject)
|
|
5212
|
-
};
|
|
5213
|
-
}
|
|
5214
5100
|
const abstractAnnotationBehaviors = [defineBehavior({
|
|
5215
5101
|
on: "annotation.toggle",
|
|
5216
5102
|
guard: ({
|
|
@@ -6187,7 +6073,7 @@ function getActiveDecorators({
|
|
|
6187
6073
|
schema,
|
|
6188
6074
|
slateEditorInstance
|
|
6189
6075
|
}) {
|
|
6190
|
-
const decorators = schema.decorators.map((decorator) => decorator.
|
|
6076
|
+
const decorators = schema.decorators.map((decorator) => decorator.name);
|
|
6191
6077
|
return ({
|
|
6192
6078
|
...Editor.marks(slateEditorInstance) ?? {}
|
|
6193
6079
|
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
@@ -6612,6 +6498,201 @@ const editorMachine = setup({
|
|
|
6612
6498
|
}
|
|
6613
6499
|
}
|
|
6614
6500
|
});
|
|
6501
|
+
function createLegacySchema(portableTextType) {
|
|
6502
|
+
if (!portableTextType)
|
|
6503
|
+
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
6504
|
+
const blockType = portableTextType.of?.find(findBlockType);
|
|
6505
|
+
if (!blockType)
|
|
6506
|
+
throw new Error("Block type is not defined in this schema (required)");
|
|
6507
|
+
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
6508
|
+
if (!childrenField)
|
|
6509
|
+
throw new Error("Children field for block type found in schema (required)");
|
|
6510
|
+
const ofType = childrenField.type.of;
|
|
6511
|
+
if (!ofType)
|
|
6512
|
+
throw new Error("Valid types for block children not found in schema (required)");
|
|
6513
|
+
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
6514
|
+
if (!spanType)
|
|
6515
|
+
throw new Error("Span type not found in schema (required)");
|
|
6516
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
6517
|
+
return {
|
|
6518
|
+
styles: resolveEnabledStyles(blockType),
|
|
6519
|
+
decorators: resolveEnabledDecorators(spanType),
|
|
6520
|
+
lists: resolveEnabledListItems(blockType),
|
|
6521
|
+
block: blockType,
|
|
6522
|
+
span: spanType,
|
|
6523
|
+
portableText: portableTextType,
|
|
6524
|
+
inlineObjects: inlineObjectTypes,
|
|
6525
|
+
blockObjects: blockObjectTypes,
|
|
6526
|
+
annotations: spanType.annotations
|
|
6527
|
+
};
|
|
6528
|
+
}
|
|
6529
|
+
function resolveEnabledStyles(blockType) {
|
|
6530
|
+
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
6531
|
+
if (!styleField)
|
|
6532
|
+
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
6533
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
6534
|
+
if (!textStyles || textStyles.length === 0)
|
|
6535
|
+
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
6536
|
+
return textStyles;
|
|
6537
|
+
}
|
|
6538
|
+
function resolveEnabledDecorators(spanType) {
|
|
6539
|
+
return spanType.decorators;
|
|
6540
|
+
}
|
|
6541
|
+
function resolveEnabledListItems(blockType) {
|
|
6542
|
+
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
6543
|
+
if (!listField)
|
|
6544
|
+
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
6545
|
+
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
6546
|
+
if (!listItems)
|
|
6547
|
+
throw new Error("The list field need at least to be an empty array");
|
|
6548
|
+
return listItems;
|
|
6549
|
+
}
|
|
6550
|
+
function findBlockType(type) {
|
|
6551
|
+
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
6552
|
+
}
|
|
6553
|
+
function defineSchema(definition) {
|
|
6554
|
+
return definition;
|
|
6555
|
+
}
|
|
6556
|
+
const temporaryImageName = `tmp-${defaultKeyGenerator()}-image`, temporaryUrlName = `tmp-${defaultKeyGenerator()}-url`, temporaryObjectNames = {
|
|
6557
|
+
image: temporaryImageName,
|
|
6558
|
+
url: temporaryUrlName
|
|
6559
|
+
}, objectNames = {
|
|
6560
|
+
[temporaryImageName]: "image",
|
|
6561
|
+
[temporaryUrlName]: "url"
|
|
6562
|
+
}, defaultObjectTitles = {
|
|
6563
|
+
image: "Image",
|
|
6564
|
+
url: "URL"
|
|
6565
|
+
};
|
|
6566
|
+
function legacySchemaToEditorSchema(schema) {
|
|
6567
|
+
return {
|
|
6568
|
+
annotations: schema.annotations.map((annotation) => ({
|
|
6569
|
+
name: annotation.name,
|
|
6570
|
+
fields: annotation.fields.map((field) => ({
|
|
6571
|
+
name: field.name,
|
|
6572
|
+
type: field.type.jsonType
|
|
6573
|
+
})),
|
|
6574
|
+
title: annotation.title
|
|
6575
|
+
})),
|
|
6576
|
+
block: {
|
|
6577
|
+
name: schema.block.name
|
|
6578
|
+
},
|
|
6579
|
+
blockObjects: schema.blockObjects.map((blockObject) => ({
|
|
6580
|
+
name: blockObject.name,
|
|
6581
|
+
fields: blockObject.fields.map((field) => ({
|
|
6582
|
+
name: field.name,
|
|
6583
|
+
type: field.type.jsonType
|
|
6584
|
+
})),
|
|
6585
|
+
title: blockObject.title
|
|
6586
|
+
})),
|
|
6587
|
+
decorators: schema.decorators.map((decorator) => ({
|
|
6588
|
+
name: decorator.value,
|
|
6589
|
+
title: decorator.title,
|
|
6590
|
+
value: decorator.value
|
|
6591
|
+
})),
|
|
6592
|
+
inlineObjects: schema.inlineObjects.map((inlineObject) => ({
|
|
6593
|
+
name: inlineObject.name,
|
|
6594
|
+
fields: inlineObject.fields.map((field) => ({
|
|
6595
|
+
name: field.name,
|
|
6596
|
+
type: field.type.jsonType
|
|
6597
|
+
})),
|
|
6598
|
+
title: inlineObject.title
|
|
6599
|
+
})),
|
|
6600
|
+
span: {
|
|
6601
|
+
name: schema.span.name
|
|
6602
|
+
},
|
|
6603
|
+
styles: schema.styles.map((style) => ({
|
|
6604
|
+
name: style.value,
|
|
6605
|
+
title: style.title,
|
|
6606
|
+
value: style.value
|
|
6607
|
+
})),
|
|
6608
|
+
lists: schema.lists.map((list) => ({
|
|
6609
|
+
name: list.value,
|
|
6610
|
+
title: list.title,
|
|
6611
|
+
value: list.value
|
|
6612
|
+
}))
|
|
6613
|
+
};
|
|
6614
|
+
}
|
|
6615
|
+
function compileSchemaDefinitionToLegacySchema(definition) {
|
|
6616
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => defineType({
|
|
6617
|
+
type: "object",
|
|
6618
|
+
// Very naive way to work around `SanitySchema.compile` adding default
|
|
6619
|
+
// fields to objects with certain names.
|
|
6620
|
+
name: temporaryObjectNames[blockObject.name] ?? blockObject.name,
|
|
6621
|
+
title: blockObject.title === void 0 ? (
|
|
6622
|
+
// This avoids the default title which is a title case of the object name
|
|
6623
|
+
defaultObjectTitles[blockObject.name]
|
|
6624
|
+
) : blockObject.title,
|
|
6625
|
+
fields: blockObject.fields?.map((field) => ({
|
|
6626
|
+
name: field.name,
|
|
6627
|
+
type: field.type
|
|
6628
|
+
})) ?? []
|
|
6629
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => defineType({
|
|
6630
|
+
type: "object",
|
|
6631
|
+
// Very naive way to work around `SanitySchema.compile` adding default
|
|
6632
|
+
// fields to objects with certain names.
|
|
6633
|
+
name: temporaryObjectNames[inlineObject.name] ?? inlineObject.name,
|
|
6634
|
+
title: inlineObject.title === void 0 ? (
|
|
6635
|
+
// This avoids the default title which is a title case of the object name
|
|
6636
|
+
defaultObjectTitles[inlineObject.name]
|
|
6637
|
+
) : inlineObject.title,
|
|
6638
|
+
fields: inlineObject.fields?.map((field) => ({
|
|
6639
|
+
name: field.name,
|
|
6640
|
+
type: field.type
|
|
6641
|
+
})) ?? []
|
|
6642
|
+
})) ?? [], portableTextSchema = defineField({
|
|
6643
|
+
type: "array",
|
|
6644
|
+
name: "portable-text",
|
|
6645
|
+
of: [...blockObjects.map((blockObject) => ({
|
|
6646
|
+
type: blockObject.name
|
|
6647
|
+
})), {
|
|
6648
|
+
type: "block",
|
|
6649
|
+
name: "block",
|
|
6650
|
+
of: inlineObjects.map((inlineObject) => ({
|
|
6651
|
+
type: inlineObject.name
|
|
6652
|
+
})),
|
|
6653
|
+
marks: {
|
|
6654
|
+
decorators: definition?.decorators?.map((decorator) => ({
|
|
6655
|
+
title: decorator.title ?? startCase(decorator.name),
|
|
6656
|
+
value: decorator.name
|
|
6657
|
+
})) ?? [],
|
|
6658
|
+
annotations: definition?.annotations?.map((annotation) => ({
|
|
6659
|
+
name: annotation.name,
|
|
6660
|
+
type: "object",
|
|
6661
|
+
title: annotation.title,
|
|
6662
|
+
fields: annotation.fields?.map((field) => ({
|
|
6663
|
+
name: field.name,
|
|
6664
|
+
type: field.type
|
|
6665
|
+
})) ?? []
|
|
6666
|
+
})) ?? []
|
|
6667
|
+
},
|
|
6668
|
+
lists: definition?.lists?.map((list) => ({
|
|
6669
|
+
value: list.name,
|
|
6670
|
+
title: list.title ?? startCase(list.name)
|
|
6671
|
+
})) ?? [],
|
|
6672
|
+
styles: definition?.styles?.map((style) => ({
|
|
6673
|
+
value: style.name,
|
|
6674
|
+
title: style.title ?? startCase(style.name)
|
|
6675
|
+
})) ?? []
|
|
6676
|
+
}]
|
|
6677
|
+
}), schema = Schema.compile({
|
|
6678
|
+
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
6679
|
+
}).get("portable-text"), pteSchema = createLegacySchema(schema);
|
|
6680
|
+
return {
|
|
6681
|
+
...pteSchema,
|
|
6682
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => objectNames[blockObject.name] !== void 0 ? {
|
|
6683
|
+
...blockObject,
|
|
6684
|
+
name: objectNames[blockObject.name],
|
|
6685
|
+
type: {
|
|
6686
|
+
...blockObject.type,
|
|
6687
|
+
name: objectNames[blockObject.name]
|
|
6688
|
+
}
|
|
6689
|
+
} : blockObject),
|
|
6690
|
+
inlineObjects: pteSchema.inlineObjects.map((inlineObject) => objectNames[inlineObject.name] !== void 0 ? {
|
|
6691
|
+
...inlineObject,
|
|
6692
|
+
name: objectNames[inlineObject.name]
|
|
6693
|
+
} : inlineObject)
|
|
6694
|
+
};
|
|
6695
|
+
}
|
|
6615
6696
|
function defaultCompare(a, b) {
|
|
6616
6697
|
return a === b;
|
|
6617
6698
|
}
|
|
@@ -7020,35 +7101,37 @@ function isAnnotationActive({
|
|
|
7020
7101
|
}
|
|
7021
7102
|
}
|
|
7022
7103
|
function createInternalEditor(config) {
|
|
7023
|
-
const editorActor = createActor(editorMachine, {
|
|
7024
|
-
input: editorConfigToMachineInput(
|
|
7104
|
+
const legacySchema = config.schemaDefinition ? compileSchemaDefinitionToLegacySchema(config.schemaDefinition) : createLegacySchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), editorSchema = legacySchemaToEditorSchema(legacySchema), editorActor = createActor(editorMachine, {
|
|
7105
|
+
input: editorConfigToMachineInput({
|
|
7106
|
+
...config,
|
|
7107
|
+
schema: editorSchema,
|
|
7108
|
+
legacySchema
|
|
7109
|
+
})
|
|
7025
7110
|
});
|
|
7026
|
-
return editorActor.start(), createInternalEditorFromActor(editorActor);
|
|
7111
|
+
return editorActor.start(), createInternalEditorFromActor(editorActor, legacySchema);
|
|
7027
7112
|
}
|
|
7028
7113
|
function useCreateInternalEditor(config) {
|
|
7029
|
-
const
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
}
|
|
7036
|
-
|
|
7037
|
-
let t2, t3;
|
|
7038
|
-
return $[4] !== editorActor ? (t3 = createInternalEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
7114
|
+
const legacySchema = config.schemaDefinition ? compileSchemaDefinitionToLegacySchema(config.schemaDefinition) : createLegacySchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), editorSchema = legacySchemaToEditorSchema(legacySchema), editorActor = useActorRef(editorMachine, {
|
|
7115
|
+
input: editorConfigToMachineInput({
|
|
7116
|
+
...config,
|
|
7117
|
+
schema: editorSchema,
|
|
7118
|
+
legacySchema
|
|
7119
|
+
})
|
|
7120
|
+
});
|
|
7121
|
+
return useMemo(() => createInternalEditorFromActor(editorActor, legacySchema), [editorActor, legacySchema]);
|
|
7039
7122
|
}
|
|
7040
7123
|
function editorConfigToMachineInput(config) {
|
|
7041
7124
|
return {
|
|
7042
7125
|
behaviors: config.behaviors,
|
|
7043
|
-
converters:
|
|
7126
|
+
converters: createCoreConverters(config.legacySchema),
|
|
7044
7127
|
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
7045
7128
|
maxBlocks: config.maxBlocks,
|
|
7046
7129
|
readOnly: config.readOnly,
|
|
7047
|
-
schema: config.
|
|
7130
|
+
schema: config.schema,
|
|
7048
7131
|
initialValue: config.initialValue
|
|
7049
7132
|
};
|
|
7050
7133
|
}
|
|
7051
|
-
function createInternalEditorFromActor(editorActor) {
|
|
7134
|
+
function createInternalEditorFromActor(editorActor, legacySchema) {
|
|
7052
7135
|
const slateEditor = createSlateEditor({
|
|
7053
7136
|
editorActor
|
|
7054
7137
|
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
@@ -7123,6 +7206,7 @@ function createInternalEditorFromActor(editorActor) {
|
|
|
7123
7206
|
_internal: {
|
|
7124
7207
|
editable,
|
|
7125
7208
|
editorActor,
|
|
7209
|
+
legacySchema,
|
|
7126
7210
|
slateEditor
|
|
7127
7211
|
}
|
|
7128
7212
|
};
|
|
@@ -7178,12 +7262,12 @@ class PortableTextEditor extends Component {
|
|
|
7178
7262
|
initialValue: props.value,
|
|
7179
7263
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
7180
7264
|
readOnly: props.readOnly
|
|
7181
|
-
}), this.schemaTypes = this.editor._internal.
|
|
7265
|
+
}), this.schemaTypes = this.editor._internal.legacySchema, this.editable = this.editor._internal.editable;
|
|
7182
7266
|
}
|
|
7183
7267
|
componentDidUpdate(prevProps) {
|
|
7184
|
-
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes =
|
|
7268
|
+
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = createLegacySchema(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
|
|
7185
7269
|
type: "update schema",
|
|
7186
|
-
schema: this.schemaTypes
|
|
7270
|
+
schema: legacySchemaToEditorSchema(this.schemaTypes)
|
|
7187
7271
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
7188
7272
|
type: "update readOnly",
|
|
7189
7273
|
readOnly: this.props.readOnly ?? !1
|