@portabletext/editor 1.16.4 → 1.17.0
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 +319 -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 +321 -38
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +532 -881
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +532 -881
- 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 +3 -3
- package/src/behaviors/behavior.emoji-picker.ts +410 -0
- package/src/behaviors/index.ts +4 -0
package/lib/index.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
|
|
5
|
-
for (var prop in b || (b = {}))
|
|
6
|
-
__hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
7
|
-
if (__getOwnPropSymbols)
|
|
8
|
-
for (var prop of __getOwnPropSymbols(b))
|
|
9
|
-
__propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
10
|
-
return a;
|
|
11
|
-
};
|
|
12
1
|
import { Schema } from "@sanity/schema";
|
|
13
2
|
import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
|
|
14
3
|
import startCase from "lodash.startcase";
|
|
@@ -37,13 +26,12 @@ import { blockOffsetToSpanSelectionPoint, coreBehaviors, isHotkey } from "./_chu
|
|
|
37
26
|
import getRandomValues from "get-random-values-esm";
|
|
38
27
|
import { htmlToBlocks, normalizeBlock } from "@sanity/block-tools";
|
|
39
28
|
function createEditorSchema(portableTextType) {
|
|
40
|
-
var _a, _b, _c;
|
|
41
29
|
if (!portableTextType)
|
|
42
30
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
43
|
-
const blockType =
|
|
31
|
+
const blockType = portableTextType.of?.find(findBlockType);
|
|
44
32
|
if (!blockType)
|
|
45
33
|
throw new Error("Block type is not defined in this schema (required)");
|
|
46
|
-
const childrenField =
|
|
34
|
+
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
47
35
|
if (!childrenField)
|
|
48
36
|
throw new Error("Children field for block type found in schema (required)");
|
|
49
37
|
const ofType = childrenField.type.of;
|
|
@@ -52,7 +40,7 @@ function createEditorSchema(portableTextType) {
|
|
|
52
40
|
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
53
41
|
if (!spanType)
|
|
54
42
|
throw new Error("Span type not found in schema (required)");
|
|
55
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes =
|
|
43
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
56
44
|
return {
|
|
57
45
|
styles: resolveEnabledStyles(blockType),
|
|
58
46
|
decorators: resolveEnabledDecorators(spanType),
|
|
@@ -66,11 +54,10 @@ function createEditorSchema(portableTextType) {
|
|
|
66
54
|
};
|
|
67
55
|
}
|
|
68
56
|
function resolveEnabledStyles(blockType) {
|
|
69
|
-
|
|
70
|
-
const styleField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "style");
|
|
57
|
+
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
71
58
|
if (!styleField)
|
|
72
59
|
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
73
|
-
const textStyles =
|
|
60
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
74
61
|
if (!textStyles || textStyles.length === 0)
|
|
75
62
|
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
76
63
|
return textStyles;
|
|
@@ -79,11 +66,10 @@ function resolveEnabledDecorators(spanType) {
|
|
|
79
66
|
return spanType.decorators;
|
|
80
67
|
}
|
|
81
68
|
function resolveEnabledListItems(blockType) {
|
|
82
|
-
|
|
83
|
-
const listField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "listItem");
|
|
69
|
+
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
84
70
|
if (!listField)
|
|
85
71
|
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
86
|
-
const listItems =
|
|
72
|
+
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
87
73
|
if (!listItems)
|
|
88
74
|
throw new Error("The list field need at least to be an empty array");
|
|
89
75
|
return listItems;
|
|
@@ -91,20 +77,11 @@ function resolveEnabledListItems(blockType) {
|
|
|
91
77
|
function findBlockType(type) {
|
|
92
78
|
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
93
79
|
}
|
|
94
|
-
var __defProp$q = Object.defineProperty, __defProps$j = Object.defineProperties, __getOwnPropDescs$j = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$q = Object.getOwnPropertySymbols, __hasOwnProp$q = Object.prototype.hasOwnProperty, __propIsEnum$q = Object.prototype.propertyIsEnumerable, __defNormalProp$q = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$q = (a, b) => {
|
|
95
|
-
for (var prop in b || (b = {}))
|
|
96
|
-
__hasOwnProp$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
|
|
97
|
-
if (__getOwnPropSymbols$q)
|
|
98
|
-
for (var prop of __getOwnPropSymbols$q(b))
|
|
99
|
-
__propIsEnum$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
|
|
100
|
-
return a;
|
|
101
|
-
}, __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
|
|
102
80
|
function defineSchema(definition) {
|
|
103
81
|
return definition;
|
|
104
82
|
}
|
|
105
83
|
function compileSchemaDefinition(definition) {
|
|
106
|
-
|
|
107
|
-
const blockObjects = (_b = (_a = definition == null ? void 0 : definition.blockObjects) == null ? void 0 : _a.map((blockObject) => defineType({
|
|
84
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => defineType({
|
|
108
85
|
type: "object",
|
|
109
86
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
110
87
|
// fields to objects with the name `image`
|
|
@@ -112,13 +89,13 @@ function compileSchemaDefinition(definition) {
|
|
|
112
89
|
title: blockObject.title,
|
|
113
90
|
icon: blockObject.icon,
|
|
114
91
|
fields: []
|
|
115
|
-
}))
|
|
92
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => defineType({
|
|
116
93
|
type: "object",
|
|
117
94
|
name: inlineObject.name,
|
|
118
95
|
title: inlineObject.title,
|
|
119
96
|
icon: inlineObject.icon,
|
|
120
97
|
fields: []
|
|
121
|
-
}))
|
|
98
|
+
})) ?? [], portableTextSchema = defineField({
|
|
122
99
|
type: "array",
|
|
123
100
|
name: "portable-text",
|
|
124
101
|
of: [...blockObjects.map((blockObject) => ({
|
|
@@ -130,49 +107,43 @@ function compileSchemaDefinition(definition) {
|
|
|
130
107
|
type: inlineObject.name
|
|
131
108
|
})),
|
|
132
109
|
marks: {
|
|
133
|
-
decorators:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
})) != null ? _f : [],
|
|
141
|
-
annotations: (_h = (_g = definition == null ? void 0 : definition.annotations) == null ? void 0 : _g.map((annotation) => ({
|
|
110
|
+
decorators: definition?.decorators?.map((decorator) => ({
|
|
111
|
+
title: decorator.title ?? startCase(decorator.name),
|
|
112
|
+
value: decorator.name,
|
|
113
|
+
icon: decorator.icon
|
|
114
|
+
})) ?? [],
|
|
115
|
+
annotations: definition?.annotations?.map((annotation) => ({
|
|
142
116
|
name: annotation.name,
|
|
143
117
|
type: "object",
|
|
144
118
|
title: annotation.title,
|
|
145
119
|
icon: annotation.icon
|
|
146
|
-
}))
|
|
120
|
+
})) ?? []
|
|
147
121
|
},
|
|
148
|
-
lists:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return {
|
|
159
|
-
value: style.name,
|
|
160
|
-
title: (_a2 = style.title) != null ? _a2 : startCase(style.name),
|
|
161
|
-
icon: style.icon
|
|
162
|
-
};
|
|
163
|
-
})) != null ? _l : []
|
|
122
|
+
lists: definition?.lists?.map((list) => ({
|
|
123
|
+
value: list.name,
|
|
124
|
+
title: list.title ?? startCase(list.name),
|
|
125
|
+
icon: list.icon
|
|
126
|
+
})) ?? [],
|
|
127
|
+
styles: definition?.styles?.map((style) => ({
|
|
128
|
+
value: style.name,
|
|
129
|
+
title: style.title ?? startCase(style.name),
|
|
130
|
+
icon: style.icon
|
|
131
|
+
})) ?? []
|
|
164
132
|
}]
|
|
165
133
|
}), schema = Schema.compile({
|
|
166
134
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
167
135
|
}).get("portable-text"), pteSchema = createEditorSchema(schema);
|
|
168
|
-
return
|
|
169
|
-
|
|
136
|
+
return {
|
|
137
|
+
...pteSchema,
|
|
138
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
|
|
139
|
+
...blockObject,
|
|
170
140
|
name: "image",
|
|
171
|
-
type:
|
|
141
|
+
type: {
|
|
142
|
+
...blockObject.type,
|
|
172
143
|
name: "image"
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
144
|
+
}
|
|
145
|
+
} : blockObject)
|
|
146
|
+
};
|
|
176
147
|
}
|
|
177
148
|
const rootName = "sanity-pte:";
|
|
178
149
|
debug$l(rootName);
|
|
@@ -307,22 +278,6 @@ function normalizeSelection(selection, value) {
|
|
|
307
278
|
backward: selection.backward
|
|
308
279
|
} : null;
|
|
309
280
|
}
|
|
310
|
-
var __defProp$p = Object.defineProperty, __defProps$i = Object.defineProperties, __getOwnPropDescs$i = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$p = Object.getOwnPropertySymbols, __hasOwnProp$p = Object.prototype.hasOwnProperty, __propIsEnum$p = Object.prototype.propertyIsEnumerable, __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$p = (a, b) => {
|
|
311
|
-
for (var prop in b || (b = {}))
|
|
312
|
-
__hasOwnProp$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
313
|
-
if (__getOwnPropSymbols$p)
|
|
314
|
-
for (var prop of __getOwnPropSymbols$p(b))
|
|
315
|
-
__propIsEnum$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
316
|
-
return a;
|
|
317
|
-
}, __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b)), __objRest$3 = (source, exclude) => {
|
|
318
|
-
var target = {};
|
|
319
|
-
for (var prop in source)
|
|
320
|
-
__hasOwnProp$p.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
321
|
-
if (source != null && __getOwnPropSymbols$p)
|
|
322
|
-
for (var prop of __getOwnPropSymbols$p(source))
|
|
323
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$p.call(source, prop) && (target[prop] = source[prop]);
|
|
324
|
-
return target;
|
|
325
|
-
};
|
|
326
281
|
const VOID_CHILD_KEY = "void-child";
|
|
327
282
|
function keepObjectEquality(object, keyMap) {
|
|
328
283
|
const value = keyMap[object._key];
|
|
@@ -332,13 +287,11 @@ function toSlateValue(value, {
|
|
|
332
287
|
schemaTypes
|
|
333
288
|
}, keyMap = {}) {
|
|
334
289
|
return value && Array.isArray(value) ? value.map((block) => {
|
|
335
|
-
const
|
|
290
|
+
const {
|
|
336
291
|
_type,
|
|
337
|
-
_key
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
"_key"
|
|
341
|
-
]), voidChildren = [{
|
|
292
|
+
_key,
|
|
293
|
+
...rest
|
|
294
|
+
} = block, voidChildren = [{
|
|
342
295
|
_key: VOID_CHILD_KEY,
|
|
343
296
|
_type: "span",
|
|
344
297
|
text: "",
|
|
@@ -348,13 +301,11 @@ function toSlateValue(value, {
|
|
|
348
301
|
const textBlock = block;
|
|
349
302
|
let hasInlines = !1;
|
|
350
303
|
const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
|
|
351
|
-
const
|
|
304
|
+
const {
|
|
352
305
|
_type: cType,
|
|
353
|
-
_key: cKey
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
"_key"
|
|
357
|
-
]);
|
|
306
|
+
_key: cKey,
|
|
307
|
+
...cRest
|
|
308
|
+
} = child;
|
|
358
309
|
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
359
310
|
_type: cType,
|
|
360
311
|
_key: cKey,
|
|
@@ -363,12 +314,12 @@ function toSlateValue(value, {
|
|
|
363
314
|
__inline: !0
|
|
364
315
|
}, keyMap)) : child;
|
|
365
316
|
});
|
|
366
|
-
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(
|
|
317
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality({
|
|
367
318
|
_type,
|
|
368
|
-
_key
|
|
369
|
-
|
|
319
|
+
_key,
|
|
320
|
+
...rest,
|
|
370
321
|
children
|
|
371
|
-
}
|
|
322
|
+
}, keyMap));
|
|
372
323
|
}
|
|
373
324
|
return keepObjectEquality({
|
|
374
325
|
_type,
|
|
@@ -394,42 +345,40 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
394
345
|
} = child;
|
|
395
346
|
if ("value" in child && _cType !== "span") {
|
|
396
347
|
hasInlines = !0;
|
|
397
|
-
const
|
|
348
|
+
const {
|
|
398
349
|
value: v,
|
|
399
350
|
_key: k,
|
|
400
351
|
_type: t,
|
|
401
352
|
__inline: _i,
|
|
402
|
-
children: _c
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
"children"
|
|
409
|
-
]);
|
|
410
|
-
return keepObjectEquality(__spreadProps$i(__spreadValues$p(__spreadValues$p({}, rest), v), {
|
|
353
|
+
children: _c,
|
|
354
|
+
...rest
|
|
355
|
+
} = child;
|
|
356
|
+
return keepObjectEquality({
|
|
357
|
+
...rest,
|
|
358
|
+
...v,
|
|
411
359
|
_key: k,
|
|
412
360
|
_type: t
|
|
413
|
-
}
|
|
361
|
+
}, keyMap);
|
|
414
362
|
}
|
|
415
363
|
return child;
|
|
416
364
|
});
|
|
417
|
-
return hasInlines ? keepObjectEquality(
|
|
365
|
+
return hasInlines ? keepObjectEquality({
|
|
366
|
+
...block,
|
|
418
367
|
children,
|
|
419
368
|
_key,
|
|
420
369
|
_type
|
|
421
|
-
}
|
|
370
|
+
}, keyMap) : block;
|
|
422
371
|
}
|
|
423
372
|
const blockValue = "value" in block && block.value;
|
|
424
|
-
return keepObjectEquality(
|
|
373
|
+
return keepObjectEquality({
|
|
425
374
|
_key,
|
|
426
|
-
_type
|
|
427
|
-
|
|
375
|
+
_type,
|
|
376
|
+
...typeof blockValue == "object" ? blockValue : {}
|
|
377
|
+
}, keyMap);
|
|
428
378
|
});
|
|
429
379
|
}
|
|
430
380
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
431
|
-
|
|
432
|
-
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element$1.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !((_a = children[0].children[0].marks) != null && _a.join("")) && children[0].children[0].text === "";
|
|
381
|
+
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element$1.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
433
382
|
}
|
|
434
383
|
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), DefaultObject = (props) => {
|
|
435
384
|
const $ = c(4);
|
|
@@ -729,14 +678,6 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
729
678
|
] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
|
|
730
679
|
};
|
|
731
680
|
DraggableBlock.displayName = "DraggableBlock";
|
|
732
|
-
var __defProp$o = Object.defineProperty, __defProps$h = Object.defineProperties, __getOwnPropDescs$h = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$o = Object.getOwnPropertySymbols, __hasOwnProp$o = Object.prototype.hasOwnProperty, __propIsEnum$o = Object.prototype.propertyIsEnumerable, __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$o = (a, b) => {
|
|
733
|
-
for (var prop in b || (b = {}))
|
|
734
|
-
__hasOwnProp$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
735
|
-
if (__getOwnPropSymbols$o)
|
|
736
|
-
for (var prop of __getOwnPropSymbols$o(b))
|
|
737
|
-
__propIsEnum$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
738
|
-
return a;
|
|
739
|
-
}, __spreadProps$h = (a, b) => __defProps$h(a, __getOwnPropDescs$h(b));
|
|
740
681
|
debugWithName("components:Element");
|
|
741
682
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
742
683
|
display: "inline-block"
|
|
@@ -773,7 +714,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
773
714
|
}, "children", {
|
|
774
715
|
_key: element._key
|
|
775
716
|
}];
|
|
776
|
-
return /* @__PURE__ */ jsxs("span",
|
|
717
|
+
return /* @__PURE__ */ jsxs("span", { ...attributes, children: [
|
|
777
718
|
children,
|
|
778
719
|
/* @__PURE__ */ jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
|
|
779
720
|
renderChild && renderChild({
|
|
@@ -790,7 +731,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
790
731
|
}),
|
|
791
732
|
!renderChild && /* @__PURE__ */ jsx(DefaultObject, { value })
|
|
792
733
|
] }, element._key)
|
|
793
|
-
] })
|
|
734
|
+
] });
|
|
794
735
|
}
|
|
795
736
|
throw new Error("Block not found!");
|
|
796
737
|
}
|
|
@@ -841,7 +782,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
841
782
|
return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
|
|
842
783
|
}
|
|
843
784
|
}), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
|
|
844
|
-
return /* @__PURE__ */ jsx("div",
|
|
785
|
+
return /* @__PURE__ */ jsx("div", { ...attributes, className, spellCheck, children: /* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }, element._key);
|
|
845
786
|
}
|
|
846
787
|
const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
|
|
847
788
|
if (!schemaType_0)
|
|
@@ -866,13 +807,13 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
866
807
|
});
|
|
867
808
|
renderedBlockFromProps = renderBlock(_props);
|
|
868
809
|
}
|
|
869
|
-
return /* @__PURE__ */ jsxs("div",
|
|
810
|
+
return /* @__PURE__ */ jsxs("div", { ...attributes, className, children: [
|
|
870
811
|
children,
|
|
871
812
|
/* @__PURE__ */ jsxs(DraggableBlock, { element, readOnly, blockRef, children: [
|
|
872
813
|
renderedBlockFromProps && /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
|
|
873
814
|
!renderedBlockFromProps && /* @__PURE__ */ jsx(DefaultBlockObject, { selected, children: /* @__PURE__ */ jsx(DefaultObject, { value }) })
|
|
874
815
|
] })
|
|
875
|
-
] }
|
|
816
|
+
] }, element._key);
|
|
876
817
|
};
|
|
877
818
|
Element.displayName = "Element";
|
|
878
819
|
const PortableTextEditorContext = createContext(null), usePortableTextEditor = () => {
|
|
@@ -971,14 +912,6 @@ const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3,
|
|
|
971
912
|
}
|
|
972
913
|
}
|
|
973
914
|
});
|
|
974
|
-
var __defProp$n = Object.defineProperty, __defProps$g = Object.defineProperties, __getOwnPropDescs$g = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$n = Object.getOwnPropertySymbols, __hasOwnProp$n = Object.prototype.hasOwnProperty, __propIsEnum$n = Object.prototype.propertyIsEnumerable, __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$n = (a, b) => {
|
|
975
|
-
for (var prop in b || (b = {}))
|
|
976
|
-
__hasOwnProp$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
977
|
-
if (__getOwnPropSymbols$n)
|
|
978
|
-
for (var prop of __getOwnPropSymbols$n(b))
|
|
979
|
-
__propIsEnum$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
980
|
-
return a;
|
|
981
|
-
}, __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
|
|
982
915
|
function validateValue(value, types, keyGenerator) {
|
|
983
916
|
let resolution = null, valid = !0;
|
|
984
917
|
const validChildTypes = [types.span.name, ...types.inlineObjects.map((t) => t.name)], validBlockTypes = [types.block.name, ...types.blockObjects.map((t) => t.name)];
|
|
@@ -1016,9 +949,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1016
949
|
}, !0;
|
|
1017
950
|
if (!blk._key || typeof blk._key != "string")
|
|
1018
951
|
return resolution = {
|
|
1019
|
-
patches: [set(
|
|
952
|
+
patches: [set({
|
|
953
|
+
...blk,
|
|
1020
954
|
_key: keyGenerator()
|
|
1021
|
-
}
|
|
955
|
+
}, [index])],
|
|
1022
956
|
description: `Block at index ${index} is missing required _key.`,
|
|
1023
957
|
action: "Set the block with a random _key value",
|
|
1024
958
|
item: blk,
|
|
@@ -1034,9 +968,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1034
968
|
if (blk._type === "block") {
|
|
1035
969
|
const currentBlockTypeName = types.block.name;
|
|
1036
970
|
return resolution = {
|
|
1037
|
-
patches: [set(
|
|
971
|
+
patches: [set({
|
|
972
|
+
...blk,
|
|
1038
973
|
_type: currentBlockTypeName
|
|
1039
|
-
}
|
|
974
|
+
}, [{
|
|
1040
975
|
_key: blk._key
|
|
1041
976
|
}])],
|
|
1042
977
|
description: `Block with _key '${blk._key}' has invalid type name '${blk._type}'. According to the schema, the block type name is '${currentBlockTypeName}'`,
|
|
@@ -1052,12 +987,14 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1052
987
|
}
|
|
1053
988
|
}, !0;
|
|
1054
989
|
}
|
|
1055
|
-
return !blk._type && isPortableTextTextBlock(
|
|
990
|
+
return !blk._type && isPortableTextTextBlock({
|
|
991
|
+
...blk,
|
|
1056
992
|
_type: types.block.name
|
|
1057
|
-
})
|
|
1058
|
-
patches: [set(
|
|
993
|
+
}) ? (resolution = {
|
|
994
|
+
patches: [set({
|
|
995
|
+
...blk,
|
|
1059
996
|
_type: types.block.name
|
|
1060
|
-
}
|
|
997
|
+
}, [{
|
|
1061
998
|
_key: blk._key
|
|
1062
999
|
}])],
|
|
1063
1000
|
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types.block.name}'`,
|
|
@@ -1217,9 +1154,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1217
1154
|
}
|
|
1218
1155
|
}, !0;
|
|
1219
1156
|
if (!child._key || typeof child._key != "string") {
|
|
1220
|
-
const newChild =
|
|
1157
|
+
const newChild = {
|
|
1158
|
+
...child,
|
|
1221
1159
|
_key: keyGenerator()
|
|
1222
|
-
}
|
|
1160
|
+
};
|
|
1223
1161
|
return resolution = {
|
|
1224
1162
|
autoResolve: !0,
|
|
1225
1163
|
patches: [set(newChild, [{
|
|
@@ -1239,9 +1177,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1239
1177
|
}, !0;
|
|
1240
1178
|
}
|
|
1241
1179
|
return child._type ? validChildTypes.includes(child._type) ? child._type === types.span.name && typeof child.text != "string" ? (resolution = {
|
|
1242
|
-
patches: [set(
|
|
1180
|
+
patches: [set({
|
|
1181
|
+
...child,
|
|
1243
1182
|
text: ""
|
|
1244
|
-
}
|
|
1183
|
+
}, [{
|
|
1245
1184
|
_key: blk._key
|
|
1246
1185
|
}, "children", {
|
|
1247
1186
|
_key: child._key
|
|
@@ -1649,10 +1588,11 @@ function createDeadLine(timeout) {
|
|
|
1649
1588
|
return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
|
|
1650
1589
|
}
|
|
1651
1590
|
function createInternalOpts(opts) {
|
|
1652
|
-
return
|
|
1591
|
+
return {
|
|
1653
1592
|
checkLines: !0,
|
|
1654
|
-
deadline: createDeadLine(opts.timeout || 1)
|
|
1655
|
-
|
|
1593
|
+
deadline: createDeadLine(opts.timeout || 1),
|
|
1594
|
+
...opts
|
|
1595
|
+
};
|
|
1656
1596
|
}
|
|
1657
1597
|
function combineChar(data, char, dir) {
|
|
1658
1598
|
return dir === 1 ? data + char : char + data;
|
|
@@ -1716,7 +1656,10 @@ const DEFAULT_OPTIONS = {
|
|
|
1716
1656
|
distance: 1e3
|
|
1717
1657
|
};
|
|
1718
1658
|
function applyDefaults(options) {
|
|
1719
|
-
return
|
|
1659
|
+
return {
|
|
1660
|
+
...DEFAULT_OPTIONS,
|
|
1661
|
+
...options
|
|
1662
|
+
};
|
|
1720
1663
|
}
|
|
1721
1664
|
const MAX_BITS$1 = 32;
|
|
1722
1665
|
function bitap(text, pattern, loc) {
|
|
@@ -1988,7 +1931,7 @@ function parse(textline) {
|
|
|
1988
1931
|
let line;
|
|
1989
1932
|
try {
|
|
1990
1933
|
line = decodeURI(currentLine.slice(1));
|
|
1991
|
-
} catch
|
|
1934
|
+
} catch {
|
|
1992
1935
|
throw new Error("Illegal escape in parse: ".concat(currentLine));
|
|
1993
1936
|
}
|
|
1994
1937
|
const utf8Diff = countUtf8Bytes(line) - line.length;
|
|
@@ -2014,8 +1957,7 @@ function withUndoing(editor, fn) {
|
|
|
2014
1957
|
IS_UDOING.set(editor, !0), fn(), IS_UDOING.set(editor, prev);
|
|
2015
1958
|
}
|
|
2016
1959
|
function isUndoing(editor) {
|
|
2017
|
-
|
|
2018
|
-
return (_a = IS_UDOING.get(editor)) != null ? _a : !1;
|
|
1960
|
+
return IS_UDOING.get(editor) ?? !1;
|
|
2019
1961
|
}
|
|
2020
1962
|
function setIsUndoing(editor, isUndoing2) {
|
|
2021
1963
|
IS_UDOING.set(editor, isUndoing2);
|
|
@@ -2025,20 +1967,11 @@ function withRedoing(editor, fn) {
|
|
|
2025
1967
|
IS_REDOING.set(editor, !0), fn(), IS_REDOING.set(editor, prev);
|
|
2026
1968
|
}
|
|
2027
1969
|
function isRedoing(editor) {
|
|
2028
|
-
|
|
2029
|
-
return (_a = IS_REDOING.get(editor)) != null ? _a : !1;
|
|
1970
|
+
return IS_REDOING.get(editor) ?? !1;
|
|
2030
1971
|
}
|
|
2031
1972
|
function setIsRedoing(editor, isRedoing2) {
|
|
2032
1973
|
IS_REDOING.set(editor, isRedoing2);
|
|
2033
1974
|
}
|
|
2034
|
-
var __defProp$m = Object.defineProperty, __getOwnPropSymbols$m = Object.getOwnPropertySymbols, __hasOwnProp$m = Object.prototype.hasOwnProperty, __propIsEnum$m = Object.prototype.propertyIsEnumerable, __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$m = (a, b) => {
|
|
2035
|
-
for (var prop in b || (b = {}))
|
|
2036
|
-
__hasOwnProp$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
2037
|
-
if (__getOwnPropSymbols$m)
|
|
2038
|
-
for (var prop of __getOwnPropSymbols$m(b))
|
|
2039
|
-
__propIsEnum$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
2040
|
-
return a;
|
|
2041
|
-
};
|
|
2042
1975
|
const debug$j = debugWithName("plugin:withUndoRedo"), debugVerbose$3 = debug$j.enabled && !1, SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2043
1976
|
const state = SAVING.get(editor);
|
|
2044
1977
|
return state === void 0 ? !0 : state;
|
|
@@ -2201,7 +2134,9 @@ function createWithUndoRedo(options) {
|
|
|
2201
2134
|
}
|
|
2202
2135
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2203
2136
|
debugVerbose$3 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
|
|
2204
|
-
const transformedOperation =
|
|
2137
|
+
const transformedOperation = {
|
|
2138
|
+
...operation
|
|
2139
|
+
};
|
|
2205
2140
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
2206
2141
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
2207
2142
|
_key: blk._key
|
|
@@ -2221,7 +2156,6 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2221
2156
|
return !operationTargetBlock || !isEqual({
|
|
2222
2157
|
_key: operationTargetBlock._key
|
|
2223
2158
|
}, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
2224
|
-
var _a, _b, _c, _d;
|
|
2225
2159
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
|
|
2226
2160
|
const {
|
|
2227
2161
|
diffs
|
|
@@ -2230,7 +2164,15 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2230
2164
|
const [diffType, text] = diff2;
|
|
2231
2165
|
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
|
|
2232
2166
|
}), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
|
|
2233
|
-
const currentFocus =
|
|
2167
|
+
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2168
|
+
...transformedOperation.properties.focus
|
|
2169
|
+
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
2170
|
+
...transformedOperation.properties.anchor
|
|
2171
|
+
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
2172
|
+
...transformedOperation.newProperties.focus
|
|
2173
|
+
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
2174
|
+
...transformedOperation.newProperties.anchor
|
|
2175
|
+
} : void 0;
|
|
2234
2176
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2235
2177
|
point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
|
|
2236
2178
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2246,14 +2188,23 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2246
2188
|
return [transformedOperation];
|
|
2247
2189
|
}
|
|
2248
2190
|
function adjustBlockPath(operation, level, blockIndex) {
|
|
2249
|
-
|
|
2250
|
-
|
|
2191
|
+
const transformedOperation = {
|
|
2192
|
+
...operation
|
|
2193
|
+
};
|
|
2251
2194
|
if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
|
|
2252
2195
|
const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
|
|
2253
2196
|
transformedOperation.path = newPath;
|
|
2254
2197
|
}
|
|
2255
2198
|
if (transformedOperation.type === "set_selection") {
|
|
2256
|
-
const currentFocus =
|
|
2199
|
+
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2200
|
+
...transformedOperation.properties.focus
|
|
2201
|
+
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
2202
|
+
...transformedOperation.properties.anchor
|
|
2203
|
+
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
2204
|
+
...transformedOperation.newProperties.focus
|
|
2205
|
+
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
2206
|
+
...transformedOperation.newProperties.anchor
|
|
2207
|
+
} : void 0;
|
|
2257
2208
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2258
2209
|
point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
|
|
2259
2210
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2274,27 +2225,18 @@ function withoutSaving(editor, fn) {
|
|
|
2274
2225
|
function createSelectOperation(editor) {
|
|
2275
2226
|
return {
|
|
2276
2227
|
type: "set_selection",
|
|
2277
|
-
properties:
|
|
2278
|
-
|
|
2228
|
+
properties: {
|
|
2229
|
+
...editor.selection
|
|
2230
|
+
},
|
|
2231
|
+
newProperties: {
|
|
2232
|
+
...editor.selection
|
|
2233
|
+
}
|
|
2279
2234
|
};
|
|
2280
2235
|
}
|
|
2281
2236
|
function findOperationTargetBlock(editor, operation) {
|
|
2282
2237
|
let block;
|
|
2283
2238
|
return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
|
|
2284
2239
|
}
|
|
2285
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name), __await = function(promise, isYieldStar) {
|
|
2286
|
-
this[0] = promise, this[1] = isYieldStar;
|
|
2287
|
-
}, __asyncGenerator = (__this, __arguments, generator) => {
|
|
2288
|
-
var resume = (k, v, yes, no) => {
|
|
2289
|
-
try {
|
|
2290
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
2291
|
-
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
2292
|
-
} catch (e) {
|
|
2293
|
-
no(e);
|
|
2294
|
-
}
|
|
2295
|
-
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
2296
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
2297
|
-
}, __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
2298
2240
|
const syncValueCallback = ({
|
|
2299
2241
|
sendBack,
|
|
2300
2242
|
input
|
|
@@ -2345,10 +2287,7 @@ const syncValueCallback = ({
|
|
|
2345
2287
|
}) => context.initialValueSynced,
|
|
2346
2288
|
"is busy": ({
|
|
2347
2289
|
context
|
|
2348
|
-
}) =>
|
|
2349
|
-
var _a;
|
|
2350
|
-
return !context.readOnly && (context.isProcessingLocalChanges || ((_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1));
|
|
2351
|
-
},
|
|
2290
|
+
}) => !context.readOnly && (context.isProcessingLocalChanges || (isChangingRemotely(context.slateEditor) ?? !1)),
|
|
2352
2291
|
"value changed while syncing": ({
|
|
2353
2292
|
context,
|
|
2354
2293
|
event
|
|
@@ -2533,33 +2472,22 @@ async function updateValue({
|
|
|
2533
2472
|
});
|
|
2534
2473
|
isChanged = !0;
|
|
2535
2474
|
}
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2553
|
-
}
|
|
2554
|
-
} catch (temp2) {
|
|
2555
|
-
error = [temp2];
|
|
2556
|
-
} finally {
|
|
2557
|
-
try {
|
|
2558
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2559
|
-
} finally {
|
|
2560
|
-
if (error)
|
|
2561
|
-
throw error[0];
|
|
2562
|
-
}
|
|
2475
|
+
for await (const [currentBlock, currentBlockIndex] of getBlocks({
|
|
2476
|
+
slateValue: slateValueFromProps,
|
|
2477
|
+
streamBlocks
|
|
2478
|
+
})) {
|
|
2479
|
+
const {
|
|
2480
|
+
blockChanged,
|
|
2481
|
+
blockValid
|
|
2482
|
+
} = syncBlock({
|
|
2483
|
+
context,
|
|
2484
|
+
sendBack,
|
|
2485
|
+
block: currentBlock,
|
|
2486
|
+
index: currentBlockIndex,
|
|
2487
|
+
slateEditor,
|
|
2488
|
+
value
|
|
2489
|
+
});
|
|
2490
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2563
2491
|
}
|
|
2564
2492
|
resolve();
|
|
2565
2493
|
});
|
|
@@ -2609,28 +2537,13 @@ async function updateValue({
|
|
|
2609
2537
|
value
|
|
2610
2538
|
});
|
|
2611
2539
|
}
|
|
2612
|
-
function getBlocks(
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
for (var iter = __forAwait(slateValue), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = !1) {
|
|
2620
|
-
const block = temp.value;
|
|
2621
|
-
streamBlocks && (yield new __await(new Promise((resolve) => setTimeout(resolve, 0)))), yield [block, index], index++;
|
|
2622
|
-
}
|
|
2623
|
-
} catch (temp2) {
|
|
2624
|
-
error = [temp2];
|
|
2625
|
-
} finally {
|
|
2626
|
-
try {
|
|
2627
|
-
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2628
|
-
} finally {
|
|
2629
|
-
if (error)
|
|
2630
|
-
throw error[0];
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
});
|
|
2540
|
+
async function* getBlocks({
|
|
2541
|
+
slateValue,
|
|
2542
|
+
streamBlocks
|
|
2543
|
+
}) {
|
|
2544
|
+
let index = 0;
|
|
2545
|
+
for await (const block of slateValue)
|
|
2546
|
+
streamBlocks && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
2634
2547
|
}
|
|
2635
2548
|
function syncBlock({
|
|
2636
2549
|
context,
|
|
@@ -2645,15 +2558,14 @@ function syncBlock({
|
|
|
2645
2558
|
return Editor.withoutNormalizing(slateEditor, () => {
|
|
2646
2559
|
withRemoteChanges(slateEditor, () => {
|
|
2647
2560
|
withoutPatching(slateEditor, () => {
|
|
2648
|
-
var _a, _b, _c, _d, _e;
|
|
2649
2561
|
if (hasChanges && blockValid) {
|
|
2650
2562
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2651
|
-
!validation.valid &&
|
|
2563
|
+
!validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${validation.resolution?.description}`), validation.resolution.patches.forEach((patch) => {
|
|
2652
2564
|
sendBack({
|
|
2653
2565
|
type: "patch",
|
|
2654
2566
|
patch
|
|
2655
2567
|
});
|
|
2656
|
-
})), validation.valid ||
|
|
2568
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
2657
2569
|
type: "invalid value",
|
|
2658
2570
|
resolution: validation.resolution,
|
|
2659
2571
|
value
|
|
@@ -2661,7 +2573,7 @@ function syncBlock({
|
|
|
2661
2573
|
}
|
|
2662
2574
|
if (!oldBlock && blockValid) {
|
|
2663
2575
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2664
|
-
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid ||
|
|
2576
|
+
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2665
2577
|
at: [currentBlockIndex]
|
|
2666
2578
|
}) : (debug$i("Invalid", validation), sendBack({
|
|
2667
2579
|
type: "invalid value",
|
|
@@ -2695,9 +2607,9 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2695
2607
|
at: [currentBlockIndex, childIndex]
|
|
2696
2608
|
}));
|
|
2697
2609
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2698
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild
|
|
2610
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2699
2611
|
if (isChildChanged)
|
|
2700
|
-
if (currentBlockChild._key ===
|
|
2612
|
+
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2701
2613
|
debug$i("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2702
2614
|
at: path
|
|
2703
2615
|
});
|
|
@@ -2824,14 +2736,6 @@ function _temp(s) {
|
|
|
2824
2736
|
return s.context.value;
|
|
2825
2737
|
}
|
|
2826
2738
|
Synchronizer.displayName = "Synchronizer";
|
|
2827
|
-
var __defProp$l = Object.defineProperty, __defProps$f = Object.defineProperties, __getOwnPropDescs$f = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$l = Object.getOwnPropertySymbols, __hasOwnProp$l = Object.prototype.hasOwnProperty, __propIsEnum$l = Object.prototype.propertyIsEnumerable, __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$l = (a, b) => {
|
|
2828
|
-
for (var prop in b || (b = {}))
|
|
2829
|
-
__hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2830
|
-
if (__getOwnPropSymbols$l)
|
|
2831
|
-
for (var prop of __getOwnPropSymbols$l(b))
|
|
2832
|
-
__propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2833
|
-
return a;
|
|
2834
|
-
}, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
|
|
2835
2739
|
const debug$g = debugWithName("operationToPatches");
|
|
2836
2740
|
function createOperationToPatches(types) {
|
|
2837
2741
|
const textBlockName = types.block.name;
|
|
@@ -2871,7 +2775,10 @@ function createOperationToPatches(types) {
|
|
|
2871
2775
|
const block = editor.children[operation.path[0]];
|
|
2872
2776
|
if (typeof block._key != "string")
|
|
2873
2777
|
throw new Error("Expected block to have a _key");
|
|
2874
|
-
const setNode = omitBy(
|
|
2778
|
+
const setNode = omitBy({
|
|
2779
|
+
...editor.children[operation.path[0]],
|
|
2780
|
+
...operation.newProperties
|
|
2781
|
+
}, isUndefined);
|
|
2875
2782
|
return [set(fromSlateValue([setNode], textBlockName)[0], [{
|
|
2876
2783
|
_key: block._key
|
|
2877
2784
|
}])];
|
|
@@ -2906,12 +2813,14 @@ function createOperationToPatches(types) {
|
|
|
2906
2813
|
function insertNodePatch(editor, operation, beforeValue) {
|
|
2907
2814
|
const block = beforeValue[operation.path[0]], isTextBlock = editor.isTextBlock(block);
|
|
2908
2815
|
if (operation.path.length === 1) {
|
|
2909
|
-
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block
|
|
2816
|
+
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
|
|
2910
2817
|
return targetKey ? [insert([fromSlateValue([operation.node], textBlockName)[0]], position, [{
|
|
2911
2818
|
_key: targetKey
|
|
2912
2819
|
}])] : [setIfMissing(beforeValue, []), insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
|
|
2913
2820
|
} else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
|
|
2914
|
-
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node =
|
|
2821
|
+
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
|
|
2822
|
+
...operation.node
|
|
2823
|
+
};
|
|
2915
2824
|
!node._type && Text.isText(node) && (node._type = "span", node.marks = []);
|
|
2916
2825
|
const child = fromSlateValue([{
|
|
2917
2826
|
_key: "bogus",
|
|
@@ -2950,9 +2859,10 @@ function createOperationToPatches(types) {
|
|
|
2950
2859
|
if (operation.path.length === 2) {
|
|
2951
2860
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
2952
2861
|
if (editor.isTextSpan(splitSpan)) {
|
|
2953
|
-
const targetSpans = fromSlateValue([
|
|
2862
|
+
const targetSpans = fromSlateValue([{
|
|
2863
|
+
...splitBlock,
|
|
2954
2864
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
2955
|
-
}
|
|
2865
|
+
}], textBlockName)[0].children;
|
|
2956
2866
|
patches.push(insert(targetSpans, "after", [{
|
|
2957
2867
|
_key: splitBlock._key
|
|
2958
2868
|
}, "children", {
|
|
@@ -2988,7 +2898,7 @@ function createOperationToPatches(types) {
|
|
|
2988
2898
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2989
2899
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
2990
2900
|
if (operation.path.length === 1)
|
|
2991
|
-
if (block
|
|
2901
|
+
if (block?._key) {
|
|
2992
2902
|
const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
|
|
2993
2903
|
patches.push(set(newBlock, [{
|
|
2994
2904
|
_key: newBlock._key
|
|
@@ -3260,7 +3170,6 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3260
3170
|
apply: apply2
|
|
3261
3171
|
} = editor;
|
|
3262
3172
|
return editor.apply = (operation) => {
|
|
3263
|
-
var _a;
|
|
3264
3173
|
if (editorActor.getSnapshot().matches({
|
|
3265
3174
|
"edit mode": "read only"
|
|
3266
3175
|
})) {
|
|
@@ -3275,19 +3184,11 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3275
3184
|
apply2(operation);
|
|
3276
3185
|
return;
|
|
3277
3186
|
}
|
|
3278
|
-
const rows =
|
|
3187
|
+
const rows = editorActor.getSnapshot().context.maxBlocks ?? -1;
|
|
3279
3188
|
rows > 0 && editor.children.length >= rows && (operation.type === "insert_node" || operation.type === "split_node") && operation.path.length === 1 || apply2(operation);
|
|
3280
3189
|
}, editor;
|
|
3281
3190
|
};
|
|
3282
3191
|
}
|
|
3283
|
-
var __defProp$k = Object.defineProperty, __defProps$e = Object.defineProperties, __getOwnPropDescs$e = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$k = Object.getOwnPropertySymbols, __hasOwnProp$k = Object.prototype.hasOwnProperty, __propIsEnum$k = Object.prototype.propertyIsEnumerable, __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$k = (a, b) => {
|
|
3284
|
-
for (var prop in b || (b = {}))
|
|
3285
|
-
__hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3286
|
-
if (__getOwnPropSymbols$k)
|
|
3287
|
-
for (var prop of __getOwnPropSymbols$k(b))
|
|
3288
|
-
__propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3289
|
-
return a;
|
|
3290
|
-
}, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
3291
3192
|
function createWithObjectKeys(editorActor, schemaTypes) {
|
|
3292
3193
|
return function(editor) {
|
|
3293
3194
|
const {
|
|
@@ -3304,19 +3205,23 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3304
3205
|
return;
|
|
3305
3206
|
}
|
|
3306
3207
|
if (operation.type === "split_node") {
|
|
3307
|
-
apply2(
|
|
3308
|
-
|
|
3208
|
+
apply2({
|
|
3209
|
+
...operation,
|
|
3210
|
+
properties: {
|
|
3211
|
+
...operation.properties,
|
|
3309
3212
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3310
|
-
}
|
|
3311
|
-
})
|
|
3213
|
+
}
|
|
3214
|
+
});
|
|
3312
3215
|
return;
|
|
3313
3216
|
}
|
|
3314
3217
|
if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
|
|
3315
|
-
apply2(
|
|
3316
|
-
|
|
3218
|
+
apply2({
|
|
3219
|
+
...operation,
|
|
3220
|
+
node: {
|
|
3221
|
+
...operation.node,
|
|
3317
3222
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3318
|
-
}
|
|
3319
|
-
})
|
|
3223
|
+
}
|
|
3224
|
+
});
|
|
3320
3225
|
return;
|
|
3321
3226
|
}
|
|
3322
3227
|
apply2(operation);
|
|
@@ -3353,22 +3258,6 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3353
3258
|
}, editor;
|
|
3354
3259
|
};
|
|
3355
3260
|
}
|
|
3356
|
-
var __defProp$j = Object.defineProperty, __defProps$d = Object.defineProperties, __getOwnPropDescs$d = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$j = Object.getOwnPropertySymbols, __hasOwnProp$j = Object.prototype.hasOwnProperty, __propIsEnum$j = Object.prototype.propertyIsEnumerable, __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$j = (a, b) => {
|
|
3357
|
-
for (var prop in b || (b = {}))
|
|
3358
|
-
__hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3359
|
-
if (__getOwnPropSymbols$j)
|
|
3360
|
-
for (var prop of __getOwnPropSymbols$j(b))
|
|
3361
|
-
__propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3362
|
-
return a;
|
|
3363
|
-
}, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
|
|
3364
|
-
var target = {};
|
|
3365
|
-
for (var prop in source)
|
|
3366
|
-
__hasOwnProp$j.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
3367
|
-
if (source != null && __getOwnPropSymbols$j)
|
|
3368
|
-
for (var prop of __getOwnPropSymbols$j(source))
|
|
3369
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$j.call(source, prop) && (target[prop] = source[prop]);
|
|
3370
|
-
return target;
|
|
3371
|
-
};
|
|
3372
3261
|
const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
|
|
3373
3262
|
function createApplyPatch(schemaTypes) {
|
|
3374
3263
|
return (editor, patch) => {
|
|
@@ -3458,9 +3347,10 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3458
3347
|
} = patch;
|
|
3459
3348
|
if (!targetChild || !targetChildPath)
|
|
3460
3349
|
return debug$f("Child not found"), !1;
|
|
3461
|
-
const childrenToInsert = targetBlock && toSlateValue([
|
|
3350
|
+
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3351
|
+
...targetBlock,
|
|
3462
3352
|
children: items
|
|
3463
|
-
}
|
|
3353
|
+
}], {
|
|
3464
3354
|
schemaTypes
|
|
3465
3355
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3466
3356
|
return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
@@ -3505,19 +3395,21 @@ function setPatch(editor, patch) {
|
|
|
3505
3395
|
return !0;
|
|
3506
3396
|
} else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3507
3397
|
debug$f("Setting block property");
|
|
3508
|
-
const
|
|
3509
|
-
children
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3398
|
+
const {
|
|
3399
|
+
children,
|
|
3400
|
+
...nextRest
|
|
3401
|
+
} = value, {
|
|
3402
|
+
children: prevChildren,
|
|
3403
|
+
...prevRest
|
|
3404
|
+
} = block || {
|
|
3513
3405
|
children: void 0
|
|
3514
|
-
}
|
|
3515
|
-
"children"
|
|
3516
|
-
]);
|
|
3406
|
+
};
|
|
3517
3407
|
editor.apply({
|
|
3518
3408
|
type: "set_node",
|
|
3519
3409
|
path: blockPath,
|
|
3520
|
-
properties:
|
|
3410
|
+
properties: {
|
|
3411
|
+
...prevRest
|
|
3412
|
+
},
|
|
3521
3413
|
newProperties: nextRest
|
|
3522
3414
|
}), debug$f("Setting children"), block.children.forEach((c2, cIndex) => {
|
|
3523
3415
|
editor.apply({
|
|
@@ -3534,9 +3426,10 @@ function setPatch(editor, patch) {
|
|
|
3534
3426
|
});
|
|
3535
3427
|
} else if (block && "value" in block) {
|
|
3536
3428
|
const newVal = applyAll([block.value], [patch])[0];
|
|
3537
|
-
return Transforms.setNodes(editor,
|
|
3429
|
+
return Transforms.setNodes(editor, {
|
|
3430
|
+
...block,
|
|
3538
3431
|
value: newVal
|
|
3539
|
-
}
|
|
3432
|
+
}, {
|
|
3540
3433
|
at: blockPath
|
|
3541
3434
|
}), !0;
|
|
3542
3435
|
}
|
|
@@ -3619,7 +3512,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3619
3512
|
block,
|
|
3620
3513
|
child,
|
|
3621
3514
|
blockPath,
|
|
3622
|
-
childPath: blockPath
|
|
3515
|
+
childPath: blockPath?.concat(childIndex)
|
|
3623
3516
|
} : {
|
|
3624
3517
|
block,
|
|
3625
3518
|
blockPath,
|
|
@@ -3627,14 +3520,6 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3627
3520
|
childPath: void 0
|
|
3628
3521
|
};
|
|
3629
3522
|
}
|
|
3630
|
-
var __defProp$i = Object.defineProperty, __defProps$c = Object.defineProperties, __getOwnPropDescs$c = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$i = Object.getOwnPropertySymbols, __hasOwnProp$i = Object.prototype.hasOwnProperty, __propIsEnum$i = Object.prototype.propertyIsEnumerable, __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$i = (a, b) => {
|
|
3631
|
-
for (var prop in b || (b = {}))
|
|
3632
|
-
__hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3633
|
-
if (__getOwnPropSymbols$i)
|
|
3634
|
-
for (var prop of __getOwnPropSymbols$i(b))
|
|
3635
|
-
__propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3636
|
-
return a;
|
|
3637
|
-
}, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
3638
3523
|
const debug$e = debugWithName("plugin:withPatches");
|
|
3639
3524
|
function createWithPatches({
|
|
3640
3525
|
editorActor,
|
|
@@ -3719,9 +3604,10 @@ function createWithPatches({
|
|
|
3719
3604
|
})), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0 && patches.forEach((patch) => {
|
|
3720
3605
|
editorActor.send({
|
|
3721
3606
|
type: "patch",
|
|
3722
|
-
patch:
|
|
3607
|
+
patch: {
|
|
3608
|
+
...patch,
|
|
3723
3609
|
origin: "local"
|
|
3724
|
-
}
|
|
3610
|
+
}
|
|
3725
3611
|
});
|
|
3726
3612
|
}), editor;
|
|
3727
3613
|
}, editor;
|
|
@@ -3834,14 +3720,6 @@ function getNextSpan({
|
|
|
3834
3720
|
}
|
|
3835
3721
|
return nextSpan;
|
|
3836
3722
|
}
|
|
3837
|
-
var __defProp$h = Object.defineProperty, __defProps$b = Object.defineProperties, __getOwnPropDescs$b = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$h = Object.getOwnPropertySymbols, __hasOwnProp$h = Object.prototype.hasOwnProperty, __propIsEnum$h = Object.prototype.propertyIsEnumerable, __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$h = (a, b) => {
|
|
3838
|
-
for (var prop in b || (b = {}))
|
|
3839
|
-
__hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3840
|
-
if (__getOwnPropSymbols$h)
|
|
3841
|
-
for (var prop of __getOwnPropSymbols$h(b))
|
|
3842
|
-
__propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3843
|
-
return a;
|
|
3844
|
-
}, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
|
|
3845
3723
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
3846
3724
|
function createWithPortableTextMarkModel(editorActor, types) {
|
|
3847
3725
|
return function(editor) {
|
|
@@ -3850,19 +3728,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3850
3728
|
normalizeNode
|
|
3851
3729
|
} = editor, decorators = types.decorators.map((t) => t.value);
|
|
3852
3730
|
return editor.normalizeNode = (nodeEntry) => {
|
|
3853
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3854
3731
|
const [node, path] = nodeEntry;
|
|
3855
3732
|
if (editor.isTextBlock(node)) {
|
|
3856
3733
|
const children = Node.children(editor, path);
|
|
3857
3734
|
for (const [child, childPath] of children) {
|
|
3858
3735
|
const nextNode = node.children[childPath[1] + 1];
|
|
3859
|
-
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && (
|
|
3860
|
-
var _a2;
|
|
3861
|
-
return (_a2 = nextNode.marks) == null ? void 0 : _a2.includes(mark);
|
|
3862
|
-
}) && (_b = nextNode.marks) != null && _b.every((mark) => {
|
|
3863
|
-
var _a2;
|
|
3864
|
-
return (_a2 = child.marks) == null ? void 0 : _a2.includes(mark);
|
|
3865
|
-
})) {
|
|
3736
|
+
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3866
3737
|
debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3867
3738
|
type: "normalizing"
|
|
3868
3739
|
}), Transforms.mergeNodes(editor, {
|
|
@@ -3900,12 +3771,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3900
3771
|
return;
|
|
3901
3772
|
}
|
|
3902
3773
|
if (editor.isTextSpan(node)) {
|
|
3903
|
-
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations =
|
|
3774
|
+
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3904
3775
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3905
3776
|
debug$b("Removing annotations from empty span node"), editorActor.send({
|
|
3906
3777
|
type: "normalizing"
|
|
3907
3778
|
}), Transforms.setNodes(editor, {
|
|
3908
|
-
marks:
|
|
3779
|
+
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
3909
3780
|
}, {
|
|
3910
3781
|
at: path
|
|
3911
3782
|
}), editorActor.send({
|
|
@@ -3918,10 +3789,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3918
3789
|
const decorators2 = types.decorators.map((decorator) => decorator.value);
|
|
3919
3790
|
for (const [child, childPath] of Node.children(editor, path))
|
|
3920
3791
|
if (editor.isTextSpan(child)) {
|
|
3921
|
-
const marks =
|
|
3922
|
-
var _a2;
|
|
3923
|
-
return !decorators2.includes(mark) && !((_a2 = node.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3924
|
-
});
|
|
3792
|
+
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3925
3793
|
if (orphanedAnnotations.length > 0) {
|
|
3926
3794
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3927
3795
|
type: "normalizing"
|
|
@@ -3939,10 +3807,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3939
3807
|
if (editor.isTextSpan(node)) {
|
|
3940
3808
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath);
|
|
3941
3809
|
if (editor.isTextBlock(block)) {
|
|
3942
|
-
const decorators2 = types.decorators.map((decorator) => decorator.value), marks =
|
|
3943
|
-
var _a2;
|
|
3944
|
-
return !decorators2.includes(mark) && !((_a2 = block.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3945
|
-
});
|
|
3810
|
+
const decorators2 = types.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3946
3811
|
if (orphanedAnnotations.length > 0) {
|
|
3947
3812
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3948
3813
|
type: "normalizing"
|
|
@@ -3958,7 +3823,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3958
3823
|
}
|
|
3959
3824
|
}
|
|
3960
3825
|
if (editor.isTextBlock(node)) {
|
|
3961
|
-
const markDefs =
|
|
3826
|
+
const markDefs = node.markDefs ?? [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
|
|
3962
3827
|
for (const markDef of markDefs)
|
|
3963
3828
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3964
3829
|
if (markDefs.length !== newMarkDefs.length) {
|
|
@@ -3991,7 +3856,6 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3991
3856
|
}
|
|
3992
3857
|
normalizeNode(nodeEntry);
|
|
3993
3858
|
}, editor.apply = (op) => {
|
|
3994
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
3995
3859
|
if (isChangingRemotely(editor)) {
|
|
3996
3860
|
apply2(op);
|
|
3997
3861
|
return;
|
|
@@ -4009,17 +3873,17 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4009
3873
|
focus: op.newProperties.focus
|
|
4010
3874
|
});
|
|
4011
3875
|
if (previousSelectionIsCollapsed && newSelectionIsCollapsed) {
|
|
4012
|
-
const focusSpan =
|
|
3876
|
+
const focusSpan = Array.from(Editor.nodes(editor, {
|
|
4013
3877
|
mode: "lowest",
|
|
4014
3878
|
at: op.properties.focus,
|
|
4015
3879
|
match: (n) => editor.isTextSpan(n),
|
|
4016
3880
|
voids: !1
|
|
4017
|
-
}))[0]
|
|
3881
|
+
}))[0]?.[0], newFocusSpan = Array.from(Editor.nodes(editor, {
|
|
4018
3882
|
mode: "lowest",
|
|
4019
3883
|
at: op.newProperties.focus,
|
|
4020
3884
|
match: (n) => editor.isTextSpan(n),
|
|
4021
3885
|
voids: !1
|
|
4022
|
-
}))[0]
|
|
3886
|
+
}))[0]?.[0], movedToNextSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] + 1 && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] - 1 && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
|
|
4023
3887
|
if (movedToNextSpan || movedToPreviousSpan)
|
|
4024
3888
|
return;
|
|
4025
3889
|
}
|
|
@@ -4035,29 +3899,32 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4035
3899
|
editor,
|
|
4036
3900
|
blockPath,
|
|
4037
3901
|
spanPath: op.path
|
|
4038
|
-
}), previousSpanAnnotations = previousSpan ?
|
|
3902
|
+
}), previousSpanAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], nextSpan = getNextSpan({
|
|
4039
3903
|
editor,
|
|
4040
3904
|
blockPath,
|
|
4041
3905
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
4042
|
-
}), nextSpanAnnotations = nextSpan ?
|
|
4043
|
-
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4044
|
-
Transforms.insertNodes(editor,
|
|
4045
|
-
|
|
4046
|
-
|
|
3906
|
+
}), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [], atTheEndOfAnnotation = annotationsEnding.length > 0;
|
|
3907
|
+
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
|
|
3908
|
+
Transforms.insertNodes(editor, {
|
|
3909
|
+
...op.node,
|
|
3910
|
+
marks: op.node.marks?.filter((mark) => !annotationsEnding.includes(mark)) ?? []
|
|
3911
|
+
});
|
|
4047
3912
|
return;
|
|
4048
3913
|
}
|
|
4049
|
-
const annotationsStarting =
|
|
4050
|
-
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4051
|
-
Transforms.insertNodes(editor,
|
|
4052
|
-
|
|
4053
|
-
|
|
3914
|
+
const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3915
|
+
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
|
|
3916
|
+
Transforms.insertNodes(editor, {
|
|
3917
|
+
...op.node,
|
|
3918
|
+
marks: op.node.marks?.filter((mark) => !annotationsStarting.includes(mark)) ?? []
|
|
3919
|
+
});
|
|
4054
3920
|
return;
|
|
4055
3921
|
}
|
|
4056
|
-
const nextSpanDecorators =
|
|
4057
|
-
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4058
|
-
Transforms.insertNodes(editor,
|
|
3922
|
+
const nextSpanDecorators = nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? [];
|
|
3923
|
+
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.length === 0) {
|
|
3924
|
+
Transforms.insertNodes(editor, {
|
|
3925
|
+
...op.node,
|
|
4059
3926
|
marks: nextSpanDecorators
|
|
4060
|
-
})
|
|
3927
|
+
});
|
|
4061
3928
|
return;
|
|
4062
3929
|
}
|
|
4063
3930
|
}
|
|
@@ -4069,12 +3936,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4069
3936
|
if (selection && collapsedSelection) {
|
|
4070
3937
|
const [_block, blockPath] = Editor.node(editor, selection, {
|
|
4071
3938
|
depth: 1
|
|
4072
|
-
}), [span, spanPath] =
|
|
3939
|
+
}), [span, spanPath] = Array.from(Editor.nodes(editor, {
|
|
4073
3940
|
mode: "lowest",
|
|
4074
3941
|
at: selection.focus,
|
|
4075
3942
|
match: (n) => editor.isTextSpan(n),
|
|
4076
3943
|
voids: !1
|
|
4077
|
-
}))[0]
|
|
3944
|
+
}))[0] ?? [void 0, void 0], marks = span.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = selection.anchor.offset === 0, atTheEndOfSpan = selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
|
|
4078
3945
|
editor,
|
|
4079
3946
|
blockPath,
|
|
4080
3947
|
spanPath
|
|
@@ -4082,7 +3949,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4082
3949
|
editor,
|
|
4083
3950
|
blockPath,
|
|
4084
3951
|
spanPath
|
|
4085
|
-
}), nextSpanAnnotations =
|
|
3952
|
+
}), nextSpanAnnotations = nextSpan?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
|
|
4086
3953
|
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4087
3954
|
if (atTheBeginningOfSpan) {
|
|
4088
3955
|
if (previousSpanHasSameMarks) {
|
|
@@ -4090,7 +3957,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4090
3957
|
_type: "span",
|
|
4091
3958
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4092
3959
|
text: op.text,
|
|
4093
|
-
marks:
|
|
3960
|
+
marks: previousSpan?.marks ?? []
|
|
4094
3961
|
});
|
|
4095
3962
|
return;
|
|
4096
3963
|
} else if (previousSpanHasSameAnnotations) {
|
|
@@ -4098,7 +3965,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4098
3965
|
_type: "span",
|
|
4099
3966
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4100
3967
|
text: op.text,
|
|
4101
|
-
marks:
|
|
3968
|
+
marks: previousSpan?.marks ?? []
|
|
4102
3969
|
});
|
|
4103
3970
|
return;
|
|
4104
3971
|
} else if (previousSpanHasSameAnnotation) {
|
|
@@ -4120,7 +3987,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4120
3987
|
_type: "span",
|
|
4121
3988
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4122
3989
|
text: op.text,
|
|
4123
|
-
marks:
|
|
3990
|
+
marks: nextSpan?.marks ?? []
|
|
4124
3991
|
});
|
|
4125
3992
|
return;
|
|
4126
3993
|
}
|
|
@@ -4140,7 +4007,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4140
4007
|
_type: "span",
|
|
4141
4008
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4142
4009
|
text: op.text,
|
|
4143
|
-
marks: previousSpanHasAnnotations ? [] : (
|
|
4010
|
+
marks: previousSpanHasAnnotations ? [] : (previousSpan.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
4144
4011
|
});
|
|
4145
4012
|
return;
|
|
4146
4013
|
}
|
|
@@ -4153,7 +4020,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4153
4020
|
if (selection && Range.isExpanded(selection)) {
|
|
4154
4021
|
const [block, blockPath] = Editor.node(editor, selection, {
|
|
4155
4022
|
depth: 1
|
|
4156
|
-
}), [span, spanPath] =
|
|
4023
|
+
}), [span, spanPath] = Array.from(Editor.nodes(editor, {
|
|
4157
4024
|
mode: "lowest",
|
|
4158
4025
|
at: {
|
|
4159
4026
|
path: op.path,
|
|
@@ -4161,9 +4028,9 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4161
4028
|
},
|
|
4162
4029
|
match: (n) => editor.isTextSpan(n),
|
|
4163
4030
|
voids: !1
|
|
4164
|
-
}))[0]
|
|
4031
|
+
}))[0] ?? [void 0, void 0];
|
|
4165
4032
|
if (span && block && isPortableTextBlock(block)) {
|
|
4166
|
-
const markDefs =
|
|
4033
|
+
const markDefs = block.markDefs ?? [], marks = span.marks ?? [], spanHasAnnotations = marks.some((mark) => markDefs.find((markDef) => markDef._key === mark)), deletingFromTheEnd = op.offset + op.text.length === span.text.length, deletingAllText = op.offset === 0 && deletingFromTheEnd, previousSpan = getPreviousSpan({
|
|
4167
4034
|
editor,
|
|
4168
4035
|
blockPath,
|
|
4169
4036
|
spanPath
|
|
@@ -4171,9 +4038,11 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4171
4038
|
editor,
|
|
4172
4039
|
blockPath,
|
|
4173
4040
|
spanPath
|
|
4174
|
-
}), previousSpanHasSameAnnotation = previousSpan ?
|
|
4041
|
+
}), previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? nextSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
|
|
4175
4042
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
4176
|
-
const marksWithoutAnnotationMarks = (
|
|
4043
|
+
const marksWithoutAnnotationMarks = ({
|
|
4044
|
+
...Editor.marks(editor) || {}
|
|
4045
|
+
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
4177
4046
|
Editor.withoutNormalizing(editor, () => {
|
|
4178
4047
|
apply2(op), Transforms.setNodes(editor, {
|
|
4179
4048
|
marks: marksWithoutAnnotationMarks
|
|
@@ -4206,7 +4075,6 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4206
4075
|
const addDecoratorActionImplementation = ({
|
|
4207
4076
|
action
|
|
4208
4077
|
}) => {
|
|
4209
|
-
var _a;
|
|
4210
4078
|
const editor = action.editor, mark = action.decorator;
|
|
4211
4079
|
if (editor.selection) {
|
|
4212
4080
|
if (Range.isExpanded(editor.selection)) {
|
|
@@ -4219,10 +4087,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4219
4087
|
at: editor.selection,
|
|
4220
4088
|
match: Text.isText
|
|
4221
4089
|
})] : [];
|
|
4222
|
-
splitTextNodes.length > 1 && splitTextNodes.every((node) => {
|
|
4223
|
-
var _a2;
|
|
4224
|
-
return (_a2 = node[0].marks) == null ? void 0 : _a2.includes(mark);
|
|
4225
|
-
}) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4090
|
+
splitTextNodes.length > 1 && splitTextNodes.every((node) => node[0].marks?.includes(mark)) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4226
4091
|
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
4227
4092
|
Transforms.setNodes(editor, {
|
|
4228
4093
|
marks
|
|
@@ -4238,7 +4103,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4238
4103
|
depth: 1
|
|
4239
4104
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4240
4105
|
if (lonelyEmptySpan) {
|
|
4241
|
-
const existingMarks =
|
|
4106
|
+
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
4242
4107
|
Transforms.setNodes(editor, {
|
|
4243
4108
|
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
4244
4109
|
}, {
|
|
@@ -4246,9 +4111,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4246
4111
|
match: (node) => editor.isTextSpan(node)
|
|
4247
4112
|
});
|
|
4248
4113
|
} else {
|
|
4249
|
-
const existingMarks =
|
|
4114
|
+
const existingMarks = {
|
|
4115
|
+
...Editor.marks(editor) || {}
|
|
4116
|
+
}.marks || [], marks = {
|
|
4117
|
+
...Editor.marks(editor) || {},
|
|
4250
4118
|
marks: [...existingMarks, mark]
|
|
4251
|
-
}
|
|
4119
|
+
};
|
|
4252
4120
|
editor.marks = marks;
|
|
4253
4121
|
}
|
|
4254
4122
|
}
|
|
@@ -4257,7 +4125,6 @@ const addDecoratorActionImplementation = ({
|
|
|
4257
4125
|
}, removeDecoratorActionImplementation = ({
|
|
4258
4126
|
action
|
|
4259
4127
|
}) => {
|
|
4260
|
-
var _a;
|
|
4261
4128
|
const editor = action.editor, mark = action.decorator, {
|
|
4262
4129
|
selection
|
|
4263
4130
|
} = editor;
|
|
@@ -4284,7 +4151,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4284
4151
|
depth: 1
|
|
4285
4152
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4286
4153
|
if (lonelyEmptySpan) {
|
|
4287
|
-
const existingMarksWithoutDecorator = (
|
|
4154
|
+
const existingMarksWithoutDecorator = (lonelyEmptySpan.marks ?? []).filter((existingMark) => existingMark !== mark);
|
|
4288
4155
|
Transforms.setNodes(editor, {
|
|
4289
4156
|
marks: existingMarksWithoutDecorator
|
|
4290
4157
|
}, {
|
|
@@ -4292,9 +4159,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4292
4159
|
match: (node) => editor.isTextSpan(node)
|
|
4293
4160
|
});
|
|
4294
4161
|
} else {
|
|
4295
|
-
const existingMarks =
|
|
4162
|
+
const existingMarks = {
|
|
4163
|
+
...Editor.marks(editor) || {}
|
|
4164
|
+
}.marks || [], marks = {
|
|
4165
|
+
...Editor.marks(editor) || {},
|
|
4296
4166
|
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
4297
|
-
}
|
|
4167
|
+
};
|
|
4298
4168
|
editor.marks = {
|
|
4299
4169
|
marks: marks.marks,
|
|
4300
4170
|
_type: "span"
|
|
@@ -4313,10 +4183,11 @@ function isDecoratorActive({
|
|
|
4313
4183
|
at: editor.selection
|
|
4314
4184
|
}));
|
|
4315
4185
|
return selectedTextNodes.length === 0 ? !1 : Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
|
|
4316
|
-
var _a;
|
|
4317
4186
|
const [node] = n;
|
|
4318
|
-
return
|
|
4319
|
-
}) : (
|
|
4187
|
+
return node.marks?.includes(decorator);
|
|
4188
|
+
}) : ({
|
|
4189
|
+
...Editor.marks(editor) || {}
|
|
4190
|
+
}.marks || []).includes(decorator);
|
|
4320
4191
|
}
|
|
4321
4192
|
const toggleDecoratorActionImplementation = ({
|
|
4322
4193
|
context,
|
|
@@ -4376,14 +4247,6 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
4376
4247
|
}, editor;
|
|
4377
4248
|
};
|
|
4378
4249
|
}
|
|
4379
|
-
var __defProp$g = Object.defineProperty, __defProps$a = Object.defineProperties, __getOwnPropDescs$a = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$g = Object.getOwnPropertySymbols, __hasOwnProp$g = Object.prototype.hasOwnProperty, __propIsEnum$g = Object.prototype.propertyIsEnumerable, __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$g = (a, b) => {
|
|
4380
|
-
for (var prop in b || (b = {}))
|
|
4381
|
-
__hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4382
|
-
if (__getOwnPropSymbols$g)
|
|
4383
|
-
for (var prop of __getOwnPropSymbols$g(b))
|
|
4384
|
-
__propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4385
|
-
return a;
|
|
4386
|
-
}, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
4387
4250
|
const debug$9 = debugWithName("plugin:withSchemaTypes");
|
|
4388
4251
|
function createWithSchemaTypes({
|
|
4389
4252
|
editorActor,
|
|
@@ -4401,10 +4264,11 @@ function createWithSchemaTypes({
|
|
|
4401
4264
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4402
4265
|
editorActor.send({
|
|
4403
4266
|
type: "normalizing"
|
|
4404
|
-
}), Transforms.setNodes(editor,
|
|
4267
|
+
}), Transforms.setNodes(editor, {
|
|
4268
|
+
...span,
|
|
4405
4269
|
_type: schemaTypes.span.name,
|
|
4406
4270
|
_key: key
|
|
4407
|
-
}
|
|
4271
|
+
}, {
|
|
4408
4272
|
at: path
|
|
4409
4273
|
}), editorActor.send({
|
|
4410
4274
|
type: "done normalizing"
|
|
@@ -4429,14 +4293,6 @@ function createWithSchemaTypes({
|
|
|
4429
4293
|
}, editor;
|
|
4430
4294
|
};
|
|
4431
4295
|
}
|
|
4432
|
-
var __defProp$f = Object.defineProperty, __defProps$9 = Object.defineProperties, __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$f = Object.getOwnPropertySymbols, __hasOwnProp$f = Object.prototype.hasOwnProperty, __propIsEnum$f = Object.prototype.propertyIsEnumerable, __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$f = (a, b) => {
|
|
4433
|
-
for (var prop in b || (b = {}))
|
|
4434
|
-
__hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4435
|
-
if (__getOwnPropSymbols$f)
|
|
4436
|
-
for (var prop of __getOwnPropSymbols$f(b))
|
|
4437
|
-
__propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4438
|
-
return a;
|
|
4439
|
-
}, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
4440
4296
|
const debug$8 = debugWithName("plugin:withUtils");
|
|
4441
4297
|
function createWithUtils({
|
|
4442
4298
|
editorActor,
|
|
@@ -4460,26 +4316,29 @@ function createWithUtils({
|
|
|
4460
4316
|
} = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
|
|
4461
4317
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4462
4318
|
debug$8("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
|
|
4463
|
-
anchor:
|
|
4319
|
+
anchor: {
|
|
4320
|
+
...selection.anchor,
|
|
4464
4321
|
offset: newStartOffset
|
|
4465
|
-
}
|
|
4466
|
-
focus:
|
|
4322
|
+
},
|
|
4323
|
+
focus: {
|
|
4324
|
+
...selection.focus,
|
|
4467
4325
|
offset: newEndOffset
|
|
4468
|
-
}
|
|
4326
|
+
}
|
|
4469
4327
|
});
|
|
4470
4328
|
return;
|
|
4471
4329
|
}
|
|
4472
4330
|
debug$8("pteExpandToWord: Can't expand to word here");
|
|
4473
4331
|
}
|
|
4474
|
-
}, editor.pteCreateTextBlock = (options) => toSlateValue([
|
|
4332
|
+
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4475
4333
|
_type: schemaTypes.block.name,
|
|
4476
4334
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4477
|
-
style: schemaTypes.styles[0].value || "normal"
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4335
|
+
style: schemaTypes.styles[0].value || "normal",
|
|
4336
|
+
...options.listItem ? {
|
|
4337
|
+
listItem: options.listItem
|
|
4338
|
+
} : {},
|
|
4339
|
+
...options.level ? {
|
|
4340
|
+
level: options.level
|
|
4341
|
+
} : {},
|
|
4483
4342
|
markDefs: [],
|
|
4484
4343
|
children: [{
|
|
4485
4344
|
_type: "span",
|
|
@@ -4489,7 +4348,7 @@ function createWithUtils({
|
|
|
4489
4348
|
value
|
|
4490
4349
|
}) => value === decorator))
|
|
4491
4350
|
}]
|
|
4492
|
-
}
|
|
4351
|
+
}], {
|
|
4493
4352
|
schemaTypes
|
|
4494
4353
|
})[0], editor;
|
|
4495
4354
|
};
|
|
@@ -4535,14 +4394,6 @@ function createSlateEditor(config) {
|
|
|
4535
4394
|
};
|
|
4536
4395
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4537
4396
|
}
|
|
4538
|
-
var __defProp$e = Object.defineProperty, __defProps$8 = Object.defineProperties, __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$e = Object.getOwnPropertySymbols, __hasOwnProp$e = Object.prototype.hasOwnProperty, __propIsEnum$e = Object.prototype.propertyIsEnumerable, __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$e = (a, b) => {
|
|
4539
|
-
for (var prop in b || (b = {}))
|
|
4540
|
-
__hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4541
|
-
if (__getOwnPropSymbols$e)
|
|
4542
|
-
for (var prop of __getOwnPropSymbols$e(b))
|
|
4543
|
-
__propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4544
|
-
return a;
|
|
4545
|
-
}, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
4546
4397
|
const toggleListItemActionImplementation = ({
|
|
4547
4398
|
context,
|
|
4548
4399
|
action
|
|
@@ -4552,14 +4403,16 @@ const toggleListItemActionImplementation = ({
|
|
|
4552
4403
|
listItem: action.listItem
|
|
4553
4404
|
}) ? removeListItemActionImplementation({
|
|
4554
4405
|
context,
|
|
4555
|
-
action:
|
|
4406
|
+
action: {
|
|
4407
|
+
...action,
|
|
4556
4408
|
type: "list item.remove"
|
|
4557
|
-
}
|
|
4409
|
+
}
|
|
4558
4410
|
}) : addListItemActionImplementation({
|
|
4559
4411
|
context,
|
|
4560
|
-
action:
|
|
4412
|
+
action: {
|
|
4413
|
+
...action,
|
|
4561
4414
|
type: "list item.add"
|
|
4562
|
-
}
|
|
4415
|
+
}
|
|
4563
4416
|
});
|
|
4564
4417
|
}, removeListItemActionImplementation = ({
|
|
4565
4418
|
context,
|
|
@@ -4605,14 +4458,6 @@ function isListItemActive({
|
|
|
4605
4458
|
})];
|
|
4606
4459
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
4607
4460
|
}
|
|
4608
|
-
var __defProp$d = Object.defineProperty, __defProps$7 = Object.defineProperties, __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$d = Object.getOwnPropertySymbols, __hasOwnProp$d = Object.prototype.hasOwnProperty, __propIsEnum$d = Object.prototype.propertyIsEnumerable, __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$d = (a, b) => {
|
|
4609
|
-
for (var prop in b || (b = {}))
|
|
4610
|
-
__hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4611
|
-
if (__getOwnPropSymbols$d)
|
|
4612
|
-
for (var prop of __getOwnPropSymbols$d(b))
|
|
4613
|
-
__propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4614
|
-
return a;
|
|
4615
|
-
}, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
4616
4461
|
const toggleStyleActionImplementation = ({
|
|
4617
4462
|
context,
|
|
4618
4463
|
action
|
|
@@ -4622,14 +4467,16 @@ const toggleStyleActionImplementation = ({
|
|
|
4622
4467
|
style: action.style
|
|
4623
4468
|
}) ? removeStyleActionImplementation({
|
|
4624
4469
|
context,
|
|
4625
|
-
action:
|
|
4470
|
+
action: {
|
|
4471
|
+
...action,
|
|
4626
4472
|
type: "style.remove"
|
|
4627
|
-
}
|
|
4473
|
+
}
|
|
4628
4474
|
}) : addStyleActionImplementation({
|
|
4629
4475
|
context,
|
|
4630
|
-
action:
|
|
4476
|
+
action: {
|
|
4477
|
+
...action,
|
|
4631
4478
|
type: "style.add"
|
|
4632
|
-
}
|
|
4479
|
+
}
|
|
4633
4480
|
});
|
|
4634
4481
|
}, removeStyleActionImplementation = ({
|
|
4635
4482
|
context,
|
|
@@ -4676,14 +4523,6 @@ function isStyleActive({
|
|
|
4676
4523
|
})];
|
|
4677
4524
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
4678
4525
|
}
|
|
4679
|
-
var __defProp$c = Object.defineProperty, __getOwnPropSymbols$c = Object.getOwnPropertySymbols, __hasOwnProp$c = Object.prototype.hasOwnProperty, __propIsEnum$c = Object.prototype.propertyIsEnumerable, __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$c = (a, b) => {
|
|
4680
|
-
for (var prop in b || (b = {}))
|
|
4681
|
-
__hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4682
|
-
if (__getOwnPropSymbols$c)
|
|
4683
|
-
for (var prop of __getOwnPropSymbols$c(b))
|
|
4684
|
-
__propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4685
|
-
return a;
|
|
4686
|
-
};
|
|
4687
4526
|
const debug$6 = debugWithName("API:editable");
|
|
4688
4527
|
function createEditableAPI(editor, editorActor) {
|
|
4689
4528
|
const types = editorActor.getSnapshot().context.schema;
|
|
@@ -4746,7 +4585,9 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4746
4585
|
return console.warn(err), !1;
|
|
4747
4586
|
}
|
|
4748
4587
|
},
|
|
4749
|
-
marks: () =>
|
|
4588
|
+
marks: () => ({
|
|
4589
|
+
...Editor.marks(editor) || {}
|
|
4590
|
+
}).marks || [],
|
|
4750
4591
|
undo: () => editor.undo(),
|
|
4751
4592
|
redo: () => editor.redo(),
|
|
4752
4593
|
select: (selection) => {
|
|
@@ -4768,7 +4609,6 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4768
4609
|
}
|
|
4769
4610
|
},
|
|
4770
4611
|
insertChild: (type, value) => {
|
|
4771
|
-
var _a, _b, _c;
|
|
4772
4612
|
if (type.name !== types.span.name)
|
|
4773
4613
|
return editorActor.send({
|
|
4774
4614
|
type: "behavior event",
|
|
@@ -4780,7 +4620,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4780
4620
|
}
|
|
4781
4621
|
},
|
|
4782
4622
|
editor
|
|
4783
|
-
}),
|
|
4623
|
+
}), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path ?? [];
|
|
4784
4624
|
if (!editor.selection)
|
|
4785
4625
|
throw new Error("The editor has no selection");
|
|
4786
4626
|
const [focusBlock] = Array.from(Editor.nodes(editor, {
|
|
@@ -4794,10 +4634,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4794
4634
|
const child = toSlateValue([{
|
|
4795
4635
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4796
4636
|
_type: types.block.name,
|
|
4797
|
-
children: [
|
|
4637
|
+
children: [{
|
|
4798
4638
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4799
|
-
_type: type.name
|
|
4800
|
-
|
|
4639
|
+
_type: type.name,
|
|
4640
|
+
...value || {}
|
|
4641
|
+
}]
|
|
4801
4642
|
}], {
|
|
4802
4643
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
4803
4644
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
|
|
@@ -4807,30 +4648,27 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4807
4648
|
})), Transforms.insertNodes(editor, child, {
|
|
4808
4649
|
select: !0,
|
|
4809
4650
|
at: editor.selection
|
|
4810
|
-
}), editor.onChange(),
|
|
4651
|
+
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path || [];
|
|
4811
4652
|
},
|
|
4812
|
-
insertBlock: (type, value) => {
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
type: "
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
name: type.name,
|
|
4820
|
-
value
|
|
4821
|
-
},
|
|
4822
|
-
placement: "auto"
|
|
4653
|
+
insertBlock: (type, value) => (editorActor.send({
|
|
4654
|
+
type: "behavior event",
|
|
4655
|
+
behaviorEvent: {
|
|
4656
|
+
type: "insert.block object",
|
|
4657
|
+
blockObject: {
|
|
4658
|
+
name: type.name,
|
|
4659
|
+
value
|
|
4823
4660
|
},
|
|
4824
|
-
|
|
4825
|
-
}
|
|
4826
|
-
|
|
4661
|
+
placement: "auto"
|
|
4662
|
+
},
|
|
4663
|
+
editor
|
|
4664
|
+
}), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path ?? []),
|
|
4827
4665
|
hasBlockStyle: (style) => {
|
|
4828
4666
|
try {
|
|
4829
4667
|
return isStyleActive({
|
|
4830
4668
|
editor,
|
|
4831
4669
|
style
|
|
4832
4670
|
});
|
|
4833
|
-
} catch
|
|
4671
|
+
} catch {
|
|
4834
4672
|
return !1;
|
|
4835
4673
|
}
|
|
4836
4674
|
},
|
|
@@ -4840,7 +4678,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4840
4678
|
editor,
|
|
4841
4679
|
listItem
|
|
4842
4680
|
});
|
|
4843
|
-
} catch
|
|
4681
|
+
} catch {
|
|
4844
4682
|
return !1;
|
|
4845
4683
|
}
|
|
4846
4684
|
},
|
|
@@ -4885,12 +4723,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4885
4723
|
match: (n) => n._key === element._key
|
|
4886
4724
|
}) || [])[0] || [void 0];
|
|
4887
4725
|
node = ReactEditor.toDOMNode(editor, item);
|
|
4888
|
-
} catch
|
|
4726
|
+
} catch {
|
|
4889
4727
|
}
|
|
4890
4728
|
return node;
|
|
4891
4729
|
},
|
|
4892
4730
|
activeAnnotations: () => {
|
|
4893
|
-
var _a;
|
|
4894
4731
|
if (!editor.selection || editor.selection.focus.path.length < 2)
|
|
4895
4732
|
return [];
|
|
4896
4733
|
try {
|
|
@@ -4902,12 +4739,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4902
4739
|
const [block] = Editor.node(editor, path, {
|
|
4903
4740
|
depth: 1
|
|
4904
4741
|
});
|
|
4905
|
-
editor.isTextBlock(block) &&
|
|
4742
|
+
editor.isTextBlock(block) && block.markDefs?.forEach((def) => {
|
|
4906
4743
|
Text.isText(span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
|
|
4907
|
-
})
|
|
4744
|
+
});
|
|
4908
4745
|
}
|
|
4909
4746
|
return activeAnnotations;
|
|
4910
|
-
} catch
|
|
4747
|
+
} catch {
|
|
4911
4748
|
return [];
|
|
4912
4749
|
}
|
|
4913
4750
|
},
|
|
@@ -4929,7 +4766,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4929
4766
|
type: "annotation.add",
|
|
4930
4767
|
annotation: {
|
|
4931
4768
|
name: type.name,
|
|
4932
|
-
value: value
|
|
4769
|
+
value: value ?? {}
|
|
4933
4770
|
},
|
|
4934
4771
|
editor
|
|
4935
4772
|
}
|
|
@@ -4942,7 +4779,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4942
4779
|
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
4943
4780
|
throw new Error("Invalid range");
|
|
4944
4781
|
if (range) {
|
|
4945
|
-
if (!
|
|
4782
|
+
if (!options?.mode || options?.mode === "selected") {
|
|
4946
4783
|
debug$6("Deleting content in selection"), Transforms.delete(editor, {
|
|
4947
4784
|
at: range,
|
|
4948
4785
|
hanging: !0,
|
|
@@ -4950,11 +4787,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4950
4787
|
}), editor.onChange();
|
|
4951
4788
|
return;
|
|
4952
4789
|
}
|
|
4953
|
-
|
|
4790
|
+
options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
4954
4791
|
at: range,
|
|
4955
4792
|
voids: !0,
|
|
4956
4793
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
|
|
4957
|
-
})),
|
|
4794
|
+
})), options?.mode === "children" && (debug$6("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
4958
4795
|
at: range,
|
|
4959
4796
|
voids: !0,
|
|
4960
4797
|
match: (node) => node._type === types.span.name || // Text children
|
|
@@ -5011,26 +4848,15 @@ function isAnnotationActive({
|
|
|
5011
4848
|
at: editor.selection,
|
|
5012
4849
|
match: (node) => Text.isText(node)
|
|
5013
4850
|
})];
|
|
5014
|
-
if (spans.length === 0 || spans.some(([span]) =>
|
|
5015
|
-
var _a;
|
|
5016
|
-
return !isPortableTextSpan$1(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
|
|
5017
|
-
})) return !1;
|
|
4851
|
+
if (spans.length === 0 || spans.some(([span]) => !isPortableTextSpan$1(span) || !span.marks || span.marks?.length === 0)) return !1;
|
|
5018
4852
|
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
5019
4853
|
const [block] = Editor.node(editor, path, {
|
|
5020
4854
|
depth: 1
|
|
5021
4855
|
});
|
|
5022
4856
|
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
5023
4857
|
}, []);
|
|
5024
|
-
return spans.every(([span]) =>
|
|
5025
|
-
|
|
5026
|
-
if (!isPortableTextSpan$1(span)) return !1;
|
|
5027
|
-
const spanMarkDefs = (_a = span.marks) == null ? void 0 : _a.map((markKey) => {
|
|
5028
|
-
var _a2;
|
|
5029
|
-
return (_a2 = selectionMarkDefs.find((def) => (def == null ? void 0 : def._key) === markKey)) == null ? void 0 : _a2._type;
|
|
5030
|
-
});
|
|
5031
|
-
return spanMarkDefs == null ? void 0 : spanMarkDefs.includes(annotation.name);
|
|
5032
|
-
});
|
|
5033
|
-
} catch (e) {
|
|
4858
|
+
return spans.every(([span]) => isPortableTextSpan$1(span) ? span.marks?.map((markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type)?.includes(annotation.name) : !1);
|
|
4859
|
+
} catch {
|
|
5034
4860
|
return !1;
|
|
5035
4861
|
}
|
|
5036
4862
|
}
|
|
@@ -5038,7 +4864,6 @@ const addAnnotationActionImplementation = ({
|
|
|
5038
4864
|
context,
|
|
5039
4865
|
action
|
|
5040
4866
|
}) => {
|
|
5041
|
-
var _a, _b;
|
|
5042
4867
|
const editor = action.editor, {
|
|
5043
4868
|
selection: originalSelection
|
|
5044
4869
|
} = editor;
|
|
@@ -5056,12 +4881,13 @@ const addAnnotationActionImplementation = ({
|
|
|
5056
4881
|
for (const [block, blockPath] of selectedBlocks) {
|
|
5057
4882
|
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
5058
4883
|
continue;
|
|
5059
|
-
const annotationKey = context.keyGenerator(), markDefs =
|
|
4884
|
+
const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
|
|
5060
4885
|
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
|
|
5061
|
-
markDefs: [...markDefs,
|
|
4886
|
+
markDefs: [...markDefs, {
|
|
5062
4887
|
_type: action.annotation.name,
|
|
5063
|
-
_key: annotationKey
|
|
5064
|
-
|
|
4888
|
+
_key: annotationKey,
|
|
4889
|
+
...action.annotation.value
|
|
4890
|
+
}]
|
|
5065
4891
|
}, {
|
|
5066
4892
|
at: blockPath
|
|
5067
4893
|
}), markDefPath = [{
|
|
@@ -5076,7 +4902,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5076
4902
|
for (const [span, path] of children) {
|
|
5077
4903
|
if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
|
|
5078
4904
|
continue;
|
|
5079
|
-
const marks =
|
|
4905
|
+
const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
|
|
5080
4906
|
Transforms.setNodes(editor, {
|
|
5081
4907
|
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
5082
4908
|
}, {
|
|
@@ -5098,7 +4924,6 @@ const addAnnotationActionImplementation = ({
|
|
|
5098
4924
|
}, removeAnnotationActionImplementation = ({
|
|
5099
4925
|
action
|
|
5100
4926
|
}) => {
|
|
5101
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
5102
4927
|
const editor = action.editor;
|
|
5103
4928
|
if (debug$6("Removing annotation", action.annotation.name), !!editor.selection)
|
|
5104
4929
|
if (Range.isCollapsed(editor.selection)) {
|
|
@@ -5107,12 +4932,12 @@ const addAnnotationActionImplementation = ({
|
|
|
5107
4932
|
});
|
|
5108
4933
|
if (!editor.isTextBlock(block))
|
|
5109
4934
|
return;
|
|
5110
|
-
const potentialAnnotations = (
|
|
4935
|
+
const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = Editor.node(editor, editor.selection, {
|
|
5111
4936
|
depth: 2
|
|
5112
4937
|
});
|
|
5113
4938
|
if (!editor.isTextSpan(selectedChild))
|
|
5114
4939
|
return;
|
|
5115
|
-
const annotationToRemove =
|
|
4940
|
+
const annotationToRemove = selectedChild.marks?.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
|
|
5116
4941
|
if (!annotationToRemove)
|
|
5117
4942
|
return;
|
|
5118
4943
|
const previousSpansWithSameAnnotation = [];
|
|
@@ -5120,20 +4945,20 @@ const addAnnotationActionImplementation = ({
|
|
|
5120
4945
|
reverse: !0
|
|
5121
4946
|
}))
|
|
5122
4947
|
if (editor.isTextSpan(child) && Path.isBefore(childPath, selectedChildPath))
|
|
5123
|
-
if (
|
|
4948
|
+
if (child.marks?.includes(annotationToRemove))
|
|
5124
4949
|
previousSpansWithSameAnnotation.push([child, childPath]);
|
|
5125
4950
|
else
|
|
5126
4951
|
break;
|
|
5127
4952
|
const nextSpansWithSameAnnotation = [];
|
|
5128
4953
|
for (const [child, childPath] of Node.children(editor, blockPath))
|
|
5129
4954
|
if (editor.isTextSpan(child) && Path.isAfter(childPath, selectedChildPath))
|
|
5130
|
-
if (
|
|
4955
|
+
if (child.marks?.includes(annotationToRemove))
|
|
5131
4956
|
nextSpansWithSameAnnotation.push([child, childPath]);
|
|
5132
4957
|
else
|
|
5133
4958
|
break;
|
|
5134
4959
|
for (const [child, childPath] of [...previousSpansWithSameAnnotation, [selectedChild, selectedChildPath], ...nextSpansWithSameAnnotation])
|
|
5135
4960
|
Transforms.setNodes(editor, {
|
|
5136
|
-
marks:
|
|
4961
|
+
marks: child.marks?.filter((mark) => mark !== annotationToRemove)
|
|
5137
4962
|
}, {
|
|
5138
4963
|
at: childPath
|
|
5139
4964
|
});
|
|
@@ -5152,10 +4977,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5152
4977
|
for (const [child, childPath] of children) {
|
|
5153
4978
|
if (!editor.isTextSpan(child) || !Range.includes(editor.selection, childPath))
|
|
5154
4979
|
continue;
|
|
5155
|
-
const markDefs =
|
|
5156
|
-
const markDef = markDefs.find((markDef2) => markDef2._key === mark);
|
|
5157
|
-
return (markDef == null ? void 0 : markDef._type) !== action.annotation.name;
|
|
5158
|
-
});
|
|
4980
|
+
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== action.annotation.name);
|
|
5159
4981
|
marksWithoutAnnotation.length !== marks.length && Transforms.setNodes(editor, {
|
|
5160
4982
|
marks: marksWithoutAnnotation
|
|
5161
4983
|
}, {
|
|
@@ -5198,12 +5020,11 @@ function insertBlock({
|
|
|
5198
5020
|
editor,
|
|
5199
5021
|
schema
|
|
5200
5022
|
}) {
|
|
5201
|
-
var _a;
|
|
5202
5023
|
if (editor.selection) {
|
|
5203
|
-
const [focusBlock, focusBlockPath] =
|
|
5024
|
+
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(editor, {
|
|
5204
5025
|
at: editor.selection.focus.path.slice(0, 1),
|
|
5205
5026
|
match: (n) => !Editor.isEditor(n)
|
|
5206
|
-
}))[0]
|
|
5027
|
+
}))[0] ?? [void 0, void 0];
|
|
5207
5028
|
if (placement === "after") {
|
|
5208
5029
|
const nextPath = [focusBlockPath[0] + 1];
|
|
5209
5030
|
Transforms.insertNodes(editor, block, {
|
|
@@ -5235,22 +5056,15 @@ function insertBlock({
|
|
|
5235
5056
|
});
|
|
5236
5057
|
}
|
|
5237
5058
|
}
|
|
5238
|
-
var __defProp$b = Object.defineProperty, __getOwnPropSymbols$b = Object.getOwnPropertySymbols, __hasOwnProp$b = Object.prototype.hasOwnProperty, __propIsEnum$b = Object.prototype.propertyIsEnumerable, __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$b = (a, b) => {
|
|
5239
|
-
for (var prop in b || (b = {}))
|
|
5240
|
-
__hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5241
|
-
if (__getOwnPropSymbols$b)
|
|
5242
|
-
for (var prop of __getOwnPropSymbols$b(b))
|
|
5243
|
-
__propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5244
|
-
return a;
|
|
5245
|
-
};
|
|
5246
5059
|
const insertBlockObjectActionImplementation = ({
|
|
5247
5060
|
context,
|
|
5248
5061
|
action
|
|
5249
5062
|
}) => {
|
|
5250
|
-
const block = toSlateValue([
|
|
5063
|
+
const block = toSlateValue([{
|
|
5251
5064
|
_key: context.keyGenerator(),
|
|
5252
|
-
_type: action.blockObject.name
|
|
5253
|
-
|
|
5065
|
+
_type: action.blockObject.name,
|
|
5066
|
+
...action.blockObject.value ? action.blockObject.value : {}
|
|
5067
|
+
}], {
|
|
5254
5068
|
schemaTypes: context.schema
|
|
5255
5069
|
})[0];
|
|
5256
5070
|
insertBlock({
|
|
@@ -5259,29 +5073,19 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5259
5073
|
editor: action.editor,
|
|
5260
5074
|
schema: context.schema
|
|
5261
5075
|
});
|
|
5262
|
-
}
|
|
5263
|
-
var __defProp$a = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$a = Object.getOwnPropertySymbols, __hasOwnProp$a = Object.prototype.hasOwnProperty, __propIsEnum$a = Object.prototype.propertyIsEnumerable, __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$a = (a, b) => {
|
|
5264
|
-
for (var prop in b || (b = {}))
|
|
5265
|
-
__hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5266
|
-
if (__getOwnPropSymbols$a)
|
|
5267
|
-
for (var prop of __getOwnPropSymbols$a(b))
|
|
5268
|
-
__propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5269
|
-
return a;
|
|
5270
|
-
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
5271
|
-
const insertBreakActionImplementation = ({
|
|
5076
|
+
}, insertBreakActionImplementation = ({
|
|
5272
5077
|
context,
|
|
5273
5078
|
action
|
|
5274
5079
|
}) => {
|
|
5275
|
-
var _a, _b, _c, _d, _e;
|
|
5276
5080
|
const keyGenerator = context.keyGenerator, schema = context.schema, editor = action.editor;
|
|
5277
5081
|
if (!editor.selection)
|
|
5278
5082
|
return;
|
|
5279
|
-
const [focusSpan] =
|
|
5083
|
+
const [focusSpan] = Array.from(Editor.nodes(editor, {
|
|
5280
5084
|
mode: "lowest",
|
|
5281
5085
|
at: editor.selection.focus,
|
|
5282
5086
|
match: (n) => editor.isTextSpan(n),
|
|
5283
5087
|
voids: !1
|
|
5284
|
-
}))[0]
|
|
5088
|
+
}))[0] ?? [void 0], focusDecorators = focusSpan?.marks?.filter((mark) => schema.decorators.some((decorator) => decorator.value === mark)) ?? [], focusAnnotations = focusSpan?.marks?.filter((mark) => !schema.decorators.some((decorator) => decorator.value === mark)) ?? [], anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
|
|
5285
5089
|
if (editor.isTextBlock(focusBlock)) {
|
|
5286
5090
|
const [start, end] = Range.edges(editor.selection), lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual(start, {
|
|
5287
5091
|
path: [...focusBlockPath, focusBlock.children.length - 1],
|
|
@@ -5320,7 +5124,6 @@ const insertBreakActionImplementation = ({
|
|
|
5320
5124
|
const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0];
|
|
5321
5125
|
if (!atTheStartOfBlock && !atTheEndOfBlock && !selectionAcrossBlocks) {
|
|
5322
5126
|
Editor.withoutNormalizing(editor, () => {
|
|
5323
|
-
var _a2;
|
|
5324
5127
|
if (!editor.selection)
|
|
5325
5128
|
return;
|
|
5326
5129
|
Transforms.splitNodes(editor, {
|
|
@@ -5343,28 +5146,20 @@ const insertBreakActionImplementation = ({
|
|
|
5343
5146
|
for (const [child, childPath] of children) {
|
|
5344
5147
|
if (!editor.isTextSpan(child))
|
|
5345
5148
|
continue;
|
|
5346
|
-
const marks =
|
|
5149
|
+
const marks = child.marks ?? [];
|
|
5347
5150
|
for (const mark of marks)
|
|
5348
|
-
schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) =>
|
|
5349
|
-
|
|
5350
|
-
return (_a3 = prevNodeSpan.marks) == null ? void 0 : _a3.includes(mark);
|
|
5351
|
-
}) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
5352
|
-
const newMarks = marks.map((mark) => {
|
|
5353
|
-
var _a3;
|
|
5354
|
-
return (_a3 = newMarkDefKeys.get(mark)) != null ? _a3 : mark;
|
|
5355
|
-
});
|
|
5151
|
+
schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
5152
|
+
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
5356
5153
|
isEqual(marks, newMarks) || Transforms.setNodes(editor, {
|
|
5357
5154
|
marks: newMarks
|
|
5358
5155
|
}, {
|
|
5359
5156
|
at: childPath
|
|
5360
5157
|
});
|
|
5361
5158
|
}
|
|
5362
|
-
const newMarkDefs = nextNode.markDefs.map((markDef) => {
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
});
|
|
5367
|
-
});
|
|
5159
|
+
const newMarkDefs = nextNode.markDefs.map((markDef) => ({
|
|
5160
|
+
...markDef,
|
|
5161
|
+
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
5162
|
+
}));
|
|
5368
5163
|
isEqual(nextNode.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
|
|
5369
5164
|
markDefs: newMarkDefs
|
|
5370
5165
|
}, {
|
|
@@ -5385,24 +5180,15 @@ const insertBreakActionImplementation = ({
|
|
|
5385
5180
|
}) => {
|
|
5386
5181
|
insertBreakActionImplementation({
|
|
5387
5182
|
context,
|
|
5388
|
-
action:
|
|
5183
|
+
action: {
|
|
5184
|
+
...action,
|
|
5389
5185
|
type: "insert.break"
|
|
5390
|
-
}
|
|
5186
|
+
}
|
|
5391
5187
|
});
|
|
5392
|
-
}
|
|
5393
|
-
var __defProp$9 = Object.defineProperty, __getOwnPropSymbols$9 = Object.getOwnPropertySymbols, __hasOwnProp$9 = Object.prototype.hasOwnProperty, __propIsEnum$9 = Object.prototype.propertyIsEnumerable, __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$9 = (a, b) => {
|
|
5394
|
-
for (var prop in b || (b = {}))
|
|
5395
|
-
__hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5396
|
-
if (__getOwnPropSymbols$9)
|
|
5397
|
-
for (var prop of __getOwnPropSymbols$9(b))
|
|
5398
|
-
__propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5399
|
-
return a;
|
|
5400
|
-
};
|
|
5401
|
-
const insertInlineObjectActionImplementation = ({
|
|
5188
|
+
}, insertInlineObjectActionImplementation = ({
|
|
5402
5189
|
context,
|
|
5403
5190
|
action
|
|
5404
5191
|
}) => {
|
|
5405
|
-
var _a, _b;
|
|
5406
5192
|
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
5407
5193
|
console.error("Unable to insert unknown inline object");
|
|
5408
5194
|
return;
|
|
@@ -5411,77 +5197,60 @@ const insertInlineObjectActionImplementation = ({
|
|
|
5411
5197
|
console.error("Unable to insert inline object without selection");
|
|
5412
5198
|
return;
|
|
5413
5199
|
}
|
|
5414
|
-
const [focusTextBlock] =
|
|
5200
|
+
const [focusTextBlock] = Array.from(Editor.nodes(action.editor, {
|
|
5415
5201
|
at: action.editor.selection.focus.path,
|
|
5416
5202
|
match: (node) => action.editor.isTextBlock(node)
|
|
5417
|
-
})).at(0)
|
|
5203
|
+
})).at(0) ?? [void 0, void 0];
|
|
5418
5204
|
if (!focusTextBlock) {
|
|
5419
5205
|
console.error("Unable to perform action without focus text block");
|
|
5420
5206
|
return;
|
|
5421
5207
|
}
|
|
5422
|
-
const
|
|
5208
|
+
const child = toSlateValue([{
|
|
5423
5209
|
_type: context.schema.block.name,
|
|
5424
5210
|
_key: context.keyGenerator(),
|
|
5425
|
-
children: [
|
|
5211
|
+
children: [{
|
|
5426
5212
|
_type: action.inlineObject.name,
|
|
5427
|
-
_key: context.keyGenerator()
|
|
5428
|
-
|
|
5213
|
+
_key: context.keyGenerator(),
|
|
5214
|
+
...action.inlineObject.value ?? {}
|
|
5215
|
+
}]
|
|
5429
5216
|
}], {
|
|
5430
5217
|
schemaTypes: context.schema
|
|
5431
|
-
}).at(0)
|
|
5218
|
+
}).at(0)?.children.at(0);
|
|
5432
5219
|
if (!child) {
|
|
5433
5220
|
console.error("Unable to insert inline object");
|
|
5434
5221
|
return;
|
|
5435
5222
|
}
|
|
5436
5223
|
Transforms.insertNodes(action.editor, child);
|
|
5437
|
-
}
|
|
5438
|
-
var __defProp$8 = Object.defineProperty, __getOwnPropSymbols$8 = Object.getOwnPropertySymbols, __hasOwnProp$8 = Object.prototype.hasOwnProperty, __propIsEnum$8 = Object.prototype.propertyIsEnumerable, __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$8 = (a, b) => {
|
|
5439
|
-
for (var prop in b || (b = {}))
|
|
5440
|
-
__hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5441
|
-
if (__getOwnPropSymbols$8)
|
|
5442
|
-
for (var prop of __getOwnPropSymbols$8(b))
|
|
5443
|
-
__propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5444
|
-
return a;
|
|
5445
|
-
};
|
|
5446
|
-
const insertSpanActionImplementation = ({
|
|
5224
|
+
}, insertSpanActionImplementation = ({
|
|
5447
5225
|
context,
|
|
5448
5226
|
action
|
|
5449
5227
|
}) => {
|
|
5450
|
-
var _a, _b, _c, _d;
|
|
5451
5228
|
if (!action.editor.selection) {
|
|
5452
5229
|
console.error("Unable to perform action without selection", action);
|
|
5453
5230
|
return;
|
|
5454
5231
|
}
|
|
5455
|
-
const [focusBlock, focusBlockPath] =
|
|
5232
|
+
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(action.editor, {
|
|
5456
5233
|
at: action.editor.selection.focus.path,
|
|
5457
5234
|
match: (node) => action.editor.isTextBlock(node)
|
|
5458
|
-
}))[0]
|
|
5235
|
+
}))[0] ?? [void 0, void 0];
|
|
5459
5236
|
if (!focusBlock || !focusBlockPath) {
|
|
5460
5237
|
console.error("Unable to perform action without focus block", action);
|
|
5461
5238
|
return;
|
|
5462
5239
|
}
|
|
5463
|
-
const markDefs =
|
|
5240
|
+
const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
|
|
5464
5241
|
_type: annotation.name,
|
|
5465
|
-
_key: context.keyGenerator()
|
|
5466
|
-
|
|
5242
|
+
_key: context.keyGenerator(),
|
|
5243
|
+
...annotation.value
|
|
5244
|
+
})) : void 0;
|
|
5467
5245
|
annotations && annotations.length > 0 && Transforms.setNodes(action.editor, {
|
|
5468
5246
|
markDefs: [...markDefs, ...annotations]
|
|
5469
5247
|
}), Transforms.insertNodes(action.editor, {
|
|
5470
5248
|
_type: "span",
|
|
5471
5249
|
_key: context.keyGenerator(),
|
|
5472
5250
|
text: action.text,
|
|
5473
|
-
marks: [...
|
|
5251
|
+
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
5474
5252
|
});
|
|
5475
|
-
}
|
|
5476
|
-
var __defProp$7 = Object.defineProperty, __getOwnPropSymbols$7 = Object.getOwnPropertySymbols, __hasOwnProp$7 = Object.prototype.hasOwnProperty, __propIsEnum$7 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$7 = (a, b) => {
|
|
5477
|
-
for (var prop in b || (b = {}))
|
|
5478
|
-
__hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5479
|
-
if (__getOwnPropSymbols$7)
|
|
5480
|
-
for (var prop of __getOwnPropSymbols$7(b))
|
|
5481
|
-
__propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5482
|
-
return a;
|
|
5483
|
-
};
|
|
5484
|
-
const textBlockSetActionImplementation = ({
|
|
5253
|
+
}, textBlockSetActionImplementation = ({
|
|
5485
5254
|
action
|
|
5486
5255
|
}) => {
|
|
5487
5256
|
const at = toSlateRange({
|
|
@@ -5494,13 +5263,17 @@ const textBlockSetActionImplementation = ({
|
|
|
5494
5263
|
offset: 0
|
|
5495
5264
|
}
|
|
5496
5265
|
}, action.editor);
|
|
5497
|
-
Transforms.setNodes(action.editor,
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5266
|
+
Transforms.setNodes(action.editor, {
|
|
5267
|
+
...action.style ? {
|
|
5268
|
+
style: action.style
|
|
5269
|
+
} : {},
|
|
5270
|
+
...action.listItem ? {
|
|
5271
|
+
listItem: action.listItem
|
|
5272
|
+
} : {},
|
|
5273
|
+
...action.level ? {
|
|
5274
|
+
level: action.level
|
|
5275
|
+
} : {}
|
|
5276
|
+
}, {
|
|
5504
5277
|
at
|
|
5505
5278
|
});
|
|
5506
5279
|
}, textBlockUnsetActionImplementation = ({
|
|
@@ -5519,16 +5292,7 @@ const textBlockSetActionImplementation = ({
|
|
|
5519
5292
|
Transforms.unsetNodes(action.editor, action.props, {
|
|
5520
5293
|
at
|
|
5521
5294
|
});
|
|
5522
|
-
}
|
|
5523
|
-
var __defProp$6 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
|
|
5524
|
-
for (var prop in b || (b = {}))
|
|
5525
|
-
__hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5526
|
-
if (__getOwnPropSymbols$6)
|
|
5527
|
-
for (var prop of __getOwnPropSymbols$6(b))
|
|
5528
|
-
__propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5529
|
-
return a;
|
|
5530
|
-
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
5531
|
-
const behaviorActionImplementations = {
|
|
5295
|
+
}, behaviorActionImplementations = {
|
|
5532
5296
|
"annotation.add": addAnnotationActionImplementation,
|
|
5533
5297
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
5534
5298
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
@@ -5617,15 +5381,15 @@ const behaviorActionImplementations = {
|
|
|
5617
5381
|
context,
|
|
5618
5382
|
action
|
|
5619
5383
|
}) => {
|
|
5620
|
-
var _a, _b, _c, _d;
|
|
5621
5384
|
const block = toSlateValue([{
|
|
5622
5385
|
_key: context.keyGenerator(),
|
|
5623
5386
|
_type: context.schema.block.name,
|
|
5624
|
-
style:
|
|
5387
|
+
style: context.schema.styles[0].value ?? "normal",
|
|
5625
5388
|
markDefs: [],
|
|
5626
|
-
children:
|
|
5389
|
+
children: action.textBlock?.children?.map((child) => ({
|
|
5390
|
+
...child,
|
|
5627
5391
|
_key: context.keyGenerator()
|
|
5628
|
-
}))
|
|
5392
|
+
})) ?? [{
|
|
5629
5393
|
_type: context.schema.span.name,
|
|
5630
5394
|
_key: context.keyGenerator(),
|
|
5631
5395
|
text: ""
|
|
@@ -5718,7 +5482,11 @@ const behaviorActionImplementations = {
|
|
|
5718
5482
|
action
|
|
5719
5483
|
}) => {
|
|
5720
5484
|
const selection = action.editor.selection;
|
|
5721
|
-
selection && (Transforms.select(action.editor,
|
|
5485
|
+
selection && (Transforms.select(action.editor, {
|
|
5486
|
+
...selection
|
|
5487
|
+
}), action.editor.selection = {
|
|
5488
|
+
...selection
|
|
5489
|
+
});
|
|
5722
5490
|
},
|
|
5723
5491
|
"style.toggle": toggleStyleActionImplementation,
|
|
5724
5492
|
"style.add": addStyleActionImplementation,
|
|
@@ -5990,30 +5758,15 @@ function performDefaultAction({
|
|
|
5990
5758
|
});
|
|
5991
5759
|
}
|
|
5992
5760
|
}
|
|
5993
|
-
var __defProp$5 = Object.defineProperty, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
|
|
5994
|
-
for (var prop in b || (b = {}))
|
|
5995
|
-
__hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5996
|
-
if (__getOwnPropSymbols$5)
|
|
5997
|
-
for (var prop of __getOwnPropSymbols$5(b))
|
|
5998
|
-
__propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5999
|
-
return a;
|
|
6000
|
-
};
|
|
6001
5761
|
function getActiveDecorators({
|
|
6002
5762
|
schema,
|
|
6003
5763
|
slateEditorInstance
|
|
6004
5764
|
}) {
|
|
6005
|
-
var _a, _b;
|
|
6006
5765
|
const decorators = schema.decorators.map((decorator) => decorator.value);
|
|
6007
|
-
return (
|
|
6008
|
-
}
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
__hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
6012
|
-
if (__getOwnPropSymbols$4)
|
|
6013
|
-
for (var prop of __getOwnPropSymbols$4(b))
|
|
6014
|
-
__propIsEnum$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
6015
|
-
return a;
|
|
6016
|
-
}, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
5766
|
+
return ({
|
|
5767
|
+
...Editor.marks(slateEditorInstance) ?? {}
|
|
5768
|
+
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
5769
|
+
}
|
|
6017
5770
|
const editorMachine = setup({
|
|
6018
5771
|
types: {
|
|
6019
5772
|
context: {},
|
|
@@ -6068,11 +5821,11 @@ const editorMachine = setup({
|
|
|
6068
5821
|
event,
|
|
6069
5822
|
enqueue
|
|
6070
5823
|
}) => {
|
|
6071
|
-
var _a;
|
|
6072
5824
|
assertEvent(event, ["behavior event"]);
|
|
6073
|
-
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 :
|
|
5825
|
+
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
5826
|
+
...event.behaviorEvent,
|
|
6074
5827
|
editor: event.editor
|
|
6075
|
-
}
|
|
5828
|
+
}, eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
6076
5829
|
if (eventBehaviors.length === 0) {
|
|
6077
5830
|
if (!defaultAction)
|
|
6078
5831
|
return;
|
|
@@ -6112,7 +5865,7 @@ const editorMachine = setup({
|
|
|
6112
5865
|
actionIntends
|
|
6113
5866
|
});
|
|
6114
5867
|
if (behaviorOverwritten) {
|
|
6115
|
-
|
|
5868
|
+
event.nativeEvent?.preventDefault();
|
|
6116
5869
|
break;
|
|
6117
5870
|
}
|
|
6118
5871
|
}
|
|
@@ -6131,19 +5884,16 @@ const editorMachine = setup({
|
|
|
6131
5884
|
id: "editor",
|
|
6132
5885
|
context: ({
|
|
6133
5886
|
input
|
|
6134
|
-
}) => {
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
value: input.value
|
|
6145
|
-
};
|
|
6146
|
-
},
|
|
5887
|
+
}) => ({
|
|
5888
|
+
behaviors: input.behaviors ?? coreBehaviors,
|
|
5889
|
+
keyGenerator: input.keyGenerator,
|
|
5890
|
+
pendingEvents: [],
|
|
5891
|
+
schema: input.schema,
|
|
5892
|
+
selection: null,
|
|
5893
|
+
initialReadOnly: input.readOnly ?? !1,
|
|
5894
|
+
maxBlocks: input.maxBlocks,
|
|
5895
|
+
value: input.value
|
|
5896
|
+
}),
|
|
6147
5897
|
on: {
|
|
6148
5898
|
unset: {
|
|
6149
5899
|
actions: emit(({
|
|
@@ -6226,9 +5976,10 @@ const editorMachine = setup({
|
|
|
6226
5976
|
}) => {
|
|
6227
5977
|
Editor.withoutNormalizing(event.editor, () => {
|
|
6228
5978
|
for (const actionIntend of event.actionIntends) {
|
|
6229
|
-
const action =
|
|
5979
|
+
const action = {
|
|
5980
|
+
...actionIntend,
|
|
6230
5981
|
editor: event.editor
|
|
6231
|
-
}
|
|
5982
|
+
};
|
|
6232
5983
|
performAction({
|
|
6233
5984
|
context,
|
|
6234
5985
|
action
|
|
@@ -6443,10 +6194,9 @@ function useCreateEditor(config) {
|
|
|
6443
6194
|
return $[4] !== editorActor ? (t3 = createEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
6444
6195
|
}
|
|
6445
6196
|
function editorConfigToMachineInput(config) {
|
|
6446
|
-
var _a;
|
|
6447
6197
|
return {
|
|
6448
6198
|
behaviors: config.behaviors,
|
|
6449
|
-
keyGenerator:
|
|
6199
|
+
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
6450
6200
|
maxBlocks: config.maxBlocks,
|
|
6451
6201
|
readOnly: config.readOnly,
|
|
6452
6202
|
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
@@ -6496,16 +6246,13 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
6496
6246
|
let t2;
|
|
6497
6247
|
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
6498
6248
|
}
|
|
6499
|
-
var __defProp$3 = Object.defineProperty, __defProps$3 = Object.defineProperties, __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
|
|
6500
|
-
for (var prop in b || (b = {}))
|
|
6501
|
-
__hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6502
|
-
if (__getOwnPropSymbols$3)
|
|
6503
|
-
for (var prop of __getOwnPropSymbols$3(b))
|
|
6504
|
-
__propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6505
|
-
return a;
|
|
6506
|
-
}, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)), __publicField = (obj, key, value) => __defNormalProp$3(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
6507
6249
|
const debug$4 = debugWithName("component:PortableTextEditor");
|
|
6508
6250
|
class PortableTextEditor extends Component {
|
|
6251
|
+
static displayName = "PortableTextEditor";
|
|
6252
|
+
/**
|
|
6253
|
+
* An observable of all the editor changes.
|
|
6254
|
+
*/
|
|
6255
|
+
change$ = new Subject();
|
|
6509
6256
|
/**
|
|
6510
6257
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
6511
6258
|
*/
|
|
@@ -6516,11 +6263,8 @@ class PortableTextEditor extends Component {
|
|
|
6516
6263
|
* The editor API (currently implemented with Slate).
|
|
6517
6264
|
*/
|
|
6518
6265
|
constructor(props) {
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
this.editor._internal.editable = __spreadValues$3(__spreadValues$3({}, this.editor._internal.editable), editable);
|
|
6522
|
-
}), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6523
|
-
keyGenerator: (_a = props.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6266
|
+
super(props), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6267
|
+
keyGenerator: props.keyGenerator ?? defaultKeyGenerator,
|
|
6524
6268
|
schema: props.schemaType,
|
|
6525
6269
|
initialValue: props.value,
|
|
6526
6270
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
@@ -6528,13 +6272,12 @@ class PortableTextEditor extends Component {
|
|
|
6528
6272
|
}), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
|
|
6529
6273
|
}
|
|
6530
6274
|
componentDidUpdate(prevProps) {
|
|
6531
|
-
var _a;
|
|
6532
6275
|
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = createEditorSchema(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
|
|
6533
6276
|
type: "update schema",
|
|
6534
6277
|
schema: this.schemaTypes
|
|
6535
6278
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
6536
6279
|
type: "update readOnly",
|
|
6537
|
-
readOnly:
|
|
6280
|
+
readOnly: this.props.readOnly ?? !1
|
|
6538
6281
|
}), this.props.maxBlocks !== prevProps.maxBlocks && this.editor._internal.editorActor.send({
|
|
6539
6282
|
type: "update maxBlocks",
|
|
6540
6283
|
maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
|
|
@@ -6543,9 +6286,14 @@ class PortableTextEditor extends Component {
|
|
|
6543
6286
|
value: this.props.value
|
|
6544
6287
|
}), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
|
|
6545
6288
|
}
|
|
6289
|
+
setEditable = (editable) => {
|
|
6290
|
+
this.editor._internal.editable = {
|
|
6291
|
+
...this.editor._internal.editable,
|
|
6292
|
+
...editable
|
|
6293
|
+
};
|
|
6294
|
+
};
|
|
6546
6295
|
render() {
|
|
6547
|
-
|
|
6548
|
-
const legacyPatches = this.props.editor ? void 0 : (_a = this.props.incomingPatches$) != null ? _a : this.props.patches$;
|
|
6296
|
+
const legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
|
|
6549
6297
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6550
6298
|
legacyPatches ? /* @__PURE__ */ jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
|
|
6551
6299
|
/* @__PURE__ */ jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
|
|
@@ -6555,105 +6303,65 @@ class PortableTextEditor extends Component {
|
|
|
6555
6303
|
/* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsx(Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
|
|
6556
6304
|
] });
|
|
6557
6305
|
}
|
|
6306
|
+
// Static API methods
|
|
6307
|
+
static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
|
|
6308
|
+
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6309
|
+
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6310
|
+
static blur = (editor) => {
|
|
6311
|
+
debug$4("Host blurred"), editor.editable?.blur();
|
|
6312
|
+
};
|
|
6313
|
+
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6314
|
+
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6315
|
+
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6316
|
+
static focus = (editor) => {
|
|
6317
|
+
debug$4("Host requesting focus"), editor.editable?.focus();
|
|
6318
|
+
};
|
|
6319
|
+
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6320
|
+
static focusChild = (editor) => editor.editable?.focusChild();
|
|
6321
|
+
static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
|
|
6322
|
+
static getValue = (editor) => editor.editable?.getValue();
|
|
6323
|
+
static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
|
|
6324
|
+
static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
|
|
6325
|
+
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6326
|
+
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6327
|
+
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6328
|
+
static insertChild = (editor, type, value) => (debug$4("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6329
|
+
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6330
|
+
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6331
|
+
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
6332
|
+
static isObjectPath = (_editor, path) => {
|
|
6333
|
+
if (!path || !Array.isArray(path)) return !1;
|
|
6334
|
+
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6335
|
+
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6336
|
+
};
|
|
6337
|
+
static marks = (editor) => editor.editable?.marks();
|
|
6338
|
+
static select = (editor, selection) => {
|
|
6339
|
+
debug$4("Host setting selection", selection), editor.editable?.select(selection);
|
|
6340
|
+
};
|
|
6341
|
+
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6342
|
+
static toggleBlockStyle = (editor, blockStyle) => (debug$4("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6343
|
+
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6344
|
+
static toggleMark = (editor, mark) => {
|
|
6345
|
+
debug$4("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6346
|
+
};
|
|
6347
|
+
static getFragment = (editor) => (debug$4("Host getting fragment"), editor.editable?.getFragment());
|
|
6348
|
+
static undo = (editor) => {
|
|
6349
|
+
debug$4("Host undoing"), editor.editable?.undo();
|
|
6350
|
+
};
|
|
6351
|
+
static redo = (editor) => {
|
|
6352
|
+
debug$4("Host redoing"), editor.editable?.redo();
|
|
6353
|
+
};
|
|
6354
|
+
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6558
6355
|
}
|
|
6559
|
-
__publicField(PortableTextEditor, "displayName", "PortableTextEditor"), // Static API methods
|
|
6560
|
-
__publicField(PortableTextEditor, "activeAnnotations", (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : []), __publicField(PortableTextEditor, "isAnnotationActive", (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1), __publicField(PortableTextEditor, "addAnnotation", (editor, type, value) => {
|
|
6561
|
-
var _a;
|
|
6562
|
-
return (_a = editor.editable) == null ? void 0 : _a.addAnnotation(type, value);
|
|
6563
|
-
}), __publicField(PortableTextEditor, "blur", (editor) => {
|
|
6564
|
-
var _a;
|
|
6565
|
-
debug$4("Host blurred"), (_a = editor.editable) == null || _a.blur();
|
|
6566
|
-
}), __publicField(PortableTextEditor, "delete", (editor, selection, options) => {
|
|
6567
|
-
var _a;
|
|
6568
|
-
return (_a = editor.editable) == null ? void 0 : _a.delete(selection, options);
|
|
6569
|
-
}), __publicField(PortableTextEditor, "findDOMNode", (editor, element) => {
|
|
6570
|
-
var _a;
|
|
6571
|
-
return (_a = editor.editable) == null ? void 0 : _a.findDOMNode(element);
|
|
6572
|
-
}), __publicField(PortableTextEditor, "findByPath", (editor, path) => {
|
|
6573
|
-
var _a;
|
|
6574
|
-
return ((_a = editor.editable) == null ? void 0 : _a.findByPath(path)) || [];
|
|
6575
|
-
}), __publicField(PortableTextEditor, "focus", (editor) => {
|
|
6576
|
-
var _a;
|
|
6577
|
-
debug$4("Host requesting focus"), (_a = editor.editable) == null || _a.focus();
|
|
6578
|
-
}), __publicField(PortableTextEditor, "focusBlock", (editor) => {
|
|
6579
|
-
var _a;
|
|
6580
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusBlock();
|
|
6581
|
-
}), __publicField(PortableTextEditor, "focusChild", (editor) => {
|
|
6582
|
-
var _a;
|
|
6583
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusChild();
|
|
6584
|
-
}), __publicField(PortableTextEditor, "getSelection", (editor) => editor.editable ? editor.editable.getSelection() : null), __publicField(PortableTextEditor, "getValue", (editor) => {
|
|
6585
|
-
var _a;
|
|
6586
|
-
return (_a = editor.editable) == null ? void 0 : _a.getValue();
|
|
6587
|
-
}), __publicField(PortableTextEditor, "hasBlockStyle", (editor, blockStyle) => {
|
|
6588
|
-
var _a;
|
|
6589
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasBlockStyle(blockStyle);
|
|
6590
|
-
}), __publicField(PortableTextEditor, "hasListStyle", (editor, listStyle) => {
|
|
6591
|
-
var _a;
|
|
6592
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasListStyle(listStyle);
|
|
6593
|
-
}), __publicField(PortableTextEditor, "isCollapsedSelection", (editor) => {
|
|
6594
|
-
var _a;
|
|
6595
|
-
return (_a = editor.editable) == null ? void 0 : _a.isCollapsedSelection();
|
|
6596
|
-
}), __publicField(PortableTextEditor, "isExpandedSelection", (editor) => {
|
|
6597
|
-
var _a;
|
|
6598
|
-
return (_a = editor.editable) == null ? void 0 : _a.isExpandedSelection();
|
|
6599
|
-
}), __publicField(PortableTextEditor, "isMarkActive", (editor, mark) => {
|
|
6600
|
-
var _a;
|
|
6601
|
-
return (_a = editor.editable) == null ? void 0 : _a.isMarkActive(mark);
|
|
6602
|
-
}), __publicField(PortableTextEditor, "insertChild", (editor, type, value) => {
|
|
6603
|
-
var _a;
|
|
6604
|
-
return debug$4("Host inserting child"), (_a = editor.editable) == null ? void 0 : _a.insertChild(type, value);
|
|
6605
|
-
}), __publicField(PortableTextEditor, "insertBlock", (editor, type, value) => {
|
|
6606
|
-
var _a;
|
|
6607
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBlock(type, value);
|
|
6608
|
-
}), __publicField(PortableTextEditor, "insertBreak", (editor) => {
|
|
6609
|
-
var _a;
|
|
6610
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBreak();
|
|
6611
|
-
}), __publicField(PortableTextEditor, "isVoid", (editor, element) => {
|
|
6612
|
-
var _a;
|
|
6613
|
-
return (_a = editor.editable) == null ? void 0 : _a.isVoid(element);
|
|
6614
|
-
}), __publicField(PortableTextEditor, "isObjectPath", (_editor, path) => {
|
|
6615
|
-
if (!path || !Array.isArray(path)) return !1;
|
|
6616
|
-
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6617
|
-
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6618
|
-
}), __publicField(PortableTextEditor, "marks", (editor) => {
|
|
6619
|
-
var _a;
|
|
6620
|
-
return (_a = editor.editable) == null ? void 0 : _a.marks();
|
|
6621
|
-
}), __publicField(PortableTextEditor, "select", (editor, selection) => {
|
|
6622
|
-
var _a;
|
|
6623
|
-
debug$4("Host setting selection", selection), (_a = editor.editable) == null || _a.select(selection);
|
|
6624
|
-
}), __publicField(PortableTextEditor, "removeAnnotation", (editor, type) => {
|
|
6625
|
-
var _a;
|
|
6626
|
-
return (_a = editor.editable) == null ? void 0 : _a.removeAnnotation(type);
|
|
6627
|
-
}), __publicField(PortableTextEditor, "toggleBlockStyle", (editor, blockStyle) => {
|
|
6628
|
-
var _a;
|
|
6629
|
-
return debug$4("Host is toggling block style"), (_a = editor.editable) == null ? void 0 : _a.toggleBlockStyle(blockStyle);
|
|
6630
|
-
}), __publicField(PortableTextEditor, "toggleList", (editor, listStyle) => {
|
|
6631
|
-
var _a;
|
|
6632
|
-
return (_a = editor.editable) == null ? void 0 : _a.toggleList(listStyle);
|
|
6633
|
-
}), __publicField(PortableTextEditor, "toggleMark", (editor, mark) => {
|
|
6634
|
-
var _a;
|
|
6635
|
-
debug$4("Host toggling mark", mark), (_a = editor.editable) == null || _a.toggleMark(mark);
|
|
6636
|
-
}), __publicField(PortableTextEditor, "getFragment", (editor) => {
|
|
6637
|
-
var _a;
|
|
6638
|
-
return debug$4("Host getting fragment"), (_a = editor.editable) == null ? void 0 : _a.getFragment();
|
|
6639
|
-
}), __publicField(PortableTextEditor, "undo", (editor) => {
|
|
6640
|
-
var _a;
|
|
6641
|
-
debug$4("Host undoing"), (_a = editor.editable) == null || _a.undo();
|
|
6642
|
-
}), __publicField(PortableTextEditor, "redo", (editor) => {
|
|
6643
|
-
var _a;
|
|
6644
|
-
debug$4("Host redoing"), (_a = editor.editable) == null || _a.redo();
|
|
6645
|
-
}), __publicField(PortableTextEditor, "isSelectionsOverlapping", (editor, selectionA, selectionB) => {
|
|
6646
|
-
var _a;
|
|
6647
|
-
return (_a = editor.editable) == null ? void 0 : _a.isSelectionsOverlapping(selectionA, selectionB);
|
|
6648
|
-
});
|
|
6649
6356
|
function RoutePatchesObservableToEditorActor(props) {
|
|
6650
6357
|
const $ = c(4);
|
|
6651
6358
|
let t0, t1;
|
|
6652
6359
|
return $[0] !== props.editorActor || $[1] !== props.patches$ ? (t0 = () => {
|
|
6653
6360
|
const subscription = props.patches$.subscribe((payload) => {
|
|
6654
|
-
props.editorActor.send(
|
|
6655
|
-
type: "patches"
|
|
6656
|
-
|
|
6361
|
+
props.editorActor.send({
|
|
6362
|
+
type: "patches",
|
|
6363
|
+
...payload
|
|
6364
|
+
});
|
|
6657
6365
|
});
|
|
6658
6366
|
return () => {
|
|
6659
6367
|
subscription.unsubscribe();
|
|
@@ -6718,9 +6426,10 @@ function RouteEventsToChanges(props) {
|
|
|
6718
6426
|
break bb5;
|
|
6719
6427
|
}
|
|
6720
6428
|
case "error": {
|
|
6721
|
-
handleChange(
|
|
6429
|
+
handleChange({
|
|
6430
|
+
...event,
|
|
6722
6431
|
level: "warning"
|
|
6723
|
-
})
|
|
6432
|
+
});
|
|
6724
6433
|
break bb5;
|
|
6725
6434
|
}
|
|
6726
6435
|
case "annotation.add":
|
|
@@ -6748,14 +6457,6 @@ function RouteEventsToChanges(props) {
|
|
|
6748
6457
|
};
|
|
6749
6458
|
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), null;
|
|
6750
6459
|
}
|
|
6751
|
-
var __defProp$2 = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
|
|
6752
|
-
for (var prop in b || (b = {}))
|
|
6753
|
-
__hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6754
|
-
if (__getOwnPropSymbols$2)
|
|
6755
|
-
for (var prop of __getOwnPropSymbols$2(b))
|
|
6756
|
-
__propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6757
|
-
return a;
|
|
6758
|
-
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
6759
6460
|
const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
6760
6461
|
const {
|
|
6761
6462
|
editorActor,
|
|
@@ -6767,13 +6468,10 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6767
6468
|
renderDecorator,
|
|
6768
6469
|
renderAnnotation
|
|
6769
6470
|
} = props, spanRef = useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = useSelected(), [focused, setFocused] = useState(!1), [selected, setSelected] = useState(!1), block = children.props.parent, path = useMemo(() => block ? [{
|
|
6770
|
-
_key: block
|
|
6471
|
+
_key: block?._key
|
|
6771
6472
|
}, "children", {
|
|
6772
6473
|
_key: leaf._key
|
|
6773
|
-
}] : [], [block, leaf._key]), decoratorValues = useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = useMemo(() => uniq((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = useMemo(() => annotationMarks.map((mark_0) =>
|
|
6774
|
-
var _a;
|
|
6775
|
-
return !decoratorValues.includes(mark_0) && ((_a = block == null ? void 0 : block.markDefs) == null ? void 0 : _a.find((def) => def._key === mark_0));
|
|
6776
|
-
}).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
6474
|
+
}] : [], [block, leaf._key]), decoratorValues = useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = useMemo(() => uniq((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = useMemo(() => annotationMarks.map((mark_0) => !decoratorValues.includes(mark_0) && block?.markDefs?.find((def) => def._key === mark_0)).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
6777
6475
|
useEffect(() => {
|
|
6778
6476
|
if (!shouldTrackSelectionAndFocus) {
|
|
6779
6477
|
setFocused(!1);
|
|
@@ -6880,7 +6578,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6880
6578
|
}
|
|
6881
6579
|
return returnedChildren;
|
|
6882
6580
|
}, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
|
|
6883
|
-
return useMemo(() => /* @__PURE__ */ jsx("span",
|
|
6581
|
+
return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6884
6582
|
};
|
|
6885
6583
|
Leaf.displayName = "Leaf";
|
|
6886
6584
|
const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
@@ -6933,32 +6631,10 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6933
6631
|
}, editor;
|
|
6934
6632
|
};
|
|
6935
6633
|
}
|
|
6936
|
-
var __defProp$1 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
|
|
6937
|
-
for (var prop in b || (b = {}))
|
|
6938
|
-
__hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6939
|
-
if (__getOwnPropSymbols$1)
|
|
6940
|
-
for (var prop of __getOwnPropSymbols$1(b))
|
|
6941
|
-
__propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6942
|
-
return a;
|
|
6943
|
-
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), __objRest$1 = (source, exclude) => {
|
|
6944
|
-
var target = {};
|
|
6945
|
-
for (var prop in source)
|
|
6946
|
-
__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
6947
|
-
if (source != null && __getOwnPropSymbols$1)
|
|
6948
|
-
for (var prop of __getOwnPropSymbols$1(source))
|
|
6949
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop) && (target[prop] = source[prop]);
|
|
6950
|
-
return target;
|
|
6951
|
-
};
|
|
6952
6634
|
const debug$1 = debugWithName("plugin:withInsertData");
|
|
6953
6635
|
function createWithInsertData(editorActor, schemaTypes) {
|
|
6954
6636
|
return function(editor) {
|
|
6955
|
-
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => {
|
|
6956
|
-
var _a;
|
|
6957
|
-
return editor.isTextBlock(block) ? block.children.map((child) => {
|
|
6958
|
-
var _a2;
|
|
6959
|
-
return child._type === spanTypeName ? child.text : `[${((_a2 = schemaTypes.inlineObjects.find((t) => t.name === child._type)) == null ? void 0 : _a2.title) || "Object"}]`;
|
|
6960
|
-
}).join("") : `[${((_a = schemaTypes.blockObjects.find((t) => t.name === block._type)) == null ? void 0 : _a.title) || "Object"}]`;
|
|
6961
|
-
}).join(`
|
|
6637
|
+
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => editor.isTextBlock(block) ? block.children.map((child) => child._type === spanTypeName ? child.text : `[${schemaTypes.inlineObjects.find((t) => t.name === child._type)?.title || "Object"}]`).join("") : `[${schemaTypes.blockObjects.find((t) => t.name === block._type)?.title || "Object"}]`).join(`
|
|
6962
6638
|
|
|
6963
6639
|
`);
|
|
6964
6640
|
return editor.setFragmentData = (data, originEvent) => {
|
|
@@ -6996,7 +6672,6 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
6996
6672
|
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
6997
6673
|
data.clearData(), data.setData("text/plain", asPlainText), data.setData("text/html", asHTML), data.setData("application/json", asJSON), data.setData("application/x-portable-text", asJSON), debug$1("text", asPlainText), data.setData("application/x-portable-text-event-origin", originEvent || "external"), debug$1("Set fragment data", asJSON, asHTML);
|
|
6998
6674
|
}, editor.insertPortableTextData = (data) => {
|
|
6999
|
-
var _a, _b;
|
|
7000
6675
|
if (!editor.selection)
|
|
7001
6676
|
return !1;
|
|
7002
6677
|
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
@@ -7006,8 +6681,8 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7006
6681
|
const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
|
|
7007
6682
|
schemaTypes
|
|
7008
6683
|
}), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7009
|
-
if (!validation.valid && !
|
|
7010
|
-
const errorDescription = `${
|
|
6684
|
+
if (!validation.valid && !validation.resolution?.autoResolve) {
|
|
6685
|
+
const errorDescription = `${validation.resolution?.description}`;
|
|
7011
6686
|
return editorActor.send({
|
|
7012
6687
|
type: "error",
|
|
7013
6688
|
name: "pasteError",
|
|
@@ -7020,7 +6695,6 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7020
6695
|
}
|
|
7021
6696
|
return !1;
|
|
7022
6697
|
}, editor.insertTextOrHTMLData = (data) => {
|
|
7023
|
-
var _a;
|
|
7024
6698
|
if (!editor.selection)
|
|
7025
6699
|
return debug$1("No selection, not inserting"), !1;
|
|
7026
6700
|
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
@@ -7047,7 +6721,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7047
6721
|
const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7048
6722
|
if (!validation.valid) {
|
|
7049
6723
|
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
7050
|
-
${
|
|
6724
|
+
${validation.resolution?.description}
|
|
7051
6725
|
Try to insert as plain text (shift-paste) instead.`;
|
|
7052
6726
|
return editorActor.send({
|
|
7053
6727
|
type: "error",
|
|
@@ -7086,37 +6760,46 @@ function escapeHtml(str) {
|
|
|
7086
6760
|
}
|
|
7087
6761
|
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
7088
6762
|
return fragment.map((node) => {
|
|
7089
|
-
const newNode =
|
|
6763
|
+
const newNode = {
|
|
6764
|
+
...node
|
|
6765
|
+
};
|
|
7090
6766
|
if (editor.isTextBlock(newNode)) {
|
|
7091
6767
|
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
7092
6768
|
if (annotations.length === 0) {
|
|
7093
|
-
const
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
6769
|
+
const {
|
|
6770
|
+
markDefs,
|
|
6771
|
+
...NewNodeNoDefs
|
|
6772
|
+
} = newNode;
|
|
6773
|
+
return {
|
|
6774
|
+
...NewNodeNoDefs,
|
|
7097
6775
|
_key: keyGenerator()
|
|
7098
|
-
}
|
|
6776
|
+
};
|
|
7099
6777
|
}
|
|
7100
6778
|
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
7101
6779
|
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
7102
|
-
return
|
|
6780
|
+
return {
|
|
6781
|
+
...newNode,
|
|
7103
6782
|
markDefs: allowedAnnotations,
|
|
7104
6783
|
_key: keyGenerator()
|
|
7105
|
-
}
|
|
6784
|
+
};
|
|
7106
6785
|
}
|
|
7107
6786
|
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
7108
6787
|
const oldKey = def._key, newKey = keyGenerator();
|
|
7109
|
-
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ?
|
|
6788
|
+
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
6789
|
+
...child,
|
|
7110
6790
|
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
7111
|
-
}
|
|
6791
|
+
} : child), {
|
|
6792
|
+
...def,
|
|
7112
6793
|
_key: newKey
|
|
7113
|
-
}
|
|
6794
|
+
};
|
|
7114
6795
|
});
|
|
7115
6796
|
}
|
|
7116
|
-
const nodeWithNewKeys =
|
|
6797
|
+
const nodeWithNewKeys = {
|
|
6798
|
+
...newNode,
|
|
7117
6799
|
_key: keyGenerator()
|
|
7118
|
-
}
|
|
7119
|
-
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) =>
|
|
6800
|
+
};
|
|
6801
|
+
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
6802
|
+
...child,
|
|
7120
6803
|
_key: keyGenerator()
|
|
7121
6804
|
}))), nodeWithNewKeys;
|
|
7122
6805
|
});
|
|
@@ -7161,22 +6844,6 @@ function withSyncRangeDecorations({
|
|
|
7161
6844
|
slateEditor.apply = originalApply;
|
|
7162
6845
|
};
|
|
7163
6846
|
}
|
|
7164
|
-
var __defProp2 = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols2 = Object.getOwnPropertySymbols, __hasOwnProp2 = Object.prototype.hasOwnProperty, __propIsEnum2 = Object.prototype.propertyIsEnumerable, __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues2 = (a, b) => {
|
|
7165
|
-
for (var prop in b || (b = {}))
|
|
7166
|
-
__hasOwnProp2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
7167
|
-
if (__getOwnPropSymbols2)
|
|
7168
|
-
for (var prop of __getOwnPropSymbols2(b))
|
|
7169
|
-
__propIsEnum2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
7170
|
-
return a;
|
|
7171
|
-
}, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)), __objRest = (source, exclude) => {
|
|
7172
|
-
var target = {};
|
|
7173
|
-
for (var prop in source)
|
|
7174
|
-
__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
7175
|
-
if (source != null && __getOwnPropSymbols2)
|
|
7176
|
-
for (var prop of __getOwnPropSymbols2(source))
|
|
7177
|
-
exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop) && (target[prop] = source[prop]);
|
|
7178
|
-
return target;
|
|
7179
|
-
};
|
|
7180
6847
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
7181
6848
|
position: "absolute",
|
|
7182
6849
|
userSelect: "none",
|
|
@@ -7184,7 +6851,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7184
6851
|
left: 0,
|
|
7185
6852
|
right: 0
|
|
7186
6853
|
}, PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
7187
|
-
const
|
|
6854
|
+
const {
|
|
7188
6855
|
hotkeys,
|
|
7189
6856
|
onBlur,
|
|
7190
6857
|
onFocus,
|
|
@@ -7202,27 +6869,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7202
6869
|
renderStyle,
|
|
7203
6870
|
selection: propsSelection,
|
|
7204
6871
|
scrollSelectionIntoView,
|
|
7205
|
-
spellCheck
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
"onBlur",
|
|
7209
|
-
"onFocus",
|
|
7210
|
-
"onBeforeInput",
|
|
7211
|
-
"onPaste",
|
|
7212
|
-
"onCopy",
|
|
7213
|
-
"onClick",
|
|
7214
|
-
"rangeDecorations",
|
|
7215
|
-
"renderAnnotation",
|
|
7216
|
-
"renderBlock",
|
|
7217
|
-
"renderChild",
|
|
7218
|
-
"renderDecorator",
|
|
7219
|
-
"renderListItem",
|
|
7220
|
-
"renderPlaceholder",
|
|
7221
|
-
"renderStyle",
|
|
7222
|
-
"selection",
|
|
7223
|
-
"scrollSelectionIntoView",
|
|
7224
|
-
"spellCheck"
|
|
7225
|
-
]), portableTextEditor = usePortableTextEditor(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
|
|
6872
|
+
spellCheck,
|
|
6873
|
+
...restProps
|
|
6874
|
+
} = props, portableTextEditor = usePortableTextEditor(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
|
|
7226
6875
|
useImperativeHandle(forwardedRef, () => ref.current);
|
|
7227
6876
|
const rangeDecorationsRef = useRef(rangeDecorations), editorActor = useContext(EditorActorContext), readOnly = useSelector(editorActor, (s) => s.matches({
|
|
7228
6877
|
"edit mode": "read only"
|
|
@@ -7234,9 +6883,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7234
6883
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
7235
6884
|
return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
|
|
7236
6885
|
}, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
|
|
7237
|
-
const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element,
|
|
6886
|
+
const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((lProps) => {
|
|
7238
6887
|
if (lProps.leaf._type === "span") {
|
|
7239
|
-
let rendered = /* @__PURE__ */ jsx(Leaf,
|
|
6888
|
+
let rendered = /* @__PURE__ */ jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
7240
6889
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
7241
6890
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7242
6891
|
/* @__PURE__ */ jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: renderPlaceholder() }),
|
|
@@ -7283,9 +6932,10 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7283
6932
|
origin: "local"
|
|
7284
6933
|
});
|
|
7285
6934
|
}
|
|
7286
|
-
newRange !== null && newSlateRanges.push(
|
|
6935
|
+
newRange !== null && newSlateRanges.push({
|
|
6936
|
+
...newRange || slateRange_0,
|
|
7287
6937
|
rangeDecoration: rangeDecorationItem
|
|
7288
|
-
})
|
|
6938
|
+
});
|
|
7289
6939
|
}), newSlateRanges.length > 0) {
|
|
7290
6940
|
setRangeDecorationsState(newSlateRanges);
|
|
7291
6941
|
return;
|
|
@@ -7331,7 +6981,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7331
6981
|
nativeEvent: event
|
|
7332
6982
|
});
|
|
7333
6983
|
}, [onCopy, editorActor, slateEditor]), handlePaste = useCallback((event_0) => {
|
|
7334
|
-
const value_0 = PortableTextEditor.getValue(portableTextEditor),
|
|
6984
|
+
const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
|
|
7335
6985
|
event: event_0,
|
|
7336
6986
|
value: value_0,
|
|
7337
6987
|
path,
|
|
@@ -7396,8 +7046,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7396
7046
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
7397
7047
|
try {
|
|
7398
7048
|
const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
7399
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection
|
|
7400
|
-
} catch
|
|
7049
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
7050
|
+
} catch {
|
|
7401
7051
|
debug("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
7402
7052
|
}
|
|
7403
7053
|
}, [ref, slateEditor]);
|
|
@@ -7485,7 +7135,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7485
7135
|
ref.current = ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
7486
7136
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsx(
|
|
7487
7137
|
Editable,
|
|
7488
|
-
|
|
7138
|
+
{
|
|
7139
|
+
...restProps,
|
|
7489
7140
|
autoFocus: !1,
|
|
7490
7141
|
className: restProps.className || "pt-editable",
|
|
7491
7142
|
decorate,
|
|
@@ -7502,7 +7153,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7502
7153
|
renderElement,
|
|
7503
7154
|
renderLeaf,
|
|
7504
7155
|
scrollSelectionIntoView: scrollSelectionIntoViewToSlate
|
|
7505
|
-
}
|
|
7156
|
+
}
|
|
7506
7157
|
) : null;
|
|
7507
7158
|
});
|
|
7508
7159
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|