@portabletext/editor 1.16.4 → 1.17.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/README.md +1 -1
- package/lib/_chunks-cjs/behavior.core.cjs +5 -12
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -10
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs +1 -4
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +5 -12
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +3 -10
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-collapsed.js +1 -4
- package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -1
- package/lib/behaviors/index.cjs +318 -37
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +46 -0
- package/lib/behaviors/index.d.ts +46 -0
- package/lib/behaviors/index.js +320 -38
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +745 -1153
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +745 -1153
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +7 -19
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +7 -19
- package/lib/selectors/index.js.map +1 -1
- package/package.json +11 -11
- package/src/behaviors/behavior.emoji-picker.ts +416 -0
- package/src/behaviors/index.ts +4 -0
package/lib/index.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
|
|
5
|
-
for (var prop in b || (b = {}))
|
|
6
|
-
__hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
7
|
-
if (__getOwnPropSymbols)
|
|
8
|
-
for (var prop of __getOwnPropSymbols(b))
|
|
9
|
-
__propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
10
|
-
return a;
|
|
11
|
-
};
|
|
12
1
|
import { Schema } from "@sanity/schema";
|
|
13
2
|
import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
|
|
14
3
|
import startCase from "lodash.startcase";
|
|
@@ -37,13 +26,12 @@ import { blockOffsetToSpanSelectionPoint, coreBehaviors, isHotkey } from "./_chu
|
|
|
37
26
|
import getRandomValues from "get-random-values-esm";
|
|
38
27
|
import { htmlToBlocks, normalizeBlock } from "@sanity/block-tools";
|
|
39
28
|
function createEditorSchema(portableTextType) {
|
|
40
|
-
var _a, _b, _c;
|
|
41
29
|
if (!portableTextType)
|
|
42
30
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
43
|
-
const blockType =
|
|
31
|
+
const blockType = portableTextType.of?.find(findBlockType);
|
|
44
32
|
if (!blockType)
|
|
45
33
|
throw new Error("Block type is not defined in this schema (required)");
|
|
46
|
-
const childrenField =
|
|
34
|
+
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
47
35
|
if (!childrenField)
|
|
48
36
|
throw new Error("Children field for block type found in schema (required)");
|
|
49
37
|
const ofType = childrenField.type.of;
|
|
@@ -52,7 +40,7 @@ function createEditorSchema(portableTextType) {
|
|
|
52
40
|
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
53
41
|
if (!spanType)
|
|
54
42
|
throw new Error("Span type not found in schema (required)");
|
|
55
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes =
|
|
43
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
56
44
|
return {
|
|
57
45
|
styles: resolveEnabledStyles(blockType),
|
|
58
46
|
decorators: resolveEnabledDecorators(spanType),
|
|
@@ -66,11 +54,10 @@ function createEditorSchema(portableTextType) {
|
|
|
66
54
|
};
|
|
67
55
|
}
|
|
68
56
|
function resolveEnabledStyles(blockType) {
|
|
69
|
-
|
|
70
|
-
const styleField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "style");
|
|
57
|
+
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
71
58
|
if (!styleField)
|
|
72
59
|
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
73
|
-
const textStyles =
|
|
60
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
74
61
|
if (!textStyles || textStyles.length === 0)
|
|
75
62
|
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
76
63
|
return textStyles;
|
|
@@ -79,11 +66,10 @@ function resolveEnabledDecorators(spanType) {
|
|
|
79
66
|
return spanType.decorators;
|
|
80
67
|
}
|
|
81
68
|
function resolveEnabledListItems(blockType) {
|
|
82
|
-
|
|
83
|
-
const listField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "listItem");
|
|
69
|
+
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
84
70
|
if (!listField)
|
|
85
71
|
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
86
|
-
const listItems =
|
|
72
|
+
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
87
73
|
if (!listItems)
|
|
88
74
|
throw new Error("The list field need at least to be an empty array");
|
|
89
75
|
return listItems;
|
|
@@ -91,20 +77,11 @@ function resolveEnabledListItems(blockType) {
|
|
|
91
77
|
function findBlockType(type) {
|
|
92
78
|
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
93
79
|
}
|
|
94
|
-
var __defProp$q = Object.defineProperty, __defProps$j = Object.defineProperties, __getOwnPropDescs$j = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$q = Object.getOwnPropertySymbols, __hasOwnProp$q = Object.prototype.hasOwnProperty, __propIsEnum$q = Object.prototype.propertyIsEnumerable, __defNormalProp$q = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$q = (a, b) => {
|
|
95
|
-
for (var prop in b || (b = {}))
|
|
96
|
-
__hasOwnProp$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
|
|
97
|
-
if (__getOwnPropSymbols$q)
|
|
98
|
-
for (var prop of __getOwnPropSymbols$q(b))
|
|
99
|
-
__propIsEnum$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
|
|
100
|
-
return a;
|
|
101
|
-
}, __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
|
|
102
80
|
function defineSchema(definition) {
|
|
103
81
|
return definition;
|
|
104
82
|
}
|
|
105
83
|
function compileSchemaDefinition(definition) {
|
|
106
|
-
|
|
107
|
-
const blockObjects = (_b = (_a = definition == null ? void 0 : definition.blockObjects) == null ? void 0 : _a.map((blockObject) => defineType({
|
|
84
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => defineType({
|
|
108
85
|
type: "object",
|
|
109
86
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
110
87
|
// fields to objects with the name `image`
|
|
@@ -112,13 +89,13 @@ function compileSchemaDefinition(definition) {
|
|
|
112
89
|
title: blockObject.title,
|
|
113
90
|
icon: blockObject.icon,
|
|
114
91
|
fields: []
|
|
115
|
-
}))
|
|
92
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => defineType({
|
|
116
93
|
type: "object",
|
|
117
94
|
name: inlineObject.name,
|
|
118
95
|
title: inlineObject.title,
|
|
119
96
|
icon: inlineObject.icon,
|
|
120
97
|
fields: []
|
|
121
|
-
}))
|
|
98
|
+
})) ?? [], portableTextSchema = defineField({
|
|
122
99
|
type: "array",
|
|
123
100
|
name: "portable-text",
|
|
124
101
|
of: [...blockObjects.map((blockObject) => ({
|
|
@@ -130,49 +107,43 @@ function compileSchemaDefinition(definition) {
|
|
|
130
107
|
type: inlineObject.name
|
|
131
108
|
})),
|
|
132
109
|
marks: {
|
|
133
|
-
decorators:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
})) != null ? _f : [],
|
|
141
|
-
annotations: (_h = (_g = definition == null ? void 0 : definition.annotations) == null ? void 0 : _g.map((annotation) => ({
|
|
110
|
+
decorators: definition?.decorators?.map((decorator) => ({
|
|
111
|
+
title: decorator.title ?? startCase(decorator.name),
|
|
112
|
+
value: decorator.name,
|
|
113
|
+
icon: decorator.icon
|
|
114
|
+
})) ?? [],
|
|
115
|
+
annotations: definition?.annotations?.map((annotation) => ({
|
|
142
116
|
name: annotation.name,
|
|
143
117
|
type: "object",
|
|
144
118
|
title: annotation.title,
|
|
145
119
|
icon: annotation.icon
|
|
146
|
-
}))
|
|
120
|
+
})) ?? []
|
|
147
121
|
},
|
|
148
|
-
lists:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return {
|
|
159
|
-
value: style.name,
|
|
160
|
-
title: (_a2 = style.title) != null ? _a2 : startCase(style.name),
|
|
161
|
-
icon: style.icon
|
|
162
|
-
};
|
|
163
|
-
})) != null ? _l : []
|
|
122
|
+
lists: definition?.lists?.map((list) => ({
|
|
123
|
+
value: list.name,
|
|
124
|
+
title: list.title ?? startCase(list.name),
|
|
125
|
+
icon: list.icon
|
|
126
|
+
})) ?? [],
|
|
127
|
+
styles: definition?.styles?.map((style) => ({
|
|
128
|
+
value: style.name,
|
|
129
|
+
title: style.title ?? startCase(style.name),
|
|
130
|
+
icon: style.icon
|
|
131
|
+
})) ?? []
|
|
164
132
|
}]
|
|
165
133
|
}), schema = Schema.compile({
|
|
166
134
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
167
135
|
}).get("portable-text"), pteSchema = createEditorSchema(schema);
|
|
168
|
-
return
|
|
169
|
-
|
|
136
|
+
return {
|
|
137
|
+
...pteSchema,
|
|
138
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
|
|
139
|
+
...blockObject,
|
|
170
140
|
name: "image",
|
|
171
|
-
type:
|
|
141
|
+
type: {
|
|
142
|
+
...blockObject.type,
|
|
172
143
|
name: "image"
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
144
|
+
}
|
|
145
|
+
} : blockObject)
|
|
146
|
+
};
|
|
176
147
|
}
|
|
177
148
|
const rootName = "sanity-pte:";
|
|
178
149
|
debug$l(rootName);
|
|
@@ -307,22 +278,6 @@ function normalizeSelection(selection, value) {
|
|
|
307
278
|
backward: selection.backward
|
|
308
279
|
} : null;
|
|
309
280
|
}
|
|
310
|
-
var __defProp$p = Object.defineProperty, __defProps$i = Object.defineProperties, __getOwnPropDescs$i = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$p = Object.getOwnPropertySymbols, __hasOwnProp$p = Object.prototype.hasOwnProperty, __propIsEnum$p = Object.prototype.propertyIsEnumerable, __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$p = (a, b) => {
|
|
311
|
-
for (var prop in b || (b = {}))
|
|
312
|
-
__hasOwnProp$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
313
|
-
if (__getOwnPropSymbols$p)
|
|
314
|
-
for (var prop of __getOwnPropSymbols$p(b))
|
|
315
|
-
__propIsEnum$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
316
|
-
return a;
|
|
317
|
-
}, __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b)), __objRest$3 = (source, exclude) => {
|
|
318
|
-
var target = {};
|
|
319
|
-
for (var prop in source)
|
|
320
|
-
__hasOwnProp$p.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
321
|
-
if (source != null && __getOwnPropSymbols$p)
|
|
322
|
-
for (var prop of __getOwnPropSymbols$p(source))
|
|
323
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$p.call(source, prop) && (target[prop] = source[prop]);
|
|
324
|
-
return target;
|
|
325
|
-
};
|
|
326
281
|
const VOID_CHILD_KEY = "void-child";
|
|
327
282
|
function keepObjectEquality(object, keyMap) {
|
|
328
283
|
const value = keyMap[object._key];
|
|
@@ -332,13 +287,11 @@ function toSlateValue(value, {
|
|
|
332
287
|
schemaTypes
|
|
333
288
|
}, keyMap = {}) {
|
|
334
289
|
return value && Array.isArray(value) ? value.map((block) => {
|
|
335
|
-
const
|
|
290
|
+
const {
|
|
336
291
|
_type,
|
|
337
|
-
_key
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
"_key"
|
|
341
|
-
]), voidChildren = [{
|
|
292
|
+
_key,
|
|
293
|
+
...rest
|
|
294
|
+
} = block, voidChildren = [{
|
|
342
295
|
_key: VOID_CHILD_KEY,
|
|
343
296
|
_type: "span",
|
|
344
297
|
text: "",
|
|
@@ -348,13 +301,11 @@ function toSlateValue(value, {
|
|
|
348
301
|
const textBlock = block;
|
|
349
302
|
let hasInlines = !1;
|
|
350
303
|
const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
|
|
351
|
-
const
|
|
304
|
+
const {
|
|
352
305
|
_type: cType,
|
|
353
|
-
_key: cKey
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
"_key"
|
|
357
|
-
]);
|
|
306
|
+
_key: cKey,
|
|
307
|
+
...cRest
|
|
308
|
+
} = child;
|
|
358
309
|
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
359
310
|
_type: cType,
|
|
360
311
|
_key: cKey,
|
|
@@ -363,12 +314,12 @@ function toSlateValue(value, {
|
|
|
363
314
|
__inline: !0
|
|
364
315
|
}, keyMap)) : child;
|
|
365
316
|
});
|
|
366
|
-
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(
|
|
317
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality({
|
|
367
318
|
_type,
|
|
368
|
-
_key
|
|
369
|
-
|
|
319
|
+
_key,
|
|
320
|
+
...rest,
|
|
370
321
|
children
|
|
371
|
-
}
|
|
322
|
+
}, keyMap));
|
|
372
323
|
}
|
|
373
324
|
return keepObjectEquality({
|
|
374
325
|
_type,
|
|
@@ -394,42 +345,40 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
394
345
|
} = child;
|
|
395
346
|
if ("value" in child && _cType !== "span") {
|
|
396
347
|
hasInlines = !0;
|
|
397
|
-
const
|
|
348
|
+
const {
|
|
398
349
|
value: v,
|
|
399
350
|
_key: k,
|
|
400
351
|
_type: t,
|
|
401
352
|
__inline: _i,
|
|
402
|
-
children: _c
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
"children"
|
|
409
|
-
]);
|
|
410
|
-
return keepObjectEquality(__spreadProps$i(__spreadValues$p(__spreadValues$p({}, rest), v), {
|
|
353
|
+
children: _c,
|
|
354
|
+
...rest
|
|
355
|
+
} = child;
|
|
356
|
+
return keepObjectEquality({
|
|
357
|
+
...rest,
|
|
358
|
+
...v,
|
|
411
359
|
_key: k,
|
|
412
360
|
_type: t
|
|
413
|
-
}
|
|
361
|
+
}, keyMap);
|
|
414
362
|
}
|
|
415
363
|
return child;
|
|
416
364
|
});
|
|
417
|
-
return hasInlines ? keepObjectEquality(
|
|
365
|
+
return hasInlines ? keepObjectEquality({
|
|
366
|
+
...block,
|
|
418
367
|
children,
|
|
419
368
|
_key,
|
|
420
369
|
_type
|
|
421
|
-
}
|
|
370
|
+
}, keyMap) : block;
|
|
422
371
|
}
|
|
423
372
|
const blockValue = "value" in block && block.value;
|
|
424
|
-
return keepObjectEquality(
|
|
373
|
+
return keepObjectEquality({
|
|
425
374
|
_key,
|
|
426
|
-
_type
|
|
427
|
-
|
|
375
|
+
_type,
|
|
376
|
+
...typeof blockValue == "object" ? blockValue : {}
|
|
377
|
+
}, keyMap);
|
|
428
378
|
});
|
|
429
379
|
}
|
|
430
380
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
431
|
-
|
|
432
|
-
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element$1.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !((_a = children[0].children[0].marks) != null && _a.join("")) && children[0].children[0].text === "";
|
|
381
|
+
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element$1.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
433
382
|
}
|
|
434
383
|
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__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(), DefaultObject = (props) => {
|
|
435
384
|
const $ = c(4);
|
|
@@ -729,14 +678,6 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
729
678
|
] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
|
|
730
679
|
};
|
|
731
680
|
DraggableBlock.displayName = "DraggableBlock";
|
|
732
|
-
var __defProp$o = Object.defineProperty, __defProps$h = Object.defineProperties, __getOwnPropDescs$h = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$o = Object.getOwnPropertySymbols, __hasOwnProp$o = Object.prototype.hasOwnProperty, __propIsEnum$o = Object.prototype.propertyIsEnumerable, __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$o = (a, b) => {
|
|
733
|
-
for (var prop in b || (b = {}))
|
|
734
|
-
__hasOwnProp$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
735
|
-
if (__getOwnPropSymbols$o)
|
|
736
|
-
for (var prop of __getOwnPropSymbols$o(b))
|
|
737
|
-
__propIsEnum$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
738
|
-
return a;
|
|
739
|
-
}, __spreadProps$h = (a, b) => __defProps$h(a, __getOwnPropDescs$h(b));
|
|
740
681
|
debugWithName("components:Element");
|
|
741
682
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
742
683
|
display: "inline-block"
|
|
@@ -773,7 +714,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
773
714
|
}, "children", {
|
|
774
715
|
_key: element._key
|
|
775
716
|
}];
|
|
776
|
-
return /* @__PURE__ */ jsxs("span",
|
|
717
|
+
return /* @__PURE__ */ jsxs("span", { ...attributes, children: [
|
|
777
718
|
children,
|
|
778
719
|
/* @__PURE__ */ jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
|
|
779
720
|
renderChild && renderChild({
|
|
@@ -790,7 +731,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
790
731
|
}),
|
|
791
732
|
!renderChild && /* @__PURE__ */ jsx(DefaultObject, { value })
|
|
792
733
|
] }, element._key)
|
|
793
|
-
] })
|
|
734
|
+
] });
|
|
794
735
|
}
|
|
795
736
|
throw new Error("Block not found!");
|
|
796
737
|
}
|
|
@@ -841,7 +782,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
841
782
|
return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
|
|
842
783
|
}
|
|
843
784
|
}), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
|
|
844
|
-
return /* @__PURE__ */ jsx("div",
|
|
785
|
+
return /* @__PURE__ */ jsx("div", { ...attributes, className, spellCheck, children: /* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }, element._key);
|
|
845
786
|
}
|
|
846
787
|
const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
|
|
847
788
|
if (!schemaType_0)
|
|
@@ -866,13 +807,13 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
866
807
|
});
|
|
867
808
|
renderedBlockFromProps = renderBlock(_props);
|
|
868
809
|
}
|
|
869
|
-
return /* @__PURE__ */ jsxs("div",
|
|
810
|
+
return /* @__PURE__ */ jsxs("div", { ...attributes, className, children: [
|
|
870
811
|
children,
|
|
871
812
|
/* @__PURE__ */ jsxs(DraggableBlock, { element, readOnly, blockRef, children: [
|
|
872
813
|
renderedBlockFromProps && /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
|
|
873
814
|
!renderedBlockFromProps && /* @__PURE__ */ jsx(DefaultBlockObject, { selected, children: /* @__PURE__ */ jsx(DefaultObject, { value }) })
|
|
874
815
|
] })
|
|
875
|
-
] }
|
|
816
|
+
] }, element._key);
|
|
876
817
|
};
|
|
877
818
|
Element.displayName = "Element";
|
|
878
819
|
const PortableTextEditorContext = createContext(null), usePortableTextEditor = () => {
|
|
@@ -971,14 +912,6 @@ const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3,
|
|
|
971
912
|
}
|
|
972
913
|
}
|
|
973
914
|
});
|
|
974
|
-
var __defProp$n = Object.defineProperty, __defProps$g = Object.defineProperties, __getOwnPropDescs$g = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$n = Object.getOwnPropertySymbols, __hasOwnProp$n = Object.prototype.hasOwnProperty, __propIsEnum$n = Object.prototype.propertyIsEnumerable, __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$n = (a, b) => {
|
|
975
|
-
for (var prop in b || (b = {}))
|
|
976
|
-
__hasOwnProp$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
977
|
-
if (__getOwnPropSymbols$n)
|
|
978
|
-
for (var prop of __getOwnPropSymbols$n(b))
|
|
979
|
-
__propIsEnum$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
980
|
-
return a;
|
|
981
|
-
}, __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
|
|
982
915
|
function validateValue(value, types, keyGenerator) {
|
|
983
916
|
let resolution = null, valid = !0;
|
|
984
917
|
const validChildTypes = [types.span.name, ...types.inlineObjects.map((t) => t.name)], validBlockTypes = [types.block.name, ...types.blockObjects.map((t) => t.name)];
|
|
@@ -1016,9 +949,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1016
949
|
}, !0;
|
|
1017
950
|
if (!blk._key || typeof blk._key != "string")
|
|
1018
951
|
return resolution = {
|
|
1019
|
-
patches: [set(
|
|
952
|
+
patches: [set({
|
|
953
|
+
...blk,
|
|
1020
954
|
_key: keyGenerator()
|
|
1021
|
-
}
|
|
955
|
+
}, [index])],
|
|
1022
956
|
description: `Block at index ${index} is missing required _key.`,
|
|
1023
957
|
action: "Set the block with a random _key value",
|
|
1024
958
|
item: blk,
|
|
@@ -1034,9 +968,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1034
968
|
if (blk._type === "block") {
|
|
1035
969
|
const currentBlockTypeName = types.block.name;
|
|
1036
970
|
return resolution = {
|
|
1037
|
-
patches: [set(
|
|
971
|
+
patches: [set({
|
|
972
|
+
...blk,
|
|
1038
973
|
_type: currentBlockTypeName
|
|
1039
|
-
}
|
|
974
|
+
}, [{
|
|
1040
975
|
_key: blk._key
|
|
1041
976
|
}])],
|
|
1042
977
|
description: `Block with _key '${blk._key}' has invalid type name '${blk._type}'. According to the schema, the block type name is '${currentBlockTypeName}'`,
|
|
@@ -1052,12 +987,14 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1052
987
|
}
|
|
1053
988
|
}, !0;
|
|
1054
989
|
}
|
|
1055
|
-
return !blk._type && isPortableTextTextBlock(
|
|
990
|
+
return !blk._type && isPortableTextTextBlock({
|
|
991
|
+
...blk,
|
|
1056
992
|
_type: types.block.name
|
|
1057
|
-
})
|
|
1058
|
-
patches: [set(
|
|
993
|
+
}) ? (resolution = {
|
|
994
|
+
patches: [set({
|
|
995
|
+
...blk,
|
|
1059
996
|
_type: types.block.name
|
|
1060
|
-
}
|
|
997
|
+
}, [{
|
|
1061
998
|
_key: blk._key
|
|
1062
999
|
}])],
|
|
1063
1000
|
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types.block.name}'`,
|
|
@@ -1217,9 +1154,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1217
1154
|
}
|
|
1218
1155
|
}, !0;
|
|
1219
1156
|
if (!child._key || typeof child._key != "string") {
|
|
1220
|
-
const newChild =
|
|
1157
|
+
const newChild = {
|
|
1158
|
+
...child,
|
|
1221
1159
|
_key: keyGenerator()
|
|
1222
|
-
}
|
|
1160
|
+
};
|
|
1223
1161
|
return resolution = {
|
|
1224
1162
|
autoResolve: !0,
|
|
1225
1163
|
patches: [set(newChild, [{
|
|
@@ -1239,9 +1177,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1239
1177
|
}, !0;
|
|
1240
1178
|
}
|
|
1241
1179
|
return child._type ? validChildTypes.includes(child._type) ? child._type === types.span.name && typeof child.text != "string" ? (resolution = {
|
|
1242
|
-
patches: [set(
|
|
1180
|
+
patches: [set({
|
|
1181
|
+
...child,
|
|
1243
1182
|
text: ""
|
|
1244
|
-
}
|
|
1183
|
+
}, [{
|
|
1245
1184
|
_key: blk._key
|
|
1246
1185
|
}, "children", {
|
|
1247
1186
|
_key: child._key
|
|
@@ -1317,14 +1256,6 @@ function withoutPatching(editor, fn) {
|
|
|
1317
1256
|
function isPatching(editor) {
|
|
1318
1257
|
return PATCHING.get(editor);
|
|
1319
1258
|
}
|
|
1320
|
-
function isHighSurrogate(char) {
|
|
1321
|
-
const charCode = char.charCodeAt(0);
|
|
1322
|
-
return charCode >= 55296 && charCode <= 56319;
|
|
1323
|
-
}
|
|
1324
|
-
function isLowSurrogate(char) {
|
|
1325
|
-
const charCode = char.charCodeAt(0);
|
|
1326
|
-
return charCode >= 56320 && charCode <= 57343;
|
|
1327
|
-
}
|
|
1328
1259
|
function cloneDiff(diff2) {
|
|
1329
1260
|
const [type, patch] = diff2;
|
|
1330
1261
|
return [type, patch];
|
|
@@ -1332,123 +1263,41 @@ function cloneDiff(diff2) {
|
|
|
1332
1263
|
function getCommonOverlap(textA, textB) {
|
|
1333
1264
|
let text1 = textA, text2 = textB;
|
|
1334
1265
|
const text1Length = text1.length, text2Length = text2.length;
|
|
1335
|
-
if (text1Length === 0 || text2Length === 0)
|
|
1336
|
-
return 0;
|
|
1266
|
+
if (text1Length === 0 || text2Length === 0) return 0;
|
|
1337
1267
|
text1Length > text2Length ? text1 = text1.substring(text1Length - text2Length) : text1Length < text2Length && (text2 = text2.substring(0, text1Length));
|
|
1338
1268
|
const textLength = Math.min(text1Length, text2Length);
|
|
1339
|
-
if (text1 === text2)
|
|
1340
|
-
return textLength;
|
|
1269
|
+
if (text1 === text2) return textLength;
|
|
1341
1270
|
let best = 0, length = 1;
|
|
1342
1271
|
for (let found = 0; found !== -1; ) {
|
|
1343
1272
|
const pattern = text1.substring(textLength - length);
|
|
1344
|
-
if (found = text2.indexOf(pattern), found === -1)
|
|
1345
|
-
return best;
|
|
1273
|
+
if (found = text2.indexOf(pattern), found === -1) return best;
|
|
1346
1274
|
length += found, (found === 0 || text1.substring(textLength - length) === text2.substring(0, length)) && (best = length, length++);
|
|
1347
1275
|
}
|
|
1348
1276
|
return best;
|
|
1349
1277
|
}
|
|
1350
1278
|
function getCommonPrefix(text1, text2) {
|
|
1351
|
-
if (!text1 || !text2 || text1[0] !== text2[0])
|
|
1352
|
-
return 0;
|
|
1279
|
+
if (!text1 || !text2 || text1[0] !== text2[0]) return 0;
|
|
1353
1280
|
let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerStart = 0;
|
|
1354
|
-
for (; pointerMin < pointerMid; )
|
|
1355
|
-
text1.substring(pointerStart, pointerMid) === text2.substring(pointerStart, pointerMid) ? (pointerMin = pointerMid, pointerStart = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
1281
|
+
for (; pointerMin < pointerMid; ) text1.substring(pointerStart, pointerMid) === text2.substring(pointerStart, pointerMid) ? (pointerMin = pointerMid, pointerStart = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
1356
1282
|
return pointerMid;
|
|
1357
1283
|
}
|
|
1358
1284
|
function getCommonSuffix(text1, text2) {
|
|
1359
|
-
if (!text1 || !text2 || text1[text1.length - 1] !== text2[text2.length - 1])
|
|
1360
|
-
return 0;
|
|
1285
|
+
if (!text1 || !text2 || text1[text1.length - 1] !== text2[text2.length - 1]) return 0;
|
|
1361
1286
|
let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerEnd = 0;
|
|
1362
|
-
for (; pointerMin < pointerMid; )
|
|
1363
|
-
text1.substring(text1.length - pointerMid, text1.length - pointerEnd) === text2.substring(text2.length - pointerMid, text2.length - pointerEnd) ? (pointerMin = pointerMid, pointerEnd = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
1287
|
+
for (; pointerMin < pointerMid; ) text1.substring(text1.length - pointerMid, text1.length - pointerEnd) === text2.substring(text2.length - pointerMid, text2.length - pointerEnd) ? (pointerMin = pointerMid, pointerEnd = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
1364
1288
|
return pointerMid;
|
|
1365
1289
|
}
|
|
1366
|
-
function
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
let equalitiesLength = 0, lastEquality = null, pointer = 0, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0;
|
|
1370
|
-
for (; pointer < diffs.length; )
|
|
1371
|
-
diffs[pointer][0] === DIFF_EQUAL ? (equalities[equalitiesLength++] = pointer, lengthInsertions1 = lengthInsertions2, lengthDeletions1 = lengthDeletions2, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = diffs[pointer][1]) : (diffs[pointer][0] === DIFF_INSERT ? lengthInsertions2 += diffs[pointer][1].length : lengthDeletions2 += diffs[pointer][1].length, lastEquality && lastEquality.length <= Math.max(lengthInsertions1, lengthDeletions1) && lastEquality.length <= Math.max(lengthInsertions2, lengthDeletions2) && (diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT, equalitiesLength--, equalitiesLength--, pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = null, hasChanges = !0)), pointer++;
|
|
1372
|
-
for (hasChanges && (diffs = cleanupMerge(diffs)), diffs = cleanupSemanticLossless(diffs), pointer = 1; pointer < diffs.length; ) {
|
|
1373
|
-
if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
|
|
1374
|
-
const deletion = diffs[pointer - 1][1], insertion = diffs[pointer][1], overlapLength1 = getCommonOverlap(deletion, insertion), overlapLength2 = getCommonOverlap(insertion, deletion);
|
|
1375
|
-
overlapLength1 >= overlapLength2 ? (overlapLength1 >= deletion.length / 2 || overlapLength1 >= insertion.length / 2) && (diffs.splice(pointer, 0, [DIFF_EQUAL, insertion.substring(0, overlapLength1)]), diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlapLength1), diffs[pointer + 1][1] = insertion.substring(overlapLength1), pointer++) : (overlapLength2 >= deletion.length / 2 || overlapLength2 >= insertion.length / 2) && (diffs.splice(pointer, 0, [DIFF_EQUAL, deletion.substring(0, overlapLength2)]), diffs[pointer - 1][0] = DIFF_INSERT, diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlapLength2), diffs[pointer + 1][0] = DIFF_DELETE, diffs[pointer + 1][1] = deletion.substring(overlapLength2), pointer++), pointer++;
|
|
1376
|
-
}
|
|
1377
|
-
pointer++;
|
|
1378
|
-
}
|
|
1379
|
-
return diffs;
|
|
1380
|
-
}
|
|
1381
|
-
const nonAlphaNumericRegex = /[^a-zA-Z0-9]/, whitespaceRegex = /\s/, linebreakRegex = /[\r\n]/, blanklineEndRegex = /\n\r?\n$/, blanklineStartRegex = /^\r?\n\r?\n/;
|
|
1382
|
-
function cleanupSemanticLossless(rawDiffs) {
|
|
1383
|
-
const diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1384
|
-
function diffCleanupSemanticScore(one, two) {
|
|
1385
|
-
if (!one || !two)
|
|
1386
|
-
return 6;
|
|
1387
|
-
const char1 = one.charAt(one.length - 1), char2 = two.charAt(0), nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex), nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex), whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex), whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex), lineBreak1 = whitespace1 && char1.match(linebreakRegex), lineBreak2 = whitespace2 && char2.match(linebreakRegex), blankLine1 = lineBreak1 && one.match(blanklineEndRegex), blankLine2 = lineBreak2 && two.match(blanklineStartRegex);
|
|
1388
|
-
return blankLine1 || blankLine2 ? 5 : lineBreak1 || lineBreak2 ? 4 : nonAlphaNumeric1 && !whitespace1 && whitespace2 ? 3 : whitespace1 || whitespace2 ? 2 : nonAlphaNumeric1 || nonAlphaNumeric2 ? 1 : 0;
|
|
1389
|
-
}
|
|
1390
|
-
let pointer = 1;
|
|
1391
|
-
for (; pointer < diffs.length - 1; ) {
|
|
1392
|
-
if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
|
|
1393
|
-
let equality1 = diffs[pointer - 1][1], edit = diffs[pointer][1], equality2 = diffs[pointer + 1][1];
|
|
1394
|
-
const commonOffset = getCommonSuffix(equality1, edit);
|
|
1395
|
-
if (commonOffset) {
|
|
1396
|
-
const commonString = edit.substring(edit.length - commonOffset);
|
|
1397
|
-
equality1 = equality1.substring(0, equality1.length - commonOffset), edit = commonString + edit.substring(0, edit.length - commonOffset), equality2 = commonString + equality2;
|
|
1398
|
-
}
|
|
1399
|
-
let bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2, bestScore = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1400
|
-
for (; edit.charAt(0) === equality2.charAt(0); ) {
|
|
1401
|
-
equality1 += edit.charAt(0), edit = edit.substring(1) + equality2.charAt(0), equality2 = equality2.substring(1);
|
|
1402
|
-
const score = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1403
|
-
score >= bestScore && (bestScore = score, bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2);
|
|
1404
|
-
}
|
|
1405
|
-
diffs[pointer - 1][1] !== bestEquality1 && (bestEquality1 ? diffs[pointer - 1][1] = bestEquality1 : (diffs.splice(pointer - 1, 1), pointer--), diffs[pointer][1] = bestEdit, bestEquality2 ? diffs[pointer + 1][1] = bestEquality2 : (diffs.splice(pointer + 1, 1), pointer--));
|
|
1406
|
-
}
|
|
1407
|
-
pointer++;
|
|
1408
|
-
}
|
|
1409
|
-
return diffs;
|
|
1410
|
-
}
|
|
1411
|
-
function cleanupMerge(rawDiffs) {
|
|
1412
|
-
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1413
|
-
diffs.push([DIFF_EQUAL, ""]);
|
|
1414
|
-
let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "", commonlength;
|
|
1415
|
-
for (; pointer < diffs.length; )
|
|
1416
|
-
switch (diffs[pointer][0]) {
|
|
1417
|
-
case DIFF_INSERT:
|
|
1418
|
-
countInsert++, textInsert += diffs[pointer][1], pointer++;
|
|
1419
|
-
break;
|
|
1420
|
-
case DIFF_DELETE:
|
|
1421
|
-
countDelete++, textDelete += diffs[pointer][1], pointer++;
|
|
1422
|
-
break;
|
|
1423
|
-
case DIFF_EQUAL:
|
|
1424
|
-
countDelete + countInsert > 1 ? (countDelete !== 0 && countInsert !== 0 && (commonlength = getCommonPrefix(textInsert, textDelete), commonlength !== 0 && (pointer - countDelete - countInsert > 0 && diffs[pointer - countDelete - countInsert - 1][0] === DIFF_EQUAL ? diffs[pointer - countDelete - countInsert - 1][1] += textInsert.substring(0, commonlength) : (diffs.splice(0, 0, [DIFF_EQUAL, textInsert.substring(0, commonlength)]), pointer++), textInsert = textInsert.substring(commonlength), textDelete = textDelete.substring(commonlength)), commonlength = getCommonSuffix(textInsert, textDelete), commonlength !== 0 && (diffs[pointer][1] = textInsert.substring(textInsert.length - commonlength) + diffs[pointer][1], textInsert = textInsert.substring(0, textInsert.length - commonlength), textDelete = textDelete.substring(0, textDelete.length - commonlength))), pointer -= countDelete + countInsert, diffs.splice(pointer, countDelete + countInsert), textDelete.length && (diffs.splice(pointer, 0, [DIFF_DELETE, textDelete]), pointer++), textInsert.length && (diffs.splice(pointer, 0, [DIFF_INSERT, textInsert]), pointer++), pointer++) : pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL ? (diffs[pointer - 1][1] += diffs[pointer][1], diffs.splice(pointer, 1)) : pointer++, countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
|
|
1425
|
-
break;
|
|
1426
|
-
default:
|
|
1427
|
-
throw new Error("Unknown diff operation");
|
|
1428
|
-
}
|
|
1429
|
-
diffs[diffs.length - 1][1] === "" && diffs.pop();
|
|
1430
|
-
let hasChanges = !1;
|
|
1431
|
-
for (pointer = 1; pointer < diffs.length - 1; )
|
|
1432
|
-
diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL && (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1] ? (diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length), diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1], diffs.splice(pointer - 1, 1), hasChanges = !0) : diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1] && (diffs[pointer - 1][1] += diffs[pointer + 1][1], diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1], diffs.splice(pointer + 1, 1), hasChanges = !0)), pointer++;
|
|
1433
|
-
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
1434
|
-
}
|
|
1435
|
-
function trueCount() {
|
|
1436
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++)
|
|
1437
|
-
args[_key] = arguments[_key];
|
|
1438
|
-
return args.reduce((n, bool) => n + (bool ? 1 : 0), 0);
|
|
1290
|
+
function isHighSurrogate(char) {
|
|
1291
|
+
const charCode = char.charCodeAt(0);
|
|
1292
|
+
return charCode >= 55296 && charCode <= 56319;
|
|
1439
1293
|
}
|
|
1440
|
-
function
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
let equalitiesLength = 0, lastEquality = null, pointer = 0, preIns = !1, preDel = !1, postIns = !1, postDel = !1;
|
|
1444
|
-
for (; pointer < diffs.length; )
|
|
1445
|
-
diffs[pointer][0] === DIFF_EQUAL ? (diffs[pointer][1].length < editCost && (postIns || postDel) ? (equalities[equalitiesLength++] = pointer, preIns = postIns, preDel = postDel, lastEquality = diffs[pointer][1]) : (equalitiesLength = 0, lastEquality = null), postIns = !1, postDel = !1) : (diffs[pointer][0] === DIFF_DELETE ? postDel = !0 : postIns = !0, lastEquality && (preIns && preDel && postIns && postDel || lastEquality.length < editCost / 2 && trueCount(preIns, preDel, postIns, postDel) === 3) && (diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT, equalitiesLength--, lastEquality = null, preIns && preDel ? (postIns = !0, postDel = !0, equalitiesLength = 0) : (equalitiesLength--, pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1, postIns = !1, postDel = !1), hasChanges = !0)), pointer++;
|
|
1446
|
-
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
1294
|
+
function isLowSurrogate(char) {
|
|
1295
|
+
const charCode = char.charCodeAt(0);
|
|
1296
|
+
return charCode >= 56320 && charCode <= 57343;
|
|
1447
1297
|
}
|
|
1448
1298
|
function bisect(text1, text2, deadline) {
|
|
1449
1299
|
const text1Length = text1.length, text2Length = text2.length, maxD = Math.ceil((text1Length + text2Length) / 2), vOffset = maxD, vLength = 2 * maxD, v1 = new Array(vLength), v2 = new Array(vLength);
|
|
1450
|
-
for (let x = 0; x < vLength; x++)
|
|
1451
|
-
v1[x] = -1, v2[x] = -1;
|
|
1300
|
+
for (let x = 0; x < vLength; x++) v1[x] = -1, v2[x] = -1;
|
|
1452
1301
|
v1[vOffset + 1] = 0, v2[vOffset + 1] = 0;
|
|
1453
1302
|
const delta = text1Length - text2Length, front = delta % 2 !== 0;
|
|
1454
1303
|
let k1start = 0, k1end = 0, k2start = 0, k2end = 0;
|
|
@@ -1458,18 +1307,14 @@ function bisect(text1, text2, deadline) {
|
|
|
1458
1307
|
let x1;
|
|
1459
1308
|
k1 === -d || k1 !== d && v1[k1Offset - 1] < v1[k1Offset + 1] ? x1 = v1[k1Offset + 1] : x1 = v1[k1Offset - 1] + 1;
|
|
1460
1309
|
let y1 = x1 - k1;
|
|
1461
|
-
for (; x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1); )
|
|
1462
|
-
|
|
1463
|
-
if (
|
|
1464
|
-
k1end += 2;
|
|
1465
|
-
else if (y1 > text2Length)
|
|
1466
|
-
k1start += 2;
|
|
1310
|
+
for (; x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1); ) x1++, y1++;
|
|
1311
|
+
if (v1[k1Offset] = x1, x1 > text1Length) k1end += 2;
|
|
1312
|
+
else if (y1 > text2Length) k1start += 2;
|
|
1467
1313
|
else if (front) {
|
|
1468
1314
|
const k2Offset = vOffset + delta - k1;
|
|
1469
1315
|
if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] !== -1) {
|
|
1470
1316
|
const x2 = text1Length - v2[k2Offset];
|
|
1471
|
-
if (x1 >= x2)
|
|
1472
|
-
return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1317
|
+
if (x1 >= x2) return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1473
1318
|
}
|
|
1474
1319
|
}
|
|
1475
1320
|
}
|
|
@@ -1478,18 +1323,14 @@ function bisect(text1, text2, deadline) {
|
|
|
1478
1323
|
let x2;
|
|
1479
1324
|
k2 === -d || k2 !== d && v2[k2Offset - 1] < v2[k2Offset + 1] ? x2 = v2[k2Offset + 1] : x2 = v2[k2Offset - 1] + 1;
|
|
1480
1325
|
let y2 = x2 - k2;
|
|
1481
|
-
for (; x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1); )
|
|
1482
|
-
|
|
1483
|
-
if (
|
|
1484
|
-
k2end += 2;
|
|
1485
|
-
else if (y2 > text2Length)
|
|
1486
|
-
k2start += 2;
|
|
1326
|
+
for (; x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1); ) x2++, y2++;
|
|
1327
|
+
if (v2[k2Offset] = x2, x2 > text1Length) k2end += 2;
|
|
1328
|
+
else if (y2 > text2Length) k2start += 2;
|
|
1487
1329
|
else if (!front) {
|
|
1488
1330
|
const k1Offset = vOffset + delta - k2;
|
|
1489
1331
|
if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] !== -1) {
|
|
1490
1332
|
const x1 = v1[k1Offset], y1 = vOffset + x1 - k1Offset;
|
|
1491
|
-
if (x2 = text1Length - x2, x1 >= x2)
|
|
1492
|
-
return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1333
|
+
if (x2 = text1Length - x2, x1 >= x2) return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1493
1334
|
}
|
|
1494
1335
|
}
|
|
1495
1336
|
}
|
|
@@ -1506,23 +1347,18 @@ function bisectSplit(text1, text2, x, y, deadline) {
|
|
|
1506
1347
|
});
|
|
1507
1348
|
return diffs.concat(diffsb);
|
|
1508
1349
|
}
|
|
1509
|
-
function findHalfMatch(text1, text2) {
|
|
1510
|
-
if (
|
|
1511
|
-
return null;
|
|
1350
|
+
function findHalfMatch(text1, text2, timeout = 1) {
|
|
1351
|
+
if (timeout <= 0) return null;
|
|
1512
1352
|
const longText = text1.length > text2.length ? text1 : text2, shortText = text1.length > text2.length ? text2 : text1;
|
|
1513
|
-
if (longText.length < 4 || shortText.length * 2 < longText.length)
|
|
1514
|
-
return null;
|
|
1353
|
+
if (longText.length < 4 || shortText.length * 2 < longText.length) return null;
|
|
1515
1354
|
const halfMatch1 = halfMatchI(longText, shortText, Math.ceil(longText.length / 4)), halfMatch2 = halfMatchI(longText, shortText, Math.ceil(longText.length / 2));
|
|
1516
1355
|
let halfMatch;
|
|
1517
|
-
if (halfMatch1 && halfMatch2)
|
|
1518
|
-
halfMatch = halfMatch1[4].length > halfMatch2[4].length ? halfMatch1 : halfMatch2;
|
|
1356
|
+
if (halfMatch1 && halfMatch2) halfMatch = halfMatch1[4].length > halfMatch2[4].length ? halfMatch1 : halfMatch2;
|
|
1519
1357
|
else {
|
|
1520
|
-
if (!halfMatch1 && !halfMatch2)
|
|
1521
|
-
return null;
|
|
1358
|
+
if (!halfMatch1 && !halfMatch2) return null;
|
|
1522
1359
|
halfMatch2 ? halfMatch1 || (halfMatch = halfMatch2) : halfMatch = halfMatch1;
|
|
1523
1360
|
}
|
|
1524
|
-
if (!halfMatch)
|
|
1525
|
-
throw new Error("Unable to find a half match.");
|
|
1361
|
+
if (!halfMatch) throw new Error("Unable to find a half match.");
|
|
1526
1362
|
let text1A, text1B, text2A, text2B;
|
|
1527
1363
|
text1.length > text2.length ? (text1A = halfMatch[0], text1B = halfMatch[1], text2A = halfMatch[2], text2B = halfMatch[3]) : (text2A = halfMatch[0], text2B = halfMatch[1], text1A = halfMatch[2], text1B = halfMatch[3]);
|
|
1528
1364
|
const midCommon = halfMatch[4];
|
|
@@ -1540,8 +1376,7 @@ function halfMatchI(longText, shortText, i) {
|
|
|
1540
1376
|
function charsToLines(diffs, lineArray) {
|
|
1541
1377
|
for (let x = 0; x < diffs.length; x++) {
|
|
1542
1378
|
const chars = diffs[x][1], text = [];
|
|
1543
|
-
for (let y = 0; y < chars.length; y++)
|
|
1544
|
-
text[y] = lineArray[chars.charCodeAt(y)];
|
|
1379
|
+
for (let y = 0; y < chars.length; y++) text[y] = lineArray[chars.charCodeAt(y)];
|
|
1545
1380
|
diffs[x][1] = text.join("");
|
|
1546
1381
|
}
|
|
1547
1382
|
}
|
|
@@ -1594,8 +1429,7 @@ function doLineModeDiff(textA, textB, opts) {
|
|
|
1594
1429
|
checkLines: !1,
|
|
1595
1430
|
deadline: opts.deadline
|
|
1596
1431
|
});
|
|
1597
|
-
for (let j = aa.length - 1; j >= 0; j--)
|
|
1598
|
-
diffs.splice(pointer, 0, aa[j]);
|
|
1432
|
+
for (let j = aa.length - 1; j >= 0; j--) diffs.splice(pointer, 0, aa[j]);
|
|
1599
1433
|
pointer += aa.length;
|
|
1600
1434
|
}
|
|
1601
1435
|
countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
|
|
@@ -1609,15 +1443,11 @@ function doLineModeDiff(textA, textB, opts) {
|
|
|
1609
1443
|
}
|
|
1610
1444
|
function computeDiff(text1, text2, opts) {
|
|
1611
1445
|
let diffs;
|
|
1612
|
-
if (!text1)
|
|
1613
|
-
|
|
1614
|
-
if (!text2)
|
|
1615
|
-
return [[DIFF_DELETE, text1]];
|
|
1446
|
+
if (!text1) return [[DIFF_INSERT, text2]];
|
|
1447
|
+
if (!text2) return [[DIFF_DELETE, text1]];
|
|
1616
1448
|
const longtext = text1.length > text2.length ? text1 : text2, shorttext = text1.length > text2.length ? text2 : text1, i = longtext.indexOf(shorttext);
|
|
1617
|
-
if (i !== -1)
|
|
1618
|
-
|
|
1619
|
-
if (shorttext.length === 1)
|
|
1620
|
-
return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
|
|
1449
|
+
if (i !== -1) return diffs = [[DIFF_INSERT, longtext.substring(0, i)], [DIFF_EQUAL, shorttext], [DIFF_INSERT, longtext.substring(i + shorttext.length)]], text1.length > text2.length && (diffs[0][0] = DIFF_DELETE, diffs[2][0] = DIFF_DELETE), diffs;
|
|
1450
|
+
if (shorttext.length === 1) return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
|
|
1621
1451
|
const halfMatch = findHalfMatch(text1, text2);
|
|
1622
1452
|
if (halfMatch) {
|
|
1623
1453
|
const text1A = halfMatch[0], text1B = halfMatch[1], text2A = halfMatch[2], text2B = halfMatch[3], midCommon = halfMatch[4], diffsA = doDiff(text1A, text2A, opts), diffsB = doDiff(text1B, text2B, opts);
|
|
@@ -1625,17 +1455,25 @@ function computeDiff(text1, text2, opts) {
|
|
|
1625
1455
|
}
|
|
1626
1456
|
return opts.checkLines && text1.length > 100 && text2.length > 100 ? doLineModeDiff(text1, text2, opts) : bisect(text1, text2, opts.deadline);
|
|
1627
1457
|
}
|
|
1458
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {
|
|
1459
|
+
enumerable: !0,
|
|
1460
|
+
configurable: !0,
|
|
1461
|
+
writable: !0,
|
|
1462
|
+
value
|
|
1463
|
+
}) : obj[key] = value, __spreadValues$2 = (a, b) => {
|
|
1464
|
+
for (var prop in b || (b = {})) __hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
1465
|
+
if (__getOwnPropSymbols$2) for (var prop of __getOwnPropSymbols$2(b)) __propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
1466
|
+
return a;
|
|
1467
|
+
};
|
|
1628
1468
|
const DIFF_DELETE = -1, DIFF_INSERT = 1, DIFF_EQUAL = 0;
|
|
1629
1469
|
function diff(textA, textB, opts) {
|
|
1630
|
-
if (textA === null || textB === null)
|
|
1631
|
-
throw new Error("Null input. (diff)");
|
|
1470
|
+
if (textA === null || textB === null) throw new Error("Null input. (diff)");
|
|
1632
1471
|
const diffs = doDiff(textA, textB, createInternalOpts(opts || {}));
|
|
1633
1472
|
return adjustDiffForSurrogatePairs(diffs), diffs;
|
|
1634
1473
|
}
|
|
1635
1474
|
function doDiff(textA, textB, options) {
|
|
1636
1475
|
let text1 = textA, text2 = textB;
|
|
1637
|
-
if (text1 === text2)
|
|
1638
|
-
return text1 ? [[DIFF_EQUAL, text1]] : [];
|
|
1476
|
+
if (text1 === text2) return text1 ? [[DIFF_EQUAL, text1]] : [];
|
|
1639
1477
|
let commonlength = getCommonPrefix(text1, text2);
|
|
1640
1478
|
const commonprefix = text1.substring(0, commonlength);
|
|
1641
1479
|
text1 = text1.substring(commonlength), text2 = text2.substring(commonlength), commonlength = getCommonSuffix(text1, text2);
|
|
@@ -1649,7 +1487,7 @@ function createDeadLine(timeout) {
|
|
|
1649
1487
|
return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
|
|
1650
1488
|
}
|
|
1651
1489
|
function createInternalOpts(opts) {
|
|
1652
|
-
return __spreadValues({
|
|
1490
|
+
return __spreadValues$2({
|
|
1653
1491
|
checkLines: !0,
|
|
1654
1492
|
deadline: createDeadLine(opts.timeout || 1)
|
|
1655
1493
|
}, opts);
|
|
@@ -1700,9 +1538,93 @@ function adjustDiffForSurrogatePairs(diffs) {
|
|
|
1700
1538
|
const firstChar = diffText[0], lastChar = diffText[diffText.length - 1];
|
|
1701
1539
|
isHighSurrogate(lastChar) && diffType === DIFF_EQUAL && deisolateChar(diffs, i, 1), isLowSurrogate(firstChar) && diffType === DIFF_EQUAL && deisolateChar(diffs, i, -1);
|
|
1702
1540
|
}
|
|
1703
|
-
for (let i = 0; i < diffs.length; i++)
|
|
1704
|
-
|
|
1541
|
+
for (let i = 0; i < diffs.length; i++) diffs[i][1].length === 0 && diffs.splice(i, 1);
|
|
1542
|
+
}
|
|
1543
|
+
function cleanupSemantic(rawDiffs) {
|
|
1544
|
+
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1;
|
|
1545
|
+
const equalities = [];
|
|
1546
|
+
let equalitiesLength = 0, lastEquality = null, pointer = 0, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0;
|
|
1547
|
+
for (; pointer < diffs.length; ) diffs[pointer][0] === DIFF_EQUAL ? (equalities[equalitiesLength++] = pointer, lengthInsertions1 = lengthInsertions2, lengthDeletions1 = lengthDeletions2, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = diffs[pointer][1]) : (diffs[pointer][0] === DIFF_INSERT ? lengthInsertions2 += diffs[pointer][1].length : lengthDeletions2 += diffs[pointer][1].length, lastEquality && lastEquality.length <= Math.max(lengthInsertions1, lengthDeletions1) && lastEquality.length <= Math.max(lengthInsertions2, lengthDeletions2) && (diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT, equalitiesLength--, equalitiesLength--, pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = null, hasChanges = !0)), pointer++;
|
|
1548
|
+
for (hasChanges && (diffs = cleanupMerge(diffs)), diffs = cleanupSemanticLossless(diffs), pointer = 1; pointer < diffs.length; ) {
|
|
1549
|
+
if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
|
|
1550
|
+
const deletion = diffs[pointer - 1][1], insertion = diffs[pointer][1], overlapLength1 = getCommonOverlap(deletion, insertion), overlapLength2 = getCommonOverlap(insertion, deletion);
|
|
1551
|
+
overlapLength1 >= overlapLength2 ? (overlapLength1 >= deletion.length / 2 || overlapLength1 >= insertion.length / 2) && (diffs.splice(pointer, 0, [DIFF_EQUAL, insertion.substring(0, overlapLength1)]), diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlapLength1), diffs[pointer + 1][1] = insertion.substring(overlapLength1), pointer++) : (overlapLength2 >= deletion.length / 2 || overlapLength2 >= insertion.length / 2) && (diffs.splice(pointer, 0, [DIFF_EQUAL, deletion.substring(0, overlapLength2)]), diffs[pointer - 1][0] = DIFF_INSERT, diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlapLength2), diffs[pointer + 1][0] = DIFF_DELETE, diffs[pointer + 1][1] = deletion.substring(overlapLength2), pointer++), pointer++;
|
|
1552
|
+
}
|
|
1553
|
+
pointer++;
|
|
1554
|
+
}
|
|
1555
|
+
return diffs;
|
|
1705
1556
|
}
|
|
1557
|
+
const nonAlphaNumericRegex = /[^a-zA-Z0-9]/, whitespaceRegex = /\s/, linebreakRegex = /[\r\n]/, blanklineEndRegex = /\n\r?\n$/, blanklineStartRegex = /^\r?\n\r?\n/;
|
|
1558
|
+
function cleanupSemanticLossless(rawDiffs) {
|
|
1559
|
+
const diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1560
|
+
function diffCleanupSemanticScore(one, two) {
|
|
1561
|
+
if (!one || !two) return 6;
|
|
1562
|
+
const char1 = one.charAt(one.length - 1), char2 = two.charAt(0), nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex), nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex), whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex), whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex), lineBreak1 = whitespace1 && char1.match(linebreakRegex), lineBreak2 = whitespace2 && char2.match(linebreakRegex), blankLine1 = lineBreak1 && one.match(blanklineEndRegex), blankLine2 = lineBreak2 && two.match(blanklineStartRegex);
|
|
1563
|
+
return blankLine1 || blankLine2 ? 5 : lineBreak1 || lineBreak2 ? 4 : nonAlphaNumeric1 && !whitespace1 && whitespace2 ? 3 : whitespace1 || whitespace2 ? 2 : nonAlphaNumeric1 || nonAlphaNumeric2 ? 1 : 0;
|
|
1564
|
+
}
|
|
1565
|
+
let pointer = 1;
|
|
1566
|
+
for (; pointer < diffs.length - 1; ) {
|
|
1567
|
+
if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
|
|
1568
|
+
let equality1 = diffs[pointer - 1][1], edit = diffs[pointer][1], equality2 = diffs[pointer + 1][1];
|
|
1569
|
+
const commonOffset = getCommonSuffix(equality1, edit);
|
|
1570
|
+
if (commonOffset) {
|
|
1571
|
+
const commonString = edit.substring(edit.length - commonOffset);
|
|
1572
|
+
equality1 = equality1.substring(0, equality1.length - commonOffset), edit = commonString + edit.substring(0, edit.length - commonOffset), equality2 = commonString + equality2;
|
|
1573
|
+
}
|
|
1574
|
+
let bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2, bestScore = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1575
|
+
for (; edit.charAt(0) === equality2.charAt(0); ) {
|
|
1576
|
+
equality1 += edit.charAt(0), edit = edit.substring(1) + equality2.charAt(0), equality2 = equality2.substring(1);
|
|
1577
|
+
const score = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1578
|
+
score >= bestScore && (bestScore = score, bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2);
|
|
1579
|
+
}
|
|
1580
|
+
diffs[pointer - 1][1] !== bestEquality1 && (bestEquality1 ? diffs[pointer - 1][1] = bestEquality1 : (diffs.splice(pointer - 1, 1), pointer--), diffs[pointer][1] = bestEdit, bestEquality2 ? diffs[pointer + 1][1] = bestEquality2 : (diffs.splice(pointer + 1, 1), pointer--));
|
|
1581
|
+
}
|
|
1582
|
+
pointer++;
|
|
1583
|
+
}
|
|
1584
|
+
return diffs;
|
|
1585
|
+
}
|
|
1586
|
+
function cleanupMerge(rawDiffs) {
|
|
1587
|
+
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1588
|
+
diffs.push([DIFF_EQUAL, ""]);
|
|
1589
|
+
let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "", commonlength;
|
|
1590
|
+
for (; pointer < diffs.length; ) switch (diffs[pointer][0]) {
|
|
1591
|
+
case DIFF_INSERT:
|
|
1592
|
+
countInsert++, textInsert += diffs[pointer][1], pointer++;
|
|
1593
|
+
break;
|
|
1594
|
+
case DIFF_DELETE:
|
|
1595
|
+
countDelete++, textDelete += diffs[pointer][1], pointer++;
|
|
1596
|
+
break;
|
|
1597
|
+
case DIFF_EQUAL:
|
|
1598
|
+
countDelete + countInsert > 1 ? (countDelete !== 0 && countInsert !== 0 && (commonlength = getCommonPrefix(textInsert, textDelete), commonlength !== 0 && (pointer - countDelete - countInsert > 0 && diffs[pointer - countDelete - countInsert - 1][0] === DIFF_EQUAL ? diffs[pointer - countDelete - countInsert - 1][1] += textInsert.substring(0, commonlength) : (diffs.splice(0, 0, [DIFF_EQUAL, textInsert.substring(0, commonlength)]), pointer++), textInsert = textInsert.substring(commonlength), textDelete = textDelete.substring(commonlength)), commonlength = getCommonSuffix(textInsert, textDelete), commonlength !== 0 && (diffs[pointer][1] = textInsert.substring(textInsert.length - commonlength) + diffs[pointer][1], textInsert = textInsert.substring(0, textInsert.length - commonlength), textDelete = textDelete.substring(0, textDelete.length - commonlength))), pointer -= countDelete + countInsert, diffs.splice(pointer, countDelete + countInsert), textDelete.length && (diffs.splice(pointer, 0, [DIFF_DELETE, textDelete]), pointer++), textInsert.length && (diffs.splice(pointer, 0, [DIFF_INSERT, textInsert]), pointer++), pointer++) : pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL ? (diffs[pointer - 1][1] += diffs[pointer][1], diffs.splice(pointer, 1)) : pointer++, countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
|
|
1599
|
+
break;
|
|
1600
|
+
default:
|
|
1601
|
+
throw new Error("Unknown diff operation");
|
|
1602
|
+
}
|
|
1603
|
+
diffs[diffs.length - 1][1] === "" && diffs.pop();
|
|
1604
|
+
let hasChanges = !1;
|
|
1605
|
+
for (pointer = 1; pointer < diffs.length - 1; ) diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL && (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1] ? (diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length), diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1], diffs.splice(pointer - 1, 1), hasChanges = !0) : diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1] && (diffs[pointer - 1][1] += diffs[pointer + 1][1], diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1], diffs.splice(pointer + 1, 1), hasChanges = !0)), pointer++;
|
|
1606
|
+
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
1607
|
+
}
|
|
1608
|
+
function trueCount(...args) {
|
|
1609
|
+
return args.reduce((n, bool) => n + (bool ? 1 : 0), 0);
|
|
1610
|
+
}
|
|
1611
|
+
function cleanupEfficiency(rawDiffs, editCost = 4) {
|
|
1612
|
+
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1;
|
|
1613
|
+
const equalities = [];
|
|
1614
|
+
let equalitiesLength = 0, lastEquality = null, pointer = 0, preIns = !1, preDel = !1, postIns = !1, postDel = !1;
|
|
1615
|
+
for (; pointer < diffs.length; ) diffs[pointer][0] === DIFF_EQUAL ? (diffs[pointer][1].length < editCost && (postIns || postDel) ? (equalities[equalitiesLength++] = pointer, preIns = postIns, preDel = postDel, lastEquality = diffs[pointer][1]) : (equalitiesLength = 0, lastEquality = null), postIns = !1, postDel = !1) : (diffs[pointer][0] === DIFF_DELETE ? postDel = !0 : postIns = !0, lastEquality && (preIns && preDel && postIns && postDel || lastEquality.length < editCost / 2 && trueCount(preIns, preDel, postIns, postDel) === 3) && (diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT, equalitiesLength--, lastEquality = null, preIns && preDel ? (postIns = !0, postDel = !0, equalitiesLength = 0) : (equalitiesLength--, pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1, postIns = !1, postDel = !1), hasChanges = !0)), pointer++;
|
|
1616
|
+
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
1617
|
+
}
|
|
1618
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
1619
|
+
enumerable: !0,
|
|
1620
|
+
configurable: !0,
|
|
1621
|
+
writable: !0,
|
|
1622
|
+
value
|
|
1623
|
+
}) : obj[key] = value, __spreadValues$1 = (a, b) => {
|
|
1624
|
+
for (var prop in b || (b = {})) __hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
1625
|
+
if (__getOwnPropSymbols$1) for (var prop of __getOwnPropSymbols$1(b)) __propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
1626
|
+
return a;
|
|
1627
|
+
};
|
|
1706
1628
|
const DEFAULT_OPTIONS = {
|
|
1707
1629
|
/**
|
|
1708
1630
|
* At what point is no match declared (0.0 = perfection, 1.0 = very loose).
|
|
@@ -1716,13 +1638,11 @@ const DEFAULT_OPTIONS = {
|
|
|
1716
1638
|
distance: 1e3
|
|
1717
1639
|
};
|
|
1718
1640
|
function applyDefaults(options) {
|
|
1719
|
-
return __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options);
|
|
1641
|
+
return __spreadValues$1(__spreadValues$1({}, DEFAULT_OPTIONS), options);
|
|
1720
1642
|
}
|
|
1721
1643
|
const MAX_BITS$1 = 32;
|
|
1722
|
-
function bitap(text, pattern, loc) {
|
|
1723
|
-
|
|
1724
|
-
if (pattern.length > MAX_BITS$1)
|
|
1725
|
-
throw new Error("Pattern too long for this browser.");
|
|
1644
|
+
function bitap(text, pattern, loc, opts = {}) {
|
|
1645
|
+
if (pattern.length > MAX_BITS$1) throw new Error("Pattern too long for this browser.");
|
|
1726
1646
|
const options = applyDefaults(opts), s = getAlphabetFromPattern(pattern);
|
|
1727
1647
|
function getBitapScore(e, x) {
|
|
1728
1648
|
const accuracy = e / pattern.length, proximity = Math.abs(loc - x);
|
|
@@ -1734,8 +1654,7 @@ function bitap(text, pattern, loc) {
|
|
|
1734
1654
|
bestLoc = -1;
|
|
1735
1655
|
let binMin, binMid, binMax = pattern.length + text.length, lastRd = [];
|
|
1736
1656
|
for (let d = 0; d < pattern.length; d++) {
|
|
1737
|
-
for (binMin = 0, binMid = binMax; binMin < binMid; )
|
|
1738
|
-
getBitapScore(d, loc + binMid) <= scoreThreshold ? binMin = binMid : binMax = binMid, binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
1657
|
+
for (binMin = 0, binMid = binMax; binMin < binMid; ) getBitapScore(d, loc + binMid) <= scoreThreshold ? binMin = binMid : binMax = binMid, binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
1739
1658
|
binMax = binMid;
|
|
1740
1659
|
let start = Math.max(1, loc - binMid + 1);
|
|
1741
1660
|
const finish = Math.min(loc + binMid, text.length) + pattern.length, rd = new Array(finish + 2);
|
|
@@ -1744,106 +1663,40 @@ function bitap(text, pattern, loc) {
|
|
|
1744
1663
|
const charMatch = s[text.charAt(j - 1)];
|
|
1745
1664
|
if (d === 0 ? rd[j] = (rd[j + 1] << 1 | 1) & charMatch : rd[j] = (rd[j + 1] << 1 | 1) & charMatch | ((lastRd[j + 1] | lastRd[j]) << 1 | 1) | lastRd[j + 1], rd[j] & matchmask) {
|
|
1746
1665
|
const score = getBitapScore(d, j - 1);
|
|
1747
|
-
if (score <= scoreThreshold)
|
|
1748
|
-
|
|
1749
|
-
start = Math.max(1, 2 * loc - bestLoc);
|
|
1750
|
-
else
|
|
1751
|
-
break;
|
|
1666
|
+
if (score <= scoreThreshold) if (scoreThreshold = score, bestLoc = j - 1, bestLoc > loc) start = Math.max(1, 2 * loc - bestLoc);
|
|
1667
|
+
else break;
|
|
1752
1668
|
}
|
|
1753
1669
|
}
|
|
1754
|
-
if (getBitapScore(d + 1, loc) > scoreThreshold)
|
|
1755
|
-
break;
|
|
1670
|
+
if (getBitapScore(d + 1, loc) > scoreThreshold) break;
|
|
1756
1671
|
lastRd = rd;
|
|
1757
1672
|
}
|
|
1758
1673
|
return bestLoc;
|
|
1759
1674
|
}
|
|
1760
1675
|
function getAlphabetFromPattern(pattern) {
|
|
1761
1676
|
const s = {};
|
|
1762
|
-
for (let i = 0; i < pattern.length; i++)
|
|
1763
|
-
|
|
1764
|
-
for (let i = 0; i < pattern.length; i++)
|
|
1765
|
-
s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
|
|
1677
|
+
for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] = 0;
|
|
1678
|
+
for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
|
|
1766
1679
|
return s;
|
|
1767
1680
|
}
|
|
1768
1681
|
function match(text, pattern, searchLocation) {
|
|
1769
|
-
if (text === null || pattern === null || searchLocation === null)
|
|
1770
|
-
throw new Error("Null input. (match())");
|
|
1682
|
+
if (text === null || pattern === null || searchLocation === null) throw new Error("Null input. (match())");
|
|
1771
1683
|
const loc = Math.max(0, Math.min(searchLocation, text.length));
|
|
1772
|
-
if (text === pattern)
|
|
1773
|
-
return 0;
|
|
1684
|
+
if (text === pattern) return 0;
|
|
1774
1685
|
if (text.length) {
|
|
1775
|
-
if (text.substring(loc, loc + pattern.length) === pattern)
|
|
1776
|
-
return loc;
|
|
1686
|
+
if (text.substring(loc, loc + pattern.length) === pattern) return loc;
|
|
1777
1687
|
} else return -1;
|
|
1778
1688
|
return bitap(text, pattern, loc);
|
|
1779
1689
|
}
|
|
1780
|
-
function createPatchObject(start1, start2) {
|
|
1781
|
-
return {
|
|
1782
|
-
diffs: [],
|
|
1783
|
-
start1,
|
|
1784
|
-
start2,
|
|
1785
|
-
utf8Start1: start1,
|
|
1786
|
-
utf8Start2: start2,
|
|
1787
|
-
length1: 0,
|
|
1788
|
-
length2: 0,
|
|
1789
|
-
utf8Length1: 0,
|
|
1790
|
-
utf8Length2: 0
|
|
1791
|
-
};
|
|
1792
|
-
}
|
|
1793
1690
|
function diffText1(diffs) {
|
|
1794
1691
|
const text = [];
|
|
1795
|
-
for (let x = 0; x < diffs.length; x++)
|
|
1796
|
-
diffs[x][0] !== DIFF_INSERT && (text[x] = diffs[x][1]);
|
|
1692
|
+
for (let x = 0; x < diffs.length; x++) diffs[x][0] !== DIFF_INSERT && (text[x] = diffs[x][1]);
|
|
1797
1693
|
return text.join("");
|
|
1798
1694
|
}
|
|
1799
1695
|
function diffText2(diffs) {
|
|
1800
1696
|
const text = [];
|
|
1801
|
-
for (let x = 0; x < diffs.length; x++)
|
|
1802
|
-
diffs[x][0] !== DIFF_DELETE && (text[x] = diffs[x][1]);
|
|
1697
|
+
for (let x = 0; x < diffs.length; x++) diffs[x][0] !== DIFF_DELETE && (text[x] = diffs[x][1]);
|
|
1803
1698
|
return text.join("");
|
|
1804
1699
|
}
|
|
1805
|
-
function countUtf8Bytes(str) {
|
|
1806
|
-
let bytes = 0;
|
|
1807
|
-
for (let i = 0; i < str.length; i++) {
|
|
1808
|
-
const codePoint = str.codePointAt(i);
|
|
1809
|
-
if (typeof codePoint > "u")
|
|
1810
|
-
throw new Error("Failed to get codepoint");
|
|
1811
|
-
bytes += utf8len(codePoint);
|
|
1812
|
-
}
|
|
1813
|
-
return bytes;
|
|
1814
|
-
}
|
|
1815
|
-
function adjustIndiciesToUcs2(patches, base) {
|
|
1816
|
-
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, byteOffset = 0, idx = 0;
|
|
1817
|
-
function advanceTo(target) {
|
|
1818
|
-
for (; byteOffset < target; ) {
|
|
1819
|
-
const codePoint = base.codePointAt(idx);
|
|
1820
|
-
if (typeof codePoint > "u")
|
|
1821
|
-
return idx;
|
|
1822
|
-
byteOffset += utf8len(codePoint), codePoint > 65535 ? idx += 2 : idx += 1;
|
|
1823
|
-
}
|
|
1824
|
-
if (!options.allowExceedingIndices && byteOffset !== target)
|
|
1825
|
-
throw new Error("Failed to determine byte offset");
|
|
1826
|
-
return idx;
|
|
1827
|
-
}
|
|
1828
|
-
const adjusted = [];
|
|
1829
|
-
for (const patch of patches)
|
|
1830
|
-
adjusted.push({
|
|
1831
|
-
diffs: patch.diffs.map((diff2) => cloneDiff(diff2)),
|
|
1832
|
-
start1: advanceTo(patch.start1),
|
|
1833
|
-
start2: advanceTo(patch.start2),
|
|
1834
|
-
utf8Start1: patch.utf8Start1,
|
|
1835
|
-
utf8Start2: patch.utf8Start2,
|
|
1836
|
-
length1: patch.length1,
|
|
1837
|
-
length2: patch.length2,
|
|
1838
|
-
utf8Length1: patch.utf8Length1,
|
|
1839
|
-
utf8Length2: patch.utf8Length2
|
|
1840
|
-
});
|
|
1841
|
-
return adjusted;
|
|
1842
|
-
}
|
|
1843
|
-
function utf8len(codePoint) {
|
|
1844
|
-
return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
1845
|
-
}
|
|
1846
|
-
const MAX_BITS = 32, DEFAULT_MARGIN = 4;
|
|
1847
1700
|
function levenshtein(diffs) {
|
|
1848
1701
|
let leven = 0, insertions = 0, deletions = 0;
|
|
1849
1702
|
for (let x = 0; x < diffs.length; x++) {
|
|
@@ -1866,38 +1719,82 @@ function levenshtein(diffs) {
|
|
|
1866
1719
|
}
|
|
1867
1720
|
function xIndex(diffs, loc) {
|
|
1868
1721
|
let chars1 = 0, chars2 = 0, lastChars1 = 0, lastChars2 = 0, x;
|
|
1869
|
-
for (x = 0; x < diffs.length && (diffs[x][0] !== DIFF_INSERT && (chars1 += diffs[x][1].length), diffs[x][0] !== DIFF_DELETE && (chars2 += diffs[x][1].length), !(chars1 > loc)); x++)
|
|
1870
|
-
lastChars1 = chars1, lastChars2 = chars2;
|
|
1722
|
+
for (x = 0; x < diffs.length && (diffs[x][0] !== DIFF_INSERT && (chars1 += diffs[x][1].length), diffs[x][0] !== DIFF_DELETE && (chars2 += diffs[x][1].length), !(chars1 > loc)); x++) lastChars1 = chars1, lastChars2 = chars2;
|
|
1871
1723
|
return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (loc - lastChars1);
|
|
1872
1724
|
}
|
|
1873
|
-
function
|
|
1874
|
-
|
|
1725
|
+
function countUtf8Bytes(str) {
|
|
1726
|
+
let bytes = 0;
|
|
1727
|
+
for (let i = 0; i < str.length; i++) {
|
|
1728
|
+
const codePoint = str.codePointAt(i);
|
|
1729
|
+
if (typeof codePoint > "u") throw new Error("Failed to get codepoint");
|
|
1730
|
+
bytes += utf8len(codePoint);
|
|
1731
|
+
}
|
|
1732
|
+
return bytes;
|
|
1733
|
+
}
|
|
1734
|
+
function adjustIndiciesToUcs2(patches, base, options = {}) {
|
|
1735
|
+
let byteOffset = 0, idx = 0;
|
|
1736
|
+
function advanceTo(target) {
|
|
1737
|
+
for (; byteOffset < target; ) {
|
|
1738
|
+
const codePoint = base.codePointAt(idx);
|
|
1739
|
+
if (typeof codePoint > "u") return idx;
|
|
1740
|
+
byteOffset += utf8len(codePoint), codePoint > 65535 ? idx += 2 : idx += 1;
|
|
1741
|
+
}
|
|
1742
|
+
if (!options.allowExceedingIndices && byteOffset !== target) throw new Error("Failed to determine byte offset");
|
|
1743
|
+
return idx;
|
|
1744
|
+
}
|
|
1745
|
+
const adjusted = [];
|
|
1746
|
+
for (const patch of patches) adjusted.push({
|
|
1747
|
+
diffs: patch.diffs.map((diff2) => cloneDiff(diff2)),
|
|
1748
|
+
start1: advanceTo(patch.start1),
|
|
1749
|
+
start2: advanceTo(patch.start2),
|
|
1750
|
+
utf8Start1: patch.utf8Start1,
|
|
1751
|
+
utf8Start2: patch.utf8Start2,
|
|
1752
|
+
length1: patch.length1,
|
|
1753
|
+
length2: patch.length2,
|
|
1754
|
+
utf8Length1: patch.utf8Length1,
|
|
1755
|
+
utf8Length2: patch.utf8Length2
|
|
1756
|
+
});
|
|
1757
|
+
return adjusted;
|
|
1758
|
+
}
|
|
1759
|
+
function utf8len(codePoint) {
|
|
1760
|
+
return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
1761
|
+
}
|
|
1762
|
+
const MAX_BITS = 32, DEFAULT_MARGIN = 4;
|
|
1763
|
+
function addPadding(patches, margin = DEFAULT_MARGIN) {
|
|
1764
|
+
const paddingLength = margin;
|
|
1875
1765
|
let nullPadding = "";
|
|
1876
|
-
for (let x = 1; x <= paddingLength; x++)
|
|
1877
|
-
|
|
1878
|
-
for (const p of patches)
|
|
1879
|
-
p.start1 += paddingLength, p.start2 += paddingLength, p.utf8Start1 += paddingLength, p.utf8Start2 += paddingLength;
|
|
1766
|
+
for (let x = 1; x <= paddingLength; x++) nullPadding += String.fromCharCode(x);
|
|
1767
|
+
for (const p of patches) p.start1 += paddingLength, p.start2 += paddingLength, p.utf8Start1 += paddingLength, p.utf8Start2 += paddingLength;
|
|
1880
1768
|
let patch = patches[0], diffs = patch.diffs;
|
|
1881
|
-
if (diffs.length === 0 || diffs[0][0] !== DIFF_EQUAL)
|
|
1882
|
-
diffs.unshift([DIFF_EQUAL, nullPadding]), patch.start1 -= paddingLength, patch.start2 -= paddingLength, patch.utf8Start1 -= paddingLength, patch.utf8Start2 -= paddingLength, patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
1769
|
+
if (diffs.length === 0 || diffs[0][0] !== DIFF_EQUAL) diffs.unshift([DIFF_EQUAL, nullPadding]), patch.start1 -= paddingLength, patch.start2 -= paddingLength, patch.utf8Start1 -= paddingLength, patch.utf8Start2 -= paddingLength, patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
1883
1770
|
else if (paddingLength > diffs[0][1].length) {
|
|
1884
1771
|
const firstDiffLength = diffs[0][1].length, extraLength = paddingLength - firstDiffLength;
|
|
1885
1772
|
diffs[0][1] = nullPadding.substring(firstDiffLength) + diffs[0][1], patch.start1 -= extraLength, patch.start2 -= extraLength, patch.utf8Start1 -= extraLength, patch.utf8Start2 -= extraLength, patch.length1 += extraLength, patch.length2 += extraLength, patch.utf8Length1 += extraLength, patch.utf8Length2 += extraLength;
|
|
1886
1773
|
}
|
|
1887
|
-
if (patch = patches[patches.length - 1], diffs = patch.diffs, diffs.length === 0 || diffs[diffs.length - 1][0] !== DIFF_EQUAL)
|
|
1888
|
-
diffs.push([DIFF_EQUAL, nullPadding]), patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
1774
|
+
if (patch = patches[patches.length - 1], diffs = patch.diffs, diffs.length === 0 || diffs[diffs.length - 1][0] !== DIFF_EQUAL) diffs.push([DIFF_EQUAL, nullPadding]), patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
1889
1775
|
else if (paddingLength > diffs[diffs.length - 1][1].length) {
|
|
1890
1776
|
const extraLength = paddingLength - diffs[diffs.length - 1][1].length;
|
|
1891
1777
|
diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength), patch.length1 += extraLength, patch.length2 += extraLength, patch.utf8Length1 += extraLength, patch.utf8Length2 += extraLength;
|
|
1892
1778
|
}
|
|
1893
1779
|
return nullPadding;
|
|
1894
1780
|
}
|
|
1895
|
-
function
|
|
1896
|
-
|
|
1781
|
+
function createPatchObject(start1, start2) {
|
|
1782
|
+
return {
|
|
1783
|
+
diffs: [],
|
|
1784
|
+
start1,
|
|
1785
|
+
start2,
|
|
1786
|
+
utf8Start1: start1,
|
|
1787
|
+
utf8Start2: start2,
|
|
1788
|
+
length1: 0,
|
|
1789
|
+
length2: 0,
|
|
1790
|
+
utf8Length1: 0,
|
|
1791
|
+
utf8Length2: 0
|
|
1792
|
+
};
|
|
1793
|
+
}
|
|
1794
|
+
function splitMax(patches, margin = DEFAULT_MARGIN) {
|
|
1897
1795
|
const patchSize = MAX_BITS;
|
|
1898
1796
|
for (let x = 0; x < patches.length; x++) {
|
|
1899
|
-
if (patches[x].length1 <= patchSize)
|
|
1900
|
-
continue;
|
|
1797
|
+
if (patches[x].length1 <= patchSize) continue;
|
|
1901
1798
|
const bigpatch = patches[x];
|
|
1902
1799
|
patches.splice(x--, 1);
|
|
1903
1800
|
let start1 = bigpatch.start1, start2 = bigpatch.start2, preContext = "";
|
|
@@ -1923,13 +1820,10 @@ function splitMax(patches) {
|
|
|
1923
1820
|
}
|
|
1924
1821
|
}
|
|
1925
1822
|
}
|
|
1926
|
-
function apply(patches, originalText) {
|
|
1927
|
-
|
|
1928
|
-
if (typeof patches == "string")
|
|
1929
|
-
throw new Error("Patches must be an array - pass the patch to `parsePatch()` first");
|
|
1823
|
+
function apply(patches, originalText, opts = {}) {
|
|
1824
|
+
if (typeof patches == "string") throw new Error("Patches must be an array - pass the patch to `parsePatch()` first");
|
|
1930
1825
|
let text = originalText;
|
|
1931
|
-
if (patches.length === 0)
|
|
1932
|
-
return [text, []];
|
|
1826
|
+
if (patches.length === 0) return [text, []];
|
|
1933
1827
|
const parsed = adjustIndiciesToUcs2(patches, text, {
|
|
1934
1828
|
allowExceedingIndices: opts.allowExceedingIndices
|
|
1935
1829
|
}), margin = opts.margin || DEFAULT_MARGIN, deleteThreshold = opts.deleteThreshold || 0.4, nullPadding = addPadding(parsed, margin);
|
|
@@ -1939,19 +1833,16 @@ function apply(patches, originalText) {
|
|
|
1939
1833
|
for (let x = 0; x < parsed.length; x++) {
|
|
1940
1834
|
const expectedLoc = parsed[x].start2 + delta, text1 = diffText1(parsed[x].diffs);
|
|
1941
1835
|
let startLoc, endLoc = -1;
|
|
1942
|
-
if (text1.length > MAX_BITS ? (startLoc = match(text, text1.substring(0, MAX_BITS), expectedLoc), startLoc !== -1 && (endLoc = match(text, text1.substring(text1.length - MAX_BITS), expectedLoc + text1.length - MAX_BITS), (endLoc === -1 || startLoc >= endLoc) && (startLoc = -1))) : startLoc = match(text, text1, expectedLoc), startLoc === -1)
|
|
1943
|
-
results[x] = !1, delta -= parsed[x].length2 - parsed[x].length1;
|
|
1836
|
+
if (text1.length > MAX_BITS ? (startLoc = match(text, text1.substring(0, MAX_BITS), expectedLoc), startLoc !== -1 && (endLoc = match(text, text1.substring(text1.length - MAX_BITS), expectedLoc + text1.length - MAX_BITS), (endLoc === -1 || startLoc >= endLoc) && (startLoc = -1))) : startLoc = match(text, text1, expectedLoc), startLoc === -1) results[x] = !1, delta -= parsed[x].length2 - parsed[x].length1;
|
|
1944
1837
|
else {
|
|
1945
1838
|
results[x] = !0, delta = startLoc - expectedLoc;
|
|
1946
1839
|
let text2;
|
|
1947
|
-
if (endLoc === -1 ? text2 = text.substring(startLoc, startLoc + text1.length) : text2 = text.substring(startLoc, endLoc + MAX_BITS), text1 === text2)
|
|
1948
|
-
text = text.substring(0, startLoc) + diffText2(parsed[x].diffs) + text.substring(startLoc + text1.length);
|
|
1840
|
+
if (endLoc === -1 ? text2 = text.substring(startLoc, startLoc + text1.length) : text2 = text.substring(startLoc, endLoc + MAX_BITS), text1 === text2) text = text.substring(0, startLoc) + diffText2(parsed[x].diffs) + text.substring(startLoc + text1.length);
|
|
1949
1841
|
else {
|
|
1950
1842
|
let diffs = diff(text1, text2, {
|
|
1951
1843
|
checkLines: !1
|
|
1952
1844
|
});
|
|
1953
|
-
if (text1.length > MAX_BITS && levenshtein(diffs) / text1.length > deleteThreshold)
|
|
1954
|
-
results[x] = !1;
|
|
1845
|
+
if (text1.length > MAX_BITS && levenshtein(diffs) / text1.length > deleteThreshold) results[x] = !1;
|
|
1955
1846
|
else {
|
|
1956
1847
|
diffs = cleanupSemanticLossless(diffs);
|
|
1957
1848
|
let index1 = 0, index2 = 0;
|
|
@@ -1967,20 +1858,17 @@ function apply(patches, originalText) {
|
|
|
1967
1858
|
}
|
|
1968
1859
|
const patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;
|
|
1969
1860
|
function parse(textline) {
|
|
1970
|
-
if (!textline)
|
|
1971
|
-
return [];
|
|
1861
|
+
if (!textline) return [];
|
|
1972
1862
|
const patches = [], lines = textline.split(`
|
|
1973
1863
|
`);
|
|
1974
1864
|
let textPointer = 0;
|
|
1975
1865
|
for (; textPointer < lines.length; ) {
|
|
1976
1866
|
const m = lines[textPointer].match(patchHeader);
|
|
1977
|
-
if (!m)
|
|
1978
|
-
throw new Error("Invalid patch string: ".concat(lines[textPointer]));
|
|
1867
|
+
if (!m) throw new Error(`Invalid patch string: ${lines[textPointer]}`);
|
|
1979
1868
|
const patch = createPatchObject(toInt(m[1]), toInt(m[3]));
|
|
1980
1869
|
for (patches.push(patch), m[2] === "" ? (patch.start1--, patch.utf8Start1--, patch.length1 = 1, patch.utf8Length1 = 1) : m[2] === "0" ? (patch.length1 = 0, patch.utf8Length1 = 0) : (patch.start1--, patch.utf8Start1--, patch.utf8Length1 = toInt(m[2]), patch.length1 = patch.utf8Length1), m[4] === "" ? (patch.start2--, patch.utf8Start2--, patch.length2 = 1, patch.utf8Length2 = 1) : m[4] === "0" ? (patch.length2 = 0, patch.utf8Length2 = 0) : (patch.start2--, patch.utf8Start2--, patch.utf8Length2 = toInt(m[4]), patch.length2 = patch.utf8Length2), textPointer++; textPointer < lines.length; ) {
|
|
1981
1870
|
const currentLine = lines[textPointer], sign = currentLine.charAt(0);
|
|
1982
|
-
if (sign === "@")
|
|
1983
|
-
break;
|
|
1871
|
+
if (sign === "@") break;
|
|
1984
1872
|
if (sign === "") {
|
|
1985
1873
|
textPointer++;
|
|
1986
1874
|
continue;
|
|
@@ -1988,18 +1876,14 @@ function parse(textline) {
|
|
|
1988
1876
|
let line;
|
|
1989
1877
|
try {
|
|
1990
1878
|
line = decodeURI(currentLine.slice(1));
|
|
1991
|
-
} catch
|
|
1992
|
-
throw new Error(
|
|
1879
|
+
} catch {
|
|
1880
|
+
throw new Error(`Illegal escape in parse: ${currentLine}`);
|
|
1993
1881
|
}
|
|
1994
1882
|
const utf8Diff = countUtf8Bytes(line) - line.length;
|
|
1995
|
-
if (sign === "-")
|
|
1996
|
-
|
|
1997
|
-
else if (sign === "
|
|
1998
|
-
|
|
1999
|
-
else if (sign === " ")
|
|
2000
|
-
patch.diffs.push([DIFF_EQUAL, line]), patch.length1 -= utf8Diff, patch.length2 -= utf8Diff;
|
|
2001
|
-
else
|
|
2002
|
-
throw new Error('Invalid patch mode "'.concat(sign, '" in: ').concat(line));
|
|
1883
|
+
if (sign === "-") patch.diffs.push([DIFF_DELETE, line]), patch.length1 -= utf8Diff;
|
|
1884
|
+
else if (sign === "+") patch.diffs.push([DIFF_INSERT, line]), patch.length2 -= utf8Diff;
|
|
1885
|
+
else if (sign === " ") patch.diffs.push([DIFF_EQUAL, line]), patch.length1 -= utf8Diff, patch.length2 -= utf8Diff;
|
|
1886
|
+
else throw new Error(`Invalid patch mode "${sign}" in: ${line}`);
|
|
2003
1887
|
textPointer++;
|
|
2004
1888
|
}
|
|
2005
1889
|
}
|
|
@@ -2014,8 +1898,7 @@ function withUndoing(editor, fn) {
|
|
|
2014
1898
|
IS_UDOING.set(editor, !0), fn(), IS_UDOING.set(editor, prev);
|
|
2015
1899
|
}
|
|
2016
1900
|
function isUndoing(editor) {
|
|
2017
|
-
|
|
2018
|
-
return (_a = IS_UDOING.get(editor)) != null ? _a : !1;
|
|
1901
|
+
return IS_UDOING.get(editor) ?? !1;
|
|
2019
1902
|
}
|
|
2020
1903
|
function setIsUndoing(editor, isUndoing2) {
|
|
2021
1904
|
IS_UDOING.set(editor, isUndoing2);
|
|
@@ -2025,20 +1908,11 @@ function withRedoing(editor, fn) {
|
|
|
2025
1908
|
IS_REDOING.set(editor, !0), fn(), IS_REDOING.set(editor, prev);
|
|
2026
1909
|
}
|
|
2027
1910
|
function isRedoing(editor) {
|
|
2028
|
-
|
|
2029
|
-
return (_a = IS_REDOING.get(editor)) != null ? _a : !1;
|
|
1911
|
+
return IS_REDOING.get(editor) ?? !1;
|
|
2030
1912
|
}
|
|
2031
1913
|
function setIsRedoing(editor, isRedoing2) {
|
|
2032
1914
|
IS_REDOING.set(editor, isRedoing2);
|
|
2033
1915
|
}
|
|
2034
|
-
var __defProp$m = Object.defineProperty, __getOwnPropSymbols$m = Object.getOwnPropertySymbols, __hasOwnProp$m = Object.prototype.hasOwnProperty, __propIsEnum$m = Object.prototype.propertyIsEnumerable, __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$m = (a, b) => {
|
|
2035
|
-
for (var prop in b || (b = {}))
|
|
2036
|
-
__hasOwnProp$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
2037
|
-
if (__getOwnPropSymbols$m)
|
|
2038
|
-
for (var prop of __getOwnPropSymbols$m(b))
|
|
2039
|
-
__propIsEnum$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
2040
|
-
return a;
|
|
2041
|
-
};
|
|
2042
1916
|
const debug$j = debugWithName("plugin:withUndoRedo"), debugVerbose$3 = debug$j.enabled && !1, SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2043
1917
|
const state = SAVING.get(editor);
|
|
2044
1918
|
return state === void 0 ? !0 : state;
|
|
@@ -2201,7 +2075,9 @@ function createWithUndoRedo(options) {
|
|
|
2201
2075
|
}
|
|
2202
2076
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2203
2077
|
debugVerbose$3 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
|
|
2204
|
-
const transformedOperation =
|
|
2078
|
+
const transformedOperation = {
|
|
2079
|
+
...operation
|
|
2080
|
+
};
|
|
2205
2081
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
2206
2082
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
2207
2083
|
_key: blk._key
|
|
@@ -2221,7 +2097,6 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2221
2097
|
return !operationTargetBlock || !isEqual({
|
|
2222
2098
|
_key: operationTargetBlock._key
|
|
2223
2099
|
}, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
2224
|
-
var _a, _b, _c, _d;
|
|
2225
2100
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
|
|
2226
2101
|
const {
|
|
2227
2102
|
diffs
|
|
@@ -2230,7 +2105,15 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2230
2105
|
const [diffType, text] = diff2;
|
|
2231
2106
|
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
|
|
2232
2107
|
}), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
|
|
2233
|
-
const currentFocus =
|
|
2108
|
+
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2109
|
+
...transformedOperation.properties.focus
|
|
2110
|
+
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
2111
|
+
...transformedOperation.properties.anchor
|
|
2112
|
+
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
2113
|
+
...transformedOperation.newProperties.focus
|
|
2114
|
+
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
2115
|
+
...transformedOperation.newProperties.anchor
|
|
2116
|
+
} : void 0;
|
|
2234
2117
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2235
2118
|
point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
|
|
2236
2119
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2246,14 +2129,23 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2246
2129
|
return [transformedOperation];
|
|
2247
2130
|
}
|
|
2248
2131
|
function adjustBlockPath(operation, level, blockIndex) {
|
|
2249
|
-
|
|
2250
|
-
|
|
2132
|
+
const transformedOperation = {
|
|
2133
|
+
...operation
|
|
2134
|
+
};
|
|
2251
2135
|
if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
|
|
2252
2136
|
const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
|
|
2253
2137
|
transformedOperation.path = newPath;
|
|
2254
2138
|
}
|
|
2255
2139
|
if (transformedOperation.type === "set_selection") {
|
|
2256
|
-
const currentFocus =
|
|
2140
|
+
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2141
|
+
...transformedOperation.properties.focus
|
|
2142
|
+
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
2143
|
+
...transformedOperation.properties.anchor
|
|
2144
|
+
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
2145
|
+
...transformedOperation.newProperties.focus
|
|
2146
|
+
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
2147
|
+
...transformedOperation.newProperties.anchor
|
|
2148
|
+
} : void 0;
|
|
2257
2149
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2258
2150
|
point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
|
|
2259
2151
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2274,27 +2166,18 @@ function withoutSaving(editor, fn) {
|
|
|
2274
2166
|
function createSelectOperation(editor) {
|
|
2275
2167
|
return {
|
|
2276
2168
|
type: "set_selection",
|
|
2277
|
-
properties:
|
|
2278
|
-
|
|
2169
|
+
properties: {
|
|
2170
|
+
...editor.selection
|
|
2171
|
+
},
|
|
2172
|
+
newProperties: {
|
|
2173
|
+
...editor.selection
|
|
2174
|
+
}
|
|
2279
2175
|
};
|
|
2280
2176
|
}
|
|
2281
2177
|
function findOperationTargetBlock(editor, operation) {
|
|
2282
2178
|
let block;
|
|
2283
2179
|
return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
|
|
2284
2180
|
}
|
|
2285
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name), __await = function(promise, isYieldStar) {
|
|
2286
|
-
this[0] = promise, this[1] = isYieldStar;
|
|
2287
|
-
}, __asyncGenerator = (__this, __arguments, generator) => {
|
|
2288
|
-
var resume = (k, v, yes, no) => {
|
|
2289
|
-
try {
|
|
2290
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
2291
|
-
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
2292
|
-
} catch (e) {
|
|
2293
|
-
no(e);
|
|
2294
|
-
}
|
|
2295
|
-
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
2296
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
2297
|
-
}, __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
2298
2181
|
const syncValueCallback = ({
|
|
2299
2182
|
sendBack,
|
|
2300
2183
|
input
|
|
@@ -2345,10 +2228,7 @@ const syncValueCallback = ({
|
|
|
2345
2228
|
}) => context.initialValueSynced,
|
|
2346
2229
|
"is busy": ({
|
|
2347
2230
|
context
|
|
2348
|
-
}) =>
|
|
2349
|
-
var _a;
|
|
2350
|
-
return !context.readOnly && (context.isProcessingLocalChanges || ((_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1));
|
|
2351
|
-
},
|
|
2231
|
+
}) => !context.readOnly && (context.isProcessingLocalChanges || (isChangingRemotely(context.slateEditor) ?? !1)),
|
|
2352
2232
|
"value changed while syncing": ({
|
|
2353
2233
|
context,
|
|
2354
2234
|
event
|
|
@@ -2533,33 +2413,22 @@ async function updateValue({
|
|
|
2533
2413
|
});
|
|
2534
2414
|
isChanged = !0;
|
|
2535
2415
|
}
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2553
|
-
}
|
|
2554
|
-
} catch (temp2) {
|
|
2555
|
-
error = [temp2];
|
|
2556
|
-
} finally {
|
|
2557
|
-
try {
|
|
2558
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2559
|
-
} finally {
|
|
2560
|
-
if (error)
|
|
2561
|
-
throw error[0];
|
|
2562
|
-
}
|
|
2416
|
+
for await (const [currentBlock, currentBlockIndex] of getBlocks({
|
|
2417
|
+
slateValue: slateValueFromProps,
|
|
2418
|
+
streamBlocks
|
|
2419
|
+
})) {
|
|
2420
|
+
const {
|
|
2421
|
+
blockChanged,
|
|
2422
|
+
blockValid
|
|
2423
|
+
} = syncBlock({
|
|
2424
|
+
context,
|
|
2425
|
+
sendBack,
|
|
2426
|
+
block: currentBlock,
|
|
2427
|
+
index: currentBlockIndex,
|
|
2428
|
+
slateEditor,
|
|
2429
|
+
value
|
|
2430
|
+
});
|
|
2431
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2563
2432
|
}
|
|
2564
2433
|
resolve();
|
|
2565
2434
|
});
|
|
@@ -2609,28 +2478,13 @@ async function updateValue({
|
|
|
2609
2478
|
value
|
|
2610
2479
|
});
|
|
2611
2480
|
}
|
|
2612
|
-
function getBlocks(
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
for (var iter = __forAwait(slateValue), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = !1) {
|
|
2620
|
-
const block = temp.value;
|
|
2621
|
-
streamBlocks && (yield new __await(new Promise((resolve) => setTimeout(resolve, 0)))), yield [block, index], index++;
|
|
2622
|
-
}
|
|
2623
|
-
} catch (temp2) {
|
|
2624
|
-
error = [temp2];
|
|
2625
|
-
} finally {
|
|
2626
|
-
try {
|
|
2627
|
-
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2628
|
-
} finally {
|
|
2629
|
-
if (error)
|
|
2630
|
-
throw error[0];
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
});
|
|
2481
|
+
async function* getBlocks({
|
|
2482
|
+
slateValue,
|
|
2483
|
+
streamBlocks
|
|
2484
|
+
}) {
|
|
2485
|
+
let index = 0;
|
|
2486
|
+
for await (const block of slateValue)
|
|
2487
|
+
streamBlocks && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
2634
2488
|
}
|
|
2635
2489
|
function syncBlock({
|
|
2636
2490
|
context,
|
|
@@ -2645,15 +2499,14 @@ function syncBlock({
|
|
|
2645
2499
|
return Editor.withoutNormalizing(slateEditor, () => {
|
|
2646
2500
|
withRemoteChanges(slateEditor, () => {
|
|
2647
2501
|
withoutPatching(slateEditor, () => {
|
|
2648
|
-
var _a, _b, _c, _d, _e;
|
|
2649
2502
|
if (hasChanges && blockValid) {
|
|
2650
2503
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2651
|
-
!validation.valid &&
|
|
2504
|
+
!validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${validation.resolution?.description}`), validation.resolution.patches.forEach((patch) => {
|
|
2652
2505
|
sendBack({
|
|
2653
2506
|
type: "patch",
|
|
2654
2507
|
patch
|
|
2655
2508
|
});
|
|
2656
|
-
})), validation.valid ||
|
|
2509
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
2657
2510
|
type: "invalid value",
|
|
2658
2511
|
resolution: validation.resolution,
|
|
2659
2512
|
value
|
|
@@ -2661,7 +2514,7 @@ function syncBlock({
|
|
|
2661
2514
|
}
|
|
2662
2515
|
if (!oldBlock && blockValid) {
|
|
2663
2516
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2664
|
-
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid ||
|
|
2517
|
+
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2665
2518
|
at: [currentBlockIndex]
|
|
2666
2519
|
}) : (debug$i("Invalid", validation), sendBack({
|
|
2667
2520
|
type: "invalid value",
|
|
@@ -2695,9 +2548,9 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2695
2548
|
at: [currentBlockIndex, childIndex]
|
|
2696
2549
|
}));
|
|
2697
2550
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2698
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild
|
|
2551
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2699
2552
|
if (isChildChanged)
|
|
2700
|
-
if (currentBlockChild._key ===
|
|
2553
|
+
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2701
2554
|
debug$i("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2702
2555
|
at: path
|
|
2703
2556
|
});
|
|
@@ -2824,14 +2677,6 @@ function _temp(s) {
|
|
|
2824
2677
|
return s.context.value;
|
|
2825
2678
|
}
|
|
2826
2679
|
Synchronizer.displayName = "Synchronizer";
|
|
2827
|
-
var __defProp$l = Object.defineProperty, __defProps$f = Object.defineProperties, __getOwnPropDescs$f = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$l = Object.getOwnPropertySymbols, __hasOwnProp$l = Object.prototype.hasOwnProperty, __propIsEnum$l = Object.prototype.propertyIsEnumerable, __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$l = (a, b) => {
|
|
2828
|
-
for (var prop in b || (b = {}))
|
|
2829
|
-
__hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2830
|
-
if (__getOwnPropSymbols$l)
|
|
2831
|
-
for (var prop of __getOwnPropSymbols$l(b))
|
|
2832
|
-
__propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2833
|
-
return a;
|
|
2834
|
-
}, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
|
|
2835
2680
|
const debug$g = debugWithName("operationToPatches");
|
|
2836
2681
|
function createOperationToPatches(types) {
|
|
2837
2682
|
const textBlockName = types.block.name;
|
|
@@ -2871,7 +2716,10 @@ function createOperationToPatches(types) {
|
|
|
2871
2716
|
const block = editor.children[operation.path[0]];
|
|
2872
2717
|
if (typeof block._key != "string")
|
|
2873
2718
|
throw new Error("Expected block to have a _key");
|
|
2874
|
-
const setNode = omitBy(
|
|
2719
|
+
const setNode = omitBy({
|
|
2720
|
+
...editor.children[operation.path[0]],
|
|
2721
|
+
...operation.newProperties
|
|
2722
|
+
}, isUndefined);
|
|
2875
2723
|
return [set(fromSlateValue([setNode], textBlockName)[0], [{
|
|
2876
2724
|
_key: block._key
|
|
2877
2725
|
}])];
|
|
@@ -2906,12 +2754,14 @@ function createOperationToPatches(types) {
|
|
|
2906
2754
|
function insertNodePatch(editor, operation, beforeValue) {
|
|
2907
2755
|
const block = beforeValue[operation.path[0]], isTextBlock = editor.isTextBlock(block);
|
|
2908
2756
|
if (operation.path.length === 1) {
|
|
2909
|
-
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block
|
|
2757
|
+
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
|
|
2910
2758
|
return targetKey ? [insert([fromSlateValue([operation.node], textBlockName)[0]], position, [{
|
|
2911
2759
|
_key: targetKey
|
|
2912
2760
|
}])] : [setIfMissing(beforeValue, []), insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
|
|
2913
2761
|
} else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
|
|
2914
|
-
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node =
|
|
2762
|
+
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
|
|
2763
|
+
...operation.node
|
|
2764
|
+
};
|
|
2915
2765
|
!node._type && Text.isText(node) && (node._type = "span", node.marks = []);
|
|
2916
2766
|
const child = fromSlateValue([{
|
|
2917
2767
|
_key: "bogus",
|
|
@@ -2950,9 +2800,10 @@ function createOperationToPatches(types) {
|
|
|
2950
2800
|
if (operation.path.length === 2) {
|
|
2951
2801
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
2952
2802
|
if (editor.isTextSpan(splitSpan)) {
|
|
2953
|
-
const targetSpans = fromSlateValue([
|
|
2803
|
+
const targetSpans = fromSlateValue([{
|
|
2804
|
+
...splitBlock,
|
|
2954
2805
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
2955
|
-
}
|
|
2806
|
+
}], textBlockName)[0].children;
|
|
2956
2807
|
patches.push(insert(targetSpans, "after", [{
|
|
2957
2808
|
_key: splitBlock._key
|
|
2958
2809
|
}, "children", {
|
|
@@ -2988,7 +2839,7 @@ function createOperationToPatches(types) {
|
|
|
2988
2839
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2989
2840
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
2990
2841
|
if (operation.path.length === 1)
|
|
2991
|
-
if (block
|
|
2842
|
+
if (block?._key) {
|
|
2992
2843
|
const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
|
|
2993
2844
|
patches.push(set(newBlock, [{
|
|
2994
2845
|
_key: newBlock._key
|
|
@@ -3260,7 +3111,6 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3260
3111
|
apply: apply2
|
|
3261
3112
|
} = editor;
|
|
3262
3113
|
return editor.apply = (operation) => {
|
|
3263
|
-
var _a;
|
|
3264
3114
|
if (editorActor.getSnapshot().matches({
|
|
3265
3115
|
"edit mode": "read only"
|
|
3266
3116
|
})) {
|
|
@@ -3275,19 +3125,11 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3275
3125
|
apply2(operation);
|
|
3276
3126
|
return;
|
|
3277
3127
|
}
|
|
3278
|
-
const rows =
|
|
3128
|
+
const rows = editorActor.getSnapshot().context.maxBlocks ?? -1;
|
|
3279
3129
|
rows > 0 && editor.children.length >= rows && (operation.type === "insert_node" || operation.type === "split_node") && operation.path.length === 1 || apply2(operation);
|
|
3280
3130
|
}, editor;
|
|
3281
3131
|
};
|
|
3282
3132
|
}
|
|
3283
|
-
var __defProp$k = Object.defineProperty, __defProps$e = Object.defineProperties, __getOwnPropDescs$e = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$k = Object.getOwnPropertySymbols, __hasOwnProp$k = Object.prototype.hasOwnProperty, __propIsEnum$k = Object.prototype.propertyIsEnumerable, __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$k = (a, b) => {
|
|
3284
|
-
for (var prop in b || (b = {}))
|
|
3285
|
-
__hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3286
|
-
if (__getOwnPropSymbols$k)
|
|
3287
|
-
for (var prop of __getOwnPropSymbols$k(b))
|
|
3288
|
-
__propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3289
|
-
return a;
|
|
3290
|
-
}, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
3291
3133
|
function createWithObjectKeys(editorActor, schemaTypes) {
|
|
3292
3134
|
return function(editor) {
|
|
3293
3135
|
const {
|
|
@@ -3304,19 +3146,23 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3304
3146
|
return;
|
|
3305
3147
|
}
|
|
3306
3148
|
if (operation.type === "split_node") {
|
|
3307
|
-
apply2(
|
|
3308
|
-
|
|
3149
|
+
apply2({
|
|
3150
|
+
...operation,
|
|
3151
|
+
properties: {
|
|
3152
|
+
...operation.properties,
|
|
3309
3153
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3310
|
-
}
|
|
3311
|
-
})
|
|
3154
|
+
}
|
|
3155
|
+
});
|
|
3312
3156
|
return;
|
|
3313
3157
|
}
|
|
3314
3158
|
if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
|
|
3315
|
-
apply2(
|
|
3316
|
-
|
|
3159
|
+
apply2({
|
|
3160
|
+
...operation,
|
|
3161
|
+
node: {
|
|
3162
|
+
...operation.node,
|
|
3317
3163
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3318
|
-
}
|
|
3319
|
-
})
|
|
3164
|
+
}
|
|
3165
|
+
});
|
|
3320
3166
|
return;
|
|
3321
3167
|
}
|
|
3322
3168
|
apply2(operation);
|
|
@@ -3353,22 +3199,6 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3353
3199
|
}, editor;
|
|
3354
3200
|
};
|
|
3355
3201
|
}
|
|
3356
|
-
var __defProp$j = Object.defineProperty, __defProps$d = Object.defineProperties, __getOwnPropDescs$d = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$j = Object.getOwnPropertySymbols, __hasOwnProp$j = Object.prototype.hasOwnProperty, __propIsEnum$j = Object.prototype.propertyIsEnumerable, __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$j = (a, b) => {
|
|
3357
|
-
for (var prop in b || (b = {}))
|
|
3358
|
-
__hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3359
|
-
if (__getOwnPropSymbols$j)
|
|
3360
|
-
for (var prop of __getOwnPropSymbols$j(b))
|
|
3361
|
-
__propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3362
|
-
return a;
|
|
3363
|
-
}, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
|
|
3364
|
-
var target = {};
|
|
3365
|
-
for (var prop in source)
|
|
3366
|
-
__hasOwnProp$j.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
3367
|
-
if (source != null && __getOwnPropSymbols$j)
|
|
3368
|
-
for (var prop of __getOwnPropSymbols$j(source))
|
|
3369
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$j.call(source, prop) && (target[prop] = source[prop]);
|
|
3370
|
-
return target;
|
|
3371
|
-
};
|
|
3372
3202
|
const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
|
|
3373
3203
|
function createApplyPatch(schemaTypes) {
|
|
3374
3204
|
return (editor, patch) => {
|
|
@@ -3458,9 +3288,10 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3458
3288
|
} = patch;
|
|
3459
3289
|
if (!targetChild || !targetChildPath)
|
|
3460
3290
|
return debug$f("Child not found"), !1;
|
|
3461
|
-
const childrenToInsert = targetBlock && toSlateValue([
|
|
3291
|
+
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3292
|
+
...targetBlock,
|
|
3462
3293
|
children: items
|
|
3463
|
-
}
|
|
3294
|
+
}], {
|
|
3464
3295
|
schemaTypes
|
|
3465
3296
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3466
3297
|
return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
@@ -3505,19 +3336,21 @@ function setPatch(editor, patch) {
|
|
|
3505
3336
|
return !0;
|
|
3506
3337
|
} else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3507
3338
|
debug$f("Setting block property");
|
|
3508
|
-
const
|
|
3509
|
-
children
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3339
|
+
const {
|
|
3340
|
+
children,
|
|
3341
|
+
...nextRest
|
|
3342
|
+
} = value, {
|
|
3343
|
+
children: prevChildren,
|
|
3344
|
+
...prevRest
|
|
3345
|
+
} = block || {
|
|
3513
3346
|
children: void 0
|
|
3514
|
-
}
|
|
3515
|
-
"children"
|
|
3516
|
-
]);
|
|
3347
|
+
};
|
|
3517
3348
|
editor.apply({
|
|
3518
3349
|
type: "set_node",
|
|
3519
3350
|
path: blockPath,
|
|
3520
|
-
properties:
|
|
3351
|
+
properties: {
|
|
3352
|
+
...prevRest
|
|
3353
|
+
},
|
|
3521
3354
|
newProperties: nextRest
|
|
3522
3355
|
}), debug$f("Setting children"), block.children.forEach((c2, cIndex) => {
|
|
3523
3356
|
editor.apply({
|
|
@@ -3534,9 +3367,10 @@ function setPatch(editor, patch) {
|
|
|
3534
3367
|
});
|
|
3535
3368
|
} else if (block && "value" in block) {
|
|
3536
3369
|
const newVal = applyAll([block.value], [patch])[0];
|
|
3537
|
-
return Transforms.setNodes(editor,
|
|
3370
|
+
return Transforms.setNodes(editor, {
|
|
3371
|
+
...block,
|
|
3538
3372
|
value: newVal
|
|
3539
|
-
}
|
|
3373
|
+
}, {
|
|
3540
3374
|
at: blockPath
|
|
3541
3375
|
}), !0;
|
|
3542
3376
|
}
|
|
@@ -3619,7 +3453,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3619
3453
|
block,
|
|
3620
3454
|
child,
|
|
3621
3455
|
blockPath,
|
|
3622
|
-
childPath: blockPath
|
|
3456
|
+
childPath: blockPath?.concat(childIndex)
|
|
3623
3457
|
} : {
|
|
3624
3458
|
block,
|
|
3625
3459
|
blockPath,
|
|
@@ -3627,14 +3461,6 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3627
3461
|
childPath: void 0
|
|
3628
3462
|
};
|
|
3629
3463
|
}
|
|
3630
|
-
var __defProp$i = Object.defineProperty, __defProps$c = Object.defineProperties, __getOwnPropDescs$c = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$i = Object.getOwnPropertySymbols, __hasOwnProp$i = Object.prototype.hasOwnProperty, __propIsEnum$i = Object.prototype.propertyIsEnumerable, __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$i = (a, b) => {
|
|
3631
|
-
for (var prop in b || (b = {}))
|
|
3632
|
-
__hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3633
|
-
if (__getOwnPropSymbols$i)
|
|
3634
|
-
for (var prop of __getOwnPropSymbols$i(b))
|
|
3635
|
-
__propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3636
|
-
return a;
|
|
3637
|
-
}, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
3638
3464
|
const debug$e = debugWithName("plugin:withPatches");
|
|
3639
3465
|
function createWithPatches({
|
|
3640
3466
|
editorActor,
|
|
@@ -3719,9 +3545,10 @@ function createWithPatches({
|
|
|
3719
3545
|
})), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0 && patches.forEach((patch) => {
|
|
3720
3546
|
editorActor.send({
|
|
3721
3547
|
type: "patch",
|
|
3722
|
-
patch:
|
|
3548
|
+
patch: {
|
|
3549
|
+
...patch,
|
|
3723
3550
|
origin: "local"
|
|
3724
|
-
}
|
|
3551
|
+
}
|
|
3725
3552
|
});
|
|
3726
3553
|
}), editor;
|
|
3727
3554
|
}, editor;
|
|
@@ -3834,14 +3661,6 @@ function getNextSpan({
|
|
|
3834
3661
|
}
|
|
3835
3662
|
return nextSpan;
|
|
3836
3663
|
}
|
|
3837
|
-
var __defProp$h = Object.defineProperty, __defProps$b = Object.defineProperties, __getOwnPropDescs$b = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$h = Object.getOwnPropertySymbols, __hasOwnProp$h = Object.prototype.hasOwnProperty, __propIsEnum$h = Object.prototype.propertyIsEnumerable, __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$h = (a, b) => {
|
|
3838
|
-
for (var prop in b || (b = {}))
|
|
3839
|
-
__hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3840
|
-
if (__getOwnPropSymbols$h)
|
|
3841
|
-
for (var prop of __getOwnPropSymbols$h(b))
|
|
3842
|
-
__propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3843
|
-
return a;
|
|
3844
|
-
}, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
|
|
3845
3664
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
3846
3665
|
function createWithPortableTextMarkModel(editorActor, types) {
|
|
3847
3666
|
return function(editor) {
|
|
@@ -3850,19 +3669,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3850
3669
|
normalizeNode
|
|
3851
3670
|
} = editor, decorators = types.decorators.map((t) => t.value);
|
|
3852
3671
|
return editor.normalizeNode = (nodeEntry) => {
|
|
3853
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3854
3672
|
const [node, path] = nodeEntry;
|
|
3855
3673
|
if (editor.isTextBlock(node)) {
|
|
3856
3674
|
const children = Node.children(editor, path);
|
|
3857
3675
|
for (const [child, childPath] of children) {
|
|
3858
3676
|
const nextNode = node.children[childPath[1] + 1];
|
|
3859
|
-
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && (
|
|
3860
|
-
var _a2;
|
|
3861
|
-
return (_a2 = nextNode.marks) == null ? void 0 : _a2.includes(mark);
|
|
3862
|
-
}) && (_b = nextNode.marks) != null && _b.every((mark) => {
|
|
3863
|
-
var _a2;
|
|
3864
|
-
return (_a2 = child.marks) == null ? void 0 : _a2.includes(mark);
|
|
3865
|
-
})) {
|
|
3677
|
+
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3866
3678
|
debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3867
3679
|
type: "normalizing"
|
|
3868
3680
|
}), Transforms.mergeNodes(editor, {
|
|
@@ -3900,12 +3712,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3900
3712
|
return;
|
|
3901
3713
|
}
|
|
3902
3714
|
if (editor.isTextSpan(node)) {
|
|
3903
|
-
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations =
|
|
3715
|
+
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3904
3716
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3905
3717
|
debug$b("Removing annotations from empty span node"), editorActor.send({
|
|
3906
3718
|
type: "normalizing"
|
|
3907
3719
|
}), Transforms.setNodes(editor, {
|
|
3908
|
-
marks:
|
|
3720
|
+
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
3909
3721
|
}, {
|
|
3910
3722
|
at: path
|
|
3911
3723
|
}), editorActor.send({
|
|
@@ -3918,10 +3730,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3918
3730
|
const decorators2 = types.decorators.map((decorator) => decorator.value);
|
|
3919
3731
|
for (const [child, childPath] of Node.children(editor, path))
|
|
3920
3732
|
if (editor.isTextSpan(child)) {
|
|
3921
|
-
const marks =
|
|
3922
|
-
var _a2;
|
|
3923
|
-
return !decorators2.includes(mark) && !((_a2 = node.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3924
|
-
});
|
|
3733
|
+
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3925
3734
|
if (orphanedAnnotations.length > 0) {
|
|
3926
3735
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3927
3736
|
type: "normalizing"
|
|
@@ -3939,10 +3748,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3939
3748
|
if (editor.isTextSpan(node)) {
|
|
3940
3749
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath);
|
|
3941
3750
|
if (editor.isTextBlock(block)) {
|
|
3942
|
-
const decorators2 = types.decorators.map((decorator) => decorator.value), marks =
|
|
3943
|
-
var _a2;
|
|
3944
|
-
return !decorators2.includes(mark) && !((_a2 = block.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3945
|
-
});
|
|
3751
|
+
const decorators2 = types.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3946
3752
|
if (orphanedAnnotations.length > 0) {
|
|
3947
3753
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3948
3754
|
type: "normalizing"
|
|
@@ -3958,7 +3764,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3958
3764
|
}
|
|
3959
3765
|
}
|
|
3960
3766
|
if (editor.isTextBlock(node)) {
|
|
3961
|
-
const markDefs =
|
|
3767
|
+
const markDefs = node.markDefs ?? [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
|
|
3962
3768
|
for (const markDef of markDefs)
|
|
3963
3769
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3964
3770
|
if (markDefs.length !== newMarkDefs.length) {
|
|
@@ -3991,7 +3797,6 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3991
3797
|
}
|
|
3992
3798
|
normalizeNode(nodeEntry);
|
|
3993
3799
|
}, editor.apply = (op) => {
|
|
3994
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
3995
3800
|
if (isChangingRemotely(editor)) {
|
|
3996
3801
|
apply2(op);
|
|
3997
3802
|
return;
|
|
@@ -4009,17 +3814,17 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4009
3814
|
focus: op.newProperties.focus
|
|
4010
3815
|
});
|
|
4011
3816
|
if (previousSelectionIsCollapsed && newSelectionIsCollapsed) {
|
|
4012
|
-
const focusSpan =
|
|
3817
|
+
const focusSpan = Array.from(Editor.nodes(editor, {
|
|
4013
3818
|
mode: "lowest",
|
|
4014
3819
|
at: op.properties.focus,
|
|
4015
3820
|
match: (n) => editor.isTextSpan(n),
|
|
4016
3821
|
voids: !1
|
|
4017
|
-
}))[0]
|
|
3822
|
+
}))[0]?.[0], newFocusSpan = Array.from(Editor.nodes(editor, {
|
|
4018
3823
|
mode: "lowest",
|
|
4019
3824
|
at: op.newProperties.focus,
|
|
4020
3825
|
match: (n) => editor.isTextSpan(n),
|
|
4021
3826
|
voids: !1
|
|
4022
|
-
}))[0]
|
|
3827
|
+
}))[0]?.[0], movedToNextSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] + 1 && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] - 1 && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
|
|
4023
3828
|
if (movedToNextSpan || movedToPreviousSpan)
|
|
4024
3829
|
return;
|
|
4025
3830
|
}
|
|
@@ -4035,29 +3840,32 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4035
3840
|
editor,
|
|
4036
3841
|
blockPath,
|
|
4037
3842
|
spanPath: op.path
|
|
4038
|
-
}), previousSpanAnnotations = previousSpan ?
|
|
3843
|
+
}), previousSpanAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], nextSpan = getNextSpan({
|
|
4039
3844
|
editor,
|
|
4040
3845
|
blockPath,
|
|
4041
3846
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
4042
|
-
}), nextSpanAnnotations = nextSpan ?
|
|
4043
|
-
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4044
|
-
Transforms.insertNodes(editor,
|
|
4045
|
-
|
|
4046
|
-
|
|
3847
|
+
}), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [], atTheEndOfAnnotation = annotationsEnding.length > 0;
|
|
3848
|
+
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
|
|
3849
|
+
Transforms.insertNodes(editor, {
|
|
3850
|
+
...op.node,
|
|
3851
|
+
marks: op.node.marks?.filter((mark) => !annotationsEnding.includes(mark)) ?? []
|
|
3852
|
+
});
|
|
4047
3853
|
return;
|
|
4048
3854
|
}
|
|
4049
|
-
const annotationsStarting =
|
|
4050
|
-
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4051
|
-
Transforms.insertNodes(editor,
|
|
4052
|
-
|
|
4053
|
-
|
|
3855
|
+
const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3856
|
+
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
|
|
3857
|
+
Transforms.insertNodes(editor, {
|
|
3858
|
+
...op.node,
|
|
3859
|
+
marks: op.node.marks?.filter((mark) => !annotationsStarting.includes(mark)) ?? []
|
|
3860
|
+
});
|
|
4054
3861
|
return;
|
|
4055
3862
|
}
|
|
4056
|
-
const nextSpanDecorators =
|
|
4057
|
-
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4058
|
-
Transforms.insertNodes(editor,
|
|
3863
|
+
const nextSpanDecorators = nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? [];
|
|
3864
|
+
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.length === 0) {
|
|
3865
|
+
Transforms.insertNodes(editor, {
|
|
3866
|
+
...op.node,
|
|
4059
3867
|
marks: nextSpanDecorators
|
|
4060
|
-
})
|
|
3868
|
+
});
|
|
4061
3869
|
return;
|
|
4062
3870
|
}
|
|
4063
3871
|
}
|
|
@@ -4069,12 +3877,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4069
3877
|
if (selection && collapsedSelection) {
|
|
4070
3878
|
const [_block, blockPath] = Editor.node(editor, selection, {
|
|
4071
3879
|
depth: 1
|
|
4072
|
-
}), [span, spanPath] =
|
|
3880
|
+
}), [span, spanPath] = Array.from(Editor.nodes(editor, {
|
|
4073
3881
|
mode: "lowest",
|
|
4074
3882
|
at: selection.focus,
|
|
4075
3883
|
match: (n) => editor.isTextSpan(n),
|
|
4076
3884
|
voids: !1
|
|
4077
|
-
}))[0]
|
|
3885
|
+
}))[0] ?? [void 0, void 0], marks = span.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = selection.anchor.offset === 0, atTheEndOfSpan = selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
|
|
4078
3886
|
editor,
|
|
4079
3887
|
blockPath,
|
|
4080
3888
|
spanPath
|
|
@@ -4082,7 +3890,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4082
3890
|
editor,
|
|
4083
3891
|
blockPath,
|
|
4084
3892
|
spanPath
|
|
4085
|
-
}), nextSpanAnnotations =
|
|
3893
|
+
}), nextSpanAnnotations = nextSpan?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
|
|
4086
3894
|
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4087
3895
|
if (atTheBeginningOfSpan) {
|
|
4088
3896
|
if (previousSpanHasSameMarks) {
|
|
@@ -4090,7 +3898,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4090
3898
|
_type: "span",
|
|
4091
3899
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4092
3900
|
text: op.text,
|
|
4093
|
-
marks:
|
|
3901
|
+
marks: previousSpan?.marks ?? []
|
|
4094
3902
|
});
|
|
4095
3903
|
return;
|
|
4096
3904
|
} else if (previousSpanHasSameAnnotations) {
|
|
@@ -4098,7 +3906,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4098
3906
|
_type: "span",
|
|
4099
3907
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4100
3908
|
text: op.text,
|
|
4101
|
-
marks:
|
|
3909
|
+
marks: previousSpan?.marks ?? []
|
|
4102
3910
|
});
|
|
4103
3911
|
return;
|
|
4104
3912
|
} else if (previousSpanHasSameAnnotation) {
|
|
@@ -4120,7 +3928,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4120
3928
|
_type: "span",
|
|
4121
3929
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4122
3930
|
text: op.text,
|
|
4123
|
-
marks:
|
|
3931
|
+
marks: nextSpan?.marks ?? []
|
|
4124
3932
|
});
|
|
4125
3933
|
return;
|
|
4126
3934
|
}
|
|
@@ -4140,7 +3948,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4140
3948
|
_type: "span",
|
|
4141
3949
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4142
3950
|
text: op.text,
|
|
4143
|
-
marks: previousSpanHasAnnotations ? [] : (
|
|
3951
|
+
marks: previousSpanHasAnnotations ? [] : (previousSpan.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
4144
3952
|
});
|
|
4145
3953
|
return;
|
|
4146
3954
|
}
|
|
@@ -4153,7 +3961,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4153
3961
|
if (selection && Range.isExpanded(selection)) {
|
|
4154
3962
|
const [block, blockPath] = Editor.node(editor, selection, {
|
|
4155
3963
|
depth: 1
|
|
4156
|
-
}), [span, spanPath] =
|
|
3964
|
+
}), [span, spanPath] = Array.from(Editor.nodes(editor, {
|
|
4157
3965
|
mode: "lowest",
|
|
4158
3966
|
at: {
|
|
4159
3967
|
path: op.path,
|
|
@@ -4161,9 +3969,9 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4161
3969
|
},
|
|
4162
3970
|
match: (n) => editor.isTextSpan(n),
|
|
4163
3971
|
voids: !1
|
|
4164
|
-
}))[0]
|
|
3972
|
+
}))[0] ?? [void 0, void 0];
|
|
4165
3973
|
if (span && block && isPortableTextBlock(block)) {
|
|
4166
|
-
const markDefs =
|
|
3974
|
+
const markDefs = block.markDefs ?? [], marks = span.marks ?? [], spanHasAnnotations = marks.some((mark) => markDefs.find((markDef) => markDef._key === mark)), deletingFromTheEnd = op.offset + op.text.length === span.text.length, deletingAllText = op.offset === 0 && deletingFromTheEnd, previousSpan = getPreviousSpan({
|
|
4167
3975
|
editor,
|
|
4168
3976
|
blockPath,
|
|
4169
3977
|
spanPath
|
|
@@ -4171,9 +3979,11 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4171
3979
|
editor,
|
|
4172
3980
|
blockPath,
|
|
4173
3981
|
spanPath
|
|
4174
|
-
}), previousSpanHasSameAnnotation = previousSpan ?
|
|
3982
|
+
}), previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? nextSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
|
|
4175
3983
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
4176
|
-
const marksWithoutAnnotationMarks = (
|
|
3984
|
+
const marksWithoutAnnotationMarks = ({
|
|
3985
|
+
...Editor.marks(editor) || {}
|
|
3986
|
+
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
4177
3987
|
Editor.withoutNormalizing(editor, () => {
|
|
4178
3988
|
apply2(op), Transforms.setNodes(editor, {
|
|
4179
3989
|
marks: marksWithoutAnnotationMarks
|
|
@@ -4206,7 +4016,6 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4206
4016
|
const addDecoratorActionImplementation = ({
|
|
4207
4017
|
action
|
|
4208
4018
|
}) => {
|
|
4209
|
-
var _a;
|
|
4210
4019
|
const editor = action.editor, mark = action.decorator;
|
|
4211
4020
|
if (editor.selection) {
|
|
4212
4021
|
if (Range.isExpanded(editor.selection)) {
|
|
@@ -4219,10 +4028,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4219
4028
|
at: editor.selection,
|
|
4220
4029
|
match: Text.isText
|
|
4221
4030
|
})] : [];
|
|
4222
|
-
splitTextNodes.length > 1 && splitTextNodes.every((node) => {
|
|
4223
|
-
var _a2;
|
|
4224
|
-
return (_a2 = node[0].marks) == null ? void 0 : _a2.includes(mark);
|
|
4225
|
-
}) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4031
|
+
splitTextNodes.length > 1 && splitTextNodes.every((node) => node[0].marks?.includes(mark)) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4226
4032
|
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
4227
4033
|
Transforms.setNodes(editor, {
|
|
4228
4034
|
marks
|
|
@@ -4238,7 +4044,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4238
4044
|
depth: 1
|
|
4239
4045
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4240
4046
|
if (lonelyEmptySpan) {
|
|
4241
|
-
const existingMarks =
|
|
4047
|
+
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
4242
4048
|
Transforms.setNodes(editor, {
|
|
4243
4049
|
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
4244
4050
|
}, {
|
|
@@ -4246,9 +4052,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4246
4052
|
match: (node) => editor.isTextSpan(node)
|
|
4247
4053
|
});
|
|
4248
4054
|
} else {
|
|
4249
|
-
const existingMarks =
|
|
4055
|
+
const existingMarks = {
|
|
4056
|
+
...Editor.marks(editor) || {}
|
|
4057
|
+
}.marks || [], marks = {
|
|
4058
|
+
...Editor.marks(editor) || {},
|
|
4250
4059
|
marks: [...existingMarks, mark]
|
|
4251
|
-
}
|
|
4060
|
+
};
|
|
4252
4061
|
editor.marks = marks;
|
|
4253
4062
|
}
|
|
4254
4063
|
}
|
|
@@ -4257,7 +4066,6 @@ const addDecoratorActionImplementation = ({
|
|
|
4257
4066
|
}, removeDecoratorActionImplementation = ({
|
|
4258
4067
|
action
|
|
4259
4068
|
}) => {
|
|
4260
|
-
var _a;
|
|
4261
4069
|
const editor = action.editor, mark = action.decorator, {
|
|
4262
4070
|
selection
|
|
4263
4071
|
} = editor;
|
|
@@ -4284,7 +4092,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4284
4092
|
depth: 1
|
|
4285
4093
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4286
4094
|
if (lonelyEmptySpan) {
|
|
4287
|
-
const existingMarksWithoutDecorator = (
|
|
4095
|
+
const existingMarksWithoutDecorator = (lonelyEmptySpan.marks ?? []).filter((existingMark) => existingMark !== mark);
|
|
4288
4096
|
Transforms.setNodes(editor, {
|
|
4289
4097
|
marks: existingMarksWithoutDecorator
|
|
4290
4098
|
}, {
|
|
@@ -4292,9 +4100,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4292
4100
|
match: (node) => editor.isTextSpan(node)
|
|
4293
4101
|
});
|
|
4294
4102
|
} else {
|
|
4295
|
-
const existingMarks =
|
|
4103
|
+
const existingMarks = {
|
|
4104
|
+
...Editor.marks(editor) || {}
|
|
4105
|
+
}.marks || [], marks = {
|
|
4106
|
+
...Editor.marks(editor) || {},
|
|
4296
4107
|
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
4297
|
-
}
|
|
4108
|
+
};
|
|
4298
4109
|
editor.marks = {
|
|
4299
4110
|
marks: marks.marks,
|
|
4300
4111
|
_type: "span"
|
|
@@ -4313,10 +4124,11 @@ function isDecoratorActive({
|
|
|
4313
4124
|
at: editor.selection
|
|
4314
4125
|
}));
|
|
4315
4126
|
return selectedTextNodes.length === 0 ? !1 : Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
|
|
4316
|
-
var _a;
|
|
4317
4127
|
const [node] = n;
|
|
4318
|
-
return
|
|
4319
|
-
}) : (
|
|
4128
|
+
return node.marks?.includes(decorator);
|
|
4129
|
+
}) : ({
|
|
4130
|
+
...Editor.marks(editor) || {}
|
|
4131
|
+
}.marks || []).includes(decorator);
|
|
4320
4132
|
}
|
|
4321
4133
|
const toggleDecoratorActionImplementation = ({
|
|
4322
4134
|
context,
|
|
@@ -4376,14 +4188,6 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
4376
4188
|
}, editor;
|
|
4377
4189
|
};
|
|
4378
4190
|
}
|
|
4379
|
-
var __defProp$g = Object.defineProperty, __defProps$a = Object.defineProperties, __getOwnPropDescs$a = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$g = Object.getOwnPropertySymbols, __hasOwnProp$g = Object.prototype.hasOwnProperty, __propIsEnum$g = Object.prototype.propertyIsEnumerable, __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$g = (a, b) => {
|
|
4380
|
-
for (var prop in b || (b = {}))
|
|
4381
|
-
__hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4382
|
-
if (__getOwnPropSymbols$g)
|
|
4383
|
-
for (var prop of __getOwnPropSymbols$g(b))
|
|
4384
|
-
__propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4385
|
-
return a;
|
|
4386
|
-
}, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
4387
4191
|
const debug$9 = debugWithName("plugin:withSchemaTypes");
|
|
4388
4192
|
function createWithSchemaTypes({
|
|
4389
4193
|
editorActor,
|
|
@@ -4401,10 +4205,11 @@ function createWithSchemaTypes({
|
|
|
4401
4205
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4402
4206
|
editorActor.send({
|
|
4403
4207
|
type: "normalizing"
|
|
4404
|
-
}), Transforms.setNodes(editor,
|
|
4208
|
+
}), Transforms.setNodes(editor, {
|
|
4209
|
+
...span,
|
|
4405
4210
|
_type: schemaTypes.span.name,
|
|
4406
4211
|
_key: key
|
|
4407
|
-
}
|
|
4212
|
+
}, {
|
|
4408
4213
|
at: path
|
|
4409
4214
|
}), editorActor.send({
|
|
4410
4215
|
type: "done normalizing"
|
|
@@ -4429,14 +4234,6 @@ function createWithSchemaTypes({
|
|
|
4429
4234
|
}, editor;
|
|
4430
4235
|
};
|
|
4431
4236
|
}
|
|
4432
|
-
var __defProp$f = Object.defineProperty, __defProps$9 = Object.defineProperties, __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$f = Object.getOwnPropertySymbols, __hasOwnProp$f = Object.prototype.hasOwnProperty, __propIsEnum$f = Object.prototype.propertyIsEnumerable, __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$f = (a, b) => {
|
|
4433
|
-
for (var prop in b || (b = {}))
|
|
4434
|
-
__hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4435
|
-
if (__getOwnPropSymbols$f)
|
|
4436
|
-
for (var prop of __getOwnPropSymbols$f(b))
|
|
4437
|
-
__propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4438
|
-
return a;
|
|
4439
|
-
}, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
4440
4237
|
const debug$8 = debugWithName("plugin:withUtils");
|
|
4441
4238
|
function createWithUtils({
|
|
4442
4239
|
editorActor,
|
|
@@ -4460,26 +4257,29 @@ function createWithUtils({
|
|
|
4460
4257
|
} = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
|
|
4461
4258
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4462
4259
|
debug$8("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
|
|
4463
|
-
anchor:
|
|
4260
|
+
anchor: {
|
|
4261
|
+
...selection.anchor,
|
|
4464
4262
|
offset: newStartOffset
|
|
4465
|
-
}
|
|
4466
|
-
focus:
|
|
4263
|
+
},
|
|
4264
|
+
focus: {
|
|
4265
|
+
...selection.focus,
|
|
4467
4266
|
offset: newEndOffset
|
|
4468
|
-
}
|
|
4267
|
+
}
|
|
4469
4268
|
});
|
|
4470
4269
|
return;
|
|
4471
4270
|
}
|
|
4472
4271
|
debug$8("pteExpandToWord: Can't expand to word here");
|
|
4473
4272
|
}
|
|
4474
|
-
}, editor.pteCreateTextBlock = (options) => toSlateValue([
|
|
4273
|
+
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4475
4274
|
_type: schemaTypes.block.name,
|
|
4476
4275
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4477
|
-
style: schemaTypes.styles[0].value || "normal"
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4276
|
+
style: schemaTypes.styles[0].value || "normal",
|
|
4277
|
+
...options.listItem ? {
|
|
4278
|
+
listItem: options.listItem
|
|
4279
|
+
} : {},
|
|
4280
|
+
...options.level ? {
|
|
4281
|
+
level: options.level
|
|
4282
|
+
} : {},
|
|
4483
4283
|
markDefs: [],
|
|
4484
4284
|
children: [{
|
|
4485
4285
|
_type: "span",
|
|
@@ -4489,7 +4289,7 @@ function createWithUtils({
|
|
|
4489
4289
|
value
|
|
4490
4290
|
}) => value === decorator))
|
|
4491
4291
|
}]
|
|
4492
|
-
}
|
|
4292
|
+
}], {
|
|
4493
4293
|
schemaTypes
|
|
4494
4294
|
})[0], editor;
|
|
4495
4295
|
};
|
|
@@ -4535,14 +4335,6 @@ function createSlateEditor(config) {
|
|
|
4535
4335
|
};
|
|
4536
4336
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4537
4337
|
}
|
|
4538
|
-
var __defProp$e = Object.defineProperty, __defProps$8 = Object.defineProperties, __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$e = Object.getOwnPropertySymbols, __hasOwnProp$e = Object.prototype.hasOwnProperty, __propIsEnum$e = Object.prototype.propertyIsEnumerable, __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$e = (a, b) => {
|
|
4539
|
-
for (var prop in b || (b = {}))
|
|
4540
|
-
__hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4541
|
-
if (__getOwnPropSymbols$e)
|
|
4542
|
-
for (var prop of __getOwnPropSymbols$e(b))
|
|
4543
|
-
__propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4544
|
-
return a;
|
|
4545
|
-
}, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
4546
4338
|
const toggleListItemActionImplementation = ({
|
|
4547
4339
|
context,
|
|
4548
4340
|
action
|
|
@@ -4552,14 +4344,16 @@ const toggleListItemActionImplementation = ({
|
|
|
4552
4344
|
listItem: action.listItem
|
|
4553
4345
|
}) ? removeListItemActionImplementation({
|
|
4554
4346
|
context,
|
|
4555
|
-
action:
|
|
4347
|
+
action: {
|
|
4348
|
+
...action,
|
|
4556
4349
|
type: "list item.remove"
|
|
4557
|
-
}
|
|
4350
|
+
}
|
|
4558
4351
|
}) : addListItemActionImplementation({
|
|
4559
4352
|
context,
|
|
4560
|
-
action:
|
|
4353
|
+
action: {
|
|
4354
|
+
...action,
|
|
4561
4355
|
type: "list item.add"
|
|
4562
|
-
}
|
|
4356
|
+
}
|
|
4563
4357
|
});
|
|
4564
4358
|
}, removeListItemActionImplementation = ({
|
|
4565
4359
|
context,
|
|
@@ -4605,14 +4399,6 @@ function isListItemActive({
|
|
|
4605
4399
|
})];
|
|
4606
4400
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
4607
4401
|
}
|
|
4608
|
-
var __defProp$d = Object.defineProperty, __defProps$7 = Object.defineProperties, __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$d = Object.getOwnPropertySymbols, __hasOwnProp$d = Object.prototype.hasOwnProperty, __propIsEnum$d = Object.prototype.propertyIsEnumerable, __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$d = (a, b) => {
|
|
4609
|
-
for (var prop in b || (b = {}))
|
|
4610
|
-
__hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4611
|
-
if (__getOwnPropSymbols$d)
|
|
4612
|
-
for (var prop of __getOwnPropSymbols$d(b))
|
|
4613
|
-
__propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4614
|
-
return a;
|
|
4615
|
-
}, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
4616
4402
|
const toggleStyleActionImplementation = ({
|
|
4617
4403
|
context,
|
|
4618
4404
|
action
|
|
@@ -4622,14 +4408,16 @@ const toggleStyleActionImplementation = ({
|
|
|
4622
4408
|
style: action.style
|
|
4623
4409
|
}) ? removeStyleActionImplementation({
|
|
4624
4410
|
context,
|
|
4625
|
-
action:
|
|
4411
|
+
action: {
|
|
4412
|
+
...action,
|
|
4626
4413
|
type: "style.remove"
|
|
4627
|
-
}
|
|
4414
|
+
}
|
|
4628
4415
|
}) : addStyleActionImplementation({
|
|
4629
4416
|
context,
|
|
4630
|
-
action:
|
|
4417
|
+
action: {
|
|
4418
|
+
...action,
|
|
4631
4419
|
type: "style.add"
|
|
4632
|
-
}
|
|
4420
|
+
}
|
|
4633
4421
|
});
|
|
4634
4422
|
}, removeStyleActionImplementation = ({
|
|
4635
4423
|
context,
|
|
@@ -4676,14 +4464,6 @@ function isStyleActive({
|
|
|
4676
4464
|
})];
|
|
4677
4465
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
4678
4466
|
}
|
|
4679
|
-
var __defProp$c = Object.defineProperty, __getOwnPropSymbols$c = Object.getOwnPropertySymbols, __hasOwnProp$c = Object.prototype.hasOwnProperty, __propIsEnum$c = Object.prototype.propertyIsEnumerable, __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$c = (a, b) => {
|
|
4680
|
-
for (var prop in b || (b = {}))
|
|
4681
|
-
__hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4682
|
-
if (__getOwnPropSymbols$c)
|
|
4683
|
-
for (var prop of __getOwnPropSymbols$c(b))
|
|
4684
|
-
__propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4685
|
-
return a;
|
|
4686
|
-
};
|
|
4687
4467
|
const debug$6 = debugWithName("API:editable");
|
|
4688
4468
|
function createEditableAPI(editor, editorActor) {
|
|
4689
4469
|
const types = editorActor.getSnapshot().context.schema;
|
|
@@ -4746,7 +4526,9 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4746
4526
|
return console.warn(err), !1;
|
|
4747
4527
|
}
|
|
4748
4528
|
},
|
|
4749
|
-
marks: () =>
|
|
4529
|
+
marks: () => ({
|
|
4530
|
+
...Editor.marks(editor) || {}
|
|
4531
|
+
}).marks || [],
|
|
4750
4532
|
undo: () => editor.undo(),
|
|
4751
4533
|
redo: () => editor.redo(),
|
|
4752
4534
|
select: (selection) => {
|
|
@@ -4768,7 +4550,6 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4768
4550
|
}
|
|
4769
4551
|
},
|
|
4770
4552
|
insertChild: (type, value) => {
|
|
4771
|
-
var _a, _b, _c;
|
|
4772
4553
|
if (type.name !== types.span.name)
|
|
4773
4554
|
return editorActor.send({
|
|
4774
4555
|
type: "behavior event",
|
|
@@ -4780,7 +4561,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4780
4561
|
}
|
|
4781
4562
|
},
|
|
4782
4563
|
editor
|
|
4783
|
-
}),
|
|
4564
|
+
}), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path ?? [];
|
|
4784
4565
|
if (!editor.selection)
|
|
4785
4566
|
throw new Error("The editor has no selection");
|
|
4786
4567
|
const [focusBlock] = Array.from(Editor.nodes(editor, {
|
|
@@ -4794,10 +4575,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4794
4575
|
const child = toSlateValue([{
|
|
4795
4576
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4796
4577
|
_type: types.block.name,
|
|
4797
|
-
children: [
|
|
4578
|
+
children: [{
|
|
4798
4579
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4799
|
-
_type: type.name
|
|
4800
|
-
|
|
4580
|
+
_type: type.name,
|
|
4581
|
+
...value || {}
|
|
4582
|
+
}]
|
|
4801
4583
|
}], {
|
|
4802
4584
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
4803
4585
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
|
|
@@ -4807,30 +4589,27 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4807
4589
|
})), Transforms.insertNodes(editor, child, {
|
|
4808
4590
|
select: !0,
|
|
4809
4591
|
at: editor.selection
|
|
4810
|
-
}), editor.onChange(),
|
|
4592
|
+
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path || [];
|
|
4811
4593
|
},
|
|
4812
|
-
insertBlock: (type, value) => {
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
type: "
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
name: type.name,
|
|
4820
|
-
value
|
|
4821
|
-
},
|
|
4822
|
-
placement: "auto"
|
|
4594
|
+
insertBlock: (type, value) => (editorActor.send({
|
|
4595
|
+
type: "behavior event",
|
|
4596
|
+
behaviorEvent: {
|
|
4597
|
+
type: "insert.block object",
|
|
4598
|
+
blockObject: {
|
|
4599
|
+
name: type.name,
|
|
4600
|
+
value
|
|
4823
4601
|
},
|
|
4824
|
-
|
|
4825
|
-
}
|
|
4826
|
-
|
|
4602
|
+
placement: "auto"
|
|
4603
|
+
},
|
|
4604
|
+
editor
|
|
4605
|
+
}), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path ?? []),
|
|
4827
4606
|
hasBlockStyle: (style) => {
|
|
4828
4607
|
try {
|
|
4829
4608
|
return isStyleActive({
|
|
4830
4609
|
editor,
|
|
4831
4610
|
style
|
|
4832
4611
|
});
|
|
4833
|
-
} catch
|
|
4612
|
+
} catch {
|
|
4834
4613
|
return !1;
|
|
4835
4614
|
}
|
|
4836
4615
|
},
|
|
@@ -4840,7 +4619,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4840
4619
|
editor,
|
|
4841
4620
|
listItem
|
|
4842
4621
|
});
|
|
4843
|
-
} catch
|
|
4622
|
+
} catch {
|
|
4844
4623
|
return !1;
|
|
4845
4624
|
}
|
|
4846
4625
|
},
|
|
@@ -4885,12 +4664,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4885
4664
|
match: (n) => n._key === element._key
|
|
4886
4665
|
}) || [])[0] || [void 0];
|
|
4887
4666
|
node = ReactEditor.toDOMNode(editor, item);
|
|
4888
|
-
} catch
|
|
4667
|
+
} catch {
|
|
4889
4668
|
}
|
|
4890
4669
|
return node;
|
|
4891
4670
|
},
|
|
4892
4671
|
activeAnnotations: () => {
|
|
4893
|
-
var _a;
|
|
4894
4672
|
if (!editor.selection || editor.selection.focus.path.length < 2)
|
|
4895
4673
|
return [];
|
|
4896
4674
|
try {
|
|
@@ -4902,12 +4680,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4902
4680
|
const [block] = Editor.node(editor, path, {
|
|
4903
4681
|
depth: 1
|
|
4904
4682
|
});
|
|
4905
|
-
editor.isTextBlock(block) &&
|
|
4683
|
+
editor.isTextBlock(block) && block.markDefs?.forEach((def) => {
|
|
4906
4684
|
Text.isText(span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
|
|
4907
|
-
})
|
|
4685
|
+
});
|
|
4908
4686
|
}
|
|
4909
4687
|
return activeAnnotations;
|
|
4910
|
-
} catch
|
|
4688
|
+
} catch {
|
|
4911
4689
|
return [];
|
|
4912
4690
|
}
|
|
4913
4691
|
},
|
|
@@ -4929,7 +4707,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4929
4707
|
type: "annotation.add",
|
|
4930
4708
|
annotation: {
|
|
4931
4709
|
name: type.name,
|
|
4932
|
-
value: value
|
|
4710
|
+
value: value ?? {}
|
|
4933
4711
|
},
|
|
4934
4712
|
editor
|
|
4935
4713
|
}
|
|
@@ -4942,7 +4720,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4942
4720
|
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
4943
4721
|
throw new Error("Invalid range");
|
|
4944
4722
|
if (range) {
|
|
4945
|
-
if (!
|
|
4723
|
+
if (!options?.mode || options?.mode === "selected") {
|
|
4946
4724
|
debug$6("Deleting content in selection"), Transforms.delete(editor, {
|
|
4947
4725
|
at: range,
|
|
4948
4726
|
hanging: !0,
|
|
@@ -4950,11 +4728,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4950
4728
|
}), editor.onChange();
|
|
4951
4729
|
return;
|
|
4952
4730
|
}
|
|
4953
|
-
|
|
4731
|
+
options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
4954
4732
|
at: range,
|
|
4955
4733
|
voids: !0,
|
|
4956
4734
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
|
|
4957
|
-
})),
|
|
4735
|
+
})), options?.mode === "children" && (debug$6("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
4958
4736
|
at: range,
|
|
4959
4737
|
voids: !0,
|
|
4960
4738
|
match: (node) => node._type === types.span.name || // Text children
|
|
@@ -5011,26 +4789,15 @@ function isAnnotationActive({
|
|
|
5011
4789
|
at: editor.selection,
|
|
5012
4790
|
match: (node) => Text.isText(node)
|
|
5013
4791
|
})];
|
|
5014
|
-
if (spans.length === 0 || spans.some(([span]) =>
|
|
5015
|
-
var _a;
|
|
5016
|
-
return !isPortableTextSpan$1(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
|
|
5017
|
-
})) return !1;
|
|
4792
|
+
if (spans.length === 0 || spans.some(([span]) => !isPortableTextSpan$1(span) || !span.marks || span.marks?.length === 0)) return !1;
|
|
5018
4793
|
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
5019
4794
|
const [block] = Editor.node(editor, path, {
|
|
5020
4795
|
depth: 1
|
|
5021
4796
|
});
|
|
5022
4797
|
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
5023
4798
|
}, []);
|
|
5024
|
-
return spans.every(([span]) =>
|
|
5025
|
-
|
|
5026
|
-
if (!isPortableTextSpan$1(span)) return !1;
|
|
5027
|
-
const spanMarkDefs = (_a = span.marks) == null ? void 0 : _a.map((markKey) => {
|
|
5028
|
-
var _a2;
|
|
5029
|
-
return (_a2 = selectionMarkDefs.find((def) => (def == null ? void 0 : def._key) === markKey)) == null ? void 0 : _a2._type;
|
|
5030
|
-
});
|
|
5031
|
-
return spanMarkDefs == null ? void 0 : spanMarkDefs.includes(annotation.name);
|
|
5032
|
-
});
|
|
5033
|
-
} catch (e) {
|
|
4799
|
+
return spans.every(([span]) => isPortableTextSpan$1(span) ? span.marks?.map((markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type)?.includes(annotation.name) : !1);
|
|
4800
|
+
} catch {
|
|
5034
4801
|
return !1;
|
|
5035
4802
|
}
|
|
5036
4803
|
}
|
|
@@ -5038,7 +4805,6 @@ const addAnnotationActionImplementation = ({
|
|
|
5038
4805
|
context,
|
|
5039
4806
|
action
|
|
5040
4807
|
}) => {
|
|
5041
|
-
var _a, _b;
|
|
5042
4808
|
const editor = action.editor, {
|
|
5043
4809
|
selection: originalSelection
|
|
5044
4810
|
} = editor;
|
|
@@ -5056,12 +4822,13 @@ const addAnnotationActionImplementation = ({
|
|
|
5056
4822
|
for (const [block, blockPath] of selectedBlocks) {
|
|
5057
4823
|
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
5058
4824
|
continue;
|
|
5059
|
-
const annotationKey = context.keyGenerator(), markDefs =
|
|
4825
|
+
const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
|
|
5060
4826
|
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
|
|
5061
|
-
markDefs: [...markDefs,
|
|
4827
|
+
markDefs: [...markDefs, {
|
|
5062
4828
|
_type: action.annotation.name,
|
|
5063
|
-
_key: annotationKey
|
|
5064
|
-
|
|
4829
|
+
_key: annotationKey,
|
|
4830
|
+
...action.annotation.value
|
|
4831
|
+
}]
|
|
5065
4832
|
}, {
|
|
5066
4833
|
at: blockPath
|
|
5067
4834
|
}), markDefPath = [{
|
|
@@ -5076,7 +4843,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5076
4843
|
for (const [span, path] of children) {
|
|
5077
4844
|
if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
|
|
5078
4845
|
continue;
|
|
5079
|
-
const marks =
|
|
4846
|
+
const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
|
|
5080
4847
|
Transforms.setNodes(editor, {
|
|
5081
4848
|
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
5082
4849
|
}, {
|
|
@@ -5098,7 +4865,6 @@ const addAnnotationActionImplementation = ({
|
|
|
5098
4865
|
}, removeAnnotationActionImplementation = ({
|
|
5099
4866
|
action
|
|
5100
4867
|
}) => {
|
|
5101
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
5102
4868
|
const editor = action.editor;
|
|
5103
4869
|
if (debug$6("Removing annotation", action.annotation.name), !!editor.selection)
|
|
5104
4870
|
if (Range.isCollapsed(editor.selection)) {
|
|
@@ -5107,12 +4873,12 @@ const addAnnotationActionImplementation = ({
|
|
|
5107
4873
|
});
|
|
5108
4874
|
if (!editor.isTextBlock(block))
|
|
5109
4875
|
return;
|
|
5110
|
-
const potentialAnnotations = (
|
|
4876
|
+
const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = Editor.node(editor, editor.selection, {
|
|
5111
4877
|
depth: 2
|
|
5112
4878
|
});
|
|
5113
4879
|
if (!editor.isTextSpan(selectedChild))
|
|
5114
4880
|
return;
|
|
5115
|
-
const annotationToRemove =
|
|
4881
|
+
const annotationToRemove = selectedChild.marks?.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
|
|
5116
4882
|
if (!annotationToRemove)
|
|
5117
4883
|
return;
|
|
5118
4884
|
const previousSpansWithSameAnnotation = [];
|
|
@@ -5120,20 +4886,20 @@ const addAnnotationActionImplementation = ({
|
|
|
5120
4886
|
reverse: !0
|
|
5121
4887
|
}))
|
|
5122
4888
|
if (editor.isTextSpan(child) && Path.isBefore(childPath, selectedChildPath))
|
|
5123
|
-
if (
|
|
4889
|
+
if (child.marks?.includes(annotationToRemove))
|
|
5124
4890
|
previousSpansWithSameAnnotation.push([child, childPath]);
|
|
5125
4891
|
else
|
|
5126
4892
|
break;
|
|
5127
4893
|
const nextSpansWithSameAnnotation = [];
|
|
5128
4894
|
for (const [child, childPath] of Node.children(editor, blockPath))
|
|
5129
4895
|
if (editor.isTextSpan(child) && Path.isAfter(childPath, selectedChildPath))
|
|
5130
|
-
if (
|
|
4896
|
+
if (child.marks?.includes(annotationToRemove))
|
|
5131
4897
|
nextSpansWithSameAnnotation.push([child, childPath]);
|
|
5132
4898
|
else
|
|
5133
4899
|
break;
|
|
5134
4900
|
for (const [child, childPath] of [...previousSpansWithSameAnnotation, [selectedChild, selectedChildPath], ...nextSpansWithSameAnnotation])
|
|
5135
4901
|
Transforms.setNodes(editor, {
|
|
5136
|
-
marks:
|
|
4902
|
+
marks: child.marks?.filter((mark) => mark !== annotationToRemove)
|
|
5137
4903
|
}, {
|
|
5138
4904
|
at: childPath
|
|
5139
4905
|
});
|
|
@@ -5152,10 +4918,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5152
4918
|
for (const [child, childPath] of children) {
|
|
5153
4919
|
if (!editor.isTextSpan(child) || !Range.includes(editor.selection, childPath))
|
|
5154
4920
|
continue;
|
|
5155
|
-
const markDefs =
|
|
5156
|
-
const markDef = markDefs.find((markDef2) => markDef2._key === mark);
|
|
5157
|
-
return (markDef == null ? void 0 : markDef._type) !== action.annotation.name;
|
|
5158
|
-
});
|
|
4921
|
+
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== action.annotation.name);
|
|
5159
4922
|
marksWithoutAnnotation.length !== marks.length && Transforms.setNodes(editor, {
|
|
5160
4923
|
marks: marksWithoutAnnotation
|
|
5161
4924
|
}, {
|
|
@@ -5198,12 +4961,11 @@ function insertBlock({
|
|
|
5198
4961
|
editor,
|
|
5199
4962
|
schema
|
|
5200
4963
|
}) {
|
|
5201
|
-
var _a;
|
|
5202
4964
|
if (editor.selection) {
|
|
5203
|
-
const [focusBlock, focusBlockPath] =
|
|
4965
|
+
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(editor, {
|
|
5204
4966
|
at: editor.selection.focus.path.slice(0, 1),
|
|
5205
4967
|
match: (n) => !Editor.isEditor(n)
|
|
5206
|
-
}))[0]
|
|
4968
|
+
}))[0] ?? [void 0, void 0];
|
|
5207
4969
|
if (placement === "after") {
|
|
5208
4970
|
const nextPath = [focusBlockPath[0] + 1];
|
|
5209
4971
|
Transforms.insertNodes(editor, block, {
|
|
@@ -5235,22 +4997,15 @@ function insertBlock({
|
|
|
5235
4997
|
});
|
|
5236
4998
|
}
|
|
5237
4999
|
}
|
|
5238
|
-
var __defProp$b = Object.defineProperty, __getOwnPropSymbols$b = Object.getOwnPropertySymbols, __hasOwnProp$b = Object.prototype.hasOwnProperty, __propIsEnum$b = Object.prototype.propertyIsEnumerable, __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$b = (a, b) => {
|
|
5239
|
-
for (var prop in b || (b = {}))
|
|
5240
|
-
__hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5241
|
-
if (__getOwnPropSymbols$b)
|
|
5242
|
-
for (var prop of __getOwnPropSymbols$b(b))
|
|
5243
|
-
__propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5244
|
-
return a;
|
|
5245
|
-
};
|
|
5246
5000
|
const insertBlockObjectActionImplementation = ({
|
|
5247
5001
|
context,
|
|
5248
5002
|
action
|
|
5249
5003
|
}) => {
|
|
5250
|
-
const block = toSlateValue([
|
|
5004
|
+
const block = toSlateValue([{
|
|
5251
5005
|
_key: context.keyGenerator(),
|
|
5252
|
-
_type: action.blockObject.name
|
|
5253
|
-
|
|
5006
|
+
_type: action.blockObject.name,
|
|
5007
|
+
...action.blockObject.value ? action.blockObject.value : {}
|
|
5008
|
+
}], {
|
|
5254
5009
|
schemaTypes: context.schema
|
|
5255
5010
|
})[0];
|
|
5256
5011
|
insertBlock({
|
|
@@ -5259,29 +5014,19 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5259
5014
|
editor: action.editor,
|
|
5260
5015
|
schema: context.schema
|
|
5261
5016
|
});
|
|
5262
|
-
}
|
|
5263
|
-
var __defProp$a = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$a = Object.getOwnPropertySymbols, __hasOwnProp$a = Object.prototype.hasOwnProperty, __propIsEnum$a = Object.prototype.propertyIsEnumerable, __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$a = (a, b) => {
|
|
5264
|
-
for (var prop in b || (b = {}))
|
|
5265
|
-
__hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5266
|
-
if (__getOwnPropSymbols$a)
|
|
5267
|
-
for (var prop of __getOwnPropSymbols$a(b))
|
|
5268
|
-
__propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5269
|
-
return a;
|
|
5270
|
-
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
5271
|
-
const insertBreakActionImplementation = ({
|
|
5017
|
+
}, insertBreakActionImplementation = ({
|
|
5272
5018
|
context,
|
|
5273
5019
|
action
|
|
5274
5020
|
}) => {
|
|
5275
|
-
var _a, _b, _c, _d, _e;
|
|
5276
5021
|
const keyGenerator = context.keyGenerator, schema = context.schema, editor = action.editor;
|
|
5277
5022
|
if (!editor.selection)
|
|
5278
5023
|
return;
|
|
5279
|
-
const [focusSpan] =
|
|
5024
|
+
const [focusSpan] = Array.from(Editor.nodes(editor, {
|
|
5280
5025
|
mode: "lowest",
|
|
5281
5026
|
at: editor.selection.focus,
|
|
5282
5027
|
match: (n) => editor.isTextSpan(n),
|
|
5283
5028
|
voids: !1
|
|
5284
|
-
}))[0]
|
|
5029
|
+
}))[0] ?? [void 0], focusDecorators = focusSpan?.marks?.filter((mark) => schema.decorators.some((decorator) => decorator.value === mark)) ?? [], focusAnnotations = focusSpan?.marks?.filter((mark) => !schema.decorators.some((decorator) => decorator.value === mark)) ?? [], anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
|
|
5285
5030
|
if (editor.isTextBlock(focusBlock)) {
|
|
5286
5031
|
const [start, end] = Range.edges(editor.selection), lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual(start, {
|
|
5287
5032
|
path: [...focusBlockPath, focusBlock.children.length - 1],
|
|
@@ -5320,7 +5065,6 @@ const insertBreakActionImplementation = ({
|
|
|
5320
5065
|
const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0];
|
|
5321
5066
|
if (!atTheStartOfBlock && !atTheEndOfBlock && !selectionAcrossBlocks) {
|
|
5322
5067
|
Editor.withoutNormalizing(editor, () => {
|
|
5323
|
-
var _a2;
|
|
5324
5068
|
if (!editor.selection)
|
|
5325
5069
|
return;
|
|
5326
5070
|
Transforms.splitNodes(editor, {
|
|
@@ -5343,28 +5087,20 @@ const insertBreakActionImplementation = ({
|
|
|
5343
5087
|
for (const [child, childPath] of children) {
|
|
5344
5088
|
if (!editor.isTextSpan(child))
|
|
5345
5089
|
continue;
|
|
5346
|
-
const marks =
|
|
5090
|
+
const marks = child.marks ?? [];
|
|
5347
5091
|
for (const mark of marks)
|
|
5348
|
-
schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) =>
|
|
5349
|
-
|
|
5350
|
-
return (_a3 = prevNodeSpan.marks) == null ? void 0 : _a3.includes(mark);
|
|
5351
|
-
}) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
5352
|
-
const newMarks = marks.map((mark) => {
|
|
5353
|
-
var _a3;
|
|
5354
|
-
return (_a3 = newMarkDefKeys.get(mark)) != null ? _a3 : mark;
|
|
5355
|
-
});
|
|
5092
|
+
schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
5093
|
+
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
5356
5094
|
isEqual(marks, newMarks) || Transforms.setNodes(editor, {
|
|
5357
5095
|
marks: newMarks
|
|
5358
5096
|
}, {
|
|
5359
5097
|
at: childPath
|
|
5360
5098
|
});
|
|
5361
5099
|
}
|
|
5362
|
-
const newMarkDefs = nextNode.markDefs.map((markDef) => {
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
});
|
|
5367
|
-
});
|
|
5100
|
+
const newMarkDefs = nextNode.markDefs.map((markDef) => ({
|
|
5101
|
+
...markDef,
|
|
5102
|
+
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
5103
|
+
}));
|
|
5368
5104
|
isEqual(nextNode.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
|
|
5369
5105
|
markDefs: newMarkDefs
|
|
5370
5106
|
}, {
|
|
@@ -5385,24 +5121,15 @@ const insertBreakActionImplementation = ({
|
|
|
5385
5121
|
}) => {
|
|
5386
5122
|
insertBreakActionImplementation({
|
|
5387
5123
|
context,
|
|
5388
|
-
action:
|
|
5124
|
+
action: {
|
|
5125
|
+
...action,
|
|
5389
5126
|
type: "insert.break"
|
|
5390
|
-
}
|
|
5127
|
+
}
|
|
5391
5128
|
});
|
|
5392
|
-
}
|
|
5393
|
-
var __defProp$9 = Object.defineProperty, __getOwnPropSymbols$9 = Object.getOwnPropertySymbols, __hasOwnProp$9 = Object.prototype.hasOwnProperty, __propIsEnum$9 = Object.prototype.propertyIsEnumerable, __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$9 = (a, b) => {
|
|
5394
|
-
for (var prop in b || (b = {}))
|
|
5395
|
-
__hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5396
|
-
if (__getOwnPropSymbols$9)
|
|
5397
|
-
for (var prop of __getOwnPropSymbols$9(b))
|
|
5398
|
-
__propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5399
|
-
return a;
|
|
5400
|
-
};
|
|
5401
|
-
const insertInlineObjectActionImplementation = ({
|
|
5129
|
+
}, insertInlineObjectActionImplementation = ({
|
|
5402
5130
|
context,
|
|
5403
5131
|
action
|
|
5404
5132
|
}) => {
|
|
5405
|
-
var _a, _b;
|
|
5406
5133
|
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
5407
5134
|
console.error("Unable to insert unknown inline object");
|
|
5408
5135
|
return;
|
|
@@ -5411,77 +5138,60 @@ const insertInlineObjectActionImplementation = ({
|
|
|
5411
5138
|
console.error("Unable to insert inline object without selection");
|
|
5412
5139
|
return;
|
|
5413
5140
|
}
|
|
5414
|
-
const [focusTextBlock] =
|
|
5141
|
+
const [focusTextBlock] = Array.from(Editor.nodes(action.editor, {
|
|
5415
5142
|
at: action.editor.selection.focus.path,
|
|
5416
5143
|
match: (node) => action.editor.isTextBlock(node)
|
|
5417
|
-
})).at(0)
|
|
5144
|
+
})).at(0) ?? [void 0, void 0];
|
|
5418
5145
|
if (!focusTextBlock) {
|
|
5419
5146
|
console.error("Unable to perform action without focus text block");
|
|
5420
5147
|
return;
|
|
5421
5148
|
}
|
|
5422
|
-
const
|
|
5149
|
+
const child = toSlateValue([{
|
|
5423
5150
|
_type: context.schema.block.name,
|
|
5424
5151
|
_key: context.keyGenerator(),
|
|
5425
|
-
children: [
|
|
5152
|
+
children: [{
|
|
5426
5153
|
_type: action.inlineObject.name,
|
|
5427
|
-
_key: context.keyGenerator()
|
|
5428
|
-
|
|
5154
|
+
_key: context.keyGenerator(),
|
|
5155
|
+
...action.inlineObject.value ?? {}
|
|
5156
|
+
}]
|
|
5429
5157
|
}], {
|
|
5430
5158
|
schemaTypes: context.schema
|
|
5431
|
-
}).at(0)
|
|
5159
|
+
}).at(0)?.children.at(0);
|
|
5432
5160
|
if (!child) {
|
|
5433
5161
|
console.error("Unable to insert inline object");
|
|
5434
5162
|
return;
|
|
5435
5163
|
}
|
|
5436
5164
|
Transforms.insertNodes(action.editor, child);
|
|
5437
|
-
}
|
|
5438
|
-
var __defProp$8 = Object.defineProperty, __getOwnPropSymbols$8 = Object.getOwnPropertySymbols, __hasOwnProp$8 = Object.prototype.hasOwnProperty, __propIsEnum$8 = Object.prototype.propertyIsEnumerable, __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$8 = (a, b) => {
|
|
5439
|
-
for (var prop in b || (b = {}))
|
|
5440
|
-
__hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5441
|
-
if (__getOwnPropSymbols$8)
|
|
5442
|
-
for (var prop of __getOwnPropSymbols$8(b))
|
|
5443
|
-
__propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5444
|
-
return a;
|
|
5445
|
-
};
|
|
5446
|
-
const insertSpanActionImplementation = ({
|
|
5165
|
+
}, insertSpanActionImplementation = ({
|
|
5447
5166
|
context,
|
|
5448
5167
|
action
|
|
5449
5168
|
}) => {
|
|
5450
|
-
var _a, _b, _c, _d;
|
|
5451
5169
|
if (!action.editor.selection) {
|
|
5452
5170
|
console.error("Unable to perform action without selection", action);
|
|
5453
5171
|
return;
|
|
5454
5172
|
}
|
|
5455
|
-
const [focusBlock, focusBlockPath] =
|
|
5173
|
+
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(action.editor, {
|
|
5456
5174
|
at: action.editor.selection.focus.path,
|
|
5457
5175
|
match: (node) => action.editor.isTextBlock(node)
|
|
5458
|
-
}))[0]
|
|
5176
|
+
}))[0] ?? [void 0, void 0];
|
|
5459
5177
|
if (!focusBlock || !focusBlockPath) {
|
|
5460
5178
|
console.error("Unable to perform action without focus block", action);
|
|
5461
5179
|
return;
|
|
5462
5180
|
}
|
|
5463
|
-
const markDefs =
|
|
5181
|
+
const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
|
|
5464
5182
|
_type: annotation.name,
|
|
5465
|
-
_key: context.keyGenerator()
|
|
5466
|
-
|
|
5183
|
+
_key: context.keyGenerator(),
|
|
5184
|
+
...annotation.value
|
|
5185
|
+
})) : void 0;
|
|
5467
5186
|
annotations && annotations.length > 0 && Transforms.setNodes(action.editor, {
|
|
5468
5187
|
markDefs: [...markDefs, ...annotations]
|
|
5469
5188
|
}), Transforms.insertNodes(action.editor, {
|
|
5470
5189
|
_type: "span",
|
|
5471
5190
|
_key: context.keyGenerator(),
|
|
5472
5191
|
text: action.text,
|
|
5473
|
-
marks: [...
|
|
5192
|
+
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
5474
5193
|
});
|
|
5475
|
-
}
|
|
5476
|
-
var __defProp$7 = Object.defineProperty, __getOwnPropSymbols$7 = Object.getOwnPropertySymbols, __hasOwnProp$7 = Object.prototype.hasOwnProperty, __propIsEnum$7 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$7 = (a, b) => {
|
|
5477
|
-
for (var prop in b || (b = {}))
|
|
5478
|
-
__hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5479
|
-
if (__getOwnPropSymbols$7)
|
|
5480
|
-
for (var prop of __getOwnPropSymbols$7(b))
|
|
5481
|
-
__propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5482
|
-
return a;
|
|
5483
|
-
};
|
|
5484
|
-
const textBlockSetActionImplementation = ({
|
|
5194
|
+
}, textBlockSetActionImplementation = ({
|
|
5485
5195
|
action
|
|
5486
5196
|
}) => {
|
|
5487
5197
|
const at = toSlateRange({
|
|
@@ -5494,13 +5204,17 @@ const textBlockSetActionImplementation = ({
|
|
|
5494
5204
|
offset: 0
|
|
5495
5205
|
}
|
|
5496
5206
|
}, action.editor);
|
|
5497
|
-
Transforms.setNodes(action.editor,
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5207
|
+
Transforms.setNodes(action.editor, {
|
|
5208
|
+
...action.style ? {
|
|
5209
|
+
style: action.style
|
|
5210
|
+
} : {},
|
|
5211
|
+
...action.listItem ? {
|
|
5212
|
+
listItem: action.listItem
|
|
5213
|
+
} : {},
|
|
5214
|
+
...action.level ? {
|
|
5215
|
+
level: action.level
|
|
5216
|
+
} : {}
|
|
5217
|
+
}, {
|
|
5504
5218
|
at
|
|
5505
5219
|
});
|
|
5506
5220
|
}, textBlockUnsetActionImplementation = ({
|
|
@@ -5519,16 +5233,7 @@ const textBlockSetActionImplementation = ({
|
|
|
5519
5233
|
Transforms.unsetNodes(action.editor, action.props, {
|
|
5520
5234
|
at
|
|
5521
5235
|
});
|
|
5522
|
-
}
|
|
5523
|
-
var __defProp$6 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
|
|
5524
|
-
for (var prop in b || (b = {}))
|
|
5525
|
-
__hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5526
|
-
if (__getOwnPropSymbols$6)
|
|
5527
|
-
for (var prop of __getOwnPropSymbols$6(b))
|
|
5528
|
-
__propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5529
|
-
return a;
|
|
5530
|
-
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
5531
|
-
const behaviorActionImplementations = {
|
|
5236
|
+
}, behaviorActionImplementations = {
|
|
5532
5237
|
"annotation.add": addAnnotationActionImplementation,
|
|
5533
5238
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
5534
5239
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
@@ -5617,15 +5322,15 @@ const behaviorActionImplementations = {
|
|
|
5617
5322
|
context,
|
|
5618
5323
|
action
|
|
5619
5324
|
}) => {
|
|
5620
|
-
var _a, _b, _c, _d;
|
|
5621
5325
|
const block = toSlateValue([{
|
|
5622
5326
|
_key: context.keyGenerator(),
|
|
5623
5327
|
_type: context.schema.block.name,
|
|
5624
|
-
style:
|
|
5328
|
+
style: context.schema.styles[0].value ?? "normal",
|
|
5625
5329
|
markDefs: [],
|
|
5626
|
-
children:
|
|
5330
|
+
children: action.textBlock?.children?.map((child) => ({
|
|
5331
|
+
...child,
|
|
5627
5332
|
_key: context.keyGenerator()
|
|
5628
|
-
}))
|
|
5333
|
+
})) ?? [{
|
|
5629
5334
|
_type: context.schema.span.name,
|
|
5630
5335
|
_key: context.keyGenerator(),
|
|
5631
5336
|
text: ""
|
|
@@ -5718,7 +5423,11 @@ const behaviorActionImplementations = {
|
|
|
5718
5423
|
action
|
|
5719
5424
|
}) => {
|
|
5720
5425
|
const selection = action.editor.selection;
|
|
5721
|
-
selection && (Transforms.select(action.editor,
|
|
5426
|
+
selection && (Transforms.select(action.editor, {
|
|
5427
|
+
...selection
|
|
5428
|
+
}), action.editor.selection = {
|
|
5429
|
+
...selection
|
|
5430
|
+
});
|
|
5722
5431
|
},
|
|
5723
5432
|
"style.toggle": toggleStyleActionImplementation,
|
|
5724
5433
|
"style.add": addStyleActionImplementation,
|
|
@@ -5990,30 +5699,15 @@ function performDefaultAction({
|
|
|
5990
5699
|
});
|
|
5991
5700
|
}
|
|
5992
5701
|
}
|
|
5993
|
-
var __defProp$5 = Object.defineProperty, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
|
|
5994
|
-
for (var prop in b || (b = {}))
|
|
5995
|
-
__hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5996
|
-
if (__getOwnPropSymbols$5)
|
|
5997
|
-
for (var prop of __getOwnPropSymbols$5(b))
|
|
5998
|
-
__propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5999
|
-
return a;
|
|
6000
|
-
};
|
|
6001
5702
|
function getActiveDecorators({
|
|
6002
5703
|
schema,
|
|
6003
5704
|
slateEditorInstance
|
|
6004
5705
|
}) {
|
|
6005
|
-
var _a, _b;
|
|
6006
5706
|
const decorators = schema.decorators.map((decorator) => decorator.value);
|
|
6007
|
-
return (
|
|
6008
|
-
}
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
__hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
6012
|
-
if (__getOwnPropSymbols$4)
|
|
6013
|
-
for (var prop of __getOwnPropSymbols$4(b))
|
|
6014
|
-
__propIsEnum$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
6015
|
-
return a;
|
|
6016
|
-
}, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
5707
|
+
return ({
|
|
5708
|
+
...Editor.marks(slateEditorInstance) ?? {}
|
|
5709
|
+
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
5710
|
+
}
|
|
6017
5711
|
const editorMachine = setup({
|
|
6018
5712
|
types: {
|
|
6019
5713
|
context: {},
|
|
@@ -6068,11 +5762,11 @@ const editorMachine = setup({
|
|
|
6068
5762
|
event,
|
|
6069
5763
|
enqueue
|
|
6070
5764
|
}) => {
|
|
6071
|
-
var _a;
|
|
6072
5765
|
assertEvent(event, ["behavior event"]);
|
|
6073
|
-
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 :
|
|
5766
|
+
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
5767
|
+
...event.behaviorEvent,
|
|
6074
5768
|
editor: event.editor
|
|
6075
|
-
}
|
|
5769
|
+
}, eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
6076
5770
|
if (eventBehaviors.length === 0) {
|
|
6077
5771
|
if (!defaultAction)
|
|
6078
5772
|
return;
|
|
@@ -6112,7 +5806,7 @@ const editorMachine = setup({
|
|
|
6112
5806
|
actionIntends
|
|
6113
5807
|
});
|
|
6114
5808
|
if (behaviorOverwritten) {
|
|
6115
|
-
|
|
5809
|
+
event.nativeEvent?.preventDefault();
|
|
6116
5810
|
break;
|
|
6117
5811
|
}
|
|
6118
5812
|
}
|
|
@@ -6131,19 +5825,16 @@ const editorMachine = setup({
|
|
|
6131
5825
|
id: "editor",
|
|
6132
5826
|
context: ({
|
|
6133
5827
|
input
|
|
6134
|
-
}) => {
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
value: input.value
|
|
6145
|
-
};
|
|
6146
|
-
},
|
|
5828
|
+
}) => ({
|
|
5829
|
+
behaviors: input.behaviors ?? coreBehaviors,
|
|
5830
|
+
keyGenerator: input.keyGenerator,
|
|
5831
|
+
pendingEvents: [],
|
|
5832
|
+
schema: input.schema,
|
|
5833
|
+
selection: null,
|
|
5834
|
+
initialReadOnly: input.readOnly ?? !1,
|
|
5835
|
+
maxBlocks: input.maxBlocks,
|
|
5836
|
+
value: input.value
|
|
5837
|
+
}),
|
|
6147
5838
|
on: {
|
|
6148
5839
|
unset: {
|
|
6149
5840
|
actions: emit(({
|
|
@@ -6226,9 +5917,10 @@ const editorMachine = setup({
|
|
|
6226
5917
|
}) => {
|
|
6227
5918
|
Editor.withoutNormalizing(event.editor, () => {
|
|
6228
5919
|
for (const actionIntend of event.actionIntends) {
|
|
6229
|
-
const action =
|
|
5920
|
+
const action = {
|
|
5921
|
+
...actionIntend,
|
|
6230
5922
|
editor: event.editor
|
|
6231
|
-
}
|
|
5923
|
+
};
|
|
6232
5924
|
performAction({
|
|
6233
5925
|
context,
|
|
6234
5926
|
action
|
|
@@ -6443,10 +6135,9 @@ function useCreateEditor(config) {
|
|
|
6443
6135
|
return $[4] !== editorActor ? (t3 = createEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
6444
6136
|
}
|
|
6445
6137
|
function editorConfigToMachineInput(config) {
|
|
6446
|
-
var _a;
|
|
6447
6138
|
return {
|
|
6448
6139
|
behaviors: config.behaviors,
|
|
6449
|
-
keyGenerator:
|
|
6140
|
+
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
6450
6141
|
maxBlocks: config.maxBlocks,
|
|
6451
6142
|
readOnly: config.readOnly,
|
|
6452
6143
|
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
@@ -6496,16 +6187,13 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
6496
6187
|
let t2;
|
|
6497
6188
|
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
6498
6189
|
}
|
|
6499
|
-
var __defProp$3 = Object.defineProperty, __defProps$3 = Object.defineProperties, __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
|
|
6500
|
-
for (var prop in b || (b = {}))
|
|
6501
|
-
__hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6502
|
-
if (__getOwnPropSymbols$3)
|
|
6503
|
-
for (var prop of __getOwnPropSymbols$3(b))
|
|
6504
|
-
__propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6505
|
-
return a;
|
|
6506
|
-
}, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)), __publicField = (obj, key, value) => __defNormalProp$3(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
6507
6190
|
const debug$4 = debugWithName("component:PortableTextEditor");
|
|
6508
6191
|
class PortableTextEditor extends Component {
|
|
6192
|
+
static displayName = "PortableTextEditor";
|
|
6193
|
+
/**
|
|
6194
|
+
* An observable of all the editor changes.
|
|
6195
|
+
*/
|
|
6196
|
+
change$ = new Subject();
|
|
6509
6197
|
/**
|
|
6510
6198
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
6511
6199
|
*/
|
|
@@ -6516,11 +6204,8 @@ class PortableTextEditor extends Component {
|
|
|
6516
6204
|
* The editor API (currently implemented with Slate).
|
|
6517
6205
|
*/
|
|
6518
6206
|
constructor(props) {
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
this.editor._internal.editable = __spreadValues$3(__spreadValues$3({}, this.editor._internal.editable), editable);
|
|
6522
|
-
}), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6523
|
-
keyGenerator: (_a = props.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6207
|
+
super(props), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6208
|
+
keyGenerator: props.keyGenerator ?? defaultKeyGenerator,
|
|
6524
6209
|
schema: props.schemaType,
|
|
6525
6210
|
initialValue: props.value,
|
|
6526
6211
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
@@ -6528,13 +6213,12 @@ class PortableTextEditor extends Component {
|
|
|
6528
6213
|
}), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
|
|
6529
6214
|
}
|
|
6530
6215
|
componentDidUpdate(prevProps) {
|
|
6531
|
-
var _a;
|
|
6532
6216
|
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = createEditorSchema(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
|
|
6533
6217
|
type: "update schema",
|
|
6534
6218
|
schema: this.schemaTypes
|
|
6535
6219
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
6536
6220
|
type: "update readOnly",
|
|
6537
|
-
readOnly:
|
|
6221
|
+
readOnly: this.props.readOnly ?? !1
|
|
6538
6222
|
}), this.props.maxBlocks !== prevProps.maxBlocks && this.editor._internal.editorActor.send({
|
|
6539
6223
|
type: "update maxBlocks",
|
|
6540
6224
|
maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
|
|
@@ -6543,9 +6227,14 @@ class PortableTextEditor extends Component {
|
|
|
6543
6227
|
value: this.props.value
|
|
6544
6228
|
}), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
|
|
6545
6229
|
}
|
|
6230
|
+
setEditable = (editable) => {
|
|
6231
|
+
this.editor._internal.editable = {
|
|
6232
|
+
...this.editor._internal.editable,
|
|
6233
|
+
...editable
|
|
6234
|
+
};
|
|
6235
|
+
};
|
|
6546
6236
|
render() {
|
|
6547
|
-
|
|
6548
|
-
const legacyPatches = this.props.editor ? void 0 : (_a = this.props.incomingPatches$) != null ? _a : this.props.patches$;
|
|
6237
|
+
const legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
|
|
6549
6238
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6550
6239
|
legacyPatches ? /* @__PURE__ */ jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
|
|
6551
6240
|
/* @__PURE__ */ jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
|
|
@@ -6555,105 +6244,65 @@ class PortableTextEditor extends Component {
|
|
|
6555
6244
|
/* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsx(Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
|
|
6556
6245
|
] });
|
|
6557
6246
|
}
|
|
6247
|
+
// Static API methods
|
|
6248
|
+
static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
|
|
6249
|
+
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6250
|
+
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6251
|
+
static blur = (editor) => {
|
|
6252
|
+
debug$4("Host blurred"), editor.editable?.blur();
|
|
6253
|
+
};
|
|
6254
|
+
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6255
|
+
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6256
|
+
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6257
|
+
static focus = (editor) => {
|
|
6258
|
+
debug$4("Host requesting focus"), editor.editable?.focus();
|
|
6259
|
+
};
|
|
6260
|
+
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6261
|
+
static focusChild = (editor) => editor.editable?.focusChild();
|
|
6262
|
+
static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
|
|
6263
|
+
static getValue = (editor) => editor.editable?.getValue();
|
|
6264
|
+
static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
|
|
6265
|
+
static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
|
|
6266
|
+
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6267
|
+
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6268
|
+
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6269
|
+
static insertChild = (editor, type, value) => (debug$4("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6270
|
+
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6271
|
+
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6272
|
+
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
6273
|
+
static isObjectPath = (_editor, path) => {
|
|
6274
|
+
if (!path || !Array.isArray(path)) return !1;
|
|
6275
|
+
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6276
|
+
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6277
|
+
};
|
|
6278
|
+
static marks = (editor) => editor.editable?.marks();
|
|
6279
|
+
static select = (editor, selection) => {
|
|
6280
|
+
debug$4("Host setting selection", selection), editor.editable?.select(selection);
|
|
6281
|
+
};
|
|
6282
|
+
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6283
|
+
static toggleBlockStyle = (editor, blockStyle) => (debug$4("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6284
|
+
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6285
|
+
static toggleMark = (editor, mark) => {
|
|
6286
|
+
debug$4("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6287
|
+
};
|
|
6288
|
+
static getFragment = (editor) => (debug$4("Host getting fragment"), editor.editable?.getFragment());
|
|
6289
|
+
static undo = (editor) => {
|
|
6290
|
+
debug$4("Host undoing"), editor.editable?.undo();
|
|
6291
|
+
};
|
|
6292
|
+
static redo = (editor) => {
|
|
6293
|
+
debug$4("Host redoing"), editor.editable?.redo();
|
|
6294
|
+
};
|
|
6295
|
+
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6558
6296
|
}
|
|
6559
|
-
__publicField(PortableTextEditor, "displayName", "PortableTextEditor"), // Static API methods
|
|
6560
|
-
__publicField(PortableTextEditor, "activeAnnotations", (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : []), __publicField(PortableTextEditor, "isAnnotationActive", (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1), __publicField(PortableTextEditor, "addAnnotation", (editor, type, value) => {
|
|
6561
|
-
var _a;
|
|
6562
|
-
return (_a = editor.editable) == null ? void 0 : _a.addAnnotation(type, value);
|
|
6563
|
-
}), __publicField(PortableTextEditor, "blur", (editor) => {
|
|
6564
|
-
var _a;
|
|
6565
|
-
debug$4("Host blurred"), (_a = editor.editable) == null || _a.blur();
|
|
6566
|
-
}), __publicField(PortableTextEditor, "delete", (editor, selection, options) => {
|
|
6567
|
-
var _a;
|
|
6568
|
-
return (_a = editor.editable) == null ? void 0 : _a.delete(selection, options);
|
|
6569
|
-
}), __publicField(PortableTextEditor, "findDOMNode", (editor, element) => {
|
|
6570
|
-
var _a;
|
|
6571
|
-
return (_a = editor.editable) == null ? void 0 : _a.findDOMNode(element);
|
|
6572
|
-
}), __publicField(PortableTextEditor, "findByPath", (editor, path) => {
|
|
6573
|
-
var _a;
|
|
6574
|
-
return ((_a = editor.editable) == null ? void 0 : _a.findByPath(path)) || [];
|
|
6575
|
-
}), __publicField(PortableTextEditor, "focus", (editor) => {
|
|
6576
|
-
var _a;
|
|
6577
|
-
debug$4("Host requesting focus"), (_a = editor.editable) == null || _a.focus();
|
|
6578
|
-
}), __publicField(PortableTextEditor, "focusBlock", (editor) => {
|
|
6579
|
-
var _a;
|
|
6580
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusBlock();
|
|
6581
|
-
}), __publicField(PortableTextEditor, "focusChild", (editor) => {
|
|
6582
|
-
var _a;
|
|
6583
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusChild();
|
|
6584
|
-
}), __publicField(PortableTextEditor, "getSelection", (editor) => editor.editable ? editor.editable.getSelection() : null), __publicField(PortableTextEditor, "getValue", (editor) => {
|
|
6585
|
-
var _a;
|
|
6586
|
-
return (_a = editor.editable) == null ? void 0 : _a.getValue();
|
|
6587
|
-
}), __publicField(PortableTextEditor, "hasBlockStyle", (editor, blockStyle) => {
|
|
6588
|
-
var _a;
|
|
6589
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasBlockStyle(blockStyle);
|
|
6590
|
-
}), __publicField(PortableTextEditor, "hasListStyle", (editor, listStyle) => {
|
|
6591
|
-
var _a;
|
|
6592
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasListStyle(listStyle);
|
|
6593
|
-
}), __publicField(PortableTextEditor, "isCollapsedSelection", (editor) => {
|
|
6594
|
-
var _a;
|
|
6595
|
-
return (_a = editor.editable) == null ? void 0 : _a.isCollapsedSelection();
|
|
6596
|
-
}), __publicField(PortableTextEditor, "isExpandedSelection", (editor) => {
|
|
6597
|
-
var _a;
|
|
6598
|
-
return (_a = editor.editable) == null ? void 0 : _a.isExpandedSelection();
|
|
6599
|
-
}), __publicField(PortableTextEditor, "isMarkActive", (editor, mark) => {
|
|
6600
|
-
var _a;
|
|
6601
|
-
return (_a = editor.editable) == null ? void 0 : _a.isMarkActive(mark);
|
|
6602
|
-
}), __publicField(PortableTextEditor, "insertChild", (editor, type, value) => {
|
|
6603
|
-
var _a;
|
|
6604
|
-
return debug$4("Host inserting child"), (_a = editor.editable) == null ? void 0 : _a.insertChild(type, value);
|
|
6605
|
-
}), __publicField(PortableTextEditor, "insertBlock", (editor, type, value) => {
|
|
6606
|
-
var _a;
|
|
6607
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBlock(type, value);
|
|
6608
|
-
}), __publicField(PortableTextEditor, "insertBreak", (editor) => {
|
|
6609
|
-
var _a;
|
|
6610
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBreak();
|
|
6611
|
-
}), __publicField(PortableTextEditor, "isVoid", (editor, element) => {
|
|
6612
|
-
var _a;
|
|
6613
|
-
return (_a = editor.editable) == null ? void 0 : _a.isVoid(element);
|
|
6614
|
-
}), __publicField(PortableTextEditor, "isObjectPath", (_editor, path) => {
|
|
6615
|
-
if (!path || !Array.isArray(path)) return !1;
|
|
6616
|
-
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6617
|
-
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6618
|
-
}), __publicField(PortableTextEditor, "marks", (editor) => {
|
|
6619
|
-
var _a;
|
|
6620
|
-
return (_a = editor.editable) == null ? void 0 : _a.marks();
|
|
6621
|
-
}), __publicField(PortableTextEditor, "select", (editor, selection) => {
|
|
6622
|
-
var _a;
|
|
6623
|
-
debug$4("Host setting selection", selection), (_a = editor.editable) == null || _a.select(selection);
|
|
6624
|
-
}), __publicField(PortableTextEditor, "removeAnnotation", (editor, type) => {
|
|
6625
|
-
var _a;
|
|
6626
|
-
return (_a = editor.editable) == null ? void 0 : _a.removeAnnotation(type);
|
|
6627
|
-
}), __publicField(PortableTextEditor, "toggleBlockStyle", (editor, blockStyle) => {
|
|
6628
|
-
var _a;
|
|
6629
|
-
return debug$4("Host is toggling block style"), (_a = editor.editable) == null ? void 0 : _a.toggleBlockStyle(blockStyle);
|
|
6630
|
-
}), __publicField(PortableTextEditor, "toggleList", (editor, listStyle) => {
|
|
6631
|
-
var _a;
|
|
6632
|
-
return (_a = editor.editable) == null ? void 0 : _a.toggleList(listStyle);
|
|
6633
|
-
}), __publicField(PortableTextEditor, "toggleMark", (editor, mark) => {
|
|
6634
|
-
var _a;
|
|
6635
|
-
debug$4("Host toggling mark", mark), (_a = editor.editable) == null || _a.toggleMark(mark);
|
|
6636
|
-
}), __publicField(PortableTextEditor, "getFragment", (editor) => {
|
|
6637
|
-
var _a;
|
|
6638
|
-
return debug$4("Host getting fragment"), (_a = editor.editable) == null ? void 0 : _a.getFragment();
|
|
6639
|
-
}), __publicField(PortableTextEditor, "undo", (editor) => {
|
|
6640
|
-
var _a;
|
|
6641
|
-
debug$4("Host undoing"), (_a = editor.editable) == null || _a.undo();
|
|
6642
|
-
}), __publicField(PortableTextEditor, "redo", (editor) => {
|
|
6643
|
-
var _a;
|
|
6644
|
-
debug$4("Host redoing"), (_a = editor.editable) == null || _a.redo();
|
|
6645
|
-
}), __publicField(PortableTextEditor, "isSelectionsOverlapping", (editor, selectionA, selectionB) => {
|
|
6646
|
-
var _a;
|
|
6647
|
-
return (_a = editor.editable) == null ? void 0 : _a.isSelectionsOverlapping(selectionA, selectionB);
|
|
6648
|
-
});
|
|
6649
6297
|
function RoutePatchesObservableToEditorActor(props) {
|
|
6650
6298
|
const $ = c(4);
|
|
6651
6299
|
let t0, t1;
|
|
6652
6300
|
return $[0] !== props.editorActor || $[1] !== props.patches$ ? (t0 = () => {
|
|
6653
6301
|
const subscription = props.patches$.subscribe((payload) => {
|
|
6654
|
-
props.editorActor.send(
|
|
6655
|
-
type: "patches"
|
|
6656
|
-
|
|
6302
|
+
props.editorActor.send({
|
|
6303
|
+
type: "patches",
|
|
6304
|
+
...payload
|
|
6305
|
+
});
|
|
6657
6306
|
});
|
|
6658
6307
|
return () => {
|
|
6659
6308
|
subscription.unsubscribe();
|
|
@@ -6718,9 +6367,10 @@ function RouteEventsToChanges(props) {
|
|
|
6718
6367
|
break bb5;
|
|
6719
6368
|
}
|
|
6720
6369
|
case "error": {
|
|
6721
|
-
handleChange(
|
|
6370
|
+
handleChange({
|
|
6371
|
+
...event,
|
|
6722
6372
|
level: "warning"
|
|
6723
|
-
})
|
|
6373
|
+
});
|
|
6724
6374
|
break bb5;
|
|
6725
6375
|
}
|
|
6726
6376
|
case "annotation.add":
|
|
@@ -6748,14 +6398,6 @@ function RouteEventsToChanges(props) {
|
|
|
6748
6398
|
};
|
|
6749
6399
|
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), null;
|
|
6750
6400
|
}
|
|
6751
|
-
var __defProp$2 = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
|
|
6752
|
-
for (var prop in b || (b = {}))
|
|
6753
|
-
__hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6754
|
-
if (__getOwnPropSymbols$2)
|
|
6755
|
-
for (var prop of __getOwnPropSymbols$2(b))
|
|
6756
|
-
__propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6757
|
-
return a;
|
|
6758
|
-
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
6759
6401
|
const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
6760
6402
|
const {
|
|
6761
6403
|
editorActor,
|
|
@@ -6767,13 +6409,10 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6767
6409
|
renderDecorator,
|
|
6768
6410
|
renderAnnotation
|
|
6769
6411
|
} = props, spanRef = useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = useSelected(), [focused, setFocused] = useState(!1), [selected, setSelected] = useState(!1), block = children.props.parent, path = useMemo(() => block ? [{
|
|
6770
|
-
_key: block
|
|
6412
|
+
_key: block?._key
|
|
6771
6413
|
}, "children", {
|
|
6772
6414
|
_key: leaf._key
|
|
6773
|
-
}] : [], [block, leaf._key]), decoratorValues = useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = useMemo(() => uniq((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = useMemo(() => annotationMarks.map((mark_0) =>
|
|
6774
|
-
var _a;
|
|
6775
|
-
return !decoratorValues.includes(mark_0) && ((_a = block == null ? void 0 : block.markDefs) == null ? void 0 : _a.find((def) => def._key === mark_0));
|
|
6776
|
-
}).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
6415
|
+
}] : [], [block, leaf._key]), decoratorValues = useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = useMemo(() => uniq((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = useMemo(() => annotationMarks.map((mark_0) => !decoratorValues.includes(mark_0) && block?.markDefs?.find((def) => def._key === mark_0)).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
6777
6416
|
useEffect(() => {
|
|
6778
6417
|
if (!shouldTrackSelectionAndFocus) {
|
|
6779
6418
|
setFocused(!1);
|
|
@@ -6880,7 +6519,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6880
6519
|
}
|
|
6881
6520
|
return returnedChildren;
|
|
6882
6521
|
}, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
|
|
6883
|
-
return useMemo(() => /* @__PURE__ */ jsx("span",
|
|
6522
|
+
return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6884
6523
|
};
|
|
6885
6524
|
Leaf.displayName = "Leaf";
|
|
6886
6525
|
const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
@@ -6933,32 +6572,10 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6933
6572
|
}, editor;
|
|
6934
6573
|
};
|
|
6935
6574
|
}
|
|
6936
|
-
var __defProp$1 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
|
|
6937
|
-
for (var prop in b || (b = {}))
|
|
6938
|
-
__hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6939
|
-
if (__getOwnPropSymbols$1)
|
|
6940
|
-
for (var prop of __getOwnPropSymbols$1(b))
|
|
6941
|
-
__propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6942
|
-
return a;
|
|
6943
|
-
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), __objRest$1 = (source, exclude) => {
|
|
6944
|
-
var target = {};
|
|
6945
|
-
for (var prop in source)
|
|
6946
|
-
__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
6947
|
-
if (source != null && __getOwnPropSymbols$1)
|
|
6948
|
-
for (var prop of __getOwnPropSymbols$1(source))
|
|
6949
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop) && (target[prop] = source[prop]);
|
|
6950
|
-
return target;
|
|
6951
|
-
};
|
|
6952
6575
|
const debug$1 = debugWithName("plugin:withInsertData");
|
|
6953
6576
|
function createWithInsertData(editorActor, schemaTypes) {
|
|
6954
6577
|
return function(editor) {
|
|
6955
|
-
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => {
|
|
6956
|
-
var _a;
|
|
6957
|
-
return editor.isTextBlock(block) ? block.children.map((child) => {
|
|
6958
|
-
var _a2;
|
|
6959
|
-
return child._type === spanTypeName ? child.text : `[${((_a2 = schemaTypes.inlineObjects.find((t) => t.name === child._type)) == null ? void 0 : _a2.title) || "Object"}]`;
|
|
6960
|
-
}).join("") : `[${((_a = schemaTypes.blockObjects.find((t) => t.name === block._type)) == null ? void 0 : _a.title) || "Object"}]`;
|
|
6961
|
-
}).join(`
|
|
6578
|
+
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => editor.isTextBlock(block) ? block.children.map((child) => child._type === spanTypeName ? child.text : `[${schemaTypes.inlineObjects.find((t) => t.name === child._type)?.title || "Object"}]`).join("") : `[${schemaTypes.blockObjects.find((t) => t.name === block._type)?.title || "Object"}]`).join(`
|
|
6962
6579
|
|
|
6963
6580
|
`);
|
|
6964
6581
|
return editor.setFragmentData = (data, originEvent) => {
|
|
@@ -6996,7 +6613,6 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
6996
6613
|
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
6997
6614
|
data.clearData(), data.setData("text/plain", asPlainText), data.setData("text/html", asHTML), data.setData("application/json", asJSON), data.setData("application/x-portable-text", asJSON), debug$1("text", asPlainText), data.setData("application/x-portable-text-event-origin", originEvent || "external"), debug$1("Set fragment data", asJSON, asHTML);
|
|
6998
6615
|
}, editor.insertPortableTextData = (data) => {
|
|
6999
|
-
var _a, _b;
|
|
7000
6616
|
if (!editor.selection)
|
|
7001
6617
|
return !1;
|
|
7002
6618
|
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
@@ -7006,8 +6622,8 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7006
6622
|
const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
|
|
7007
6623
|
schemaTypes
|
|
7008
6624
|
}), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7009
|
-
if (!validation.valid && !
|
|
7010
|
-
const errorDescription = `${
|
|
6625
|
+
if (!validation.valid && !validation.resolution?.autoResolve) {
|
|
6626
|
+
const errorDescription = `${validation.resolution?.description}`;
|
|
7011
6627
|
return editorActor.send({
|
|
7012
6628
|
type: "error",
|
|
7013
6629
|
name: "pasteError",
|
|
@@ -7020,7 +6636,6 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7020
6636
|
}
|
|
7021
6637
|
return !1;
|
|
7022
6638
|
}, editor.insertTextOrHTMLData = (data) => {
|
|
7023
|
-
var _a;
|
|
7024
6639
|
if (!editor.selection)
|
|
7025
6640
|
return debug$1("No selection, not inserting"), !1;
|
|
7026
6641
|
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
@@ -7047,7 +6662,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7047
6662
|
const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7048
6663
|
if (!validation.valid) {
|
|
7049
6664
|
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
7050
|
-
${
|
|
6665
|
+
${validation.resolution?.description}
|
|
7051
6666
|
Try to insert as plain text (shift-paste) instead.`;
|
|
7052
6667
|
return editorActor.send({
|
|
7053
6668
|
type: "error",
|
|
@@ -7086,37 +6701,46 @@ function escapeHtml(str) {
|
|
|
7086
6701
|
}
|
|
7087
6702
|
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
7088
6703
|
return fragment.map((node) => {
|
|
7089
|
-
const newNode =
|
|
6704
|
+
const newNode = {
|
|
6705
|
+
...node
|
|
6706
|
+
};
|
|
7090
6707
|
if (editor.isTextBlock(newNode)) {
|
|
7091
6708
|
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
7092
6709
|
if (annotations.length === 0) {
|
|
7093
|
-
const
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
6710
|
+
const {
|
|
6711
|
+
markDefs,
|
|
6712
|
+
...NewNodeNoDefs
|
|
6713
|
+
} = newNode;
|
|
6714
|
+
return {
|
|
6715
|
+
...NewNodeNoDefs,
|
|
7097
6716
|
_key: keyGenerator()
|
|
7098
|
-
}
|
|
6717
|
+
};
|
|
7099
6718
|
}
|
|
7100
6719
|
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
7101
6720
|
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
7102
|
-
return
|
|
6721
|
+
return {
|
|
6722
|
+
...newNode,
|
|
7103
6723
|
markDefs: allowedAnnotations,
|
|
7104
6724
|
_key: keyGenerator()
|
|
7105
|
-
}
|
|
6725
|
+
};
|
|
7106
6726
|
}
|
|
7107
6727
|
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
7108
6728
|
const oldKey = def._key, newKey = keyGenerator();
|
|
7109
|
-
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ?
|
|
6729
|
+
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
6730
|
+
...child,
|
|
7110
6731
|
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
7111
|
-
}
|
|
6732
|
+
} : child), {
|
|
6733
|
+
...def,
|
|
7112
6734
|
_key: newKey
|
|
7113
|
-
}
|
|
6735
|
+
};
|
|
7114
6736
|
});
|
|
7115
6737
|
}
|
|
7116
|
-
const nodeWithNewKeys =
|
|
6738
|
+
const nodeWithNewKeys = {
|
|
6739
|
+
...newNode,
|
|
7117
6740
|
_key: keyGenerator()
|
|
7118
|
-
}
|
|
7119
|
-
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) =>
|
|
6741
|
+
};
|
|
6742
|
+
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
6743
|
+
...child,
|
|
7120
6744
|
_key: keyGenerator()
|
|
7121
6745
|
}))), nodeWithNewKeys;
|
|
7122
6746
|
});
|
|
@@ -7161,22 +6785,6 @@ function withSyncRangeDecorations({
|
|
|
7161
6785
|
slateEditor.apply = originalApply;
|
|
7162
6786
|
};
|
|
7163
6787
|
}
|
|
7164
|
-
var __defProp2 = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols2 = Object.getOwnPropertySymbols, __hasOwnProp2 = Object.prototype.hasOwnProperty, __propIsEnum2 = Object.prototype.propertyIsEnumerable, __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues2 = (a, b) => {
|
|
7165
|
-
for (var prop in b || (b = {}))
|
|
7166
|
-
__hasOwnProp2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
7167
|
-
if (__getOwnPropSymbols2)
|
|
7168
|
-
for (var prop of __getOwnPropSymbols2(b))
|
|
7169
|
-
__propIsEnum2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
7170
|
-
return a;
|
|
7171
|
-
}, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)), __objRest = (source, exclude) => {
|
|
7172
|
-
var target = {};
|
|
7173
|
-
for (var prop in source)
|
|
7174
|
-
__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
7175
|
-
if (source != null && __getOwnPropSymbols2)
|
|
7176
|
-
for (var prop of __getOwnPropSymbols2(source))
|
|
7177
|
-
exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop) && (target[prop] = source[prop]);
|
|
7178
|
-
return target;
|
|
7179
|
-
};
|
|
7180
6788
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
7181
6789
|
position: "absolute",
|
|
7182
6790
|
userSelect: "none",
|
|
@@ -7184,7 +6792,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7184
6792
|
left: 0,
|
|
7185
6793
|
right: 0
|
|
7186
6794
|
}, PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
7187
|
-
const
|
|
6795
|
+
const {
|
|
7188
6796
|
hotkeys,
|
|
7189
6797
|
onBlur,
|
|
7190
6798
|
onFocus,
|
|
@@ -7202,27 +6810,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7202
6810
|
renderStyle,
|
|
7203
6811
|
selection: propsSelection,
|
|
7204
6812
|
scrollSelectionIntoView,
|
|
7205
|
-
spellCheck
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
"onBlur",
|
|
7209
|
-
"onFocus",
|
|
7210
|
-
"onBeforeInput",
|
|
7211
|
-
"onPaste",
|
|
7212
|
-
"onCopy",
|
|
7213
|
-
"onClick",
|
|
7214
|
-
"rangeDecorations",
|
|
7215
|
-
"renderAnnotation",
|
|
7216
|
-
"renderBlock",
|
|
7217
|
-
"renderChild",
|
|
7218
|
-
"renderDecorator",
|
|
7219
|
-
"renderListItem",
|
|
7220
|
-
"renderPlaceholder",
|
|
7221
|
-
"renderStyle",
|
|
7222
|
-
"selection",
|
|
7223
|
-
"scrollSelectionIntoView",
|
|
7224
|
-
"spellCheck"
|
|
7225
|
-
]), portableTextEditor = usePortableTextEditor(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
|
|
6813
|
+
spellCheck,
|
|
6814
|
+
...restProps
|
|
6815
|
+
} = props, portableTextEditor = usePortableTextEditor(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
|
|
7226
6816
|
useImperativeHandle(forwardedRef, () => ref.current);
|
|
7227
6817
|
const rangeDecorationsRef = useRef(rangeDecorations), editorActor = useContext(EditorActorContext), readOnly = useSelector(editorActor, (s) => s.matches({
|
|
7228
6818
|
"edit mode": "read only"
|
|
@@ -7234,9 +6824,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7234
6824
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
7235
6825
|
return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
|
|
7236
6826
|
}, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
|
|
7237
|
-
const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element,
|
|
6827
|
+
const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((lProps) => {
|
|
7238
6828
|
if (lProps.leaf._type === "span") {
|
|
7239
|
-
let rendered = /* @__PURE__ */ jsx(Leaf,
|
|
6829
|
+
let rendered = /* @__PURE__ */ jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
7240
6830
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
7241
6831
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7242
6832
|
/* @__PURE__ */ jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: renderPlaceholder() }),
|
|
@@ -7283,9 +6873,10 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7283
6873
|
origin: "local"
|
|
7284
6874
|
});
|
|
7285
6875
|
}
|
|
7286
|
-
newRange !== null && newSlateRanges.push(
|
|
6876
|
+
newRange !== null && newSlateRanges.push({
|
|
6877
|
+
...newRange || slateRange_0,
|
|
7287
6878
|
rangeDecoration: rangeDecorationItem
|
|
7288
|
-
})
|
|
6879
|
+
});
|
|
7289
6880
|
}), newSlateRanges.length > 0) {
|
|
7290
6881
|
setRangeDecorationsState(newSlateRanges);
|
|
7291
6882
|
return;
|
|
@@ -7331,7 +6922,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7331
6922
|
nativeEvent: event
|
|
7332
6923
|
});
|
|
7333
6924
|
}, [onCopy, editorActor, slateEditor]), handlePaste = useCallback((event_0) => {
|
|
7334
|
-
const value_0 = PortableTextEditor.getValue(portableTextEditor),
|
|
6925
|
+
const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
|
|
7335
6926
|
event: event_0,
|
|
7336
6927
|
value: value_0,
|
|
7337
6928
|
path,
|
|
@@ -7396,8 +6987,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7396
6987
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
7397
6988
|
try {
|
|
7398
6989
|
const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
7399
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection
|
|
7400
|
-
} catch
|
|
6990
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
6991
|
+
} catch {
|
|
7401
6992
|
debug("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
7402
6993
|
}
|
|
7403
6994
|
}, [ref, slateEditor]);
|
|
@@ -7485,7 +7076,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7485
7076
|
ref.current = ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
7486
7077
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsx(
|
|
7487
7078
|
Editable,
|
|
7488
|
-
|
|
7079
|
+
{
|
|
7080
|
+
...restProps,
|
|
7489
7081
|
autoFocus: !1,
|
|
7490
7082
|
className: restProps.className || "pt-editable",
|
|
7491
7083
|
decorate,
|
|
@@ -7502,7 +7094,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7502
7094
|
renderElement,
|
|
7503
7095
|
renderLeaf,
|
|
7504
7096
|
scrollSelectionIntoView: scrollSelectionIntoViewToSlate
|
|
7505
|
-
}
|
|
7097
|
+
}
|
|
7506
7098
|
) : null;
|
|
7507
7099
|
});
|
|
7508
7100
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|