@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.cjs
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
|
|
6
|
-
for (var prop in b || (b = {}))
|
|
7
|
-
__hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
8
|
-
if (__getOwnPropSymbols)
|
|
9
|
-
for (var prop of __getOwnPropSymbols(b))
|
|
10
|
-
__propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
11
|
-
return a;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
14
3
|
var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$l = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isSelectionCollapsed = require("./_chunks-cjs/selector.is-selection-collapsed.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), blockTools = require("@sanity/block-tools");
|
|
15
4
|
function _interopDefaultCompat(e) {
|
|
@@ -17,13 +6,12 @@ function _interopDefaultCompat(e) {
|
|
|
17
6
|
}
|
|
18
7
|
var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$l), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
|
|
19
8
|
function createEditorSchema(portableTextType) {
|
|
20
|
-
var _a, _b, _c;
|
|
21
9
|
if (!portableTextType)
|
|
22
10
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
23
|
-
const blockType =
|
|
11
|
+
const blockType = portableTextType.of?.find(findBlockType);
|
|
24
12
|
if (!blockType)
|
|
25
13
|
throw new Error("Block type is not defined in this schema (required)");
|
|
26
|
-
const childrenField =
|
|
14
|
+
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
27
15
|
if (!childrenField)
|
|
28
16
|
throw new Error("Children field for block type found in schema (required)");
|
|
29
17
|
const ofType = childrenField.type.of;
|
|
@@ -32,7 +20,7 @@ function createEditorSchema(portableTextType) {
|
|
|
32
20
|
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
33
21
|
if (!spanType)
|
|
34
22
|
throw new Error("Span type not found in schema (required)");
|
|
35
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes =
|
|
23
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
36
24
|
return {
|
|
37
25
|
styles: resolveEnabledStyles(blockType),
|
|
38
26
|
decorators: resolveEnabledDecorators(spanType),
|
|
@@ -46,11 +34,10 @@ function createEditorSchema(portableTextType) {
|
|
|
46
34
|
};
|
|
47
35
|
}
|
|
48
36
|
function resolveEnabledStyles(blockType) {
|
|
49
|
-
|
|
50
|
-
const styleField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "style");
|
|
37
|
+
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
51
38
|
if (!styleField)
|
|
52
39
|
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
53
|
-
const textStyles =
|
|
40
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
54
41
|
if (!textStyles || textStyles.length === 0)
|
|
55
42
|
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
56
43
|
return textStyles;
|
|
@@ -59,11 +46,10 @@ function resolveEnabledDecorators(spanType) {
|
|
|
59
46
|
return spanType.decorators;
|
|
60
47
|
}
|
|
61
48
|
function resolveEnabledListItems(blockType) {
|
|
62
|
-
|
|
63
|
-
const listField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "listItem");
|
|
49
|
+
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
64
50
|
if (!listField)
|
|
65
51
|
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
66
|
-
const listItems =
|
|
52
|
+
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
67
53
|
if (!listItems)
|
|
68
54
|
throw new Error("The list field need at least to be an empty array");
|
|
69
55
|
return listItems;
|
|
@@ -71,20 +57,11 @@ function resolveEnabledListItems(blockType) {
|
|
|
71
57
|
function findBlockType(type) {
|
|
72
58
|
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
73
59
|
}
|
|
74
|
-
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) => {
|
|
75
|
-
for (var prop in b || (b = {}))
|
|
76
|
-
__hasOwnProp$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
|
|
77
|
-
if (__getOwnPropSymbols$q)
|
|
78
|
-
for (var prop of __getOwnPropSymbols$q(b))
|
|
79
|
-
__propIsEnum$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
|
|
80
|
-
return a;
|
|
81
|
-
}, __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
|
|
82
60
|
function defineSchema(definition) {
|
|
83
61
|
return definition;
|
|
84
62
|
}
|
|
85
63
|
function compileSchemaDefinition(definition) {
|
|
86
|
-
|
|
87
|
-
const blockObjects = (_b = (_a = definition == null ? void 0 : definition.blockObjects) == null ? void 0 : _a.map((blockObject) => types.defineType({
|
|
64
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
|
|
88
65
|
type: "object",
|
|
89
66
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
90
67
|
// fields to objects with the name `image`
|
|
@@ -92,13 +69,13 @@ function compileSchemaDefinition(definition) {
|
|
|
92
69
|
title: blockObject.title,
|
|
93
70
|
icon: blockObject.icon,
|
|
94
71
|
fields: []
|
|
95
|
-
}))
|
|
72
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
|
|
96
73
|
type: "object",
|
|
97
74
|
name: inlineObject.name,
|
|
98
75
|
title: inlineObject.title,
|
|
99
76
|
icon: inlineObject.icon,
|
|
100
77
|
fields: []
|
|
101
|
-
}))
|
|
78
|
+
})) ?? [], portableTextSchema = types.defineField({
|
|
102
79
|
type: "array",
|
|
103
80
|
name: "portable-text",
|
|
104
81
|
of: [...blockObjects.map((blockObject) => ({
|
|
@@ -110,49 +87,43 @@ function compileSchemaDefinition(definition) {
|
|
|
110
87
|
type: inlineObject.name
|
|
111
88
|
})),
|
|
112
89
|
marks: {
|
|
113
|
-
decorators:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
})) != null ? _f : [],
|
|
121
|
-
annotations: (_h = (_g = definition == null ? void 0 : definition.annotations) == null ? void 0 : _g.map((annotation) => ({
|
|
90
|
+
decorators: definition?.decorators?.map((decorator) => ({
|
|
91
|
+
title: decorator.title ?? startCase__default.default(decorator.name),
|
|
92
|
+
value: decorator.name,
|
|
93
|
+
icon: decorator.icon
|
|
94
|
+
})) ?? [],
|
|
95
|
+
annotations: definition?.annotations?.map((annotation) => ({
|
|
122
96
|
name: annotation.name,
|
|
123
97
|
type: "object",
|
|
124
98
|
title: annotation.title,
|
|
125
99
|
icon: annotation.icon
|
|
126
|
-
}))
|
|
100
|
+
})) ?? []
|
|
127
101
|
},
|
|
128
|
-
lists:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
value: style.name,
|
|
140
|
-
title: (_a2 = style.title) != null ? _a2 : startCase__default.default(style.name),
|
|
141
|
-
icon: style.icon
|
|
142
|
-
};
|
|
143
|
-
})) != null ? _l : []
|
|
102
|
+
lists: definition?.lists?.map((list) => ({
|
|
103
|
+
value: list.name,
|
|
104
|
+
title: list.title ?? startCase__default.default(list.name),
|
|
105
|
+
icon: list.icon
|
|
106
|
+
})) ?? [],
|
|
107
|
+
styles: definition?.styles?.map((style) => ({
|
|
108
|
+
value: style.name,
|
|
109
|
+
title: style.title ?? startCase__default.default(style.name),
|
|
110
|
+
icon: style.icon
|
|
111
|
+
})) ?? []
|
|
144
112
|
}]
|
|
145
113
|
}), schema$1 = schema.Schema.compile({
|
|
146
114
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
147
115
|
}).get("portable-text"), pteSchema = createEditorSchema(schema$1);
|
|
148
|
-
return
|
|
149
|
-
|
|
116
|
+
return {
|
|
117
|
+
...pteSchema,
|
|
118
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
|
|
119
|
+
...blockObject,
|
|
150
120
|
name: "image",
|
|
151
|
-
type:
|
|
121
|
+
type: {
|
|
122
|
+
...blockObject.type,
|
|
152
123
|
name: "image"
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
124
|
+
}
|
|
125
|
+
} : blockObject)
|
|
126
|
+
};
|
|
156
127
|
}
|
|
157
128
|
const rootName = "sanity-pte:";
|
|
158
129
|
debug__default.default(rootName);
|
|
@@ -287,22 +258,6 @@ function normalizeSelection(selection, value) {
|
|
|
287
258
|
backward: selection.backward
|
|
288
259
|
} : null;
|
|
289
260
|
}
|
|
290
|
-
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) => {
|
|
291
|
-
for (var prop in b || (b = {}))
|
|
292
|
-
__hasOwnProp$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
293
|
-
if (__getOwnPropSymbols$p)
|
|
294
|
-
for (var prop of __getOwnPropSymbols$p(b))
|
|
295
|
-
__propIsEnum$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
296
|
-
return a;
|
|
297
|
-
}, __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b)), __objRest$3 = (source, exclude) => {
|
|
298
|
-
var target = {};
|
|
299
|
-
for (var prop in source)
|
|
300
|
-
__hasOwnProp$p.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
301
|
-
if (source != null && __getOwnPropSymbols$p)
|
|
302
|
-
for (var prop of __getOwnPropSymbols$p(source))
|
|
303
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$p.call(source, prop) && (target[prop] = source[prop]);
|
|
304
|
-
return target;
|
|
305
|
-
};
|
|
306
261
|
const VOID_CHILD_KEY = "void-child";
|
|
307
262
|
function keepObjectEquality(object, keyMap) {
|
|
308
263
|
const value = keyMap[object._key];
|
|
@@ -312,13 +267,11 @@ function toSlateValue(value, {
|
|
|
312
267
|
schemaTypes
|
|
313
268
|
}, keyMap = {}) {
|
|
314
269
|
return value && Array.isArray(value) ? value.map((block) => {
|
|
315
|
-
const
|
|
270
|
+
const {
|
|
316
271
|
_type,
|
|
317
|
-
_key
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
"_key"
|
|
321
|
-
]), voidChildren = [{
|
|
272
|
+
_key,
|
|
273
|
+
...rest
|
|
274
|
+
} = block, voidChildren = [{
|
|
322
275
|
_key: VOID_CHILD_KEY,
|
|
323
276
|
_type: "span",
|
|
324
277
|
text: "",
|
|
@@ -328,13 +281,11 @@ function toSlateValue(value, {
|
|
|
328
281
|
const textBlock = block;
|
|
329
282
|
let hasInlines = !1;
|
|
330
283
|
const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
|
|
331
|
-
const
|
|
284
|
+
const {
|
|
332
285
|
_type: cType,
|
|
333
|
-
_key: cKey
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
"_key"
|
|
337
|
-
]);
|
|
286
|
+
_key: cKey,
|
|
287
|
+
...cRest
|
|
288
|
+
} = child;
|
|
338
289
|
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
339
290
|
_type: cType,
|
|
340
291
|
_key: cKey,
|
|
@@ -343,12 +294,12 @@ function toSlateValue(value, {
|
|
|
343
294
|
__inline: !0
|
|
344
295
|
}, keyMap)) : child;
|
|
345
296
|
});
|
|
346
|
-
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(
|
|
297
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality({
|
|
347
298
|
_type,
|
|
348
|
-
_key
|
|
349
|
-
|
|
299
|
+
_key,
|
|
300
|
+
...rest,
|
|
350
301
|
children
|
|
351
|
-
}
|
|
302
|
+
}, keyMap));
|
|
352
303
|
}
|
|
353
304
|
return keepObjectEquality({
|
|
354
305
|
_type,
|
|
@@ -374,42 +325,40 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
374
325
|
} = child;
|
|
375
326
|
if ("value" in child && _cType !== "span") {
|
|
376
327
|
hasInlines = !0;
|
|
377
|
-
const
|
|
328
|
+
const {
|
|
378
329
|
value: v,
|
|
379
330
|
_key: k,
|
|
380
331
|
_type: t,
|
|
381
332
|
__inline: _i,
|
|
382
|
-
children: _c
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
"children"
|
|
389
|
-
]);
|
|
390
|
-
return keepObjectEquality(__spreadProps$i(__spreadValues$p(__spreadValues$p({}, rest), v), {
|
|
333
|
+
children: _c,
|
|
334
|
+
...rest
|
|
335
|
+
} = child;
|
|
336
|
+
return keepObjectEquality({
|
|
337
|
+
...rest,
|
|
338
|
+
...v,
|
|
391
339
|
_key: k,
|
|
392
340
|
_type: t
|
|
393
|
-
}
|
|
341
|
+
}, keyMap);
|
|
394
342
|
}
|
|
395
343
|
return child;
|
|
396
344
|
});
|
|
397
|
-
return hasInlines ? keepObjectEquality(
|
|
345
|
+
return hasInlines ? keepObjectEquality({
|
|
346
|
+
...block,
|
|
398
347
|
children,
|
|
399
348
|
_key,
|
|
400
349
|
_type
|
|
401
|
-
}
|
|
350
|
+
}, keyMap) : block;
|
|
402
351
|
}
|
|
403
352
|
const blockValue = "value" in block && block.value;
|
|
404
|
-
return keepObjectEquality(
|
|
353
|
+
return keepObjectEquality({
|
|
405
354
|
_key,
|
|
406
|
-
_type
|
|
407
|
-
|
|
355
|
+
_type,
|
|
356
|
+
...typeof blockValue == "object" ? blockValue : {}
|
|
357
|
+
}, keyMap);
|
|
408
358
|
});
|
|
409
359
|
}
|
|
410
360
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
411
|
-
|
|
412
|
-
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !((_a = children[0].children[0].marks) != null && _a.join("")) && children[0].children[0].text === "";
|
|
361
|
+
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
413
362
|
}
|
|
414
363
|
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) => {
|
|
415
364
|
const $ = reactCompilerRuntime.c(4);
|
|
@@ -709,14 +658,6 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
709
658
|
] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
|
|
710
659
|
};
|
|
711
660
|
DraggableBlock.displayName = "DraggableBlock";
|
|
712
|
-
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) => {
|
|
713
|
-
for (var prop in b || (b = {}))
|
|
714
|
-
__hasOwnProp$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
715
|
-
if (__getOwnPropSymbols$o)
|
|
716
|
-
for (var prop of __getOwnPropSymbols$o(b))
|
|
717
|
-
__propIsEnum$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
718
|
-
return a;
|
|
719
|
-
}, __spreadProps$h = (a, b) => __defProps$h(a, __getOwnPropDescs$h(b));
|
|
720
661
|
debugWithName("components:Element");
|
|
721
662
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
722
663
|
display: "inline-block"
|
|
@@ -753,7 +694,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
753
694
|
}, "children", {
|
|
754
695
|
_key: element._key
|
|
755
696
|
}];
|
|
756
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span",
|
|
697
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", { ...attributes, children: [
|
|
757
698
|
children,
|
|
758
699
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
|
|
759
700
|
renderChild && renderChild({
|
|
@@ -770,7 +711,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
770
711
|
}),
|
|
771
712
|
!renderChild && /* @__PURE__ */ jsxRuntime.jsx(DefaultObject, { value })
|
|
772
713
|
] }, element._key)
|
|
773
|
-
] })
|
|
714
|
+
] });
|
|
774
715
|
}
|
|
775
716
|
throw new Error("Block not found!");
|
|
776
717
|
}
|
|
@@ -821,7 +762,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
821
762
|
return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
|
|
822
763
|
}
|
|
823
764
|
}), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
|
|
824
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div",
|
|
765
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ...attributes, className, spellCheck, children: /* @__PURE__ */ jsxRuntime.jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }, element._key);
|
|
825
766
|
}
|
|
826
767
|
const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
|
|
827
768
|
if (!schemaType_0)
|
|
@@ -846,13 +787,13 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
846
787
|
});
|
|
847
788
|
renderedBlockFromProps = renderBlock(_props);
|
|
848
789
|
}
|
|
849
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div",
|
|
790
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...attributes, className, children: [
|
|
850
791
|
children,
|
|
851
792
|
/* @__PURE__ */ jsxRuntime.jsxs(DraggableBlock, { element, readOnly, blockRef, children: [
|
|
852
793
|
renderedBlockFromProps && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
|
|
853
794
|
!renderedBlockFromProps && /* @__PURE__ */ jsxRuntime.jsx(DefaultBlockObject, { selected, children: /* @__PURE__ */ jsxRuntime.jsx(DefaultObject, { value }) })
|
|
854
795
|
] })
|
|
855
|
-
] }
|
|
796
|
+
] }, element._key);
|
|
856
797
|
};
|
|
857
798
|
Element.displayName = "Element";
|
|
858
799
|
const PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
|
|
@@ -951,14 +892,6 @@ const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3,
|
|
|
951
892
|
}
|
|
952
893
|
}
|
|
953
894
|
});
|
|
954
|
-
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) => {
|
|
955
|
-
for (var prop in b || (b = {}))
|
|
956
|
-
__hasOwnProp$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
957
|
-
if (__getOwnPropSymbols$n)
|
|
958
|
-
for (var prop of __getOwnPropSymbols$n(b))
|
|
959
|
-
__propIsEnum$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
960
|
-
return a;
|
|
961
|
-
}, __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
|
|
962
895
|
function validateValue(value, types$1, keyGenerator) {
|
|
963
896
|
let resolution = null, valid = !0;
|
|
964
897
|
const validChildTypes = [types$1.span.name, ...types$1.inlineObjects.map((t) => t.name)], validBlockTypes = [types$1.block.name, ...types$1.blockObjects.map((t) => t.name)];
|
|
@@ -996,9 +929,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
996
929
|
}, !0;
|
|
997
930
|
if (!blk._key || typeof blk._key != "string")
|
|
998
931
|
return resolution = {
|
|
999
|
-
patches: [patches.set(
|
|
932
|
+
patches: [patches.set({
|
|
933
|
+
...blk,
|
|
1000
934
|
_key: keyGenerator()
|
|
1001
|
-
}
|
|
935
|
+
}, [index])],
|
|
1002
936
|
description: `Block at index ${index} is missing required _key.`,
|
|
1003
937
|
action: "Set the block with a random _key value",
|
|
1004
938
|
item: blk,
|
|
@@ -1014,9 +948,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1014
948
|
if (blk._type === "block") {
|
|
1015
949
|
const currentBlockTypeName = types$1.block.name;
|
|
1016
950
|
return resolution = {
|
|
1017
|
-
patches: [patches.set(
|
|
951
|
+
patches: [patches.set({
|
|
952
|
+
...blk,
|
|
1018
953
|
_type: currentBlockTypeName
|
|
1019
|
-
}
|
|
954
|
+
}, [{
|
|
1020
955
|
_key: blk._key
|
|
1021
956
|
}])],
|
|
1022
957
|
description: `Block with _key '${blk._key}' has invalid type name '${blk._type}'. According to the schema, the block type name is '${currentBlockTypeName}'`,
|
|
@@ -1032,12 +967,14 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1032
967
|
}
|
|
1033
968
|
}, !0;
|
|
1034
969
|
}
|
|
1035
|
-
return !blk._type && types.isPortableTextTextBlock(
|
|
970
|
+
return !blk._type && types.isPortableTextTextBlock({
|
|
971
|
+
...blk,
|
|
1036
972
|
_type: types$1.block.name
|
|
1037
|
-
})
|
|
1038
|
-
patches: [patches.set(
|
|
973
|
+
}) ? (resolution = {
|
|
974
|
+
patches: [patches.set({
|
|
975
|
+
...blk,
|
|
1039
976
|
_type: types$1.block.name
|
|
1040
|
-
}
|
|
977
|
+
}, [{
|
|
1041
978
|
_key: blk._key
|
|
1042
979
|
}])],
|
|
1043
980
|
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types$1.block.name}'`,
|
|
@@ -1197,9 +1134,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1197
1134
|
}
|
|
1198
1135
|
}, !0;
|
|
1199
1136
|
if (!child._key || typeof child._key != "string") {
|
|
1200
|
-
const newChild =
|
|
1137
|
+
const newChild = {
|
|
1138
|
+
...child,
|
|
1201
1139
|
_key: keyGenerator()
|
|
1202
|
-
}
|
|
1140
|
+
};
|
|
1203
1141
|
return resolution = {
|
|
1204
1142
|
autoResolve: !0,
|
|
1205
1143
|
patches: [patches.set(newChild, [{
|
|
@@ -1219,9 +1157,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1219
1157
|
}, !0;
|
|
1220
1158
|
}
|
|
1221
1159
|
return child._type ? validChildTypes.includes(child._type) ? child._type === types$1.span.name && typeof child.text != "string" ? (resolution = {
|
|
1222
|
-
patches: [patches.set(
|
|
1160
|
+
patches: [patches.set({
|
|
1161
|
+
...child,
|
|
1223
1162
|
text: ""
|
|
1224
|
-
}
|
|
1163
|
+
}, [{
|
|
1225
1164
|
_key: blk._key
|
|
1226
1165
|
}, "children", {
|
|
1227
1166
|
_key: child._key
|
|
@@ -1297,14 +1236,6 @@ function withoutPatching(editor, fn) {
|
|
|
1297
1236
|
function isPatching(editor) {
|
|
1298
1237
|
return PATCHING.get(editor);
|
|
1299
1238
|
}
|
|
1300
|
-
function isHighSurrogate(char) {
|
|
1301
|
-
const charCode = char.charCodeAt(0);
|
|
1302
|
-
return charCode >= 55296 && charCode <= 56319;
|
|
1303
|
-
}
|
|
1304
|
-
function isLowSurrogate(char) {
|
|
1305
|
-
const charCode = char.charCodeAt(0);
|
|
1306
|
-
return charCode >= 56320 && charCode <= 57343;
|
|
1307
|
-
}
|
|
1308
1239
|
function cloneDiff(diff2) {
|
|
1309
1240
|
const [type, patch] = diff2;
|
|
1310
1241
|
return [type, patch];
|
|
@@ -1312,123 +1243,41 @@ function cloneDiff(diff2) {
|
|
|
1312
1243
|
function getCommonOverlap(textA, textB) {
|
|
1313
1244
|
let text1 = textA, text2 = textB;
|
|
1314
1245
|
const text1Length = text1.length, text2Length = text2.length;
|
|
1315
|
-
if (text1Length === 0 || text2Length === 0)
|
|
1316
|
-
return 0;
|
|
1246
|
+
if (text1Length === 0 || text2Length === 0) return 0;
|
|
1317
1247
|
text1Length > text2Length ? text1 = text1.substring(text1Length - text2Length) : text1Length < text2Length && (text2 = text2.substring(0, text1Length));
|
|
1318
1248
|
const textLength = Math.min(text1Length, text2Length);
|
|
1319
|
-
if (text1 === text2)
|
|
1320
|
-
return textLength;
|
|
1249
|
+
if (text1 === text2) return textLength;
|
|
1321
1250
|
let best = 0, length = 1;
|
|
1322
1251
|
for (let found = 0; found !== -1; ) {
|
|
1323
1252
|
const pattern = text1.substring(textLength - length);
|
|
1324
|
-
if (found = text2.indexOf(pattern), found === -1)
|
|
1325
|
-
return best;
|
|
1253
|
+
if (found = text2.indexOf(pattern), found === -1) return best;
|
|
1326
1254
|
length += found, (found === 0 || text1.substring(textLength - length) === text2.substring(0, length)) && (best = length, length++);
|
|
1327
1255
|
}
|
|
1328
1256
|
return best;
|
|
1329
1257
|
}
|
|
1330
1258
|
function getCommonPrefix(text1, text2) {
|
|
1331
|
-
if (!text1 || !text2 || text1[0] !== text2[0])
|
|
1332
|
-
return 0;
|
|
1259
|
+
if (!text1 || !text2 || text1[0] !== text2[0]) return 0;
|
|
1333
1260
|
let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerStart = 0;
|
|
1334
|
-
for (; pointerMin < pointerMid; )
|
|
1335
|
-
text1.substring(pointerStart, pointerMid) === text2.substring(pointerStart, pointerMid) ? (pointerMin = pointerMid, pointerStart = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
1261
|
+
for (; pointerMin < pointerMid; ) text1.substring(pointerStart, pointerMid) === text2.substring(pointerStart, pointerMid) ? (pointerMin = pointerMid, pointerStart = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
1336
1262
|
return pointerMid;
|
|
1337
1263
|
}
|
|
1338
1264
|
function getCommonSuffix(text1, text2) {
|
|
1339
|
-
if (!text1 || !text2 || text1[text1.length - 1] !== text2[text2.length - 1])
|
|
1340
|
-
return 0;
|
|
1265
|
+
if (!text1 || !text2 || text1[text1.length - 1] !== text2[text2.length - 1]) return 0;
|
|
1341
1266
|
let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerEnd = 0;
|
|
1342
|
-
for (; pointerMin < pointerMid; )
|
|
1343
|
-
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);
|
|
1267
|
+
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);
|
|
1344
1268
|
return pointerMid;
|
|
1345
1269
|
}
|
|
1346
|
-
function
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
let equalitiesLength = 0, lastEquality = null, pointer = 0, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0;
|
|
1350
|
-
for (; pointer < diffs.length; )
|
|
1351
|
-
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++;
|
|
1352
|
-
for (hasChanges && (diffs = cleanupMerge(diffs)), diffs = cleanupSemanticLossless(diffs), pointer = 1; pointer < diffs.length; ) {
|
|
1353
|
-
if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
|
|
1354
|
-
const deletion = diffs[pointer - 1][1], insertion = diffs[pointer][1], overlapLength1 = getCommonOverlap(deletion, insertion), overlapLength2 = getCommonOverlap(insertion, deletion);
|
|
1355
|
-
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++;
|
|
1356
|
-
}
|
|
1357
|
-
pointer++;
|
|
1358
|
-
}
|
|
1359
|
-
return diffs;
|
|
1360
|
-
}
|
|
1361
|
-
const nonAlphaNumericRegex = /[^a-zA-Z0-9]/, whitespaceRegex = /\s/, linebreakRegex = /[\r\n]/, blanklineEndRegex = /\n\r?\n$/, blanklineStartRegex = /^\r?\n\r?\n/;
|
|
1362
|
-
function cleanupSemanticLossless(rawDiffs) {
|
|
1363
|
-
const diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1364
|
-
function diffCleanupSemanticScore(one, two) {
|
|
1365
|
-
if (!one || !two)
|
|
1366
|
-
return 6;
|
|
1367
|
-
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);
|
|
1368
|
-
return blankLine1 || blankLine2 ? 5 : lineBreak1 || lineBreak2 ? 4 : nonAlphaNumeric1 && !whitespace1 && whitespace2 ? 3 : whitespace1 || whitespace2 ? 2 : nonAlphaNumeric1 || nonAlphaNumeric2 ? 1 : 0;
|
|
1369
|
-
}
|
|
1370
|
-
let pointer = 1;
|
|
1371
|
-
for (; pointer < diffs.length - 1; ) {
|
|
1372
|
-
if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
|
|
1373
|
-
let equality1 = diffs[pointer - 1][1], edit = diffs[pointer][1], equality2 = diffs[pointer + 1][1];
|
|
1374
|
-
const commonOffset = getCommonSuffix(equality1, edit);
|
|
1375
|
-
if (commonOffset) {
|
|
1376
|
-
const commonString = edit.substring(edit.length - commonOffset);
|
|
1377
|
-
equality1 = equality1.substring(0, equality1.length - commonOffset), edit = commonString + edit.substring(0, edit.length - commonOffset), equality2 = commonString + equality2;
|
|
1378
|
-
}
|
|
1379
|
-
let bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2, bestScore = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1380
|
-
for (; edit.charAt(0) === equality2.charAt(0); ) {
|
|
1381
|
-
equality1 += edit.charAt(0), edit = edit.substring(1) + equality2.charAt(0), equality2 = equality2.substring(1);
|
|
1382
|
-
const score = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1383
|
-
score >= bestScore && (bestScore = score, bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2);
|
|
1384
|
-
}
|
|
1385
|
-
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--));
|
|
1386
|
-
}
|
|
1387
|
-
pointer++;
|
|
1388
|
-
}
|
|
1389
|
-
return diffs;
|
|
1390
|
-
}
|
|
1391
|
-
function cleanupMerge(rawDiffs) {
|
|
1392
|
-
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1393
|
-
diffs.push([DIFF_EQUAL, ""]);
|
|
1394
|
-
let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "", commonlength;
|
|
1395
|
-
for (; pointer < diffs.length; )
|
|
1396
|
-
switch (diffs[pointer][0]) {
|
|
1397
|
-
case DIFF_INSERT:
|
|
1398
|
-
countInsert++, textInsert += diffs[pointer][1], pointer++;
|
|
1399
|
-
break;
|
|
1400
|
-
case DIFF_DELETE:
|
|
1401
|
-
countDelete++, textDelete += diffs[pointer][1], pointer++;
|
|
1402
|
-
break;
|
|
1403
|
-
case DIFF_EQUAL:
|
|
1404
|
-
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 = "";
|
|
1405
|
-
break;
|
|
1406
|
-
default:
|
|
1407
|
-
throw new Error("Unknown diff operation");
|
|
1408
|
-
}
|
|
1409
|
-
diffs[diffs.length - 1][1] === "" && diffs.pop();
|
|
1410
|
-
let hasChanges = !1;
|
|
1411
|
-
for (pointer = 1; pointer < diffs.length - 1; )
|
|
1412
|
-
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++;
|
|
1413
|
-
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
1414
|
-
}
|
|
1415
|
-
function trueCount() {
|
|
1416
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++)
|
|
1417
|
-
args[_key] = arguments[_key];
|
|
1418
|
-
return args.reduce((n, bool) => n + (bool ? 1 : 0), 0);
|
|
1270
|
+
function isHighSurrogate(char) {
|
|
1271
|
+
const charCode = char.charCodeAt(0);
|
|
1272
|
+
return charCode >= 55296 && charCode <= 56319;
|
|
1419
1273
|
}
|
|
1420
|
-
function
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
let equalitiesLength = 0, lastEquality = null, pointer = 0, preIns = !1, preDel = !1, postIns = !1, postDel = !1;
|
|
1424
|
-
for (; pointer < diffs.length; )
|
|
1425
|
-
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++;
|
|
1426
|
-
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
1274
|
+
function isLowSurrogate(char) {
|
|
1275
|
+
const charCode = char.charCodeAt(0);
|
|
1276
|
+
return charCode >= 56320 && charCode <= 57343;
|
|
1427
1277
|
}
|
|
1428
1278
|
function bisect(text1, text2, deadline) {
|
|
1429
1279
|
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);
|
|
1430
|
-
for (let x = 0; x < vLength; x++)
|
|
1431
|
-
v1[x] = -1, v2[x] = -1;
|
|
1280
|
+
for (let x = 0; x < vLength; x++) v1[x] = -1, v2[x] = -1;
|
|
1432
1281
|
v1[vOffset + 1] = 0, v2[vOffset + 1] = 0;
|
|
1433
1282
|
const delta = text1Length - text2Length, front = delta % 2 !== 0;
|
|
1434
1283
|
let k1start = 0, k1end = 0, k2start = 0, k2end = 0;
|
|
@@ -1438,18 +1287,14 @@ function bisect(text1, text2, deadline) {
|
|
|
1438
1287
|
let x1;
|
|
1439
1288
|
k1 === -d || k1 !== d && v1[k1Offset - 1] < v1[k1Offset + 1] ? x1 = v1[k1Offset + 1] : x1 = v1[k1Offset - 1] + 1;
|
|
1440
1289
|
let y1 = x1 - k1;
|
|
1441
|
-
for (; x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1); )
|
|
1442
|
-
|
|
1443
|
-
if (
|
|
1444
|
-
k1end += 2;
|
|
1445
|
-
else if (y1 > text2Length)
|
|
1446
|
-
k1start += 2;
|
|
1290
|
+
for (; x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1); ) x1++, y1++;
|
|
1291
|
+
if (v1[k1Offset] = x1, x1 > text1Length) k1end += 2;
|
|
1292
|
+
else if (y1 > text2Length) k1start += 2;
|
|
1447
1293
|
else if (front) {
|
|
1448
1294
|
const k2Offset = vOffset + delta - k1;
|
|
1449
1295
|
if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] !== -1) {
|
|
1450
1296
|
const x2 = text1Length - v2[k2Offset];
|
|
1451
|
-
if (x1 >= x2)
|
|
1452
|
-
return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1297
|
+
if (x1 >= x2) return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1453
1298
|
}
|
|
1454
1299
|
}
|
|
1455
1300
|
}
|
|
@@ -1458,18 +1303,14 @@ function bisect(text1, text2, deadline) {
|
|
|
1458
1303
|
let x2;
|
|
1459
1304
|
k2 === -d || k2 !== d && v2[k2Offset - 1] < v2[k2Offset + 1] ? x2 = v2[k2Offset + 1] : x2 = v2[k2Offset - 1] + 1;
|
|
1460
1305
|
let y2 = x2 - k2;
|
|
1461
|
-
for (; x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1); )
|
|
1462
|
-
|
|
1463
|
-
if (
|
|
1464
|
-
k2end += 2;
|
|
1465
|
-
else if (y2 > text2Length)
|
|
1466
|
-
k2start += 2;
|
|
1306
|
+
for (; x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1); ) x2++, y2++;
|
|
1307
|
+
if (v2[k2Offset] = x2, x2 > text1Length) k2end += 2;
|
|
1308
|
+
else if (y2 > text2Length) k2start += 2;
|
|
1467
1309
|
else if (!front) {
|
|
1468
1310
|
const k1Offset = vOffset + delta - k2;
|
|
1469
1311
|
if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] !== -1) {
|
|
1470
1312
|
const x1 = v1[k1Offset], y1 = vOffset + x1 - k1Offset;
|
|
1471
|
-
if (x2 = text1Length - x2, x1 >= x2)
|
|
1472
|
-
return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1313
|
+
if (x2 = text1Length - x2, x1 >= x2) return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1473
1314
|
}
|
|
1474
1315
|
}
|
|
1475
1316
|
}
|
|
@@ -1486,23 +1327,18 @@ function bisectSplit(text1, text2, x, y, deadline) {
|
|
|
1486
1327
|
});
|
|
1487
1328
|
return diffs.concat(diffsb);
|
|
1488
1329
|
}
|
|
1489
|
-
function findHalfMatch(text1, text2) {
|
|
1490
|
-
if (
|
|
1491
|
-
return null;
|
|
1330
|
+
function findHalfMatch(text1, text2, timeout = 1) {
|
|
1331
|
+
if (timeout <= 0) return null;
|
|
1492
1332
|
const longText = text1.length > text2.length ? text1 : text2, shortText = text1.length > text2.length ? text2 : text1;
|
|
1493
|
-
if (longText.length < 4 || shortText.length * 2 < longText.length)
|
|
1494
|
-
return null;
|
|
1333
|
+
if (longText.length < 4 || shortText.length * 2 < longText.length) return null;
|
|
1495
1334
|
const halfMatch1 = halfMatchI(longText, shortText, Math.ceil(longText.length / 4)), halfMatch2 = halfMatchI(longText, shortText, Math.ceil(longText.length / 2));
|
|
1496
1335
|
let halfMatch;
|
|
1497
|
-
if (halfMatch1 && halfMatch2)
|
|
1498
|
-
halfMatch = halfMatch1[4].length > halfMatch2[4].length ? halfMatch1 : halfMatch2;
|
|
1336
|
+
if (halfMatch1 && halfMatch2) halfMatch = halfMatch1[4].length > halfMatch2[4].length ? halfMatch1 : halfMatch2;
|
|
1499
1337
|
else {
|
|
1500
|
-
if (!halfMatch1 && !halfMatch2)
|
|
1501
|
-
return null;
|
|
1338
|
+
if (!halfMatch1 && !halfMatch2) return null;
|
|
1502
1339
|
halfMatch2 ? halfMatch1 || (halfMatch = halfMatch2) : halfMatch = halfMatch1;
|
|
1503
1340
|
}
|
|
1504
|
-
if (!halfMatch)
|
|
1505
|
-
throw new Error("Unable to find a half match.");
|
|
1341
|
+
if (!halfMatch) throw new Error("Unable to find a half match.");
|
|
1506
1342
|
let text1A, text1B, text2A, text2B;
|
|
1507
1343
|
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]);
|
|
1508
1344
|
const midCommon = halfMatch[4];
|
|
@@ -1520,8 +1356,7 @@ function halfMatchI(longText, shortText, i) {
|
|
|
1520
1356
|
function charsToLines(diffs, lineArray) {
|
|
1521
1357
|
for (let x = 0; x < diffs.length; x++) {
|
|
1522
1358
|
const chars = diffs[x][1], text = [];
|
|
1523
|
-
for (let y = 0; y < chars.length; y++)
|
|
1524
|
-
text[y] = lineArray[chars.charCodeAt(y)];
|
|
1359
|
+
for (let y = 0; y < chars.length; y++) text[y] = lineArray[chars.charCodeAt(y)];
|
|
1525
1360
|
diffs[x][1] = text.join("");
|
|
1526
1361
|
}
|
|
1527
1362
|
}
|
|
@@ -1574,8 +1409,7 @@ function doLineModeDiff(textA, textB, opts) {
|
|
|
1574
1409
|
checkLines: !1,
|
|
1575
1410
|
deadline: opts.deadline
|
|
1576
1411
|
});
|
|
1577
|
-
for (let j = aa.length - 1; j >= 0; j--)
|
|
1578
|
-
diffs.splice(pointer, 0, aa[j]);
|
|
1412
|
+
for (let j = aa.length - 1; j >= 0; j--) diffs.splice(pointer, 0, aa[j]);
|
|
1579
1413
|
pointer += aa.length;
|
|
1580
1414
|
}
|
|
1581
1415
|
countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
|
|
@@ -1589,15 +1423,11 @@ function doLineModeDiff(textA, textB, opts) {
|
|
|
1589
1423
|
}
|
|
1590
1424
|
function computeDiff(text1, text2, opts) {
|
|
1591
1425
|
let diffs;
|
|
1592
|
-
if (!text1)
|
|
1593
|
-
|
|
1594
|
-
if (!text2)
|
|
1595
|
-
return [[DIFF_DELETE, text1]];
|
|
1426
|
+
if (!text1) return [[DIFF_INSERT, text2]];
|
|
1427
|
+
if (!text2) return [[DIFF_DELETE, text1]];
|
|
1596
1428
|
const longtext = text1.length > text2.length ? text1 : text2, shorttext = text1.length > text2.length ? text2 : text1, i = longtext.indexOf(shorttext);
|
|
1597
|
-
if (i !== -1)
|
|
1598
|
-
|
|
1599
|
-
if (shorttext.length === 1)
|
|
1600
|
-
return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
|
|
1429
|
+
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;
|
|
1430
|
+
if (shorttext.length === 1) return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
|
|
1601
1431
|
const halfMatch = findHalfMatch(text1, text2);
|
|
1602
1432
|
if (halfMatch) {
|
|
1603
1433
|
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);
|
|
@@ -1605,17 +1435,25 @@ function computeDiff(text1, text2, opts) {
|
|
|
1605
1435
|
}
|
|
1606
1436
|
return opts.checkLines && text1.length > 100 && text2.length > 100 ? doLineModeDiff(text1, text2, opts) : bisect(text1, text2, opts.deadline);
|
|
1607
1437
|
}
|
|
1438
|
+
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, {
|
|
1439
|
+
enumerable: !0,
|
|
1440
|
+
configurable: !0,
|
|
1441
|
+
writable: !0,
|
|
1442
|
+
value
|
|
1443
|
+
}) : obj[key] = value, __spreadValues$2 = (a, b) => {
|
|
1444
|
+
for (var prop in b || (b = {})) __hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
1445
|
+
if (__getOwnPropSymbols$2) for (var prop of __getOwnPropSymbols$2(b)) __propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
1446
|
+
return a;
|
|
1447
|
+
};
|
|
1608
1448
|
const DIFF_DELETE = -1, DIFF_INSERT = 1, DIFF_EQUAL = 0;
|
|
1609
1449
|
function diff(textA, textB, opts) {
|
|
1610
|
-
if (textA === null || textB === null)
|
|
1611
|
-
throw new Error("Null input. (diff)");
|
|
1450
|
+
if (textA === null || textB === null) throw new Error("Null input. (diff)");
|
|
1612
1451
|
const diffs = doDiff(textA, textB, createInternalOpts(opts || {}));
|
|
1613
1452
|
return adjustDiffForSurrogatePairs(diffs), diffs;
|
|
1614
1453
|
}
|
|
1615
1454
|
function doDiff(textA, textB, options) {
|
|
1616
1455
|
let text1 = textA, text2 = textB;
|
|
1617
|
-
if (text1 === text2)
|
|
1618
|
-
return text1 ? [[DIFF_EQUAL, text1]] : [];
|
|
1456
|
+
if (text1 === text2) return text1 ? [[DIFF_EQUAL, text1]] : [];
|
|
1619
1457
|
let commonlength = getCommonPrefix(text1, text2);
|
|
1620
1458
|
const commonprefix = text1.substring(0, commonlength);
|
|
1621
1459
|
text1 = text1.substring(commonlength), text2 = text2.substring(commonlength), commonlength = getCommonSuffix(text1, text2);
|
|
@@ -1629,7 +1467,7 @@ function createDeadLine(timeout) {
|
|
|
1629
1467
|
return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
|
|
1630
1468
|
}
|
|
1631
1469
|
function createInternalOpts(opts) {
|
|
1632
|
-
return __spreadValues({
|
|
1470
|
+
return __spreadValues$2({
|
|
1633
1471
|
checkLines: !0,
|
|
1634
1472
|
deadline: createDeadLine(opts.timeout || 1)
|
|
1635
1473
|
}, opts);
|
|
@@ -1680,9 +1518,93 @@ function adjustDiffForSurrogatePairs(diffs) {
|
|
|
1680
1518
|
const firstChar = diffText[0], lastChar = diffText[diffText.length - 1];
|
|
1681
1519
|
isHighSurrogate(lastChar) && diffType === DIFF_EQUAL && deisolateChar(diffs, i, 1), isLowSurrogate(firstChar) && diffType === DIFF_EQUAL && deisolateChar(diffs, i, -1);
|
|
1682
1520
|
}
|
|
1683
|
-
for (let i = 0; i < diffs.length; i++)
|
|
1684
|
-
|
|
1521
|
+
for (let i = 0; i < diffs.length; i++) diffs[i][1].length === 0 && diffs.splice(i, 1);
|
|
1522
|
+
}
|
|
1523
|
+
function cleanupSemantic(rawDiffs) {
|
|
1524
|
+
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1;
|
|
1525
|
+
const equalities = [];
|
|
1526
|
+
let equalitiesLength = 0, lastEquality = null, pointer = 0, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0;
|
|
1527
|
+
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++;
|
|
1528
|
+
for (hasChanges && (diffs = cleanupMerge(diffs)), diffs = cleanupSemanticLossless(diffs), pointer = 1; pointer < diffs.length; ) {
|
|
1529
|
+
if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
|
|
1530
|
+
const deletion = diffs[pointer - 1][1], insertion = diffs[pointer][1], overlapLength1 = getCommonOverlap(deletion, insertion), overlapLength2 = getCommonOverlap(insertion, deletion);
|
|
1531
|
+
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++;
|
|
1532
|
+
}
|
|
1533
|
+
pointer++;
|
|
1534
|
+
}
|
|
1535
|
+
return diffs;
|
|
1685
1536
|
}
|
|
1537
|
+
const nonAlphaNumericRegex = /[^a-zA-Z0-9]/, whitespaceRegex = /\s/, linebreakRegex = /[\r\n]/, blanklineEndRegex = /\n\r?\n$/, blanklineStartRegex = /^\r?\n\r?\n/;
|
|
1538
|
+
function cleanupSemanticLossless(rawDiffs) {
|
|
1539
|
+
const diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1540
|
+
function diffCleanupSemanticScore(one, two) {
|
|
1541
|
+
if (!one || !two) return 6;
|
|
1542
|
+
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);
|
|
1543
|
+
return blankLine1 || blankLine2 ? 5 : lineBreak1 || lineBreak2 ? 4 : nonAlphaNumeric1 && !whitespace1 && whitespace2 ? 3 : whitespace1 || whitespace2 ? 2 : nonAlphaNumeric1 || nonAlphaNumeric2 ? 1 : 0;
|
|
1544
|
+
}
|
|
1545
|
+
let pointer = 1;
|
|
1546
|
+
for (; pointer < diffs.length - 1; ) {
|
|
1547
|
+
if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
|
|
1548
|
+
let equality1 = diffs[pointer - 1][1], edit = diffs[pointer][1], equality2 = diffs[pointer + 1][1];
|
|
1549
|
+
const commonOffset = getCommonSuffix(equality1, edit);
|
|
1550
|
+
if (commonOffset) {
|
|
1551
|
+
const commonString = edit.substring(edit.length - commonOffset);
|
|
1552
|
+
equality1 = equality1.substring(0, equality1.length - commonOffset), edit = commonString + edit.substring(0, edit.length - commonOffset), equality2 = commonString + equality2;
|
|
1553
|
+
}
|
|
1554
|
+
let bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2, bestScore = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1555
|
+
for (; edit.charAt(0) === equality2.charAt(0); ) {
|
|
1556
|
+
equality1 += edit.charAt(0), edit = edit.substring(1) + equality2.charAt(0), equality2 = equality2.substring(1);
|
|
1557
|
+
const score = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1558
|
+
score >= bestScore && (bestScore = score, bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2);
|
|
1559
|
+
}
|
|
1560
|
+
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--));
|
|
1561
|
+
}
|
|
1562
|
+
pointer++;
|
|
1563
|
+
}
|
|
1564
|
+
return diffs;
|
|
1565
|
+
}
|
|
1566
|
+
function cleanupMerge(rawDiffs) {
|
|
1567
|
+
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1568
|
+
diffs.push([DIFF_EQUAL, ""]);
|
|
1569
|
+
let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "", commonlength;
|
|
1570
|
+
for (; pointer < diffs.length; ) switch (diffs[pointer][0]) {
|
|
1571
|
+
case DIFF_INSERT:
|
|
1572
|
+
countInsert++, textInsert += diffs[pointer][1], pointer++;
|
|
1573
|
+
break;
|
|
1574
|
+
case DIFF_DELETE:
|
|
1575
|
+
countDelete++, textDelete += diffs[pointer][1], pointer++;
|
|
1576
|
+
break;
|
|
1577
|
+
case DIFF_EQUAL:
|
|
1578
|
+
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 = "";
|
|
1579
|
+
break;
|
|
1580
|
+
default:
|
|
1581
|
+
throw new Error("Unknown diff operation");
|
|
1582
|
+
}
|
|
1583
|
+
diffs[diffs.length - 1][1] === "" && diffs.pop();
|
|
1584
|
+
let hasChanges = !1;
|
|
1585
|
+
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++;
|
|
1586
|
+
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
1587
|
+
}
|
|
1588
|
+
function trueCount(...args) {
|
|
1589
|
+
return args.reduce((n, bool) => n + (bool ? 1 : 0), 0);
|
|
1590
|
+
}
|
|
1591
|
+
function cleanupEfficiency(rawDiffs, editCost = 4) {
|
|
1592
|
+
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1;
|
|
1593
|
+
const equalities = [];
|
|
1594
|
+
let equalitiesLength = 0, lastEquality = null, pointer = 0, preIns = !1, preDel = !1, postIns = !1, postDel = !1;
|
|
1595
|
+
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++;
|
|
1596
|
+
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
1597
|
+
}
|
|
1598
|
+
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, {
|
|
1599
|
+
enumerable: !0,
|
|
1600
|
+
configurable: !0,
|
|
1601
|
+
writable: !0,
|
|
1602
|
+
value
|
|
1603
|
+
}) : obj[key] = value, __spreadValues$1 = (a, b) => {
|
|
1604
|
+
for (var prop in b || (b = {})) __hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
1605
|
+
if (__getOwnPropSymbols$1) for (var prop of __getOwnPropSymbols$1(b)) __propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
1606
|
+
return a;
|
|
1607
|
+
};
|
|
1686
1608
|
const DEFAULT_OPTIONS = {
|
|
1687
1609
|
/**
|
|
1688
1610
|
* At what point is no match declared (0.0 = perfection, 1.0 = very loose).
|
|
@@ -1696,13 +1618,11 @@ const DEFAULT_OPTIONS = {
|
|
|
1696
1618
|
distance: 1e3
|
|
1697
1619
|
};
|
|
1698
1620
|
function applyDefaults(options) {
|
|
1699
|
-
return __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options);
|
|
1621
|
+
return __spreadValues$1(__spreadValues$1({}, DEFAULT_OPTIONS), options);
|
|
1700
1622
|
}
|
|
1701
1623
|
const MAX_BITS$1 = 32;
|
|
1702
|
-
function bitap(text, pattern, loc) {
|
|
1703
|
-
|
|
1704
|
-
if (pattern.length > MAX_BITS$1)
|
|
1705
|
-
throw new Error("Pattern too long for this browser.");
|
|
1624
|
+
function bitap(text, pattern, loc, opts = {}) {
|
|
1625
|
+
if (pattern.length > MAX_BITS$1) throw new Error("Pattern too long for this browser.");
|
|
1706
1626
|
const options = applyDefaults(opts), s = getAlphabetFromPattern(pattern);
|
|
1707
1627
|
function getBitapScore(e, x) {
|
|
1708
1628
|
const accuracy = e / pattern.length, proximity = Math.abs(loc - x);
|
|
@@ -1714,8 +1634,7 @@ function bitap(text, pattern, loc) {
|
|
|
1714
1634
|
bestLoc = -1;
|
|
1715
1635
|
let binMin, binMid, binMax = pattern.length + text.length, lastRd = [];
|
|
1716
1636
|
for (let d = 0; d < pattern.length; d++) {
|
|
1717
|
-
for (binMin = 0, binMid = binMax; binMin < binMid; )
|
|
1718
|
-
getBitapScore(d, loc + binMid) <= scoreThreshold ? binMin = binMid : binMax = binMid, binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
1637
|
+
for (binMin = 0, binMid = binMax; binMin < binMid; ) getBitapScore(d, loc + binMid) <= scoreThreshold ? binMin = binMid : binMax = binMid, binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
1719
1638
|
binMax = binMid;
|
|
1720
1639
|
let start = Math.max(1, loc - binMid + 1);
|
|
1721
1640
|
const finish = Math.min(loc + binMid, text.length) + pattern.length, rd = new Array(finish + 2);
|
|
@@ -1724,106 +1643,40 @@ function bitap(text, pattern, loc) {
|
|
|
1724
1643
|
const charMatch = s[text.charAt(j - 1)];
|
|
1725
1644
|
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) {
|
|
1726
1645
|
const score = getBitapScore(d, j - 1);
|
|
1727
|
-
if (score <= scoreThreshold)
|
|
1728
|
-
|
|
1729
|
-
start = Math.max(1, 2 * loc - bestLoc);
|
|
1730
|
-
else
|
|
1731
|
-
break;
|
|
1646
|
+
if (score <= scoreThreshold) if (scoreThreshold = score, bestLoc = j - 1, bestLoc > loc) start = Math.max(1, 2 * loc - bestLoc);
|
|
1647
|
+
else break;
|
|
1732
1648
|
}
|
|
1733
1649
|
}
|
|
1734
|
-
if (getBitapScore(d + 1, loc) > scoreThreshold)
|
|
1735
|
-
break;
|
|
1650
|
+
if (getBitapScore(d + 1, loc) > scoreThreshold) break;
|
|
1736
1651
|
lastRd = rd;
|
|
1737
1652
|
}
|
|
1738
1653
|
return bestLoc;
|
|
1739
1654
|
}
|
|
1740
1655
|
function getAlphabetFromPattern(pattern) {
|
|
1741
1656
|
const s = {};
|
|
1742
|
-
for (let i = 0; i < pattern.length; i++)
|
|
1743
|
-
|
|
1744
|
-
for (let i = 0; i < pattern.length; i++)
|
|
1745
|
-
s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
|
|
1657
|
+
for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] = 0;
|
|
1658
|
+
for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
|
|
1746
1659
|
return s;
|
|
1747
1660
|
}
|
|
1748
1661
|
function match(text, pattern, searchLocation) {
|
|
1749
|
-
if (text === null || pattern === null || searchLocation === null)
|
|
1750
|
-
throw new Error("Null input. (match())");
|
|
1662
|
+
if (text === null || pattern === null || searchLocation === null) throw new Error("Null input. (match())");
|
|
1751
1663
|
const loc = Math.max(0, Math.min(searchLocation, text.length));
|
|
1752
|
-
if (text === pattern)
|
|
1753
|
-
return 0;
|
|
1664
|
+
if (text === pattern) return 0;
|
|
1754
1665
|
if (text.length) {
|
|
1755
|
-
if (text.substring(loc, loc + pattern.length) === pattern)
|
|
1756
|
-
return loc;
|
|
1666
|
+
if (text.substring(loc, loc + pattern.length) === pattern) return loc;
|
|
1757
1667
|
} else return -1;
|
|
1758
1668
|
return bitap(text, pattern, loc);
|
|
1759
1669
|
}
|
|
1760
|
-
function createPatchObject(start1, start2) {
|
|
1761
|
-
return {
|
|
1762
|
-
diffs: [],
|
|
1763
|
-
start1,
|
|
1764
|
-
start2,
|
|
1765
|
-
utf8Start1: start1,
|
|
1766
|
-
utf8Start2: start2,
|
|
1767
|
-
length1: 0,
|
|
1768
|
-
length2: 0,
|
|
1769
|
-
utf8Length1: 0,
|
|
1770
|
-
utf8Length2: 0
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
1670
|
function diffText1(diffs) {
|
|
1774
1671
|
const text = [];
|
|
1775
|
-
for (let x = 0; x < diffs.length; x++)
|
|
1776
|
-
diffs[x][0] !== DIFF_INSERT && (text[x] = diffs[x][1]);
|
|
1672
|
+
for (let x = 0; x < diffs.length; x++) diffs[x][0] !== DIFF_INSERT && (text[x] = diffs[x][1]);
|
|
1777
1673
|
return text.join("");
|
|
1778
1674
|
}
|
|
1779
1675
|
function diffText2(diffs) {
|
|
1780
1676
|
const text = [];
|
|
1781
|
-
for (let x = 0; x < diffs.length; x++)
|
|
1782
|
-
diffs[x][0] !== DIFF_DELETE && (text[x] = diffs[x][1]);
|
|
1677
|
+
for (let x = 0; x < diffs.length; x++) diffs[x][0] !== DIFF_DELETE && (text[x] = diffs[x][1]);
|
|
1783
1678
|
return text.join("");
|
|
1784
1679
|
}
|
|
1785
|
-
function countUtf8Bytes(str) {
|
|
1786
|
-
let bytes = 0;
|
|
1787
|
-
for (let i = 0; i < str.length; i++) {
|
|
1788
|
-
const codePoint = str.codePointAt(i);
|
|
1789
|
-
if (typeof codePoint > "u")
|
|
1790
|
-
throw new Error("Failed to get codepoint");
|
|
1791
|
-
bytes += utf8len(codePoint);
|
|
1792
|
-
}
|
|
1793
|
-
return bytes;
|
|
1794
|
-
}
|
|
1795
|
-
function adjustIndiciesToUcs2(patches2, base) {
|
|
1796
|
-
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, byteOffset = 0, idx = 0;
|
|
1797
|
-
function advanceTo(target) {
|
|
1798
|
-
for (; byteOffset < target; ) {
|
|
1799
|
-
const codePoint = base.codePointAt(idx);
|
|
1800
|
-
if (typeof codePoint > "u")
|
|
1801
|
-
return idx;
|
|
1802
|
-
byteOffset += utf8len(codePoint), codePoint > 65535 ? idx += 2 : idx += 1;
|
|
1803
|
-
}
|
|
1804
|
-
if (!options.allowExceedingIndices && byteOffset !== target)
|
|
1805
|
-
throw new Error("Failed to determine byte offset");
|
|
1806
|
-
return idx;
|
|
1807
|
-
}
|
|
1808
|
-
const adjusted = [];
|
|
1809
|
-
for (const patch of patches2)
|
|
1810
|
-
adjusted.push({
|
|
1811
|
-
diffs: patch.diffs.map((diff2) => cloneDiff(diff2)),
|
|
1812
|
-
start1: advanceTo(patch.start1),
|
|
1813
|
-
start2: advanceTo(patch.start2),
|
|
1814
|
-
utf8Start1: patch.utf8Start1,
|
|
1815
|
-
utf8Start2: patch.utf8Start2,
|
|
1816
|
-
length1: patch.length1,
|
|
1817
|
-
length2: patch.length2,
|
|
1818
|
-
utf8Length1: patch.utf8Length1,
|
|
1819
|
-
utf8Length2: patch.utf8Length2
|
|
1820
|
-
});
|
|
1821
|
-
return adjusted;
|
|
1822
|
-
}
|
|
1823
|
-
function utf8len(codePoint) {
|
|
1824
|
-
return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
1825
|
-
}
|
|
1826
|
-
const MAX_BITS = 32, DEFAULT_MARGIN = 4;
|
|
1827
1680
|
function levenshtein(diffs) {
|
|
1828
1681
|
let leven = 0, insertions = 0, deletions = 0;
|
|
1829
1682
|
for (let x = 0; x < diffs.length; x++) {
|
|
@@ -1846,38 +1699,82 @@ function levenshtein(diffs) {
|
|
|
1846
1699
|
}
|
|
1847
1700
|
function xIndex(diffs, loc) {
|
|
1848
1701
|
let chars1 = 0, chars2 = 0, lastChars1 = 0, lastChars2 = 0, x;
|
|
1849
|
-
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++)
|
|
1850
|
-
lastChars1 = chars1, lastChars2 = chars2;
|
|
1702
|
+
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;
|
|
1851
1703
|
return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (loc - lastChars1);
|
|
1852
1704
|
}
|
|
1853
|
-
function
|
|
1854
|
-
|
|
1705
|
+
function countUtf8Bytes(str) {
|
|
1706
|
+
let bytes = 0;
|
|
1707
|
+
for (let i = 0; i < str.length; i++) {
|
|
1708
|
+
const codePoint = str.codePointAt(i);
|
|
1709
|
+
if (typeof codePoint > "u") throw new Error("Failed to get codepoint");
|
|
1710
|
+
bytes += utf8len(codePoint);
|
|
1711
|
+
}
|
|
1712
|
+
return bytes;
|
|
1713
|
+
}
|
|
1714
|
+
function adjustIndiciesToUcs2(patches2, base, options = {}) {
|
|
1715
|
+
let byteOffset = 0, idx = 0;
|
|
1716
|
+
function advanceTo(target) {
|
|
1717
|
+
for (; byteOffset < target; ) {
|
|
1718
|
+
const codePoint = base.codePointAt(idx);
|
|
1719
|
+
if (typeof codePoint > "u") return idx;
|
|
1720
|
+
byteOffset += utf8len(codePoint), codePoint > 65535 ? idx += 2 : idx += 1;
|
|
1721
|
+
}
|
|
1722
|
+
if (!options.allowExceedingIndices && byteOffset !== target) throw new Error("Failed to determine byte offset");
|
|
1723
|
+
return idx;
|
|
1724
|
+
}
|
|
1725
|
+
const adjusted = [];
|
|
1726
|
+
for (const patch of patches2) adjusted.push({
|
|
1727
|
+
diffs: patch.diffs.map((diff2) => cloneDiff(diff2)),
|
|
1728
|
+
start1: advanceTo(patch.start1),
|
|
1729
|
+
start2: advanceTo(patch.start2),
|
|
1730
|
+
utf8Start1: patch.utf8Start1,
|
|
1731
|
+
utf8Start2: patch.utf8Start2,
|
|
1732
|
+
length1: patch.length1,
|
|
1733
|
+
length2: patch.length2,
|
|
1734
|
+
utf8Length1: patch.utf8Length1,
|
|
1735
|
+
utf8Length2: patch.utf8Length2
|
|
1736
|
+
});
|
|
1737
|
+
return adjusted;
|
|
1738
|
+
}
|
|
1739
|
+
function utf8len(codePoint) {
|
|
1740
|
+
return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
1741
|
+
}
|
|
1742
|
+
const MAX_BITS = 32, DEFAULT_MARGIN = 4;
|
|
1743
|
+
function addPadding(patches2, margin = DEFAULT_MARGIN) {
|
|
1744
|
+
const paddingLength = margin;
|
|
1855
1745
|
let nullPadding = "";
|
|
1856
|
-
for (let x = 1; x <= paddingLength; x++)
|
|
1857
|
-
|
|
1858
|
-
for (const p of patches2)
|
|
1859
|
-
p.start1 += paddingLength, p.start2 += paddingLength, p.utf8Start1 += paddingLength, p.utf8Start2 += paddingLength;
|
|
1746
|
+
for (let x = 1; x <= paddingLength; x++) nullPadding += String.fromCharCode(x);
|
|
1747
|
+
for (const p of patches2) p.start1 += paddingLength, p.start2 += paddingLength, p.utf8Start1 += paddingLength, p.utf8Start2 += paddingLength;
|
|
1860
1748
|
let patch = patches2[0], diffs = patch.diffs;
|
|
1861
|
-
if (diffs.length === 0 || diffs[0][0] !== DIFF_EQUAL)
|
|
1862
|
-
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;
|
|
1749
|
+
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;
|
|
1863
1750
|
else if (paddingLength > diffs[0][1].length) {
|
|
1864
1751
|
const firstDiffLength = diffs[0][1].length, extraLength = paddingLength - firstDiffLength;
|
|
1865
1752
|
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;
|
|
1866
1753
|
}
|
|
1867
|
-
if (patch = patches2[patches2.length - 1], diffs = patch.diffs, diffs.length === 0 || diffs[diffs.length - 1][0] !== DIFF_EQUAL)
|
|
1868
|
-
diffs.push([DIFF_EQUAL, nullPadding]), patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
1754
|
+
if (patch = patches2[patches2.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;
|
|
1869
1755
|
else if (paddingLength > diffs[diffs.length - 1][1].length) {
|
|
1870
1756
|
const extraLength = paddingLength - diffs[diffs.length - 1][1].length;
|
|
1871
1757
|
diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength), patch.length1 += extraLength, patch.length2 += extraLength, patch.utf8Length1 += extraLength, patch.utf8Length2 += extraLength;
|
|
1872
1758
|
}
|
|
1873
1759
|
return nullPadding;
|
|
1874
1760
|
}
|
|
1875
|
-
function
|
|
1876
|
-
|
|
1761
|
+
function createPatchObject(start1, start2) {
|
|
1762
|
+
return {
|
|
1763
|
+
diffs: [],
|
|
1764
|
+
start1,
|
|
1765
|
+
start2,
|
|
1766
|
+
utf8Start1: start1,
|
|
1767
|
+
utf8Start2: start2,
|
|
1768
|
+
length1: 0,
|
|
1769
|
+
length2: 0,
|
|
1770
|
+
utf8Length1: 0,
|
|
1771
|
+
utf8Length2: 0
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
function splitMax(patches2, margin = DEFAULT_MARGIN) {
|
|
1877
1775
|
const patchSize = MAX_BITS;
|
|
1878
1776
|
for (let x = 0; x < patches2.length; x++) {
|
|
1879
|
-
if (patches2[x].length1 <= patchSize)
|
|
1880
|
-
continue;
|
|
1777
|
+
if (patches2[x].length1 <= patchSize) continue;
|
|
1881
1778
|
const bigpatch = patches2[x];
|
|
1882
1779
|
patches2.splice(x--, 1);
|
|
1883
1780
|
let start1 = bigpatch.start1, start2 = bigpatch.start2, preContext = "";
|
|
@@ -1903,13 +1800,10 @@ function splitMax(patches2) {
|
|
|
1903
1800
|
}
|
|
1904
1801
|
}
|
|
1905
1802
|
}
|
|
1906
|
-
function apply(patches2, originalText) {
|
|
1907
|
-
|
|
1908
|
-
if (typeof patches2 == "string")
|
|
1909
|
-
throw new Error("Patches must be an array - pass the patch to `parsePatch()` first");
|
|
1803
|
+
function apply(patches2, originalText, opts = {}) {
|
|
1804
|
+
if (typeof patches2 == "string") throw new Error("Patches must be an array - pass the patch to `parsePatch()` first");
|
|
1910
1805
|
let text = originalText;
|
|
1911
|
-
if (patches2.length === 0)
|
|
1912
|
-
return [text, []];
|
|
1806
|
+
if (patches2.length === 0) return [text, []];
|
|
1913
1807
|
const parsed = adjustIndiciesToUcs2(patches2, text, {
|
|
1914
1808
|
allowExceedingIndices: opts.allowExceedingIndices
|
|
1915
1809
|
}), margin = opts.margin || DEFAULT_MARGIN, deleteThreshold = opts.deleteThreshold || 0.4, nullPadding = addPadding(parsed, margin);
|
|
@@ -1919,19 +1813,16 @@ function apply(patches2, originalText) {
|
|
|
1919
1813
|
for (let x = 0; x < parsed.length; x++) {
|
|
1920
1814
|
const expectedLoc = parsed[x].start2 + delta, text1 = diffText1(parsed[x].diffs);
|
|
1921
1815
|
let startLoc, endLoc = -1;
|
|
1922
|
-
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)
|
|
1923
|
-
results[x] = !1, delta -= parsed[x].length2 - parsed[x].length1;
|
|
1816
|
+
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;
|
|
1924
1817
|
else {
|
|
1925
1818
|
results[x] = !0, delta = startLoc - expectedLoc;
|
|
1926
1819
|
let text2;
|
|
1927
|
-
if (endLoc === -1 ? text2 = text.substring(startLoc, startLoc + text1.length) : text2 = text.substring(startLoc, endLoc + MAX_BITS), text1 === text2)
|
|
1928
|
-
text = text.substring(0, startLoc) + diffText2(parsed[x].diffs) + text.substring(startLoc + text1.length);
|
|
1820
|
+
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);
|
|
1929
1821
|
else {
|
|
1930
1822
|
let diffs = diff(text1, text2, {
|
|
1931
1823
|
checkLines: !1
|
|
1932
1824
|
});
|
|
1933
|
-
if (text1.length > MAX_BITS && levenshtein(diffs) / text1.length > deleteThreshold)
|
|
1934
|
-
results[x] = !1;
|
|
1825
|
+
if (text1.length > MAX_BITS && levenshtein(diffs) / text1.length > deleteThreshold) results[x] = !1;
|
|
1935
1826
|
else {
|
|
1936
1827
|
diffs = cleanupSemanticLossless(diffs);
|
|
1937
1828
|
let index1 = 0, index2 = 0;
|
|
@@ -1947,20 +1838,17 @@ function apply(patches2, originalText) {
|
|
|
1947
1838
|
}
|
|
1948
1839
|
const patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;
|
|
1949
1840
|
function parse(textline) {
|
|
1950
|
-
if (!textline)
|
|
1951
|
-
return [];
|
|
1841
|
+
if (!textline) return [];
|
|
1952
1842
|
const patches2 = [], lines = textline.split(`
|
|
1953
1843
|
`);
|
|
1954
1844
|
let textPointer = 0;
|
|
1955
1845
|
for (; textPointer < lines.length; ) {
|
|
1956
1846
|
const m = lines[textPointer].match(patchHeader);
|
|
1957
|
-
if (!m)
|
|
1958
|
-
throw new Error("Invalid patch string: ".concat(lines[textPointer]));
|
|
1847
|
+
if (!m) throw new Error(`Invalid patch string: ${lines[textPointer]}`);
|
|
1959
1848
|
const patch = createPatchObject(toInt(m[1]), toInt(m[3]));
|
|
1960
1849
|
for (patches2.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; ) {
|
|
1961
1850
|
const currentLine = lines[textPointer], sign = currentLine.charAt(0);
|
|
1962
|
-
if (sign === "@")
|
|
1963
|
-
break;
|
|
1851
|
+
if (sign === "@") break;
|
|
1964
1852
|
if (sign === "") {
|
|
1965
1853
|
textPointer++;
|
|
1966
1854
|
continue;
|
|
@@ -1968,18 +1856,14 @@ function parse(textline) {
|
|
|
1968
1856
|
let line;
|
|
1969
1857
|
try {
|
|
1970
1858
|
line = decodeURI(currentLine.slice(1));
|
|
1971
|
-
} catch
|
|
1972
|
-
throw new Error(
|
|
1859
|
+
} catch {
|
|
1860
|
+
throw new Error(`Illegal escape in parse: ${currentLine}`);
|
|
1973
1861
|
}
|
|
1974
1862
|
const utf8Diff = countUtf8Bytes(line) - line.length;
|
|
1975
|
-
if (sign === "-")
|
|
1976
|
-
|
|
1977
|
-
else if (sign === "
|
|
1978
|
-
|
|
1979
|
-
else if (sign === " ")
|
|
1980
|
-
patch.diffs.push([DIFF_EQUAL, line]), patch.length1 -= utf8Diff, patch.length2 -= utf8Diff;
|
|
1981
|
-
else
|
|
1982
|
-
throw new Error('Invalid patch mode "'.concat(sign, '" in: ').concat(line));
|
|
1863
|
+
if (sign === "-") patch.diffs.push([DIFF_DELETE, line]), patch.length1 -= utf8Diff;
|
|
1864
|
+
else if (sign === "+") patch.diffs.push([DIFF_INSERT, line]), patch.length2 -= utf8Diff;
|
|
1865
|
+
else if (sign === " ") patch.diffs.push([DIFF_EQUAL, line]), patch.length1 -= utf8Diff, patch.length2 -= utf8Diff;
|
|
1866
|
+
else throw new Error(`Invalid patch mode "${sign}" in: ${line}`);
|
|
1983
1867
|
textPointer++;
|
|
1984
1868
|
}
|
|
1985
1869
|
}
|
|
@@ -1994,8 +1878,7 @@ function withUndoing(editor, fn) {
|
|
|
1994
1878
|
IS_UDOING.set(editor, !0), fn(), IS_UDOING.set(editor, prev);
|
|
1995
1879
|
}
|
|
1996
1880
|
function isUndoing(editor) {
|
|
1997
|
-
|
|
1998
|
-
return (_a = IS_UDOING.get(editor)) != null ? _a : !1;
|
|
1881
|
+
return IS_UDOING.get(editor) ?? !1;
|
|
1999
1882
|
}
|
|
2000
1883
|
function setIsUndoing(editor, isUndoing2) {
|
|
2001
1884
|
IS_UDOING.set(editor, isUndoing2);
|
|
@@ -2005,20 +1888,11 @@ function withRedoing(editor, fn) {
|
|
|
2005
1888
|
IS_REDOING.set(editor, !0), fn(), IS_REDOING.set(editor, prev);
|
|
2006
1889
|
}
|
|
2007
1890
|
function isRedoing(editor) {
|
|
2008
|
-
|
|
2009
|
-
return (_a = IS_REDOING.get(editor)) != null ? _a : !1;
|
|
1891
|
+
return IS_REDOING.get(editor) ?? !1;
|
|
2010
1892
|
}
|
|
2011
1893
|
function setIsRedoing(editor, isRedoing2) {
|
|
2012
1894
|
IS_REDOING.set(editor, isRedoing2);
|
|
2013
1895
|
}
|
|
2014
|
-
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) => {
|
|
2015
|
-
for (var prop in b || (b = {}))
|
|
2016
|
-
__hasOwnProp$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
2017
|
-
if (__getOwnPropSymbols$m)
|
|
2018
|
-
for (var prop of __getOwnPropSymbols$m(b))
|
|
2019
|
-
__propIsEnum$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
2020
|
-
return a;
|
|
2021
|
-
};
|
|
2022
1896
|
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) => {
|
|
2023
1897
|
const state = SAVING.get(editor);
|
|
2024
1898
|
return state === void 0 ? !0 : state;
|
|
@@ -2181,7 +2055,9 @@ function createWithUndoRedo(options) {
|
|
|
2181
2055
|
}
|
|
2182
2056
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2183
2057
|
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)}`));
|
|
2184
|
-
const transformedOperation =
|
|
2058
|
+
const transformedOperation = {
|
|
2059
|
+
...operation
|
|
2060
|
+
};
|
|
2185
2061
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
2186
2062
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2187
2063
|
_key: blk._key
|
|
@@ -2201,7 +2077,6 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2201
2077
|
return !operationTargetBlock || !isEqual__default.default({
|
|
2202
2078
|
_key: operationTargetBlock._key
|
|
2203
2079
|
}, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
2204
|
-
var _a, _b, _c, _d;
|
|
2205
2080
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
|
|
2206
2081
|
const {
|
|
2207
2082
|
diffs
|
|
@@ -2210,7 +2085,15 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2210
2085
|
const [diffType, text] = diff2;
|
|
2211
2086
|
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));
|
|
2212
2087
|
}), 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") {
|
|
2213
|
-
const currentFocus =
|
|
2088
|
+
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2089
|
+
...transformedOperation.properties.focus
|
|
2090
|
+
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
2091
|
+
...transformedOperation.properties.anchor
|
|
2092
|
+
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
2093
|
+
...transformedOperation.newProperties.focus
|
|
2094
|
+
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
2095
|
+
...transformedOperation.newProperties.anchor
|
|
2096
|
+
} : void 0;
|
|
2214
2097
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2215
2098
|
point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
|
|
2216
2099
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2226,14 +2109,23 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2226
2109
|
return [transformedOperation];
|
|
2227
2110
|
}
|
|
2228
2111
|
function adjustBlockPath(operation, level, blockIndex) {
|
|
2229
|
-
|
|
2230
|
-
|
|
2112
|
+
const transformedOperation = {
|
|
2113
|
+
...operation
|
|
2114
|
+
};
|
|
2231
2115
|
if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
|
|
2232
2116
|
const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
|
|
2233
2117
|
transformedOperation.path = newPath;
|
|
2234
2118
|
}
|
|
2235
2119
|
if (transformedOperation.type === "set_selection") {
|
|
2236
|
-
const currentFocus =
|
|
2120
|
+
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2121
|
+
...transformedOperation.properties.focus
|
|
2122
|
+
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
2123
|
+
...transformedOperation.properties.anchor
|
|
2124
|
+
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
2125
|
+
...transformedOperation.newProperties.focus
|
|
2126
|
+
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
2127
|
+
...transformedOperation.newProperties.anchor
|
|
2128
|
+
} : void 0;
|
|
2237
2129
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2238
2130
|
point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
|
|
2239
2131
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2254,27 +2146,18 @@ function withoutSaving(editor, fn) {
|
|
|
2254
2146
|
function createSelectOperation(editor) {
|
|
2255
2147
|
return {
|
|
2256
2148
|
type: "set_selection",
|
|
2257
|
-
properties:
|
|
2258
|
-
|
|
2149
|
+
properties: {
|
|
2150
|
+
...editor.selection
|
|
2151
|
+
},
|
|
2152
|
+
newProperties: {
|
|
2153
|
+
...editor.selection
|
|
2154
|
+
}
|
|
2259
2155
|
};
|
|
2260
2156
|
}
|
|
2261
2157
|
function findOperationTargetBlock(editor, operation) {
|
|
2262
2158
|
let block;
|
|
2263
2159
|
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;
|
|
2264
2160
|
}
|
|
2265
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name), __await = function(promise, isYieldStar) {
|
|
2266
|
-
this[0] = promise, this[1] = isYieldStar;
|
|
2267
|
-
}, __asyncGenerator = (__this, __arguments, generator) => {
|
|
2268
|
-
var resume = (k, v, yes, no) => {
|
|
2269
|
-
try {
|
|
2270
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
2271
|
-
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));
|
|
2272
|
-
} catch (e) {
|
|
2273
|
-
no(e);
|
|
2274
|
-
}
|
|
2275
|
-
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
2276
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
2277
|
-
}, __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);
|
|
2278
2161
|
const syncValueCallback = ({
|
|
2279
2162
|
sendBack,
|
|
2280
2163
|
input
|
|
@@ -2325,10 +2208,7 @@ const syncValueCallback = ({
|
|
|
2325
2208
|
}) => context.initialValueSynced,
|
|
2326
2209
|
"is busy": ({
|
|
2327
2210
|
context
|
|
2328
|
-
}) =>
|
|
2329
|
-
var _a;
|
|
2330
|
-
return !context.readOnly && (context.isProcessingLocalChanges || ((_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1));
|
|
2331
|
-
},
|
|
2211
|
+
}) => !context.readOnly && (context.isProcessingLocalChanges || (isChangingRemotely(context.slateEditor) ?? !1)),
|
|
2332
2212
|
"value changed while syncing": ({
|
|
2333
2213
|
context,
|
|
2334
2214
|
event
|
|
@@ -2513,33 +2393,22 @@ async function updateValue({
|
|
|
2513
2393
|
});
|
|
2514
2394
|
isChanged = !0;
|
|
2515
2395
|
}
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2533
|
-
}
|
|
2534
|
-
} catch (temp2) {
|
|
2535
|
-
error = [temp2];
|
|
2536
|
-
} finally {
|
|
2537
|
-
try {
|
|
2538
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2539
|
-
} finally {
|
|
2540
|
-
if (error)
|
|
2541
|
-
throw error[0];
|
|
2542
|
-
}
|
|
2396
|
+
for await (const [currentBlock, currentBlockIndex] of getBlocks({
|
|
2397
|
+
slateValue: slateValueFromProps,
|
|
2398
|
+
streamBlocks
|
|
2399
|
+
})) {
|
|
2400
|
+
const {
|
|
2401
|
+
blockChanged,
|
|
2402
|
+
blockValid
|
|
2403
|
+
} = syncBlock({
|
|
2404
|
+
context,
|
|
2405
|
+
sendBack,
|
|
2406
|
+
block: currentBlock,
|
|
2407
|
+
index: currentBlockIndex,
|
|
2408
|
+
slateEditor,
|
|
2409
|
+
value
|
|
2410
|
+
});
|
|
2411
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2543
2412
|
}
|
|
2544
2413
|
resolve();
|
|
2545
2414
|
});
|
|
@@ -2589,28 +2458,13 @@ async function updateValue({
|
|
|
2589
2458
|
value
|
|
2590
2459
|
});
|
|
2591
2460
|
}
|
|
2592
|
-
function getBlocks(
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
for (var iter = __forAwait(slateValue), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = !1) {
|
|
2600
|
-
const block = temp.value;
|
|
2601
|
-
streamBlocks && (yield new __await(new Promise((resolve) => setTimeout(resolve, 0)))), yield [block, index], index++;
|
|
2602
|
-
}
|
|
2603
|
-
} catch (temp2) {
|
|
2604
|
-
error = [temp2];
|
|
2605
|
-
} finally {
|
|
2606
|
-
try {
|
|
2607
|
-
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2608
|
-
} finally {
|
|
2609
|
-
if (error)
|
|
2610
|
-
throw error[0];
|
|
2611
|
-
}
|
|
2612
|
-
}
|
|
2613
|
-
});
|
|
2461
|
+
async function* getBlocks({
|
|
2462
|
+
slateValue,
|
|
2463
|
+
streamBlocks
|
|
2464
|
+
}) {
|
|
2465
|
+
let index = 0;
|
|
2466
|
+
for await (const block of slateValue)
|
|
2467
|
+
streamBlocks && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
2614
2468
|
}
|
|
2615
2469
|
function syncBlock({
|
|
2616
2470
|
context,
|
|
@@ -2625,15 +2479,14 @@ function syncBlock({
|
|
|
2625
2479
|
return slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
2626
2480
|
withRemoteChanges(slateEditor, () => {
|
|
2627
2481
|
withoutPatching(slateEditor, () => {
|
|
2628
|
-
var _a, _b, _c, _d, _e;
|
|
2629
2482
|
if (hasChanges && blockValid) {
|
|
2630
2483
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2631
|
-
!validation.valid &&
|
|
2484
|
+
!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) => {
|
|
2632
2485
|
sendBack({
|
|
2633
2486
|
type: "patch",
|
|
2634
2487
|
patch
|
|
2635
2488
|
});
|
|
2636
|
-
})), validation.valid ||
|
|
2489
|
+
})), 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({
|
|
2637
2490
|
type: "invalid value",
|
|
2638
2491
|
resolution: validation.resolution,
|
|
2639
2492
|
value
|
|
@@ -2641,7 +2494,7 @@ function syncBlock({
|
|
|
2641
2494
|
}
|
|
2642
2495
|
if (!oldBlock && blockValid) {
|
|
2643
2496
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2644
|
-
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid ||
|
|
2497
|
+
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2645
2498
|
at: [currentBlockIndex]
|
|
2646
2499
|
}) : (debug$i("Invalid", validation), sendBack({
|
|
2647
2500
|
type: "invalid value",
|
|
@@ -2675,9 +2528,9 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2675
2528
|
at: [currentBlockIndex, childIndex]
|
|
2676
2529
|
}));
|
|
2677
2530
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2678
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild
|
|
2531
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2679
2532
|
if (isChildChanged)
|
|
2680
|
-
if (currentBlockChild._key ===
|
|
2533
|
+
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2681
2534
|
debug$i("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2682
2535
|
at: path
|
|
2683
2536
|
});
|
|
@@ -2804,14 +2657,6 @@ function _temp(s) {
|
|
|
2804
2657
|
return s.context.value;
|
|
2805
2658
|
}
|
|
2806
2659
|
Synchronizer.displayName = "Synchronizer";
|
|
2807
|
-
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) => {
|
|
2808
|
-
for (var prop in b || (b = {}))
|
|
2809
|
-
__hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2810
|
-
if (__getOwnPropSymbols$l)
|
|
2811
|
-
for (var prop of __getOwnPropSymbols$l(b))
|
|
2812
|
-
__propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2813
|
-
return a;
|
|
2814
|
-
}, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
|
|
2815
2660
|
const debug$g = debugWithName("operationToPatches");
|
|
2816
2661
|
function createOperationToPatches(types2) {
|
|
2817
2662
|
const textBlockName = types2.block.name;
|
|
@@ -2851,7 +2696,10 @@ function createOperationToPatches(types2) {
|
|
|
2851
2696
|
const block = editor.children[operation.path[0]];
|
|
2852
2697
|
if (typeof block._key != "string")
|
|
2853
2698
|
throw new Error("Expected block to have a _key");
|
|
2854
|
-
const setNode = omitBy__default.default(
|
|
2699
|
+
const setNode = omitBy__default.default({
|
|
2700
|
+
...editor.children[operation.path[0]],
|
|
2701
|
+
...operation.newProperties
|
|
2702
|
+
}, isUndefined__default.default);
|
|
2855
2703
|
return [patches.set(fromSlateValue([setNode], textBlockName)[0], [{
|
|
2856
2704
|
_key: block._key
|
|
2857
2705
|
}])];
|
|
@@ -2886,12 +2734,14 @@ function createOperationToPatches(types2) {
|
|
|
2886
2734
|
function insertNodePatch(editor, operation, beforeValue) {
|
|
2887
2735
|
const block = beforeValue[operation.path[0]], isTextBlock = editor.isTextBlock(block);
|
|
2888
2736
|
if (operation.path.length === 1) {
|
|
2889
|
-
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block
|
|
2737
|
+
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
|
|
2890
2738
|
return targetKey ? [patches.insert([fromSlateValue([operation.node], textBlockName)[0]], position, [{
|
|
2891
2739
|
_key: targetKey
|
|
2892
2740
|
}])] : [patches.setIfMissing(beforeValue, []), patches.insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
|
|
2893
2741
|
} else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
|
|
2894
|
-
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node =
|
|
2742
|
+
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
|
|
2743
|
+
...operation.node
|
|
2744
|
+
};
|
|
2895
2745
|
!node._type && slate.Text.isText(node) && (node._type = "span", node.marks = []);
|
|
2896
2746
|
const child = fromSlateValue([{
|
|
2897
2747
|
_key: "bogus",
|
|
@@ -2930,9 +2780,10 @@ function createOperationToPatches(types2) {
|
|
|
2930
2780
|
if (operation.path.length === 2) {
|
|
2931
2781
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
2932
2782
|
if (editor.isTextSpan(splitSpan)) {
|
|
2933
|
-
const targetSpans = fromSlateValue([
|
|
2783
|
+
const targetSpans = fromSlateValue([{
|
|
2784
|
+
...splitBlock,
|
|
2934
2785
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
2935
|
-
}
|
|
2786
|
+
}], textBlockName)[0].children;
|
|
2936
2787
|
patches$1.push(patches.insert(targetSpans, "after", [{
|
|
2937
2788
|
_key: splitBlock._key
|
|
2938
2789
|
}, "children", {
|
|
@@ -2968,7 +2819,7 @@ function createOperationToPatches(types2) {
|
|
|
2968
2819
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2969
2820
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
2970
2821
|
if (operation.path.length === 1)
|
|
2971
|
-
if (block
|
|
2822
|
+
if (block?._key) {
|
|
2972
2823
|
const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
|
|
2973
2824
|
patches$1.push(patches.set(newBlock, [{
|
|
2974
2825
|
_key: newBlock._key
|
|
@@ -3240,7 +3091,6 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3240
3091
|
apply: apply2
|
|
3241
3092
|
} = editor;
|
|
3242
3093
|
return editor.apply = (operation) => {
|
|
3243
|
-
var _a;
|
|
3244
3094
|
if (editorActor.getSnapshot().matches({
|
|
3245
3095
|
"edit mode": "read only"
|
|
3246
3096
|
})) {
|
|
@@ -3255,19 +3105,11 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3255
3105
|
apply2(operation);
|
|
3256
3106
|
return;
|
|
3257
3107
|
}
|
|
3258
|
-
const rows =
|
|
3108
|
+
const rows = editorActor.getSnapshot().context.maxBlocks ?? -1;
|
|
3259
3109
|
rows > 0 && editor.children.length >= rows && (operation.type === "insert_node" || operation.type === "split_node") && operation.path.length === 1 || apply2(operation);
|
|
3260
3110
|
}, editor;
|
|
3261
3111
|
};
|
|
3262
3112
|
}
|
|
3263
|
-
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) => {
|
|
3264
|
-
for (var prop in b || (b = {}))
|
|
3265
|
-
__hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3266
|
-
if (__getOwnPropSymbols$k)
|
|
3267
|
-
for (var prop of __getOwnPropSymbols$k(b))
|
|
3268
|
-
__propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3269
|
-
return a;
|
|
3270
|
-
}, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
3271
3113
|
function createWithObjectKeys(editorActor, schemaTypes) {
|
|
3272
3114
|
return function(editor) {
|
|
3273
3115
|
const {
|
|
@@ -3284,19 +3126,23 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3284
3126
|
return;
|
|
3285
3127
|
}
|
|
3286
3128
|
if (operation.type === "split_node") {
|
|
3287
|
-
apply2(
|
|
3288
|
-
|
|
3129
|
+
apply2({
|
|
3130
|
+
...operation,
|
|
3131
|
+
properties: {
|
|
3132
|
+
...operation.properties,
|
|
3289
3133
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3290
|
-
}
|
|
3291
|
-
})
|
|
3134
|
+
}
|
|
3135
|
+
});
|
|
3292
3136
|
return;
|
|
3293
3137
|
}
|
|
3294
3138
|
if (operation.type === "insert_node" && !slate.Editor.isEditor(operation.node)) {
|
|
3295
|
-
apply2(
|
|
3296
|
-
|
|
3139
|
+
apply2({
|
|
3140
|
+
...operation,
|
|
3141
|
+
node: {
|
|
3142
|
+
...operation.node,
|
|
3297
3143
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3298
|
-
}
|
|
3299
|
-
})
|
|
3144
|
+
}
|
|
3145
|
+
});
|
|
3300
3146
|
return;
|
|
3301
3147
|
}
|
|
3302
3148
|
apply2(operation);
|
|
@@ -3333,22 +3179,6 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3333
3179
|
}, editor;
|
|
3334
3180
|
};
|
|
3335
3181
|
}
|
|
3336
|
-
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) => {
|
|
3337
|
-
for (var prop in b || (b = {}))
|
|
3338
|
-
__hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3339
|
-
if (__getOwnPropSymbols$j)
|
|
3340
|
-
for (var prop of __getOwnPropSymbols$j(b))
|
|
3341
|
-
__propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3342
|
-
return a;
|
|
3343
|
-
}, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
|
|
3344
|
-
var target = {};
|
|
3345
|
-
for (var prop in source)
|
|
3346
|
-
__hasOwnProp$j.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
3347
|
-
if (source != null && __getOwnPropSymbols$j)
|
|
3348
|
-
for (var prop of __getOwnPropSymbols$j(source))
|
|
3349
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$j.call(source, prop) && (target[prop] = source[prop]);
|
|
3350
|
-
return target;
|
|
3351
|
-
};
|
|
3352
3182
|
const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
|
|
3353
3183
|
function createApplyPatch(schemaTypes) {
|
|
3354
3184
|
return (editor, patch) => {
|
|
@@ -3438,9 +3268,10 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3438
3268
|
} = patch;
|
|
3439
3269
|
if (!targetChild || !targetChildPath)
|
|
3440
3270
|
return debug$f("Child not found"), !1;
|
|
3441
|
-
const childrenToInsert = targetBlock && toSlateValue([
|
|
3271
|
+
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3272
|
+
...targetBlock,
|
|
3442
3273
|
children: items
|
|
3443
|
-
}
|
|
3274
|
+
}], {
|
|
3444
3275
|
schemaTypes
|
|
3445
3276
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3446
3277
|
return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
@@ -3485,19 +3316,21 @@ function setPatch(editor, patch) {
|
|
|
3485
3316
|
return !0;
|
|
3486
3317
|
} else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3487
3318
|
debug$f("Setting block property");
|
|
3488
|
-
const
|
|
3489
|
-
children
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3319
|
+
const {
|
|
3320
|
+
children,
|
|
3321
|
+
...nextRest
|
|
3322
|
+
} = value, {
|
|
3323
|
+
children: prevChildren,
|
|
3324
|
+
...prevRest
|
|
3325
|
+
} = block || {
|
|
3493
3326
|
children: void 0
|
|
3494
|
-
}
|
|
3495
|
-
"children"
|
|
3496
|
-
]);
|
|
3327
|
+
};
|
|
3497
3328
|
editor.apply({
|
|
3498
3329
|
type: "set_node",
|
|
3499
3330
|
path: blockPath,
|
|
3500
|
-
properties:
|
|
3331
|
+
properties: {
|
|
3332
|
+
...prevRest
|
|
3333
|
+
},
|
|
3501
3334
|
newProperties: nextRest
|
|
3502
3335
|
}), debug$f("Setting children"), block.children.forEach((c, cIndex) => {
|
|
3503
3336
|
editor.apply({
|
|
@@ -3514,9 +3347,10 @@ function setPatch(editor, patch) {
|
|
|
3514
3347
|
});
|
|
3515
3348
|
} else if (block && "value" in block) {
|
|
3516
3349
|
const newVal = patches.applyAll([block.value], [patch])[0];
|
|
3517
|
-
return slate.Transforms.setNodes(editor,
|
|
3350
|
+
return slate.Transforms.setNodes(editor, {
|
|
3351
|
+
...block,
|
|
3518
3352
|
value: newVal
|
|
3519
|
-
}
|
|
3353
|
+
}, {
|
|
3520
3354
|
at: blockPath
|
|
3521
3355
|
}), !0;
|
|
3522
3356
|
}
|
|
@@ -3599,7 +3433,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3599
3433
|
block,
|
|
3600
3434
|
child,
|
|
3601
3435
|
blockPath,
|
|
3602
|
-
childPath: blockPath
|
|
3436
|
+
childPath: blockPath?.concat(childIndex)
|
|
3603
3437
|
} : {
|
|
3604
3438
|
block,
|
|
3605
3439
|
blockPath,
|
|
@@ -3607,14 +3441,6 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3607
3441
|
childPath: void 0
|
|
3608
3442
|
};
|
|
3609
3443
|
}
|
|
3610
|
-
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) => {
|
|
3611
|
-
for (var prop in b || (b = {}))
|
|
3612
|
-
__hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3613
|
-
if (__getOwnPropSymbols$i)
|
|
3614
|
-
for (var prop of __getOwnPropSymbols$i(b))
|
|
3615
|
-
__propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3616
|
-
return a;
|
|
3617
|
-
}, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
3618
3444
|
const debug$e = debugWithName("plugin:withPatches");
|
|
3619
3445
|
function createWithPatches({
|
|
3620
3446
|
editorActor,
|
|
@@ -3699,9 +3525,10 @@ function createWithPatches({
|
|
|
3699
3525
|
})), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0 && patches$1.forEach((patch) => {
|
|
3700
3526
|
editorActor.send({
|
|
3701
3527
|
type: "patch",
|
|
3702
|
-
patch:
|
|
3528
|
+
patch: {
|
|
3529
|
+
...patch,
|
|
3703
3530
|
origin: "local"
|
|
3704
|
-
}
|
|
3531
|
+
}
|
|
3705
3532
|
});
|
|
3706
3533
|
}), editor;
|
|
3707
3534
|
}, editor;
|
|
@@ -3814,14 +3641,6 @@ function getNextSpan({
|
|
|
3814
3641
|
}
|
|
3815
3642
|
return nextSpan;
|
|
3816
3643
|
}
|
|
3817
|
-
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) => {
|
|
3818
|
-
for (var prop in b || (b = {}))
|
|
3819
|
-
__hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3820
|
-
if (__getOwnPropSymbols$h)
|
|
3821
|
-
for (var prop of __getOwnPropSymbols$h(b))
|
|
3822
|
-
__propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3823
|
-
return a;
|
|
3824
|
-
}, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
|
|
3825
3644
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
3826
3645
|
function createWithPortableTextMarkModel(editorActor, types2) {
|
|
3827
3646
|
return function(editor) {
|
|
@@ -3830,19 +3649,12 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3830
3649
|
normalizeNode
|
|
3831
3650
|
} = editor, decorators = types2.decorators.map((t) => t.value);
|
|
3832
3651
|
return editor.normalizeNode = (nodeEntry) => {
|
|
3833
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3834
3652
|
const [node, path] = nodeEntry;
|
|
3835
3653
|
if (editor.isTextBlock(node)) {
|
|
3836
3654
|
const children = slate.Node.children(editor, path);
|
|
3837
3655
|
for (const [child, childPath] of children) {
|
|
3838
3656
|
const nextNode = node.children[childPath[1] + 1];
|
|
3839
|
-
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && (
|
|
3840
|
-
var _a2;
|
|
3841
|
-
return (_a2 = nextNode.marks) == null ? void 0 : _a2.includes(mark);
|
|
3842
|
-
}) && (_b = nextNode.marks) != null && _b.every((mark) => {
|
|
3843
|
-
var _a2;
|
|
3844
|
-
return (_a2 = child.marks) == null ? void 0 : _a2.includes(mark);
|
|
3845
|
-
})) {
|
|
3657
|
+
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3846
3658
|
debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3847
3659
|
type: "normalizing"
|
|
3848
3660
|
}), slate.Transforms.mergeNodes(editor, {
|
|
@@ -3880,12 +3692,12 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3880
3692
|
return;
|
|
3881
3693
|
}
|
|
3882
3694
|
if (editor.isTextSpan(node)) {
|
|
3883
|
-
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations =
|
|
3695
|
+
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3884
3696
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3885
3697
|
debug$b("Removing annotations from empty span node"), editorActor.send({
|
|
3886
3698
|
type: "normalizing"
|
|
3887
3699
|
}), slate.Transforms.setNodes(editor, {
|
|
3888
|
-
marks:
|
|
3700
|
+
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
3889
3701
|
}, {
|
|
3890
3702
|
at: path
|
|
3891
3703
|
}), editorActor.send({
|
|
@@ -3898,10 +3710,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3898
3710
|
const decorators2 = types2.decorators.map((decorator) => decorator.value);
|
|
3899
3711
|
for (const [child, childPath] of slate.Node.children(editor, path))
|
|
3900
3712
|
if (editor.isTextSpan(child)) {
|
|
3901
|
-
const marks =
|
|
3902
|
-
var _a2;
|
|
3903
|
-
return !decorators2.includes(mark) && !((_a2 = node.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3904
|
-
});
|
|
3713
|
+
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3905
3714
|
if (orphanedAnnotations.length > 0) {
|
|
3906
3715
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3907
3716
|
type: "normalizing"
|
|
@@ -3919,10 +3728,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3919
3728
|
if (editor.isTextSpan(node)) {
|
|
3920
3729
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath);
|
|
3921
3730
|
if (editor.isTextBlock(block)) {
|
|
3922
|
-
const decorators2 = types2.decorators.map((decorator) => decorator.value), marks =
|
|
3923
|
-
var _a2;
|
|
3924
|
-
return !decorators2.includes(mark) && !((_a2 = block.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3925
|
-
});
|
|
3731
|
+
const decorators2 = types2.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3926
3732
|
if (orphanedAnnotations.length > 0) {
|
|
3927
3733
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3928
3734
|
type: "normalizing"
|
|
@@ -3938,7 +3744,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3938
3744
|
}
|
|
3939
3745
|
}
|
|
3940
3746
|
if (editor.isTextBlock(node)) {
|
|
3941
|
-
const markDefs =
|
|
3747
|
+
const markDefs = node.markDefs ?? [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
|
|
3942
3748
|
for (const markDef of markDefs)
|
|
3943
3749
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3944
3750
|
if (markDefs.length !== newMarkDefs.length) {
|
|
@@ -3971,7 +3777,6 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3971
3777
|
}
|
|
3972
3778
|
normalizeNode(nodeEntry);
|
|
3973
3779
|
}, editor.apply = (op) => {
|
|
3974
|
-
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;
|
|
3975
3780
|
if (isChangingRemotely(editor)) {
|
|
3976
3781
|
apply2(op);
|
|
3977
3782
|
return;
|
|
@@ -3989,17 +3794,17 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3989
3794
|
focus: op.newProperties.focus
|
|
3990
3795
|
});
|
|
3991
3796
|
if (previousSelectionIsCollapsed && newSelectionIsCollapsed) {
|
|
3992
|
-
const focusSpan =
|
|
3797
|
+
const focusSpan = Array.from(slate.Editor.nodes(editor, {
|
|
3993
3798
|
mode: "lowest",
|
|
3994
3799
|
at: op.properties.focus,
|
|
3995
3800
|
match: (n) => editor.isTextSpan(n),
|
|
3996
3801
|
voids: !1
|
|
3997
|
-
}))[0]
|
|
3802
|
+
}))[0]?.[0], newFocusSpan = Array.from(slate.Editor.nodes(editor, {
|
|
3998
3803
|
mode: "lowest",
|
|
3999
3804
|
at: op.newProperties.focus,
|
|
4000
3805
|
match: (n) => editor.isTextSpan(n),
|
|
4001
3806
|
voids: !1
|
|
4002
|
-
}))[0]
|
|
3807
|
+
}))[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;
|
|
4003
3808
|
if (movedToNextSpan || movedToPreviousSpan)
|
|
4004
3809
|
return;
|
|
4005
3810
|
}
|
|
@@ -4015,29 +3820,32 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4015
3820
|
editor,
|
|
4016
3821
|
blockPath,
|
|
4017
3822
|
spanPath: op.path
|
|
4018
|
-
}), previousSpanAnnotations = previousSpan ?
|
|
3823
|
+
}), previousSpanAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], nextSpan = getNextSpan({
|
|
4019
3824
|
editor,
|
|
4020
3825
|
blockPath,
|
|
4021
3826
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
4022
|
-
}), nextSpanAnnotations = nextSpan ?
|
|
4023
|
-
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4024
|
-
slate.Transforms.insertNodes(editor,
|
|
4025
|
-
|
|
4026
|
-
|
|
3827
|
+
}), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [], atTheEndOfAnnotation = annotationsEnding.length > 0;
|
|
3828
|
+
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
|
|
3829
|
+
slate.Transforms.insertNodes(editor, {
|
|
3830
|
+
...op.node,
|
|
3831
|
+
marks: op.node.marks?.filter((mark) => !annotationsEnding.includes(mark)) ?? []
|
|
3832
|
+
});
|
|
4027
3833
|
return;
|
|
4028
3834
|
}
|
|
4029
|
-
const annotationsStarting =
|
|
4030
|
-
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4031
|
-
slate.Transforms.insertNodes(editor,
|
|
4032
|
-
|
|
4033
|
-
|
|
3835
|
+
const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3836
|
+
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
|
|
3837
|
+
slate.Transforms.insertNodes(editor, {
|
|
3838
|
+
...op.node,
|
|
3839
|
+
marks: op.node.marks?.filter((mark) => !annotationsStarting.includes(mark)) ?? []
|
|
3840
|
+
});
|
|
4034
3841
|
return;
|
|
4035
3842
|
}
|
|
4036
|
-
const nextSpanDecorators =
|
|
4037
|
-
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4038
|
-
slate.Transforms.insertNodes(editor,
|
|
3843
|
+
const nextSpanDecorators = nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? [];
|
|
3844
|
+
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.length === 0) {
|
|
3845
|
+
slate.Transforms.insertNodes(editor, {
|
|
3846
|
+
...op.node,
|
|
4039
3847
|
marks: nextSpanDecorators
|
|
4040
|
-
})
|
|
3848
|
+
});
|
|
4041
3849
|
return;
|
|
4042
3850
|
}
|
|
4043
3851
|
}
|
|
@@ -4049,12 +3857,12 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4049
3857
|
if (selection && collapsedSelection) {
|
|
4050
3858
|
const [_block, blockPath] = slate.Editor.node(editor, selection, {
|
|
4051
3859
|
depth: 1
|
|
4052
|
-
}), [span, spanPath] =
|
|
3860
|
+
}), [span, spanPath] = Array.from(slate.Editor.nodes(editor, {
|
|
4053
3861
|
mode: "lowest",
|
|
4054
3862
|
at: selection.focus,
|
|
4055
3863
|
match: (n) => editor.isTextSpan(n),
|
|
4056
3864
|
voids: !1
|
|
4057
|
-
}))[0]
|
|
3865
|
+
}))[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({
|
|
4058
3866
|
editor,
|
|
4059
3867
|
blockPath,
|
|
4060
3868
|
spanPath
|
|
@@ -4062,7 +3870,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4062
3870
|
editor,
|
|
4063
3871
|
blockPath,
|
|
4064
3872
|
spanPath
|
|
4065
|
-
}), nextSpanAnnotations =
|
|
3873
|
+
}), 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));
|
|
4066
3874
|
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4067
3875
|
if (atTheBeginningOfSpan) {
|
|
4068
3876
|
if (previousSpanHasSameMarks) {
|
|
@@ -4070,7 +3878,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4070
3878
|
_type: "span",
|
|
4071
3879
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4072
3880
|
text: op.text,
|
|
4073
|
-
marks:
|
|
3881
|
+
marks: previousSpan?.marks ?? []
|
|
4074
3882
|
});
|
|
4075
3883
|
return;
|
|
4076
3884
|
} else if (previousSpanHasSameAnnotations) {
|
|
@@ -4078,7 +3886,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4078
3886
|
_type: "span",
|
|
4079
3887
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4080
3888
|
text: op.text,
|
|
4081
|
-
marks:
|
|
3889
|
+
marks: previousSpan?.marks ?? []
|
|
4082
3890
|
});
|
|
4083
3891
|
return;
|
|
4084
3892
|
} else if (previousSpanHasSameAnnotation) {
|
|
@@ -4100,7 +3908,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4100
3908
|
_type: "span",
|
|
4101
3909
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4102
3910
|
text: op.text,
|
|
4103
|
-
marks:
|
|
3911
|
+
marks: nextSpan?.marks ?? []
|
|
4104
3912
|
});
|
|
4105
3913
|
return;
|
|
4106
3914
|
}
|
|
@@ -4120,7 +3928,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4120
3928
|
_type: "span",
|
|
4121
3929
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4122
3930
|
text: op.text,
|
|
4123
|
-
marks: previousSpanHasAnnotations ? [] : (
|
|
3931
|
+
marks: previousSpanHasAnnotations ? [] : (previousSpan.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
4124
3932
|
});
|
|
4125
3933
|
return;
|
|
4126
3934
|
}
|
|
@@ -4133,7 +3941,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4133
3941
|
if (selection && slate.Range.isExpanded(selection)) {
|
|
4134
3942
|
const [block, blockPath] = slate.Editor.node(editor, selection, {
|
|
4135
3943
|
depth: 1
|
|
4136
|
-
}), [span, spanPath] =
|
|
3944
|
+
}), [span, spanPath] = Array.from(slate.Editor.nodes(editor, {
|
|
4137
3945
|
mode: "lowest",
|
|
4138
3946
|
at: {
|
|
4139
3947
|
path: op.path,
|
|
@@ -4141,9 +3949,9 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4141
3949
|
},
|
|
4142
3950
|
match: (n) => editor.isTextSpan(n),
|
|
4143
3951
|
voids: !1
|
|
4144
|
-
}))[0]
|
|
3952
|
+
}))[0] ?? [void 0, void 0];
|
|
4145
3953
|
if (span && block && isPortableTextBlock(block)) {
|
|
4146
|
-
const markDefs =
|
|
3954
|
+
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({
|
|
4147
3955
|
editor,
|
|
4148
3956
|
blockPath,
|
|
4149
3957
|
spanPath
|
|
@@ -4151,9 +3959,11 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4151
3959
|
editor,
|
|
4152
3960
|
blockPath,
|
|
4153
3961
|
spanPath
|
|
4154
|
-
}), previousSpanHasSameAnnotation = previousSpan ?
|
|
3962
|
+
}), 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;
|
|
4155
3963
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
4156
|
-
const marksWithoutAnnotationMarks = (
|
|
3964
|
+
const marksWithoutAnnotationMarks = ({
|
|
3965
|
+
...slate.Editor.marks(editor) || {}
|
|
3966
|
+
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
4157
3967
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
4158
3968
|
apply2(op), slate.Transforms.setNodes(editor, {
|
|
4159
3969
|
marks: marksWithoutAnnotationMarks
|
|
@@ -4186,7 +3996,6 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4186
3996
|
const addDecoratorActionImplementation = ({
|
|
4187
3997
|
action
|
|
4188
3998
|
}) => {
|
|
4189
|
-
var _a;
|
|
4190
3999
|
const editor = action.editor, mark = action.decorator;
|
|
4191
4000
|
if (editor.selection) {
|
|
4192
4001
|
if (slate.Range.isExpanded(editor.selection)) {
|
|
@@ -4199,10 +4008,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4199
4008
|
at: editor.selection,
|
|
4200
4009
|
match: slate.Text.isText
|
|
4201
4010
|
})] : [];
|
|
4202
|
-
splitTextNodes.length > 1 && splitTextNodes.every((node) => {
|
|
4203
|
-
var _a2;
|
|
4204
|
-
return (_a2 = node[0].marks) == null ? void 0 : _a2.includes(mark);
|
|
4205
|
-
}) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4011
|
+
splitTextNodes.length > 1 && splitTextNodes.every((node) => node[0].marks?.includes(mark)) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4206
4012
|
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
4207
4013
|
slate.Transforms.setNodes(editor, {
|
|
4208
4014
|
marks
|
|
@@ -4218,7 +4024,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4218
4024
|
depth: 1
|
|
4219
4025
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4220
4026
|
if (lonelyEmptySpan) {
|
|
4221
|
-
const existingMarks =
|
|
4027
|
+
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
4222
4028
|
slate.Transforms.setNodes(editor, {
|
|
4223
4029
|
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
4224
4030
|
}, {
|
|
@@ -4226,9 +4032,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4226
4032
|
match: (node) => editor.isTextSpan(node)
|
|
4227
4033
|
});
|
|
4228
4034
|
} else {
|
|
4229
|
-
const existingMarks =
|
|
4035
|
+
const existingMarks = {
|
|
4036
|
+
...slate.Editor.marks(editor) || {}
|
|
4037
|
+
}.marks || [], marks = {
|
|
4038
|
+
...slate.Editor.marks(editor) || {},
|
|
4230
4039
|
marks: [...existingMarks, mark]
|
|
4231
|
-
}
|
|
4040
|
+
};
|
|
4232
4041
|
editor.marks = marks;
|
|
4233
4042
|
}
|
|
4234
4043
|
}
|
|
@@ -4237,7 +4046,6 @@ const addDecoratorActionImplementation = ({
|
|
|
4237
4046
|
}, removeDecoratorActionImplementation = ({
|
|
4238
4047
|
action
|
|
4239
4048
|
}) => {
|
|
4240
|
-
var _a;
|
|
4241
4049
|
const editor = action.editor, mark = action.decorator, {
|
|
4242
4050
|
selection
|
|
4243
4051
|
} = editor;
|
|
@@ -4264,7 +4072,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4264
4072
|
depth: 1
|
|
4265
4073
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4266
4074
|
if (lonelyEmptySpan) {
|
|
4267
|
-
const existingMarksWithoutDecorator = (
|
|
4075
|
+
const existingMarksWithoutDecorator = (lonelyEmptySpan.marks ?? []).filter((existingMark) => existingMark !== mark);
|
|
4268
4076
|
slate.Transforms.setNodes(editor, {
|
|
4269
4077
|
marks: existingMarksWithoutDecorator
|
|
4270
4078
|
}, {
|
|
@@ -4272,9 +4080,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4272
4080
|
match: (node) => editor.isTextSpan(node)
|
|
4273
4081
|
});
|
|
4274
4082
|
} else {
|
|
4275
|
-
const existingMarks =
|
|
4083
|
+
const existingMarks = {
|
|
4084
|
+
...slate.Editor.marks(editor) || {}
|
|
4085
|
+
}.marks || [], marks = {
|
|
4086
|
+
...slate.Editor.marks(editor) || {},
|
|
4276
4087
|
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
4277
|
-
}
|
|
4088
|
+
};
|
|
4278
4089
|
editor.marks = {
|
|
4279
4090
|
marks: marks.marks,
|
|
4280
4091
|
_type: "span"
|
|
@@ -4293,10 +4104,11 @@ function isDecoratorActive({
|
|
|
4293
4104
|
at: editor.selection
|
|
4294
4105
|
}));
|
|
4295
4106
|
return selectedTextNodes.length === 0 ? !1 : slate.Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
|
|
4296
|
-
var _a;
|
|
4297
4107
|
const [node] = n;
|
|
4298
|
-
return
|
|
4299
|
-
}) : (
|
|
4108
|
+
return node.marks?.includes(decorator);
|
|
4109
|
+
}) : ({
|
|
4110
|
+
...slate.Editor.marks(editor) || {}
|
|
4111
|
+
}.marks || []).includes(decorator);
|
|
4300
4112
|
}
|
|
4301
4113
|
const toggleDecoratorActionImplementation = ({
|
|
4302
4114
|
context,
|
|
@@ -4356,14 +4168,6 @@ function createWithPortableTextSelections(editorActor, types2) {
|
|
|
4356
4168
|
}, editor;
|
|
4357
4169
|
};
|
|
4358
4170
|
}
|
|
4359
|
-
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) => {
|
|
4360
|
-
for (var prop in b || (b = {}))
|
|
4361
|
-
__hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4362
|
-
if (__getOwnPropSymbols$g)
|
|
4363
|
-
for (var prop of __getOwnPropSymbols$g(b))
|
|
4364
|
-
__propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4365
|
-
return a;
|
|
4366
|
-
}, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
4367
4171
|
const debug$9 = debugWithName("plugin:withSchemaTypes");
|
|
4368
4172
|
function createWithSchemaTypes({
|
|
4369
4173
|
editorActor,
|
|
@@ -4381,10 +4185,11 @@ function createWithSchemaTypes({
|
|
|
4381
4185
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4382
4186
|
editorActor.send({
|
|
4383
4187
|
type: "normalizing"
|
|
4384
|
-
}), slate.Transforms.setNodes(editor,
|
|
4188
|
+
}), slate.Transforms.setNodes(editor, {
|
|
4189
|
+
...span,
|
|
4385
4190
|
_type: schemaTypes.span.name,
|
|
4386
4191
|
_key: key
|
|
4387
|
-
}
|
|
4192
|
+
}, {
|
|
4388
4193
|
at: path
|
|
4389
4194
|
}), editorActor.send({
|
|
4390
4195
|
type: "done normalizing"
|
|
@@ -4409,14 +4214,6 @@ function createWithSchemaTypes({
|
|
|
4409
4214
|
}, editor;
|
|
4410
4215
|
};
|
|
4411
4216
|
}
|
|
4412
|
-
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) => {
|
|
4413
|
-
for (var prop in b || (b = {}))
|
|
4414
|
-
__hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4415
|
-
if (__getOwnPropSymbols$f)
|
|
4416
|
-
for (var prop of __getOwnPropSymbols$f(b))
|
|
4417
|
-
__propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4418
|
-
return a;
|
|
4419
|
-
}, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
4420
4217
|
const debug$8 = debugWithName("plugin:withUtils");
|
|
4421
4218
|
function createWithUtils({
|
|
4422
4219
|
editorActor,
|
|
@@ -4440,26 +4237,29 @@ function createWithUtils({
|
|
|
4440
4237
|
} = 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);
|
|
4441
4238
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4442
4239
|
debug$8("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
|
|
4443
|
-
anchor:
|
|
4240
|
+
anchor: {
|
|
4241
|
+
...selection.anchor,
|
|
4444
4242
|
offset: newStartOffset
|
|
4445
|
-
}
|
|
4446
|
-
focus:
|
|
4243
|
+
},
|
|
4244
|
+
focus: {
|
|
4245
|
+
...selection.focus,
|
|
4447
4246
|
offset: newEndOffset
|
|
4448
|
-
}
|
|
4247
|
+
}
|
|
4449
4248
|
});
|
|
4450
4249
|
return;
|
|
4451
4250
|
}
|
|
4452
4251
|
debug$8("pteExpandToWord: Can't expand to word here");
|
|
4453
4252
|
}
|
|
4454
|
-
}, editor.pteCreateTextBlock = (options) => toSlateValue([
|
|
4253
|
+
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4455
4254
|
_type: schemaTypes.block.name,
|
|
4456
4255
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4457
|
-
style: schemaTypes.styles[0].value || "normal"
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4256
|
+
style: schemaTypes.styles[0].value || "normal",
|
|
4257
|
+
...options.listItem ? {
|
|
4258
|
+
listItem: options.listItem
|
|
4259
|
+
} : {},
|
|
4260
|
+
...options.level ? {
|
|
4261
|
+
level: options.level
|
|
4262
|
+
} : {},
|
|
4463
4263
|
markDefs: [],
|
|
4464
4264
|
children: [{
|
|
4465
4265
|
_type: "span",
|
|
@@ -4469,7 +4269,7 @@ function createWithUtils({
|
|
|
4469
4269
|
value
|
|
4470
4270
|
}) => value === decorator))
|
|
4471
4271
|
}]
|
|
4472
|
-
}
|
|
4272
|
+
}], {
|
|
4473
4273
|
schemaTypes
|
|
4474
4274
|
})[0], editor;
|
|
4475
4275
|
};
|
|
@@ -4515,14 +4315,6 @@ function createSlateEditor(config) {
|
|
|
4515
4315
|
};
|
|
4516
4316
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4517
4317
|
}
|
|
4518
|
-
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) => {
|
|
4519
|
-
for (var prop in b || (b = {}))
|
|
4520
|
-
__hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4521
|
-
if (__getOwnPropSymbols$e)
|
|
4522
|
-
for (var prop of __getOwnPropSymbols$e(b))
|
|
4523
|
-
__propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4524
|
-
return a;
|
|
4525
|
-
}, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
4526
4318
|
const toggleListItemActionImplementation = ({
|
|
4527
4319
|
context,
|
|
4528
4320
|
action
|
|
@@ -4532,14 +4324,16 @@ const toggleListItemActionImplementation = ({
|
|
|
4532
4324
|
listItem: action.listItem
|
|
4533
4325
|
}) ? removeListItemActionImplementation({
|
|
4534
4326
|
context,
|
|
4535
|
-
action:
|
|
4327
|
+
action: {
|
|
4328
|
+
...action,
|
|
4536
4329
|
type: "list item.remove"
|
|
4537
|
-
}
|
|
4330
|
+
}
|
|
4538
4331
|
}) : addListItemActionImplementation({
|
|
4539
4332
|
context,
|
|
4540
|
-
action:
|
|
4333
|
+
action: {
|
|
4334
|
+
...action,
|
|
4541
4335
|
type: "list item.add"
|
|
4542
|
-
}
|
|
4336
|
+
}
|
|
4543
4337
|
});
|
|
4544
4338
|
}, removeListItemActionImplementation = ({
|
|
4545
4339
|
context,
|
|
@@ -4585,14 +4379,6 @@ function isListItemActive({
|
|
|
4585
4379
|
})];
|
|
4586
4380
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
4587
4381
|
}
|
|
4588
|
-
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) => {
|
|
4589
|
-
for (var prop in b || (b = {}))
|
|
4590
|
-
__hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4591
|
-
if (__getOwnPropSymbols$d)
|
|
4592
|
-
for (var prop of __getOwnPropSymbols$d(b))
|
|
4593
|
-
__propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4594
|
-
return a;
|
|
4595
|
-
}, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
4596
4382
|
const toggleStyleActionImplementation = ({
|
|
4597
4383
|
context,
|
|
4598
4384
|
action
|
|
@@ -4602,14 +4388,16 @@ const toggleStyleActionImplementation = ({
|
|
|
4602
4388
|
style: action.style
|
|
4603
4389
|
}) ? removeStyleActionImplementation({
|
|
4604
4390
|
context,
|
|
4605
|
-
action:
|
|
4391
|
+
action: {
|
|
4392
|
+
...action,
|
|
4606
4393
|
type: "style.remove"
|
|
4607
|
-
}
|
|
4394
|
+
}
|
|
4608
4395
|
}) : addStyleActionImplementation({
|
|
4609
4396
|
context,
|
|
4610
|
-
action:
|
|
4397
|
+
action: {
|
|
4398
|
+
...action,
|
|
4611
4399
|
type: "style.add"
|
|
4612
|
-
}
|
|
4400
|
+
}
|
|
4613
4401
|
});
|
|
4614
4402
|
}, removeStyleActionImplementation = ({
|
|
4615
4403
|
context,
|
|
@@ -4656,14 +4444,6 @@ function isStyleActive({
|
|
|
4656
4444
|
})];
|
|
4657
4445
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
4658
4446
|
}
|
|
4659
|
-
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) => {
|
|
4660
|
-
for (var prop in b || (b = {}))
|
|
4661
|
-
__hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4662
|
-
if (__getOwnPropSymbols$c)
|
|
4663
|
-
for (var prop of __getOwnPropSymbols$c(b))
|
|
4664
|
-
__propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4665
|
-
return a;
|
|
4666
|
-
};
|
|
4667
4447
|
const debug$6 = debugWithName("API:editable");
|
|
4668
4448
|
function createEditableAPI(editor, editorActor) {
|
|
4669
4449
|
const types2 = editorActor.getSnapshot().context.schema;
|
|
@@ -4726,7 +4506,9 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4726
4506
|
return console.warn(err), !1;
|
|
4727
4507
|
}
|
|
4728
4508
|
},
|
|
4729
|
-
marks: () =>
|
|
4509
|
+
marks: () => ({
|
|
4510
|
+
...slate.Editor.marks(editor) || {}
|
|
4511
|
+
}).marks || [],
|
|
4730
4512
|
undo: () => editor.undo(),
|
|
4731
4513
|
redo: () => editor.redo(),
|
|
4732
4514
|
select: (selection) => {
|
|
@@ -4748,7 +4530,6 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4748
4530
|
}
|
|
4749
4531
|
},
|
|
4750
4532
|
insertChild: (type, value) => {
|
|
4751
|
-
var _a, _b, _c;
|
|
4752
4533
|
if (type.name !== types2.span.name)
|
|
4753
4534
|
return editorActor.send({
|
|
4754
4535
|
type: "behavior event",
|
|
@@ -4760,7 +4541,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4760
4541
|
}
|
|
4761
4542
|
},
|
|
4762
4543
|
editor
|
|
4763
|
-
}),
|
|
4544
|
+
}), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path ?? [];
|
|
4764
4545
|
if (!editor.selection)
|
|
4765
4546
|
throw new Error("The editor has no selection");
|
|
4766
4547
|
const [focusBlock] = Array.from(slate.Editor.nodes(editor, {
|
|
@@ -4774,10 +4555,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4774
4555
|
const child = toSlateValue([{
|
|
4775
4556
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4776
4557
|
_type: types2.block.name,
|
|
4777
|
-
children: [
|
|
4558
|
+
children: [{
|
|
4778
4559
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4779
|
-
_type: type.name
|
|
4780
|
-
|
|
4560
|
+
_type: type.name,
|
|
4561
|
+
...value || {}
|
|
4562
|
+
}]
|
|
4781
4563
|
}], {
|
|
4782
4564
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
4783
4565
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
@@ -4787,30 +4569,27 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4787
4569
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
4788
4570
|
select: !0,
|
|
4789
4571
|
at: editor.selection
|
|
4790
|
-
}), editor.onChange(),
|
|
4572
|
+
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path || [];
|
|
4791
4573
|
},
|
|
4792
|
-
insertBlock: (type, value) => {
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
type: "
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
name: type.name,
|
|
4800
|
-
value
|
|
4801
|
-
},
|
|
4802
|
-
placement: "auto"
|
|
4574
|
+
insertBlock: (type, value) => (editorActor.send({
|
|
4575
|
+
type: "behavior event",
|
|
4576
|
+
behaviorEvent: {
|
|
4577
|
+
type: "insert.block object",
|
|
4578
|
+
blockObject: {
|
|
4579
|
+
name: type.name,
|
|
4580
|
+
value
|
|
4803
4581
|
},
|
|
4804
|
-
|
|
4805
|
-
}
|
|
4806
|
-
|
|
4582
|
+
placement: "auto"
|
|
4583
|
+
},
|
|
4584
|
+
editor
|
|
4585
|
+
}), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path ?? []),
|
|
4807
4586
|
hasBlockStyle: (style) => {
|
|
4808
4587
|
try {
|
|
4809
4588
|
return isStyleActive({
|
|
4810
4589
|
editor,
|
|
4811
4590
|
style
|
|
4812
4591
|
});
|
|
4813
|
-
} catch
|
|
4592
|
+
} catch {
|
|
4814
4593
|
return !1;
|
|
4815
4594
|
}
|
|
4816
4595
|
},
|
|
@@ -4820,7 +4599,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4820
4599
|
editor,
|
|
4821
4600
|
listItem
|
|
4822
4601
|
});
|
|
4823
|
-
} catch
|
|
4602
|
+
} catch {
|
|
4824
4603
|
return !1;
|
|
4825
4604
|
}
|
|
4826
4605
|
},
|
|
@@ -4865,12 +4644,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4865
4644
|
match: (n) => n._key === element._key
|
|
4866
4645
|
}) || [])[0] || [void 0];
|
|
4867
4646
|
node = slateReact.ReactEditor.toDOMNode(editor, item);
|
|
4868
|
-
} catch
|
|
4647
|
+
} catch {
|
|
4869
4648
|
}
|
|
4870
4649
|
return node;
|
|
4871
4650
|
},
|
|
4872
4651
|
activeAnnotations: () => {
|
|
4873
|
-
var _a;
|
|
4874
4652
|
if (!editor.selection || editor.selection.focus.path.length < 2)
|
|
4875
4653
|
return [];
|
|
4876
4654
|
try {
|
|
@@ -4882,12 +4660,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4882
4660
|
const [block] = slate.Editor.node(editor, path, {
|
|
4883
4661
|
depth: 1
|
|
4884
4662
|
});
|
|
4885
|
-
editor.isTextBlock(block) &&
|
|
4663
|
+
editor.isTextBlock(block) && block.markDefs?.forEach((def) => {
|
|
4886
4664
|
slate.Text.isText(span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
|
|
4887
|
-
})
|
|
4665
|
+
});
|
|
4888
4666
|
}
|
|
4889
4667
|
return activeAnnotations;
|
|
4890
|
-
} catch
|
|
4668
|
+
} catch {
|
|
4891
4669
|
return [];
|
|
4892
4670
|
}
|
|
4893
4671
|
},
|
|
@@ -4909,7 +4687,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4909
4687
|
type: "annotation.add",
|
|
4910
4688
|
annotation: {
|
|
4911
4689
|
name: type.name,
|
|
4912
|
-
value: value
|
|
4690
|
+
value: value ?? {}
|
|
4913
4691
|
},
|
|
4914
4692
|
editor
|
|
4915
4693
|
}
|
|
@@ -4922,7 +4700,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4922
4700
|
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
4923
4701
|
throw new Error("Invalid range");
|
|
4924
4702
|
if (range) {
|
|
4925
|
-
if (!
|
|
4703
|
+
if (!options?.mode || options?.mode === "selected") {
|
|
4926
4704
|
debug$6("Deleting content in selection"), slate.Transforms.delete(editor, {
|
|
4927
4705
|
at: range,
|
|
4928
4706
|
hanging: !0,
|
|
@@ -4930,11 +4708,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4930
4708
|
}), editor.onChange();
|
|
4931
4709
|
return;
|
|
4932
4710
|
}
|
|
4933
|
-
|
|
4711
|
+
options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
4934
4712
|
at: range,
|
|
4935
4713
|
voids: !0,
|
|
4936
4714
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
4937
|
-
})),
|
|
4715
|
+
})), options?.mode === "children" && (debug$6("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
4938
4716
|
at: range,
|
|
4939
4717
|
voids: !0,
|
|
4940
4718
|
match: (node) => node._type === types2.span.name || // Text children
|
|
@@ -4991,26 +4769,15 @@ function isAnnotationActive({
|
|
|
4991
4769
|
at: editor.selection,
|
|
4992
4770
|
match: (node) => slate.Text.isText(node)
|
|
4993
4771
|
})];
|
|
4994
|
-
if (spans.length === 0 || spans.some(([span]) =>
|
|
4995
|
-
var _a;
|
|
4996
|
-
return !types.isPortableTextSpan(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
|
|
4997
|
-
})) return !1;
|
|
4772
|
+
if (spans.length === 0 || spans.some(([span]) => !types.isPortableTextSpan(span) || !span.marks || span.marks?.length === 0)) return !1;
|
|
4998
4773
|
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
4999
4774
|
const [block] = slate.Editor.node(editor, path, {
|
|
5000
4775
|
depth: 1
|
|
5001
4776
|
});
|
|
5002
4777
|
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
5003
4778
|
}, []);
|
|
5004
|
-
return spans.every(([span]) =>
|
|
5005
|
-
|
|
5006
|
-
if (!types.isPortableTextSpan(span)) return !1;
|
|
5007
|
-
const spanMarkDefs = (_a = span.marks) == null ? void 0 : _a.map((markKey) => {
|
|
5008
|
-
var _a2;
|
|
5009
|
-
return (_a2 = selectionMarkDefs.find((def) => (def == null ? void 0 : def._key) === markKey)) == null ? void 0 : _a2._type;
|
|
5010
|
-
});
|
|
5011
|
-
return spanMarkDefs == null ? void 0 : spanMarkDefs.includes(annotation.name);
|
|
5012
|
-
});
|
|
5013
|
-
} catch (e) {
|
|
4779
|
+
return spans.every(([span]) => types.isPortableTextSpan(span) ? span.marks?.map((markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type)?.includes(annotation.name) : !1);
|
|
4780
|
+
} catch {
|
|
5014
4781
|
return !1;
|
|
5015
4782
|
}
|
|
5016
4783
|
}
|
|
@@ -5018,7 +4785,6 @@ const addAnnotationActionImplementation = ({
|
|
|
5018
4785
|
context,
|
|
5019
4786
|
action
|
|
5020
4787
|
}) => {
|
|
5021
|
-
var _a, _b;
|
|
5022
4788
|
const editor = action.editor, {
|
|
5023
4789
|
selection: originalSelection
|
|
5024
4790
|
} = editor;
|
|
@@ -5036,12 +4802,13 @@ const addAnnotationActionImplementation = ({
|
|
|
5036
4802
|
for (const [block, blockPath] of selectedBlocks) {
|
|
5037
4803
|
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
5038
4804
|
continue;
|
|
5039
|
-
const annotationKey = context.keyGenerator(), markDefs =
|
|
4805
|
+
const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
|
|
5040
4806
|
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (slate.Transforms.setNodes(editor, {
|
|
5041
|
-
markDefs: [...markDefs,
|
|
4807
|
+
markDefs: [...markDefs, {
|
|
5042
4808
|
_type: action.annotation.name,
|
|
5043
|
-
_key: annotationKey
|
|
5044
|
-
|
|
4809
|
+
_key: annotationKey,
|
|
4810
|
+
...action.annotation.value
|
|
4811
|
+
}]
|
|
5045
4812
|
}, {
|
|
5046
4813
|
at: blockPath
|
|
5047
4814
|
}), markDefPath = [{
|
|
@@ -5056,7 +4823,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5056
4823
|
for (const [span, path] of children) {
|
|
5057
4824
|
if (!editor.isTextSpan(span) || !slate.Range.includes(editor.selection, path))
|
|
5058
4825
|
continue;
|
|
5059
|
-
const marks =
|
|
4826
|
+
const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
|
|
5060
4827
|
slate.Transforms.setNodes(editor, {
|
|
5061
4828
|
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
5062
4829
|
}, {
|
|
@@ -5078,7 +4845,6 @@ const addAnnotationActionImplementation = ({
|
|
|
5078
4845
|
}, removeAnnotationActionImplementation = ({
|
|
5079
4846
|
action
|
|
5080
4847
|
}) => {
|
|
5081
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
5082
4848
|
const editor = action.editor;
|
|
5083
4849
|
if (debug$6("Removing annotation", action.annotation.name), !!editor.selection)
|
|
5084
4850
|
if (slate.Range.isCollapsed(editor.selection)) {
|
|
@@ -5087,12 +4853,12 @@ const addAnnotationActionImplementation = ({
|
|
|
5087
4853
|
});
|
|
5088
4854
|
if (!editor.isTextBlock(block))
|
|
5089
4855
|
return;
|
|
5090
|
-
const potentialAnnotations = (
|
|
4856
|
+
const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = slate.Editor.node(editor, editor.selection, {
|
|
5091
4857
|
depth: 2
|
|
5092
4858
|
});
|
|
5093
4859
|
if (!editor.isTextSpan(selectedChild))
|
|
5094
4860
|
return;
|
|
5095
|
-
const annotationToRemove =
|
|
4861
|
+
const annotationToRemove = selectedChild.marks?.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
|
|
5096
4862
|
if (!annotationToRemove)
|
|
5097
4863
|
return;
|
|
5098
4864
|
const previousSpansWithSameAnnotation = [];
|
|
@@ -5100,20 +4866,20 @@ const addAnnotationActionImplementation = ({
|
|
|
5100
4866
|
reverse: !0
|
|
5101
4867
|
}))
|
|
5102
4868
|
if (editor.isTextSpan(child) && slate.Path.isBefore(childPath, selectedChildPath))
|
|
5103
|
-
if (
|
|
4869
|
+
if (child.marks?.includes(annotationToRemove))
|
|
5104
4870
|
previousSpansWithSameAnnotation.push([child, childPath]);
|
|
5105
4871
|
else
|
|
5106
4872
|
break;
|
|
5107
4873
|
const nextSpansWithSameAnnotation = [];
|
|
5108
4874
|
for (const [child, childPath] of slate.Node.children(editor, blockPath))
|
|
5109
4875
|
if (editor.isTextSpan(child) && slate.Path.isAfter(childPath, selectedChildPath))
|
|
5110
|
-
if (
|
|
4876
|
+
if (child.marks?.includes(annotationToRemove))
|
|
5111
4877
|
nextSpansWithSameAnnotation.push([child, childPath]);
|
|
5112
4878
|
else
|
|
5113
4879
|
break;
|
|
5114
4880
|
for (const [child, childPath] of [...previousSpansWithSameAnnotation, [selectedChild, selectedChildPath], ...nextSpansWithSameAnnotation])
|
|
5115
4881
|
slate.Transforms.setNodes(editor, {
|
|
5116
|
-
marks:
|
|
4882
|
+
marks: child.marks?.filter((mark) => mark !== annotationToRemove)
|
|
5117
4883
|
}, {
|
|
5118
4884
|
at: childPath
|
|
5119
4885
|
});
|
|
@@ -5132,10 +4898,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5132
4898
|
for (const [child, childPath] of children) {
|
|
5133
4899
|
if (!editor.isTextSpan(child) || !slate.Range.includes(editor.selection, childPath))
|
|
5134
4900
|
continue;
|
|
5135
|
-
const markDefs =
|
|
5136
|
-
const markDef = markDefs.find((markDef2) => markDef2._key === mark);
|
|
5137
|
-
return (markDef == null ? void 0 : markDef._type) !== action.annotation.name;
|
|
5138
|
-
});
|
|
4901
|
+
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== action.annotation.name);
|
|
5139
4902
|
marksWithoutAnnotation.length !== marks.length && slate.Transforms.setNodes(editor, {
|
|
5140
4903
|
marks: marksWithoutAnnotation
|
|
5141
4904
|
}, {
|
|
@@ -5178,12 +4941,11 @@ function insertBlock({
|
|
|
5178
4941
|
editor,
|
|
5179
4942
|
schema: schema2
|
|
5180
4943
|
}) {
|
|
5181
|
-
var _a;
|
|
5182
4944
|
if (editor.selection) {
|
|
5183
|
-
const [focusBlock, focusBlockPath] =
|
|
4945
|
+
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(editor, {
|
|
5184
4946
|
at: editor.selection.focus.path.slice(0, 1),
|
|
5185
4947
|
match: (n) => !slate.Editor.isEditor(n)
|
|
5186
|
-
}))[0]
|
|
4948
|
+
}))[0] ?? [void 0, void 0];
|
|
5187
4949
|
if (placement === "after") {
|
|
5188
4950
|
const nextPath = [focusBlockPath[0] + 1];
|
|
5189
4951
|
slate.Transforms.insertNodes(editor, block, {
|
|
@@ -5215,22 +4977,15 @@ function insertBlock({
|
|
|
5215
4977
|
});
|
|
5216
4978
|
}
|
|
5217
4979
|
}
|
|
5218
|
-
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) => {
|
|
5219
|
-
for (var prop in b || (b = {}))
|
|
5220
|
-
__hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5221
|
-
if (__getOwnPropSymbols$b)
|
|
5222
|
-
for (var prop of __getOwnPropSymbols$b(b))
|
|
5223
|
-
__propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5224
|
-
return a;
|
|
5225
|
-
};
|
|
5226
4980
|
const insertBlockObjectActionImplementation = ({
|
|
5227
4981
|
context,
|
|
5228
4982
|
action
|
|
5229
4983
|
}) => {
|
|
5230
|
-
const block = toSlateValue([
|
|
4984
|
+
const block = toSlateValue([{
|
|
5231
4985
|
_key: context.keyGenerator(),
|
|
5232
|
-
_type: action.blockObject.name
|
|
5233
|
-
|
|
4986
|
+
_type: action.blockObject.name,
|
|
4987
|
+
...action.blockObject.value ? action.blockObject.value : {}
|
|
4988
|
+
}], {
|
|
5234
4989
|
schemaTypes: context.schema
|
|
5235
4990
|
})[0];
|
|
5236
4991
|
insertBlock({
|
|
@@ -5239,29 +4994,19 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5239
4994
|
editor: action.editor,
|
|
5240
4995
|
schema: context.schema
|
|
5241
4996
|
});
|
|
5242
|
-
}
|
|
5243
|
-
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) => {
|
|
5244
|
-
for (var prop in b || (b = {}))
|
|
5245
|
-
__hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5246
|
-
if (__getOwnPropSymbols$a)
|
|
5247
|
-
for (var prop of __getOwnPropSymbols$a(b))
|
|
5248
|
-
__propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5249
|
-
return a;
|
|
5250
|
-
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
5251
|
-
const insertBreakActionImplementation = ({
|
|
4997
|
+
}, insertBreakActionImplementation = ({
|
|
5252
4998
|
context,
|
|
5253
4999
|
action
|
|
5254
5000
|
}) => {
|
|
5255
|
-
var _a, _b, _c, _d, _e;
|
|
5256
5001
|
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
5257
5002
|
if (!editor.selection)
|
|
5258
5003
|
return;
|
|
5259
|
-
const [focusSpan] =
|
|
5004
|
+
const [focusSpan] = Array.from(slate.Editor.nodes(editor, {
|
|
5260
5005
|
mode: "lowest",
|
|
5261
5006
|
at: editor.selection.focus,
|
|
5262
5007
|
match: (n) => editor.isTextSpan(n),
|
|
5263
5008
|
voids: !1
|
|
5264
|
-
}))[0]
|
|
5009
|
+
}))[0] ?? [void 0], focusDecorators = focusSpan?.marks?.filter((mark) => schema2.decorators.some((decorator) => decorator.value === mark)) ?? [], focusAnnotations = focusSpan?.marks?.filter((mark) => !schema2.decorators.some((decorator) => decorator.value === mark)) ?? [], anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
5265
5010
|
if (editor.isTextBlock(focusBlock)) {
|
|
5266
5011
|
const [start, end] = slate.Range.edges(editor.selection), lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual__default.default(start, {
|
|
5267
5012
|
path: [...focusBlockPath, focusBlock.children.length - 1],
|
|
@@ -5300,7 +5045,6 @@ const insertBreakActionImplementation = ({
|
|
|
5300
5045
|
const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0];
|
|
5301
5046
|
if (!atTheStartOfBlock && !atTheEndOfBlock && !selectionAcrossBlocks) {
|
|
5302
5047
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
5303
|
-
var _a2;
|
|
5304
5048
|
if (!editor.selection)
|
|
5305
5049
|
return;
|
|
5306
5050
|
slate.Transforms.splitNodes(editor, {
|
|
@@ -5323,28 +5067,20 @@ const insertBreakActionImplementation = ({
|
|
|
5323
5067
|
for (const [child, childPath] of children) {
|
|
5324
5068
|
if (!editor.isTextSpan(child))
|
|
5325
5069
|
continue;
|
|
5326
|
-
const marks =
|
|
5070
|
+
const marks = child.marks ?? [];
|
|
5327
5071
|
for (const mark of marks)
|
|
5328
|
-
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) =>
|
|
5329
|
-
|
|
5330
|
-
return (_a3 = prevNodeSpan.marks) == null ? void 0 : _a3.includes(mark);
|
|
5331
|
-
}) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
5332
|
-
const newMarks = marks.map((mark) => {
|
|
5333
|
-
var _a3;
|
|
5334
|
-
return (_a3 = newMarkDefKeys.get(mark)) != null ? _a3 : mark;
|
|
5335
|
-
});
|
|
5072
|
+
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
5073
|
+
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
5336
5074
|
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
5337
5075
|
marks: newMarks
|
|
5338
5076
|
}, {
|
|
5339
5077
|
at: childPath
|
|
5340
5078
|
});
|
|
5341
5079
|
}
|
|
5342
|
-
const newMarkDefs = nextNode.markDefs.map((markDef) => {
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
});
|
|
5347
|
-
});
|
|
5080
|
+
const newMarkDefs = nextNode.markDefs.map((markDef) => ({
|
|
5081
|
+
...markDef,
|
|
5082
|
+
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
5083
|
+
}));
|
|
5348
5084
|
isEqual__default.default(nextNode.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
5349
5085
|
markDefs: newMarkDefs
|
|
5350
5086
|
}, {
|
|
@@ -5365,24 +5101,15 @@ const insertBreakActionImplementation = ({
|
|
|
5365
5101
|
}) => {
|
|
5366
5102
|
insertBreakActionImplementation({
|
|
5367
5103
|
context,
|
|
5368
|
-
action:
|
|
5104
|
+
action: {
|
|
5105
|
+
...action,
|
|
5369
5106
|
type: "insert.break"
|
|
5370
|
-
}
|
|
5107
|
+
}
|
|
5371
5108
|
});
|
|
5372
|
-
}
|
|
5373
|
-
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) => {
|
|
5374
|
-
for (var prop in b || (b = {}))
|
|
5375
|
-
__hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5376
|
-
if (__getOwnPropSymbols$9)
|
|
5377
|
-
for (var prop of __getOwnPropSymbols$9(b))
|
|
5378
|
-
__propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5379
|
-
return a;
|
|
5380
|
-
};
|
|
5381
|
-
const insertInlineObjectActionImplementation = ({
|
|
5109
|
+
}, insertInlineObjectActionImplementation = ({
|
|
5382
5110
|
context,
|
|
5383
5111
|
action
|
|
5384
5112
|
}) => {
|
|
5385
|
-
var _a, _b;
|
|
5386
5113
|
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
5387
5114
|
console.error("Unable to insert unknown inline object");
|
|
5388
5115
|
return;
|
|
@@ -5391,77 +5118,60 @@ const insertInlineObjectActionImplementation = ({
|
|
|
5391
5118
|
console.error("Unable to insert inline object without selection");
|
|
5392
5119
|
return;
|
|
5393
5120
|
}
|
|
5394
|
-
const [focusTextBlock] =
|
|
5121
|
+
const [focusTextBlock] = Array.from(slate.Editor.nodes(action.editor, {
|
|
5395
5122
|
at: action.editor.selection.focus.path,
|
|
5396
5123
|
match: (node) => action.editor.isTextBlock(node)
|
|
5397
|
-
})).at(0)
|
|
5124
|
+
})).at(0) ?? [void 0, void 0];
|
|
5398
5125
|
if (!focusTextBlock) {
|
|
5399
5126
|
console.error("Unable to perform action without focus text block");
|
|
5400
5127
|
return;
|
|
5401
5128
|
}
|
|
5402
|
-
const
|
|
5129
|
+
const child = toSlateValue([{
|
|
5403
5130
|
_type: context.schema.block.name,
|
|
5404
5131
|
_key: context.keyGenerator(),
|
|
5405
|
-
children: [
|
|
5132
|
+
children: [{
|
|
5406
5133
|
_type: action.inlineObject.name,
|
|
5407
|
-
_key: context.keyGenerator()
|
|
5408
|
-
|
|
5134
|
+
_key: context.keyGenerator(),
|
|
5135
|
+
...action.inlineObject.value ?? {}
|
|
5136
|
+
}]
|
|
5409
5137
|
}], {
|
|
5410
5138
|
schemaTypes: context.schema
|
|
5411
|
-
}).at(0)
|
|
5139
|
+
}).at(0)?.children.at(0);
|
|
5412
5140
|
if (!child) {
|
|
5413
5141
|
console.error("Unable to insert inline object");
|
|
5414
5142
|
return;
|
|
5415
5143
|
}
|
|
5416
5144
|
slate.Transforms.insertNodes(action.editor, child);
|
|
5417
|
-
}
|
|
5418
|
-
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) => {
|
|
5419
|
-
for (var prop in b || (b = {}))
|
|
5420
|
-
__hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5421
|
-
if (__getOwnPropSymbols$8)
|
|
5422
|
-
for (var prop of __getOwnPropSymbols$8(b))
|
|
5423
|
-
__propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5424
|
-
return a;
|
|
5425
|
-
};
|
|
5426
|
-
const insertSpanActionImplementation = ({
|
|
5145
|
+
}, insertSpanActionImplementation = ({
|
|
5427
5146
|
context,
|
|
5428
5147
|
action
|
|
5429
5148
|
}) => {
|
|
5430
|
-
var _a, _b, _c, _d;
|
|
5431
5149
|
if (!action.editor.selection) {
|
|
5432
5150
|
console.error("Unable to perform action without selection", action);
|
|
5433
5151
|
return;
|
|
5434
5152
|
}
|
|
5435
|
-
const [focusBlock, focusBlockPath] =
|
|
5153
|
+
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(action.editor, {
|
|
5436
5154
|
at: action.editor.selection.focus.path,
|
|
5437
5155
|
match: (node) => action.editor.isTextBlock(node)
|
|
5438
|
-
}))[0]
|
|
5156
|
+
}))[0] ?? [void 0, void 0];
|
|
5439
5157
|
if (!focusBlock || !focusBlockPath) {
|
|
5440
5158
|
console.error("Unable to perform action without focus block", action);
|
|
5441
5159
|
return;
|
|
5442
5160
|
}
|
|
5443
|
-
const markDefs =
|
|
5161
|
+
const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
|
|
5444
5162
|
_type: annotation.name,
|
|
5445
|
-
_key: context.keyGenerator()
|
|
5446
|
-
|
|
5163
|
+
_key: context.keyGenerator(),
|
|
5164
|
+
...annotation.value
|
|
5165
|
+
})) : void 0;
|
|
5447
5166
|
annotations && annotations.length > 0 && slate.Transforms.setNodes(action.editor, {
|
|
5448
5167
|
markDefs: [...markDefs, ...annotations]
|
|
5449
5168
|
}), slate.Transforms.insertNodes(action.editor, {
|
|
5450
5169
|
_type: "span",
|
|
5451
5170
|
_key: context.keyGenerator(),
|
|
5452
5171
|
text: action.text,
|
|
5453
|
-
marks: [...
|
|
5172
|
+
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
5454
5173
|
});
|
|
5455
|
-
}
|
|
5456
|
-
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) => {
|
|
5457
|
-
for (var prop in b || (b = {}))
|
|
5458
|
-
__hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5459
|
-
if (__getOwnPropSymbols$7)
|
|
5460
|
-
for (var prop of __getOwnPropSymbols$7(b))
|
|
5461
|
-
__propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5462
|
-
return a;
|
|
5463
|
-
};
|
|
5464
|
-
const textBlockSetActionImplementation = ({
|
|
5174
|
+
}, textBlockSetActionImplementation = ({
|
|
5465
5175
|
action
|
|
5466
5176
|
}) => {
|
|
5467
5177
|
const at = toSlateRange({
|
|
@@ -5474,13 +5184,17 @@ const textBlockSetActionImplementation = ({
|
|
|
5474
5184
|
offset: 0
|
|
5475
5185
|
}
|
|
5476
5186
|
}, action.editor);
|
|
5477
|
-
slate.Transforms.setNodes(action.editor,
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5187
|
+
slate.Transforms.setNodes(action.editor, {
|
|
5188
|
+
...action.style ? {
|
|
5189
|
+
style: action.style
|
|
5190
|
+
} : {},
|
|
5191
|
+
...action.listItem ? {
|
|
5192
|
+
listItem: action.listItem
|
|
5193
|
+
} : {},
|
|
5194
|
+
...action.level ? {
|
|
5195
|
+
level: action.level
|
|
5196
|
+
} : {}
|
|
5197
|
+
}, {
|
|
5484
5198
|
at
|
|
5485
5199
|
});
|
|
5486
5200
|
}, textBlockUnsetActionImplementation = ({
|
|
@@ -5499,16 +5213,7 @@ const textBlockSetActionImplementation = ({
|
|
|
5499
5213
|
slate.Transforms.unsetNodes(action.editor, action.props, {
|
|
5500
5214
|
at
|
|
5501
5215
|
});
|
|
5502
|
-
}
|
|
5503
|
-
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) => {
|
|
5504
|
-
for (var prop in b || (b = {}))
|
|
5505
|
-
__hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5506
|
-
if (__getOwnPropSymbols$6)
|
|
5507
|
-
for (var prop of __getOwnPropSymbols$6(b))
|
|
5508
|
-
__propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5509
|
-
return a;
|
|
5510
|
-
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
5511
|
-
const behaviorActionImplementations = {
|
|
5216
|
+
}, behaviorActionImplementations = {
|
|
5512
5217
|
"annotation.add": addAnnotationActionImplementation,
|
|
5513
5218
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
5514
5219
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
@@ -5597,15 +5302,15 @@ const behaviorActionImplementations = {
|
|
|
5597
5302
|
context,
|
|
5598
5303
|
action
|
|
5599
5304
|
}) => {
|
|
5600
|
-
var _a, _b, _c, _d;
|
|
5601
5305
|
const block = toSlateValue([{
|
|
5602
5306
|
_key: context.keyGenerator(),
|
|
5603
5307
|
_type: context.schema.block.name,
|
|
5604
|
-
style:
|
|
5308
|
+
style: context.schema.styles[0].value ?? "normal",
|
|
5605
5309
|
markDefs: [],
|
|
5606
|
-
children:
|
|
5310
|
+
children: action.textBlock?.children?.map((child) => ({
|
|
5311
|
+
...child,
|
|
5607
5312
|
_key: context.keyGenerator()
|
|
5608
|
-
}))
|
|
5313
|
+
})) ?? [{
|
|
5609
5314
|
_type: context.schema.span.name,
|
|
5610
5315
|
_key: context.keyGenerator(),
|
|
5611
5316
|
text: ""
|
|
@@ -5698,7 +5403,11 @@ const behaviorActionImplementations = {
|
|
|
5698
5403
|
action
|
|
5699
5404
|
}) => {
|
|
5700
5405
|
const selection = action.editor.selection;
|
|
5701
|
-
selection && (slate.Transforms.select(action.editor,
|
|
5406
|
+
selection && (slate.Transforms.select(action.editor, {
|
|
5407
|
+
...selection
|
|
5408
|
+
}), action.editor.selection = {
|
|
5409
|
+
...selection
|
|
5410
|
+
});
|
|
5702
5411
|
},
|
|
5703
5412
|
"style.toggle": toggleStyleActionImplementation,
|
|
5704
5413
|
"style.add": addStyleActionImplementation,
|
|
@@ -5970,30 +5679,15 @@ function performDefaultAction({
|
|
|
5970
5679
|
});
|
|
5971
5680
|
}
|
|
5972
5681
|
}
|
|
5973
|
-
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) => {
|
|
5974
|
-
for (var prop in b || (b = {}))
|
|
5975
|
-
__hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5976
|
-
if (__getOwnPropSymbols$5)
|
|
5977
|
-
for (var prop of __getOwnPropSymbols$5(b))
|
|
5978
|
-
__propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5979
|
-
return a;
|
|
5980
|
-
};
|
|
5981
5682
|
function getActiveDecorators({
|
|
5982
5683
|
schema: schema2,
|
|
5983
5684
|
slateEditorInstance
|
|
5984
5685
|
}) {
|
|
5985
|
-
var _a, _b;
|
|
5986
5686
|
const decorators = schema2.decorators.map((decorator) => decorator.value);
|
|
5987
|
-
return (
|
|
5988
|
-
}
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
__hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
5992
|
-
if (__getOwnPropSymbols$4)
|
|
5993
|
-
for (var prop of __getOwnPropSymbols$4(b))
|
|
5994
|
-
__propIsEnum$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
5995
|
-
return a;
|
|
5996
|
-
}, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
5687
|
+
return ({
|
|
5688
|
+
...slate.Editor.marks(slateEditorInstance) ?? {}
|
|
5689
|
+
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
5690
|
+
}
|
|
5997
5691
|
const editorMachine = xstate.setup({
|
|
5998
5692
|
types: {
|
|
5999
5693
|
context: {},
|
|
@@ -6048,11 +5742,11 @@ const editorMachine = xstate.setup({
|
|
|
6048
5742
|
event,
|
|
6049
5743
|
enqueue
|
|
6050
5744
|
}) => {
|
|
6051
|
-
var _a;
|
|
6052
5745
|
xstate.assertEvent(event, ["behavior event"]);
|
|
6053
|
-
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 :
|
|
5746
|
+
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
5747
|
+
...event.behaviorEvent,
|
|
6054
5748
|
editor: event.editor
|
|
6055
|
-
}
|
|
5749
|
+
}, eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
6056
5750
|
if (eventBehaviors.length === 0) {
|
|
6057
5751
|
if (!defaultAction)
|
|
6058
5752
|
return;
|
|
@@ -6092,7 +5786,7 @@ const editorMachine = xstate.setup({
|
|
|
6092
5786
|
actionIntends
|
|
6093
5787
|
});
|
|
6094
5788
|
if (behaviorOverwritten) {
|
|
6095
|
-
|
|
5789
|
+
event.nativeEvent?.preventDefault();
|
|
6096
5790
|
break;
|
|
6097
5791
|
}
|
|
6098
5792
|
}
|
|
@@ -6111,19 +5805,16 @@ const editorMachine = xstate.setup({
|
|
|
6111
5805
|
id: "editor",
|
|
6112
5806
|
context: ({
|
|
6113
5807
|
input
|
|
6114
|
-
}) => {
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
value: input.value
|
|
6125
|
-
};
|
|
6126
|
-
},
|
|
5808
|
+
}) => ({
|
|
5809
|
+
behaviors: input.behaviors ?? behavior_core.coreBehaviors,
|
|
5810
|
+
keyGenerator: input.keyGenerator,
|
|
5811
|
+
pendingEvents: [],
|
|
5812
|
+
schema: input.schema,
|
|
5813
|
+
selection: null,
|
|
5814
|
+
initialReadOnly: input.readOnly ?? !1,
|
|
5815
|
+
maxBlocks: input.maxBlocks,
|
|
5816
|
+
value: input.value
|
|
5817
|
+
}),
|
|
6127
5818
|
on: {
|
|
6128
5819
|
unset: {
|
|
6129
5820
|
actions: xstate.emit(({
|
|
@@ -6206,9 +5897,10 @@ const editorMachine = xstate.setup({
|
|
|
6206
5897
|
}) => {
|
|
6207
5898
|
slate.Editor.withoutNormalizing(event.editor, () => {
|
|
6208
5899
|
for (const actionIntend of event.actionIntends) {
|
|
6209
|
-
const action =
|
|
5900
|
+
const action = {
|
|
5901
|
+
...actionIntend,
|
|
6210
5902
|
editor: event.editor
|
|
6211
|
-
}
|
|
5903
|
+
};
|
|
6212
5904
|
performAction({
|
|
6213
5905
|
context,
|
|
6214
5906
|
action
|
|
@@ -6423,10 +6115,9 @@ function useCreateEditor(config) {
|
|
|
6423
6115
|
return $[4] !== editorActor ? (t3 = createEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
6424
6116
|
}
|
|
6425
6117
|
function editorConfigToMachineInput(config) {
|
|
6426
|
-
var _a;
|
|
6427
6118
|
return {
|
|
6428
6119
|
behaviors: config.behaviors,
|
|
6429
|
-
keyGenerator:
|
|
6120
|
+
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
6430
6121
|
maxBlocks: config.maxBlocks,
|
|
6431
6122
|
readOnly: config.readOnly,
|
|
6432
6123
|
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
@@ -6476,16 +6167,13 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
6476
6167
|
let t2;
|
|
6477
6168
|
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
6478
6169
|
}
|
|
6479
|
-
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) => {
|
|
6480
|
-
for (var prop in b || (b = {}))
|
|
6481
|
-
__hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6482
|
-
if (__getOwnPropSymbols$3)
|
|
6483
|
-
for (var prop of __getOwnPropSymbols$3(b))
|
|
6484
|
-
__propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6485
|
-
return a;
|
|
6486
|
-
}, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)), __publicField = (obj, key, value) => __defNormalProp$3(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
6487
6170
|
const debug$4 = debugWithName("component:PortableTextEditor");
|
|
6488
6171
|
class PortableTextEditor extends React.Component {
|
|
6172
|
+
static displayName = "PortableTextEditor";
|
|
6173
|
+
/**
|
|
6174
|
+
* An observable of all the editor changes.
|
|
6175
|
+
*/
|
|
6176
|
+
change$ = new rxjs.Subject();
|
|
6489
6177
|
/**
|
|
6490
6178
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
6491
6179
|
*/
|
|
@@ -6496,11 +6184,8 @@ class PortableTextEditor extends React.Component {
|
|
|
6496
6184
|
* The editor API (currently implemented with Slate).
|
|
6497
6185
|
*/
|
|
6498
6186
|
constructor(props) {
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
this.editor._internal.editable = __spreadValues$3(__spreadValues$3({}, this.editor._internal.editable), editable);
|
|
6502
|
-
}), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6503
|
-
keyGenerator: (_a = props.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6187
|
+
super(props), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6188
|
+
keyGenerator: props.keyGenerator ?? defaultKeyGenerator,
|
|
6504
6189
|
schema: props.schemaType,
|
|
6505
6190
|
initialValue: props.value,
|
|
6506
6191
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
@@ -6508,13 +6193,12 @@ class PortableTextEditor extends React.Component {
|
|
|
6508
6193
|
}), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
|
|
6509
6194
|
}
|
|
6510
6195
|
componentDidUpdate(prevProps) {
|
|
6511
|
-
var _a;
|
|
6512
6196
|
!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({
|
|
6513
6197
|
type: "update schema",
|
|
6514
6198
|
schema: this.schemaTypes
|
|
6515
6199
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
6516
6200
|
type: "update readOnly",
|
|
6517
|
-
readOnly:
|
|
6201
|
+
readOnly: this.props.readOnly ?? !1
|
|
6518
6202
|
}), this.props.maxBlocks !== prevProps.maxBlocks && this.editor._internal.editorActor.send({
|
|
6519
6203
|
type: "update maxBlocks",
|
|
6520
6204
|
maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
|
|
@@ -6523,9 +6207,14 @@ class PortableTextEditor extends React.Component {
|
|
|
6523
6207
|
value: this.props.value
|
|
6524
6208
|
}), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
|
|
6525
6209
|
}
|
|
6210
|
+
setEditable = (editable) => {
|
|
6211
|
+
this.editor._internal.editable = {
|
|
6212
|
+
...this.editor._internal.editable,
|
|
6213
|
+
...editable
|
|
6214
|
+
};
|
|
6215
|
+
};
|
|
6526
6216
|
render() {
|
|
6527
|
-
|
|
6528
|
-
const legacyPatches = this.props.editor ? void 0 : (_a = this.props.incomingPatches$) != null ? _a : this.props.patches$;
|
|
6217
|
+
const legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
|
|
6529
6218
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6530
6219
|
legacyPatches ? /* @__PURE__ */ jsxRuntime.jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
|
|
6531
6220
|
/* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
|
|
@@ -6535,105 +6224,65 @@ class PortableTextEditor extends React.Component {
|
|
|
6535
6224
|
/* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
|
|
6536
6225
|
] });
|
|
6537
6226
|
}
|
|
6227
|
+
// Static API methods
|
|
6228
|
+
static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
|
|
6229
|
+
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6230
|
+
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6231
|
+
static blur = (editor) => {
|
|
6232
|
+
debug$4("Host blurred"), editor.editable?.blur();
|
|
6233
|
+
};
|
|
6234
|
+
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6235
|
+
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6236
|
+
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6237
|
+
static focus = (editor) => {
|
|
6238
|
+
debug$4("Host requesting focus"), editor.editable?.focus();
|
|
6239
|
+
};
|
|
6240
|
+
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6241
|
+
static focusChild = (editor) => editor.editable?.focusChild();
|
|
6242
|
+
static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
|
|
6243
|
+
static getValue = (editor) => editor.editable?.getValue();
|
|
6244
|
+
static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
|
|
6245
|
+
static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
|
|
6246
|
+
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6247
|
+
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6248
|
+
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6249
|
+
static insertChild = (editor, type, value) => (debug$4("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6250
|
+
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6251
|
+
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6252
|
+
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
6253
|
+
static isObjectPath = (_editor, path) => {
|
|
6254
|
+
if (!path || !Array.isArray(path)) return !1;
|
|
6255
|
+
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6256
|
+
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6257
|
+
};
|
|
6258
|
+
static marks = (editor) => editor.editable?.marks();
|
|
6259
|
+
static select = (editor, selection) => {
|
|
6260
|
+
debug$4("Host setting selection", selection), editor.editable?.select(selection);
|
|
6261
|
+
};
|
|
6262
|
+
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6263
|
+
static toggleBlockStyle = (editor, blockStyle) => (debug$4("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6264
|
+
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6265
|
+
static toggleMark = (editor, mark) => {
|
|
6266
|
+
debug$4("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6267
|
+
};
|
|
6268
|
+
static getFragment = (editor) => (debug$4("Host getting fragment"), editor.editable?.getFragment());
|
|
6269
|
+
static undo = (editor) => {
|
|
6270
|
+
debug$4("Host undoing"), editor.editable?.undo();
|
|
6271
|
+
};
|
|
6272
|
+
static redo = (editor) => {
|
|
6273
|
+
debug$4("Host redoing"), editor.editable?.redo();
|
|
6274
|
+
};
|
|
6275
|
+
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6538
6276
|
}
|
|
6539
|
-
__publicField(PortableTextEditor, "displayName", "PortableTextEditor"), // Static API methods
|
|
6540
|
-
__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) => {
|
|
6541
|
-
var _a;
|
|
6542
|
-
return (_a = editor.editable) == null ? void 0 : _a.addAnnotation(type, value);
|
|
6543
|
-
}), __publicField(PortableTextEditor, "blur", (editor) => {
|
|
6544
|
-
var _a;
|
|
6545
|
-
debug$4("Host blurred"), (_a = editor.editable) == null || _a.blur();
|
|
6546
|
-
}), __publicField(PortableTextEditor, "delete", (editor, selection, options) => {
|
|
6547
|
-
var _a;
|
|
6548
|
-
return (_a = editor.editable) == null ? void 0 : _a.delete(selection, options);
|
|
6549
|
-
}), __publicField(PortableTextEditor, "findDOMNode", (editor, element) => {
|
|
6550
|
-
var _a;
|
|
6551
|
-
return (_a = editor.editable) == null ? void 0 : _a.findDOMNode(element);
|
|
6552
|
-
}), __publicField(PortableTextEditor, "findByPath", (editor, path) => {
|
|
6553
|
-
var _a;
|
|
6554
|
-
return ((_a = editor.editable) == null ? void 0 : _a.findByPath(path)) || [];
|
|
6555
|
-
}), __publicField(PortableTextEditor, "focus", (editor) => {
|
|
6556
|
-
var _a;
|
|
6557
|
-
debug$4("Host requesting focus"), (_a = editor.editable) == null || _a.focus();
|
|
6558
|
-
}), __publicField(PortableTextEditor, "focusBlock", (editor) => {
|
|
6559
|
-
var _a;
|
|
6560
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusBlock();
|
|
6561
|
-
}), __publicField(PortableTextEditor, "focusChild", (editor) => {
|
|
6562
|
-
var _a;
|
|
6563
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusChild();
|
|
6564
|
-
}), __publicField(PortableTextEditor, "getSelection", (editor) => editor.editable ? editor.editable.getSelection() : null), __publicField(PortableTextEditor, "getValue", (editor) => {
|
|
6565
|
-
var _a;
|
|
6566
|
-
return (_a = editor.editable) == null ? void 0 : _a.getValue();
|
|
6567
|
-
}), __publicField(PortableTextEditor, "hasBlockStyle", (editor, blockStyle) => {
|
|
6568
|
-
var _a;
|
|
6569
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasBlockStyle(blockStyle);
|
|
6570
|
-
}), __publicField(PortableTextEditor, "hasListStyle", (editor, listStyle) => {
|
|
6571
|
-
var _a;
|
|
6572
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasListStyle(listStyle);
|
|
6573
|
-
}), __publicField(PortableTextEditor, "isCollapsedSelection", (editor) => {
|
|
6574
|
-
var _a;
|
|
6575
|
-
return (_a = editor.editable) == null ? void 0 : _a.isCollapsedSelection();
|
|
6576
|
-
}), __publicField(PortableTextEditor, "isExpandedSelection", (editor) => {
|
|
6577
|
-
var _a;
|
|
6578
|
-
return (_a = editor.editable) == null ? void 0 : _a.isExpandedSelection();
|
|
6579
|
-
}), __publicField(PortableTextEditor, "isMarkActive", (editor, mark) => {
|
|
6580
|
-
var _a;
|
|
6581
|
-
return (_a = editor.editable) == null ? void 0 : _a.isMarkActive(mark);
|
|
6582
|
-
}), __publicField(PortableTextEditor, "insertChild", (editor, type, value) => {
|
|
6583
|
-
var _a;
|
|
6584
|
-
return debug$4("Host inserting child"), (_a = editor.editable) == null ? void 0 : _a.insertChild(type, value);
|
|
6585
|
-
}), __publicField(PortableTextEditor, "insertBlock", (editor, type, value) => {
|
|
6586
|
-
var _a;
|
|
6587
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBlock(type, value);
|
|
6588
|
-
}), __publicField(PortableTextEditor, "insertBreak", (editor) => {
|
|
6589
|
-
var _a;
|
|
6590
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBreak();
|
|
6591
|
-
}), __publicField(PortableTextEditor, "isVoid", (editor, element) => {
|
|
6592
|
-
var _a;
|
|
6593
|
-
return (_a = editor.editable) == null ? void 0 : _a.isVoid(element);
|
|
6594
|
-
}), __publicField(PortableTextEditor, "isObjectPath", (_editor, path) => {
|
|
6595
|
-
if (!path || !Array.isArray(path)) return !1;
|
|
6596
|
-
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6597
|
-
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6598
|
-
}), __publicField(PortableTextEditor, "marks", (editor) => {
|
|
6599
|
-
var _a;
|
|
6600
|
-
return (_a = editor.editable) == null ? void 0 : _a.marks();
|
|
6601
|
-
}), __publicField(PortableTextEditor, "select", (editor, selection) => {
|
|
6602
|
-
var _a;
|
|
6603
|
-
debug$4("Host setting selection", selection), (_a = editor.editable) == null || _a.select(selection);
|
|
6604
|
-
}), __publicField(PortableTextEditor, "removeAnnotation", (editor, type) => {
|
|
6605
|
-
var _a;
|
|
6606
|
-
return (_a = editor.editable) == null ? void 0 : _a.removeAnnotation(type);
|
|
6607
|
-
}), __publicField(PortableTextEditor, "toggleBlockStyle", (editor, blockStyle) => {
|
|
6608
|
-
var _a;
|
|
6609
|
-
return debug$4("Host is toggling block style"), (_a = editor.editable) == null ? void 0 : _a.toggleBlockStyle(blockStyle);
|
|
6610
|
-
}), __publicField(PortableTextEditor, "toggleList", (editor, listStyle) => {
|
|
6611
|
-
var _a;
|
|
6612
|
-
return (_a = editor.editable) == null ? void 0 : _a.toggleList(listStyle);
|
|
6613
|
-
}), __publicField(PortableTextEditor, "toggleMark", (editor, mark) => {
|
|
6614
|
-
var _a;
|
|
6615
|
-
debug$4("Host toggling mark", mark), (_a = editor.editable) == null || _a.toggleMark(mark);
|
|
6616
|
-
}), __publicField(PortableTextEditor, "getFragment", (editor) => {
|
|
6617
|
-
var _a;
|
|
6618
|
-
return debug$4("Host getting fragment"), (_a = editor.editable) == null ? void 0 : _a.getFragment();
|
|
6619
|
-
}), __publicField(PortableTextEditor, "undo", (editor) => {
|
|
6620
|
-
var _a;
|
|
6621
|
-
debug$4("Host undoing"), (_a = editor.editable) == null || _a.undo();
|
|
6622
|
-
}), __publicField(PortableTextEditor, "redo", (editor) => {
|
|
6623
|
-
var _a;
|
|
6624
|
-
debug$4("Host redoing"), (_a = editor.editable) == null || _a.redo();
|
|
6625
|
-
}), __publicField(PortableTextEditor, "isSelectionsOverlapping", (editor, selectionA, selectionB) => {
|
|
6626
|
-
var _a;
|
|
6627
|
-
return (_a = editor.editable) == null ? void 0 : _a.isSelectionsOverlapping(selectionA, selectionB);
|
|
6628
|
-
});
|
|
6629
6277
|
function RoutePatchesObservableToEditorActor(props) {
|
|
6630
6278
|
const $ = reactCompilerRuntime.c(4);
|
|
6631
6279
|
let t0, t1;
|
|
6632
6280
|
return $[0] !== props.editorActor || $[1] !== props.patches$ ? (t0 = () => {
|
|
6633
6281
|
const subscription = props.patches$.subscribe((payload) => {
|
|
6634
|
-
props.editorActor.send(
|
|
6635
|
-
type: "patches"
|
|
6636
|
-
|
|
6282
|
+
props.editorActor.send({
|
|
6283
|
+
type: "patches",
|
|
6284
|
+
...payload
|
|
6285
|
+
});
|
|
6637
6286
|
});
|
|
6638
6287
|
return () => {
|
|
6639
6288
|
subscription.unsubscribe();
|
|
@@ -6698,9 +6347,10 @@ function RouteEventsToChanges(props) {
|
|
|
6698
6347
|
break bb5;
|
|
6699
6348
|
}
|
|
6700
6349
|
case "error": {
|
|
6701
|
-
handleChange(
|
|
6350
|
+
handleChange({
|
|
6351
|
+
...event,
|
|
6702
6352
|
level: "warning"
|
|
6703
|
-
})
|
|
6353
|
+
});
|
|
6704
6354
|
break bb5;
|
|
6705
6355
|
}
|
|
6706
6356
|
case "annotation.add":
|
|
@@ -6728,14 +6378,6 @@ function RouteEventsToChanges(props) {
|
|
|
6728
6378
|
};
|
|
6729
6379
|
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), React.useEffect(t1, t2), null;
|
|
6730
6380
|
}
|
|
6731
|
-
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) => {
|
|
6732
|
-
for (var prop in b || (b = {}))
|
|
6733
|
-
__hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6734
|
-
if (__getOwnPropSymbols$2)
|
|
6735
|
-
for (var prop of __getOwnPropSymbols$2(b))
|
|
6736
|
-
__propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6737
|
-
return a;
|
|
6738
|
-
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
6739
6381
|
const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
6740
6382
|
const {
|
|
6741
6383
|
editorActor,
|
|
@@ -6747,13 +6389,10 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6747
6389
|
renderDecorator,
|
|
6748
6390
|
renderAnnotation
|
|
6749
6391
|
} = props, spanRef = React.useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = slateReact.useSelected(), [focused, setFocused] = React.useState(!1), [selected, setSelected] = React.useState(!1), block = children.props.parent, path = React.useMemo(() => block ? [{
|
|
6750
|
-
_key: block
|
|
6392
|
+
_key: block?._key
|
|
6751
6393
|
}, "children", {
|
|
6752
6394
|
_key: leaf._key
|
|
6753
|
-
}] : [], [block, leaf._key]), decoratorValues = React.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = React.useMemo(() => uniq__default.default((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = React.useMemo(() => annotationMarks.map((mark_0) =>
|
|
6754
|
-
var _a;
|
|
6755
|
-
return !decoratorValues.includes(mark_0) && ((_a = block == null ? void 0 : block.markDefs) == null ? void 0 : _a.find((def) => def._key === mark_0));
|
|
6756
|
-
}).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
6395
|
+
}] : [], [block, leaf._key]), decoratorValues = React.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = React.useMemo(() => uniq__default.default((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = React.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;
|
|
6757
6396
|
React.useEffect(() => {
|
|
6758
6397
|
if (!shouldTrackSelectionAndFocus) {
|
|
6759
6398
|
setFocused(!1);
|
|
@@ -6860,7 +6499,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6860
6499
|
}
|
|
6861
6500
|
return returnedChildren;
|
|
6862
6501
|
}, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
|
|
6863
|
-
return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span",
|
|
6502
|
+
return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6864
6503
|
};
|
|
6865
6504
|
Leaf.displayName = "Leaf";
|
|
6866
6505
|
const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
@@ -6913,32 +6552,10 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6913
6552
|
}, editor;
|
|
6914
6553
|
};
|
|
6915
6554
|
}
|
|
6916
|
-
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) => {
|
|
6917
|
-
for (var prop in b || (b = {}))
|
|
6918
|
-
__hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6919
|
-
if (__getOwnPropSymbols$1)
|
|
6920
|
-
for (var prop of __getOwnPropSymbols$1(b))
|
|
6921
|
-
__propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6922
|
-
return a;
|
|
6923
|
-
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), __objRest$1 = (source, exclude) => {
|
|
6924
|
-
var target = {};
|
|
6925
|
-
for (var prop in source)
|
|
6926
|
-
__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
6927
|
-
if (source != null && __getOwnPropSymbols$1)
|
|
6928
|
-
for (var prop of __getOwnPropSymbols$1(source))
|
|
6929
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop) && (target[prop] = source[prop]);
|
|
6930
|
-
return target;
|
|
6931
|
-
};
|
|
6932
6555
|
const debug$1 = debugWithName("plugin:withInsertData");
|
|
6933
6556
|
function createWithInsertData(editorActor, schemaTypes) {
|
|
6934
6557
|
return function(editor) {
|
|
6935
|
-
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => {
|
|
6936
|
-
var _a;
|
|
6937
|
-
return editor.isTextBlock(block) ? block.children.map((child) => {
|
|
6938
|
-
var _a2;
|
|
6939
|
-
return child._type === spanTypeName ? child.text : `[${((_a2 = schemaTypes.inlineObjects.find((t) => t.name === child._type)) == null ? void 0 : _a2.title) || "Object"}]`;
|
|
6940
|
-
}).join("") : `[${((_a = schemaTypes.blockObjects.find((t) => t.name === block._type)) == null ? void 0 : _a.title) || "Object"}]`;
|
|
6941
|
-
}).join(`
|
|
6558
|
+
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(`
|
|
6942
6559
|
|
|
6943
6560
|
`);
|
|
6944
6561
|
return editor.setFragmentData = (data, originEvent) => {
|
|
@@ -6976,7 +6593,6 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
6976
6593
|
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
6977
6594
|
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);
|
|
6978
6595
|
}, editor.insertPortableTextData = (data) => {
|
|
6979
|
-
var _a, _b;
|
|
6980
6596
|
if (!editor.selection)
|
|
6981
6597
|
return !1;
|
|
6982
6598
|
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
@@ -6986,8 +6602,8 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
6986
6602
|
const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
|
|
6987
6603
|
schemaTypes
|
|
6988
6604
|
}), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
6989
|
-
if (!validation.valid && !
|
|
6990
|
-
const errorDescription = `${
|
|
6605
|
+
if (!validation.valid && !validation.resolution?.autoResolve) {
|
|
6606
|
+
const errorDescription = `${validation.resolution?.description}`;
|
|
6991
6607
|
return editorActor.send({
|
|
6992
6608
|
type: "error",
|
|
6993
6609
|
name: "pasteError",
|
|
@@ -7000,7 +6616,6 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7000
6616
|
}
|
|
7001
6617
|
return !1;
|
|
7002
6618
|
}, editor.insertTextOrHTMLData = (data) => {
|
|
7003
|
-
var _a;
|
|
7004
6619
|
if (!editor.selection)
|
|
7005
6620
|
return debug$1("No selection, not inserting"), !1;
|
|
7006
6621
|
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
@@ -7027,7 +6642,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7027
6642
|
const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7028
6643
|
if (!validation.valid) {
|
|
7029
6644
|
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
7030
|
-
${
|
|
6645
|
+
${validation.resolution?.description}
|
|
7031
6646
|
Try to insert as plain text (shift-paste) instead.`;
|
|
7032
6647
|
return editorActor.send({
|
|
7033
6648
|
type: "error",
|
|
@@ -7066,37 +6681,46 @@ function escapeHtml(str) {
|
|
|
7066
6681
|
}
|
|
7067
6682
|
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
7068
6683
|
return fragment.map((node) => {
|
|
7069
|
-
const newNode =
|
|
6684
|
+
const newNode = {
|
|
6685
|
+
...node
|
|
6686
|
+
};
|
|
7070
6687
|
if (editor.isTextBlock(newNode)) {
|
|
7071
6688
|
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
7072
6689
|
if (annotations.length === 0) {
|
|
7073
|
-
const
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
6690
|
+
const {
|
|
6691
|
+
markDefs,
|
|
6692
|
+
...NewNodeNoDefs
|
|
6693
|
+
} = newNode;
|
|
6694
|
+
return {
|
|
6695
|
+
...NewNodeNoDefs,
|
|
7077
6696
|
_key: keyGenerator()
|
|
7078
|
-
}
|
|
6697
|
+
};
|
|
7079
6698
|
}
|
|
7080
6699
|
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
7081
6700
|
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
7082
|
-
return
|
|
6701
|
+
return {
|
|
6702
|
+
...newNode,
|
|
7083
6703
|
markDefs: allowedAnnotations,
|
|
7084
6704
|
_key: keyGenerator()
|
|
7085
|
-
}
|
|
6705
|
+
};
|
|
7086
6706
|
}
|
|
7087
6707
|
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
7088
6708
|
const oldKey = def._key, newKey = keyGenerator();
|
|
7089
|
-
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ?
|
|
6709
|
+
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
6710
|
+
...child,
|
|
7090
6711
|
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
7091
|
-
}
|
|
6712
|
+
} : child), {
|
|
6713
|
+
...def,
|
|
7092
6714
|
_key: newKey
|
|
7093
|
-
}
|
|
6715
|
+
};
|
|
7094
6716
|
});
|
|
7095
6717
|
}
|
|
7096
|
-
const nodeWithNewKeys =
|
|
6718
|
+
const nodeWithNewKeys = {
|
|
6719
|
+
...newNode,
|
|
7097
6720
|
_key: keyGenerator()
|
|
7098
|
-
}
|
|
7099
|
-
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) =>
|
|
6721
|
+
};
|
|
6722
|
+
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
6723
|
+
...child,
|
|
7100
6724
|
_key: keyGenerator()
|
|
7101
6725
|
}))), nodeWithNewKeys;
|
|
7102
6726
|
});
|
|
@@ -7141,22 +6765,6 @@ function withSyncRangeDecorations({
|
|
|
7141
6765
|
slateEditor.apply = originalApply;
|
|
7142
6766
|
};
|
|
7143
6767
|
}
|
|
7144
|
-
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) => {
|
|
7145
|
-
for (var prop in b || (b = {}))
|
|
7146
|
-
__hasOwnProp2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
7147
|
-
if (__getOwnPropSymbols2)
|
|
7148
|
-
for (var prop of __getOwnPropSymbols2(b))
|
|
7149
|
-
__propIsEnum2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
7150
|
-
return a;
|
|
7151
|
-
}, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)), __objRest = (source, exclude) => {
|
|
7152
|
-
var target = {};
|
|
7153
|
-
for (var prop in source)
|
|
7154
|
-
__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
7155
|
-
if (source != null && __getOwnPropSymbols2)
|
|
7156
|
-
for (var prop of __getOwnPropSymbols2(source))
|
|
7157
|
-
exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop) && (target[prop] = source[prop]);
|
|
7158
|
-
return target;
|
|
7159
|
-
};
|
|
7160
6768
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
7161
6769
|
position: "absolute",
|
|
7162
6770
|
userSelect: "none",
|
|
@@ -7164,7 +6772,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7164
6772
|
left: 0,
|
|
7165
6773
|
right: 0
|
|
7166
6774
|
}, PortableTextEditable = React.forwardRef(function(props, forwardedRef) {
|
|
7167
|
-
const
|
|
6775
|
+
const {
|
|
7168
6776
|
hotkeys,
|
|
7169
6777
|
onBlur,
|
|
7170
6778
|
onFocus,
|
|
@@ -7182,27 +6790,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7182
6790
|
renderStyle,
|
|
7183
6791
|
selection: propsSelection,
|
|
7184
6792
|
scrollSelectionIntoView,
|
|
7185
|
-
spellCheck
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
"onBlur",
|
|
7189
|
-
"onFocus",
|
|
7190
|
-
"onBeforeInput",
|
|
7191
|
-
"onPaste",
|
|
7192
|
-
"onCopy",
|
|
7193
|
-
"onClick",
|
|
7194
|
-
"rangeDecorations",
|
|
7195
|
-
"renderAnnotation",
|
|
7196
|
-
"renderBlock",
|
|
7197
|
-
"renderChild",
|
|
7198
|
-
"renderDecorator",
|
|
7199
|
-
"renderListItem",
|
|
7200
|
-
"renderPlaceholder",
|
|
7201
|
-
"renderStyle",
|
|
7202
|
-
"selection",
|
|
7203
|
-
"scrollSelectionIntoView",
|
|
7204
|
-
"spellCheck"
|
|
7205
|
-
]), portableTextEditor = usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), [rangeDecorationState, setRangeDecorationsState] = React.useState([]);
|
|
6793
|
+
spellCheck,
|
|
6794
|
+
...restProps
|
|
6795
|
+
} = props, portableTextEditor = usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), [rangeDecorationState, setRangeDecorationsState] = React.useState([]);
|
|
7206
6796
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
7207
6797
|
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
7208
6798
|
"edit mode": "read only"
|
|
@@ -7214,9 +6804,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7214
6804
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
7215
6805
|
return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
|
|
7216
6806
|
}, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
|
|
7217
|
-
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element,
|
|
6807
|
+
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = React.useCallback((lProps) => {
|
|
7218
6808
|
if (lProps.leaf._type === "span") {
|
|
7219
|
-
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf,
|
|
6809
|
+
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
7220
6810
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
7221
6811
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
7222
6812
|
/* @__PURE__ */ jsxRuntime.jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: renderPlaceholder() }),
|
|
@@ -7263,9 +6853,10 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7263
6853
|
origin: "local"
|
|
7264
6854
|
});
|
|
7265
6855
|
}
|
|
7266
|
-
newRange !== null && newSlateRanges.push(
|
|
6856
|
+
newRange !== null && newSlateRanges.push({
|
|
6857
|
+
...newRange || slateRange_0,
|
|
7267
6858
|
rangeDecoration: rangeDecorationItem
|
|
7268
|
-
})
|
|
6859
|
+
});
|
|
7269
6860
|
}), newSlateRanges.length > 0) {
|
|
7270
6861
|
setRangeDecorationsState(newSlateRanges);
|
|
7271
6862
|
return;
|
|
@@ -7311,7 +6902,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7311
6902
|
nativeEvent: event
|
|
7312
6903
|
});
|
|
7313
6904
|
}, [onCopy, editorActor, slateEditor]), handlePaste = React.useCallback((event_0) => {
|
|
7314
|
-
const value_0 = PortableTextEditor.getValue(portableTextEditor),
|
|
6905
|
+
const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
|
|
7315
6906
|
event: event_0,
|
|
7316
6907
|
value: value_0,
|
|
7317
6908
|
path,
|
|
@@ -7376,8 +6967,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7376
6967
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
7377
6968
|
try {
|
|
7378
6969
|
const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
7379
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection
|
|
7380
|
-
} catch
|
|
6970
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
6971
|
+
} catch {
|
|
7381
6972
|
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
7382
6973
|
}
|
|
7383
6974
|
}, [ref, slateEditor]);
|
|
@@ -7465,7 +7056,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7465
7056
|
ref.current = slateReact.ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
7466
7057
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
7467
7058
|
slateReact.Editable,
|
|
7468
|
-
|
|
7059
|
+
{
|
|
7060
|
+
...restProps,
|
|
7469
7061
|
autoFocus: !1,
|
|
7470
7062
|
className: restProps.className || "pt-editable",
|
|
7471
7063
|
decorate,
|
|
@@ -7482,7 +7074,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7482
7074
|
renderElement,
|
|
7483
7075
|
renderLeaf,
|
|
7484
7076
|
scrollSelectionIntoView: scrollSelectionIntoViewToSlate
|
|
7485
|
-
}
|
|
7077
|
+
}
|
|
7486
7078
|
) : null;
|
|
7487
7079
|
});
|
|
7488
7080
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|