@portabletext/editor 3.3.6 → 3.3.7
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.js
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
3
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
4
|
-
import noop from "lodash/noop.js";
|
|
5
4
|
import { createContext, useContext, useEffect, useState, useRef, forwardRef, Component, startTransition } from "react";
|
|
6
5
|
import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transforms, Operation, deleteText, createEditor } from "slate";
|
|
7
6
|
import { useSelected, useSlateSelector, useSlateStatic, ReactEditor, useSlate, Editable, withReact, Slate } from "slate-react";
|
|
8
7
|
import debug$h from "debug";
|
|
9
8
|
import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION, IS_FOCUSED, IS_READ_ONLY } from "slate-dom";
|
|
10
|
-
import { getBlockEndPoint, getBlockStartPoint, getBlockKeyFromSelectionPoint, isSelectionCollapsed, isEqualSelectionPoints, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject,
|
|
11
|
-
import isEqual from "lodash/isEqual.js";
|
|
9
|
+
import { getBlockEndPoint, getBlockStartPoint, getBlockKeyFromSelectionPoint, isSelectionCollapsed, isKeyedSegment, isEqualSelectionPoints, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint } from "./_chunks-es/util.slice-blocks.js";
|
|
12
10
|
import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
|
|
13
11
|
import { defineSchema } from "@portabletext/schema";
|
|
14
12
|
import { isEmptyTextBlock, sliceTextBlock, getTextBlockText } from "./_chunks-es/util.slice-text-block.js";
|
|
15
13
|
import { getFocusInlineObject, isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, getFocusBlock as getFocusBlock$1, isSelectingEntireBlocks, getSelectedValue, getActiveDecorators, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getFocusChild as getFocusChild$1, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
|
|
16
14
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
17
|
-
import uniq from "lodash/uniq.js";
|
|
18
15
|
import { setup, fromCallback, assign, and, enqueueActions, emit, assertEvent, raise as raise$1, not, createActor } from "xstate";
|
|
19
16
|
import { compileSchemaDefinitionToPortableTextMemberSchemaTypes, createPortableTextMemberSchemaTypes, portableTextMemberSchemaTypesToSchema } from "@portabletext/sanity-bridge";
|
|
20
17
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
21
18
|
import { toHTML } from "@portabletext/to-html";
|
|
22
19
|
import { markdownToPortableText, portableTextToMarkdown } from "@portabletext/markdown";
|
|
23
20
|
import { Schema } from "@sanity/schema";
|
|
24
|
-
import flatten from "lodash/flatten.js";
|
|
25
21
|
import { set, applyAll, unset, insert, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
26
22
|
import { createKeyboardShortcut, code, underline, italic, bold, undo, redo } from "@portabletext/keyboard-shortcuts";
|
|
27
|
-
import isPlainObject from "lodash/isPlainObject.js";
|
|
28
23
|
import { EditorContext } from "./_chunks-es/use-editor.js";
|
|
29
24
|
import { useEditor } from "./_chunks-es/use-editor.js";
|
|
30
25
|
import { Subject } from "rxjs";
|
|
@@ -34,10 +29,144 @@ function debugWithName(name) {
|
|
|
34
29
|
const namespace = `${rootName}${name}`;
|
|
35
30
|
return debug$h && debug$h.enabled(namespace) ? debug$h(namespace) : debug$h(rootName);
|
|
36
31
|
}
|
|
32
|
+
function isEqualValues(context, a, b) {
|
|
33
|
+
if (!a || !b)
|
|
34
|
+
return a === b;
|
|
35
|
+
if (a.length !== b.length)
|
|
36
|
+
return !1;
|
|
37
|
+
for (let index = 0; index < a.length; index++) {
|
|
38
|
+
const blockA = a.at(index), blockB = b.at(index);
|
|
39
|
+
if (!blockA || !blockB || !isEqualBlocks(context, blockA, blockB))
|
|
40
|
+
return !1;
|
|
41
|
+
}
|
|
42
|
+
return !0;
|
|
43
|
+
}
|
|
44
|
+
function isEqualBlocks(context, a, b) {
|
|
45
|
+
return a._type !== b._type ? !1 : a._type === context.schema.block.name && b._type === context.schema.block.name ? isEqualTextBlocks(context, a, b) : isEqualPortableTextObjects(a, b);
|
|
46
|
+
}
|
|
47
|
+
function isEqualTextBlocks(context, a, b) {
|
|
48
|
+
return !isTextBlock(context, a) || !isTextBlock(context, b) || a._key !== b._key || a.style !== b.style || a.listItem !== b.listItem || a.level !== b.level || "markDefs" in a && "markDefs" in b && (!Array.isArray(a.markDefs) || !Array.isArray(b.markDefs) || !isEqualMarkDefs(a.markDefs, b.markDefs)) || !isEqualChildren(a.children, b.children) ? !1 : isEqualProps(a, b, ["_key", "_type", "style", "listItem", "level", "markDefs", "children"]);
|
|
49
|
+
}
|
|
50
|
+
function isEqualProps(a, b, excludeKeys) {
|
|
51
|
+
const keysA = Object.keys(a).filter((key) => !excludeKeys.includes(key)), keysB = Object.keys(b).filter((key) => !excludeKeys.includes(key));
|
|
52
|
+
if (keysA.length !== keysB.length)
|
|
53
|
+
return !1;
|
|
54
|
+
for (const key of keysA) {
|
|
55
|
+
if (!(key in a) || !(key in b))
|
|
56
|
+
return !1;
|
|
57
|
+
const valueA = a[key], valueB = b[key];
|
|
58
|
+
if (valueA !== valueB && !isDeepEqual(valueA, valueB))
|
|
59
|
+
return !1;
|
|
60
|
+
}
|
|
61
|
+
return !0;
|
|
62
|
+
}
|
|
63
|
+
function isEqualInlineObjects(a, b) {
|
|
64
|
+
return a._key !== b._key || a._type !== b._type ? !1 : isEqualProps(a, b, ["_key", "_type"]);
|
|
65
|
+
}
|
|
66
|
+
function isEqualMarks(a, b) {
|
|
67
|
+
if (!a || !b)
|
|
68
|
+
return a === b;
|
|
69
|
+
if (a.length !== b.length)
|
|
70
|
+
return !1;
|
|
71
|
+
for (let index = 0; index < a.length; index++)
|
|
72
|
+
if (a.at(index) !== b.at(index))
|
|
73
|
+
return !1;
|
|
74
|
+
return !0;
|
|
75
|
+
}
|
|
76
|
+
function isEqualSpans(a, b) {
|
|
77
|
+
return a._key !== b._key || a._type !== b._type || a.text !== b.text || !isEqualMarks(a.marks, b.marks) ? !1 : isEqualProps(a, b, ["_key", "_type", "text", "marks"]);
|
|
78
|
+
}
|
|
79
|
+
function isEqualMarkDefs(a, b) {
|
|
80
|
+
if (a.length !== b.length)
|
|
81
|
+
return !1;
|
|
82
|
+
for (let index = 0; index < a.length; index++) {
|
|
83
|
+
const markDefA = a.at(index), markDefB = b.at(index);
|
|
84
|
+
if (!markDefA || !markDefB || !isDeepEqual(markDefA, markDefB))
|
|
85
|
+
return !1;
|
|
86
|
+
}
|
|
87
|
+
return !0;
|
|
88
|
+
}
|
|
89
|
+
function isEqualChildren(a, b) {
|
|
90
|
+
if (a.length !== b.length)
|
|
91
|
+
return !1;
|
|
92
|
+
for (let index = 0; index < a.length; index++) {
|
|
93
|
+
const childA = a.at(index), childB = b.at(index);
|
|
94
|
+
if (!childA || !childB || !isEqualChild(childA, childB))
|
|
95
|
+
return !1;
|
|
96
|
+
}
|
|
97
|
+
return !0;
|
|
98
|
+
}
|
|
99
|
+
function isEqualChild(a, b) {
|
|
100
|
+
return a._type === "span" && b._type === "span" ? isEqualSpans(a, b) : isEqualInlineObjects(a, b);
|
|
101
|
+
}
|
|
102
|
+
function isEqualPortableTextObjects(a, b) {
|
|
103
|
+
return a._key !== b._key || a._type !== b._type ? !1 : isEqualProps(a, b, ["_key", "_type"]);
|
|
104
|
+
}
|
|
105
|
+
function isDeepEqual(data, other) {
|
|
106
|
+
return isDeepEqualImplementation(data, other);
|
|
107
|
+
}
|
|
108
|
+
function isDeepEqualImplementation(data, other) {
|
|
109
|
+
if (data === other || Object.is(data, other))
|
|
110
|
+
return !0;
|
|
111
|
+
if (typeof data != "object" || typeof other != "object" || data === null || other === null || Object.getPrototypeOf(data) !== Object.getPrototypeOf(other))
|
|
112
|
+
return !1;
|
|
113
|
+
if (Array.isArray(data))
|
|
114
|
+
return isDeepEqualArrays(data, other);
|
|
115
|
+
if (data instanceof Map)
|
|
116
|
+
return isDeepEqualMaps(data, other);
|
|
117
|
+
if (data instanceof Set)
|
|
118
|
+
return isDeepEqualSets(data, other);
|
|
119
|
+
if (data instanceof Date)
|
|
120
|
+
return data.getTime() === other.getTime();
|
|
121
|
+
if (data instanceof RegExp)
|
|
122
|
+
return data.toString() === other.toString();
|
|
123
|
+
if (Object.keys(data).length !== Object.keys(other).length)
|
|
124
|
+
return !1;
|
|
125
|
+
for (const [key, value] of Object.entries(data))
|
|
126
|
+
if (!(key in other) || !isDeepEqualImplementation(
|
|
127
|
+
value,
|
|
128
|
+
// @ts-expect-error [ts7053] - We already checked that `other` has `key`
|
|
129
|
+
other[key]
|
|
130
|
+
))
|
|
131
|
+
return !1;
|
|
132
|
+
return !0;
|
|
133
|
+
}
|
|
134
|
+
function isDeepEqualArrays(data, other) {
|
|
135
|
+
if (data.length !== other.length)
|
|
136
|
+
return !1;
|
|
137
|
+
for (const [index, item] of data.entries())
|
|
138
|
+
if (!isDeepEqualImplementation(item, other[index]))
|
|
139
|
+
return !1;
|
|
140
|
+
return !0;
|
|
141
|
+
}
|
|
142
|
+
function isDeepEqualMaps(data, other) {
|
|
143
|
+
if (data.size !== other.size)
|
|
144
|
+
return !1;
|
|
145
|
+
for (const [key, value] of data.entries())
|
|
146
|
+
if (!other.has(key) || !isDeepEqualImplementation(value, other.get(key)))
|
|
147
|
+
return !1;
|
|
148
|
+
return !0;
|
|
149
|
+
}
|
|
150
|
+
function isDeepEqualSets(data, other) {
|
|
151
|
+
if (data.size !== other.size)
|
|
152
|
+
return !1;
|
|
153
|
+
const otherCopy = [...other];
|
|
154
|
+
for (const dataItem of data) {
|
|
155
|
+
let isFound = !1;
|
|
156
|
+
for (const [index, otherItem] of otherCopy.entries())
|
|
157
|
+
if (isDeepEqualImplementation(dataItem, otherItem)) {
|
|
158
|
+
isFound = !0, otherCopy.splice(index, 1);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
if (!isFound)
|
|
162
|
+
return !1;
|
|
163
|
+
}
|
|
164
|
+
return !0;
|
|
165
|
+
}
|
|
37
166
|
const VOID_CHILD_KEY = "void-child";
|
|
38
|
-
function keepObjectEquality(object, keyMap) {
|
|
167
|
+
function keepObjectEquality(context, object, keyMap) {
|
|
39
168
|
const value = keyMap[object._key];
|
|
40
|
-
return value &&
|
|
169
|
+
return value && isEqualBlocks(context, object, value) ? value : (keyMap[object._key] = object, object);
|
|
41
170
|
}
|
|
42
171
|
function toSlateBlock(block, {
|
|
43
172
|
schemaTypes
|
|
@@ -61,6 +190,8 @@ function toSlateBlock(block, {
|
|
|
61
190
|
_type: schemaTypes.span.name,
|
|
62
191
|
text: childProps.text
|
|
63
192
|
} : childType !== schemaTypes.span.name ? (hasInlines = !0, keepObjectEquality({
|
|
193
|
+
schema: schemaTypes
|
|
194
|
+
}, {
|
|
64
195
|
_type: childType,
|
|
65
196
|
_key: childKey,
|
|
66
197
|
children: [{
|
|
@@ -74,6 +205,8 @@ function toSlateBlock(block, {
|
|
|
74
205
|
}, keyMap)) : child;
|
|
75
206
|
});
|
|
76
207
|
return !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : keepObjectEquality({
|
|
208
|
+
schema: schemaTypes
|
|
209
|
+
}, {
|
|
77
210
|
_type,
|
|
78
211
|
_key,
|
|
79
212
|
...rest,
|
|
@@ -81,6 +214,8 @@ function toSlateBlock(block, {
|
|
|
81
214
|
}, keyMap);
|
|
82
215
|
}
|
|
83
216
|
return keepObjectEquality({
|
|
217
|
+
schema: schemaTypes
|
|
218
|
+
}, {
|
|
84
219
|
_type,
|
|
85
220
|
_key,
|
|
86
221
|
children: [{
|
|
@@ -92,7 +227,7 @@ function toSlateBlock(block, {
|
|
|
92
227
|
value: rest
|
|
93
228
|
}, keyMap);
|
|
94
229
|
}
|
|
95
|
-
function fromSlateBlock(block, textBlockType, keyMap = {}) {
|
|
230
|
+
function fromSlateBlock(context, block, textBlockType, keyMap = {}) {
|
|
96
231
|
const {
|
|
97
232
|
_key,
|
|
98
233
|
_type
|
|
@@ -115,7 +250,7 @@ function fromSlateBlock(block, textBlockType, keyMap = {}) {
|
|
|
115
250
|
children: _c,
|
|
116
251
|
...rest
|
|
117
252
|
} = child;
|
|
118
|
-
return keepObjectEquality({
|
|
253
|
+
return keepObjectEquality(context, {
|
|
119
254
|
...rest,
|
|
120
255
|
...v,
|
|
121
256
|
_key: k,
|
|
@@ -124,7 +259,7 @@ function fromSlateBlock(block, textBlockType, keyMap = {}) {
|
|
|
124
259
|
}
|
|
125
260
|
return child;
|
|
126
261
|
});
|
|
127
|
-
return hasInlines ? keepObjectEquality({
|
|
262
|
+
return hasInlines ? keepObjectEquality(context, {
|
|
128
263
|
...block,
|
|
129
264
|
children,
|
|
130
265
|
_key,
|
|
@@ -132,7 +267,7 @@ function fromSlateBlock(block, textBlockType, keyMap = {}) {
|
|
|
132
267
|
}, keyMap) : block;
|
|
133
268
|
}
|
|
134
269
|
const blockValue = "value" in block && block.value;
|
|
135
|
-
return keepObjectEquality({
|
|
270
|
+
return keepObjectEquality(context, {
|
|
136
271
|
_key,
|
|
137
272
|
_type,
|
|
138
273
|
...typeof blockValue == "object" ? blockValue : {}
|
|
@@ -147,7 +282,9 @@ function isEqualToEmptyEditor(initialValue, blocks, schemaTypes) {
|
|
|
147
282
|
if (!Element$1.isElement(firstBlock) || firstBlock._type !== schemaTypes.block.name || "listItem" in firstBlock || !("style" in firstBlock) || firstBlock.style !== schemaTypes.styles.at(0)?.name || !Array.isArray(firstBlock.children) || firstBlock.children.length !== 1)
|
|
148
283
|
return !1;
|
|
149
284
|
const firstChild = firstBlock.children.at(0);
|
|
150
|
-
return !(!firstChild || !Text.isText(firstChild) || !("_type" in firstChild) || firstChild._type !== schemaTypes.span.name || firstChild.text !== "" || firstChild.marks?.join("") || Object.keys(firstBlock).some((key) => key !== "_type" && key !== "_key" && key !== "children" && key !== "markDefs" && key !== "style") ||
|
|
285
|
+
return !(!firstChild || !Text.isText(firstChild) || !("_type" in firstChild) || firstChild._type !== schemaTypes.span.name || firstChild.text !== "" || firstChild.marks?.join("") || Object.keys(firstBlock).some((key) => key !== "_type" && key !== "_key" && key !== "children" && key !== "markDefs" && key !== "style") || isEqualValues({
|
|
286
|
+
schema: schemaTypes
|
|
287
|
+
}, initialValue, [firstBlock]));
|
|
151
288
|
}
|
|
152
289
|
function getFocusBlock({
|
|
153
290
|
editor
|
|
@@ -280,7 +417,9 @@ function elementToBlock({
|
|
|
280
417
|
schema,
|
|
281
418
|
element
|
|
282
419
|
}) {
|
|
283
|
-
return fromSlateBlock(
|
|
420
|
+
return fromSlateBlock({
|
|
421
|
+
schema
|
|
422
|
+
}, element, schema.block.name);
|
|
284
423
|
}
|
|
285
424
|
function isBlockElement({
|
|
286
425
|
editor,
|
|
@@ -609,11 +748,7 @@ function normalizeSelection(selection, value) {
|
|
|
609
748
|
anchor,
|
|
610
749
|
focus
|
|
611
750
|
} = selection;
|
|
612
|
-
return anchor && value.find((blk) =>
|
|
613
|
-
_key: blk._key
|
|
614
|
-
}, anchor.path[0])) && (newAnchor = normalizePoint(anchor, value)), focus && value.find((blk) => isEqual({
|
|
615
|
-
_key: blk._key
|
|
616
|
-
}, focus.path[0])) && (newFocus = normalizePoint(focus, value)), newAnchor && newFocus ? {
|
|
751
|
+
return anchor && value.find((blk) => isKeyedSegment(anchor.path[0]) && blk._key === anchor.path[0]._key) && (newAnchor = normalizePoint(anchor, value)), focus && value.find((blk) => isKeyedSegment(focus.path[0]) && blk._key === focus.path[0]._key) && (newFocus = normalizePoint(focus, value)), newAnchor && newFocus ? {
|
|
617
752
|
anchor: newAnchor,
|
|
618
753
|
focus: newFocus,
|
|
619
754
|
backward: selection.backward
|
|
@@ -1330,7 +1465,7 @@ function RenderSpan(props) {
|
|
|
1330
1465
|
const path = t2;
|
|
1331
1466
|
let annotationMarkDefs, children;
|
|
1332
1467
|
if ($[11] !== block_0 || $[12] !== editorActor || $[13] !== focused || $[14] !== legacySchema || $[15] !== path || $[16] !== props.children || $[17] !== props.leaf.marks || $[18] !== props.renderAnnotation || $[19] !== props.renderDecorator || $[20] !== selected) {
|
|
1333
|
-
const decoratorSchemaTypes = editorActor.getSnapshot().context.schema.decorators.map(_temp2$1), decorators =
|
|
1468
|
+
const decoratorSchemaTypes = editorActor.getSnapshot().context.schema.decorators.map(_temp2$1), decorators = [...new Set((props.leaf.marks ?? []).filter((mark) => decoratorSchemaTypes.includes(mark)))];
|
|
1334
1469
|
annotationMarkDefs = (props.leaf.marks ?? []).flatMap((mark_0) => {
|
|
1335
1470
|
if (decoratorSchemaTypes.includes(mark_0))
|
|
1336
1471
|
return [];
|
|
@@ -1823,7 +1958,7 @@ const slateOperationCallback = ({
|
|
|
1823
1958
|
focus: rangeDecoration.selection?.focus,
|
|
1824
1959
|
payload: rangeDecoration.payload
|
|
1825
1960
|
}));
|
|
1826
|
-
return !
|
|
1961
|
+
return !isDeepEqual(existingRangeDecorations, newRangeDecorations);
|
|
1827
1962
|
},
|
|
1828
1963
|
"not read only": ({
|
|
1829
1964
|
context
|
|
@@ -2598,6 +2733,8 @@ const debug$e = debugWithName("component:Editable"), PortableTextEditable = forw
|
|
|
2598
2733
|
return $[151] !== callbackRef || $[152] !== decorate || $[153] !== handleClick || $[154] !== handleCopy || $[155] !== handleCut || $[156] !== handleDrag || $[157] !== handleDragEnd || $[158] !== handleDragEnter || $[159] !== handleDragLeave || $[160] !== handleDragOver || $[161] !== handleDragStart || $[162] !== handleDrop || $[163] !== handleKeyDown || $[164] !== handleKeyUp || $[165] !== handleOnBeforeInput || $[166] !== handleOnBlur || $[167] !== handleOnFocus || $[168] !== handlePaste || $[169] !== hasInvalidValue || $[170] !== readOnly || $[171] !== renderElement || $[172] !== renderLeaf || $[173] !== restProps || $[174] !== scrollSelectionIntoViewToSlate ? (t39 = hasInvalidValue ? null : /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderPlaceholder: void 0, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToSlate }), $[151] = callbackRef, $[152] = decorate, $[153] = handleClick, $[154] = handleCopy, $[155] = handleCut, $[156] = handleDrag, $[157] = handleDragEnd, $[158] = handleDragEnter, $[159] = handleDragLeave, $[160] = handleDragOver, $[161] = handleDragStart, $[162] = handleDrop, $[163] = handleKeyDown, $[164] = handleKeyUp, $[165] = handleOnBeforeInput, $[166] = handleOnBlur, $[167] = handleOnFocus, $[168] = handlePaste, $[169] = hasInvalidValue, $[170] = readOnly, $[171] = renderElement, $[172] = renderLeaf, $[173] = restProps, $[174] = scrollSelectionIntoViewToSlate, $[175] = t39) : t39 = $[175], t39;
|
|
2599
2734
|
});
|
|
2600
2735
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
2736
|
+
function noop() {
|
|
2737
|
+
}
|
|
2601
2738
|
function _temp(s) {
|
|
2602
2739
|
return s.matches({
|
|
2603
2740
|
"edit mode": "read only"
|
|
@@ -3321,7 +3458,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3321
3458
|
}
|
|
3322
3459
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3323
3460
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3324
|
-
if (node.markDefs && !
|
|
3461
|
+
if (node.markDefs && !isEqualMarkDefs(newMarkDefs, node.markDefs)) {
|
|
3325
3462
|
debug$c("Removing markDef not in use"), withNormalizeNode(editor, () => {
|
|
3326
3463
|
Transforms.setNodes(editor, {
|
|
3327
3464
|
markDefs: newMarkDefs
|
|
@@ -3415,7 +3552,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3415
3552
|
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) {
|
|
3416
3553
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
3417
3554
|
if (editor.isTextBlock(targetBlock)) {
|
|
3418
|
-
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs =
|
|
3555
|
+
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = [...new Map([...oldDefs, ...op.properties.markDefs].map((def) => [def._key, def])).values()];
|
|
3419
3556
|
debug$c("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
3420
3557
|
markDefs: newMarkDefs
|
|
3421
3558
|
}, {
|
|
@@ -4118,24 +4255,18 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
4118
4255
|
...operation
|
|
4119
4256
|
};
|
|
4120
4257
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
4121
|
-
const insertBlockIndex = (snapshot || []).findIndex((blk) =>
|
|
4122
|
-
_key: blk._key
|
|
4123
|
-
}, patch.path[0]));
|
|
4258
|
+
const pathSegment = patch.path[0], insertBlockIndex = (snapshot || []).findIndex((blk) => isKeyedSegment(pathSegment) && blk._key === pathSegment._key);
|
|
4124
4259
|
return debug$b(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
4125
4260
|
}
|
|
4126
4261
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
4127
|
-
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) =>
|
|
4128
|
-
_key: blk._key
|
|
4129
|
-
}, patch.path[0]));
|
|
4262
|
+
const pathSegment = patch.path[0], unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isKeyedSegment(pathSegment) && blk._key === pathSegment._key);
|
|
4130
4263
|
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$b("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
4131
4264
|
}
|
|
4132
4265
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
4133
4266
|
return debug$b(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
4134
4267
|
if (patch.type === "diffMatchPatch") {
|
|
4135
|
-
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
4136
|
-
return !operationTargetBlock || !
|
|
4137
|
-
_key: operationTargetBlock._key
|
|
4138
|
-
}, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
4268
|
+
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation), pathSegment = patch.path[0];
|
|
4269
|
+
return !operationTargetBlock || !isKeyedSegment(pathSegment) || operationTargetBlock._key !== pathSegment._key ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
4139
4270
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
|
|
4140
4271
|
const {
|
|
4141
4272
|
diffs
|
|
@@ -4213,7 +4344,7 @@ const debug$a = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4213
4344
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
4214
4345
|
let transformedOperations = step.operations;
|
|
4215
4346
|
otherPatches.forEach((item) => {
|
|
4216
|
-
transformedOperations =
|
|
4347
|
+
transformedOperations = transformedOperations.flatMap((op) => transformOperation(editor, item.patch, op, item.snapshot, item.previousSnapshot));
|
|
4217
4348
|
});
|
|
4218
4349
|
try {
|
|
4219
4350
|
Editor.withoutNormalizing(editor, () => {
|
|
@@ -4247,7 +4378,7 @@ const debug$a = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4247
4378
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
4248
4379
|
let transformedOperations = step.operations;
|
|
4249
4380
|
otherPatches.forEach((item) => {
|
|
4250
|
-
transformedOperations =
|
|
4381
|
+
transformedOperations = transformedOperations.flatMap((op) => transformOperation(editor, item.patch, op, item.snapshot, item.previousSnapshot));
|
|
4251
4382
|
});
|
|
4252
4383
|
const reversedOperations = transformedOperations.map(Operation.inverse).reverse();
|
|
4253
4384
|
try {
|
|
@@ -4995,7 +5126,7 @@ function insertBlock(options) {
|
|
|
4995
5126
|
}), adjustedChildren = block.children.map((child) => {
|
|
4996
5127
|
if (isSpan(context, child)) {
|
|
4997
5128
|
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
4998
|
-
if (!
|
|
5129
|
+
if (!isEqualMarks(child.marks, marks))
|
|
4999
5130
|
return {
|
|
5000
5131
|
...child,
|
|
5001
5132
|
_key: endBlockChildKeys.includes(child._key) ? context.keyGenerator() : child._key,
|
|
@@ -5012,7 +5143,7 @@ function insertBlock(options) {
|
|
|
5012
5143
|
}, {
|
|
5013
5144
|
at: endBlockPath
|
|
5014
5145
|
});
|
|
5015
|
-
const adjustedBlock =
|
|
5146
|
+
const adjustedBlock = isEqualChildren(block.children, adjustedChildren) ? block : {
|
|
5016
5147
|
...block,
|
|
5017
5148
|
children: adjustedChildren
|
|
5018
5149
|
};
|
|
@@ -5711,7 +5842,7 @@ function createWithObjectKeys(editorActor) {
|
|
|
5711
5842
|
for (const child of block.children) {
|
|
5712
5843
|
if (isSpan(editorActor.getSnapshot().context, child)) {
|
|
5713
5844
|
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
5714
|
-
|
|
5845
|
+
isEqualMarks(child.marks, marks) || Transforms.setNodes(editor, {
|
|
5715
5846
|
marks
|
|
5716
5847
|
}, {
|
|
5717
5848
|
at: [index, childIndex]
|
|
@@ -6285,9 +6416,13 @@ function insertNodePatch(schema, children, operation, beforeValue) {
|
|
|
6285
6416
|
const block = beforeValue[operation.path[0]];
|
|
6286
6417
|
if (operation.path.length === 1) {
|
|
6287
6418
|
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
|
|
6288
|
-
return targetKey ? [insert([fromSlateBlock(
|
|
6419
|
+
return targetKey ? [insert([fromSlateBlock({
|
|
6420
|
+
schema
|
|
6421
|
+
}, operation.node, schema.block.name)], position, [{
|
|
6289
6422
|
_key: targetKey
|
|
6290
|
-
}])] : [setIfMissing(beforeValue, []), insert([fromSlateBlock(
|
|
6423
|
+
}])] : [setIfMissing(beforeValue, []), insert([fromSlateBlock({
|
|
6424
|
+
schema
|
|
6425
|
+
}, operation.node, schema.block.name)], "before", [operation.path[0]])];
|
|
6291
6426
|
} else if (isTextBlock({
|
|
6292
6427
|
schema
|
|
6293
6428
|
}, block) && operation.path.length === 2 && children[operation.path[0]]) {
|
|
@@ -6320,7 +6455,9 @@ function splitNodePatch(schema, children, operation, beforeValue) {
|
|
|
6320
6455
|
if (isTextBlock({
|
|
6321
6456
|
schema
|
|
6322
6457
|
}, oldBlock)) {
|
|
6323
|
-
const targetValue = fromSlateBlock(
|
|
6458
|
+
const targetValue = fromSlateBlock({
|
|
6459
|
+
schema
|
|
6460
|
+
}, children[operation.path[0] + 1], schema.block.name);
|
|
6324
6461
|
targetValue && (patches.push(insert([targetValue], "after", [{
|
|
6325
6462
|
_key: splitBlock._key
|
|
6326
6463
|
}])), oldBlock.children.slice(operation.position).forEach((span) => {
|
|
@@ -6340,6 +6477,8 @@ function splitNodePatch(schema, children, operation, beforeValue) {
|
|
|
6340
6477
|
schema
|
|
6341
6478
|
}, splitSpan)) {
|
|
6342
6479
|
const targetSpans = fromSlateBlock({
|
|
6480
|
+
schema
|
|
6481
|
+
}, {
|
|
6343
6482
|
...splitBlock,
|
|
6344
6483
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
6345
6484
|
}, schema.block.name).children;
|
|
@@ -6381,7 +6520,9 @@ function mergeNodePatch(schema, children, operation, beforeValue) {
|
|
|
6381
6520
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = children[operation.path[0]];
|
|
6382
6521
|
if (operation.path.length === 1)
|
|
6383
6522
|
if (block?._key) {
|
|
6384
|
-
const newBlock = fromSlateBlock(
|
|
6523
|
+
const newBlock = fromSlateBlock({
|
|
6524
|
+
schema
|
|
6525
|
+
}, children[operation.path[0] - 1], schema.block.name);
|
|
6385
6526
|
patches.push(set(newBlock, [{
|
|
6386
6527
|
_key: newBlock._key
|
|
6387
6528
|
}])), patches.push(unset([{
|
|
@@ -11486,7 +11627,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
11486
11627
|
},
|
|
11487
11628
|
value
|
|
11488
11629
|
} : (value.some((blk, index) => {
|
|
11489
|
-
if (
|
|
11630
|
+
if (typeof blk != "object" || blk === null)
|
|
11490
11631
|
return resolution = {
|
|
11491
11632
|
patches: [unset([index])],
|
|
11492
11633
|
description: `Block must be an object, got ${String(blk)}`,
|
|
@@ -11640,11 +11781,11 @@ function validateValue(value, types, keyGenerator) {
|
|
|
11640
11781
|
}
|
|
11641
11782
|
}, !0;
|
|
11642
11783
|
}
|
|
11643
|
-
const allUsedMarks =
|
|
11784
|
+
const allUsedMarks = [...new Set(textBlock.children.filter((child) => isSpan({
|
|
11644
11785
|
schema: types
|
|
11645
|
-
}, child)).
|
|
11786
|
+
}, child)).flatMap((cld) => cld.marks || []))];
|
|
11646
11787
|
if (Array.isArray(blk.markDefs) && blk.markDefs.length > 0) {
|
|
11647
|
-
const unusedMarkDefs =
|
|
11788
|
+
const unusedMarkDefs = [...new Set(blk.markDefs.map((def) => def._key).filter((key) => !allUsedMarks.includes(key)))];
|
|
11648
11789
|
if (unusedMarkDefs.length > 0)
|
|
11649
11790
|
return resolution = {
|
|
11650
11791
|
autoResolve: !0,
|
|
@@ -11693,7 +11834,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
11693
11834
|
}
|
|
11694
11835
|
}
|
|
11695
11836
|
textBlock.children.some((child, cIndex) => {
|
|
11696
|
-
if (
|
|
11837
|
+
if (typeof child != "object" || child === null)
|
|
11697
11838
|
return resolution = {
|
|
11698
11839
|
patches: [unset([{
|
|
11699
11840
|
_key: blk._key
|
|
@@ -11875,7 +12016,9 @@ const debug$2 = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
11875
12016
|
}) => (assertEvent(event, "done syncing"), context.pendingValue !== event.value),
|
|
11876
12017
|
"pending value equals previous value": ({
|
|
11877
12018
|
context
|
|
11878
|
-
}) =>
|
|
12019
|
+
}) => isEqualValues({
|
|
12020
|
+
schema: context.schema
|
|
12021
|
+
}, context.pendingValue, context.previousValue)
|
|
11879
12022
|
},
|
|
11880
12023
|
actors: {
|
|
11881
12024
|
"sync value": syncValueLogic
|
|
@@ -12233,7 +12376,7 @@ function syncBlock({
|
|
|
12233
12376
|
blockValid: !1
|
|
12234
12377
|
};
|
|
12235
12378
|
}
|
|
12236
|
-
if (
|
|
12379
|
+
if (isEqualBlocks(context, block, oldBlock))
|
|
12237
12380
|
return {
|
|
12238
12381
|
blockChanged: !1,
|
|
12239
12382
|
blockValid: !0
|
|
@@ -12314,7 +12457,7 @@ function updateBlock({
|
|
|
12314
12457
|
at: [index2, childIndex]
|
|
12315
12458
|
}));
|
|
12316
12459
|
}), slateBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
12317
|
-
const oldBlockChild = oldBlock.children
|
|
12460
|
+
const oldBlockChild = oldBlock.children.at(currentBlockChildIndex), isChildChanged = oldBlockChild && !isEqualChild(currentBlockChild, oldBlockChild), isTextChanged = oldBlockChild && Text.isText(oldBlockChild) && currentBlockChild.text !== oldBlockChild.text, path = [index, currentBlockChildIndex];
|
|
12318
12461
|
if (isChildChanged)
|
|
12319
12462
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
12320
12463
|
debug$2("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|