@portabletext/editor 1.47.0 → 1.47.2
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 +379 -326
- 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 +380 -327
- 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 +70 -28
- package/lib/behaviors/index.d.ts +70 -28
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +12 -14
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +61 -3
- package/lib/index.d.ts +61 -3
- package/lib/index.js +12 -14
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +68 -23
- package/lib/plugins/index.d.ts +68 -23
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +69 -27
- package/lib/selectors/index.d.ts +69 -27
- package/lib/utils/index.d.cts +74 -29
- package/lib/utils/index.d.ts +74 -29
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action.insert.block.ts +1 -1
- package/src/behavior-actions/behavior.action.split.block.ts +1 -1
- 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/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 +18 -13
- 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,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$g = 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"), parseBlocks = require("./parse-blocks.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"), omit = require("lodash/omit.js"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"),
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$g = 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"), parseBlocks = require("./parse-blocks.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"), omit = require("lodash/omit.js"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), behavior_core = require("./behavior.core.cjs"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), startCase = require("lodash.startcase"), 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
|
}
|
|
@@ -46,7 +46,7 @@ function toSlateValue(value, {
|
|
|
46
46
|
__inline: !0
|
|
47
47
|
}, keyMap)) : child;
|
|
48
48
|
});
|
|
49
|
-
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].
|
|
49
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].name), keepObjectEquality({
|
|
50
50
|
_type,
|
|
51
51
|
_key,
|
|
52
52
|
...rest,
|
|
@@ -115,7 +115,7 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
118
|
-
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].
|
|
118
|
+
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].name && !("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 === "";
|
|
119
119
|
}
|
|
120
120
|
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 = xstate.setup({
|
|
121
121
|
types: {
|
|
@@ -476,7 +476,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
476
476
|
}
|
|
477
477
|
}, !0;
|
|
478
478
|
}
|
|
479
|
-
const orphanedMarks = allUsedMarks.filter((mark) => !types$1.decorators.map((dec) => dec.
|
|
479
|
+
const orphanedMarks = allUsedMarks.filter((mark) => !types$1.decorators.map((dec) => dec.name).includes(mark)).filter((mark) => textBlock.markDefs === void 0 || !textBlock.markDefs.find((def) => def._key === mark));
|
|
480
480
|
if (orphanedMarks.length > 0) {
|
|
481
481
|
const spanChildren = textBlock.children.filter((cld) => cld._type === types$1.span.name && Array.isArray(cld.marks) && cld.marks.some((mark) => orphanedMarks.includes(mark)));
|
|
482
482
|
if (spanChildren) {
|
|
@@ -1329,11 +1329,10 @@ const debug$f = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ n
|
|
|
1329
1329
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
1330
1330
|
function createWithUndoRedo(options) {
|
|
1331
1331
|
const {
|
|
1332
|
-
editorActor
|
|
1333
|
-
blockSchemaType
|
|
1332
|
+
editorActor
|
|
1334
1333
|
} = options;
|
|
1335
1334
|
return (editor) => {
|
|
1336
|
-
let previousSnapshot = fromSlateValue(editor.children,
|
|
1335
|
+
let previousSnapshot = fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name);
|
|
1337
1336
|
const remotePatches = getRemotePatches(editor);
|
|
1338
1337
|
let previousBehaviorActionSetId = getCurrentBehaviorActionSetId(editor);
|
|
1339
1338
|
options.subscriptions.push(() => {
|
|
@@ -2059,7 +2058,7 @@ function Synchronizer(props) {
|
|
|
2059
2058
|
}, $[6] = slateEditor, $[7] = t0.context.keyGenerator, $[8] = t2, $[9] = t3.context.schema, $[10] = t4) : t4 = $[10];
|
|
2060
2059
|
const syncActorRef = react.useActorRef(syncMachine, t4);
|
|
2061
2060
|
let t5;
|
|
2062
|
-
$[11] !== editorActor ? (t5 = editorActor.getSnapshot(), $[11] = editorActor, $[12] = t5) : t5 = $[12];
|
|
2061
|
+
$[11] !== props.editorActor ? (t5 = props.editorActor.getSnapshot(), $[11] = props.editorActor, $[12] = t5) : t5 = $[12];
|
|
2063
2062
|
let t6;
|
|
2064
2063
|
$[13] !== slateEditor || $[14] !== t5.context.schema ? (t6 = {
|
|
2065
2064
|
input: {
|
|
@@ -2262,121 +2261,128 @@ const converterJson = {
|
|
|
2262
2261
|
mimeType: "application/x-portable-text"
|
|
2263
2262
|
};
|
|
2264
2263
|
}
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2264
|
+
};
|
|
2265
|
+
function createConverterTextHtml(legacySchema) {
|
|
2266
|
+
return {
|
|
2267
|
+
mimeType: "text/html",
|
|
2268
|
+
serialize: ({
|
|
2269
|
+
snapshot,
|
|
2270
|
+
event
|
|
2271
|
+
}) => {
|
|
2272
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2273
|
+
if (!selection)
|
|
2274
|
+
return {
|
|
2275
|
+
type: "serialization.failure",
|
|
2276
|
+
mimeType: "text/html",
|
|
2277
|
+
originEvent: event.originEvent,
|
|
2278
|
+
reason: "No selection"
|
|
2279
|
+
};
|
|
2280
|
+
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2281
|
+
blocks: snapshot.context.value,
|
|
2282
|
+
selection
|
|
2283
|
+
}), html = toHtml.toHTML(blocks, {
|
|
2284
|
+
onMissingComponent: !1,
|
|
2285
|
+
components: {
|
|
2286
|
+
unknownType: ({
|
|
2287
|
+
children
|
|
2288
|
+
}) => children !== void 0 ? `${children}` : ""
|
|
2289
|
+
}
|
|
2290
|
+
});
|
|
2291
|
+
return html === "" ? {
|
|
2274
2292
|
type: "serialization.failure",
|
|
2275
2293
|
mimeType: "text/html",
|
|
2276
2294
|
originEvent: event.originEvent,
|
|
2277
|
-
reason: "
|
|
2295
|
+
reason: "Serialized HTML is empty"
|
|
2296
|
+
} : {
|
|
2297
|
+
type: "serialization.success",
|
|
2298
|
+
data: html,
|
|
2299
|
+
mimeType: "text/html",
|
|
2300
|
+
originEvent: event.originEvent
|
|
2278
2301
|
};
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
type: "serialization.success",
|
|
2297
|
-
data: html,
|
|
2298
|
-
mimeType: "text/html",
|
|
2299
|
-
originEvent: event.originEvent
|
|
2300
|
-
};
|
|
2301
|
-
},
|
|
2302
|
-
deserialize: ({
|
|
2303
|
-
snapshot,
|
|
2304
|
-
event
|
|
2305
|
-
}) => {
|
|
2306
|
-
const parsedBlocks = blockTools.htmlToBlocks(event.data, snapshot.context.schema.portableText, {
|
|
2307
|
-
keyGenerator: snapshot.context.keyGenerator,
|
|
2308
|
-
unstable_whitespaceOnPasteMode: snapshot.context.schema.block.options.unstable_whitespaceOnPasteMode
|
|
2309
|
-
}).flatMap((block) => {
|
|
2310
|
-
const parsedBlock = parseBlocks.parseBlock({
|
|
2311
|
-
context: snapshot.context,
|
|
2312
|
-
block,
|
|
2313
|
-
options: {
|
|
2314
|
-
refreshKeys: !1
|
|
2315
|
-
}
|
|
2302
|
+
},
|
|
2303
|
+
deserialize: ({
|
|
2304
|
+
snapshot,
|
|
2305
|
+
event
|
|
2306
|
+
}) => {
|
|
2307
|
+
const parsedBlocks = blockTools.htmlToBlocks(event.data, legacySchema.portableText, {
|
|
2308
|
+
keyGenerator: snapshot.context.keyGenerator,
|
|
2309
|
+
unstable_whitespaceOnPasteMode: legacySchema.block.options.unstable_whitespaceOnPasteMode
|
|
2310
|
+
}).flatMap((block) => {
|
|
2311
|
+
const parsedBlock = parseBlocks.parseBlock({
|
|
2312
|
+
context: snapshot.context,
|
|
2313
|
+
block,
|
|
2314
|
+
options: {
|
|
2315
|
+
refreshKeys: !1
|
|
2316
|
+
}
|
|
2317
|
+
});
|
|
2318
|
+
return parsedBlock ? [parsedBlock] : [];
|
|
2316
2319
|
});
|
|
2317
|
-
return
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2320
|
+
return parsedBlocks.length === 0 ? {
|
|
2321
|
+
type: "deserialization.failure",
|
|
2322
|
+
mimeType: "text/html",
|
|
2323
|
+
reason: "No blocks deserialized"
|
|
2324
|
+
} : {
|
|
2325
|
+
type: "deserialization.success",
|
|
2326
|
+
data: parsedBlocks,
|
|
2327
|
+
mimeType: "text/html"
|
|
2328
|
+
};
|
|
2329
|
+
}
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
function createConverterTextPlain(legacySchema) {
|
|
2333
|
+
return {
|
|
2334
|
+
mimeType: "text/plain",
|
|
2335
|
+
serialize: ({
|
|
2336
|
+
snapshot,
|
|
2337
|
+
event
|
|
2338
|
+
}) => {
|
|
2339
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2340
|
+
return selection ? {
|
|
2341
|
+
type: "serialization.success",
|
|
2342
|
+
data: util_sliceBlocks.sliceBlocks({
|
|
2343
|
+
blocks: snapshot.context.value,
|
|
2344
|
+
selection
|
|
2345
|
+
}).map((block) => types.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(`
|
|
2342
2346
|
|
|
2343
2347
|
`),
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2348
|
+
mimeType: "text/plain",
|
|
2349
|
+
originEvent: event.originEvent
|
|
2350
|
+
} : {
|
|
2351
|
+
type: "serialization.failure",
|
|
2352
|
+
mimeType: "text/plain",
|
|
2353
|
+
originEvent: event.originEvent,
|
|
2354
|
+
reason: "No selection"
|
|
2355
|
+
};
|
|
2356
|
+
},
|
|
2357
|
+
deserialize: ({
|
|
2358
|
+
snapshot,
|
|
2359
|
+
event
|
|
2360
|
+
}) => {
|
|
2361
|
+
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 = blockTools.htmlToBlocks(textToHtml, legacySchema.portableText, {
|
|
2362
|
+
keyGenerator: snapshot.context.keyGenerator
|
|
2363
|
+
}).flatMap((block) => {
|
|
2364
|
+
const parsedBlock = parseBlocks.parseBlock({
|
|
2365
|
+
context: snapshot.context,
|
|
2366
|
+
block,
|
|
2367
|
+
options: {
|
|
2368
|
+
refreshKeys: !1
|
|
2369
|
+
}
|
|
2370
|
+
});
|
|
2371
|
+
return parsedBlock ? [parsedBlock] : [];
|
|
2366
2372
|
});
|
|
2367
|
-
return
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2373
|
+
return parsedBlocks.length === 0 ? {
|
|
2374
|
+
type: "deserialization.failure",
|
|
2375
|
+
mimeType: "text/plain",
|
|
2376
|
+
reason: "No blocks deserialized"
|
|
2377
|
+
} : {
|
|
2378
|
+
type: "deserialization.success",
|
|
2379
|
+
data: parsedBlocks,
|
|
2380
|
+
mimeType: "text/plain"
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
};
|
|
2384
|
+
}
|
|
2385
|
+
const entityMap = {
|
|
2380
2386
|
"&": "&",
|
|
2381
2387
|
"<": "<",
|
|
2382
2388
|
">": ">",
|
|
@@ -2389,68 +2395,18 @@ const converterJson = {
|
|
|
2389
2395
|
function escapeHtml(str) {
|
|
2390
2396
|
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
2391
2397
|
}
|
|
2392
|
-
|
|
2398
|
+
function createCoreConverters(legacySchema) {
|
|
2399
|
+
return [converterJson, converterPortableText, createConverterTextHtml(legacySchema), createConverterTextPlain(legacySchema)];
|
|
2400
|
+
}
|
|
2393
2401
|
function compileType(rawType) {
|
|
2394
2402
|
return schema.Schema.compile({
|
|
2395
2403
|
name: "blockTypeSchema",
|
|
2396
2404
|
types: [rawType]
|
|
2397
2405
|
}).get(rawType.name);
|
|
2398
2406
|
}
|
|
2399
|
-
function createEditorSchema(portableTextType) {
|
|
2400
|
-
if (!portableTextType)
|
|
2401
|
-
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
2402
|
-
const blockType = portableTextType.of?.find(findBlockType);
|
|
2403
|
-
if (!blockType)
|
|
2404
|
-
throw new Error("Block type is not defined in this schema (required)");
|
|
2405
|
-
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
2406
|
-
if (!childrenField)
|
|
2407
|
-
throw new Error("Children field for block type found in schema (required)");
|
|
2408
|
-
const ofType = childrenField.type.of;
|
|
2409
|
-
if (!ofType)
|
|
2410
|
-
throw new Error("Valid types for block children not found in schema (required)");
|
|
2411
|
-
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
2412
|
-
if (!spanType)
|
|
2413
|
-
throw new Error("Span type not found in schema (required)");
|
|
2414
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
2415
|
-
return {
|
|
2416
|
-
styles: resolveEnabledStyles(blockType),
|
|
2417
|
-
decorators: resolveEnabledDecorators(spanType),
|
|
2418
|
-
lists: resolveEnabledListItems(blockType),
|
|
2419
|
-
block: blockType,
|
|
2420
|
-
span: spanType,
|
|
2421
|
-
portableText: portableTextType,
|
|
2422
|
-
inlineObjects: inlineObjectTypes,
|
|
2423
|
-
blockObjects: blockObjectTypes,
|
|
2424
|
-
annotations: spanType.annotations
|
|
2425
|
-
};
|
|
2426
|
-
}
|
|
2427
|
-
function resolveEnabledStyles(blockType) {
|
|
2428
|
-
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
2429
|
-
if (!styleField)
|
|
2430
|
-
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
2431
|
-
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
2432
|
-
if (!textStyles || textStyles.length === 0)
|
|
2433
|
-
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
2434
|
-
return textStyles;
|
|
2435
|
-
}
|
|
2436
|
-
function resolveEnabledDecorators(spanType) {
|
|
2437
|
-
return spanType.decorators;
|
|
2438
|
-
}
|
|
2439
|
-
function resolveEnabledListItems(blockType) {
|
|
2440
|
-
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
2441
|
-
if (!listField)
|
|
2442
|
-
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
2443
|
-
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
2444
|
-
if (!listItems)
|
|
2445
|
-
throw new Error("The list field need at least to be an empty array");
|
|
2446
|
-
return listItems;
|
|
2447
|
-
}
|
|
2448
|
-
function findBlockType(type) {
|
|
2449
|
-
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
2450
|
-
}
|
|
2451
2407
|
const debug$c = debugWithName("operationToPatches");
|
|
2452
|
-
function createOperationToPatches(
|
|
2453
|
-
const textBlockName =
|
|
2408
|
+
function createOperationToPatches(editorActor) {
|
|
2409
|
+
const textBlockName = editorActor.getSnapshot().context.schema.block.name;
|
|
2454
2410
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
2455
2411
|
debug$c.enabled && debug$c("Operation", JSON.stringify(operation, null, 2));
|
|
2456
2412
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
@@ -2719,12 +2675,12 @@ function getNextSpan({
|
|
|
2719
2675
|
return nextSpan;
|
|
2720
2676
|
}
|
|
2721
2677
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
2722
|
-
function createWithPortableTextMarkModel(editorActor
|
|
2678
|
+
function createWithPortableTextMarkModel(editorActor) {
|
|
2723
2679
|
return function(editor) {
|
|
2724
2680
|
const {
|
|
2725
2681
|
apply: apply2,
|
|
2726
2682
|
normalizeNode
|
|
2727
|
-
} = editor, decorators =
|
|
2683
|
+
} = editor, decorators = editorActor.getSnapshot().context.schema.decorators.map((t) => t.name);
|
|
2728
2684
|
return editor.normalizeNode = (nodeEntry) => {
|
|
2729
2685
|
const [node, path] = nodeEntry;
|
|
2730
2686
|
if (editor.isTextBlock(node)) {
|
|
@@ -2769,7 +2725,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
2769
2725
|
return;
|
|
2770
2726
|
}
|
|
2771
2727
|
if (editor.isTextSpan(node)) {
|
|
2772
|
-
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 =
|
|
2728
|
+
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
2773
2729
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
2774
2730
|
debug$b("Removing annotations from empty span node"), editorActor.send({
|
|
2775
2731
|
type: "normalizing"
|
|
@@ -2784,7 +2740,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
2784
2740
|
}
|
|
2785
2741
|
}
|
|
2786
2742
|
if (editor.isTextBlock(node)) {
|
|
2787
|
-
const decorators2 =
|
|
2743
|
+
const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name);
|
|
2788
2744
|
for (const [child, childPath] of slate.Node.children(editor, path))
|
|
2789
2745
|
if (editor.isTextSpan(child)) {
|
|
2790
2746
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
@@ -2805,7 +2761,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
2805
2761
|
if (editor.isTextSpan(node)) {
|
|
2806
2762
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath);
|
|
2807
2763
|
if (editor.isTextBlock(block)) {
|
|
2808
|
-
const decorators2 =
|
|
2764
|
+
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));
|
|
2809
2765
|
if (orphanedAnnotations.length > 0) {
|
|
2810
2766
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
2811
2767
|
type: "normalizing"
|
|
@@ -3056,7 +3012,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3056
3012
|
}
|
|
3057
3013
|
}
|
|
3058
3014
|
}
|
|
3059
|
-
if (op.type === "merge_node" && op.path.length === 1 && "markDefs" in op.properties && op.properties._type ===
|
|
3015
|
+
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) {
|
|
3060
3016
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
3061
3017
|
if (editor.isTextBlock(targetBlock)) {
|
|
3062
3018
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
@@ -4053,7 +4009,7 @@ const moveBackwardActionImplementation = ({
|
|
|
4053
4009
|
continue;
|
|
4054
4010
|
const marks = child.marks ?? [];
|
|
4055
4011
|
for (const mark of marks)
|
|
4056
|
-
schema2.decorators.some((decorator) => decorator.
|
|
4012
|
+
schema2.decorators.some((decorator) => decorator.name === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
4057
4013
|
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
4058
4014
|
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
4059
4015
|
marks: newMarks
|
|
@@ -4474,7 +4430,7 @@ function createWithMaxBlocks(editorActor) {
|
|
|
4474
4430
|
}, editor;
|
|
4475
4431
|
};
|
|
4476
4432
|
}
|
|
4477
|
-
function createWithObjectKeys(editorActor
|
|
4433
|
+
function createWithObjectKeys(editorActor) {
|
|
4478
4434
|
return function(editor) {
|
|
4479
4435
|
const {
|
|
4480
4436
|
apply: apply2,
|
|
@@ -4514,7 +4470,7 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
4514
4470
|
apply2(operation);
|
|
4515
4471
|
}, editor.normalizeNode = (entry) => {
|
|
4516
4472
|
const [node, path] = entry;
|
|
4517
|
-
if (slate.Element.isElement(node) && node._type ===
|
|
4473
|
+
if (slate.Element.isElement(node) && node._type === editorActor.getSnapshot().context.schema.block.name) {
|
|
4518
4474
|
if (!node._key) {
|
|
4519
4475
|
editorActor.send({
|
|
4520
4476
|
type: "normalizing"
|
|
@@ -4546,7 +4502,7 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
4546
4502
|
};
|
|
4547
4503
|
}
|
|
4548
4504
|
const debug$9 = debugWithName("applyPatches"), debugVerbose = debug$9.enabled && !0;
|
|
4549
|
-
function createApplyPatch(
|
|
4505
|
+
function createApplyPatch(schema2) {
|
|
4550
4506
|
return (editor, patch) => {
|
|
4551
4507
|
let changed = !1;
|
|
4552
4508
|
debugVerbose && (debug$9(`
|
|
@@ -4555,7 +4511,7 @@ NEW PATCH =============================================================`), debug
|
|
|
4555
4511
|
try {
|
|
4556
4512
|
switch (patch.type) {
|
|
4557
4513
|
case "insert":
|
|
4558
|
-
changed = insertPatch(editor, patch,
|
|
4514
|
+
changed = insertPatch(editor, patch, schema2);
|
|
4559
4515
|
break;
|
|
4560
4516
|
case "unset":
|
|
4561
4517
|
changed = unsetPatch(editor, patch);
|
|
@@ -4606,7 +4562,7 @@ function diffMatchPatch(editor, patch) {
|
|
|
4606
4562
|
}) : op === DIFF_EQUAL && (offset += text.length);
|
|
4607
4563
|
return debugState(editor, "after"), !0;
|
|
4608
4564
|
}
|
|
4609
|
-
function insertPatch(editor, patch,
|
|
4565
|
+
function insertPatch(editor, patch, schema2) {
|
|
4610
4566
|
const {
|
|
4611
4567
|
block: targetBlock,
|
|
4612
4568
|
child: targetChild,
|
|
@@ -4622,7 +4578,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
4622
4578
|
items: items2,
|
|
4623
4579
|
position: position2
|
|
4624
4580
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
4625
|
-
schemaTypes
|
|
4581
|
+
schemaTypes: schema2
|
|
4626
4582
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
4627
4583
|
return debug$9(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
|
|
4628
4584
|
at: [normalizedIdx2]
|
|
@@ -4638,7 +4594,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
4638
4594
|
...targetBlock,
|
|
4639
4595
|
children: items
|
|
4640
4596
|
}], {
|
|
4641
|
-
schemaTypes
|
|
4597
|
+
schemaTypes: schema2
|
|
4642
4598
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
4643
4599
|
return debug$9(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
4644
4600
|
at: childInsertPath
|
|
@@ -4816,11 +4772,10 @@ const debug$8 = debugWithName("plugin:withPatches");
|
|
|
4816
4772
|
function createWithPatches({
|
|
4817
4773
|
editorActor,
|
|
4818
4774
|
patchFunctions,
|
|
4819
|
-
schemaTypes,
|
|
4820
4775
|
subscriptions
|
|
4821
4776
|
}) {
|
|
4822
4777
|
let previousChildren;
|
|
4823
|
-
const applyPatch = createApplyPatch(
|
|
4778
|
+
const applyPatch = createApplyPatch(editorActor.getSnapshot().context.schema);
|
|
4824
4779
|
return function(editor) {
|
|
4825
4780
|
IS_PROCESSING_REMOTE_CHANGES.set(editor, !1), PATCHING.set(editor, !0), previousChildren = [...editor.children];
|
|
4826
4781
|
const {
|
|
@@ -4859,9 +4814,9 @@ function createWithPatches({
|
|
|
4859
4814
|
}), editor.apply = (operation) => {
|
|
4860
4815
|
let patches$1 = [];
|
|
4861
4816
|
previousChildren = editor.children;
|
|
4862
|
-
const editorWasEmpty = isEqualToEmptyEditor(previousChildren,
|
|
4817
|
+
const editorWasEmpty = isEqualToEmptyEditor(previousChildren, editorActor.getSnapshot().context.schema);
|
|
4863
4818
|
apply2(operation);
|
|
4864
|
-
const editorIsEmpty = isEqualToEmptyEditor(editor.children,
|
|
4819
|
+
const editorIsEmpty = isEqualToEmptyEditor(editor.children, editorActor.getSnapshot().context.schema);
|
|
4865
4820
|
if (!isPatching(editor))
|
|
4866
4821
|
return editor;
|
|
4867
4822
|
switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches$1.push(patches.insert(previousChildren, "before", [0])), operation.type) {
|
|
@@ -4892,7 +4847,7 @@ function createWithPatches({
|
|
|
4892
4847
|
}
|
|
4893
4848
|
if (!editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches$1 = [...patches$1, patches.unset([])], editorActor.send({
|
|
4894
4849
|
type: "notify.unset",
|
|
4895
|
-
previousValue: fromSlateValue(previousChildren,
|
|
4850
|
+
previousValue: fromSlateValue(previousChildren, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
|
|
4896
4851
|
})), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0)
|
|
4897
4852
|
for (const patch of patches$1)
|
|
4898
4853
|
editorActor.send({
|
|
@@ -4902,7 +4857,7 @@ function createWithPatches({
|
|
|
4902
4857
|
origin: "local"
|
|
4903
4858
|
},
|
|
4904
4859
|
actionId: getCurrentActionId(editor),
|
|
4905
|
-
value: fromSlateValue(editor.children,
|
|
4860
|
+
value: fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
|
|
4906
4861
|
});
|
|
4907
4862
|
return editor;
|
|
4908
4863
|
}, editor;
|
|
@@ -4943,8 +4898,8 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4943
4898
|
};
|
|
4944
4899
|
}
|
|
4945
4900
|
const debug$6 = debugWithName("plugin:withPortableTextBlockStyle");
|
|
4946
|
-
function createWithPortableTextBlockStyle(editorActor
|
|
4947
|
-
const defaultStyle =
|
|
4901
|
+
function createWithPortableTextBlockStyle(editorActor) {
|
|
4902
|
+
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
|
|
4948
4903
|
return function(editor) {
|
|
4949
4904
|
const {
|
|
4950
4905
|
normalizeNode
|
|
@@ -5008,11 +4963,10 @@ function createWithPortableTextSelections(editorActor) {
|
|
|
5008
4963
|
}
|
|
5009
4964
|
const debug$5 = debugWithName("plugin:withSchemaTypes");
|
|
5010
4965
|
function createWithSchemaTypes({
|
|
5011
|
-
editorActor
|
|
5012
|
-
schemaTypes
|
|
4966
|
+
editorActor
|
|
5013
4967
|
}) {
|
|
5014
4968
|
return function(editor) {
|
|
5015
|
-
editor.isTextBlock = (value) => types.isPortableTextTextBlock(value) && value._type ===
|
|
4969
|
+
editor.isTextBlock = (value) => types.isPortableTextTextBlock(value) && value._type === editorActor.getSnapshot().context.schema.block.name, editor.isTextSpan = (value) => types.isPortableTextSpan(value) && value._type === editorActor.getSnapshot().context.schema.span.name, editor.isListBlock = (value) => types.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;
|
|
5016
4970
|
const {
|
|
5017
4971
|
normalizeNode
|
|
5018
4972
|
} = editor;
|
|
@@ -5025,7 +4979,7 @@ function createWithSchemaTypes({
|
|
|
5025
4979
|
type: "normalizing"
|
|
5026
4980
|
}), slate.Transforms.setNodes(editor, {
|
|
5027
4981
|
...span,
|
|
5028
|
-
_type:
|
|
4982
|
+
_type: editorActor.getSnapshot().context.schema.span.name,
|
|
5029
4983
|
_key: key
|
|
5030
4984
|
}, {
|
|
5031
4985
|
at: path
|
|
@@ -5053,14 +5007,13 @@ function createWithSchemaTypes({
|
|
|
5053
5007
|
};
|
|
5054
5008
|
}
|
|
5055
5009
|
function createWithUtils({
|
|
5056
|
-
editorActor
|
|
5057
|
-
schemaTypes
|
|
5010
|
+
editorActor
|
|
5058
5011
|
}) {
|
|
5059
5012
|
return function(editor) {
|
|
5060
5013
|
return editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
5061
|
-
_type:
|
|
5014
|
+
_type: editorActor.getSnapshot().context.schema.block.name,
|
|
5062
5015
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5063
|
-
style:
|
|
5016
|
+
style: editorActor.getSnapshot().context.schema.styles[0].name || "normal",
|
|
5064
5017
|
...options.listItem ? {
|
|
5065
5018
|
listItem: options.listItem
|
|
5066
5019
|
} : {},
|
|
@@ -5072,33 +5025,29 @@ function createWithUtils({
|
|
|
5072
5025
|
_type: "span",
|
|
5073
5026
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5074
5027
|
text: "",
|
|
5075
|
-
marks: options.decorators.filter((decorator) =>
|
|
5076
|
-
|
|
5077
|
-
}) =>
|
|
5028
|
+
marks: options.decorators.filter((decorator) => editorActor.getSnapshot().context.schema.decorators.find(({
|
|
5029
|
+
name
|
|
5030
|
+
}) => name === decorator))
|
|
5078
5031
|
}]
|
|
5079
5032
|
}], {
|
|
5080
|
-
schemaTypes
|
|
5033
|
+
schemaTypes: editorActor.getSnapshot().context.schema
|
|
5081
5034
|
})[0], editor;
|
|
5082
5035
|
};
|
|
5083
5036
|
}
|
|
5084
5037
|
const withPlugins = (editor, options) => {
|
|
5085
5038
|
const e = editor, {
|
|
5086
5039
|
editorActor
|
|
5087
|
-
} = options,
|
|
5088
|
-
editorActor
|
|
5089
|
-
schemaTypes
|
|
5040
|
+
} = options, operationToPatches = createOperationToPatches(editorActor), withObjectKeys = createWithObjectKeys(editorActor), withSchemaTypes = createWithSchemaTypes({
|
|
5041
|
+
editorActor
|
|
5090
5042
|
}), withPatches = createWithPatches({
|
|
5091
5043
|
editorActor,
|
|
5092
5044
|
patchFunctions: operationToPatches,
|
|
5093
|
-
schemaTypes,
|
|
5094
5045
|
subscriptions: options.subscriptions
|
|
5095
5046
|
}), withMaxBlocks = createWithMaxBlocks(editorActor), withUndoRedo = createWithUndoRedo({
|
|
5096
5047
|
editorActor,
|
|
5097
|
-
blockSchemaType: schemaTypes.block,
|
|
5098
5048
|
subscriptions: options.subscriptions
|
|
5099
|
-
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor
|
|
5100
|
-
editorActor
|
|
5101
|
-
schemaTypes
|
|
5049
|
+
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5050
|
+
editorActor
|
|
5102
5051
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
5103
5052
|
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5104
5053
|
}, debug$4 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
@@ -5122,100 +5071,6 @@ function createSlateEditor(config) {
|
|
|
5122
5071
|
};
|
|
5123
5072
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
5124
5073
|
}
|
|
5125
|
-
function defineSchema(definition) {
|
|
5126
|
-
return definition;
|
|
5127
|
-
}
|
|
5128
|
-
const temporaryImageName = `tmp-${defaultKeyGenerator()}-image`, temporaryUrlName = `tmp-${defaultKeyGenerator()}-url`, temporaryObjectNames = {
|
|
5129
|
-
image: temporaryImageName,
|
|
5130
|
-
url: temporaryUrlName
|
|
5131
|
-
}, objectNames = {
|
|
5132
|
-
[temporaryImageName]: "image",
|
|
5133
|
-
[temporaryUrlName]: "url"
|
|
5134
|
-
}, defaultObjectTitles = {
|
|
5135
|
-
image: "Image",
|
|
5136
|
-
url: "URL"
|
|
5137
|
-
};
|
|
5138
|
-
function compileSchemaDefinition(definition) {
|
|
5139
|
-
const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
|
|
5140
|
-
type: "object",
|
|
5141
|
-
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5142
|
-
// fields to objects with certain names.
|
|
5143
|
-
name: temporaryObjectNames[blockObject.name] ?? blockObject.name,
|
|
5144
|
-
title: blockObject.title === void 0 ? (
|
|
5145
|
-
// This avoids the default title which is a title case of the object name
|
|
5146
|
-
defaultObjectTitles[blockObject.name]
|
|
5147
|
-
) : blockObject.title,
|
|
5148
|
-
fields: blockObject.fields?.map((field) => ({
|
|
5149
|
-
name: field.name,
|
|
5150
|
-
type: field.type
|
|
5151
|
-
})) ?? []
|
|
5152
|
-
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
|
|
5153
|
-
type: "object",
|
|
5154
|
-
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5155
|
-
// fields to objects with certain names.
|
|
5156
|
-
name: temporaryObjectNames[inlineObject.name] ?? inlineObject.name,
|
|
5157
|
-
title: inlineObject.title === void 0 ? (
|
|
5158
|
-
// This avoids the default title which is a title case of the object name
|
|
5159
|
-
defaultObjectTitles[inlineObject.name]
|
|
5160
|
-
) : inlineObject.title,
|
|
5161
|
-
fields: inlineObject.fields?.map((field) => ({
|
|
5162
|
-
name: field.name,
|
|
5163
|
-
type: field.type
|
|
5164
|
-
})) ?? []
|
|
5165
|
-
})) ?? [], portableTextSchema = types.defineField({
|
|
5166
|
-
type: "array",
|
|
5167
|
-
name: "portable-text",
|
|
5168
|
-
of: [...blockObjects.map((blockObject) => ({
|
|
5169
|
-
type: blockObject.name
|
|
5170
|
-
})), {
|
|
5171
|
-
type: "block",
|
|
5172
|
-
name: "block",
|
|
5173
|
-
of: inlineObjects.map((inlineObject) => ({
|
|
5174
|
-
type: inlineObject.name
|
|
5175
|
-
})),
|
|
5176
|
-
marks: {
|
|
5177
|
-
decorators: definition?.decorators?.map((decorator) => ({
|
|
5178
|
-
title: decorator.title ?? startCase__default.default(decorator.name),
|
|
5179
|
-
value: decorator.name
|
|
5180
|
-
})) ?? [],
|
|
5181
|
-
annotations: definition?.annotations?.map((annotation) => ({
|
|
5182
|
-
name: annotation.name,
|
|
5183
|
-
type: "object",
|
|
5184
|
-
title: annotation.title,
|
|
5185
|
-
fields: annotation.fields?.map((field) => ({
|
|
5186
|
-
name: field.name,
|
|
5187
|
-
type: field.type
|
|
5188
|
-
})) ?? []
|
|
5189
|
-
})) ?? []
|
|
5190
|
-
},
|
|
5191
|
-
lists: definition?.lists?.map((list) => ({
|
|
5192
|
-
value: list.name,
|
|
5193
|
-
title: list.title ?? startCase__default.default(list.name)
|
|
5194
|
-
})) ?? [],
|
|
5195
|
-
styles: definition?.styles?.map((style) => ({
|
|
5196
|
-
value: style.name,
|
|
5197
|
-
title: style.title ?? startCase__default.default(style.name)
|
|
5198
|
-
})) ?? []
|
|
5199
|
-
}]
|
|
5200
|
-
}), schema$1 = schema.Schema.compile({
|
|
5201
|
-
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
5202
|
-
}).get("portable-text"), pteSchema = createEditorSchema(schema$1);
|
|
5203
|
-
return {
|
|
5204
|
-
...pteSchema,
|
|
5205
|
-
blockObjects: pteSchema.blockObjects.map((blockObject) => objectNames[blockObject.name] !== void 0 ? {
|
|
5206
|
-
...blockObject,
|
|
5207
|
-
name: objectNames[blockObject.name],
|
|
5208
|
-
type: {
|
|
5209
|
-
...blockObject.type,
|
|
5210
|
-
name: objectNames[blockObject.name]
|
|
5211
|
-
}
|
|
5212
|
-
} : blockObject),
|
|
5213
|
-
inlineObjects: pteSchema.inlineObjects.map((inlineObject) => objectNames[inlineObject.name] !== void 0 ? {
|
|
5214
|
-
...inlineObject,
|
|
5215
|
-
name: objectNames[inlineObject.name]
|
|
5216
|
-
} : inlineObject)
|
|
5217
|
-
};
|
|
5218
|
-
}
|
|
5219
5074
|
const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
5220
5075
|
on: "annotation.toggle",
|
|
5221
5076
|
guard: ({
|
|
@@ -6192,7 +6047,7 @@ function getActiveDecorators({
|
|
|
6192
6047
|
schema: schema2,
|
|
6193
6048
|
slateEditorInstance
|
|
6194
6049
|
}) {
|
|
6195
|
-
const decorators = schema2.decorators.map((decorator) => decorator.
|
|
6050
|
+
const decorators = schema2.decorators.map((decorator) => decorator.name);
|
|
6196
6051
|
return ({
|
|
6197
6052
|
...slate.Editor.marks(slateEditorInstance) ?? {}
|
|
6198
6053
|
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
@@ -6617,6 +6472,201 @@ const editorMachine = xstate.setup({
|
|
|
6617
6472
|
}
|
|
6618
6473
|
}
|
|
6619
6474
|
});
|
|
6475
|
+
function createLegacySchema(portableTextType) {
|
|
6476
|
+
if (!portableTextType)
|
|
6477
|
+
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
6478
|
+
const blockType = portableTextType.of?.find(findBlockType);
|
|
6479
|
+
if (!blockType)
|
|
6480
|
+
throw new Error("Block type is not defined in this schema (required)");
|
|
6481
|
+
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
6482
|
+
if (!childrenField)
|
|
6483
|
+
throw new Error("Children field for block type found in schema (required)");
|
|
6484
|
+
const ofType = childrenField.type.of;
|
|
6485
|
+
if (!ofType)
|
|
6486
|
+
throw new Error("Valid types for block children not found in schema (required)");
|
|
6487
|
+
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
6488
|
+
if (!spanType)
|
|
6489
|
+
throw new Error("Span type not found in schema (required)");
|
|
6490
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
6491
|
+
return {
|
|
6492
|
+
styles: resolveEnabledStyles(blockType),
|
|
6493
|
+
decorators: resolveEnabledDecorators(spanType),
|
|
6494
|
+
lists: resolveEnabledListItems(blockType),
|
|
6495
|
+
block: blockType,
|
|
6496
|
+
span: spanType,
|
|
6497
|
+
portableText: portableTextType,
|
|
6498
|
+
inlineObjects: inlineObjectTypes,
|
|
6499
|
+
blockObjects: blockObjectTypes,
|
|
6500
|
+
annotations: spanType.annotations
|
|
6501
|
+
};
|
|
6502
|
+
}
|
|
6503
|
+
function resolveEnabledStyles(blockType) {
|
|
6504
|
+
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
6505
|
+
if (!styleField)
|
|
6506
|
+
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
6507
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
6508
|
+
if (!textStyles || textStyles.length === 0)
|
|
6509
|
+
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
6510
|
+
return textStyles;
|
|
6511
|
+
}
|
|
6512
|
+
function resolveEnabledDecorators(spanType) {
|
|
6513
|
+
return spanType.decorators;
|
|
6514
|
+
}
|
|
6515
|
+
function resolveEnabledListItems(blockType) {
|
|
6516
|
+
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
6517
|
+
if (!listField)
|
|
6518
|
+
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
6519
|
+
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
6520
|
+
if (!listItems)
|
|
6521
|
+
throw new Error("The list field need at least to be an empty array");
|
|
6522
|
+
return listItems;
|
|
6523
|
+
}
|
|
6524
|
+
function findBlockType(type) {
|
|
6525
|
+
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
6526
|
+
}
|
|
6527
|
+
function defineSchema(definition) {
|
|
6528
|
+
return definition;
|
|
6529
|
+
}
|
|
6530
|
+
const temporaryImageName = `tmp-${defaultKeyGenerator()}-image`, temporaryUrlName = `tmp-${defaultKeyGenerator()}-url`, temporaryObjectNames = {
|
|
6531
|
+
image: temporaryImageName,
|
|
6532
|
+
url: temporaryUrlName
|
|
6533
|
+
}, objectNames = {
|
|
6534
|
+
[temporaryImageName]: "image",
|
|
6535
|
+
[temporaryUrlName]: "url"
|
|
6536
|
+
}, defaultObjectTitles = {
|
|
6537
|
+
image: "Image",
|
|
6538
|
+
url: "URL"
|
|
6539
|
+
};
|
|
6540
|
+
function legacySchemaToEditorSchema(schema2) {
|
|
6541
|
+
return {
|
|
6542
|
+
annotations: schema2.annotations.map((annotation) => ({
|
|
6543
|
+
name: annotation.name,
|
|
6544
|
+
fields: annotation.fields.map((field) => ({
|
|
6545
|
+
name: field.name,
|
|
6546
|
+
type: field.type.jsonType
|
|
6547
|
+
})),
|
|
6548
|
+
title: annotation.title
|
|
6549
|
+
})),
|
|
6550
|
+
block: {
|
|
6551
|
+
name: schema2.block.name
|
|
6552
|
+
},
|
|
6553
|
+
blockObjects: schema2.blockObjects.map((blockObject) => ({
|
|
6554
|
+
name: blockObject.name,
|
|
6555
|
+
fields: blockObject.fields.map((field) => ({
|
|
6556
|
+
name: field.name,
|
|
6557
|
+
type: field.type.jsonType
|
|
6558
|
+
})),
|
|
6559
|
+
title: blockObject.title
|
|
6560
|
+
})),
|
|
6561
|
+
decorators: schema2.decorators.map((decorator) => ({
|
|
6562
|
+
name: decorator.value,
|
|
6563
|
+
title: decorator.title,
|
|
6564
|
+
value: decorator.value
|
|
6565
|
+
})),
|
|
6566
|
+
inlineObjects: schema2.inlineObjects.map((inlineObject) => ({
|
|
6567
|
+
name: inlineObject.name,
|
|
6568
|
+
fields: inlineObject.fields.map((field) => ({
|
|
6569
|
+
name: field.name,
|
|
6570
|
+
type: field.type.jsonType
|
|
6571
|
+
})),
|
|
6572
|
+
title: inlineObject.title
|
|
6573
|
+
})),
|
|
6574
|
+
span: {
|
|
6575
|
+
name: schema2.span.name
|
|
6576
|
+
},
|
|
6577
|
+
styles: schema2.styles.map((style) => ({
|
|
6578
|
+
name: style.value,
|
|
6579
|
+
title: style.title,
|
|
6580
|
+
value: style.value
|
|
6581
|
+
})),
|
|
6582
|
+
lists: schema2.lists.map((list) => ({
|
|
6583
|
+
name: list.value,
|
|
6584
|
+
title: list.title,
|
|
6585
|
+
value: list.value
|
|
6586
|
+
}))
|
|
6587
|
+
};
|
|
6588
|
+
}
|
|
6589
|
+
function compileSchemaDefinitionToLegacySchema(definition) {
|
|
6590
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
|
|
6591
|
+
type: "object",
|
|
6592
|
+
// Very naive way to work around `SanitySchema.compile` adding default
|
|
6593
|
+
// fields to objects with certain names.
|
|
6594
|
+
name: temporaryObjectNames[blockObject.name] ?? blockObject.name,
|
|
6595
|
+
title: blockObject.title === void 0 ? (
|
|
6596
|
+
// This avoids the default title which is a title case of the object name
|
|
6597
|
+
defaultObjectTitles[blockObject.name]
|
|
6598
|
+
) : blockObject.title,
|
|
6599
|
+
fields: blockObject.fields?.map((field) => ({
|
|
6600
|
+
name: field.name,
|
|
6601
|
+
type: field.type
|
|
6602
|
+
})) ?? []
|
|
6603
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
|
|
6604
|
+
type: "object",
|
|
6605
|
+
// Very naive way to work around `SanitySchema.compile` adding default
|
|
6606
|
+
// fields to objects with certain names.
|
|
6607
|
+
name: temporaryObjectNames[inlineObject.name] ?? inlineObject.name,
|
|
6608
|
+
title: inlineObject.title === void 0 ? (
|
|
6609
|
+
// This avoids the default title which is a title case of the object name
|
|
6610
|
+
defaultObjectTitles[inlineObject.name]
|
|
6611
|
+
) : inlineObject.title,
|
|
6612
|
+
fields: inlineObject.fields?.map((field) => ({
|
|
6613
|
+
name: field.name,
|
|
6614
|
+
type: field.type
|
|
6615
|
+
})) ?? []
|
|
6616
|
+
})) ?? [], portableTextSchema = types.defineField({
|
|
6617
|
+
type: "array",
|
|
6618
|
+
name: "portable-text",
|
|
6619
|
+
of: [...blockObjects.map((blockObject) => ({
|
|
6620
|
+
type: blockObject.name
|
|
6621
|
+
})), {
|
|
6622
|
+
type: "block",
|
|
6623
|
+
name: "block",
|
|
6624
|
+
of: inlineObjects.map((inlineObject) => ({
|
|
6625
|
+
type: inlineObject.name
|
|
6626
|
+
})),
|
|
6627
|
+
marks: {
|
|
6628
|
+
decorators: definition?.decorators?.map((decorator) => ({
|
|
6629
|
+
title: decorator.title ?? startCase__default.default(decorator.name),
|
|
6630
|
+
value: decorator.name
|
|
6631
|
+
})) ?? [],
|
|
6632
|
+
annotations: definition?.annotations?.map((annotation) => ({
|
|
6633
|
+
name: annotation.name,
|
|
6634
|
+
type: "object",
|
|
6635
|
+
title: annotation.title,
|
|
6636
|
+
fields: annotation.fields?.map((field) => ({
|
|
6637
|
+
name: field.name,
|
|
6638
|
+
type: field.type
|
|
6639
|
+
})) ?? []
|
|
6640
|
+
})) ?? []
|
|
6641
|
+
},
|
|
6642
|
+
lists: definition?.lists?.map((list) => ({
|
|
6643
|
+
value: list.name,
|
|
6644
|
+
title: list.title ?? startCase__default.default(list.name)
|
|
6645
|
+
})) ?? [],
|
|
6646
|
+
styles: definition?.styles?.map((style) => ({
|
|
6647
|
+
value: style.name,
|
|
6648
|
+
title: style.title ?? startCase__default.default(style.name)
|
|
6649
|
+
})) ?? []
|
|
6650
|
+
}]
|
|
6651
|
+
}), schema$1 = schema.Schema.compile({
|
|
6652
|
+
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
6653
|
+
}).get("portable-text"), pteSchema = createLegacySchema(schema$1);
|
|
6654
|
+
return {
|
|
6655
|
+
...pteSchema,
|
|
6656
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => objectNames[blockObject.name] !== void 0 ? {
|
|
6657
|
+
...blockObject,
|
|
6658
|
+
name: objectNames[blockObject.name],
|
|
6659
|
+
type: {
|
|
6660
|
+
...blockObject.type,
|
|
6661
|
+
name: objectNames[blockObject.name]
|
|
6662
|
+
}
|
|
6663
|
+
} : blockObject),
|
|
6664
|
+
inlineObjects: pteSchema.inlineObjects.map((inlineObject) => objectNames[inlineObject.name] !== void 0 ? {
|
|
6665
|
+
...inlineObject,
|
|
6666
|
+
name: objectNames[inlineObject.name]
|
|
6667
|
+
} : inlineObject)
|
|
6668
|
+
};
|
|
6669
|
+
}
|
|
6620
6670
|
function defaultCompare(a, b) {
|
|
6621
6671
|
return a === b;
|
|
6622
6672
|
}
|
|
@@ -7025,35 +7075,37 @@ function isAnnotationActive({
|
|
|
7025
7075
|
}
|
|
7026
7076
|
}
|
|
7027
7077
|
function createInternalEditor(config) {
|
|
7028
|
-
const editorActor = xstate.createActor(editorMachine, {
|
|
7029
|
-
input: editorConfigToMachineInput(
|
|
7078
|
+
const legacySchema = config.schemaDefinition ? compileSchemaDefinitionToLegacySchema(config.schemaDefinition) : createLegacySchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), editorSchema = legacySchemaToEditorSchema(legacySchema), editorActor = xstate.createActor(editorMachine, {
|
|
7079
|
+
input: editorConfigToMachineInput({
|
|
7080
|
+
...config,
|
|
7081
|
+
schema: editorSchema,
|
|
7082
|
+
legacySchema
|
|
7083
|
+
})
|
|
7030
7084
|
});
|
|
7031
|
-
return editorActor.start(), createInternalEditorFromActor(editorActor);
|
|
7085
|
+
return editorActor.start(), createInternalEditorFromActor(editorActor, legacySchema);
|
|
7032
7086
|
}
|
|
7033
7087
|
function useCreateInternalEditor(config) {
|
|
7034
|
-
const
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
}
|
|
7041
|
-
|
|
7042
|
-
let t2, t3;
|
|
7043
|
-
return $[4] !== editorActor ? (t3 = createInternalEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
7088
|
+
const legacySchema = config.schemaDefinition ? compileSchemaDefinitionToLegacySchema(config.schemaDefinition) : createLegacySchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), editorSchema = legacySchemaToEditorSchema(legacySchema), editorActor = react.useActorRef(editorMachine, {
|
|
7089
|
+
input: editorConfigToMachineInput({
|
|
7090
|
+
...config,
|
|
7091
|
+
schema: editorSchema,
|
|
7092
|
+
legacySchema
|
|
7093
|
+
})
|
|
7094
|
+
});
|
|
7095
|
+
return React.useMemo(() => createInternalEditorFromActor(editorActor, legacySchema), [editorActor, legacySchema]);
|
|
7044
7096
|
}
|
|
7045
7097
|
function editorConfigToMachineInput(config) {
|
|
7046
7098
|
return {
|
|
7047
7099
|
behaviors: config.behaviors,
|
|
7048
|
-
converters:
|
|
7100
|
+
converters: createCoreConverters(config.legacySchema),
|
|
7049
7101
|
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
7050
7102
|
maxBlocks: config.maxBlocks,
|
|
7051
7103
|
readOnly: config.readOnly,
|
|
7052
|
-
schema: config.
|
|
7104
|
+
schema: config.schema,
|
|
7053
7105
|
initialValue: config.initialValue
|
|
7054
7106
|
};
|
|
7055
7107
|
}
|
|
7056
|
-
function createInternalEditorFromActor(editorActor) {
|
|
7108
|
+
function createInternalEditorFromActor(editorActor, legacySchema) {
|
|
7057
7109
|
const slateEditor = createSlateEditor({
|
|
7058
7110
|
editorActor
|
|
7059
7111
|
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
@@ -7128,6 +7180,7 @@ function createInternalEditorFromActor(editorActor) {
|
|
|
7128
7180
|
_internal: {
|
|
7129
7181
|
editable,
|
|
7130
7182
|
editorActor,
|
|
7183
|
+
legacySchema,
|
|
7131
7184
|
slateEditor
|
|
7132
7185
|
}
|
|
7133
7186
|
};
|
|
@@ -7183,12 +7236,12 @@ class PortableTextEditor extends React.Component {
|
|
|
7183
7236
|
initialValue: props.value,
|
|
7184
7237
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
7185
7238
|
readOnly: props.readOnly
|
|
7186
|
-
}), this.schemaTypes = this.editor._internal.
|
|
7239
|
+
}), this.schemaTypes = this.editor._internal.legacySchema, this.editable = this.editor._internal.editable;
|
|
7187
7240
|
}
|
|
7188
7241
|
componentDidUpdate(prevProps) {
|
|
7189
|
-
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes =
|
|
7242
|
+
!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({
|
|
7190
7243
|
type: "update schema",
|
|
7191
|
-
schema: this.schemaTypes
|
|
7244
|
+
schema: legacySchemaToEditorSchema(this.schemaTypes)
|
|
7192
7245
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
7193
7246
|
type: "update readOnly",
|
|
7194
7247
|
readOnly: this.props.readOnly ?? !1
|