@portabletext/editor 1.16.3 → 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 +134 -118
- 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.d.cts +2 -0
- package/lib/index.d.ts +2 -0
- 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/src/editor/create-editor.ts +2 -0
package/lib/index.cjs
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
|
|
6
|
-
for (var prop in b || (b = {}))
|
|
7
|
-
__hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
8
|
-
if (__getOwnPropSymbols)
|
|
9
|
-
for (var prop of __getOwnPropSymbols(b))
|
|
10
|
-
__propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
11
|
-
return a;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
14
3
|
var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$l = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isSelectionCollapsed = require("./_chunks-cjs/selector.is-selection-collapsed.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), blockTools = require("@sanity/block-tools");
|
|
15
4
|
function _interopDefaultCompat(e) {
|
|
@@ -17,13 +6,12 @@ function _interopDefaultCompat(e) {
|
|
|
17
6
|
}
|
|
18
7
|
var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$l), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
|
|
19
8
|
function createEditorSchema(portableTextType) {
|
|
20
|
-
var _a, _b, _c;
|
|
21
9
|
if (!portableTextType)
|
|
22
10
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
23
|
-
const blockType =
|
|
11
|
+
const blockType = portableTextType.of?.find(findBlockType);
|
|
24
12
|
if (!blockType)
|
|
25
13
|
throw new Error("Block type is not defined in this schema (required)");
|
|
26
|
-
const childrenField =
|
|
14
|
+
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
27
15
|
if (!childrenField)
|
|
28
16
|
throw new Error("Children field for block type found in schema (required)");
|
|
29
17
|
const ofType = childrenField.type.of;
|
|
@@ -32,7 +20,7 @@ function createEditorSchema(portableTextType) {
|
|
|
32
20
|
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
33
21
|
if (!spanType)
|
|
34
22
|
throw new Error("Span type not found in schema (required)");
|
|
35
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes =
|
|
23
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
36
24
|
return {
|
|
37
25
|
styles: resolveEnabledStyles(blockType),
|
|
38
26
|
decorators: resolveEnabledDecorators(spanType),
|
|
@@ -46,11 +34,10 @@ function createEditorSchema(portableTextType) {
|
|
|
46
34
|
};
|
|
47
35
|
}
|
|
48
36
|
function resolveEnabledStyles(blockType) {
|
|
49
|
-
|
|
50
|
-
const styleField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "style");
|
|
37
|
+
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
51
38
|
if (!styleField)
|
|
52
39
|
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
53
|
-
const textStyles =
|
|
40
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
54
41
|
if (!textStyles || textStyles.length === 0)
|
|
55
42
|
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
56
43
|
return textStyles;
|
|
@@ -59,11 +46,10 @@ function resolveEnabledDecorators(spanType) {
|
|
|
59
46
|
return spanType.decorators;
|
|
60
47
|
}
|
|
61
48
|
function resolveEnabledListItems(blockType) {
|
|
62
|
-
|
|
63
|
-
const listField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "listItem");
|
|
49
|
+
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
64
50
|
if (!listField)
|
|
65
51
|
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
66
|
-
const listItems =
|
|
52
|
+
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
67
53
|
if (!listItems)
|
|
68
54
|
throw new Error("The list field need at least to be an empty array");
|
|
69
55
|
return listItems;
|
|
@@ -71,20 +57,11 @@ function resolveEnabledListItems(blockType) {
|
|
|
71
57
|
function findBlockType(type) {
|
|
72
58
|
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
73
59
|
}
|
|
74
|
-
var __defProp$q = Object.defineProperty, __defProps$j = Object.defineProperties, __getOwnPropDescs$j = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$q = Object.getOwnPropertySymbols, __hasOwnProp$q = Object.prototype.hasOwnProperty, __propIsEnum$q = Object.prototype.propertyIsEnumerable, __defNormalProp$q = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$q = (a, b) => {
|
|
75
|
-
for (var prop in b || (b = {}))
|
|
76
|
-
__hasOwnProp$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
|
|
77
|
-
if (__getOwnPropSymbols$q)
|
|
78
|
-
for (var prop of __getOwnPropSymbols$q(b))
|
|
79
|
-
__propIsEnum$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
|
|
80
|
-
return a;
|
|
81
|
-
}, __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
|
|
82
60
|
function defineSchema(definition) {
|
|
83
61
|
return definition;
|
|
84
62
|
}
|
|
85
63
|
function compileSchemaDefinition(definition) {
|
|
86
|
-
|
|
87
|
-
const blockObjects = (_b = (_a = definition == null ? void 0 : definition.blockObjects) == null ? void 0 : _a.map((blockObject) => types.defineType({
|
|
64
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
|
|
88
65
|
type: "object",
|
|
89
66
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
90
67
|
// fields to objects with the name `image`
|
|
@@ -92,13 +69,13 @@ function compileSchemaDefinition(definition) {
|
|
|
92
69
|
title: blockObject.title,
|
|
93
70
|
icon: blockObject.icon,
|
|
94
71
|
fields: []
|
|
95
|
-
}))
|
|
72
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
|
|
96
73
|
type: "object",
|
|
97
74
|
name: inlineObject.name,
|
|
98
75
|
title: inlineObject.title,
|
|
99
76
|
icon: inlineObject.icon,
|
|
100
77
|
fields: []
|
|
101
|
-
}))
|
|
78
|
+
})) ?? [], portableTextSchema = types.defineField({
|
|
102
79
|
type: "array",
|
|
103
80
|
name: "portable-text",
|
|
104
81
|
of: [...blockObjects.map((blockObject) => ({
|
|
@@ -110,49 +87,43 @@ function compileSchemaDefinition(definition) {
|
|
|
110
87
|
type: inlineObject.name
|
|
111
88
|
})),
|
|
112
89
|
marks: {
|
|
113
|
-
decorators:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
})) != null ? _f : [],
|
|
121
|
-
annotations: (_h = (_g = definition == null ? void 0 : definition.annotations) == null ? void 0 : _g.map((annotation) => ({
|
|
90
|
+
decorators: definition?.decorators?.map((decorator) => ({
|
|
91
|
+
title: decorator.title ?? startCase__default.default(decorator.name),
|
|
92
|
+
value: decorator.name,
|
|
93
|
+
icon: decorator.icon
|
|
94
|
+
})) ?? [],
|
|
95
|
+
annotations: definition?.annotations?.map((annotation) => ({
|
|
122
96
|
name: annotation.name,
|
|
123
97
|
type: "object",
|
|
124
98
|
title: annotation.title,
|
|
125
99
|
icon: annotation.icon
|
|
126
|
-
}))
|
|
100
|
+
})) ?? []
|
|
127
101
|
},
|
|
128
|
-
lists:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
value: style.name,
|
|
140
|
-
title: (_a2 = style.title) != null ? _a2 : startCase__default.default(style.name),
|
|
141
|
-
icon: style.icon
|
|
142
|
-
};
|
|
143
|
-
})) != null ? _l : []
|
|
102
|
+
lists: definition?.lists?.map((list) => ({
|
|
103
|
+
value: list.name,
|
|
104
|
+
title: list.title ?? startCase__default.default(list.name),
|
|
105
|
+
icon: list.icon
|
|
106
|
+
})) ?? [],
|
|
107
|
+
styles: definition?.styles?.map((style) => ({
|
|
108
|
+
value: style.name,
|
|
109
|
+
title: style.title ?? startCase__default.default(style.name),
|
|
110
|
+
icon: style.icon
|
|
111
|
+
})) ?? []
|
|
144
112
|
}]
|
|
145
113
|
}), schema$1 = schema.Schema.compile({
|
|
146
114
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
147
115
|
}).get("portable-text"), pteSchema = createEditorSchema(schema$1);
|
|
148
|
-
return
|
|
149
|
-
|
|
116
|
+
return {
|
|
117
|
+
...pteSchema,
|
|
118
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
|
|
119
|
+
...blockObject,
|
|
150
120
|
name: "image",
|
|
151
|
-
type:
|
|
121
|
+
type: {
|
|
122
|
+
...blockObject.type,
|
|
152
123
|
name: "image"
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
124
|
+
}
|
|
125
|
+
} : blockObject)
|
|
126
|
+
};
|
|
156
127
|
}
|
|
157
128
|
const rootName = "sanity-pte:";
|
|
158
129
|
debug__default.default(rootName);
|
|
@@ -287,22 +258,6 @@ function normalizeSelection(selection, value) {
|
|
|
287
258
|
backward: selection.backward
|
|
288
259
|
} : null;
|
|
289
260
|
}
|
|
290
|
-
var __defProp$p = Object.defineProperty, __defProps$i = Object.defineProperties, __getOwnPropDescs$i = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$p = Object.getOwnPropertySymbols, __hasOwnProp$p = Object.prototype.hasOwnProperty, __propIsEnum$p = Object.prototype.propertyIsEnumerable, __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$p = (a, b) => {
|
|
291
|
-
for (var prop in b || (b = {}))
|
|
292
|
-
__hasOwnProp$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
293
|
-
if (__getOwnPropSymbols$p)
|
|
294
|
-
for (var prop of __getOwnPropSymbols$p(b))
|
|
295
|
-
__propIsEnum$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
296
|
-
return a;
|
|
297
|
-
}, __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b)), __objRest$3 = (source, exclude) => {
|
|
298
|
-
var target = {};
|
|
299
|
-
for (var prop in source)
|
|
300
|
-
__hasOwnProp$p.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
301
|
-
if (source != null && __getOwnPropSymbols$p)
|
|
302
|
-
for (var prop of __getOwnPropSymbols$p(source))
|
|
303
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$p.call(source, prop) && (target[prop] = source[prop]);
|
|
304
|
-
return target;
|
|
305
|
-
};
|
|
306
261
|
const VOID_CHILD_KEY = "void-child";
|
|
307
262
|
function keepObjectEquality(object, keyMap) {
|
|
308
263
|
const value = keyMap[object._key];
|
|
@@ -312,13 +267,11 @@ function toSlateValue(value, {
|
|
|
312
267
|
schemaTypes
|
|
313
268
|
}, keyMap = {}) {
|
|
314
269
|
return value && Array.isArray(value) ? value.map((block) => {
|
|
315
|
-
const
|
|
270
|
+
const {
|
|
316
271
|
_type,
|
|
317
|
-
_key
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
"_key"
|
|
321
|
-
]), voidChildren = [{
|
|
272
|
+
_key,
|
|
273
|
+
...rest
|
|
274
|
+
} = block, voidChildren = [{
|
|
322
275
|
_key: VOID_CHILD_KEY,
|
|
323
276
|
_type: "span",
|
|
324
277
|
text: "",
|
|
@@ -328,13 +281,11 @@ function toSlateValue(value, {
|
|
|
328
281
|
const textBlock = block;
|
|
329
282
|
let hasInlines = !1;
|
|
330
283
|
const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
|
|
331
|
-
const
|
|
284
|
+
const {
|
|
332
285
|
_type: cType,
|
|
333
|
-
_key: cKey
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
"_key"
|
|
337
|
-
]);
|
|
286
|
+
_key: cKey,
|
|
287
|
+
...cRest
|
|
288
|
+
} = child;
|
|
338
289
|
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
339
290
|
_type: cType,
|
|
340
291
|
_key: cKey,
|
|
@@ -343,12 +294,12 @@ function toSlateValue(value, {
|
|
|
343
294
|
__inline: !0
|
|
344
295
|
}, keyMap)) : child;
|
|
345
296
|
});
|
|
346
|
-
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(
|
|
297
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality({
|
|
347
298
|
_type,
|
|
348
|
-
_key
|
|
349
|
-
|
|
299
|
+
_key,
|
|
300
|
+
...rest,
|
|
350
301
|
children
|
|
351
|
-
}
|
|
302
|
+
}, keyMap));
|
|
352
303
|
}
|
|
353
304
|
return keepObjectEquality({
|
|
354
305
|
_type,
|
|
@@ -374,42 +325,40 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
374
325
|
} = child;
|
|
375
326
|
if ("value" in child && _cType !== "span") {
|
|
376
327
|
hasInlines = !0;
|
|
377
|
-
const
|
|
328
|
+
const {
|
|
378
329
|
value: v,
|
|
379
330
|
_key: k,
|
|
380
331
|
_type: t,
|
|
381
332
|
__inline: _i,
|
|
382
|
-
children: _c
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
"children"
|
|
389
|
-
]);
|
|
390
|
-
return keepObjectEquality(__spreadProps$i(__spreadValues$p(__spreadValues$p({}, rest), v), {
|
|
333
|
+
children: _c,
|
|
334
|
+
...rest
|
|
335
|
+
} = child;
|
|
336
|
+
return keepObjectEquality({
|
|
337
|
+
...rest,
|
|
338
|
+
...v,
|
|
391
339
|
_key: k,
|
|
392
340
|
_type: t
|
|
393
|
-
}
|
|
341
|
+
}, keyMap);
|
|
394
342
|
}
|
|
395
343
|
return child;
|
|
396
344
|
});
|
|
397
|
-
return hasInlines ? keepObjectEquality(
|
|
345
|
+
return hasInlines ? keepObjectEquality({
|
|
346
|
+
...block,
|
|
398
347
|
children,
|
|
399
348
|
_key,
|
|
400
349
|
_type
|
|
401
|
-
}
|
|
350
|
+
}, keyMap) : block;
|
|
402
351
|
}
|
|
403
352
|
const blockValue = "value" in block && block.value;
|
|
404
|
-
return keepObjectEquality(
|
|
353
|
+
return keepObjectEquality({
|
|
405
354
|
_key,
|
|
406
|
-
_type
|
|
407
|
-
|
|
355
|
+
_type,
|
|
356
|
+
...typeof blockValue == "object" ? blockValue : {}
|
|
357
|
+
}, keyMap);
|
|
408
358
|
});
|
|
409
359
|
}
|
|
410
360
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
411
|
-
|
|
412
|
-
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !((_a = children[0].children[0].marks) != null && _a.join("")) && children[0].children[0].text === "";
|
|
361
|
+
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
413
362
|
}
|
|
414
363
|
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), DefaultObject = (props) => {
|
|
415
364
|
const $ = reactCompilerRuntime.c(4);
|
|
@@ -709,14 +658,6 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
709
658
|
] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
|
|
710
659
|
};
|
|
711
660
|
DraggableBlock.displayName = "DraggableBlock";
|
|
712
|
-
var __defProp$o = Object.defineProperty, __defProps$h = Object.defineProperties, __getOwnPropDescs$h = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$o = Object.getOwnPropertySymbols, __hasOwnProp$o = Object.prototype.hasOwnProperty, __propIsEnum$o = Object.prototype.propertyIsEnumerable, __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$o = (a, b) => {
|
|
713
|
-
for (var prop in b || (b = {}))
|
|
714
|
-
__hasOwnProp$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
715
|
-
if (__getOwnPropSymbols$o)
|
|
716
|
-
for (var prop of __getOwnPropSymbols$o(b))
|
|
717
|
-
__propIsEnum$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
718
|
-
return a;
|
|
719
|
-
}, __spreadProps$h = (a, b) => __defProps$h(a, __getOwnPropDescs$h(b));
|
|
720
661
|
debugWithName("components:Element");
|
|
721
662
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
722
663
|
display: "inline-block"
|
|
@@ -753,7 +694,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
753
694
|
}, "children", {
|
|
754
695
|
_key: element._key
|
|
755
696
|
}];
|
|
756
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span",
|
|
697
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", { ...attributes, children: [
|
|
757
698
|
children,
|
|
758
699
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
|
|
759
700
|
renderChild && renderChild({
|
|
@@ -770,7 +711,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
770
711
|
}),
|
|
771
712
|
!renderChild && /* @__PURE__ */ jsxRuntime.jsx(DefaultObject, { value })
|
|
772
713
|
] }, element._key)
|
|
773
|
-
] })
|
|
714
|
+
] });
|
|
774
715
|
}
|
|
775
716
|
throw new Error("Block not found!");
|
|
776
717
|
}
|
|
@@ -821,7 +762,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
821
762
|
return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
|
|
822
763
|
}
|
|
823
764
|
}), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
|
|
824
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div",
|
|
765
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ...attributes, className, spellCheck, children: /* @__PURE__ */ jsxRuntime.jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }, element._key);
|
|
825
766
|
}
|
|
826
767
|
const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
|
|
827
768
|
if (!schemaType_0)
|
|
@@ -846,13 +787,13 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
846
787
|
});
|
|
847
788
|
renderedBlockFromProps = renderBlock(_props);
|
|
848
789
|
}
|
|
849
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div",
|
|
790
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...attributes, className, children: [
|
|
850
791
|
children,
|
|
851
792
|
/* @__PURE__ */ jsxRuntime.jsxs(DraggableBlock, { element, readOnly, blockRef, children: [
|
|
852
793
|
renderedBlockFromProps && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
|
|
853
794
|
!renderedBlockFromProps && /* @__PURE__ */ jsxRuntime.jsx(DefaultBlockObject, { selected, children: /* @__PURE__ */ jsxRuntime.jsx(DefaultObject, { value }) })
|
|
854
795
|
] })
|
|
855
|
-
] }
|
|
796
|
+
] }, element._key);
|
|
856
797
|
};
|
|
857
798
|
Element.displayName = "Element";
|
|
858
799
|
const PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
|
|
@@ -951,14 +892,6 @@ const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3,
|
|
|
951
892
|
}
|
|
952
893
|
}
|
|
953
894
|
});
|
|
954
|
-
var __defProp$n = Object.defineProperty, __defProps$g = Object.defineProperties, __getOwnPropDescs$g = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$n = Object.getOwnPropertySymbols, __hasOwnProp$n = Object.prototype.hasOwnProperty, __propIsEnum$n = Object.prototype.propertyIsEnumerable, __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$n = (a, b) => {
|
|
955
|
-
for (var prop in b || (b = {}))
|
|
956
|
-
__hasOwnProp$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
957
|
-
if (__getOwnPropSymbols$n)
|
|
958
|
-
for (var prop of __getOwnPropSymbols$n(b))
|
|
959
|
-
__propIsEnum$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
960
|
-
return a;
|
|
961
|
-
}, __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
|
|
962
895
|
function validateValue(value, types$1, keyGenerator) {
|
|
963
896
|
let resolution = null, valid = !0;
|
|
964
897
|
const validChildTypes = [types$1.span.name, ...types$1.inlineObjects.map((t) => t.name)], validBlockTypes = [types$1.block.name, ...types$1.blockObjects.map((t) => t.name)];
|
|
@@ -996,9 +929,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
996
929
|
}, !0;
|
|
997
930
|
if (!blk._key || typeof blk._key != "string")
|
|
998
931
|
return resolution = {
|
|
999
|
-
patches: [patches.set(
|
|
932
|
+
patches: [patches.set({
|
|
933
|
+
...blk,
|
|
1000
934
|
_key: keyGenerator()
|
|
1001
|
-
}
|
|
935
|
+
}, [index])],
|
|
1002
936
|
description: `Block at index ${index} is missing required _key.`,
|
|
1003
937
|
action: "Set the block with a random _key value",
|
|
1004
938
|
item: blk,
|
|
@@ -1014,9 +948,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1014
948
|
if (blk._type === "block") {
|
|
1015
949
|
const currentBlockTypeName = types$1.block.name;
|
|
1016
950
|
return resolution = {
|
|
1017
|
-
patches: [patches.set(
|
|
951
|
+
patches: [patches.set({
|
|
952
|
+
...blk,
|
|
1018
953
|
_type: currentBlockTypeName
|
|
1019
|
-
}
|
|
954
|
+
}, [{
|
|
1020
955
|
_key: blk._key
|
|
1021
956
|
}])],
|
|
1022
957
|
description: `Block with _key '${blk._key}' has invalid type name '${blk._type}'. According to the schema, the block type name is '${currentBlockTypeName}'`,
|
|
@@ -1032,12 +967,14 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1032
967
|
}
|
|
1033
968
|
}, !0;
|
|
1034
969
|
}
|
|
1035
|
-
return !blk._type && types.isPortableTextTextBlock(
|
|
970
|
+
return !blk._type && types.isPortableTextTextBlock({
|
|
971
|
+
...blk,
|
|
1036
972
|
_type: types$1.block.name
|
|
1037
|
-
})
|
|
1038
|
-
patches: [patches.set(
|
|
973
|
+
}) ? (resolution = {
|
|
974
|
+
patches: [patches.set({
|
|
975
|
+
...blk,
|
|
1039
976
|
_type: types$1.block.name
|
|
1040
|
-
}
|
|
977
|
+
}, [{
|
|
1041
978
|
_key: blk._key
|
|
1042
979
|
}])],
|
|
1043
980
|
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types$1.block.name}'`,
|
|
@@ -1197,9 +1134,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1197
1134
|
}
|
|
1198
1135
|
}, !0;
|
|
1199
1136
|
if (!child._key || typeof child._key != "string") {
|
|
1200
|
-
const newChild =
|
|
1137
|
+
const newChild = {
|
|
1138
|
+
...child,
|
|
1201
1139
|
_key: keyGenerator()
|
|
1202
|
-
}
|
|
1140
|
+
};
|
|
1203
1141
|
return resolution = {
|
|
1204
1142
|
autoResolve: !0,
|
|
1205
1143
|
patches: [patches.set(newChild, [{
|
|
@@ -1219,9 +1157,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1219
1157
|
}, !0;
|
|
1220
1158
|
}
|
|
1221
1159
|
return child._type ? validChildTypes.includes(child._type) ? child._type === types$1.span.name && typeof child.text != "string" ? (resolution = {
|
|
1222
|
-
patches: [patches.set(
|
|
1160
|
+
patches: [patches.set({
|
|
1161
|
+
...child,
|
|
1223
1162
|
text: ""
|
|
1224
|
-
}
|
|
1163
|
+
}, [{
|
|
1225
1164
|
_key: blk._key
|
|
1226
1165
|
}, "children", {
|
|
1227
1166
|
_key: child._key
|
|
@@ -1629,10 +1568,11 @@ function createDeadLine(timeout) {
|
|
|
1629
1568
|
return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
|
|
1630
1569
|
}
|
|
1631
1570
|
function createInternalOpts(opts) {
|
|
1632
|
-
return
|
|
1571
|
+
return {
|
|
1633
1572
|
checkLines: !0,
|
|
1634
|
-
deadline: createDeadLine(opts.timeout || 1)
|
|
1635
|
-
|
|
1573
|
+
deadline: createDeadLine(opts.timeout || 1),
|
|
1574
|
+
...opts
|
|
1575
|
+
};
|
|
1636
1576
|
}
|
|
1637
1577
|
function combineChar(data, char, dir) {
|
|
1638
1578
|
return dir === 1 ? data + char : char + data;
|
|
@@ -1696,7 +1636,10 @@ const DEFAULT_OPTIONS = {
|
|
|
1696
1636
|
distance: 1e3
|
|
1697
1637
|
};
|
|
1698
1638
|
function applyDefaults(options) {
|
|
1699
|
-
return
|
|
1639
|
+
return {
|
|
1640
|
+
...DEFAULT_OPTIONS,
|
|
1641
|
+
...options
|
|
1642
|
+
};
|
|
1700
1643
|
}
|
|
1701
1644
|
const MAX_BITS$1 = 32;
|
|
1702
1645
|
function bitap(text, pattern, loc) {
|
|
@@ -1968,7 +1911,7 @@ function parse(textline) {
|
|
|
1968
1911
|
let line;
|
|
1969
1912
|
try {
|
|
1970
1913
|
line = decodeURI(currentLine.slice(1));
|
|
1971
|
-
} catch
|
|
1914
|
+
} catch {
|
|
1972
1915
|
throw new Error("Illegal escape in parse: ".concat(currentLine));
|
|
1973
1916
|
}
|
|
1974
1917
|
const utf8Diff = countUtf8Bytes(line) - line.length;
|
|
@@ -1994,8 +1937,7 @@ function withUndoing(editor, fn) {
|
|
|
1994
1937
|
IS_UDOING.set(editor, !0), fn(), IS_UDOING.set(editor, prev);
|
|
1995
1938
|
}
|
|
1996
1939
|
function isUndoing(editor) {
|
|
1997
|
-
|
|
1998
|
-
return (_a = IS_UDOING.get(editor)) != null ? _a : !1;
|
|
1940
|
+
return IS_UDOING.get(editor) ?? !1;
|
|
1999
1941
|
}
|
|
2000
1942
|
function setIsUndoing(editor, isUndoing2) {
|
|
2001
1943
|
IS_UDOING.set(editor, isUndoing2);
|
|
@@ -2005,20 +1947,11 @@ function withRedoing(editor, fn) {
|
|
|
2005
1947
|
IS_REDOING.set(editor, !0), fn(), IS_REDOING.set(editor, prev);
|
|
2006
1948
|
}
|
|
2007
1949
|
function isRedoing(editor) {
|
|
2008
|
-
|
|
2009
|
-
return (_a = IS_REDOING.get(editor)) != null ? _a : !1;
|
|
1950
|
+
return IS_REDOING.get(editor) ?? !1;
|
|
2010
1951
|
}
|
|
2011
1952
|
function setIsRedoing(editor, isRedoing2) {
|
|
2012
1953
|
IS_REDOING.set(editor, isRedoing2);
|
|
2013
1954
|
}
|
|
2014
|
-
var __defProp$m = Object.defineProperty, __getOwnPropSymbols$m = Object.getOwnPropertySymbols, __hasOwnProp$m = Object.prototype.hasOwnProperty, __propIsEnum$m = Object.prototype.propertyIsEnumerable, __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$m = (a, b) => {
|
|
2015
|
-
for (var prop in b || (b = {}))
|
|
2016
|
-
__hasOwnProp$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
2017
|
-
if (__getOwnPropSymbols$m)
|
|
2018
|
-
for (var prop of __getOwnPropSymbols$m(b))
|
|
2019
|
-
__propIsEnum$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
2020
|
-
return a;
|
|
2021
|
-
};
|
|
2022
1955
|
const debug$j = debugWithName("plugin:withUndoRedo"), debugVerbose$3 = debug$j.enabled && !1, SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2023
1956
|
const state = SAVING.get(editor);
|
|
2024
1957
|
return state === void 0 ? !0 : state;
|
|
@@ -2181,7 +2114,9 @@ function createWithUndoRedo(options) {
|
|
|
2181
2114
|
}
|
|
2182
2115
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2183
2116
|
debugVerbose$3 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
|
|
2184
|
-
const transformedOperation =
|
|
2117
|
+
const transformedOperation = {
|
|
2118
|
+
...operation
|
|
2119
|
+
};
|
|
2185
2120
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
2186
2121
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2187
2122
|
_key: blk._key
|
|
@@ -2201,7 +2136,6 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2201
2136
|
return !operationTargetBlock || !isEqual__default.default({
|
|
2202
2137
|
_key: operationTargetBlock._key
|
|
2203
2138
|
}, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
2204
|
-
var _a, _b, _c, _d;
|
|
2205
2139
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
|
|
2206
2140
|
const {
|
|
2207
2141
|
diffs
|
|
@@ -2210,7 +2144,15 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2210
2144
|
const [diffType, text] = diff2;
|
|
2211
2145
|
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
|
|
2212
2146
|
}), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
|
|
2213
|
-
const currentFocus =
|
|
2147
|
+
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2148
|
+
...transformedOperation.properties.focus
|
|
2149
|
+
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
2150
|
+
...transformedOperation.properties.anchor
|
|
2151
|
+
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
2152
|
+
...transformedOperation.newProperties.focus
|
|
2153
|
+
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
2154
|
+
...transformedOperation.newProperties.anchor
|
|
2155
|
+
} : void 0;
|
|
2214
2156
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2215
2157
|
point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
|
|
2216
2158
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2226,14 +2168,23 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2226
2168
|
return [transformedOperation];
|
|
2227
2169
|
}
|
|
2228
2170
|
function adjustBlockPath(operation, level, blockIndex) {
|
|
2229
|
-
|
|
2230
|
-
|
|
2171
|
+
const transformedOperation = {
|
|
2172
|
+
...operation
|
|
2173
|
+
};
|
|
2231
2174
|
if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
|
|
2232
2175
|
const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
|
|
2233
2176
|
transformedOperation.path = newPath;
|
|
2234
2177
|
}
|
|
2235
2178
|
if (transformedOperation.type === "set_selection") {
|
|
2236
|
-
const currentFocus =
|
|
2179
|
+
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2180
|
+
...transformedOperation.properties.focus
|
|
2181
|
+
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
2182
|
+
...transformedOperation.properties.anchor
|
|
2183
|
+
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
2184
|
+
...transformedOperation.newProperties.focus
|
|
2185
|
+
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
2186
|
+
...transformedOperation.newProperties.anchor
|
|
2187
|
+
} : void 0;
|
|
2237
2188
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2238
2189
|
point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
|
|
2239
2190
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2254,27 +2205,18 @@ function withoutSaving(editor, fn) {
|
|
|
2254
2205
|
function createSelectOperation(editor) {
|
|
2255
2206
|
return {
|
|
2256
2207
|
type: "set_selection",
|
|
2257
|
-
properties:
|
|
2258
|
-
|
|
2208
|
+
properties: {
|
|
2209
|
+
...editor.selection
|
|
2210
|
+
},
|
|
2211
|
+
newProperties: {
|
|
2212
|
+
...editor.selection
|
|
2213
|
+
}
|
|
2259
2214
|
};
|
|
2260
2215
|
}
|
|
2261
2216
|
function findOperationTargetBlock(editor, operation) {
|
|
2262
2217
|
let block;
|
|
2263
2218
|
return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
|
|
2264
2219
|
}
|
|
2265
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name), __await = function(promise, isYieldStar) {
|
|
2266
|
-
this[0] = promise, this[1] = isYieldStar;
|
|
2267
|
-
}, __asyncGenerator = (__this, __arguments, generator) => {
|
|
2268
|
-
var resume = (k, v, yes, no) => {
|
|
2269
|
-
try {
|
|
2270
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
2271
|
-
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
2272
|
-
} catch (e) {
|
|
2273
|
-
no(e);
|
|
2274
|
-
}
|
|
2275
|
-
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
2276
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
2277
|
-
}, __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
2278
2220
|
const syncValueCallback = ({
|
|
2279
2221
|
sendBack,
|
|
2280
2222
|
input
|
|
@@ -2325,10 +2267,7 @@ const syncValueCallback = ({
|
|
|
2325
2267
|
}) => context.initialValueSynced,
|
|
2326
2268
|
"is busy": ({
|
|
2327
2269
|
context
|
|
2328
|
-
}) =>
|
|
2329
|
-
var _a;
|
|
2330
|
-
return !context.readOnly && (context.isProcessingLocalChanges || ((_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1));
|
|
2331
|
-
},
|
|
2270
|
+
}) => !context.readOnly && (context.isProcessingLocalChanges || (isChangingRemotely(context.slateEditor) ?? !1)),
|
|
2332
2271
|
"value changed while syncing": ({
|
|
2333
2272
|
context,
|
|
2334
2273
|
event
|
|
@@ -2513,33 +2452,22 @@ async function updateValue({
|
|
|
2513
2452
|
});
|
|
2514
2453
|
isChanged = !0;
|
|
2515
2454
|
}
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2533
|
-
}
|
|
2534
|
-
} catch (temp2) {
|
|
2535
|
-
error = [temp2];
|
|
2536
|
-
} finally {
|
|
2537
|
-
try {
|
|
2538
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2539
|
-
} finally {
|
|
2540
|
-
if (error)
|
|
2541
|
-
throw error[0];
|
|
2542
|
-
}
|
|
2455
|
+
for await (const [currentBlock, currentBlockIndex] of getBlocks({
|
|
2456
|
+
slateValue: slateValueFromProps,
|
|
2457
|
+
streamBlocks
|
|
2458
|
+
})) {
|
|
2459
|
+
const {
|
|
2460
|
+
blockChanged,
|
|
2461
|
+
blockValid
|
|
2462
|
+
} = syncBlock({
|
|
2463
|
+
context,
|
|
2464
|
+
sendBack,
|
|
2465
|
+
block: currentBlock,
|
|
2466
|
+
index: currentBlockIndex,
|
|
2467
|
+
slateEditor,
|
|
2468
|
+
value
|
|
2469
|
+
});
|
|
2470
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2543
2471
|
}
|
|
2544
2472
|
resolve();
|
|
2545
2473
|
});
|
|
@@ -2589,28 +2517,13 @@ async function updateValue({
|
|
|
2589
2517
|
value
|
|
2590
2518
|
});
|
|
2591
2519
|
}
|
|
2592
|
-
function getBlocks(
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
for (var iter = __forAwait(slateValue), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = !1) {
|
|
2600
|
-
const block = temp.value;
|
|
2601
|
-
streamBlocks && (yield new __await(new Promise((resolve) => setTimeout(resolve, 0)))), yield [block, index], index++;
|
|
2602
|
-
}
|
|
2603
|
-
} catch (temp2) {
|
|
2604
|
-
error = [temp2];
|
|
2605
|
-
} finally {
|
|
2606
|
-
try {
|
|
2607
|
-
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2608
|
-
} finally {
|
|
2609
|
-
if (error)
|
|
2610
|
-
throw error[0];
|
|
2611
|
-
}
|
|
2612
|
-
}
|
|
2613
|
-
});
|
|
2520
|
+
async function* getBlocks({
|
|
2521
|
+
slateValue,
|
|
2522
|
+
streamBlocks
|
|
2523
|
+
}) {
|
|
2524
|
+
let index = 0;
|
|
2525
|
+
for await (const block of slateValue)
|
|
2526
|
+
streamBlocks && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
2614
2527
|
}
|
|
2615
2528
|
function syncBlock({
|
|
2616
2529
|
context,
|
|
@@ -2625,15 +2538,14 @@ function syncBlock({
|
|
|
2625
2538
|
return slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
2626
2539
|
withRemoteChanges(slateEditor, () => {
|
|
2627
2540
|
withoutPatching(slateEditor, () => {
|
|
2628
|
-
var _a, _b, _c, _d, _e;
|
|
2629
2541
|
if (hasChanges && blockValid) {
|
|
2630
2542
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2631
|
-
!validation.valid &&
|
|
2543
|
+
!validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${validation.resolution?.description}`), validation.resolution.patches.forEach((patch) => {
|
|
2632
2544
|
sendBack({
|
|
2633
2545
|
type: "patch",
|
|
2634
2546
|
patch
|
|
2635
2547
|
});
|
|
2636
|
-
})), validation.valid ||
|
|
2548
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
2637
2549
|
type: "invalid value",
|
|
2638
2550
|
resolution: validation.resolution,
|
|
2639
2551
|
value
|
|
@@ -2641,7 +2553,7 @@ function syncBlock({
|
|
|
2641
2553
|
}
|
|
2642
2554
|
if (!oldBlock && blockValid) {
|
|
2643
2555
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2644
|
-
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid ||
|
|
2556
|
+
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2645
2557
|
at: [currentBlockIndex]
|
|
2646
2558
|
}) : (debug$i("Invalid", validation), sendBack({
|
|
2647
2559
|
type: "invalid value",
|
|
@@ -2675,9 +2587,9 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2675
2587
|
at: [currentBlockIndex, childIndex]
|
|
2676
2588
|
}));
|
|
2677
2589
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2678
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild
|
|
2590
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2679
2591
|
if (isChildChanged)
|
|
2680
|
-
if (currentBlockChild._key ===
|
|
2592
|
+
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2681
2593
|
debug$i("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2682
2594
|
at: path
|
|
2683
2595
|
});
|
|
@@ -2804,14 +2716,6 @@ function _temp(s) {
|
|
|
2804
2716
|
return s.context.value;
|
|
2805
2717
|
}
|
|
2806
2718
|
Synchronizer.displayName = "Synchronizer";
|
|
2807
|
-
var __defProp$l = Object.defineProperty, __defProps$f = Object.defineProperties, __getOwnPropDescs$f = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$l = Object.getOwnPropertySymbols, __hasOwnProp$l = Object.prototype.hasOwnProperty, __propIsEnum$l = Object.prototype.propertyIsEnumerable, __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$l = (a, b) => {
|
|
2808
|
-
for (var prop in b || (b = {}))
|
|
2809
|
-
__hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2810
|
-
if (__getOwnPropSymbols$l)
|
|
2811
|
-
for (var prop of __getOwnPropSymbols$l(b))
|
|
2812
|
-
__propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2813
|
-
return a;
|
|
2814
|
-
}, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
|
|
2815
2719
|
const debug$g = debugWithName("operationToPatches");
|
|
2816
2720
|
function createOperationToPatches(types2) {
|
|
2817
2721
|
const textBlockName = types2.block.name;
|
|
@@ -2851,7 +2755,10 @@ function createOperationToPatches(types2) {
|
|
|
2851
2755
|
const block = editor.children[operation.path[0]];
|
|
2852
2756
|
if (typeof block._key != "string")
|
|
2853
2757
|
throw new Error("Expected block to have a _key");
|
|
2854
|
-
const setNode = omitBy__default.default(
|
|
2758
|
+
const setNode = omitBy__default.default({
|
|
2759
|
+
...editor.children[operation.path[0]],
|
|
2760
|
+
...operation.newProperties
|
|
2761
|
+
}, isUndefined__default.default);
|
|
2855
2762
|
return [patches.set(fromSlateValue([setNode], textBlockName)[0], [{
|
|
2856
2763
|
_key: block._key
|
|
2857
2764
|
}])];
|
|
@@ -2886,12 +2793,14 @@ function createOperationToPatches(types2) {
|
|
|
2886
2793
|
function insertNodePatch(editor, operation, beforeValue) {
|
|
2887
2794
|
const block = beforeValue[operation.path[0]], isTextBlock = editor.isTextBlock(block);
|
|
2888
2795
|
if (operation.path.length === 1) {
|
|
2889
|
-
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block
|
|
2796
|
+
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
|
|
2890
2797
|
return targetKey ? [patches.insert([fromSlateValue([operation.node], textBlockName)[0]], position, [{
|
|
2891
2798
|
_key: targetKey
|
|
2892
2799
|
}])] : [patches.setIfMissing(beforeValue, []), patches.insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
|
|
2893
2800
|
} else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
|
|
2894
|
-
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node =
|
|
2801
|
+
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
|
|
2802
|
+
...operation.node
|
|
2803
|
+
};
|
|
2895
2804
|
!node._type && slate.Text.isText(node) && (node._type = "span", node.marks = []);
|
|
2896
2805
|
const child = fromSlateValue([{
|
|
2897
2806
|
_key: "bogus",
|
|
@@ -2930,9 +2839,10 @@ function createOperationToPatches(types2) {
|
|
|
2930
2839
|
if (operation.path.length === 2) {
|
|
2931
2840
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
2932
2841
|
if (editor.isTextSpan(splitSpan)) {
|
|
2933
|
-
const targetSpans = fromSlateValue([
|
|
2842
|
+
const targetSpans = fromSlateValue([{
|
|
2843
|
+
...splitBlock,
|
|
2934
2844
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
2935
|
-
}
|
|
2845
|
+
}], textBlockName)[0].children;
|
|
2936
2846
|
patches$1.push(patches.insert(targetSpans, "after", [{
|
|
2937
2847
|
_key: splitBlock._key
|
|
2938
2848
|
}, "children", {
|
|
@@ -2968,7 +2878,7 @@ function createOperationToPatches(types2) {
|
|
|
2968
2878
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2969
2879
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
2970
2880
|
if (operation.path.length === 1)
|
|
2971
|
-
if (block
|
|
2881
|
+
if (block?._key) {
|
|
2972
2882
|
const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
|
|
2973
2883
|
patches$1.push(patches.set(newBlock, [{
|
|
2974
2884
|
_key: newBlock._key
|
|
@@ -3240,7 +3150,6 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3240
3150
|
apply: apply2
|
|
3241
3151
|
} = editor;
|
|
3242
3152
|
return editor.apply = (operation) => {
|
|
3243
|
-
var _a;
|
|
3244
3153
|
if (editorActor.getSnapshot().matches({
|
|
3245
3154
|
"edit mode": "read only"
|
|
3246
3155
|
})) {
|
|
@@ -3255,19 +3164,11 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3255
3164
|
apply2(operation);
|
|
3256
3165
|
return;
|
|
3257
3166
|
}
|
|
3258
|
-
const rows =
|
|
3167
|
+
const rows = editorActor.getSnapshot().context.maxBlocks ?? -1;
|
|
3259
3168
|
rows > 0 && editor.children.length >= rows && (operation.type === "insert_node" || operation.type === "split_node") && operation.path.length === 1 || apply2(operation);
|
|
3260
3169
|
}, editor;
|
|
3261
3170
|
};
|
|
3262
3171
|
}
|
|
3263
|
-
var __defProp$k = Object.defineProperty, __defProps$e = Object.defineProperties, __getOwnPropDescs$e = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$k = Object.getOwnPropertySymbols, __hasOwnProp$k = Object.prototype.hasOwnProperty, __propIsEnum$k = Object.prototype.propertyIsEnumerable, __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$k = (a, b) => {
|
|
3264
|
-
for (var prop in b || (b = {}))
|
|
3265
|
-
__hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3266
|
-
if (__getOwnPropSymbols$k)
|
|
3267
|
-
for (var prop of __getOwnPropSymbols$k(b))
|
|
3268
|
-
__propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3269
|
-
return a;
|
|
3270
|
-
}, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
3271
3172
|
function createWithObjectKeys(editorActor, schemaTypes) {
|
|
3272
3173
|
return function(editor) {
|
|
3273
3174
|
const {
|
|
@@ -3284,19 +3185,23 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3284
3185
|
return;
|
|
3285
3186
|
}
|
|
3286
3187
|
if (operation.type === "split_node") {
|
|
3287
|
-
apply2(
|
|
3288
|
-
|
|
3188
|
+
apply2({
|
|
3189
|
+
...operation,
|
|
3190
|
+
properties: {
|
|
3191
|
+
...operation.properties,
|
|
3289
3192
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3290
|
-
}
|
|
3291
|
-
})
|
|
3193
|
+
}
|
|
3194
|
+
});
|
|
3292
3195
|
return;
|
|
3293
3196
|
}
|
|
3294
3197
|
if (operation.type === "insert_node" && !slate.Editor.isEditor(operation.node)) {
|
|
3295
|
-
apply2(
|
|
3296
|
-
|
|
3198
|
+
apply2({
|
|
3199
|
+
...operation,
|
|
3200
|
+
node: {
|
|
3201
|
+
...operation.node,
|
|
3297
3202
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3298
|
-
}
|
|
3299
|
-
})
|
|
3203
|
+
}
|
|
3204
|
+
});
|
|
3300
3205
|
return;
|
|
3301
3206
|
}
|
|
3302
3207
|
apply2(operation);
|
|
@@ -3333,22 +3238,6 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3333
3238
|
}, editor;
|
|
3334
3239
|
};
|
|
3335
3240
|
}
|
|
3336
|
-
var __defProp$j = Object.defineProperty, __defProps$d = Object.defineProperties, __getOwnPropDescs$d = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$j = Object.getOwnPropertySymbols, __hasOwnProp$j = Object.prototype.hasOwnProperty, __propIsEnum$j = Object.prototype.propertyIsEnumerable, __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$j = (a, b) => {
|
|
3337
|
-
for (var prop in b || (b = {}))
|
|
3338
|
-
__hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3339
|
-
if (__getOwnPropSymbols$j)
|
|
3340
|
-
for (var prop of __getOwnPropSymbols$j(b))
|
|
3341
|
-
__propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3342
|
-
return a;
|
|
3343
|
-
}, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
|
|
3344
|
-
var target = {};
|
|
3345
|
-
for (var prop in source)
|
|
3346
|
-
__hasOwnProp$j.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
3347
|
-
if (source != null && __getOwnPropSymbols$j)
|
|
3348
|
-
for (var prop of __getOwnPropSymbols$j(source))
|
|
3349
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$j.call(source, prop) && (target[prop] = source[prop]);
|
|
3350
|
-
return target;
|
|
3351
|
-
};
|
|
3352
3241
|
const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
|
|
3353
3242
|
function createApplyPatch(schemaTypes) {
|
|
3354
3243
|
return (editor, patch) => {
|
|
@@ -3438,9 +3327,10 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3438
3327
|
} = patch;
|
|
3439
3328
|
if (!targetChild || !targetChildPath)
|
|
3440
3329
|
return debug$f("Child not found"), !1;
|
|
3441
|
-
const childrenToInsert = targetBlock && toSlateValue([
|
|
3330
|
+
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3331
|
+
...targetBlock,
|
|
3442
3332
|
children: items
|
|
3443
|
-
}
|
|
3333
|
+
}], {
|
|
3444
3334
|
schemaTypes
|
|
3445
3335
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3446
3336
|
return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
@@ -3485,19 +3375,21 @@ function setPatch(editor, patch) {
|
|
|
3485
3375
|
return !0;
|
|
3486
3376
|
} else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3487
3377
|
debug$f("Setting block property");
|
|
3488
|
-
const
|
|
3489
|
-
children
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3378
|
+
const {
|
|
3379
|
+
children,
|
|
3380
|
+
...nextRest
|
|
3381
|
+
} = value, {
|
|
3382
|
+
children: prevChildren,
|
|
3383
|
+
...prevRest
|
|
3384
|
+
} = block || {
|
|
3493
3385
|
children: void 0
|
|
3494
|
-
}
|
|
3495
|
-
"children"
|
|
3496
|
-
]);
|
|
3386
|
+
};
|
|
3497
3387
|
editor.apply({
|
|
3498
3388
|
type: "set_node",
|
|
3499
3389
|
path: blockPath,
|
|
3500
|
-
properties:
|
|
3390
|
+
properties: {
|
|
3391
|
+
...prevRest
|
|
3392
|
+
},
|
|
3501
3393
|
newProperties: nextRest
|
|
3502
3394
|
}), debug$f("Setting children"), block.children.forEach((c, cIndex) => {
|
|
3503
3395
|
editor.apply({
|
|
@@ -3514,9 +3406,10 @@ function setPatch(editor, patch) {
|
|
|
3514
3406
|
});
|
|
3515
3407
|
} else if (block && "value" in block) {
|
|
3516
3408
|
const newVal = patches.applyAll([block.value], [patch])[0];
|
|
3517
|
-
return slate.Transforms.setNodes(editor,
|
|
3409
|
+
return slate.Transforms.setNodes(editor, {
|
|
3410
|
+
...block,
|
|
3518
3411
|
value: newVal
|
|
3519
|
-
}
|
|
3412
|
+
}, {
|
|
3520
3413
|
at: blockPath
|
|
3521
3414
|
}), !0;
|
|
3522
3415
|
}
|
|
@@ -3599,7 +3492,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3599
3492
|
block,
|
|
3600
3493
|
child,
|
|
3601
3494
|
blockPath,
|
|
3602
|
-
childPath: blockPath
|
|
3495
|
+
childPath: blockPath?.concat(childIndex)
|
|
3603
3496
|
} : {
|
|
3604
3497
|
block,
|
|
3605
3498
|
blockPath,
|
|
@@ -3607,14 +3500,6 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3607
3500
|
childPath: void 0
|
|
3608
3501
|
};
|
|
3609
3502
|
}
|
|
3610
|
-
var __defProp$i = Object.defineProperty, __defProps$c = Object.defineProperties, __getOwnPropDescs$c = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$i = Object.getOwnPropertySymbols, __hasOwnProp$i = Object.prototype.hasOwnProperty, __propIsEnum$i = Object.prototype.propertyIsEnumerable, __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$i = (a, b) => {
|
|
3611
|
-
for (var prop in b || (b = {}))
|
|
3612
|
-
__hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3613
|
-
if (__getOwnPropSymbols$i)
|
|
3614
|
-
for (var prop of __getOwnPropSymbols$i(b))
|
|
3615
|
-
__propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3616
|
-
return a;
|
|
3617
|
-
}, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
3618
3503
|
const debug$e = debugWithName("plugin:withPatches");
|
|
3619
3504
|
function createWithPatches({
|
|
3620
3505
|
editorActor,
|
|
@@ -3699,9 +3584,10 @@ function createWithPatches({
|
|
|
3699
3584
|
})), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0 && patches$1.forEach((patch) => {
|
|
3700
3585
|
editorActor.send({
|
|
3701
3586
|
type: "patch",
|
|
3702
|
-
patch:
|
|
3587
|
+
patch: {
|
|
3588
|
+
...patch,
|
|
3703
3589
|
origin: "local"
|
|
3704
|
-
}
|
|
3590
|
+
}
|
|
3705
3591
|
});
|
|
3706
3592
|
}), editor;
|
|
3707
3593
|
}, editor;
|
|
@@ -3814,14 +3700,6 @@ function getNextSpan({
|
|
|
3814
3700
|
}
|
|
3815
3701
|
return nextSpan;
|
|
3816
3702
|
}
|
|
3817
|
-
var __defProp$h = Object.defineProperty, __defProps$b = Object.defineProperties, __getOwnPropDescs$b = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$h = Object.getOwnPropertySymbols, __hasOwnProp$h = Object.prototype.hasOwnProperty, __propIsEnum$h = Object.prototype.propertyIsEnumerable, __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$h = (a, b) => {
|
|
3818
|
-
for (var prop in b || (b = {}))
|
|
3819
|
-
__hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3820
|
-
if (__getOwnPropSymbols$h)
|
|
3821
|
-
for (var prop of __getOwnPropSymbols$h(b))
|
|
3822
|
-
__propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3823
|
-
return a;
|
|
3824
|
-
}, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
|
|
3825
3703
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
3826
3704
|
function createWithPortableTextMarkModel(editorActor, types2) {
|
|
3827
3705
|
return function(editor) {
|
|
@@ -3830,19 +3708,12 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3830
3708
|
normalizeNode
|
|
3831
3709
|
} = editor, decorators = types2.decorators.map((t) => t.value);
|
|
3832
3710
|
return editor.normalizeNode = (nodeEntry) => {
|
|
3833
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3834
3711
|
const [node, path] = nodeEntry;
|
|
3835
3712
|
if (editor.isTextBlock(node)) {
|
|
3836
3713
|
const children = slate.Node.children(editor, path);
|
|
3837
3714
|
for (const [child, childPath] of children) {
|
|
3838
3715
|
const nextNode = node.children[childPath[1] + 1];
|
|
3839
|
-
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && (
|
|
3840
|
-
var _a2;
|
|
3841
|
-
return (_a2 = nextNode.marks) == null ? void 0 : _a2.includes(mark);
|
|
3842
|
-
}) && (_b = nextNode.marks) != null && _b.every((mark) => {
|
|
3843
|
-
var _a2;
|
|
3844
|
-
return (_a2 = child.marks) == null ? void 0 : _a2.includes(mark);
|
|
3845
|
-
})) {
|
|
3716
|
+
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3846
3717
|
debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3847
3718
|
type: "normalizing"
|
|
3848
3719
|
}), slate.Transforms.mergeNodes(editor, {
|
|
@@ -3880,12 +3751,12 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3880
3751
|
return;
|
|
3881
3752
|
}
|
|
3882
3753
|
if (editor.isTextSpan(node)) {
|
|
3883
|
-
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations =
|
|
3754
|
+
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3884
3755
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3885
3756
|
debug$b("Removing annotations from empty span node"), editorActor.send({
|
|
3886
3757
|
type: "normalizing"
|
|
3887
3758
|
}), slate.Transforms.setNodes(editor, {
|
|
3888
|
-
marks:
|
|
3759
|
+
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
3889
3760
|
}, {
|
|
3890
3761
|
at: path
|
|
3891
3762
|
}), editorActor.send({
|
|
@@ -3898,10 +3769,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3898
3769
|
const decorators2 = types2.decorators.map((decorator) => decorator.value);
|
|
3899
3770
|
for (const [child, childPath] of slate.Node.children(editor, path))
|
|
3900
3771
|
if (editor.isTextSpan(child)) {
|
|
3901
|
-
const marks =
|
|
3902
|
-
var _a2;
|
|
3903
|
-
return !decorators2.includes(mark) && !((_a2 = node.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3904
|
-
});
|
|
3772
|
+
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3905
3773
|
if (orphanedAnnotations.length > 0) {
|
|
3906
3774
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3907
3775
|
type: "normalizing"
|
|
@@ -3919,10 +3787,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3919
3787
|
if (editor.isTextSpan(node)) {
|
|
3920
3788
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath);
|
|
3921
3789
|
if (editor.isTextBlock(block)) {
|
|
3922
|
-
const decorators2 = types2.decorators.map((decorator) => decorator.value), marks =
|
|
3923
|
-
var _a2;
|
|
3924
|
-
return !decorators2.includes(mark) && !((_a2 = block.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3925
|
-
});
|
|
3790
|
+
const decorators2 = types2.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3926
3791
|
if (orphanedAnnotations.length > 0) {
|
|
3927
3792
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3928
3793
|
type: "normalizing"
|
|
@@ -3938,7 +3803,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3938
3803
|
}
|
|
3939
3804
|
}
|
|
3940
3805
|
if (editor.isTextBlock(node)) {
|
|
3941
|
-
const markDefs =
|
|
3806
|
+
const markDefs = node.markDefs ?? [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
|
|
3942
3807
|
for (const markDef of markDefs)
|
|
3943
3808
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3944
3809
|
if (markDefs.length !== newMarkDefs.length) {
|
|
@@ -3971,7 +3836,6 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3971
3836
|
}
|
|
3972
3837
|
normalizeNode(nodeEntry);
|
|
3973
3838
|
}, editor.apply = (op) => {
|
|
3974
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
3975
3839
|
if (isChangingRemotely(editor)) {
|
|
3976
3840
|
apply2(op);
|
|
3977
3841
|
return;
|
|
@@ -3989,17 +3853,17 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3989
3853
|
focus: op.newProperties.focus
|
|
3990
3854
|
});
|
|
3991
3855
|
if (previousSelectionIsCollapsed && newSelectionIsCollapsed) {
|
|
3992
|
-
const focusSpan =
|
|
3856
|
+
const focusSpan = Array.from(slate.Editor.nodes(editor, {
|
|
3993
3857
|
mode: "lowest",
|
|
3994
3858
|
at: op.properties.focus,
|
|
3995
3859
|
match: (n) => editor.isTextSpan(n),
|
|
3996
3860
|
voids: !1
|
|
3997
|
-
}))[0]
|
|
3861
|
+
}))[0]?.[0], newFocusSpan = Array.from(slate.Editor.nodes(editor, {
|
|
3998
3862
|
mode: "lowest",
|
|
3999
3863
|
at: op.newProperties.focus,
|
|
4000
3864
|
match: (n) => editor.isTextSpan(n),
|
|
4001
3865
|
voids: !1
|
|
4002
|
-
}))[0]
|
|
3866
|
+
}))[0]?.[0], movedToNextSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] + 1 && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] - 1 && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
|
|
4003
3867
|
if (movedToNextSpan || movedToPreviousSpan)
|
|
4004
3868
|
return;
|
|
4005
3869
|
}
|
|
@@ -4015,29 +3879,32 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4015
3879
|
editor,
|
|
4016
3880
|
blockPath,
|
|
4017
3881
|
spanPath: op.path
|
|
4018
|
-
}), previousSpanAnnotations = previousSpan ?
|
|
3882
|
+
}), previousSpanAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], nextSpan = getNextSpan({
|
|
4019
3883
|
editor,
|
|
4020
3884
|
blockPath,
|
|
4021
3885
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
4022
|
-
}), nextSpanAnnotations = nextSpan ?
|
|
4023
|
-
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4024
|
-
slate.Transforms.insertNodes(editor,
|
|
4025
|
-
|
|
4026
|
-
|
|
3886
|
+
}), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [], atTheEndOfAnnotation = annotationsEnding.length > 0;
|
|
3887
|
+
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
|
|
3888
|
+
slate.Transforms.insertNodes(editor, {
|
|
3889
|
+
...op.node,
|
|
3890
|
+
marks: op.node.marks?.filter((mark) => !annotationsEnding.includes(mark)) ?? []
|
|
3891
|
+
});
|
|
4027
3892
|
return;
|
|
4028
3893
|
}
|
|
4029
|
-
const annotationsStarting =
|
|
4030
|
-
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4031
|
-
slate.Transforms.insertNodes(editor,
|
|
4032
|
-
|
|
4033
|
-
|
|
3894
|
+
const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3895
|
+
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
|
|
3896
|
+
slate.Transforms.insertNodes(editor, {
|
|
3897
|
+
...op.node,
|
|
3898
|
+
marks: op.node.marks?.filter((mark) => !annotationsStarting.includes(mark)) ?? []
|
|
3899
|
+
});
|
|
4034
3900
|
return;
|
|
4035
3901
|
}
|
|
4036
|
-
const nextSpanDecorators =
|
|
4037
|
-
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) &&
|
|
4038
|
-
slate.Transforms.insertNodes(editor,
|
|
3902
|
+
const nextSpanDecorators = nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? [];
|
|
3903
|
+
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.length === 0) {
|
|
3904
|
+
slate.Transforms.insertNodes(editor, {
|
|
3905
|
+
...op.node,
|
|
4039
3906
|
marks: nextSpanDecorators
|
|
4040
|
-
})
|
|
3907
|
+
});
|
|
4041
3908
|
return;
|
|
4042
3909
|
}
|
|
4043
3910
|
}
|
|
@@ -4049,12 +3916,12 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4049
3916
|
if (selection && collapsedSelection) {
|
|
4050
3917
|
const [_block, blockPath] = slate.Editor.node(editor, selection, {
|
|
4051
3918
|
depth: 1
|
|
4052
|
-
}), [span, spanPath] =
|
|
3919
|
+
}), [span, spanPath] = Array.from(slate.Editor.nodes(editor, {
|
|
4053
3920
|
mode: "lowest",
|
|
4054
3921
|
at: selection.focus,
|
|
4055
3922
|
match: (n) => editor.isTextSpan(n),
|
|
4056
3923
|
voids: !1
|
|
4057
|
-
}))[0]
|
|
3924
|
+
}))[0] ?? [void 0, void 0], marks = span.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = selection.anchor.offset === 0, atTheEndOfSpan = selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
|
|
4058
3925
|
editor,
|
|
4059
3926
|
blockPath,
|
|
4060
3927
|
spanPath
|
|
@@ -4062,7 +3929,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4062
3929
|
editor,
|
|
4063
3930
|
blockPath,
|
|
4064
3931
|
spanPath
|
|
4065
|
-
}), nextSpanAnnotations =
|
|
3932
|
+
}), nextSpanAnnotations = nextSpan?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
|
|
4066
3933
|
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4067
3934
|
if (atTheBeginningOfSpan) {
|
|
4068
3935
|
if (previousSpanHasSameMarks) {
|
|
@@ -4070,7 +3937,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4070
3937
|
_type: "span",
|
|
4071
3938
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4072
3939
|
text: op.text,
|
|
4073
|
-
marks:
|
|
3940
|
+
marks: previousSpan?.marks ?? []
|
|
4074
3941
|
});
|
|
4075
3942
|
return;
|
|
4076
3943
|
} else if (previousSpanHasSameAnnotations) {
|
|
@@ -4078,7 +3945,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4078
3945
|
_type: "span",
|
|
4079
3946
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4080
3947
|
text: op.text,
|
|
4081
|
-
marks:
|
|
3948
|
+
marks: previousSpan?.marks ?? []
|
|
4082
3949
|
});
|
|
4083
3950
|
return;
|
|
4084
3951
|
} else if (previousSpanHasSameAnnotation) {
|
|
@@ -4100,7 +3967,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4100
3967
|
_type: "span",
|
|
4101
3968
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4102
3969
|
text: op.text,
|
|
4103
|
-
marks:
|
|
3970
|
+
marks: nextSpan?.marks ?? []
|
|
4104
3971
|
});
|
|
4105
3972
|
return;
|
|
4106
3973
|
}
|
|
@@ -4120,7 +3987,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4120
3987
|
_type: "span",
|
|
4121
3988
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4122
3989
|
text: op.text,
|
|
4123
|
-
marks: previousSpanHasAnnotations ? [] : (
|
|
3990
|
+
marks: previousSpanHasAnnotations ? [] : (previousSpan.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
4124
3991
|
});
|
|
4125
3992
|
return;
|
|
4126
3993
|
}
|
|
@@ -4133,7 +4000,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4133
4000
|
if (selection && slate.Range.isExpanded(selection)) {
|
|
4134
4001
|
const [block, blockPath] = slate.Editor.node(editor, selection, {
|
|
4135
4002
|
depth: 1
|
|
4136
|
-
}), [span, spanPath] =
|
|
4003
|
+
}), [span, spanPath] = Array.from(slate.Editor.nodes(editor, {
|
|
4137
4004
|
mode: "lowest",
|
|
4138
4005
|
at: {
|
|
4139
4006
|
path: op.path,
|
|
@@ -4141,9 +4008,9 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4141
4008
|
},
|
|
4142
4009
|
match: (n) => editor.isTextSpan(n),
|
|
4143
4010
|
voids: !1
|
|
4144
|
-
}))[0]
|
|
4011
|
+
}))[0] ?? [void 0, void 0];
|
|
4145
4012
|
if (span && block && isPortableTextBlock(block)) {
|
|
4146
|
-
const markDefs =
|
|
4013
|
+
const markDefs = block.markDefs ?? [], marks = span.marks ?? [], spanHasAnnotations = marks.some((mark) => markDefs.find((markDef) => markDef._key === mark)), deletingFromTheEnd = op.offset + op.text.length === span.text.length, deletingAllText = op.offset === 0 && deletingFromTheEnd, previousSpan = getPreviousSpan({
|
|
4147
4014
|
editor,
|
|
4148
4015
|
blockPath,
|
|
4149
4016
|
spanPath
|
|
@@ -4151,9 +4018,11 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4151
4018
|
editor,
|
|
4152
4019
|
blockPath,
|
|
4153
4020
|
spanPath
|
|
4154
|
-
}), previousSpanHasSameAnnotation = previousSpan ?
|
|
4021
|
+
}), previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? nextSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
|
|
4155
4022
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
4156
|
-
const marksWithoutAnnotationMarks = (
|
|
4023
|
+
const marksWithoutAnnotationMarks = ({
|
|
4024
|
+
...slate.Editor.marks(editor) || {}
|
|
4025
|
+
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
4157
4026
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
4158
4027
|
apply2(op), slate.Transforms.setNodes(editor, {
|
|
4159
4028
|
marks: marksWithoutAnnotationMarks
|
|
@@ -4186,7 +4055,6 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4186
4055
|
const addDecoratorActionImplementation = ({
|
|
4187
4056
|
action
|
|
4188
4057
|
}) => {
|
|
4189
|
-
var _a;
|
|
4190
4058
|
const editor = action.editor, mark = action.decorator;
|
|
4191
4059
|
if (editor.selection) {
|
|
4192
4060
|
if (slate.Range.isExpanded(editor.selection)) {
|
|
@@ -4199,10 +4067,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4199
4067
|
at: editor.selection,
|
|
4200
4068
|
match: slate.Text.isText
|
|
4201
4069
|
})] : [];
|
|
4202
|
-
splitTextNodes.length > 1 && splitTextNodes.every((node) => {
|
|
4203
|
-
var _a2;
|
|
4204
|
-
return (_a2 = node[0].marks) == null ? void 0 : _a2.includes(mark);
|
|
4205
|
-
}) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4070
|
+
splitTextNodes.length > 1 && splitTextNodes.every((node) => node[0].marks?.includes(mark)) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4206
4071
|
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
4207
4072
|
slate.Transforms.setNodes(editor, {
|
|
4208
4073
|
marks
|
|
@@ -4218,7 +4083,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4218
4083
|
depth: 1
|
|
4219
4084
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4220
4085
|
if (lonelyEmptySpan) {
|
|
4221
|
-
const existingMarks =
|
|
4086
|
+
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
4222
4087
|
slate.Transforms.setNodes(editor, {
|
|
4223
4088
|
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
4224
4089
|
}, {
|
|
@@ -4226,9 +4091,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4226
4091
|
match: (node) => editor.isTextSpan(node)
|
|
4227
4092
|
});
|
|
4228
4093
|
} else {
|
|
4229
|
-
const existingMarks =
|
|
4094
|
+
const existingMarks = {
|
|
4095
|
+
...slate.Editor.marks(editor) || {}
|
|
4096
|
+
}.marks || [], marks = {
|
|
4097
|
+
...slate.Editor.marks(editor) || {},
|
|
4230
4098
|
marks: [...existingMarks, mark]
|
|
4231
|
-
}
|
|
4099
|
+
};
|
|
4232
4100
|
editor.marks = marks;
|
|
4233
4101
|
}
|
|
4234
4102
|
}
|
|
@@ -4237,7 +4105,6 @@ const addDecoratorActionImplementation = ({
|
|
|
4237
4105
|
}, removeDecoratorActionImplementation = ({
|
|
4238
4106
|
action
|
|
4239
4107
|
}) => {
|
|
4240
|
-
var _a;
|
|
4241
4108
|
const editor = action.editor, mark = action.decorator, {
|
|
4242
4109
|
selection
|
|
4243
4110
|
} = editor;
|
|
@@ -4264,7 +4131,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4264
4131
|
depth: 1
|
|
4265
4132
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4266
4133
|
if (lonelyEmptySpan) {
|
|
4267
|
-
const existingMarksWithoutDecorator = (
|
|
4134
|
+
const existingMarksWithoutDecorator = (lonelyEmptySpan.marks ?? []).filter((existingMark) => existingMark !== mark);
|
|
4268
4135
|
slate.Transforms.setNodes(editor, {
|
|
4269
4136
|
marks: existingMarksWithoutDecorator
|
|
4270
4137
|
}, {
|
|
@@ -4272,9 +4139,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4272
4139
|
match: (node) => editor.isTextSpan(node)
|
|
4273
4140
|
});
|
|
4274
4141
|
} else {
|
|
4275
|
-
const existingMarks =
|
|
4142
|
+
const existingMarks = {
|
|
4143
|
+
...slate.Editor.marks(editor) || {}
|
|
4144
|
+
}.marks || [], marks = {
|
|
4145
|
+
...slate.Editor.marks(editor) || {},
|
|
4276
4146
|
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
4277
|
-
}
|
|
4147
|
+
};
|
|
4278
4148
|
editor.marks = {
|
|
4279
4149
|
marks: marks.marks,
|
|
4280
4150
|
_type: "span"
|
|
@@ -4293,10 +4163,11 @@ function isDecoratorActive({
|
|
|
4293
4163
|
at: editor.selection
|
|
4294
4164
|
}));
|
|
4295
4165
|
return selectedTextNodes.length === 0 ? !1 : slate.Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
|
|
4296
|
-
var _a;
|
|
4297
4166
|
const [node] = n;
|
|
4298
|
-
return
|
|
4299
|
-
}) : (
|
|
4167
|
+
return node.marks?.includes(decorator);
|
|
4168
|
+
}) : ({
|
|
4169
|
+
...slate.Editor.marks(editor) || {}
|
|
4170
|
+
}.marks || []).includes(decorator);
|
|
4300
4171
|
}
|
|
4301
4172
|
const toggleDecoratorActionImplementation = ({
|
|
4302
4173
|
context,
|
|
@@ -4356,14 +4227,6 @@ function createWithPortableTextSelections(editorActor, types2) {
|
|
|
4356
4227
|
}, editor;
|
|
4357
4228
|
};
|
|
4358
4229
|
}
|
|
4359
|
-
var __defProp$g = Object.defineProperty, __defProps$a = Object.defineProperties, __getOwnPropDescs$a = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$g = Object.getOwnPropertySymbols, __hasOwnProp$g = Object.prototype.hasOwnProperty, __propIsEnum$g = Object.prototype.propertyIsEnumerable, __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$g = (a, b) => {
|
|
4360
|
-
for (var prop in b || (b = {}))
|
|
4361
|
-
__hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4362
|
-
if (__getOwnPropSymbols$g)
|
|
4363
|
-
for (var prop of __getOwnPropSymbols$g(b))
|
|
4364
|
-
__propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4365
|
-
return a;
|
|
4366
|
-
}, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
4367
4230
|
const debug$9 = debugWithName("plugin:withSchemaTypes");
|
|
4368
4231
|
function createWithSchemaTypes({
|
|
4369
4232
|
editorActor,
|
|
@@ -4381,10 +4244,11 @@ function createWithSchemaTypes({
|
|
|
4381
4244
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4382
4245
|
editorActor.send({
|
|
4383
4246
|
type: "normalizing"
|
|
4384
|
-
}), slate.Transforms.setNodes(editor,
|
|
4247
|
+
}), slate.Transforms.setNodes(editor, {
|
|
4248
|
+
...span,
|
|
4385
4249
|
_type: schemaTypes.span.name,
|
|
4386
4250
|
_key: key
|
|
4387
|
-
}
|
|
4251
|
+
}, {
|
|
4388
4252
|
at: path
|
|
4389
4253
|
}), editorActor.send({
|
|
4390
4254
|
type: "done normalizing"
|
|
@@ -4409,14 +4273,6 @@ function createWithSchemaTypes({
|
|
|
4409
4273
|
}, editor;
|
|
4410
4274
|
};
|
|
4411
4275
|
}
|
|
4412
|
-
var __defProp$f = Object.defineProperty, __defProps$9 = Object.defineProperties, __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$f = Object.getOwnPropertySymbols, __hasOwnProp$f = Object.prototype.hasOwnProperty, __propIsEnum$f = Object.prototype.propertyIsEnumerable, __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$f = (a, b) => {
|
|
4413
|
-
for (var prop in b || (b = {}))
|
|
4414
|
-
__hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4415
|
-
if (__getOwnPropSymbols$f)
|
|
4416
|
-
for (var prop of __getOwnPropSymbols$f(b))
|
|
4417
|
-
__propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4418
|
-
return a;
|
|
4419
|
-
}, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
4420
4276
|
const debug$8 = debugWithName("plugin:withUtils");
|
|
4421
4277
|
function createWithUtils({
|
|
4422
4278
|
editorActor,
|
|
@@ -4440,26 +4296,29 @@ function createWithUtils({
|
|
|
4440
4296
|
} = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
|
|
4441
4297
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4442
4298
|
debug$8("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
|
|
4443
|
-
anchor:
|
|
4299
|
+
anchor: {
|
|
4300
|
+
...selection.anchor,
|
|
4444
4301
|
offset: newStartOffset
|
|
4445
|
-
}
|
|
4446
|
-
focus:
|
|
4302
|
+
},
|
|
4303
|
+
focus: {
|
|
4304
|
+
...selection.focus,
|
|
4447
4305
|
offset: newEndOffset
|
|
4448
|
-
}
|
|
4306
|
+
}
|
|
4449
4307
|
});
|
|
4450
4308
|
return;
|
|
4451
4309
|
}
|
|
4452
4310
|
debug$8("pteExpandToWord: Can't expand to word here");
|
|
4453
4311
|
}
|
|
4454
|
-
}, editor.pteCreateTextBlock = (options) => toSlateValue([
|
|
4312
|
+
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4455
4313
|
_type: schemaTypes.block.name,
|
|
4456
4314
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4457
|
-
style: schemaTypes.styles[0].value || "normal"
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4315
|
+
style: schemaTypes.styles[0].value || "normal",
|
|
4316
|
+
...options.listItem ? {
|
|
4317
|
+
listItem: options.listItem
|
|
4318
|
+
} : {},
|
|
4319
|
+
...options.level ? {
|
|
4320
|
+
level: options.level
|
|
4321
|
+
} : {},
|
|
4463
4322
|
markDefs: [],
|
|
4464
4323
|
children: [{
|
|
4465
4324
|
_type: "span",
|
|
@@ -4469,7 +4328,7 @@ function createWithUtils({
|
|
|
4469
4328
|
value
|
|
4470
4329
|
}) => value === decorator))
|
|
4471
4330
|
}]
|
|
4472
|
-
}
|
|
4331
|
+
}], {
|
|
4473
4332
|
schemaTypes
|
|
4474
4333
|
})[0], editor;
|
|
4475
4334
|
};
|
|
@@ -4515,14 +4374,6 @@ function createSlateEditor(config) {
|
|
|
4515
4374
|
};
|
|
4516
4375
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4517
4376
|
}
|
|
4518
|
-
var __defProp$e = Object.defineProperty, __defProps$8 = Object.defineProperties, __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$e = Object.getOwnPropertySymbols, __hasOwnProp$e = Object.prototype.hasOwnProperty, __propIsEnum$e = Object.prototype.propertyIsEnumerable, __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$e = (a, b) => {
|
|
4519
|
-
for (var prop in b || (b = {}))
|
|
4520
|
-
__hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4521
|
-
if (__getOwnPropSymbols$e)
|
|
4522
|
-
for (var prop of __getOwnPropSymbols$e(b))
|
|
4523
|
-
__propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4524
|
-
return a;
|
|
4525
|
-
}, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
4526
4377
|
const toggleListItemActionImplementation = ({
|
|
4527
4378
|
context,
|
|
4528
4379
|
action
|
|
@@ -4532,14 +4383,16 @@ const toggleListItemActionImplementation = ({
|
|
|
4532
4383
|
listItem: action.listItem
|
|
4533
4384
|
}) ? removeListItemActionImplementation({
|
|
4534
4385
|
context,
|
|
4535
|
-
action:
|
|
4386
|
+
action: {
|
|
4387
|
+
...action,
|
|
4536
4388
|
type: "list item.remove"
|
|
4537
|
-
}
|
|
4389
|
+
}
|
|
4538
4390
|
}) : addListItemActionImplementation({
|
|
4539
4391
|
context,
|
|
4540
|
-
action:
|
|
4392
|
+
action: {
|
|
4393
|
+
...action,
|
|
4541
4394
|
type: "list item.add"
|
|
4542
|
-
}
|
|
4395
|
+
}
|
|
4543
4396
|
});
|
|
4544
4397
|
}, removeListItemActionImplementation = ({
|
|
4545
4398
|
context,
|
|
@@ -4585,14 +4438,6 @@ function isListItemActive({
|
|
|
4585
4438
|
})];
|
|
4586
4439
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
4587
4440
|
}
|
|
4588
|
-
var __defProp$d = Object.defineProperty, __defProps$7 = Object.defineProperties, __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$d = Object.getOwnPropertySymbols, __hasOwnProp$d = Object.prototype.hasOwnProperty, __propIsEnum$d = Object.prototype.propertyIsEnumerable, __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$d = (a, b) => {
|
|
4589
|
-
for (var prop in b || (b = {}))
|
|
4590
|
-
__hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4591
|
-
if (__getOwnPropSymbols$d)
|
|
4592
|
-
for (var prop of __getOwnPropSymbols$d(b))
|
|
4593
|
-
__propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4594
|
-
return a;
|
|
4595
|
-
}, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
4596
4441
|
const toggleStyleActionImplementation = ({
|
|
4597
4442
|
context,
|
|
4598
4443
|
action
|
|
@@ -4602,14 +4447,16 @@ const toggleStyleActionImplementation = ({
|
|
|
4602
4447
|
style: action.style
|
|
4603
4448
|
}) ? removeStyleActionImplementation({
|
|
4604
4449
|
context,
|
|
4605
|
-
action:
|
|
4450
|
+
action: {
|
|
4451
|
+
...action,
|
|
4606
4452
|
type: "style.remove"
|
|
4607
|
-
}
|
|
4453
|
+
}
|
|
4608
4454
|
}) : addStyleActionImplementation({
|
|
4609
4455
|
context,
|
|
4610
|
-
action:
|
|
4456
|
+
action: {
|
|
4457
|
+
...action,
|
|
4611
4458
|
type: "style.add"
|
|
4612
|
-
}
|
|
4459
|
+
}
|
|
4613
4460
|
});
|
|
4614
4461
|
}, removeStyleActionImplementation = ({
|
|
4615
4462
|
context,
|
|
@@ -4656,14 +4503,6 @@ function isStyleActive({
|
|
|
4656
4503
|
})];
|
|
4657
4504
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
4658
4505
|
}
|
|
4659
|
-
var __defProp$c = Object.defineProperty, __getOwnPropSymbols$c = Object.getOwnPropertySymbols, __hasOwnProp$c = Object.prototype.hasOwnProperty, __propIsEnum$c = Object.prototype.propertyIsEnumerable, __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$c = (a, b) => {
|
|
4660
|
-
for (var prop in b || (b = {}))
|
|
4661
|
-
__hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4662
|
-
if (__getOwnPropSymbols$c)
|
|
4663
|
-
for (var prop of __getOwnPropSymbols$c(b))
|
|
4664
|
-
__propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4665
|
-
return a;
|
|
4666
|
-
};
|
|
4667
4506
|
const debug$6 = debugWithName("API:editable");
|
|
4668
4507
|
function createEditableAPI(editor, editorActor) {
|
|
4669
4508
|
const types2 = editorActor.getSnapshot().context.schema;
|
|
@@ -4726,7 +4565,9 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4726
4565
|
return console.warn(err), !1;
|
|
4727
4566
|
}
|
|
4728
4567
|
},
|
|
4729
|
-
marks: () =>
|
|
4568
|
+
marks: () => ({
|
|
4569
|
+
...slate.Editor.marks(editor) || {}
|
|
4570
|
+
}).marks || [],
|
|
4730
4571
|
undo: () => editor.undo(),
|
|
4731
4572
|
redo: () => editor.redo(),
|
|
4732
4573
|
select: (selection) => {
|
|
@@ -4748,7 +4589,6 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4748
4589
|
}
|
|
4749
4590
|
},
|
|
4750
4591
|
insertChild: (type, value) => {
|
|
4751
|
-
var _a, _b, _c;
|
|
4752
4592
|
if (type.name !== types2.span.name)
|
|
4753
4593
|
return editorActor.send({
|
|
4754
4594
|
type: "behavior event",
|
|
@@ -4760,7 +4600,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4760
4600
|
}
|
|
4761
4601
|
},
|
|
4762
4602
|
editor
|
|
4763
|
-
}),
|
|
4603
|
+
}), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path ?? [];
|
|
4764
4604
|
if (!editor.selection)
|
|
4765
4605
|
throw new Error("The editor has no selection");
|
|
4766
4606
|
const [focusBlock] = Array.from(slate.Editor.nodes(editor, {
|
|
@@ -4774,10 +4614,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4774
4614
|
const child = toSlateValue([{
|
|
4775
4615
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4776
4616
|
_type: types2.block.name,
|
|
4777
|
-
children: [
|
|
4617
|
+
children: [{
|
|
4778
4618
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4779
|
-
_type: type.name
|
|
4780
|
-
|
|
4619
|
+
_type: type.name,
|
|
4620
|
+
...value || {}
|
|
4621
|
+
}]
|
|
4781
4622
|
}], {
|
|
4782
4623
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
4783
4624
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
@@ -4787,30 +4628,27 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4787
4628
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
4788
4629
|
select: !0,
|
|
4789
4630
|
at: editor.selection
|
|
4790
|
-
}), editor.onChange(),
|
|
4631
|
+
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path || [];
|
|
4791
4632
|
},
|
|
4792
|
-
insertBlock: (type, value) => {
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
type: "
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
name: type.name,
|
|
4800
|
-
value
|
|
4801
|
-
},
|
|
4802
|
-
placement: "auto"
|
|
4633
|
+
insertBlock: (type, value) => (editorActor.send({
|
|
4634
|
+
type: "behavior event",
|
|
4635
|
+
behaviorEvent: {
|
|
4636
|
+
type: "insert.block object",
|
|
4637
|
+
blockObject: {
|
|
4638
|
+
name: type.name,
|
|
4639
|
+
value
|
|
4803
4640
|
},
|
|
4804
|
-
|
|
4805
|
-
}
|
|
4806
|
-
|
|
4641
|
+
placement: "auto"
|
|
4642
|
+
},
|
|
4643
|
+
editor
|
|
4644
|
+
}), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path ?? []),
|
|
4807
4645
|
hasBlockStyle: (style) => {
|
|
4808
4646
|
try {
|
|
4809
4647
|
return isStyleActive({
|
|
4810
4648
|
editor,
|
|
4811
4649
|
style
|
|
4812
4650
|
});
|
|
4813
|
-
} catch
|
|
4651
|
+
} catch {
|
|
4814
4652
|
return !1;
|
|
4815
4653
|
}
|
|
4816
4654
|
},
|
|
@@ -4820,7 +4658,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4820
4658
|
editor,
|
|
4821
4659
|
listItem
|
|
4822
4660
|
});
|
|
4823
|
-
} catch
|
|
4661
|
+
} catch {
|
|
4824
4662
|
return !1;
|
|
4825
4663
|
}
|
|
4826
4664
|
},
|
|
@@ -4865,12 +4703,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4865
4703
|
match: (n) => n._key === element._key
|
|
4866
4704
|
}) || [])[0] || [void 0];
|
|
4867
4705
|
node = slateReact.ReactEditor.toDOMNode(editor, item);
|
|
4868
|
-
} catch
|
|
4706
|
+
} catch {
|
|
4869
4707
|
}
|
|
4870
4708
|
return node;
|
|
4871
4709
|
},
|
|
4872
4710
|
activeAnnotations: () => {
|
|
4873
|
-
var _a;
|
|
4874
4711
|
if (!editor.selection || editor.selection.focus.path.length < 2)
|
|
4875
4712
|
return [];
|
|
4876
4713
|
try {
|
|
@@ -4882,12 +4719,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4882
4719
|
const [block] = slate.Editor.node(editor, path, {
|
|
4883
4720
|
depth: 1
|
|
4884
4721
|
});
|
|
4885
|
-
editor.isTextBlock(block) &&
|
|
4722
|
+
editor.isTextBlock(block) && block.markDefs?.forEach((def) => {
|
|
4886
4723
|
slate.Text.isText(span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
|
|
4887
|
-
})
|
|
4724
|
+
});
|
|
4888
4725
|
}
|
|
4889
4726
|
return activeAnnotations;
|
|
4890
|
-
} catch
|
|
4727
|
+
} catch {
|
|
4891
4728
|
return [];
|
|
4892
4729
|
}
|
|
4893
4730
|
},
|
|
@@ -4909,7 +4746,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4909
4746
|
type: "annotation.add",
|
|
4910
4747
|
annotation: {
|
|
4911
4748
|
name: type.name,
|
|
4912
|
-
value: value
|
|
4749
|
+
value: value ?? {}
|
|
4913
4750
|
},
|
|
4914
4751
|
editor
|
|
4915
4752
|
}
|
|
@@ -4922,7 +4759,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4922
4759
|
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
4923
4760
|
throw new Error("Invalid range");
|
|
4924
4761
|
if (range) {
|
|
4925
|
-
if (!
|
|
4762
|
+
if (!options?.mode || options?.mode === "selected") {
|
|
4926
4763
|
debug$6("Deleting content in selection"), slate.Transforms.delete(editor, {
|
|
4927
4764
|
at: range,
|
|
4928
4765
|
hanging: !0,
|
|
@@ -4930,11 +4767,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4930
4767
|
}), editor.onChange();
|
|
4931
4768
|
return;
|
|
4932
4769
|
}
|
|
4933
|
-
|
|
4770
|
+
options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
4934
4771
|
at: range,
|
|
4935
4772
|
voids: !0,
|
|
4936
4773
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
4937
|
-
})),
|
|
4774
|
+
})), options?.mode === "children" && (debug$6("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
4938
4775
|
at: range,
|
|
4939
4776
|
voids: !0,
|
|
4940
4777
|
match: (node) => node._type === types2.span.name || // Text children
|
|
@@ -4991,26 +4828,15 @@ function isAnnotationActive({
|
|
|
4991
4828
|
at: editor.selection,
|
|
4992
4829
|
match: (node) => slate.Text.isText(node)
|
|
4993
4830
|
})];
|
|
4994
|
-
if (spans.length === 0 || spans.some(([span]) =>
|
|
4995
|
-
var _a;
|
|
4996
|
-
return !types.isPortableTextSpan(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
|
|
4997
|
-
})) return !1;
|
|
4831
|
+
if (spans.length === 0 || spans.some(([span]) => !types.isPortableTextSpan(span) || !span.marks || span.marks?.length === 0)) return !1;
|
|
4998
4832
|
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
4999
4833
|
const [block] = slate.Editor.node(editor, path, {
|
|
5000
4834
|
depth: 1
|
|
5001
4835
|
});
|
|
5002
4836
|
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
5003
4837
|
}, []);
|
|
5004
|
-
return spans.every(([span]) =>
|
|
5005
|
-
|
|
5006
|
-
if (!types.isPortableTextSpan(span)) return !1;
|
|
5007
|
-
const spanMarkDefs = (_a = span.marks) == null ? void 0 : _a.map((markKey) => {
|
|
5008
|
-
var _a2;
|
|
5009
|
-
return (_a2 = selectionMarkDefs.find((def) => (def == null ? void 0 : def._key) === markKey)) == null ? void 0 : _a2._type;
|
|
5010
|
-
});
|
|
5011
|
-
return spanMarkDefs == null ? void 0 : spanMarkDefs.includes(annotation.name);
|
|
5012
|
-
});
|
|
5013
|
-
} catch (e) {
|
|
4838
|
+
return spans.every(([span]) => types.isPortableTextSpan(span) ? span.marks?.map((markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type)?.includes(annotation.name) : !1);
|
|
4839
|
+
} catch {
|
|
5014
4840
|
return !1;
|
|
5015
4841
|
}
|
|
5016
4842
|
}
|
|
@@ -5018,7 +4844,6 @@ const addAnnotationActionImplementation = ({
|
|
|
5018
4844
|
context,
|
|
5019
4845
|
action
|
|
5020
4846
|
}) => {
|
|
5021
|
-
var _a, _b;
|
|
5022
4847
|
const editor = action.editor, {
|
|
5023
4848
|
selection: originalSelection
|
|
5024
4849
|
} = editor;
|
|
@@ -5036,12 +4861,13 @@ const addAnnotationActionImplementation = ({
|
|
|
5036
4861
|
for (const [block, blockPath] of selectedBlocks) {
|
|
5037
4862
|
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
5038
4863
|
continue;
|
|
5039
|
-
const annotationKey = context.keyGenerator(), markDefs =
|
|
4864
|
+
const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
|
|
5040
4865
|
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (slate.Transforms.setNodes(editor, {
|
|
5041
|
-
markDefs: [...markDefs,
|
|
4866
|
+
markDefs: [...markDefs, {
|
|
5042
4867
|
_type: action.annotation.name,
|
|
5043
|
-
_key: annotationKey
|
|
5044
|
-
|
|
4868
|
+
_key: annotationKey,
|
|
4869
|
+
...action.annotation.value
|
|
4870
|
+
}]
|
|
5045
4871
|
}, {
|
|
5046
4872
|
at: blockPath
|
|
5047
4873
|
}), markDefPath = [{
|
|
@@ -5056,7 +4882,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5056
4882
|
for (const [span, path] of children) {
|
|
5057
4883
|
if (!editor.isTextSpan(span) || !slate.Range.includes(editor.selection, path))
|
|
5058
4884
|
continue;
|
|
5059
|
-
const marks =
|
|
4885
|
+
const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
|
|
5060
4886
|
slate.Transforms.setNodes(editor, {
|
|
5061
4887
|
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
5062
4888
|
}, {
|
|
@@ -5078,7 +4904,6 @@ const addAnnotationActionImplementation = ({
|
|
|
5078
4904
|
}, removeAnnotationActionImplementation = ({
|
|
5079
4905
|
action
|
|
5080
4906
|
}) => {
|
|
5081
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
5082
4907
|
const editor = action.editor;
|
|
5083
4908
|
if (debug$6("Removing annotation", action.annotation.name), !!editor.selection)
|
|
5084
4909
|
if (slate.Range.isCollapsed(editor.selection)) {
|
|
@@ -5087,12 +4912,12 @@ const addAnnotationActionImplementation = ({
|
|
|
5087
4912
|
});
|
|
5088
4913
|
if (!editor.isTextBlock(block))
|
|
5089
4914
|
return;
|
|
5090
|
-
const potentialAnnotations = (
|
|
4915
|
+
const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = slate.Editor.node(editor, editor.selection, {
|
|
5091
4916
|
depth: 2
|
|
5092
4917
|
});
|
|
5093
4918
|
if (!editor.isTextSpan(selectedChild))
|
|
5094
4919
|
return;
|
|
5095
|
-
const annotationToRemove =
|
|
4920
|
+
const annotationToRemove = selectedChild.marks?.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
|
|
5096
4921
|
if (!annotationToRemove)
|
|
5097
4922
|
return;
|
|
5098
4923
|
const previousSpansWithSameAnnotation = [];
|
|
@@ -5100,20 +4925,20 @@ const addAnnotationActionImplementation = ({
|
|
|
5100
4925
|
reverse: !0
|
|
5101
4926
|
}))
|
|
5102
4927
|
if (editor.isTextSpan(child) && slate.Path.isBefore(childPath, selectedChildPath))
|
|
5103
|
-
if (
|
|
4928
|
+
if (child.marks?.includes(annotationToRemove))
|
|
5104
4929
|
previousSpansWithSameAnnotation.push([child, childPath]);
|
|
5105
4930
|
else
|
|
5106
4931
|
break;
|
|
5107
4932
|
const nextSpansWithSameAnnotation = [];
|
|
5108
4933
|
for (const [child, childPath] of slate.Node.children(editor, blockPath))
|
|
5109
4934
|
if (editor.isTextSpan(child) && slate.Path.isAfter(childPath, selectedChildPath))
|
|
5110
|
-
if (
|
|
4935
|
+
if (child.marks?.includes(annotationToRemove))
|
|
5111
4936
|
nextSpansWithSameAnnotation.push([child, childPath]);
|
|
5112
4937
|
else
|
|
5113
4938
|
break;
|
|
5114
4939
|
for (const [child, childPath] of [...previousSpansWithSameAnnotation, [selectedChild, selectedChildPath], ...nextSpansWithSameAnnotation])
|
|
5115
4940
|
slate.Transforms.setNodes(editor, {
|
|
5116
|
-
marks:
|
|
4941
|
+
marks: child.marks?.filter((mark) => mark !== annotationToRemove)
|
|
5117
4942
|
}, {
|
|
5118
4943
|
at: childPath
|
|
5119
4944
|
});
|
|
@@ -5132,10 +4957,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5132
4957
|
for (const [child, childPath] of children) {
|
|
5133
4958
|
if (!editor.isTextSpan(child) || !slate.Range.includes(editor.selection, childPath))
|
|
5134
4959
|
continue;
|
|
5135
|
-
const markDefs =
|
|
5136
|
-
const markDef = markDefs.find((markDef2) => markDef2._key === mark);
|
|
5137
|
-
return (markDef == null ? void 0 : markDef._type) !== action.annotation.name;
|
|
5138
|
-
});
|
|
4960
|
+
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== action.annotation.name);
|
|
5139
4961
|
marksWithoutAnnotation.length !== marks.length && slate.Transforms.setNodes(editor, {
|
|
5140
4962
|
marks: marksWithoutAnnotation
|
|
5141
4963
|
}, {
|
|
@@ -5178,12 +5000,11 @@ function insertBlock({
|
|
|
5178
5000
|
editor,
|
|
5179
5001
|
schema: schema2
|
|
5180
5002
|
}) {
|
|
5181
|
-
var _a;
|
|
5182
5003
|
if (editor.selection) {
|
|
5183
|
-
const [focusBlock, focusBlockPath] =
|
|
5004
|
+
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(editor, {
|
|
5184
5005
|
at: editor.selection.focus.path.slice(0, 1),
|
|
5185
5006
|
match: (n) => !slate.Editor.isEditor(n)
|
|
5186
|
-
}))[0]
|
|
5007
|
+
}))[0] ?? [void 0, void 0];
|
|
5187
5008
|
if (placement === "after") {
|
|
5188
5009
|
const nextPath = [focusBlockPath[0] + 1];
|
|
5189
5010
|
slate.Transforms.insertNodes(editor, block, {
|
|
@@ -5215,22 +5036,15 @@ function insertBlock({
|
|
|
5215
5036
|
});
|
|
5216
5037
|
}
|
|
5217
5038
|
}
|
|
5218
|
-
var __defProp$b = Object.defineProperty, __getOwnPropSymbols$b = Object.getOwnPropertySymbols, __hasOwnProp$b = Object.prototype.hasOwnProperty, __propIsEnum$b = Object.prototype.propertyIsEnumerable, __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$b = (a, b) => {
|
|
5219
|
-
for (var prop in b || (b = {}))
|
|
5220
|
-
__hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5221
|
-
if (__getOwnPropSymbols$b)
|
|
5222
|
-
for (var prop of __getOwnPropSymbols$b(b))
|
|
5223
|
-
__propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5224
|
-
return a;
|
|
5225
|
-
};
|
|
5226
5039
|
const insertBlockObjectActionImplementation = ({
|
|
5227
5040
|
context,
|
|
5228
5041
|
action
|
|
5229
5042
|
}) => {
|
|
5230
|
-
const block = toSlateValue([
|
|
5043
|
+
const block = toSlateValue([{
|
|
5231
5044
|
_key: context.keyGenerator(),
|
|
5232
|
-
_type: action.blockObject.name
|
|
5233
|
-
|
|
5045
|
+
_type: action.blockObject.name,
|
|
5046
|
+
...action.blockObject.value ? action.blockObject.value : {}
|
|
5047
|
+
}], {
|
|
5234
5048
|
schemaTypes: context.schema
|
|
5235
5049
|
})[0];
|
|
5236
5050
|
insertBlock({
|
|
@@ -5239,29 +5053,19 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5239
5053
|
editor: action.editor,
|
|
5240
5054
|
schema: context.schema
|
|
5241
5055
|
});
|
|
5242
|
-
}
|
|
5243
|
-
var __defProp$a = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$a = Object.getOwnPropertySymbols, __hasOwnProp$a = Object.prototype.hasOwnProperty, __propIsEnum$a = Object.prototype.propertyIsEnumerable, __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$a = (a, b) => {
|
|
5244
|
-
for (var prop in b || (b = {}))
|
|
5245
|
-
__hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5246
|
-
if (__getOwnPropSymbols$a)
|
|
5247
|
-
for (var prop of __getOwnPropSymbols$a(b))
|
|
5248
|
-
__propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5249
|
-
return a;
|
|
5250
|
-
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
5251
|
-
const insertBreakActionImplementation = ({
|
|
5056
|
+
}, insertBreakActionImplementation = ({
|
|
5252
5057
|
context,
|
|
5253
5058
|
action
|
|
5254
5059
|
}) => {
|
|
5255
|
-
var _a, _b, _c, _d, _e;
|
|
5256
5060
|
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
5257
5061
|
if (!editor.selection)
|
|
5258
5062
|
return;
|
|
5259
|
-
const [focusSpan] =
|
|
5063
|
+
const [focusSpan] = Array.from(slate.Editor.nodes(editor, {
|
|
5260
5064
|
mode: "lowest",
|
|
5261
5065
|
at: editor.selection.focus,
|
|
5262
5066
|
match: (n) => editor.isTextSpan(n),
|
|
5263
5067
|
voids: !1
|
|
5264
|
-
}))[0]
|
|
5068
|
+
}))[0] ?? [void 0], focusDecorators = focusSpan?.marks?.filter((mark) => schema2.decorators.some((decorator) => decorator.value === mark)) ?? [], focusAnnotations = focusSpan?.marks?.filter((mark) => !schema2.decorators.some((decorator) => decorator.value === mark)) ?? [], anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
5265
5069
|
if (editor.isTextBlock(focusBlock)) {
|
|
5266
5070
|
const [start, end] = slate.Range.edges(editor.selection), lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual__default.default(start, {
|
|
5267
5071
|
path: [...focusBlockPath, focusBlock.children.length - 1],
|
|
@@ -5300,7 +5104,6 @@ const insertBreakActionImplementation = ({
|
|
|
5300
5104
|
const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0];
|
|
5301
5105
|
if (!atTheStartOfBlock && !atTheEndOfBlock && !selectionAcrossBlocks) {
|
|
5302
5106
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
5303
|
-
var _a2;
|
|
5304
5107
|
if (!editor.selection)
|
|
5305
5108
|
return;
|
|
5306
5109
|
slate.Transforms.splitNodes(editor, {
|
|
@@ -5323,28 +5126,20 @@ const insertBreakActionImplementation = ({
|
|
|
5323
5126
|
for (const [child, childPath] of children) {
|
|
5324
5127
|
if (!editor.isTextSpan(child))
|
|
5325
5128
|
continue;
|
|
5326
|
-
const marks =
|
|
5129
|
+
const marks = child.marks ?? [];
|
|
5327
5130
|
for (const mark of marks)
|
|
5328
|
-
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) =>
|
|
5329
|
-
|
|
5330
|
-
return (_a3 = prevNodeSpan.marks) == null ? void 0 : _a3.includes(mark);
|
|
5331
|
-
}) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
5332
|
-
const newMarks = marks.map((mark) => {
|
|
5333
|
-
var _a3;
|
|
5334
|
-
return (_a3 = newMarkDefKeys.get(mark)) != null ? _a3 : mark;
|
|
5335
|
-
});
|
|
5131
|
+
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
5132
|
+
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
5336
5133
|
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
5337
5134
|
marks: newMarks
|
|
5338
5135
|
}, {
|
|
5339
5136
|
at: childPath
|
|
5340
5137
|
});
|
|
5341
5138
|
}
|
|
5342
|
-
const newMarkDefs = nextNode.markDefs.map((markDef) => {
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
});
|
|
5347
|
-
});
|
|
5139
|
+
const newMarkDefs = nextNode.markDefs.map((markDef) => ({
|
|
5140
|
+
...markDef,
|
|
5141
|
+
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
5142
|
+
}));
|
|
5348
5143
|
isEqual__default.default(nextNode.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
5349
5144
|
markDefs: newMarkDefs
|
|
5350
5145
|
}, {
|
|
@@ -5365,24 +5160,15 @@ const insertBreakActionImplementation = ({
|
|
|
5365
5160
|
}) => {
|
|
5366
5161
|
insertBreakActionImplementation({
|
|
5367
5162
|
context,
|
|
5368
|
-
action:
|
|
5163
|
+
action: {
|
|
5164
|
+
...action,
|
|
5369
5165
|
type: "insert.break"
|
|
5370
|
-
}
|
|
5166
|
+
}
|
|
5371
5167
|
});
|
|
5372
|
-
}
|
|
5373
|
-
var __defProp$9 = Object.defineProperty, __getOwnPropSymbols$9 = Object.getOwnPropertySymbols, __hasOwnProp$9 = Object.prototype.hasOwnProperty, __propIsEnum$9 = Object.prototype.propertyIsEnumerable, __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$9 = (a, b) => {
|
|
5374
|
-
for (var prop in b || (b = {}))
|
|
5375
|
-
__hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5376
|
-
if (__getOwnPropSymbols$9)
|
|
5377
|
-
for (var prop of __getOwnPropSymbols$9(b))
|
|
5378
|
-
__propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5379
|
-
return a;
|
|
5380
|
-
};
|
|
5381
|
-
const insertInlineObjectActionImplementation = ({
|
|
5168
|
+
}, insertInlineObjectActionImplementation = ({
|
|
5382
5169
|
context,
|
|
5383
5170
|
action
|
|
5384
5171
|
}) => {
|
|
5385
|
-
var _a, _b;
|
|
5386
5172
|
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
5387
5173
|
console.error("Unable to insert unknown inline object");
|
|
5388
5174
|
return;
|
|
@@ -5391,77 +5177,60 @@ const insertInlineObjectActionImplementation = ({
|
|
|
5391
5177
|
console.error("Unable to insert inline object without selection");
|
|
5392
5178
|
return;
|
|
5393
5179
|
}
|
|
5394
|
-
const [focusTextBlock] =
|
|
5180
|
+
const [focusTextBlock] = Array.from(slate.Editor.nodes(action.editor, {
|
|
5395
5181
|
at: action.editor.selection.focus.path,
|
|
5396
5182
|
match: (node) => action.editor.isTextBlock(node)
|
|
5397
|
-
})).at(0)
|
|
5183
|
+
})).at(0) ?? [void 0, void 0];
|
|
5398
5184
|
if (!focusTextBlock) {
|
|
5399
5185
|
console.error("Unable to perform action without focus text block");
|
|
5400
5186
|
return;
|
|
5401
5187
|
}
|
|
5402
|
-
const
|
|
5188
|
+
const child = toSlateValue([{
|
|
5403
5189
|
_type: context.schema.block.name,
|
|
5404
5190
|
_key: context.keyGenerator(),
|
|
5405
|
-
children: [
|
|
5191
|
+
children: [{
|
|
5406
5192
|
_type: action.inlineObject.name,
|
|
5407
|
-
_key: context.keyGenerator()
|
|
5408
|
-
|
|
5193
|
+
_key: context.keyGenerator(),
|
|
5194
|
+
...action.inlineObject.value ?? {}
|
|
5195
|
+
}]
|
|
5409
5196
|
}], {
|
|
5410
5197
|
schemaTypes: context.schema
|
|
5411
|
-
}).at(0)
|
|
5198
|
+
}).at(0)?.children.at(0);
|
|
5412
5199
|
if (!child) {
|
|
5413
5200
|
console.error("Unable to insert inline object");
|
|
5414
5201
|
return;
|
|
5415
5202
|
}
|
|
5416
5203
|
slate.Transforms.insertNodes(action.editor, child);
|
|
5417
|
-
}
|
|
5418
|
-
var __defProp$8 = Object.defineProperty, __getOwnPropSymbols$8 = Object.getOwnPropertySymbols, __hasOwnProp$8 = Object.prototype.hasOwnProperty, __propIsEnum$8 = Object.prototype.propertyIsEnumerable, __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$8 = (a, b) => {
|
|
5419
|
-
for (var prop in b || (b = {}))
|
|
5420
|
-
__hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5421
|
-
if (__getOwnPropSymbols$8)
|
|
5422
|
-
for (var prop of __getOwnPropSymbols$8(b))
|
|
5423
|
-
__propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5424
|
-
return a;
|
|
5425
|
-
};
|
|
5426
|
-
const insertSpanActionImplementation = ({
|
|
5204
|
+
}, insertSpanActionImplementation = ({
|
|
5427
5205
|
context,
|
|
5428
5206
|
action
|
|
5429
5207
|
}) => {
|
|
5430
|
-
var _a, _b, _c, _d;
|
|
5431
5208
|
if (!action.editor.selection) {
|
|
5432
5209
|
console.error("Unable to perform action without selection", action);
|
|
5433
5210
|
return;
|
|
5434
5211
|
}
|
|
5435
|
-
const [focusBlock, focusBlockPath] =
|
|
5212
|
+
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(action.editor, {
|
|
5436
5213
|
at: action.editor.selection.focus.path,
|
|
5437
5214
|
match: (node) => action.editor.isTextBlock(node)
|
|
5438
|
-
}))[0]
|
|
5215
|
+
}))[0] ?? [void 0, void 0];
|
|
5439
5216
|
if (!focusBlock || !focusBlockPath) {
|
|
5440
5217
|
console.error("Unable to perform action without focus block", action);
|
|
5441
5218
|
return;
|
|
5442
5219
|
}
|
|
5443
|
-
const markDefs =
|
|
5220
|
+
const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
|
|
5444
5221
|
_type: annotation.name,
|
|
5445
|
-
_key: context.keyGenerator()
|
|
5446
|
-
|
|
5222
|
+
_key: context.keyGenerator(),
|
|
5223
|
+
...annotation.value
|
|
5224
|
+
})) : void 0;
|
|
5447
5225
|
annotations && annotations.length > 0 && slate.Transforms.setNodes(action.editor, {
|
|
5448
5226
|
markDefs: [...markDefs, ...annotations]
|
|
5449
5227
|
}), slate.Transforms.insertNodes(action.editor, {
|
|
5450
5228
|
_type: "span",
|
|
5451
5229
|
_key: context.keyGenerator(),
|
|
5452
5230
|
text: action.text,
|
|
5453
|
-
marks: [...
|
|
5231
|
+
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
5454
5232
|
});
|
|
5455
|
-
}
|
|
5456
|
-
var __defProp$7 = Object.defineProperty, __getOwnPropSymbols$7 = Object.getOwnPropertySymbols, __hasOwnProp$7 = Object.prototype.hasOwnProperty, __propIsEnum$7 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$7 = (a, b) => {
|
|
5457
|
-
for (var prop in b || (b = {}))
|
|
5458
|
-
__hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5459
|
-
if (__getOwnPropSymbols$7)
|
|
5460
|
-
for (var prop of __getOwnPropSymbols$7(b))
|
|
5461
|
-
__propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5462
|
-
return a;
|
|
5463
|
-
};
|
|
5464
|
-
const textBlockSetActionImplementation = ({
|
|
5233
|
+
}, textBlockSetActionImplementation = ({
|
|
5465
5234
|
action
|
|
5466
5235
|
}) => {
|
|
5467
5236
|
const at = toSlateRange({
|
|
@@ -5474,13 +5243,17 @@ const textBlockSetActionImplementation = ({
|
|
|
5474
5243
|
offset: 0
|
|
5475
5244
|
}
|
|
5476
5245
|
}, action.editor);
|
|
5477
|
-
slate.Transforms.setNodes(action.editor,
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5246
|
+
slate.Transforms.setNodes(action.editor, {
|
|
5247
|
+
...action.style ? {
|
|
5248
|
+
style: action.style
|
|
5249
|
+
} : {},
|
|
5250
|
+
...action.listItem ? {
|
|
5251
|
+
listItem: action.listItem
|
|
5252
|
+
} : {},
|
|
5253
|
+
...action.level ? {
|
|
5254
|
+
level: action.level
|
|
5255
|
+
} : {}
|
|
5256
|
+
}, {
|
|
5484
5257
|
at
|
|
5485
5258
|
});
|
|
5486
5259
|
}, textBlockUnsetActionImplementation = ({
|
|
@@ -5499,16 +5272,7 @@ const textBlockSetActionImplementation = ({
|
|
|
5499
5272
|
slate.Transforms.unsetNodes(action.editor, action.props, {
|
|
5500
5273
|
at
|
|
5501
5274
|
});
|
|
5502
|
-
}
|
|
5503
|
-
var __defProp$6 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
|
|
5504
|
-
for (var prop in b || (b = {}))
|
|
5505
|
-
__hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5506
|
-
if (__getOwnPropSymbols$6)
|
|
5507
|
-
for (var prop of __getOwnPropSymbols$6(b))
|
|
5508
|
-
__propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5509
|
-
return a;
|
|
5510
|
-
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
5511
|
-
const behaviorActionImplementations = {
|
|
5275
|
+
}, behaviorActionImplementations = {
|
|
5512
5276
|
"annotation.add": addAnnotationActionImplementation,
|
|
5513
5277
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
5514
5278
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
@@ -5597,15 +5361,15 @@ const behaviorActionImplementations = {
|
|
|
5597
5361
|
context,
|
|
5598
5362
|
action
|
|
5599
5363
|
}) => {
|
|
5600
|
-
var _a, _b, _c, _d;
|
|
5601
5364
|
const block = toSlateValue([{
|
|
5602
5365
|
_key: context.keyGenerator(),
|
|
5603
5366
|
_type: context.schema.block.name,
|
|
5604
|
-
style:
|
|
5367
|
+
style: context.schema.styles[0].value ?? "normal",
|
|
5605
5368
|
markDefs: [],
|
|
5606
|
-
children:
|
|
5369
|
+
children: action.textBlock?.children?.map((child) => ({
|
|
5370
|
+
...child,
|
|
5607
5371
|
_key: context.keyGenerator()
|
|
5608
|
-
}))
|
|
5372
|
+
})) ?? [{
|
|
5609
5373
|
_type: context.schema.span.name,
|
|
5610
5374
|
_key: context.keyGenerator(),
|
|
5611
5375
|
text: ""
|
|
@@ -5698,7 +5462,11 @@ const behaviorActionImplementations = {
|
|
|
5698
5462
|
action
|
|
5699
5463
|
}) => {
|
|
5700
5464
|
const selection = action.editor.selection;
|
|
5701
|
-
selection && (slate.Transforms.select(action.editor,
|
|
5465
|
+
selection && (slate.Transforms.select(action.editor, {
|
|
5466
|
+
...selection
|
|
5467
|
+
}), action.editor.selection = {
|
|
5468
|
+
...selection
|
|
5469
|
+
});
|
|
5702
5470
|
},
|
|
5703
5471
|
"style.toggle": toggleStyleActionImplementation,
|
|
5704
5472
|
"style.add": addStyleActionImplementation,
|
|
@@ -5970,30 +5738,15 @@ function performDefaultAction({
|
|
|
5970
5738
|
});
|
|
5971
5739
|
}
|
|
5972
5740
|
}
|
|
5973
|
-
var __defProp$5 = Object.defineProperty, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
|
|
5974
|
-
for (var prop in b || (b = {}))
|
|
5975
|
-
__hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5976
|
-
if (__getOwnPropSymbols$5)
|
|
5977
|
-
for (var prop of __getOwnPropSymbols$5(b))
|
|
5978
|
-
__propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5979
|
-
return a;
|
|
5980
|
-
};
|
|
5981
5741
|
function getActiveDecorators({
|
|
5982
5742
|
schema: schema2,
|
|
5983
5743
|
slateEditorInstance
|
|
5984
5744
|
}) {
|
|
5985
|
-
var _a, _b;
|
|
5986
5745
|
const decorators = schema2.decorators.map((decorator) => decorator.value);
|
|
5987
|
-
return (
|
|
5988
|
-
}
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
__hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
5992
|
-
if (__getOwnPropSymbols$4)
|
|
5993
|
-
for (var prop of __getOwnPropSymbols$4(b))
|
|
5994
|
-
__propIsEnum$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
5995
|
-
return a;
|
|
5996
|
-
}, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
5746
|
+
return ({
|
|
5747
|
+
...slate.Editor.marks(slateEditorInstance) ?? {}
|
|
5748
|
+
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
5749
|
+
}
|
|
5997
5750
|
const editorMachine = xstate.setup({
|
|
5998
5751
|
types: {
|
|
5999
5752
|
context: {},
|
|
@@ -6048,11 +5801,11 @@ const editorMachine = xstate.setup({
|
|
|
6048
5801
|
event,
|
|
6049
5802
|
enqueue
|
|
6050
5803
|
}) => {
|
|
6051
|
-
var _a;
|
|
6052
5804
|
xstate.assertEvent(event, ["behavior event"]);
|
|
6053
|
-
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 :
|
|
5805
|
+
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
5806
|
+
...event.behaviorEvent,
|
|
6054
5807
|
editor: event.editor
|
|
6055
|
-
}
|
|
5808
|
+
}, eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
6056
5809
|
if (eventBehaviors.length === 0) {
|
|
6057
5810
|
if (!defaultAction)
|
|
6058
5811
|
return;
|
|
@@ -6092,7 +5845,7 @@ const editorMachine = xstate.setup({
|
|
|
6092
5845
|
actionIntends
|
|
6093
5846
|
});
|
|
6094
5847
|
if (behaviorOverwritten) {
|
|
6095
|
-
|
|
5848
|
+
event.nativeEvent?.preventDefault();
|
|
6096
5849
|
break;
|
|
6097
5850
|
}
|
|
6098
5851
|
}
|
|
@@ -6111,19 +5864,16 @@ const editorMachine = xstate.setup({
|
|
|
6111
5864
|
id: "editor",
|
|
6112
5865
|
context: ({
|
|
6113
5866
|
input
|
|
6114
|
-
}) => {
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
value: input.value
|
|
6125
|
-
};
|
|
6126
|
-
},
|
|
5867
|
+
}) => ({
|
|
5868
|
+
behaviors: input.behaviors ?? behavior_core.coreBehaviors,
|
|
5869
|
+
keyGenerator: input.keyGenerator,
|
|
5870
|
+
pendingEvents: [],
|
|
5871
|
+
schema: input.schema,
|
|
5872
|
+
selection: null,
|
|
5873
|
+
initialReadOnly: input.readOnly ?? !1,
|
|
5874
|
+
maxBlocks: input.maxBlocks,
|
|
5875
|
+
value: input.value
|
|
5876
|
+
}),
|
|
6127
5877
|
on: {
|
|
6128
5878
|
unset: {
|
|
6129
5879
|
actions: xstate.emit(({
|
|
@@ -6206,9 +5956,10 @@ const editorMachine = xstate.setup({
|
|
|
6206
5956
|
}) => {
|
|
6207
5957
|
slate.Editor.withoutNormalizing(event.editor, () => {
|
|
6208
5958
|
for (const actionIntend of event.actionIntends) {
|
|
6209
|
-
const action =
|
|
5959
|
+
const action = {
|
|
5960
|
+
...actionIntend,
|
|
6210
5961
|
editor: event.editor
|
|
6211
|
-
}
|
|
5962
|
+
};
|
|
6212
5963
|
performAction({
|
|
6213
5964
|
context,
|
|
6214
5965
|
action
|
|
@@ -6423,10 +6174,9 @@ function useCreateEditor(config) {
|
|
|
6423
6174
|
return $[4] !== editorActor ? (t3 = createEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
6424
6175
|
}
|
|
6425
6176
|
function editorConfigToMachineInput(config) {
|
|
6426
|
-
var _a;
|
|
6427
6177
|
return {
|
|
6428
6178
|
behaviors: config.behaviors,
|
|
6429
|
-
keyGenerator:
|
|
6179
|
+
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
6430
6180
|
maxBlocks: config.maxBlocks,
|
|
6431
6181
|
readOnly: config.readOnly,
|
|
6432
6182
|
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
@@ -6476,16 +6226,13 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
6476
6226
|
let t2;
|
|
6477
6227
|
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
6478
6228
|
}
|
|
6479
|
-
var __defProp$3 = Object.defineProperty, __defProps$3 = Object.defineProperties, __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
|
|
6480
|
-
for (var prop in b || (b = {}))
|
|
6481
|
-
__hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6482
|
-
if (__getOwnPropSymbols$3)
|
|
6483
|
-
for (var prop of __getOwnPropSymbols$3(b))
|
|
6484
|
-
__propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6485
|
-
return a;
|
|
6486
|
-
}, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)), __publicField = (obj, key, value) => __defNormalProp$3(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
6487
6229
|
const debug$4 = debugWithName("component:PortableTextEditor");
|
|
6488
6230
|
class PortableTextEditor extends React.Component {
|
|
6231
|
+
static displayName = "PortableTextEditor";
|
|
6232
|
+
/**
|
|
6233
|
+
* An observable of all the editor changes.
|
|
6234
|
+
*/
|
|
6235
|
+
change$ = new rxjs.Subject();
|
|
6489
6236
|
/**
|
|
6490
6237
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
6491
6238
|
*/
|
|
@@ -6496,11 +6243,8 @@ class PortableTextEditor extends React.Component {
|
|
|
6496
6243
|
* The editor API (currently implemented with Slate).
|
|
6497
6244
|
*/
|
|
6498
6245
|
constructor(props) {
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
this.editor._internal.editable = __spreadValues$3(__spreadValues$3({}, this.editor._internal.editable), editable);
|
|
6502
|
-
}), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6503
|
-
keyGenerator: (_a = props.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6246
|
+
super(props), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6247
|
+
keyGenerator: props.keyGenerator ?? defaultKeyGenerator,
|
|
6504
6248
|
schema: props.schemaType,
|
|
6505
6249
|
initialValue: props.value,
|
|
6506
6250
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
@@ -6508,13 +6252,12 @@ class PortableTextEditor extends React.Component {
|
|
|
6508
6252
|
}), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
|
|
6509
6253
|
}
|
|
6510
6254
|
componentDidUpdate(prevProps) {
|
|
6511
|
-
var _a;
|
|
6512
6255
|
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = createEditorSchema(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
|
|
6513
6256
|
type: "update schema",
|
|
6514
6257
|
schema: this.schemaTypes
|
|
6515
6258
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
6516
6259
|
type: "update readOnly",
|
|
6517
|
-
readOnly:
|
|
6260
|
+
readOnly: this.props.readOnly ?? !1
|
|
6518
6261
|
}), this.props.maxBlocks !== prevProps.maxBlocks && this.editor._internal.editorActor.send({
|
|
6519
6262
|
type: "update maxBlocks",
|
|
6520
6263
|
maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
|
|
@@ -6523,9 +6266,14 @@ class PortableTextEditor extends React.Component {
|
|
|
6523
6266
|
value: this.props.value
|
|
6524
6267
|
}), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
|
|
6525
6268
|
}
|
|
6269
|
+
setEditable = (editable) => {
|
|
6270
|
+
this.editor._internal.editable = {
|
|
6271
|
+
...this.editor._internal.editable,
|
|
6272
|
+
...editable
|
|
6273
|
+
};
|
|
6274
|
+
};
|
|
6526
6275
|
render() {
|
|
6527
|
-
|
|
6528
|
-
const legacyPatches = this.props.editor ? void 0 : (_a = this.props.incomingPatches$) != null ? _a : this.props.patches$;
|
|
6276
|
+
const legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
|
|
6529
6277
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6530
6278
|
legacyPatches ? /* @__PURE__ */ jsxRuntime.jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
|
|
6531
6279
|
/* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
|
|
@@ -6535,105 +6283,65 @@ class PortableTextEditor extends React.Component {
|
|
|
6535
6283
|
/* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
|
|
6536
6284
|
] });
|
|
6537
6285
|
}
|
|
6286
|
+
// Static API methods
|
|
6287
|
+
static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
|
|
6288
|
+
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6289
|
+
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6290
|
+
static blur = (editor) => {
|
|
6291
|
+
debug$4("Host blurred"), editor.editable?.blur();
|
|
6292
|
+
};
|
|
6293
|
+
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6294
|
+
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6295
|
+
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6296
|
+
static focus = (editor) => {
|
|
6297
|
+
debug$4("Host requesting focus"), editor.editable?.focus();
|
|
6298
|
+
};
|
|
6299
|
+
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6300
|
+
static focusChild = (editor) => editor.editable?.focusChild();
|
|
6301
|
+
static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
|
|
6302
|
+
static getValue = (editor) => editor.editable?.getValue();
|
|
6303
|
+
static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
|
|
6304
|
+
static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
|
|
6305
|
+
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6306
|
+
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6307
|
+
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6308
|
+
static insertChild = (editor, type, value) => (debug$4("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6309
|
+
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6310
|
+
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6311
|
+
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
6312
|
+
static isObjectPath = (_editor, path) => {
|
|
6313
|
+
if (!path || !Array.isArray(path)) return !1;
|
|
6314
|
+
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6315
|
+
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6316
|
+
};
|
|
6317
|
+
static marks = (editor) => editor.editable?.marks();
|
|
6318
|
+
static select = (editor, selection) => {
|
|
6319
|
+
debug$4("Host setting selection", selection), editor.editable?.select(selection);
|
|
6320
|
+
};
|
|
6321
|
+
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6322
|
+
static toggleBlockStyle = (editor, blockStyle) => (debug$4("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6323
|
+
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6324
|
+
static toggleMark = (editor, mark) => {
|
|
6325
|
+
debug$4("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6326
|
+
};
|
|
6327
|
+
static getFragment = (editor) => (debug$4("Host getting fragment"), editor.editable?.getFragment());
|
|
6328
|
+
static undo = (editor) => {
|
|
6329
|
+
debug$4("Host undoing"), editor.editable?.undo();
|
|
6330
|
+
};
|
|
6331
|
+
static redo = (editor) => {
|
|
6332
|
+
debug$4("Host redoing"), editor.editable?.redo();
|
|
6333
|
+
};
|
|
6334
|
+
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6538
6335
|
}
|
|
6539
|
-
__publicField(PortableTextEditor, "displayName", "PortableTextEditor"), // Static API methods
|
|
6540
|
-
__publicField(PortableTextEditor, "activeAnnotations", (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : []), __publicField(PortableTextEditor, "isAnnotationActive", (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1), __publicField(PortableTextEditor, "addAnnotation", (editor, type, value) => {
|
|
6541
|
-
var _a;
|
|
6542
|
-
return (_a = editor.editable) == null ? void 0 : _a.addAnnotation(type, value);
|
|
6543
|
-
}), __publicField(PortableTextEditor, "blur", (editor) => {
|
|
6544
|
-
var _a;
|
|
6545
|
-
debug$4("Host blurred"), (_a = editor.editable) == null || _a.blur();
|
|
6546
|
-
}), __publicField(PortableTextEditor, "delete", (editor, selection, options) => {
|
|
6547
|
-
var _a;
|
|
6548
|
-
return (_a = editor.editable) == null ? void 0 : _a.delete(selection, options);
|
|
6549
|
-
}), __publicField(PortableTextEditor, "findDOMNode", (editor, element) => {
|
|
6550
|
-
var _a;
|
|
6551
|
-
return (_a = editor.editable) == null ? void 0 : _a.findDOMNode(element);
|
|
6552
|
-
}), __publicField(PortableTextEditor, "findByPath", (editor, path) => {
|
|
6553
|
-
var _a;
|
|
6554
|
-
return ((_a = editor.editable) == null ? void 0 : _a.findByPath(path)) || [];
|
|
6555
|
-
}), __publicField(PortableTextEditor, "focus", (editor) => {
|
|
6556
|
-
var _a;
|
|
6557
|
-
debug$4("Host requesting focus"), (_a = editor.editable) == null || _a.focus();
|
|
6558
|
-
}), __publicField(PortableTextEditor, "focusBlock", (editor) => {
|
|
6559
|
-
var _a;
|
|
6560
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusBlock();
|
|
6561
|
-
}), __publicField(PortableTextEditor, "focusChild", (editor) => {
|
|
6562
|
-
var _a;
|
|
6563
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusChild();
|
|
6564
|
-
}), __publicField(PortableTextEditor, "getSelection", (editor) => editor.editable ? editor.editable.getSelection() : null), __publicField(PortableTextEditor, "getValue", (editor) => {
|
|
6565
|
-
var _a;
|
|
6566
|
-
return (_a = editor.editable) == null ? void 0 : _a.getValue();
|
|
6567
|
-
}), __publicField(PortableTextEditor, "hasBlockStyle", (editor, blockStyle) => {
|
|
6568
|
-
var _a;
|
|
6569
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasBlockStyle(blockStyle);
|
|
6570
|
-
}), __publicField(PortableTextEditor, "hasListStyle", (editor, listStyle) => {
|
|
6571
|
-
var _a;
|
|
6572
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasListStyle(listStyle);
|
|
6573
|
-
}), __publicField(PortableTextEditor, "isCollapsedSelection", (editor) => {
|
|
6574
|
-
var _a;
|
|
6575
|
-
return (_a = editor.editable) == null ? void 0 : _a.isCollapsedSelection();
|
|
6576
|
-
}), __publicField(PortableTextEditor, "isExpandedSelection", (editor) => {
|
|
6577
|
-
var _a;
|
|
6578
|
-
return (_a = editor.editable) == null ? void 0 : _a.isExpandedSelection();
|
|
6579
|
-
}), __publicField(PortableTextEditor, "isMarkActive", (editor, mark) => {
|
|
6580
|
-
var _a;
|
|
6581
|
-
return (_a = editor.editable) == null ? void 0 : _a.isMarkActive(mark);
|
|
6582
|
-
}), __publicField(PortableTextEditor, "insertChild", (editor, type, value) => {
|
|
6583
|
-
var _a;
|
|
6584
|
-
return debug$4("Host inserting child"), (_a = editor.editable) == null ? void 0 : _a.insertChild(type, value);
|
|
6585
|
-
}), __publicField(PortableTextEditor, "insertBlock", (editor, type, value) => {
|
|
6586
|
-
var _a;
|
|
6587
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBlock(type, value);
|
|
6588
|
-
}), __publicField(PortableTextEditor, "insertBreak", (editor) => {
|
|
6589
|
-
var _a;
|
|
6590
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBreak();
|
|
6591
|
-
}), __publicField(PortableTextEditor, "isVoid", (editor, element) => {
|
|
6592
|
-
var _a;
|
|
6593
|
-
return (_a = editor.editable) == null ? void 0 : _a.isVoid(element);
|
|
6594
|
-
}), __publicField(PortableTextEditor, "isObjectPath", (_editor, path) => {
|
|
6595
|
-
if (!path || !Array.isArray(path)) return !1;
|
|
6596
|
-
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6597
|
-
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6598
|
-
}), __publicField(PortableTextEditor, "marks", (editor) => {
|
|
6599
|
-
var _a;
|
|
6600
|
-
return (_a = editor.editable) == null ? void 0 : _a.marks();
|
|
6601
|
-
}), __publicField(PortableTextEditor, "select", (editor, selection) => {
|
|
6602
|
-
var _a;
|
|
6603
|
-
debug$4("Host setting selection", selection), (_a = editor.editable) == null || _a.select(selection);
|
|
6604
|
-
}), __publicField(PortableTextEditor, "removeAnnotation", (editor, type) => {
|
|
6605
|
-
var _a;
|
|
6606
|
-
return (_a = editor.editable) == null ? void 0 : _a.removeAnnotation(type);
|
|
6607
|
-
}), __publicField(PortableTextEditor, "toggleBlockStyle", (editor, blockStyle) => {
|
|
6608
|
-
var _a;
|
|
6609
|
-
return debug$4("Host is toggling block style"), (_a = editor.editable) == null ? void 0 : _a.toggleBlockStyle(blockStyle);
|
|
6610
|
-
}), __publicField(PortableTextEditor, "toggleList", (editor, listStyle) => {
|
|
6611
|
-
var _a;
|
|
6612
|
-
return (_a = editor.editable) == null ? void 0 : _a.toggleList(listStyle);
|
|
6613
|
-
}), __publicField(PortableTextEditor, "toggleMark", (editor, mark) => {
|
|
6614
|
-
var _a;
|
|
6615
|
-
debug$4("Host toggling mark", mark), (_a = editor.editable) == null || _a.toggleMark(mark);
|
|
6616
|
-
}), __publicField(PortableTextEditor, "getFragment", (editor) => {
|
|
6617
|
-
var _a;
|
|
6618
|
-
return debug$4("Host getting fragment"), (_a = editor.editable) == null ? void 0 : _a.getFragment();
|
|
6619
|
-
}), __publicField(PortableTextEditor, "undo", (editor) => {
|
|
6620
|
-
var _a;
|
|
6621
|
-
debug$4("Host undoing"), (_a = editor.editable) == null || _a.undo();
|
|
6622
|
-
}), __publicField(PortableTextEditor, "redo", (editor) => {
|
|
6623
|
-
var _a;
|
|
6624
|
-
debug$4("Host redoing"), (_a = editor.editable) == null || _a.redo();
|
|
6625
|
-
}), __publicField(PortableTextEditor, "isSelectionsOverlapping", (editor, selectionA, selectionB) => {
|
|
6626
|
-
var _a;
|
|
6627
|
-
return (_a = editor.editable) == null ? void 0 : _a.isSelectionsOverlapping(selectionA, selectionB);
|
|
6628
|
-
});
|
|
6629
6336
|
function RoutePatchesObservableToEditorActor(props) {
|
|
6630
6337
|
const $ = reactCompilerRuntime.c(4);
|
|
6631
6338
|
let t0, t1;
|
|
6632
6339
|
return $[0] !== props.editorActor || $[1] !== props.patches$ ? (t0 = () => {
|
|
6633
6340
|
const subscription = props.patches$.subscribe((payload) => {
|
|
6634
|
-
props.editorActor.send(
|
|
6635
|
-
type: "patches"
|
|
6636
|
-
|
|
6341
|
+
props.editorActor.send({
|
|
6342
|
+
type: "patches",
|
|
6343
|
+
...payload
|
|
6344
|
+
});
|
|
6637
6345
|
});
|
|
6638
6346
|
return () => {
|
|
6639
6347
|
subscription.unsubscribe();
|
|
@@ -6698,9 +6406,10 @@ function RouteEventsToChanges(props) {
|
|
|
6698
6406
|
break bb5;
|
|
6699
6407
|
}
|
|
6700
6408
|
case "error": {
|
|
6701
|
-
handleChange(
|
|
6409
|
+
handleChange({
|
|
6410
|
+
...event,
|
|
6702
6411
|
level: "warning"
|
|
6703
|
-
})
|
|
6412
|
+
});
|
|
6704
6413
|
break bb5;
|
|
6705
6414
|
}
|
|
6706
6415
|
case "annotation.add":
|
|
@@ -6728,14 +6437,6 @@ function RouteEventsToChanges(props) {
|
|
|
6728
6437
|
};
|
|
6729
6438
|
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), React.useEffect(t1, t2), null;
|
|
6730
6439
|
}
|
|
6731
|
-
var __defProp$2 = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
|
|
6732
|
-
for (var prop in b || (b = {}))
|
|
6733
|
-
__hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6734
|
-
if (__getOwnPropSymbols$2)
|
|
6735
|
-
for (var prop of __getOwnPropSymbols$2(b))
|
|
6736
|
-
__propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6737
|
-
return a;
|
|
6738
|
-
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
6739
6440
|
const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
6740
6441
|
const {
|
|
6741
6442
|
editorActor,
|
|
@@ -6747,13 +6448,10 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6747
6448
|
renderDecorator,
|
|
6748
6449
|
renderAnnotation
|
|
6749
6450
|
} = props, spanRef = React.useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = slateReact.useSelected(), [focused, setFocused] = React.useState(!1), [selected, setSelected] = React.useState(!1), block = children.props.parent, path = React.useMemo(() => block ? [{
|
|
6750
|
-
_key: block
|
|
6451
|
+
_key: block?._key
|
|
6751
6452
|
}, "children", {
|
|
6752
6453
|
_key: leaf._key
|
|
6753
|
-
}] : [], [block, leaf._key]), decoratorValues = React.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = React.useMemo(() => uniq__default.default((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = React.useMemo(() => annotationMarks.map((mark_0) =>
|
|
6754
|
-
var _a;
|
|
6755
|
-
return !decoratorValues.includes(mark_0) && ((_a = block == null ? void 0 : block.markDefs) == null ? void 0 : _a.find((def) => def._key === mark_0));
|
|
6756
|
-
}).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
6454
|
+
}] : [], [block, leaf._key]), decoratorValues = React.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = React.useMemo(() => uniq__default.default((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = React.useMemo(() => annotationMarks.map((mark_0) => !decoratorValues.includes(mark_0) && block?.markDefs?.find((def) => def._key === mark_0)).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
6757
6455
|
React.useEffect(() => {
|
|
6758
6456
|
if (!shouldTrackSelectionAndFocus) {
|
|
6759
6457
|
setFocused(!1);
|
|
@@ -6860,7 +6558,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6860
6558
|
}
|
|
6861
6559
|
return returnedChildren;
|
|
6862
6560
|
}, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
|
|
6863
|
-
return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span",
|
|
6561
|
+
return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6864
6562
|
};
|
|
6865
6563
|
Leaf.displayName = "Leaf";
|
|
6866
6564
|
const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
@@ -6913,32 +6611,10 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6913
6611
|
}, editor;
|
|
6914
6612
|
};
|
|
6915
6613
|
}
|
|
6916
|
-
var __defProp$1 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
|
|
6917
|
-
for (var prop in b || (b = {}))
|
|
6918
|
-
__hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6919
|
-
if (__getOwnPropSymbols$1)
|
|
6920
|
-
for (var prop of __getOwnPropSymbols$1(b))
|
|
6921
|
-
__propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6922
|
-
return a;
|
|
6923
|
-
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), __objRest$1 = (source, exclude) => {
|
|
6924
|
-
var target = {};
|
|
6925
|
-
for (var prop in source)
|
|
6926
|
-
__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
6927
|
-
if (source != null && __getOwnPropSymbols$1)
|
|
6928
|
-
for (var prop of __getOwnPropSymbols$1(source))
|
|
6929
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop) && (target[prop] = source[prop]);
|
|
6930
|
-
return target;
|
|
6931
|
-
};
|
|
6932
6614
|
const debug$1 = debugWithName("plugin:withInsertData");
|
|
6933
6615
|
function createWithInsertData(editorActor, schemaTypes) {
|
|
6934
6616
|
return function(editor) {
|
|
6935
|
-
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => {
|
|
6936
|
-
var _a;
|
|
6937
|
-
return editor.isTextBlock(block) ? block.children.map((child) => {
|
|
6938
|
-
var _a2;
|
|
6939
|
-
return child._type === spanTypeName ? child.text : `[${((_a2 = schemaTypes.inlineObjects.find((t) => t.name === child._type)) == null ? void 0 : _a2.title) || "Object"}]`;
|
|
6940
|
-
}).join("") : `[${((_a = schemaTypes.blockObjects.find((t) => t.name === block._type)) == null ? void 0 : _a.title) || "Object"}]`;
|
|
6941
|
-
}).join(`
|
|
6617
|
+
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => editor.isTextBlock(block) ? block.children.map((child) => child._type === spanTypeName ? child.text : `[${schemaTypes.inlineObjects.find((t) => t.name === child._type)?.title || "Object"}]`).join("") : `[${schemaTypes.blockObjects.find((t) => t.name === block._type)?.title || "Object"}]`).join(`
|
|
6942
6618
|
|
|
6943
6619
|
`);
|
|
6944
6620
|
return editor.setFragmentData = (data, originEvent) => {
|
|
@@ -6976,7 +6652,6 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
6976
6652
|
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
6977
6653
|
data.clearData(), data.setData("text/plain", asPlainText), data.setData("text/html", asHTML), data.setData("application/json", asJSON), data.setData("application/x-portable-text", asJSON), debug$1("text", asPlainText), data.setData("application/x-portable-text-event-origin", originEvent || "external"), debug$1("Set fragment data", asJSON, asHTML);
|
|
6978
6654
|
}, editor.insertPortableTextData = (data) => {
|
|
6979
|
-
var _a, _b;
|
|
6980
6655
|
if (!editor.selection)
|
|
6981
6656
|
return !1;
|
|
6982
6657
|
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
@@ -6986,8 +6661,8 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
6986
6661
|
const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
|
|
6987
6662
|
schemaTypes
|
|
6988
6663
|
}), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
6989
|
-
if (!validation.valid && !
|
|
6990
|
-
const errorDescription = `${
|
|
6664
|
+
if (!validation.valid && !validation.resolution?.autoResolve) {
|
|
6665
|
+
const errorDescription = `${validation.resolution?.description}`;
|
|
6991
6666
|
return editorActor.send({
|
|
6992
6667
|
type: "error",
|
|
6993
6668
|
name: "pasteError",
|
|
@@ -7000,7 +6675,6 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7000
6675
|
}
|
|
7001
6676
|
return !1;
|
|
7002
6677
|
}, editor.insertTextOrHTMLData = (data) => {
|
|
7003
|
-
var _a;
|
|
7004
6678
|
if (!editor.selection)
|
|
7005
6679
|
return debug$1("No selection, not inserting"), !1;
|
|
7006
6680
|
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
@@ -7027,7 +6701,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7027
6701
|
const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7028
6702
|
if (!validation.valid) {
|
|
7029
6703
|
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
7030
|
-
${
|
|
6704
|
+
${validation.resolution?.description}
|
|
7031
6705
|
Try to insert as plain text (shift-paste) instead.`;
|
|
7032
6706
|
return editorActor.send({
|
|
7033
6707
|
type: "error",
|
|
@@ -7066,37 +6740,46 @@ function escapeHtml(str) {
|
|
|
7066
6740
|
}
|
|
7067
6741
|
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
7068
6742
|
return fragment.map((node) => {
|
|
7069
|
-
const newNode =
|
|
6743
|
+
const newNode = {
|
|
6744
|
+
...node
|
|
6745
|
+
};
|
|
7070
6746
|
if (editor.isTextBlock(newNode)) {
|
|
7071
6747
|
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
7072
6748
|
if (annotations.length === 0) {
|
|
7073
|
-
const
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
6749
|
+
const {
|
|
6750
|
+
markDefs,
|
|
6751
|
+
...NewNodeNoDefs
|
|
6752
|
+
} = newNode;
|
|
6753
|
+
return {
|
|
6754
|
+
...NewNodeNoDefs,
|
|
7077
6755
|
_key: keyGenerator()
|
|
7078
|
-
}
|
|
6756
|
+
};
|
|
7079
6757
|
}
|
|
7080
6758
|
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
7081
6759
|
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
7082
|
-
return
|
|
6760
|
+
return {
|
|
6761
|
+
...newNode,
|
|
7083
6762
|
markDefs: allowedAnnotations,
|
|
7084
6763
|
_key: keyGenerator()
|
|
7085
|
-
}
|
|
6764
|
+
};
|
|
7086
6765
|
}
|
|
7087
6766
|
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
7088
6767
|
const oldKey = def._key, newKey = keyGenerator();
|
|
7089
|
-
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ?
|
|
6768
|
+
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
6769
|
+
...child,
|
|
7090
6770
|
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
7091
|
-
}
|
|
6771
|
+
} : child), {
|
|
6772
|
+
...def,
|
|
7092
6773
|
_key: newKey
|
|
7093
|
-
}
|
|
6774
|
+
};
|
|
7094
6775
|
});
|
|
7095
6776
|
}
|
|
7096
|
-
const nodeWithNewKeys =
|
|
6777
|
+
const nodeWithNewKeys = {
|
|
6778
|
+
...newNode,
|
|
7097
6779
|
_key: keyGenerator()
|
|
7098
|
-
}
|
|
7099
|
-
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) =>
|
|
6780
|
+
};
|
|
6781
|
+
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
6782
|
+
...child,
|
|
7100
6783
|
_key: keyGenerator()
|
|
7101
6784
|
}))), nodeWithNewKeys;
|
|
7102
6785
|
});
|
|
@@ -7141,22 +6824,6 @@ function withSyncRangeDecorations({
|
|
|
7141
6824
|
slateEditor.apply = originalApply;
|
|
7142
6825
|
};
|
|
7143
6826
|
}
|
|
7144
|
-
var __defProp2 = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols2 = Object.getOwnPropertySymbols, __hasOwnProp2 = Object.prototype.hasOwnProperty, __propIsEnum2 = Object.prototype.propertyIsEnumerable, __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues2 = (a, b) => {
|
|
7145
|
-
for (var prop in b || (b = {}))
|
|
7146
|
-
__hasOwnProp2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
7147
|
-
if (__getOwnPropSymbols2)
|
|
7148
|
-
for (var prop of __getOwnPropSymbols2(b))
|
|
7149
|
-
__propIsEnum2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
7150
|
-
return a;
|
|
7151
|
-
}, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)), __objRest = (source, exclude) => {
|
|
7152
|
-
var target = {};
|
|
7153
|
-
for (var prop in source)
|
|
7154
|
-
__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
7155
|
-
if (source != null && __getOwnPropSymbols2)
|
|
7156
|
-
for (var prop of __getOwnPropSymbols2(source))
|
|
7157
|
-
exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop) && (target[prop] = source[prop]);
|
|
7158
|
-
return target;
|
|
7159
|
-
};
|
|
7160
6827
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
7161
6828
|
position: "absolute",
|
|
7162
6829
|
userSelect: "none",
|
|
@@ -7164,7 +6831,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7164
6831
|
left: 0,
|
|
7165
6832
|
right: 0
|
|
7166
6833
|
}, PortableTextEditable = React.forwardRef(function(props, forwardedRef) {
|
|
7167
|
-
const
|
|
6834
|
+
const {
|
|
7168
6835
|
hotkeys,
|
|
7169
6836
|
onBlur,
|
|
7170
6837
|
onFocus,
|
|
@@ -7182,27 +6849,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7182
6849
|
renderStyle,
|
|
7183
6850
|
selection: propsSelection,
|
|
7184
6851
|
scrollSelectionIntoView,
|
|
7185
|
-
spellCheck
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
"onBlur",
|
|
7189
|
-
"onFocus",
|
|
7190
|
-
"onBeforeInput",
|
|
7191
|
-
"onPaste",
|
|
7192
|
-
"onCopy",
|
|
7193
|
-
"onClick",
|
|
7194
|
-
"rangeDecorations",
|
|
7195
|
-
"renderAnnotation",
|
|
7196
|
-
"renderBlock",
|
|
7197
|
-
"renderChild",
|
|
7198
|
-
"renderDecorator",
|
|
7199
|
-
"renderListItem",
|
|
7200
|
-
"renderPlaceholder",
|
|
7201
|
-
"renderStyle",
|
|
7202
|
-
"selection",
|
|
7203
|
-
"scrollSelectionIntoView",
|
|
7204
|
-
"spellCheck"
|
|
7205
|
-
]), portableTextEditor = usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), [rangeDecorationState, setRangeDecorationsState] = React.useState([]);
|
|
6852
|
+
spellCheck,
|
|
6853
|
+
...restProps
|
|
6854
|
+
} = props, portableTextEditor = usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), [rangeDecorationState, setRangeDecorationsState] = React.useState([]);
|
|
7206
6855
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
7207
6856
|
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
7208
6857
|
"edit mode": "read only"
|
|
@@ -7214,9 +6863,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7214
6863
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
7215
6864
|
return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
|
|
7216
6865
|
}, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
|
|
7217
|
-
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element,
|
|
6866
|
+
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = React.useCallback((lProps) => {
|
|
7218
6867
|
if (lProps.leaf._type === "span") {
|
|
7219
|
-
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf,
|
|
6868
|
+
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
7220
6869
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
7221
6870
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
7222
6871
|
/* @__PURE__ */ jsxRuntime.jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: renderPlaceholder() }),
|
|
@@ -7263,9 +6912,10 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7263
6912
|
origin: "local"
|
|
7264
6913
|
});
|
|
7265
6914
|
}
|
|
7266
|
-
newRange !== null && newSlateRanges.push(
|
|
6915
|
+
newRange !== null && newSlateRanges.push({
|
|
6916
|
+
...newRange || slateRange_0,
|
|
7267
6917
|
rangeDecoration: rangeDecorationItem
|
|
7268
|
-
})
|
|
6918
|
+
});
|
|
7269
6919
|
}), newSlateRanges.length > 0) {
|
|
7270
6920
|
setRangeDecorationsState(newSlateRanges);
|
|
7271
6921
|
return;
|
|
@@ -7311,7 +6961,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7311
6961
|
nativeEvent: event
|
|
7312
6962
|
});
|
|
7313
6963
|
}, [onCopy, editorActor, slateEditor]), handlePaste = React.useCallback((event_0) => {
|
|
7314
|
-
const value_0 = PortableTextEditor.getValue(portableTextEditor),
|
|
6964
|
+
const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
|
|
7315
6965
|
event: event_0,
|
|
7316
6966
|
value: value_0,
|
|
7317
6967
|
path,
|
|
@@ -7376,8 +7026,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7376
7026
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
7377
7027
|
try {
|
|
7378
7028
|
const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
7379
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection
|
|
7380
|
-
} catch
|
|
7029
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
7030
|
+
} catch {
|
|
7381
7031
|
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
7382
7032
|
}
|
|
7383
7033
|
}, [ref, slateEditor]);
|
|
@@ -7465,7 +7115,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7465
7115
|
ref.current = slateReact.ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
7466
7116
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
7467
7117
|
slateReact.Editable,
|
|
7468
|
-
|
|
7118
|
+
{
|
|
7119
|
+
...restProps,
|
|
7469
7120
|
autoFocus: !1,
|
|
7470
7121
|
className: restProps.className || "pt-editable",
|
|
7471
7122
|
decorate,
|
|
@@ -7482,7 +7133,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7482
7133
|
renderElement,
|
|
7483
7134
|
renderLeaf,
|
|
7484
7135
|
scrollSelectionIntoView: scrollSelectionIntoViewToSlate
|
|
7485
|
-
}
|
|
7136
|
+
}
|
|
7486
7137
|
) : null;
|
|
7487
7138
|
});
|
|
7488
7139
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|