@portabletext/editor 1.55.1 → 1.55.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/index.cjs +44 -35
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +45 -36
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/create-slate-editor.tsx +11 -6
- package/src/editor/plugins/slate-plugin.update-value.ts +10 -3
- package/src/internal-utils/build-index-maps.test.ts +133 -89
- package/src/internal-utils/build-index-maps.ts +20 -14
- package/src/internal-utils/paths.ts +46 -23
- package/src/internal-utils/ranges.ts +4 -0
package/lib/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), selectionPoint = require("./_chunks-cjs/selection-point.cjs"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"),
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), selectionPoint = require("./_chunks-cjs/selection-point.cjs"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), types = require("@sanity/types"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -520,24 +520,31 @@ function getSlateRangeFromEvent(editor, event) {
|
|
|
520
520
|
return range;
|
|
521
521
|
}
|
|
522
522
|
function toSlatePath(path, editor) {
|
|
523
|
-
|
|
523
|
+
const blockKey = selectionPoint.getBlockKeyFromSelectionPoint({
|
|
524
|
+
path
|
|
525
|
+
});
|
|
526
|
+
if (!blockKey)
|
|
524
527
|
return [];
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
528
|
+
const blockIndex = editor.blockIndexMap.get(blockKey);
|
|
529
|
+
if (blockIndex === void 0)
|
|
530
|
+
return [];
|
|
531
|
+
const block = editor.children.at(blockIndex);
|
|
529
532
|
if (!block || !slate.Element.isElement(block))
|
|
530
533
|
return [];
|
|
531
534
|
if (editor.isVoid(block))
|
|
532
|
-
return [
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
if (
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
535
|
+
return [blockIndex, 0];
|
|
536
|
+
const childKey = selectionPoint.getChildKeyFromSelectionPoint({
|
|
537
|
+
path
|
|
538
|
+
});
|
|
539
|
+
if (!childKey)
|
|
540
|
+
return [blockIndex, 0];
|
|
541
|
+
let childPath = [], childIndex = -1;
|
|
542
|
+
for (const child of block.children)
|
|
543
|
+
if (childIndex++, child._key === childKey) {
|
|
544
|
+
slate.Element.isElement(child) && editor.isVoid(child) ? childPath = [childIndex, 0] : childPath = [childIndex];
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
return [blockIndex].concat(childPath);
|
|
541
548
|
}
|
|
542
549
|
function toSlateRange(selection, editor) {
|
|
543
550
|
if (!selection || !editor)
|
|
@@ -1276,11 +1283,15 @@ function compileType(rawType) {
|
|
|
1276
1283
|
types: [rawType]
|
|
1277
1284
|
}).get(rawType.name);
|
|
1278
1285
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1286
|
+
const levelIndexMap = /* @__PURE__ */ new Map();
|
|
1287
|
+
function buildIndexMaps(context, {
|
|
1288
|
+
blockIndexMap,
|
|
1289
|
+
listIndexMap
|
|
1290
|
+
}) {
|
|
1291
|
+
blockIndexMap.clear(), listIndexMap.clear(), levelIndexMap.clear();
|
|
1281
1292
|
let previousListItem;
|
|
1282
|
-
for (let blockIndex = 0; blockIndex < value.length; blockIndex++) {
|
|
1283
|
-
const block = value.at(blockIndex);
|
|
1293
|
+
for (let blockIndex = 0; blockIndex < context.value.length; blockIndex++) {
|
|
1294
|
+
const block = context.value.at(blockIndex);
|
|
1284
1295
|
if (block !== void 0) {
|
|
1285
1296
|
if (blockIndexMap.set(block._key, blockIndex), !selectionPoint.isTextBlock(context, block)) {
|
|
1286
1297
|
levelIndexMap.clear(), previousListItem = void 0;
|
|
@@ -1328,10 +1339,6 @@ function buildIndexMaps(context, value) {
|
|
|
1328
1339
|
}
|
|
1329
1340
|
}
|
|
1330
1341
|
}
|
|
1331
|
-
return {
|
|
1332
|
-
blockIndexMap,
|
|
1333
|
-
listIndexMap
|
|
1334
|
-
};
|
|
1335
1342
|
}
|
|
1336
1343
|
function createPlaceholderBlock(context) {
|
|
1337
1344
|
return {
|
|
@@ -5204,12 +5211,13 @@ function pluginUpdateValue(context, editor) {
|
|
|
5204
5211
|
apply2(operation);
|
|
5205
5212
|
return;
|
|
5206
5213
|
}
|
|
5207
|
-
editor.value = applyOperationToPortableText(context, editor.value, operation)
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5214
|
+
editor.value = applyOperationToPortableText(context, editor.value, operation), buildIndexMaps({
|
|
5215
|
+
schema: context.schema,
|
|
5216
|
+
value: editor.value
|
|
5217
|
+
}, {
|
|
5218
|
+
blockIndexMap: editor.blockIndexMap,
|
|
5219
|
+
listIndexMap: editor.listIndexMap
|
|
5220
|
+
}), apply2(operation);
|
|
5213
5221
|
}, editor;
|
|
5214
5222
|
}
|
|
5215
5223
|
const withPlugins = (editor, options) => {
|
|
@@ -5242,12 +5250,13 @@ function createSlateEditor(config) {
|
|
|
5242
5250
|
});
|
|
5243
5251
|
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.decoratedRanges = [], instance.decoratorState = {}, instance.markState = void 0;
|
|
5244
5252
|
const placeholderBlock = createPlaceholderBlock(config.editorActor.getSnapshot().context);
|
|
5245
|
-
instance.value = [placeholderBlock]
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5253
|
+
instance.value = [placeholderBlock], instance.blockIndexMap = /* @__PURE__ */ new Map(), instance.listIndexMap = /* @__PURE__ */ new Map(), buildIndexMaps({
|
|
5254
|
+
schema: config.editorActor.getSnapshot().context.schema,
|
|
5255
|
+
value: instance.value
|
|
5256
|
+
}, {
|
|
5257
|
+
blockIndexMap: instance.blockIndexMap,
|
|
5258
|
+
listIndexMap: instance.listIndexMap
|
|
5259
|
+
});
|
|
5251
5260
|
const initialValue = toSlateValue(instance.value, {
|
|
5252
5261
|
schemaTypes: config.editorActor.getSnapshot().context.schema
|
|
5253
5262
|
});
|