@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,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]);
|
|
@@ -3984,7 +3940,15 @@ function insertBlock({
|
|
|
3984
3940
|
}
|
|
3985
3941
|
}
|
|
3986
3942
|
}
|
|
3987
|
-
const
|
|
3943
|
+
const moveBackwardActionImplementation = ({
|
|
3944
|
+
action
|
|
3945
|
+
}) => {
|
|
3946
|
+
slate.Transforms.move(action.editor, {
|
|
3947
|
+
unit: "character",
|
|
3948
|
+
distance: action.distance,
|
|
3949
|
+
reverse: !0
|
|
3950
|
+
});
|
|
3951
|
+
}, moveBlockActionImplementation = ({
|
|
3988
3952
|
action
|
|
3989
3953
|
}) => {
|
|
3990
3954
|
const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
|
|
@@ -3993,6 +3957,13 @@ const moveBlockActionImplementation = ({
|
|
|
3993
3957
|
to,
|
|
3994
3958
|
mode: "highest"
|
|
3995
3959
|
});
|
|
3960
|
+
}, moveForwardActionImplementation = ({
|
|
3961
|
+
action
|
|
3962
|
+
}) => {
|
|
3963
|
+
slate.Transforms.move(action.editor, {
|
|
3964
|
+
unit: "character",
|
|
3965
|
+
distance: action.distance
|
|
3966
|
+
});
|
|
3996
3967
|
}, noopActionImplementation = () => {
|
|
3997
3968
|
}, selectActionImplementation = ({
|
|
3998
3969
|
action
|
|
@@ -4038,7 +4009,7 @@ const moveBlockActionImplementation = ({
|
|
|
4038
4009
|
continue;
|
|
4039
4010
|
const marks = child.marks ?? [];
|
|
4040
4011
|
for (const mark of marks)
|
|
4041
|
-
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());
|
|
4042
4013
|
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
4043
4014
|
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
4044
4015
|
marks: newMarks
|
|
@@ -4082,7 +4053,9 @@ const moveBlockActionImplementation = ({
|
|
|
4082
4053
|
"insert.span": insertSpanActionImplementation,
|
|
4083
4054
|
"insert.text": insertTextActionImplementation,
|
|
4084
4055
|
effect: effectActionImplementation,
|
|
4056
|
+
"move.backward": moveBackwardActionImplementation,
|
|
4085
4057
|
"move.block": moveBlockActionImplementation,
|
|
4058
|
+
"move.forward": moveForwardActionImplementation,
|
|
4086
4059
|
noop: noopActionImplementation,
|
|
4087
4060
|
select: selectActionImplementation,
|
|
4088
4061
|
"split.block": splitBlockActionImplementation
|
|
@@ -4225,6 +4198,13 @@ function performAction({
|
|
|
4225
4198
|
});
|
|
4226
4199
|
break;
|
|
4227
4200
|
}
|
|
4201
|
+
case "move.backward": {
|
|
4202
|
+
behaviorActionImplementations["move.backward"]({
|
|
4203
|
+
context,
|
|
4204
|
+
action
|
|
4205
|
+
});
|
|
4206
|
+
break;
|
|
4207
|
+
}
|
|
4228
4208
|
case "move.block": {
|
|
4229
4209
|
behaviorActionImplementations["move.block"]({
|
|
4230
4210
|
context,
|
|
@@ -4232,6 +4212,13 @@ function performAction({
|
|
|
4232
4212
|
});
|
|
4233
4213
|
break;
|
|
4234
4214
|
}
|
|
4215
|
+
case "move.forward": {
|
|
4216
|
+
behaviorActionImplementations["move.forward"]({
|
|
4217
|
+
context,
|
|
4218
|
+
action
|
|
4219
|
+
});
|
|
4220
|
+
break;
|
|
4221
|
+
}
|
|
4235
4222
|
case "noop":
|
|
4236
4223
|
break;
|
|
4237
4224
|
case "split.block": {
|
|
@@ -4443,7 +4430,7 @@ function createWithMaxBlocks(editorActor) {
|
|
|
4443
4430
|
}, editor;
|
|
4444
4431
|
};
|
|
4445
4432
|
}
|
|
4446
|
-
function createWithObjectKeys(editorActor
|
|
4433
|
+
function createWithObjectKeys(editorActor) {
|
|
4447
4434
|
return function(editor) {
|
|
4448
4435
|
const {
|
|
4449
4436
|
apply: apply2,
|
|
@@ -4483,7 +4470,7 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
4483
4470
|
apply2(operation);
|
|
4484
4471
|
}, editor.normalizeNode = (entry) => {
|
|
4485
4472
|
const [node, path] = entry;
|
|
4486
|
-
if (slate.Element.isElement(node) && node._type ===
|
|
4473
|
+
if (slate.Element.isElement(node) && node._type === editorActor.getSnapshot().context.schema.block.name) {
|
|
4487
4474
|
if (!node._key) {
|
|
4488
4475
|
editorActor.send({
|
|
4489
4476
|
type: "normalizing"
|
|
@@ -4515,7 +4502,7 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
4515
4502
|
};
|
|
4516
4503
|
}
|
|
4517
4504
|
const debug$9 = debugWithName("applyPatches"), debugVerbose = debug$9.enabled && !0;
|
|
4518
|
-
function createApplyPatch(
|
|
4505
|
+
function createApplyPatch(schema2) {
|
|
4519
4506
|
return (editor, patch) => {
|
|
4520
4507
|
let changed = !1;
|
|
4521
4508
|
debugVerbose && (debug$9(`
|
|
@@ -4524,7 +4511,7 @@ NEW PATCH =============================================================`), debug
|
|
|
4524
4511
|
try {
|
|
4525
4512
|
switch (patch.type) {
|
|
4526
4513
|
case "insert":
|
|
4527
|
-
changed = insertPatch(editor, patch,
|
|
4514
|
+
changed = insertPatch(editor, patch, schema2);
|
|
4528
4515
|
break;
|
|
4529
4516
|
case "unset":
|
|
4530
4517
|
changed = unsetPatch(editor, patch);
|
|
@@ -4575,7 +4562,7 @@ function diffMatchPatch(editor, patch) {
|
|
|
4575
4562
|
}) : op === DIFF_EQUAL && (offset += text.length);
|
|
4576
4563
|
return debugState(editor, "after"), !0;
|
|
4577
4564
|
}
|
|
4578
|
-
function insertPatch(editor, patch,
|
|
4565
|
+
function insertPatch(editor, patch, schema2) {
|
|
4579
4566
|
const {
|
|
4580
4567
|
block: targetBlock,
|
|
4581
4568
|
child: targetChild,
|
|
@@ -4591,7 +4578,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
4591
4578
|
items: items2,
|
|
4592
4579
|
position: position2
|
|
4593
4580
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
4594
|
-
schemaTypes
|
|
4581
|
+
schemaTypes: schema2
|
|
4595
4582
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
4596
4583
|
return debug$9(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
|
|
4597
4584
|
at: [normalizedIdx2]
|
|
@@ -4607,7 +4594,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
4607
4594
|
...targetBlock,
|
|
4608
4595
|
children: items
|
|
4609
4596
|
}], {
|
|
4610
|
-
schemaTypes
|
|
4597
|
+
schemaTypes: schema2
|
|
4611
4598
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
4612
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, {
|
|
4613
4600
|
at: childInsertPath
|
|
@@ -4785,11 +4772,10 @@ const debug$8 = debugWithName("plugin:withPatches");
|
|
|
4785
4772
|
function createWithPatches({
|
|
4786
4773
|
editorActor,
|
|
4787
4774
|
patchFunctions,
|
|
4788
|
-
schemaTypes,
|
|
4789
4775
|
subscriptions
|
|
4790
4776
|
}) {
|
|
4791
4777
|
let previousChildren;
|
|
4792
|
-
const applyPatch = createApplyPatch(
|
|
4778
|
+
const applyPatch = createApplyPatch(editorActor.getSnapshot().context.schema);
|
|
4793
4779
|
return function(editor) {
|
|
4794
4780
|
IS_PROCESSING_REMOTE_CHANGES.set(editor, !1), PATCHING.set(editor, !0), previousChildren = [...editor.children];
|
|
4795
4781
|
const {
|
|
@@ -4828,9 +4814,9 @@ function createWithPatches({
|
|
|
4828
4814
|
}), editor.apply = (operation) => {
|
|
4829
4815
|
let patches$1 = [];
|
|
4830
4816
|
previousChildren = editor.children;
|
|
4831
|
-
const editorWasEmpty = isEqualToEmptyEditor(previousChildren,
|
|
4817
|
+
const editorWasEmpty = isEqualToEmptyEditor(previousChildren, editorActor.getSnapshot().context.schema);
|
|
4832
4818
|
apply2(operation);
|
|
4833
|
-
const editorIsEmpty = isEqualToEmptyEditor(editor.children,
|
|
4819
|
+
const editorIsEmpty = isEqualToEmptyEditor(editor.children, editorActor.getSnapshot().context.schema);
|
|
4834
4820
|
if (!isPatching(editor))
|
|
4835
4821
|
return editor;
|
|
4836
4822
|
switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches$1.push(patches.insert(previousChildren, "before", [0])), operation.type) {
|
|
@@ -4861,7 +4847,7 @@ function createWithPatches({
|
|
|
4861
4847
|
}
|
|
4862
4848
|
if (!editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches$1 = [...patches$1, patches.unset([])], editorActor.send({
|
|
4863
4849
|
type: "notify.unset",
|
|
4864
|
-
previousValue: fromSlateValue(previousChildren,
|
|
4850
|
+
previousValue: fromSlateValue(previousChildren, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
|
|
4865
4851
|
})), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0)
|
|
4866
4852
|
for (const patch of patches$1)
|
|
4867
4853
|
editorActor.send({
|
|
@@ -4871,7 +4857,7 @@ function createWithPatches({
|
|
|
4871
4857
|
origin: "local"
|
|
4872
4858
|
},
|
|
4873
4859
|
actionId: getCurrentActionId(editor),
|
|
4874
|
-
value: fromSlateValue(editor.children,
|
|
4860
|
+
value: fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
|
|
4875
4861
|
});
|
|
4876
4862
|
return editor;
|
|
4877
4863
|
}, editor;
|
|
@@ -4912,8 +4898,8 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4912
4898
|
};
|
|
4913
4899
|
}
|
|
4914
4900
|
const debug$6 = debugWithName("plugin:withPortableTextBlockStyle");
|
|
4915
|
-
function createWithPortableTextBlockStyle(editorActor
|
|
4916
|
-
const defaultStyle =
|
|
4901
|
+
function createWithPortableTextBlockStyle(editorActor) {
|
|
4902
|
+
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
|
|
4917
4903
|
return function(editor) {
|
|
4918
4904
|
const {
|
|
4919
4905
|
normalizeNode
|
|
@@ -4977,11 +4963,10 @@ function createWithPortableTextSelections(editorActor) {
|
|
|
4977
4963
|
}
|
|
4978
4964
|
const debug$5 = debugWithName("plugin:withSchemaTypes");
|
|
4979
4965
|
function createWithSchemaTypes({
|
|
4980
|
-
editorActor
|
|
4981
|
-
schemaTypes
|
|
4966
|
+
editorActor
|
|
4982
4967
|
}) {
|
|
4983
4968
|
return function(editor) {
|
|
4984
|
-
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;
|
|
4985
4970
|
const {
|
|
4986
4971
|
normalizeNode
|
|
4987
4972
|
} = editor;
|
|
@@ -4994,7 +4979,7 @@ function createWithSchemaTypes({
|
|
|
4994
4979
|
type: "normalizing"
|
|
4995
4980
|
}), slate.Transforms.setNodes(editor, {
|
|
4996
4981
|
...span,
|
|
4997
|
-
_type:
|
|
4982
|
+
_type: editorActor.getSnapshot().context.schema.span.name,
|
|
4998
4983
|
_key: key
|
|
4999
4984
|
}, {
|
|
5000
4985
|
at: path
|
|
@@ -5022,14 +5007,13 @@ function createWithSchemaTypes({
|
|
|
5022
5007
|
};
|
|
5023
5008
|
}
|
|
5024
5009
|
function createWithUtils({
|
|
5025
|
-
editorActor
|
|
5026
|
-
schemaTypes
|
|
5010
|
+
editorActor
|
|
5027
5011
|
}) {
|
|
5028
5012
|
return function(editor) {
|
|
5029
5013
|
return editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
5030
|
-
_type:
|
|
5014
|
+
_type: editorActor.getSnapshot().context.schema.block.name,
|
|
5031
5015
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5032
|
-
style:
|
|
5016
|
+
style: editorActor.getSnapshot().context.schema.styles[0].name || "normal",
|
|
5033
5017
|
...options.listItem ? {
|
|
5034
5018
|
listItem: options.listItem
|
|
5035
5019
|
} : {},
|
|
@@ -5041,33 +5025,29 @@ function createWithUtils({
|
|
|
5041
5025
|
_type: "span",
|
|
5042
5026
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5043
5027
|
text: "",
|
|
5044
|
-
marks: options.decorators.filter((decorator) =>
|
|
5045
|
-
|
|
5046
|
-
}) =>
|
|
5028
|
+
marks: options.decorators.filter((decorator) => editorActor.getSnapshot().context.schema.decorators.find(({
|
|
5029
|
+
name
|
|
5030
|
+
}) => name === decorator))
|
|
5047
5031
|
}]
|
|
5048
5032
|
}], {
|
|
5049
|
-
schemaTypes
|
|
5033
|
+
schemaTypes: editorActor.getSnapshot().context.schema
|
|
5050
5034
|
})[0], editor;
|
|
5051
5035
|
};
|
|
5052
5036
|
}
|
|
5053
5037
|
const withPlugins = (editor, options) => {
|
|
5054
5038
|
const e = editor, {
|
|
5055
5039
|
editorActor
|
|
5056
|
-
} = options,
|
|
5057
|
-
editorActor
|
|
5058
|
-
schemaTypes
|
|
5040
|
+
} = options, operationToPatches = createOperationToPatches(editorActor), withObjectKeys = createWithObjectKeys(editorActor), withSchemaTypes = createWithSchemaTypes({
|
|
5041
|
+
editorActor
|
|
5059
5042
|
}), withPatches = createWithPatches({
|
|
5060
5043
|
editorActor,
|
|
5061
5044
|
patchFunctions: operationToPatches,
|
|
5062
|
-
schemaTypes,
|
|
5063
5045
|
subscriptions: options.subscriptions
|
|
5064
5046
|
}), withMaxBlocks = createWithMaxBlocks(editorActor), withUndoRedo = createWithUndoRedo({
|
|
5065
5047
|
editorActor,
|
|
5066
|
-
blockSchemaType: schemaTypes.block,
|
|
5067
5048
|
subscriptions: options.subscriptions
|
|
5068
|
-
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor
|
|
5069
|
-
editorActor
|
|
5070
|
-
schemaTypes
|
|
5049
|
+
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5050
|
+
editorActor
|
|
5071
5051
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
5072
5052
|
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5073
5053
|
}, debug$4 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
@@ -5091,100 +5071,6 @@ function createSlateEditor(config) {
|
|
|
5091
5071
|
};
|
|
5092
5072
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
5093
5073
|
}
|
|
5094
|
-
function defineSchema(definition) {
|
|
5095
|
-
return definition;
|
|
5096
|
-
}
|
|
5097
|
-
const temporaryImageName = `tmp-${defaultKeyGenerator()}-image`, temporaryUrlName = `tmp-${defaultKeyGenerator()}-url`, temporaryObjectNames = {
|
|
5098
|
-
image: temporaryImageName,
|
|
5099
|
-
url: temporaryUrlName
|
|
5100
|
-
}, objectNames = {
|
|
5101
|
-
[temporaryImageName]: "image",
|
|
5102
|
-
[temporaryUrlName]: "url"
|
|
5103
|
-
}, defaultObjectTitles = {
|
|
5104
|
-
image: "Image",
|
|
5105
|
-
url: "URL"
|
|
5106
|
-
};
|
|
5107
|
-
function compileSchemaDefinition(definition) {
|
|
5108
|
-
const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
|
|
5109
|
-
type: "object",
|
|
5110
|
-
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5111
|
-
// fields to objects with certain names.
|
|
5112
|
-
name: temporaryObjectNames[blockObject.name] ?? blockObject.name,
|
|
5113
|
-
title: blockObject.title === void 0 ? (
|
|
5114
|
-
// This avoids the default title which is a title case of the object name
|
|
5115
|
-
defaultObjectTitles[blockObject.name]
|
|
5116
|
-
) : blockObject.title,
|
|
5117
|
-
fields: blockObject.fields?.map((field) => ({
|
|
5118
|
-
name: field.name,
|
|
5119
|
-
type: field.type
|
|
5120
|
-
})) ?? []
|
|
5121
|
-
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
|
|
5122
|
-
type: "object",
|
|
5123
|
-
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5124
|
-
// fields to objects with certain names.
|
|
5125
|
-
name: temporaryObjectNames[inlineObject.name] ?? inlineObject.name,
|
|
5126
|
-
title: inlineObject.title === void 0 ? (
|
|
5127
|
-
// This avoids the default title which is a title case of the object name
|
|
5128
|
-
defaultObjectTitles[inlineObject.name]
|
|
5129
|
-
) : inlineObject.title,
|
|
5130
|
-
fields: inlineObject.fields?.map((field) => ({
|
|
5131
|
-
name: field.name,
|
|
5132
|
-
type: field.type
|
|
5133
|
-
})) ?? []
|
|
5134
|
-
})) ?? [], portableTextSchema = types.defineField({
|
|
5135
|
-
type: "array",
|
|
5136
|
-
name: "portable-text",
|
|
5137
|
-
of: [...blockObjects.map((blockObject) => ({
|
|
5138
|
-
type: blockObject.name
|
|
5139
|
-
})), {
|
|
5140
|
-
type: "block",
|
|
5141
|
-
name: "block",
|
|
5142
|
-
of: inlineObjects.map((inlineObject) => ({
|
|
5143
|
-
type: inlineObject.name
|
|
5144
|
-
})),
|
|
5145
|
-
marks: {
|
|
5146
|
-
decorators: definition?.decorators?.map((decorator) => ({
|
|
5147
|
-
title: decorator.title ?? startCase__default.default(decorator.name),
|
|
5148
|
-
value: decorator.name
|
|
5149
|
-
})) ?? [],
|
|
5150
|
-
annotations: definition?.annotations?.map((annotation) => ({
|
|
5151
|
-
name: annotation.name,
|
|
5152
|
-
type: "object",
|
|
5153
|
-
title: annotation.title,
|
|
5154
|
-
fields: annotation.fields?.map((field) => ({
|
|
5155
|
-
name: field.name,
|
|
5156
|
-
type: field.type
|
|
5157
|
-
})) ?? []
|
|
5158
|
-
})) ?? []
|
|
5159
|
-
},
|
|
5160
|
-
lists: definition?.lists?.map((list) => ({
|
|
5161
|
-
value: list.name,
|
|
5162
|
-
title: list.title ?? startCase__default.default(list.name)
|
|
5163
|
-
})) ?? [],
|
|
5164
|
-
styles: definition?.styles?.map((style) => ({
|
|
5165
|
-
value: style.name,
|
|
5166
|
-
title: style.title ?? startCase__default.default(style.name)
|
|
5167
|
-
})) ?? []
|
|
5168
|
-
}]
|
|
5169
|
-
}), schema$1 = schema.Schema.compile({
|
|
5170
|
-
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
5171
|
-
}).get("portable-text"), pteSchema = createEditorSchema(schema$1);
|
|
5172
|
-
return {
|
|
5173
|
-
...pteSchema,
|
|
5174
|
-
blockObjects: pteSchema.blockObjects.map((blockObject) => objectNames[blockObject.name] !== void 0 ? {
|
|
5175
|
-
...blockObject,
|
|
5176
|
-
name: objectNames[blockObject.name],
|
|
5177
|
-
type: {
|
|
5178
|
-
...blockObject.type,
|
|
5179
|
-
name: objectNames[blockObject.name]
|
|
5180
|
-
}
|
|
5181
|
-
} : blockObject),
|
|
5182
|
-
inlineObjects: pteSchema.inlineObjects.map((inlineObject) => objectNames[inlineObject.name] !== void 0 ? {
|
|
5183
|
-
...inlineObject,
|
|
5184
|
-
name: objectNames[inlineObject.name]
|
|
5185
|
-
} : inlineObject)
|
|
5186
|
-
};
|
|
5187
|
-
}
|
|
5188
5074
|
const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
5189
5075
|
on: "annotation.toggle",
|
|
5190
5076
|
guard: ({
|
|
@@ -6161,7 +6047,7 @@ function getActiveDecorators({
|
|
|
6161
6047
|
schema: schema2,
|
|
6162
6048
|
slateEditorInstance
|
|
6163
6049
|
}) {
|
|
6164
|
-
const decorators = schema2.decorators.map((decorator) => decorator.
|
|
6050
|
+
const decorators = schema2.decorators.map((decorator) => decorator.name);
|
|
6165
6051
|
return ({
|
|
6166
6052
|
...slate.Editor.marks(slateEditorInstance) ?? {}
|
|
6167
6053
|
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
@@ -6586,6 +6472,201 @@ const editorMachine = xstate.setup({
|
|
|
6586
6472
|
}
|
|
6587
6473
|
}
|
|
6588
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
|
+
}
|
|
6589
6670
|
function defaultCompare(a, b) {
|
|
6590
6671
|
return a === b;
|
|
6591
6672
|
}
|
|
@@ -6994,35 +7075,37 @@ function isAnnotationActive({
|
|
|
6994
7075
|
}
|
|
6995
7076
|
}
|
|
6996
7077
|
function createInternalEditor(config) {
|
|
6997
|
-
const editorActor = xstate.createActor(editorMachine, {
|
|
6998
|
-
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
|
+
})
|
|
6999
7084
|
});
|
|
7000
|
-
return editorActor.start(), createInternalEditorFromActor(editorActor);
|
|
7085
|
+
return editorActor.start(), createInternalEditorFromActor(editorActor, legacySchema);
|
|
7001
7086
|
}
|
|
7002
7087
|
function useCreateInternalEditor(config) {
|
|
7003
|
-
const
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
}
|
|
7010
|
-
|
|
7011
|
-
let t2, t3;
|
|
7012
|
-
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]);
|
|
7013
7096
|
}
|
|
7014
7097
|
function editorConfigToMachineInput(config) {
|
|
7015
7098
|
return {
|
|
7016
7099
|
behaviors: config.behaviors,
|
|
7017
|
-
converters:
|
|
7100
|
+
converters: createCoreConverters(config.legacySchema),
|
|
7018
7101
|
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
7019
7102
|
maxBlocks: config.maxBlocks,
|
|
7020
7103
|
readOnly: config.readOnly,
|
|
7021
|
-
schema: config.
|
|
7104
|
+
schema: config.schema,
|
|
7022
7105
|
initialValue: config.initialValue
|
|
7023
7106
|
};
|
|
7024
7107
|
}
|
|
7025
|
-
function createInternalEditorFromActor(editorActor) {
|
|
7108
|
+
function createInternalEditorFromActor(editorActor, legacySchema) {
|
|
7026
7109
|
const slateEditor = createSlateEditor({
|
|
7027
7110
|
editorActor
|
|
7028
7111
|
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
@@ -7097,6 +7180,7 @@ function createInternalEditorFromActor(editorActor) {
|
|
|
7097
7180
|
_internal: {
|
|
7098
7181
|
editable,
|
|
7099
7182
|
editorActor,
|
|
7183
|
+
legacySchema,
|
|
7100
7184
|
slateEditor
|
|
7101
7185
|
}
|
|
7102
7186
|
};
|
|
@@ -7152,12 +7236,12 @@ class PortableTextEditor extends React.Component {
|
|
|
7152
7236
|
initialValue: props.value,
|
|
7153
7237
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
7154
7238
|
readOnly: props.readOnly
|
|
7155
|
-
}), this.schemaTypes = this.editor._internal.
|
|
7239
|
+
}), this.schemaTypes = this.editor._internal.legacySchema, this.editable = this.editor._internal.editable;
|
|
7156
7240
|
}
|
|
7157
7241
|
componentDidUpdate(prevProps) {
|
|
7158
|
-
!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({
|
|
7159
7243
|
type: "update schema",
|
|
7160
|
-
schema: this.schemaTypes
|
|
7244
|
+
schema: legacySchemaToEditorSchema(this.schemaTypes)
|
|
7161
7245
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
7162
7246
|
type: "update readOnly",
|
|
7163
7247
|
readOnly: this.props.readOnly ?? !1
|