@portabletext/editor 1.15.3 → 1.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +25 -25
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +14 -14
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/{selectors.cjs → selector.is-selection-collapsed.cjs} +8 -8
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js +7 -7
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +14 -14
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/{selectors.js → selector.is-selection-collapsed.js} +8 -8
- package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -0
- package/lib/behaviors/index.cjs +23 -23
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +1 -0
- package/lib/behaviors/index.d.ts +1 -0
- package/lib/behaviors/index.js +8 -8
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +863 -516
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3816 -4457
- package/lib/index.d.ts +3816 -4457
- package/lib/index.js +860 -515
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +166 -16
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +54 -5
- package/lib/selectors/index.d.ts +54 -5
- package/lib/selectors/index.js +154 -3
- package/lib/selectors/index.js.map +1 -1
- package/package.json +11 -11
- package/src/behaviors/behavior.code-editor.ts +5 -9
- package/src/behaviors/behavior.core.block-objects.ts +13 -19
- package/src/behaviors/behavior.core.lists.ts +11 -17
- package/src/behaviors/behavior.links.ts +4 -4
- package/src/behaviors/behavior.markdown.ts +16 -21
- package/src/editor/Editable.tsx +11 -4
- package/src/editor/PortableTextEditor.tsx +4 -4
- package/src/editor/{hooks/useSyncValue.test.tsx → __tests__/sync-value.test.tsx} +42 -23
- package/src/editor/components/Synchronizer.tsx +53 -80
- package/src/editor/create-editor.ts +4 -1
- package/src/editor/editor-machine.ts +135 -83
- package/src/editor/editor-provider.tsx +0 -3
- package/src/editor/editor-selector.ts +5 -0
- package/src/editor/editor-snapshot.ts +1 -0
- package/src/editor/get-active-decorators.ts +20 -0
- package/src/editor/mutation-machine.ts +100 -0
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +21 -15
- package/src/editor/plugins/createWithMaxBlocks.ts +1 -1
- package/src/editor/plugins/createWithPatches.ts +0 -4
- package/src/editor/plugins/createWithPlaceholderBlock.ts +1 -1
- package/src/editor/plugins/createWithPortableTextSelections.ts +4 -1
- package/src/editor/plugins/createWithUndoRedo.ts +3 -3
- package/src/editor/sync-machine.ts +661 -0
- package/src/editor/withSyncRangeDecorations.ts +17 -5
- package/src/selectors/_exports/index.ts +1 -0
- package/src/selectors/index.ts +9 -1
- package/src/selectors/selector.get-active-style.ts +37 -0
- package/src/selectors/selector.get-selected-spans.ts +136 -0
- package/src/selectors/selector.is-active-annotation.ts +49 -0
- package/src/selectors/selector.is-active-decorator.ts +21 -0
- package/src/selectors/selector.is-active-list-item.ts +13 -0
- package/src/selectors/selector.is-active-style.ts +13 -0
- package/src/selectors/selector.is-selection-collapsed.ts +12 -0
- package/src/selectors/selector.is-selection-expanded.ts +9 -0
- package/src/selectors/selectors.ts +0 -11
- package/src/utils/weakMaps.ts +0 -3
- package/src/utils/withChanges.ts +1 -8
- package/lib/_chunks-cjs/selectors.cjs.map +0 -1
- package/lib/_chunks-es/selectors.js.map +0 -1
- package/src/editor/hooks/useSyncValue.ts +0 -426
package/lib/index.cjs
CHANGED
|
@@ -11,11 +11,11 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
11
11
|
return a;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
14
|
-
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$m = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"),
|
|
14
|
+
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$m = 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
15
|
function _interopDefaultCompat(e) {
|
|
16
16
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
17
17
|
}
|
|
18
|
-
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$m), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq),
|
|
18
|
+
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$m), 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
19
|
function createEditorSchema(portableTextType) {
|
|
20
20
|
var _a, _b, _c;
|
|
21
21
|
if (!portableTextType)
|
|
@@ -71,12 +71,12 @@ function resolveEnabledListItems(blockType) {
|
|
|
71
71
|
function findBlockType(type) {
|
|
72
72
|
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
73
73
|
}
|
|
74
|
-
var __defProp$
|
|
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
75
|
for (var prop in b || (b = {}))
|
|
76
|
-
__hasOwnProp$
|
|
77
|
-
if (__getOwnPropSymbols$
|
|
78
|
-
for (var prop of __getOwnPropSymbols$
|
|
79
|
-
__propIsEnum$
|
|
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
80
|
return a;
|
|
81
81
|
}, __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
|
|
82
82
|
function defineSchema(definition) {
|
|
@@ -145,10 +145,10 @@ function compileSchemaDefinition(definition) {
|
|
|
145
145
|
}), schema$1 = schema.Schema.compile({
|
|
146
146
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
147
147
|
}).get("portable-text"), pteSchema = createEditorSchema(schema$1);
|
|
148
|
-
return __spreadProps$j(__spreadValues$
|
|
149
|
-
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$
|
|
148
|
+
return __spreadProps$j(__spreadValues$q({}, pteSchema), {
|
|
149
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$q({}, blockObject), {
|
|
150
150
|
name: "image",
|
|
151
|
-
type: __spreadProps$j(__spreadValues$
|
|
151
|
+
type: __spreadProps$j(__spreadValues$q({}, blockObject.type), {
|
|
152
152
|
name: "image"
|
|
153
153
|
})
|
|
154
154
|
}) : blockObject)
|
|
@@ -287,20 +287,20 @@ function normalizeSelection(selection, value) {
|
|
|
287
287
|
backward: selection.backward
|
|
288
288
|
} : null;
|
|
289
289
|
}
|
|
290
|
-
var __defProp$
|
|
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
291
|
for (var prop in b || (b = {}))
|
|
292
|
-
__hasOwnProp$
|
|
293
|
-
if (__getOwnPropSymbols$
|
|
294
|
-
for (var prop of __getOwnPropSymbols$
|
|
295
|
-
__propIsEnum$
|
|
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
296
|
return a;
|
|
297
297
|
}, __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b)), __objRest$3 = (source, exclude) => {
|
|
298
298
|
var target = {};
|
|
299
299
|
for (var prop in source)
|
|
300
|
-
__hasOwnProp$
|
|
301
|
-
if (source != null && __getOwnPropSymbols$
|
|
302
|
-
for (var prop of __getOwnPropSymbols$
|
|
303
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$
|
|
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
304
|
return target;
|
|
305
305
|
};
|
|
306
306
|
const VOID_CHILD_KEY = "void-child";
|
|
@@ -343,7 +343,7 @@ function toSlateValue(value, {
|
|
|
343
343
|
__inline: !0
|
|
344
344
|
}, keyMap)) : child;
|
|
345
345
|
});
|
|
346
|
-
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(__spreadProps$i(__spreadValues$
|
|
346
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(__spreadProps$i(__spreadValues$p({
|
|
347
347
|
_type,
|
|
348
348
|
_key
|
|
349
349
|
}, rest), {
|
|
@@ -387,21 +387,21 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
387
387
|
"__inline",
|
|
388
388
|
"children"
|
|
389
389
|
]);
|
|
390
|
-
return keepObjectEquality(__spreadProps$i(__spreadValues$
|
|
390
|
+
return keepObjectEquality(__spreadProps$i(__spreadValues$p(__spreadValues$p({}, rest), v), {
|
|
391
391
|
_key: k,
|
|
392
392
|
_type: t
|
|
393
393
|
}), keyMap);
|
|
394
394
|
}
|
|
395
395
|
return child;
|
|
396
396
|
});
|
|
397
|
-
return hasInlines ? keepObjectEquality(__spreadProps$i(__spreadValues$
|
|
397
|
+
return hasInlines ? keepObjectEquality(__spreadProps$i(__spreadValues$p({}, block), {
|
|
398
398
|
children,
|
|
399
399
|
_key,
|
|
400
400
|
_type
|
|
401
401
|
}), keyMap) : block;
|
|
402
402
|
}
|
|
403
403
|
const blockValue = "value" in block && block.value;
|
|
404
|
-
return keepObjectEquality(__spreadValues$
|
|
404
|
+
return keepObjectEquality(__spreadValues$p({
|
|
405
405
|
_key,
|
|
406
406
|
_type
|
|
407
407
|
}, typeof blockValue == "object" ? blockValue : {}), keyMap);
|
|
@@ -411,7 +411,7 @@ function isEqualToEmptyEditor(children, schemaTypes) {
|
|
|
411
411
|
var _a;
|
|
412
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 === "";
|
|
413
413
|
}
|
|
414
|
-
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(),
|
|
414
|
+
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
415
|
const $ = reactCompilerRuntime.c(4);
|
|
416
416
|
let t0;
|
|
417
417
|
$[0] !== props.value ? (t0 = JSON.stringify(props.value, null, 2), $[0] = props.value, $[1] = t0) : t0 = $[1];
|
|
@@ -709,12 +709,12 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
709
709
|
] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
|
|
710
710
|
};
|
|
711
711
|
DraggableBlock.displayName = "DraggableBlock";
|
|
712
|
-
var __defProp$
|
|
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
713
|
for (var prop in b || (b = {}))
|
|
714
|
-
__hasOwnProp$
|
|
715
|
-
if (__getOwnPropSymbols$
|
|
716
|
-
for (var prop of __getOwnPropSymbols$
|
|
717
|
-
__propIsEnum$
|
|
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
718
|
return a;
|
|
719
719
|
}, __spreadProps$h = (a, b) => __defProps$h(a, __getOwnPropDescs$h(b));
|
|
720
720
|
debugWithName("components:Element");
|
|
@@ -753,7 +753,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
753
753
|
}, "children", {
|
|
754
754
|
_key: element._key
|
|
755
755
|
}];
|
|
756
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span", __spreadProps$h(__spreadValues$
|
|
756
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", __spreadProps$h(__spreadValues$o({}, attributes), { children: [
|
|
757
757
|
children,
|
|
758
758
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
|
|
759
759
|
renderChild && renderChild({
|
|
@@ -821,7 +821,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
821
821
|
return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
|
|
822
822
|
}
|
|
823
823
|
}), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
|
|
824
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", __spreadProps$h(__spreadValues$
|
|
824
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", __spreadProps$h(__spreadValues$o({}, attributes), { className, spellCheck, children: /* @__PURE__ */ jsxRuntime.jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }), element._key);
|
|
825
825
|
}
|
|
826
826
|
const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
|
|
827
827
|
if (!schemaType_0)
|
|
@@ -846,7 +846,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
846
846
|
});
|
|
847
847
|
renderedBlockFromProps = renderBlock(_props);
|
|
848
848
|
}
|
|
849
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", __spreadProps$h(__spreadValues$
|
|
849
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", __spreadProps$h(__spreadValues$o({}, attributes), { className, children: [
|
|
850
850
|
children,
|
|
851
851
|
/* @__PURE__ */ jsxRuntime.jsxs(DraggableBlock, { element, readOnly, blockRef, children: [
|
|
852
852
|
renderedBlockFromProps && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
|
|
@@ -880,12 +880,83 @@ function compileType(rawType) {
|
|
|
880
880
|
types: [rawType]
|
|
881
881
|
}).get(rawType.name);
|
|
882
882
|
}
|
|
883
|
-
|
|
883
|
+
const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3, mutationMachine = xstate.setup({
|
|
884
|
+
types: {
|
|
885
|
+
context: {},
|
|
886
|
+
events: {},
|
|
887
|
+
input: {},
|
|
888
|
+
emitted: {}
|
|
889
|
+
},
|
|
890
|
+
actions: {
|
|
891
|
+
"emit has pending patches": xstate.emit({
|
|
892
|
+
type: "has pending patches"
|
|
893
|
+
}),
|
|
894
|
+
"emit mutation": xstate.emit(({
|
|
895
|
+
context
|
|
896
|
+
}) => ({
|
|
897
|
+
type: "mutation",
|
|
898
|
+
patches: context.pendingPatches,
|
|
899
|
+
snapshot: fromSlateValue(context.slateEditor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(context.slateEditor))
|
|
900
|
+
})),
|
|
901
|
+
"clear pending patches": xstate.assign({
|
|
902
|
+
pendingPatches: []
|
|
903
|
+
}),
|
|
904
|
+
"defer patch": xstate.assign({
|
|
905
|
+
pendingPatches: ({
|
|
906
|
+
context,
|
|
907
|
+
event
|
|
908
|
+
}) => [...context.pendingPatches, event.patch]
|
|
909
|
+
})
|
|
910
|
+
},
|
|
911
|
+
guards: {
|
|
912
|
+
"slate is normalizing": ({
|
|
913
|
+
context
|
|
914
|
+
}) => slate.Editor.isNormalizing(context.slateEditor)
|
|
915
|
+
}
|
|
916
|
+
}).createMachine({
|
|
917
|
+
id: "mutation",
|
|
918
|
+
context: ({
|
|
919
|
+
input
|
|
920
|
+
}) => ({
|
|
921
|
+
pendingPatches: [],
|
|
922
|
+
schema: input.schema,
|
|
923
|
+
slateEditor: input.slateEditor
|
|
924
|
+
}),
|
|
925
|
+
initial: "idle",
|
|
926
|
+
states: {
|
|
927
|
+
idle: {
|
|
928
|
+
on: {
|
|
929
|
+
patch: {
|
|
930
|
+
actions: ["defer patch", "emit has pending patches"],
|
|
931
|
+
target: "has pending patches"
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
},
|
|
935
|
+
"has pending patches": {
|
|
936
|
+
after: {
|
|
937
|
+
[FLUSH_PATCHES_THROTTLED_MS]: [{
|
|
938
|
+
guard: "slate is normalizing",
|
|
939
|
+
target: "idle",
|
|
940
|
+
actions: ["emit mutation", "clear pending patches"]
|
|
941
|
+
}, {
|
|
942
|
+
reenter: !0
|
|
943
|
+
}]
|
|
944
|
+
},
|
|
945
|
+
on: {
|
|
946
|
+
patch: {
|
|
947
|
+
actions: ["defer patch"],
|
|
948
|
+
reenter: !0
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
});
|
|
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) => {
|
|
884
955
|
for (var prop in b || (b = {}))
|
|
885
|
-
__hasOwnProp$
|
|
886
|
-
if (__getOwnPropSymbols$
|
|
887
|
-
for (var prop of __getOwnPropSymbols$
|
|
888
|
-
__propIsEnum$
|
|
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]);
|
|
889
960
|
return a;
|
|
890
961
|
}, __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
|
|
891
962
|
function validateValue(value, types$1, keyGenerator) {
|
|
@@ -925,7 +996,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
925
996
|
}, !0;
|
|
926
997
|
if (!blk._key || typeof blk._key != "string")
|
|
927
998
|
return resolution = {
|
|
928
|
-
patches: [patches.set(__spreadProps$g(__spreadValues$
|
|
999
|
+
patches: [patches.set(__spreadProps$g(__spreadValues$n({}, blk), {
|
|
929
1000
|
_key: keyGenerator()
|
|
930
1001
|
}), [index])],
|
|
931
1002
|
description: `Block at index ${index} is missing required _key.`,
|
|
@@ -943,7 +1014,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
943
1014
|
if (blk._type === "block") {
|
|
944
1015
|
const currentBlockTypeName = types$1.block.name;
|
|
945
1016
|
return resolution = {
|
|
946
|
-
patches: [patches.set(__spreadProps$g(__spreadValues$
|
|
1017
|
+
patches: [patches.set(__spreadProps$g(__spreadValues$n({}, blk), {
|
|
947
1018
|
_type: currentBlockTypeName
|
|
948
1019
|
}), [{
|
|
949
1020
|
_key: blk._key
|
|
@@ -961,10 +1032,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
961
1032
|
}
|
|
962
1033
|
}, !0;
|
|
963
1034
|
}
|
|
964
|
-
return !blk._type && types.isPortableTextTextBlock(__spreadProps$g(__spreadValues$
|
|
1035
|
+
return !blk._type && types.isPortableTextTextBlock(__spreadProps$g(__spreadValues$n({}, blk), {
|
|
965
1036
|
_type: types$1.block.name
|
|
966
1037
|
})) ? (resolution = {
|
|
967
|
-
patches: [patches.set(__spreadProps$g(__spreadValues$
|
|
1038
|
+
patches: [patches.set(__spreadProps$g(__spreadValues$n({}, blk), {
|
|
968
1039
|
_type: types$1.block.name
|
|
969
1040
|
}), [{
|
|
970
1041
|
_key: blk._key
|
|
@@ -1126,7 +1197,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1126
1197
|
}
|
|
1127
1198
|
}, !0;
|
|
1128
1199
|
if (!child._key || typeof child._key != "string") {
|
|
1129
|
-
const newChild = __spreadProps$g(__spreadValues$
|
|
1200
|
+
const newChild = __spreadProps$g(__spreadValues$n({}, child), {
|
|
1130
1201
|
_key: keyGenerator()
|
|
1131
1202
|
});
|
|
1132
1203
|
return resolution = {
|
|
@@ -1148,7 +1219,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1148
1219
|
}, !0;
|
|
1149
1220
|
}
|
|
1150
1221
|
return child._type ? validChildTypes.includes(child._type) ? child._type === types$1.span.name && typeof child.text != "string" ? (resolution = {
|
|
1151
|
-
patches: [patches.set(__spreadProps$g(__spreadValues$
|
|
1222
|
+
patches: [patches.set(__spreadProps$g(__spreadValues$n({}, child), {
|
|
1152
1223
|
text: ""
|
|
1153
1224
|
}), [{
|
|
1154
1225
|
_key: blk._key
|
|
@@ -1218,9 +1289,6 @@ function withRemoteChanges(editor, fn) {
|
|
|
1218
1289
|
function isChangingRemotely(editor) {
|
|
1219
1290
|
return IS_PROCESSING_REMOTE_CHANGES.get(editor);
|
|
1220
1291
|
}
|
|
1221
|
-
function isChangingLocally(editor) {
|
|
1222
|
-
return IS_PROCESSING_LOCAL_CHANGES.get(editor);
|
|
1223
|
-
}
|
|
1224
1292
|
const PATCHING = /* @__PURE__ */ new WeakMap();
|
|
1225
1293
|
function withoutPatching(editor, fn) {
|
|
1226
1294
|
const prev = isPatching(editor);
|
|
@@ -1943,15 +2011,15 @@ function isRedoing(editor) {
|
|
|
1943
2011
|
function setIsRedoing(editor, isRedoing2) {
|
|
1944
2012
|
IS_REDOING.set(editor, isRedoing2);
|
|
1945
2013
|
}
|
|
1946
|
-
var __defProp$
|
|
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) => {
|
|
1947
2015
|
for (var prop in b || (b = {}))
|
|
1948
|
-
__hasOwnProp$
|
|
1949
|
-
if (__getOwnPropSymbols$
|
|
1950
|
-
for (var prop of __getOwnPropSymbols$
|
|
1951
|
-
__propIsEnum$
|
|
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]);
|
|
1952
2020
|
return a;
|
|
1953
2021
|
};
|
|
1954
|
-
const debug$j = debugWithName("plugin:withUndoRedo"), debugVerbose$
|
|
2022
|
+
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) => {
|
|
1955
2023
|
const state = SAVING.get(editor);
|
|
1956
2024
|
return state === void 0 ? !0 : state;
|
|
1957
2025
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -1999,7 +2067,9 @@ function createWithUndoRedo(options) {
|
|
|
1999
2067
|
apply: apply2
|
|
2000
2068
|
} = editor;
|
|
2001
2069
|
return editor.apply = (op) => {
|
|
2002
|
-
if (editorActor.getSnapshot().
|
|
2070
|
+
if (editorActor.getSnapshot().matches({
|
|
2071
|
+
"edit mode": "read only"
|
|
2072
|
+
})) {
|
|
2003
2073
|
apply2(op);
|
|
2004
2074
|
return;
|
|
2005
2075
|
}
|
|
@@ -2034,7 +2104,9 @@ function createWithUndoRedo(options) {
|
|
|
2034
2104
|
}
|
|
2035
2105
|
apply2(op);
|
|
2036
2106
|
}, editor.undo = () => {
|
|
2037
|
-
if (editorActor.getSnapshot().
|
|
2107
|
+
if (editorActor.getSnapshot().matches({
|
|
2108
|
+
"edit mode": "read only"
|
|
2109
|
+
}))
|
|
2038
2110
|
return;
|
|
2039
2111
|
const {
|
|
2040
2112
|
undos
|
|
@@ -2069,7 +2141,9 @@ function createWithUndoRedo(options) {
|
|
|
2069
2141
|
}
|
|
2070
2142
|
}
|
|
2071
2143
|
}, editor.redo = () => {
|
|
2072
|
-
if (editorActor.getSnapshot().
|
|
2144
|
+
if (editorActor.getSnapshot().matches({
|
|
2145
|
+
"edit mode": "read only"
|
|
2146
|
+
}))
|
|
2073
2147
|
return;
|
|
2074
2148
|
const {
|
|
2075
2149
|
redos
|
|
@@ -2106,8 +2180,8 @@ function createWithUndoRedo(options) {
|
|
|
2106
2180
|
};
|
|
2107
2181
|
}
|
|
2108
2182
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2109
|
-
debugVerbose$
|
|
2110
|
-
const transformedOperation = __spreadValues$
|
|
2183
|
+
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 = __spreadValues$m({}, operation);
|
|
2111
2185
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
2112
2186
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2113
2187
|
_key: blk._key
|
|
@@ -2118,7 +2192,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2118
2192
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2119
2193
|
_key: blk._key
|
|
2120
2194
|
}, patch.path[0]));
|
|
2121
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$j("Skipping transformation that targeted removed block"), []) : (debugVerbose$
|
|
2195
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$j("Skipping transformation that targeted removed block"), []) : (debugVerbose$3 && (debug$j(`Selection ${JSON.stringify(editor.selection)}`), debug$j(`Adjusting block path (-1) for '${transformedOperation.type}' operation and patch '${patch.type}'`)), [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)]);
|
|
2122
2196
|
}
|
|
2123
2197
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2124
2198
|
return debug$j(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
@@ -2136,7 +2210,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2136
2210
|
const [diffType, text] = diff2;
|
|
2137
2211
|
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));
|
|
2138
2212
|
}), 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") {
|
|
2139
|
-
const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$
|
|
2213
|
+
const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$m({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$m({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$m({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$m({}, transformedOperation.newProperties.anchor) : void 0;
|
|
2140
2214
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2141
2215
|
point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
|
|
2142
2216
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2153,13 +2227,13 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2153
2227
|
}
|
|
2154
2228
|
function adjustBlockPath(operation, level, blockIndex) {
|
|
2155
2229
|
var _a, _b, _c, _d;
|
|
2156
|
-
const transformedOperation = __spreadValues$
|
|
2230
|
+
const transformedOperation = __spreadValues$m({}, operation);
|
|
2157
2231
|
if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
|
|
2158
2232
|
const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
|
|
2159
2233
|
transformedOperation.path = newPath;
|
|
2160
2234
|
}
|
|
2161
2235
|
if (transformedOperation.type === "set_selection") {
|
|
2162
|
-
const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$
|
|
2236
|
+
const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$m({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$m({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$m({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$m({}, transformedOperation.newProperties.anchor) : void 0;
|
|
2163
2237
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2164
2238
|
point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
|
|
2165
2239
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2180,147 +2254,336 @@ function withoutSaving(editor, fn) {
|
|
|
2180
2254
|
function createSelectOperation(editor) {
|
|
2181
2255
|
return {
|
|
2182
2256
|
type: "set_selection",
|
|
2183
|
-
properties: __spreadValues$
|
|
2184
|
-
newProperties: __spreadValues$
|
|
2257
|
+
properties: __spreadValues$m({}, editor.selection),
|
|
2258
|
+
newProperties: __spreadValues$m({}, editor.selection)
|
|
2185
2259
|
};
|
|
2186
2260
|
}
|
|
2187
2261
|
function findOperationTargetBlock(editor, operation) {
|
|
2188
2262
|
let block;
|
|
2189
2263
|
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;
|
|
2190
2264
|
}
|
|
2191
|
-
const
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2265
|
+
const syncValueCallback = ({
|
|
2266
|
+
sendBack,
|
|
2267
|
+
input
|
|
2268
|
+
}) => {
|
|
2269
|
+
updateValue({
|
|
2270
|
+
context: input.context,
|
|
2271
|
+
sendBack,
|
|
2272
|
+
slateEditor: input.slateEditor,
|
|
2273
|
+
value: input.value
|
|
2274
|
+
});
|
|
2275
|
+
}, syncValueLogic = xstate.fromCallback(syncValueCallback), syncMachine = xstate.setup({
|
|
2276
|
+
types: {
|
|
2277
|
+
context: {},
|
|
2278
|
+
input: {},
|
|
2279
|
+
events: {},
|
|
2280
|
+
emitted: {}
|
|
2281
|
+
},
|
|
2282
|
+
actions: {
|
|
2283
|
+
"assign readOnly": xstate.assign({
|
|
2284
|
+
readOnly: ({
|
|
2285
|
+
event
|
|
2286
|
+
}) => (xstate.assertEvent(event, "update readOnly"), event.readOnly)
|
|
2287
|
+
}),
|
|
2288
|
+
"assign pending value": xstate.assign({
|
|
2289
|
+
pendingValue: ({
|
|
2290
|
+
event
|
|
2291
|
+
}) => (xstate.assertEvent(event, "update value"), event.value)
|
|
2292
|
+
}),
|
|
2293
|
+
"clear pending value": xstate.assign({
|
|
2294
|
+
pendingValue: void 0
|
|
2295
|
+
}),
|
|
2296
|
+
"assign previous value": xstate.assign({
|
|
2297
|
+
previousValue: ({
|
|
2298
|
+
event
|
|
2299
|
+
}) => (xstate.assertEvent(event, "done syncing"), event.value)
|
|
2300
|
+
}),
|
|
2301
|
+
"emit done syncing": xstate.emit(({
|
|
2302
|
+
event
|
|
2303
|
+
}) => (xstate.assertEvent(event, "done syncing"), event))
|
|
2304
|
+
},
|
|
2305
|
+
guards: {
|
|
2306
|
+
"is readOnly": ({
|
|
2307
|
+
context
|
|
2308
|
+
}) => context.readOnly,
|
|
2309
|
+
"is processing local changes": ({
|
|
2310
|
+
context
|
|
2311
|
+
}) => context.isProcessingLocalChanges,
|
|
2312
|
+
"is processing remote changes": ({
|
|
2313
|
+
context
|
|
2314
|
+
}) => {
|
|
2315
|
+
var _a;
|
|
2316
|
+
return (_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1;
|
|
2317
|
+
},
|
|
2318
|
+
"is busy": xstate.and([xstate.not("is readOnly"), xstate.or(["is processing local changes", "is processing remote changes"])]),
|
|
2319
|
+
"value changed while syncing": ({
|
|
2320
|
+
context,
|
|
2321
|
+
event
|
|
2322
|
+
}) => (xstate.assertEvent(event, "done syncing"), context.pendingValue !== event.value),
|
|
2323
|
+
"pending value equals previous value": ({
|
|
2324
|
+
context
|
|
2325
|
+
}) => !(context.previousValue === void 0 && context.pendingValue === void 0) && isEqual__default.default(context.pendingValue, context.previousValue)
|
|
2326
|
+
},
|
|
2327
|
+
actors: {
|
|
2328
|
+
"sync value": syncValueLogic
|
|
2329
|
+
}
|
|
2330
|
+
}).createMachine({
|
|
2331
|
+
id: "sync",
|
|
2332
|
+
context: ({
|
|
2333
|
+
input
|
|
2334
|
+
}) => ({
|
|
2335
|
+
isProcessingLocalChanges: !1,
|
|
2336
|
+
keyGenerator: input.keyGenerator,
|
|
2337
|
+
schema: input.schema,
|
|
2338
|
+
readOnly: input.readOnly,
|
|
2339
|
+
slateEditor: input.slateEditor,
|
|
2340
|
+
pendingValue: void 0,
|
|
2341
|
+
previousValue: void 0
|
|
2342
|
+
}),
|
|
2343
|
+
initial: "idle",
|
|
2344
|
+
on: {
|
|
2345
|
+
"has pending patches": {
|
|
2346
|
+
actions: xstate.assign({
|
|
2347
|
+
isProcessingLocalChanges: !0
|
|
2348
|
+
})
|
|
2349
|
+
},
|
|
2350
|
+
mutation: {
|
|
2351
|
+
actions: xstate.assign({
|
|
2352
|
+
isProcessingLocalChanges: !1
|
|
2353
|
+
})
|
|
2354
|
+
},
|
|
2355
|
+
"update readOnly": {
|
|
2356
|
+
actions: ["assign readOnly"]
|
|
2203
2357
|
}
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2358
|
+
},
|
|
2359
|
+
states: {
|
|
2360
|
+
idle: {
|
|
2361
|
+
on: {
|
|
2362
|
+
"update value": [{
|
|
2363
|
+
guard: "is busy",
|
|
2364
|
+
target: "busy",
|
|
2365
|
+
actions: ["assign pending value"]
|
|
2366
|
+
}, {
|
|
2367
|
+
target: "syncing",
|
|
2368
|
+
actions: ["assign pending value"]
|
|
2369
|
+
}]
|
|
2370
|
+
}
|
|
2371
|
+
},
|
|
2372
|
+
busy: {
|
|
2373
|
+
after: {
|
|
2374
|
+
1e3: {
|
|
2375
|
+
target: "syncing"
|
|
2217
2376
|
}
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2377
|
+
},
|
|
2378
|
+
on: {
|
|
2379
|
+
"update value": [{
|
|
2380
|
+
guard: "is busy",
|
|
2381
|
+
actions: ["assign pending value"],
|
|
2382
|
+
reenter: !0
|
|
2383
|
+
}, {
|
|
2384
|
+
target: "syncing",
|
|
2385
|
+
actions: ["assign pending value"]
|
|
2386
|
+
}]
|
|
2387
|
+
}
|
|
2388
|
+
},
|
|
2389
|
+
syncing: {
|
|
2390
|
+
invoke: {
|
|
2391
|
+
src: "sync value",
|
|
2392
|
+
id: "sync value",
|
|
2393
|
+
input: ({
|
|
2394
|
+
context
|
|
2395
|
+
}) => {
|
|
2396
|
+
var _a;
|
|
2397
|
+
return {
|
|
2398
|
+
context: {
|
|
2399
|
+
keyGenerator: context.keyGenerator,
|
|
2400
|
+
previousValue: context.previousValue,
|
|
2401
|
+
readOnly: context.readOnly,
|
|
2402
|
+
schema: context.schema
|
|
2403
|
+
},
|
|
2404
|
+
slateEditor: context.slateEditor,
|
|
2405
|
+
value: (_a = context.pendingValue) != null ? _a : void 0
|
|
2406
|
+
};
|
|
2221
2407
|
}
|
|
2408
|
+
},
|
|
2409
|
+
always: {
|
|
2410
|
+
guard: "pending value equals previous value",
|
|
2411
|
+
actions: [xstate.emit(({
|
|
2412
|
+
context
|
|
2413
|
+
}) => ({
|
|
2414
|
+
type: "done syncing",
|
|
2415
|
+
value: context.previousValue
|
|
2416
|
+
}))],
|
|
2417
|
+
target: "idle"
|
|
2418
|
+
},
|
|
2419
|
+
on: {
|
|
2420
|
+
"update value": {
|
|
2421
|
+
actions: ["assign pending value"]
|
|
2422
|
+
},
|
|
2423
|
+
patch: {
|
|
2424
|
+
actions: [xstate.emit(({
|
|
2425
|
+
event
|
|
2426
|
+
}) => event)]
|
|
2427
|
+
},
|
|
2428
|
+
"invalid value": {
|
|
2429
|
+
actions: [xstate.emit(({
|
|
2430
|
+
event
|
|
2431
|
+
}) => event)]
|
|
2432
|
+
},
|
|
2433
|
+
"value changed": {
|
|
2434
|
+
actions: [xstate.emit(({
|
|
2435
|
+
event
|
|
2436
|
+
}) => event)]
|
|
2437
|
+
},
|
|
2438
|
+
"done syncing": [{
|
|
2439
|
+
guard: "value changed while syncing",
|
|
2440
|
+
actions: ["assign previous value", "emit done syncing"],
|
|
2441
|
+
reenter: !0
|
|
2442
|
+
}, {
|
|
2443
|
+
target: "idle",
|
|
2444
|
+
actions: ["clear pending value", "assign previous value", "emit done syncing"]
|
|
2445
|
+
}]
|
|
2222
2446
|
}
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
}), debug$i = debugWithName("hook:useSyncValue");
|
|
2450
|
+
function updateValue({
|
|
2451
|
+
context,
|
|
2452
|
+
sendBack,
|
|
2453
|
+
slateEditor,
|
|
2454
|
+
value
|
|
2455
|
+
}) {
|
|
2456
|
+
let isChanged = !1, isValid = !0;
|
|
2457
|
+
const hadSelection = !!slateEditor.selection;
|
|
2458
|
+
if ((!value || value.length === 0) && (debug$i("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
2459
|
+
withoutSaving(slateEditor, () => {
|
|
2460
|
+
withoutPatching(slateEditor, () => {
|
|
2461
|
+
hadSelection && slate.Transforms.deselect(slateEditor);
|
|
2462
|
+
const childrenLength = slateEditor.children.length;
|
|
2463
|
+
slateEditor.children.forEach((_, index) => {
|
|
2464
|
+
slate.Transforms.removeNodes(slateEditor, {
|
|
2465
|
+
at: [childrenLength - 1 - index]
|
|
2239
2466
|
});
|
|
2240
|
-
})
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
});
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
const oldBlock = slateEditor.children[currentBlockIndex];
|
|
2260
|
-
if (oldBlock && !isEqual__default.default(currentBlock, oldBlock) && isValid) {
|
|
2261
|
-
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
2262
|
-
!validation.valid && (_a = validation.resolution) != null && _a.autoResolve && ((_b = validation.resolution) == null ? void 0 : _b.patches.length) > 0 && !readOnly && previousValue.current && previousValue.current !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${(_c = validation.resolution) == null ? void 0 : _c.description}`), validation.resolution.patches.forEach((patch) => {
|
|
2263
|
-
editorActor.send({
|
|
2264
|
-
type: "patch",
|
|
2265
|
-
patch
|
|
2266
|
-
});
|
|
2267
|
-
})), validation.valid || (_d = validation.resolution) != null && _d.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)), isChanged = !0) : (editorActor.send({
|
|
2268
|
-
type: "invalid value",
|
|
2269
|
-
resolution: validation.resolution,
|
|
2270
|
-
value
|
|
2271
|
-
}), isValid = !1);
|
|
2272
|
-
}
|
|
2273
|
-
if (!oldBlock && isValid) {
|
|
2274
|
-
const validationValue_0 = [value[currentBlockIndex]], validation_0 = validateValue(validationValue_0, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
2275
|
-
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation_0.valid || (_e = validation_0.resolution) != null && _e.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2276
|
-
at: [currentBlockIndex]
|
|
2277
|
-
}) : (debug$i("Invalid", validation_0), editorActor.send({
|
|
2278
|
-
type: "invalid value",
|
|
2279
|
-
resolution: validation_0.resolution,
|
|
2280
|
-
value
|
|
2281
|
-
}), isValid = !1);
|
|
2282
|
-
}
|
|
2283
|
-
});
|
|
2467
|
+
}), slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
2468
|
+
decorators: []
|
|
2469
|
+
}), {
|
|
2470
|
+
at: [0]
|
|
2471
|
+
}), hadSelection && slate.Transforms.select(slateEditor, [0, 0]);
|
|
2472
|
+
});
|
|
2473
|
+
});
|
|
2474
|
+
}), isChanged = !0), value && value.length > 0) {
|
|
2475
|
+
const slateValueFromProps = toSlateValue(value, {
|
|
2476
|
+
schemaTypes: context.schema
|
|
2477
|
+
});
|
|
2478
|
+
slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
2479
|
+
withRemoteChanges(slateEditor, () => {
|
|
2480
|
+
withoutPatching(slateEditor, () => {
|
|
2481
|
+
const childrenLength = slateEditor.children.length;
|
|
2482
|
+
if (slateValueFromProps.length < childrenLength) {
|
|
2483
|
+
for (let i = childrenLength - 1; i > slateValueFromProps.length - 1; i--)
|
|
2484
|
+
slate.Transforms.removeNodes(slateEditor, {
|
|
2485
|
+
at: [i]
|
|
2284
2486
|
});
|
|
2487
|
+
isChanged = !0;
|
|
2488
|
+
}
|
|
2489
|
+
for (const [currentBlockIndex, currentBlock] of slateValueFromProps.entries()) {
|
|
2490
|
+
const {
|
|
2491
|
+
blockChanged,
|
|
2492
|
+
blockValid
|
|
2493
|
+
} = syncBlock({
|
|
2494
|
+
context,
|
|
2495
|
+
sendBack,
|
|
2496
|
+
block: currentBlock,
|
|
2497
|
+
index: currentBlockIndex,
|
|
2498
|
+
slateEditor,
|
|
2499
|
+
value
|
|
2285
2500
|
});
|
|
2286
|
-
|
|
2287
|
-
});
|
|
2288
|
-
}
|
|
2289
|
-
if (!isValid) {
|
|
2290
|
-
debug$i("Invalid value, returning");
|
|
2291
|
-
return;
|
|
2292
|
-
}
|
|
2293
|
-
if (isChanged) {
|
|
2294
|
-
debug$i("Server value changed, syncing editor");
|
|
2295
|
-
try {
|
|
2296
|
-
slateEditor.onChange();
|
|
2297
|
-
} catch (err) {
|
|
2298
|
-
console.error(err), editorActor.send({
|
|
2299
|
-
type: "invalid value",
|
|
2300
|
-
resolution: null,
|
|
2301
|
-
value
|
|
2302
|
-
});
|
|
2303
|
-
return;
|
|
2304
|
-
}
|
|
2305
|
-
hadSelection && !slateEditor.selection && (slate.Transforms.select(slateEditor, {
|
|
2306
|
-
anchor: {
|
|
2307
|
-
path: [0, 0],
|
|
2308
|
-
offset: 0
|
|
2309
|
-
},
|
|
2310
|
-
focus: {
|
|
2311
|
-
path: [0, 0],
|
|
2312
|
-
offset: 0
|
|
2501
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2313
2502
|
}
|
|
2314
|
-
}), slateEditor.onChange()), editorActor.send({
|
|
2315
|
-
type: "value changed",
|
|
2316
|
-
value
|
|
2317
2503
|
});
|
|
2318
|
-
}
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2504
|
+
});
|
|
2505
|
+
});
|
|
2506
|
+
}
|
|
2507
|
+
if (!isValid) {
|
|
2508
|
+
debug$i("Invalid value, returning"), sendBack({
|
|
2509
|
+
type: "done syncing",
|
|
2510
|
+
value
|
|
2511
|
+
});
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
if (isChanged) {
|
|
2515
|
+
debug$i("Server value changed, syncing editor");
|
|
2516
|
+
try {
|
|
2517
|
+
slateEditor.onChange();
|
|
2518
|
+
} catch (err) {
|
|
2519
|
+
console.error(err), sendBack({
|
|
2520
|
+
type: "invalid value",
|
|
2521
|
+
resolution: null,
|
|
2522
|
+
value
|
|
2523
|
+
}), sendBack({
|
|
2524
|
+
type: "done syncing",
|
|
2525
|
+
value
|
|
2526
|
+
});
|
|
2527
|
+
return;
|
|
2528
|
+
}
|
|
2529
|
+
hadSelection && !slateEditor.selection && (slate.Transforms.select(slateEditor, {
|
|
2530
|
+
anchor: {
|
|
2531
|
+
path: [0, 0],
|
|
2532
|
+
offset: 0
|
|
2533
|
+
},
|
|
2534
|
+
focus: {
|
|
2535
|
+
path: [0, 0],
|
|
2536
|
+
offset: 0
|
|
2537
|
+
}
|
|
2538
|
+
}), slateEditor.onChange()), sendBack({
|
|
2539
|
+
type: "value changed",
|
|
2540
|
+
value
|
|
2541
|
+
});
|
|
2542
|
+
} else
|
|
2543
|
+
debug$i("Server value and editor value is equal, no need to sync.");
|
|
2544
|
+
sendBack({
|
|
2545
|
+
type: "done syncing",
|
|
2546
|
+
value
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
function syncBlock({
|
|
2550
|
+
context,
|
|
2551
|
+
sendBack,
|
|
2552
|
+
block,
|
|
2553
|
+
index,
|
|
2554
|
+
slateEditor,
|
|
2555
|
+
value
|
|
2556
|
+
}) {
|
|
2557
|
+
var _a, _b, _c, _d, _e;
|
|
2558
|
+
let blockChanged = !1, blockValid = !0;
|
|
2559
|
+
const currentBlock = block, currentBlockIndex = index, oldBlock = slateEditor.children[currentBlockIndex];
|
|
2560
|
+
if (oldBlock && !isEqual__default.default(currentBlock, oldBlock) && blockValid) {
|
|
2561
|
+
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2562
|
+
!validation.valid && (_a = validation.resolution) != null && _a.autoResolve && ((_b = validation.resolution) == null ? void 0 : _b.patches.length) > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${(_c = validation.resolution) == null ? void 0 : _c.description}`), validation.resolution.patches.forEach((patch) => {
|
|
2563
|
+
sendBack({
|
|
2564
|
+
type: "patch",
|
|
2565
|
+
patch
|
|
2566
|
+
});
|
|
2567
|
+
})), validation.valid || (_d = validation.resolution) != null && _d.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({
|
|
2568
|
+
type: "invalid value",
|
|
2569
|
+
resolution: validation.resolution,
|
|
2570
|
+
value
|
|
2571
|
+
}), blockValid = !1);
|
|
2572
|
+
}
|
|
2573
|
+
if (!oldBlock && blockValid) {
|
|
2574
|
+
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2575
|
+
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid || (_e = validation.resolution) != null && _e.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2576
|
+
at: [currentBlockIndex]
|
|
2577
|
+
}) : (debug$i("Invalid", validation), sendBack({
|
|
2578
|
+
type: "invalid value",
|
|
2579
|
+
resolution: validation.resolution,
|
|
2580
|
+
value
|
|
2581
|
+
}), blockValid = !1);
|
|
2582
|
+
}
|
|
2583
|
+
return {
|
|
2584
|
+
blockChanged,
|
|
2585
|
+
blockValid
|
|
2586
|
+
};
|
|
2324
2587
|
}
|
|
2325
2588
|
function _replaceBlock(slateEditor, currentBlock, currentBlockIndex) {
|
|
2326
2589
|
const currentSelection = slateEditor.selection, selectionFocusOnBlock = currentSelection && currentSelection.focus.path[0] === currentBlockIndex;
|
|
@@ -2377,89 +2640,105 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2377
2640
|
});
|
|
2378
2641
|
}
|
|
2379
2642
|
}
|
|
2380
|
-
const debug$h = debugWithName("component:PortableTextEditor:Synchronizer")
|
|
2643
|
+
const debug$h = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
2381
2644
|
function Synchronizer(props) {
|
|
2382
|
-
const $ = reactCompilerRuntime.c(
|
|
2645
|
+
const $ = reactCompilerRuntime.c(40), {
|
|
2383
2646
|
editorActor,
|
|
2384
|
-
getValue: getValue2,
|
|
2385
|
-
portableTextEditor,
|
|
2386
2647
|
slateEditor
|
|
2387
|
-
} = props;
|
|
2648
|
+
} = props, value = react.useSelector(props.editorActor, _temp), readOnly = react.useSelector(props.editorActor, _temp2);
|
|
2388
2649
|
let t0;
|
|
2389
|
-
$[0]
|
|
2390
|
-
const
|
|
2391
|
-
let
|
|
2392
|
-
$[
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
}, $[1] = editorActor, $[2] = portableTextEditor, $[3] = readOnly, $[4] = slateEditor, $[5] = t1) : t1 = $[5];
|
|
2398
|
-
const syncValue = useSyncValue(t1);
|
|
2399
|
-
let t2, t3;
|
|
2400
|
-
$[6] !== slateEditor ? (t2 = () => {
|
|
2401
|
-
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
|
|
2402
|
-
}, t3 = [slateEditor], $[6] = slateEditor, $[7] = t2, $[8] = t3) : (t2 = $[7], t3 = $[8]), React.useEffect(t2, t3);
|
|
2650
|
+
$[0] !== props.editorActor ? (t0 = props.editorActor.getSnapshot(), $[0] = props.editorActor, $[1] = t0) : t0 = $[1];
|
|
2651
|
+
const t1 = t0.context.keyGenerator;
|
|
2652
|
+
let t2;
|
|
2653
|
+
$[2] !== props.editorActor ? (t2 = props.editorActor.getSnapshot().matches({
|
|
2654
|
+
"edit mode": "read only"
|
|
2655
|
+
}), $[2] = props.editorActor, $[3] = t2) : t2 = $[3];
|
|
2656
|
+
let t3;
|
|
2657
|
+
$[4] !== props.editorActor ? (t3 = props.editorActor.getSnapshot(), $[4] = props.editorActor, $[5] = t3) : t3 = $[5];
|
|
2403
2658
|
let t4;
|
|
2404
|
-
$[
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
type: "mutation",
|
|
2411
|
-
patches: pendingPatches.current,
|
|
2412
|
-
snapshot
|
|
2413
|
-
}), pendingPatches.current = [];
|
|
2659
|
+
$[6] !== slateEditor || $[7] !== t0.context.keyGenerator || $[8] !== t2 || $[9] !== t3.context.schema ? (t4 = {
|
|
2660
|
+
input: {
|
|
2661
|
+
keyGenerator: t1,
|
|
2662
|
+
readOnly: t2,
|
|
2663
|
+
schema: t3.context.schema,
|
|
2664
|
+
slateEditor
|
|
2414
2665
|
}
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2666
|
+
}, $[6] = slateEditor, $[7] = t0.context.keyGenerator, $[8] = t2, $[9] = t3.context.schema, $[10] = t4) : t4 = $[10];
|
|
2667
|
+
const syncActorRef = react.useActorRef(syncMachine, t4);
|
|
2668
|
+
let t5;
|
|
2669
|
+
$[11] !== editorActor ? (t5 = editorActor.getSnapshot(), $[11] = editorActor, $[12] = t5) : t5 = $[12];
|
|
2670
|
+
let t6;
|
|
2671
|
+
$[13] !== slateEditor || $[14] !== t5.context.schema ? (t6 = {
|
|
2672
|
+
input: {
|
|
2673
|
+
schema: t5.context.schema,
|
|
2674
|
+
slateEditor
|
|
2675
|
+
}
|
|
2676
|
+
}, $[13] = slateEditor, $[14] = t5.context.schema, $[15] = t6) : t6 = $[15];
|
|
2677
|
+
const mutationActorRef = react.useActorRef(mutationMachine, t6);
|
|
2422
2678
|
let t7, t8;
|
|
2423
|
-
$[16] !== editorActor || $[17] !==
|
|
2424
|
-
const
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
}, FLUSH_PATCHES_THROTTLED_MS, {
|
|
2431
|
-
leading: !1,
|
|
2432
|
-
trailing: !0
|
|
2679
|
+
$[16] !== editorActor || $[17] !== mutationActorRef || $[18] !== syncActorRef ? (t7 = () => {
|
|
2680
|
+
const subscription = mutationActorRef.on("*", (event) => {
|
|
2681
|
+
event.type === "has pending patches" && syncActorRef.send({
|
|
2682
|
+
type: "has pending patches"
|
|
2683
|
+
}), event.type === "mutation" && (syncActorRef.send({
|
|
2684
|
+
type: "mutation"
|
|
2685
|
+
}), editorActor.send(event));
|
|
2433
2686
|
});
|
|
2687
|
+
return () => {
|
|
2688
|
+
subscription.unsubscribe();
|
|
2689
|
+
};
|
|
2690
|
+
}, t8 = [mutationActorRef, syncActorRef, editorActor], $[16] = editorActor, $[17] = mutationActorRef, $[18] = syncActorRef, $[19] = t7, $[20] = t8) : (t7 = $[19], t8 = $[20]), React.useEffect(t7, t8);
|
|
2691
|
+
let t10, t9;
|
|
2692
|
+
$[21] !== props.editorActor || $[22] !== syncActorRef ? (t9 = () => {
|
|
2693
|
+
const subscription_0 = syncActorRef.on("*", (event_0) => {
|
|
2694
|
+
props.editorActor.send(event_0);
|
|
2695
|
+
});
|
|
2696
|
+
return () => {
|
|
2697
|
+
subscription_0.unsubscribe();
|
|
2698
|
+
};
|
|
2699
|
+
}, t10 = [props.editorActor, syncActorRef], $[21] = props.editorActor, $[22] = syncActorRef, $[23] = t10, $[24] = t9) : (t10 = $[23], t9 = $[24]), React.useEffect(t9, t10);
|
|
2700
|
+
let t11, t12;
|
|
2701
|
+
$[25] !== readOnly || $[26] !== syncActorRef ? (t11 = () => {
|
|
2702
|
+
syncActorRef.send({
|
|
2703
|
+
type: "update readOnly",
|
|
2704
|
+
readOnly
|
|
2705
|
+
});
|
|
2706
|
+
}, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), React.useEffect(t11, t12);
|
|
2707
|
+
let t13, t14;
|
|
2708
|
+
$[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
|
|
2709
|
+
debug$h("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2710
|
+
type: "update value",
|
|
2711
|
+
value
|
|
2712
|
+
});
|
|
2713
|
+
}, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), React.useEffect(t13, t14);
|
|
2714
|
+
let t15;
|
|
2715
|
+
$[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
|
|
2434
2716
|
debug$h("Subscribing to patch events");
|
|
2435
|
-
const sub = editorActor.on("patch", (
|
|
2436
|
-
|
|
2717
|
+
const sub = editorActor.on("patch", (event_1) => {
|
|
2718
|
+
mutationActorRef.send(event_1);
|
|
2437
2719
|
});
|
|
2438
2720
|
return () => {
|
|
2439
2721
|
debug$h("Unsubscribing to patch events"), sub.unsubscribe();
|
|
2440
2722
|
};
|
|
2441
|
-
},
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
return $[21] !== editorActor || $[22] !== syncValue || $[23] !== value ? (t9 = () => {
|
|
2445
|
-
debug$h("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (editorActor.send({
|
|
2446
|
-
type: "ready"
|
|
2447
|
-
}), isInitialValueFromProps.current = !1);
|
|
2448
|
-
}, t10 = [editorActor, syncValue, value], $[21] = editorActor, $[22] = syncValue, $[23] = value, $[24] = t10, $[25] = t9) : (t10 = $[24], t9 = $[25]), React.useEffect(t9, t10), null;
|
|
2723
|
+
}, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
|
|
2724
|
+
let t16;
|
|
2725
|
+
return $[36] !== editorActor || $[37] !== mutationActorRef || $[38] !== slateEditor ? (t16 = [editorActor, mutationActorRef, slateEditor], $[36] = editorActor, $[37] = mutationActorRef, $[38] = slateEditor, $[39] = t16) : t16 = $[39], React.useEffect(t15, t16), null;
|
|
2449
2726
|
}
|
|
2450
2727
|
function _temp2(s_0) {
|
|
2451
|
-
return s_0.
|
|
2728
|
+
return s_0.matches({
|
|
2729
|
+
"edit mode": "read only"
|
|
2730
|
+
});
|
|
2452
2731
|
}
|
|
2453
2732
|
function _temp(s) {
|
|
2454
|
-
return s.context.
|
|
2733
|
+
return s.context.value;
|
|
2455
2734
|
}
|
|
2456
2735
|
Synchronizer.displayName = "Synchronizer";
|
|
2457
|
-
var __defProp$
|
|
2736
|
+
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) => {
|
|
2458
2737
|
for (var prop in b || (b = {}))
|
|
2459
|
-
__hasOwnProp$
|
|
2460
|
-
if (__getOwnPropSymbols$
|
|
2461
|
-
for (var prop of __getOwnPropSymbols$
|
|
2462
|
-
__propIsEnum$
|
|
2738
|
+
__hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2739
|
+
if (__getOwnPropSymbols$l)
|
|
2740
|
+
for (var prop of __getOwnPropSymbols$l(b))
|
|
2741
|
+
__propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2463
2742
|
return a;
|
|
2464
2743
|
}, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
|
|
2465
2744
|
const debug$g = debugWithName("operationToPatches");
|
|
@@ -2501,7 +2780,7 @@ function createOperationToPatches(types2) {
|
|
|
2501
2780
|
const block = editor.children[operation.path[0]];
|
|
2502
2781
|
if (typeof block._key != "string")
|
|
2503
2782
|
throw new Error("Expected block to have a _key");
|
|
2504
|
-
const setNode = omitBy__default.default(__spreadValues$
|
|
2783
|
+
const setNode = omitBy__default.default(__spreadValues$l(__spreadValues$l({}, editor.children[operation.path[0]]), operation.newProperties), isUndefined__default.default);
|
|
2505
2784
|
return [patches.set(fromSlateValue([setNode], textBlockName)[0], [{
|
|
2506
2785
|
_key: block._key
|
|
2507
2786
|
}])];
|
|
@@ -2541,7 +2820,7 @@ function createOperationToPatches(types2) {
|
|
|
2541
2820
|
_key: targetKey
|
|
2542
2821
|
}])] : [patches.setIfMissing(beforeValue, []), patches.insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
|
|
2543
2822
|
} else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
|
|
2544
|
-
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = __spreadValues$
|
|
2823
|
+
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = __spreadValues$l({}, operation.node);
|
|
2545
2824
|
!node._type && slate.Text.isText(node) && (node._type = "span", node.marks = []);
|
|
2546
2825
|
const child = fromSlateValue([{
|
|
2547
2826
|
_key: "bogus",
|
|
@@ -2580,7 +2859,7 @@ function createOperationToPatches(types2) {
|
|
|
2580
2859
|
if (operation.path.length === 2) {
|
|
2581
2860
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
2582
2861
|
if (editor.isTextSpan(splitSpan)) {
|
|
2583
|
-
const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$
|
|
2862
|
+
const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$l({}, splitBlock), {
|
|
2584
2863
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
2585
2864
|
})], textBlockName)[0].children;
|
|
2586
2865
|
patches$1.push(patches.insert(targetSpans, "after", [{
|
|
@@ -2891,7 +3170,9 @@ function createWithMaxBlocks(editorActor) {
|
|
|
2891
3170
|
} = editor;
|
|
2892
3171
|
return editor.apply = (operation) => {
|
|
2893
3172
|
var _a;
|
|
2894
|
-
if (editorActor.getSnapshot().
|
|
3173
|
+
if (editorActor.getSnapshot().matches({
|
|
3174
|
+
"edit mode": "read only"
|
|
3175
|
+
})) {
|
|
2895
3176
|
apply2(operation);
|
|
2896
3177
|
return;
|
|
2897
3178
|
}
|
|
@@ -2908,12 +3189,12 @@ function createWithMaxBlocks(editorActor) {
|
|
|
2908
3189
|
}, editor;
|
|
2909
3190
|
};
|
|
2910
3191
|
}
|
|
2911
|
-
var __defProp$
|
|
3192
|
+
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) => {
|
|
2912
3193
|
for (var prop in b || (b = {}))
|
|
2913
|
-
__hasOwnProp$
|
|
2914
|
-
if (__getOwnPropSymbols$
|
|
2915
|
-
for (var prop of __getOwnPropSymbols$
|
|
2916
|
-
__propIsEnum$
|
|
3194
|
+
__hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3195
|
+
if (__getOwnPropSymbols$k)
|
|
3196
|
+
for (var prop of __getOwnPropSymbols$k(b))
|
|
3197
|
+
__propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
2917
3198
|
return a;
|
|
2918
3199
|
}, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
2919
3200
|
function createWithObjectKeys(editorActor, schemaTypes) {
|
|
@@ -2932,16 +3213,16 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
2932
3213
|
return;
|
|
2933
3214
|
}
|
|
2934
3215
|
if (operation.type === "split_node") {
|
|
2935
|
-
apply2(__spreadProps$e(__spreadValues$
|
|
2936
|
-
properties: __spreadProps$e(__spreadValues$
|
|
3216
|
+
apply2(__spreadProps$e(__spreadValues$k({}, operation), {
|
|
3217
|
+
properties: __spreadProps$e(__spreadValues$k({}, operation.properties), {
|
|
2937
3218
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
2938
3219
|
})
|
|
2939
3220
|
}));
|
|
2940
3221
|
return;
|
|
2941
3222
|
}
|
|
2942
3223
|
if (operation.type === "insert_node" && !slate.Editor.isEditor(operation.node)) {
|
|
2943
|
-
apply2(__spreadProps$e(__spreadValues$
|
|
2944
|
-
node: __spreadProps$e(__spreadValues$
|
|
3224
|
+
apply2(__spreadProps$e(__spreadValues$k({}, operation), {
|
|
3225
|
+
node: __spreadProps$e(__spreadValues$k({}, operation.node), {
|
|
2945
3226
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
2946
3227
|
})
|
|
2947
3228
|
}));
|
|
@@ -2981,20 +3262,20 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
2981
3262
|
}, editor;
|
|
2982
3263
|
};
|
|
2983
3264
|
}
|
|
2984
|
-
var __defProp$
|
|
3265
|
+
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) => {
|
|
2985
3266
|
for (var prop in b || (b = {}))
|
|
2986
|
-
__hasOwnProp$
|
|
2987
|
-
if (__getOwnPropSymbols$
|
|
2988
|
-
for (var prop of __getOwnPropSymbols$
|
|
2989
|
-
__propIsEnum$
|
|
3267
|
+
__hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3268
|
+
if (__getOwnPropSymbols$j)
|
|
3269
|
+
for (var prop of __getOwnPropSymbols$j(b))
|
|
3270
|
+
__propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
2990
3271
|
return a;
|
|
2991
3272
|
}, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
|
|
2992
3273
|
var target = {};
|
|
2993
3274
|
for (var prop in source)
|
|
2994
|
-
__hasOwnProp$
|
|
2995
|
-
if (source != null && __getOwnPropSymbols$
|
|
2996
|
-
for (var prop of __getOwnPropSymbols$
|
|
2997
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$
|
|
3275
|
+
__hasOwnProp$j.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
3276
|
+
if (source != null && __getOwnPropSymbols$j)
|
|
3277
|
+
for (var prop of __getOwnPropSymbols$j(source))
|
|
3278
|
+
exclude.indexOf(prop) < 0 && __propIsEnum$j.call(source, prop) && (target[prop] = source[prop]);
|
|
2998
3279
|
return target;
|
|
2999
3280
|
};
|
|
3000
3281
|
const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
|
|
@@ -3086,7 +3367,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3086
3367
|
} = patch;
|
|
3087
3368
|
if (!targetChild || !targetChildPath)
|
|
3088
3369
|
return debug$f("Child not found"), !1;
|
|
3089
|
-
const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$
|
|
3370
|
+
const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$j({}, targetBlock), {
|
|
3090
3371
|
children: items
|
|
3091
3372
|
})], {
|
|
3092
3373
|
schemaTypes
|
|
@@ -3145,7 +3426,7 @@ function setPatch(editor, patch) {
|
|
|
3145
3426
|
editor.apply({
|
|
3146
3427
|
type: "set_node",
|
|
3147
3428
|
path: blockPath,
|
|
3148
|
-
properties: __spreadValues$
|
|
3429
|
+
properties: __spreadValues$j({}, prevRest),
|
|
3149
3430
|
newProperties: nextRest
|
|
3150
3431
|
}), debug$f("Setting children"), block.children.forEach((c, cIndex) => {
|
|
3151
3432
|
editor.apply({
|
|
@@ -3162,7 +3443,7 @@ function setPatch(editor, patch) {
|
|
|
3162
3443
|
});
|
|
3163
3444
|
} else if (block && "value" in block) {
|
|
3164
3445
|
const newVal = patches.applyAll([block.value], [patch])[0];
|
|
3165
|
-
return slate.Transforms.setNodes(editor, __spreadProps$d(__spreadValues$
|
|
3446
|
+
return slate.Transforms.setNodes(editor, __spreadProps$d(__spreadValues$j({}, block), {
|
|
3166
3447
|
value: newVal
|
|
3167
3448
|
}), {
|
|
3168
3449
|
at: blockPath
|
|
@@ -3255,12 +3536,12 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3255
3536
|
childPath: void 0
|
|
3256
3537
|
};
|
|
3257
3538
|
}
|
|
3258
|
-
var __defProp$
|
|
3539
|
+
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) => {
|
|
3259
3540
|
for (var prop in b || (b = {}))
|
|
3260
|
-
__hasOwnProp$
|
|
3261
|
-
if (__getOwnPropSymbols$
|
|
3262
|
-
for (var prop of __getOwnPropSymbols$
|
|
3263
|
-
__propIsEnum$
|
|
3541
|
+
__hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3542
|
+
if (__getOwnPropSymbols$i)
|
|
3543
|
+
for (var prop of __getOwnPropSymbols$i(b))
|
|
3544
|
+
__propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3264
3545
|
return a;
|
|
3265
3546
|
}, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
3266
3547
|
const debug$e = debugWithName("plugin:withPatches");
|
|
@@ -3308,8 +3589,6 @@ function createWithPatches({
|
|
|
3308
3589
|
debug$e("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
3309
3590
|
};
|
|
3310
3591
|
}), editor.apply = (operation) => {
|
|
3311
|
-
if (editorActor.getSnapshot().context.readOnly)
|
|
3312
|
-
return apply2(operation), editor;
|
|
3313
3592
|
let patches$1 = [];
|
|
3314
3593
|
previousChildren = editor.children;
|
|
3315
3594
|
const editorWasEmpty = isEqualToEmptyEditor(previousChildren, schemaTypes);
|
|
@@ -3349,7 +3628,7 @@ function createWithPatches({
|
|
|
3349
3628
|
})), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0 && patches$1.forEach((patch) => {
|
|
3350
3629
|
editorActor.send({
|
|
3351
3630
|
type: "patch",
|
|
3352
|
-
patch: __spreadProps$c(__spreadValues$
|
|
3631
|
+
patch: __spreadProps$c(__spreadValues$i({}, patch), {
|
|
3353
3632
|
origin: "local"
|
|
3354
3633
|
})
|
|
3355
3634
|
});
|
|
@@ -3364,7 +3643,9 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3364
3643
|
apply: apply2
|
|
3365
3644
|
} = editor;
|
|
3366
3645
|
return editor.apply = (op) => {
|
|
3367
|
-
if (editorActor.getSnapshot().
|
|
3646
|
+
if (editorActor.getSnapshot().matches({
|
|
3647
|
+
"edit mode": "read only"
|
|
3648
|
+
})) {
|
|
3368
3649
|
apply2(op);
|
|
3369
3650
|
return;
|
|
3370
3651
|
}
|
|
@@ -3462,12 +3743,12 @@ function getNextSpan({
|
|
|
3462
3743
|
}
|
|
3463
3744
|
return nextSpan;
|
|
3464
3745
|
}
|
|
3465
|
-
var __defProp$
|
|
3746
|
+
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) => {
|
|
3466
3747
|
for (var prop in b || (b = {}))
|
|
3467
|
-
__hasOwnProp$
|
|
3468
|
-
if (__getOwnPropSymbols$
|
|
3469
|
-
for (var prop of __getOwnPropSymbols$
|
|
3470
|
-
__propIsEnum$
|
|
3748
|
+
__hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3749
|
+
if (__getOwnPropSymbols$h)
|
|
3750
|
+
for (var prop of __getOwnPropSymbols$h(b))
|
|
3751
|
+
__propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3471
3752
|
return a;
|
|
3472
3753
|
}, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
|
|
3473
3754
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
@@ -3669,21 +3950,21 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3669
3950
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
3670
3951
|
}), nextSpanAnnotations = nextSpan ? (_d = nextSpan.marks) == null ? void 0 : _d.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = (_e = previousSpanAnnotations == null ? void 0 : previousSpanAnnotations.filter((annotation) => !(nextSpanAnnotations != null && nextSpanAnnotations.includes(annotation)))) != null ? _e : [], atTheEndOfAnnotation = annotationsEnding.length > 0;
|
|
3671
3952
|
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && (_f = op.node.marks) != null && _f.some((mark) => annotationsEnding.includes(mark))) {
|
|
3672
|
-
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$
|
|
3953
|
+
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
|
|
3673
3954
|
marks: (_h = (_g = op.node.marks) == null ? void 0 : _g.filter((mark) => !annotationsEnding.includes(mark))) != null ? _h : []
|
|
3674
3955
|
}));
|
|
3675
3956
|
return;
|
|
3676
3957
|
}
|
|
3677
3958
|
const annotationsStarting = (_i = nextSpanAnnotations == null ? void 0 : nextSpanAnnotations.filter((annotation) => !(previousSpanAnnotations != null && previousSpanAnnotations.includes(annotation)))) != null ? _i : [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3678
3959
|
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && (_j = op.node.marks) != null && _j.some((mark) => annotationsStarting.includes(mark))) {
|
|
3679
|
-
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$
|
|
3960
|
+
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
|
|
3680
3961
|
marks: (_l = (_k = op.node.marks) == null ? void 0 : _k.filter((mark) => !annotationsStarting.includes(mark))) != null ? _l : []
|
|
3681
3962
|
}));
|
|
3682
3963
|
return;
|
|
3683
3964
|
}
|
|
3684
3965
|
const nextSpanDecorators = (_n = (_m = nextSpan == null ? void 0 : nextSpan.marks) == null ? void 0 : _m.filter((mark) => decorators.includes(mark))) != null ? _n : [];
|
|
3685
3966
|
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && ((_o = op.node.marks) == null ? void 0 : _o.length) === 0) {
|
|
3686
|
-
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$
|
|
3967
|
+
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
|
|
3687
3968
|
marks: nextSpanDecorators
|
|
3688
3969
|
}));
|
|
3689
3970
|
return;
|
|
@@ -3801,7 +4082,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3801
4082
|
spanPath
|
|
3802
4083
|
}), previousSpanHasSameAnnotation = previousSpan ? (_E = previousSpan.marks) == null ? void 0 : _E.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? (_F = nextSpan.marks) == null ? void 0 : _F.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
|
|
3803
4084
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
3804
|
-
const marksWithoutAnnotationMarks = (__spreadValues$
|
|
4085
|
+
const marksWithoutAnnotationMarks = (__spreadValues$h({}, slate.Editor.marks(editor) || {}).marks || []).filter((mark) => decorators.includes(mark));
|
|
3805
4086
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
3806
4087
|
apply2(op), slate.Transforms.setNodes(editor, {
|
|
3807
4088
|
marks: marksWithoutAnnotationMarks
|
|
@@ -3874,7 +4155,7 @@ const addDecoratorActionImplementation = ({
|
|
|
3874
4155
|
match: (node) => editor.isTextSpan(node)
|
|
3875
4156
|
});
|
|
3876
4157
|
} else {
|
|
3877
|
-
const existingMarks = __spreadValues$
|
|
4158
|
+
const existingMarks = __spreadValues$h({}, slate.Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$h({}, slate.Editor.marks(editor) || {}), {
|
|
3878
4159
|
marks: [...existingMarks, mark]
|
|
3879
4160
|
});
|
|
3880
4161
|
editor.marks = marks;
|
|
@@ -3920,7 +4201,7 @@ const addDecoratorActionImplementation = ({
|
|
|
3920
4201
|
match: (node) => editor.isTextSpan(node)
|
|
3921
4202
|
});
|
|
3922
4203
|
} else {
|
|
3923
|
-
const existingMarks = __spreadValues$
|
|
4204
|
+
const existingMarks = __spreadValues$h({}, slate.Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$h({}, slate.Editor.marks(editor) || {}), {
|
|
3924
4205
|
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
3925
4206
|
});
|
|
3926
4207
|
editor.marks = {
|
|
@@ -3944,7 +4225,7 @@ function isDecoratorActive({
|
|
|
3944
4225
|
var _a;
|
|
3945
4226
|
const [node] = n;
|
|
3946
4227
|
return (_a = node.marks) == null ? void 0 : _a.includes(decorator);
|
|
3947
|
-
}) : (__spreadValues$
|
|
4228
|
+
}) : (__spreadValues$h({}, slate.Editor.marks(editor) || {}).marks || []).includes(decorator);
|
|
3948
4229
|
}
|
|
3949
4230
|
const toggleDecoratorActionImplementation = ({
|
|
3950
4231
|
context,
|
|
@@ -3998,16 +4279,18 @@ function createWithPortableTextSelections(editorActor, types2) {
|
|
|
3998
4279
|
} = editor;
|
|
3999
4280
|
return editor.onChange = () => {
|
|
4000
4281
|
const hasChanges = editor.operations.length > 0;
|
|
4001
|
-
onChange(), hasChanges &&
|
|
4282
|
+
onChange(), hasChanges && !editorActor.getSnapshot().matches({
|
|
4283
|
+
setup: "setting up"
|
|
4284
|
+
}) && emitPortableTextSelection();
|
|
4002
4285
|
}, editor;
|
|
4003
4286
|
};
|
|
4004
4287
|
}
|
|
4005
|
-
var __defProp$
|
|
4288
|
+
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) => {
|
|
4006
4289
|
for (var prop in b || (b = {}))
|
|
4007
|
-
__hasOwnProp$
|
|
4008
|
-
if (__getOwnPropSymbols$
|
|
4009
|
-
for (var prop of __getOwnPropSymbols$
|
|
4010
|
-
__propIsEnum$
|
|
4290
|
+
__hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4291
|
+
if (__getOwnPropSymbols$g)
|
|
4292
|
+
for (var prop of __getOwnPropSymbols$g(b))
|
|
4293
|
+
__propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4011
4294
|
return a;
|
|
4012
4295
|
}, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
4013
4296
|
const debug$9 = debugWithName("plugin:withSchemaTypes");
|
|
@@ -4027,7 +4310,7 @@ function createWithSchemaTypes({
|
|
|
4027
4310
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4028
4311
|
editorActor.send({
|
|
4029
4312
|
type: "normalizing"
|
|
4030
|
-
}), slate.Transforms.setNodes(editor, __spreadProps$a(__spreadValues$
|
|
4313
|
+
}), slate.Transforms.setNodes(editor, __spreadProps$a(__spreadValues$g({}, span), {
|
|
4031
4314
|
_type: schemaTypes.span.name,
|
|
4032
4315
|
_key: key
|
|
4033
4316
|
}), {
|
|
@@ -4055,12 +4338,12 @@ function createWithSchemaTypes({
|
|
|
4055
4338
|
}, editor;
|
|
4056
4339
|
};
|
|
4057
4340
|
}
|
|
4058
|
-
var __defProp$
|
|
4341
|
+
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) => {
|
|
4059
4342
|
for (var prop in b || (b = {}))
|
|
4060
|
-
__hasOwnProp$
|
|
4061
|
-
if (__getOwnPropSymbols$
|
|
4062
|
-
for (var prop of __getOwnPropSymbols$
|
|
4063
|
-
__propIsEnum$
|
|
4343
|
+
__hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4344
|
+
if (__getOwnPropSymbols$f)
|
|
4345
|
+
for (var prop of __getOwnPropSymbols$f(b))
|
|
4346
|
+
__propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4064
4347
|
return a;
|
|
4065
4348
|
}, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
4066
4349
|
const debug$8 = debugWithName("plugin:withUtils");
|
|
@@ -4086,10 +4369,10 @@ function createWithUtils({
|
|
|
4086
4369
|
} = 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);
|
|
4087
4370
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4088
4371
|
debug$8("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
|
|
4089
|
-
anchor: __spreadProps$9(__spreadValues$
|
|
4372
|
+
anchor: __spreadProps$9(__spreadValues$f({}, selection.anchor), {
|
|
4090
4373
|
offset: newStartOffset
|
|
4091
4374
|
}),
|
|
4092
|
-
focus: __spreadProps$9(__spreadValues$
|
|
4375
|
+
focus: __spreadProps$9(__spreadValues$f({}, selection.focus), {
|
|
4093
4376
|
offset: newEndOffset
|
|
4094
4377
|
})
|
|
4095
4378
|
});
|
|
@@ -4097,7 +4380,7 @@ function createWithUtils({
|
|
|
4097
4380
|
}
|
|
4098
4381
|
debug$8("pteExpandToWord: Can't expand to word here");
|
|
4099
4382
|
}
|
|
4100
|
-
}, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$
|
|
4383
|
+
}, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$f(__spreadValues$f({
|
|
4101
4384
|
_type: schemaTypes.block.name,
|
|
4102
4385
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4103
4386
|
style: schemaTypes.styles[0].value || "normal"
|
|
@@ -4161,12 +4444,12 @@ function createSlateEditor(config) {
|
|
|
4161
4444
|
};
|
|
4162
4445
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4163
4446
|
}
|
|
4164
|
-
var __defProp$
|
|
4447
|
+
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) => {
|
|
4165
4448
|
for (var prop in b || (b = {}))
|
|
4166
|
-
__hasOwnProp$
|
|
4167
|
-
if (__getOwnPropSymbols$
|
|
4168
|
-
for (var prop of __getOwnPropSymbols$
|
|
4169
|
-
__propIsEnum$
|
|
4449
|
+
__hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4450
|
+
if (__getOwnPropSymbols$e)
|
|
4451
|
+
for (var prop of __getOwnPropSymbols$e(b))
|
|
4452
|
+
__propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4170
4453
|
return a;
|
|
4171
4454
|
}, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
4172
4455
|
const toggleListItemActionImplementation = ({
|
|
@@ -4178,12 +4461,12 @@ const toggleListItemActionImplementation = ({
|
|
|
4178
4461
|
listItem: action.listItem
|
|
4179
4462
|
}) ? removeListItemActionImplementation({
|
|
4180
4463
|
context,
|
|
4181
|
-
action: __spreadProps$8(__spreadValues$
|
|
4464
|
+
action: __spreadProps$8(__spreadValues$e({}, action), {
|
|
4182
4465
|
type: "list item.remove"
|
|
4183
4466
|
})
|
|
4184
4467
|
}) : addListItemActionImplementation({
|
|
4185
4468
|
context,
|
|
4186
|
-
action: __spreadProps$8(__spreadValues$
|
|
4469
|
+
action: __spreadProps$8(__spreadValues$e({}, action), {
|
|
4187
4470
|
type: "list item.add"
|
|
4188
4471
|
})
|
|
4189
4472
|
});
|
|
@@ -4193,7 +4476,7 @@ const toggleListItemActionImplementation = ({
|
|
|
4193
4476
|
}) => {
|
|
4194
4477
|
if (!action.editor.selection)
|
|
4195
4478
|
return;
|
|
4196
|
-
const guards =
|
|
4479
|
+
const guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
4197
4480
|
at: action.editor.selection,
|
|
4198
4481
|
match: (node) => guards.isListBlock(node)
|
|
4199
4482
|
})];
|
|
@@ -4207,7 +4490,7 @@ const toggleListItemActionImplementation = ({
|
|
|
4207
4490
|
}) => {
|
|
4208
4491
|
if (!action.editor.selection)
|
|
4209
4492
|
return;
|
|
4210
|
-
const guards =
|
|
4493
|
+
const guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
4211
4494
|
at: action.editor.selection,
|
|
4212
4495
|
match: (node) => guards.isTextBlock(node)
|
|
4213
4496
|
})];
|
|
@@ -4231,12 +4514,12 @@ function isListItemActive({
|
|
|
4231
4514
|
})];
|
|
4232
4515
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
4233
4516
|
}
|
|
4234
|
-
var __defProp$
|
|
4517
|
+
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) => {
|
|
4235
4518
|
for (var prop in b || (b = {}))
|
|
4236
|
-
__hasOwnProp$
|
|
4237
|
-
if (__getOwnPropSymbols$
|
|
4238
|
-
for (var prop of __getOwnPropSymbols$
|
|
4239
|
-
__propIsEnum$
|
|
4519
|
+
__hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4520
|
+
if (__getOwnPropSymbols$d)
|
|
4521
|
+
for (var prop of __getOwnPropSymbols$d(b))
|
|
4522
|
+
__propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4240
4523
|
return a;
|
|
4241
4524
|
}, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
4242
4525
|
const toggleStyleActionImplementation = ({
|
|
@@ -4248,12 +4531,12 @@ const toggleStyleActionImplementation = ({
|
|
|
4248
4531
|
style: action.style
|
|
4249
4532
|
}) ? removeStyleActionImplementation({
|
|
4250
4533
|
context,
|
|
4251
|
-
action: __spreadProps$7(__spreadValues$
|
|
4534
|
+
action: __spreadProps$7(__spreadValues$d({}, action), {
|
|
4252
4535
|
type: "style.remove"
|
|
4253
4536
|
})
|
|
4254
4537
|
}) : addStyleActionImplementation({
|
|
4255
4538
|
context,
|
|
4256
|
-
action: __spreadProps$7(__spreadValues$
|
|
4539
|
+
action: __spreadProps$7(__spreadValues$d({}, action), {
|
|
4257
4540
|
type: "style.add"
|
|
4258
4541
|
})
|
|
4259
4542
|
});
|
|
@@ -4263,7 +4546,7 @@ const toggleStyleActionImplementation = ({
|
|
|
4263
4546
|
}) => {
|
|
4264
4547
|
if (!action.editor.selection)
|
|
4265
4548
|
return;
|
|
4266
|
-
const defaultStyle = context.schema.styles[0].value, guards =
|
|
4549
|
+
const defaultStyle = context.schema.styles[0].value, guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
4267
4550
|
at: action.editor.selection,
|
|
4268
4551
|
match: (node) => guards.isTextBlock(node)
|
|
4269
4552
|
})];
|
|
@@ -4279,7 +4562,7 @@ const toggleStyleActionImplementation = ({
|
|
|
4279
4562
|
}) => {
|
|
4280
4563
|
if (!action.editor.selection)
|
|
4281
4564
|
return;
|
|
4282
|
-
const guards =
|
|
4565
|
+
const guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
4283
4566
|
at: action.editor.selection,
|
|
4284
4567
|
match: (node) => guards.isTextBlock(node)
|
|
4285
4568
|
})];
|
|
@@ -4302,12 +4585,12 @@ function isStyleActive({
|
|
|
4302
4585
|
})];
|
|
4303
4586
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
4304
4587
|
}
|
|
4305
|
-
var __defProp$
|
|
4588
|
+
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) => {
|
|
4306
4589
|
for (var prop in b || (b = {}))
|
|
4307
|
-
__hasOwnProp$
|
|
4308
|
-
if (__getOwnPropSymbols$
|
|
4309
|
-
for (var prop of __getOwnPropSymbols$
|
|
4310
|
-
__propIsEnum$
|
|
4590
|
+
__hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4591
|
+
if (__getOwnPropSymbols$c)
|
|
4592
|
+
for (var prop of __getOwnPropSymbols$c(b))
|
|
4593
|
+
__propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4311
4594
|
return a;
|
|
4312
4595
|
};
|
|
4313
4596
|
const debug$6 = debugWithName("API:editable");
|
|
@@ -4372,7 +4655,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4372
4655
|
return console.warn(err), !1;
|
|
4373
4656
|
}
|
|
4374
4657
|
},
|
|
4375
|
-
marks: () => __spreadValues$
|
|
4658
|
+
marks: () => __spreadValues$c({}, slate.Editor.marks(editor) || {}).marks || [],
|
|
4376
4659
|
undo: () => editor.undo(),
|
|
4377
4660
|
redo: () => editor.redo(),
|
|
4378
4661
|
select: (selection) => {
|
|
@@ -4420,7 +4703,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4420
4703
|
const child = toSlateValue([{
|
|
4421
4704
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4422
4705
|
_type: types2.block.name,
|
|
4423
|
-
children: [__spreadValues$
|
|
4706
|
+
children: [__spreadValues$c({
|
|
4424
4707
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4425
4708
|
_type: type.name
|
|
4426
4709
|
}, value || {})]
|
|
@@ -4684,7 +4967,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4684
4967
|
continue;
|
|
4685
4968
|
const annotationKey = context.keyGenerator(), markDefs = (_a = block.markDefs) != null ? _a : [];
|
|
4686
4969
|
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (slate.Transforms.setNodes(editor, {
|
|
4687
|
-
markDefs: [...markDefs, __spreadValues$
|
|
4970
|
+
markDefs: [...markDefs, __spreadValues$c({
|
|
4688
4971
|
_type: action.annotation.name,
|
|
4689
4972
|
_key: annotationKey
|
|
4690
4973
|
}, action.annotation.value)]
|
|
@@ -4861,19 +5144,19 @@ function insertBlock({
|
|
|
4861
5144
|
});
|
|
4862
5145
|
}
|
|
4863
5146
|
}
|
|
4864
|
-
var __defProp$
|
|
5147
|
+
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) => {
|
|
4865
5148
|
for (var prop in b || (b = {}))
|
|
4866
|
-
__hasOwnProp$
|
|
4867
|
-
if (__getOwnPropSymbols$
|
|
4868
|
-
for (var prop of __getOwnPropSymbols$
|
|
4869
|
-
__propIsEnum$
|
|
5149
|
+
__hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5150
|
+
if (__getOwnPropSymbols$b)
|
|
5151
|
+
for (var prop of __getOwnPropSymbols$b(b))
|
|
5152
|
+
__propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
4870
5153
|
return a;
|
|
4871
5154
|
};
|
|
4872
5155
|
const insertBlockObjectActionImplementation = ({
|
|
4873
5156
|
context,
|
|
4874
5157
|
action
|
|
4875
5158
|
}) => {
|
|
4876
|
-
const block = toSlateValue([__spreadValues$
|
|
5159
|
+
const block = toSlateValue([__spreadValues$b({
|
|
4877
5160
|
_key: context.keyGenerator(),
|
|
4878
5161
|
_type: action.blockObject.name
|
|
4879
5162
|
}, action.blockObject.value ? action.blockObject.value : {})], {
|
|
@@ -4886,12 +5169,12 @@ const insertBlockObjectActionImplementation = ({
|
|
|
4886
5169
|
schema: context.schema
|
|
4887
5170
|
});
|
|
4888
5171
|
};
|
|
4889
|
-
var __defProp$
|
|
5172
|
+
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) => {
|
|
4890
5173
|
for (var prop in b || (b = {}))
|
|
4891
|
-
__hasOwnProp$
|
|
4892
|
-
if (__getOwnPropSymbols$
|
|
4893
|
-
for (var prop of __getOwnPropSymbols$
|
|
4894
|
-
__propIsEnum$
|
|
5174
|
+
__hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5175
|
+
if (__getOwnPropSymbols$a)
|
|
5176
|
+
for (var prop of __getOwnPropSymbols$a(b))
|
|
5177
|
+
__propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
4895
5178
|
return a;
|
|
4896
5179
|
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
4897
5180
|
const insertBreakActionImplementation = ({
|
|
@@ -4987,7 +5270,7 @@ const insertBreakActionImplementation = ({
|
|
|
4987
5270
|
}
|
|
4988
5271
|
const newMarkDefs = nextNode.markDefs.map((markDef) => {
|
|
4989
5272
|
var _a3;
|
|
4990
|
-
return __spreadProps$6(__spreadValues$
|
|
5273
|
+
return __spreadProps$6(__spreadValues$a({}, markDef), {
|
|
4991
5274
|
_key: (_a3 = newMarkDefKeys.get(markDef._key)) != null ? _a3 : markDef._key
|
|
4992
5275
|
});
|
|
4993
5276
|
});
|
|
@@ -5011,17 +5294,17 @@ const insertBreakActionImplementation = ({
|
|
|
5011
5294
|
}) => {
|
|
5012
5295
|
insertBreakActionImplementation({
|
|
5013
5296
|
context,
|
|
5014
|
-
action: __spreadProps$6(__spreadValues$
|
|
5297
|
+
action: __spreadProps$6(__spreadValues$a({}, action), {
|
|
5015
5298
|
type: "insert.break"
|
|
5016
5299
|
})
|
|
5017
5300
|
});
|
|
5018
5301
|
};
|
|
5019
|
-
var __defProp$
|
|
5302
|
+
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) => {
|
|
5020
5303
|
for (var prop in b || (b = {}))
|
|
5021
|
-
__hasOwnProp$
|
|
5022
|
-
if (__getOwnPropSymbols$
|
|
5023
|
-
for (var prop of __getOwnPropSymbols$
|
|
5024
|
-
__propIsEnum$
|
|
5304
|
+
__hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5305
|
+
if (__getOwnPropSymbols$9)
|
|
5306
|
+
for (var prop of __getOwnPropSymbols$9(b))
|
|
5307
|
+
__propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5025
5308
|
return a;
|
|
5026
5309
|
};
|
|
5027
5310
|
const insertInlineObjectActionImplementation = ({
|
|
@@ -5048,7 +5331,7 @@ const insertInlineObjectActionImplementation = ({
|
|
|
5048
5331
|
const block = toSlateValue([{
|
|
5049
5332
|
_type: context.schema.block.name,
|
|
5050
5333
|
_key: context.keyGenerator(),
|
|
5051
|
-
children: [__spreadValues$
|
|
5334
|
+
children: [__spreadValues$9({
|
|
5052
5335
|
_type: action.inlineObject.name,
|
|
5053
5336
|
_key: context.keyGenerator()
|
|
5054
5337
|
}, (_b = action.inlineObject.value) != null ? _b : {})]
|
|
@@ -5061,12 +5344,12 @@ const insertInlineObjectActionImplementation = ({
|
|
|
5061
5344
|
}
|
|
5062
5345
|
slate.Transforms.insertNodes(action.editor, child);
|
|
5063
5346
|
};
|
|
5064
|
-
var __defProp$
|
|
5347
|
+
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) => {
|
|
5065
5348
|
for (var prop in b || (b = {}))
|
|
5066
|
-
__hasOwnProp$
|
|
5067
|
-
if (__getOwnPropSymbols$
|
|
5068
|
-
for (var prop of __getOwnPropSymbols$
|
|
5069
|
-
__propIsEnum$
|
|
5349
|
+
__hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5350
|
+
if (__getOwnPropSymbols$8)
|
|
5351
|
+
for (var prop of __getOwnPropSymbols$8(b))
|
|
5352
|
+
__propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5070
5353
|
return a;
|
|
5071
5354
|
};
|
|
5072
5355
|
const insertSpanActionImplementation = ({
|
|
@@ -5086,7 +5369,7 @@ const insertSpanActionImplementation = ({
|
|
|
5086
5369
|
console.error("Unable to perform action without focus block", action);
|
|
5087
5370
|
return;
|
|
5088
5371
|
}
|
|
5089
|
-
const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$
|
|
5372
|
+
const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$8({
|
|
5090
5373
|
_type: annotation.name,
|
|
5091
5374
|
_key: context.keyGenerator()
|
|
5092
5375
|
}, annotation.value)) : void 0;
|
|
@@ -5099,12 +5382,12 @@ const insertSpanActionImplementation = ({
|
|
|
5099
5382
|
marks: [...(_c = annotations == null ? void 0 : annotations.map((annotation) => annotation._key)) != null ? _c : [], ...(_d = action.decorators) != null ? _d : []]
|
|
5100
5383
|
});
|
|
5101
5384
|
};
|
|
5102
|
-
var __defProp$
|
|
5385
|
+
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) => {
|
|
5103
5386
|
for (var prop in b || (b = {}))
|
|
5104
|
-
__hasOwnProp$
|
|
5105
|
-
if (__getOwnPropSymbols$
|
|
5106
|
-
for (var prop of __getOwnPropSymbols$
|
|
5107
|
-
__propIsEnum$
|
|
5387
|
+
__hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5388
|
+
if (__getOwnPropSymbols$7)
|
|
5389
|
+
for (var prop of __getOwnPropSymbols$7(b))
|
|
5390
|
+
__propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5108
5391
|
return a;
|
|
5109
5392
|
};
|
|
5110
5393
|
const textBlockSetActionImplementation = ({
|
|
@@ -5120,7 +5403,7 @@ const textBlockSetActionImplementation = ({
|
|
|
5120
5403
|
offset: 0
|
|
5121
5404
|
}
|
|
5122
5405
|
}, action.editor);
|
|
5123
|
-
slate.Transforms.setNodes(action.editor, __spreadValues$
|
|
5406
|
+
slate.Transforms.setNodes(action.editor, __spreadValues$7(__spreadValues$7(__spreadValues$7({}, action.style ? {
|
|
5124
5407
|
style: action.style
|
|
5125
5408
|
} : {}), action.listItem ? {
|
|
5126
5409
|
listItem: action.listItem
|
|
@@ -5146,12 +5429,12 @@ const textBlockSetActionImplementation = ({
|
|
|
5146
5429
|
at
|
|
5147
5430
|
});
|
|
5148
5431
|
};
|
|
5149
|
-
var __defProp$
|
|
5432
|
+
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) => {
|
|
5150
5433
|
for (var prop in b || (b = {}))
|
|
5151
|
-
__hasOwnProp$
|
|
5152
|
-
if (__getOwnPropSymbols$
|
|
5153
|
-
for (var prop of __getOwnPropSymbols$
|
|
5154
|
-
__propIsEnum$
|
|
5434
|
+
__hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5435
|
+
if (__getOwnPropSymbols$6)
|
|
5436
|
+
for (var prop of __getOwnPropSymbols$6(b))
|
|
5437
|
+
__propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5155
5438
|
return a;
|
|
5156
5439
|
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
5157
5440
|
const behaviorActionImplementations = {
|
|
@@ -5249,7 +5532,7 @@ const behaviorActionImplementations = {
|
|
|
5249
5532
|
_type: context.schema.block.name,
|
|
5250
5533
|
style: (_a = context.schema.styles[0].value) != null ? _a : "normal",
|
|
5251
5534
|
markDefs: [],
|
|
5252
|
-
children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$
|
|
5535
|
+
children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$6({}, child), {
|
|
5253
5536
|
_key: context.keyGenerator()
|
|
5254
5537
|
}))) != null ? _d : [{
|
|
5255
5538
|
_type: context.schema.span.name,
|
|
@@ -5344,7 +5627,7 @@ const behaviorActionImplementations = {
|
|
|
5344
5627
|
action
|
|
5345
5628
|
}) => {
|
|
5346
5629
|
const selection = action.editor.selection;
|
|
5347
|
-
selection && (slate.Transforms.select(action.editor, __spreadValues$
|
|
5630
|
+
selection && (slate.Transforms.select(action.editor, __spreadValues$6({}, selection)), action.editor.selection = __spreadValues$6({}, selection));
|
|
5348
5631
|
},
|
|
5349
5632
|
"style.toggle": toggleStyleActionImplementation,
|
|
5350
5633
|
"style.add": addStyleActionImplementation,
|
|
@@ -5616,6 +5899,22 @@ function performDefaultAction({
|
|
|
5616
5899
|
});
|
|
5617
5900
|
}
|
|
5618
5901
|
}
|
|
5902
|
+
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) => {
|
|
5903
|
+
for (var prop in b || (b = {}))
|
|
5904
|
+
__hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5905
|
+
if (__getOwnPropSymbols$5)
|
|
5906
|
+
for (var prop of __getOwnPropSymbols$5(b))
|
|
5907
|
+
__propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5908
|
+
return a;
|
|
5909
|
+
};
|
|
5910
|
+
function getActiveDecorators({
|
|
5911
|
+
schema: schema2,
|
|
5912
|
+
slateEditorInstance
|
|
5913
|
+
}) {
|
|
5914
|
+
var _a, _b;
|
|
5915
|
+
const decorators = schema2.decorators.map((decorator) => decorator.value);
|
|
5916
|
+
return ((_b = __spreadValues$5({}, (_a = slate.Editor.marks(slateEditorInstance)) != null ? _a : {}).marks) != null ? _b : []).filter((mark) => decorators.includes(mark));
|
|
5917
|
+
}
|
|
5619
5918
|
var __defProp$4 = Object.defineProperty, __defProps$4 = Object.defineProperties, __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$4 = Object.getOwnPropertySymbols, __hasOwnProp$4 = Object.prototype.hasOwnProperty, __propIsEnum$4 = Object.prototype.propertyIsEnumerable, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$4 = (a, b) => {
|
|
5620
5919
|
for (var prop in b || (b = {}))
|
|
5621
5920
|
__hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
@@ -5648,6 +5947,12 @@ const editorMachine = xstate.setup({
|
|
|
5648
5947
|
"emit mutation event": xstate.emit(({
|
|
5649
5948
|
event
|
|
5650
5949
|
}) => (xstate.assertEvent(event, "mutation"), event)),
|
|
5950
|
+
"emit read only": xstate.emit({
|
|
5951
|
+
type: "read only"
|
|
5952
|
+
}),
|
|
5953
|
+
"emit editable": xstate.emit({
|
|
5954
|
+
type: "editable"
|
|
5955
|
+
}),
|
|
5651
5956
|
"defer event": xstate.assign({
|
|
5652
5957
|
pendingEvents: ({
|
|
5653
5958
|
context,
|
|
@@ -5661,6 +5966,9 @@ const editorMachine = xstate.setup({
|
|
|
5661
5966
|
for (const event of context.pendingEvents)
|
|
5662
5967
|
enqueue(xstate.emit(event));
|
|
5663
5968
|
}),
|
|
5969
|
+
"emit ready": xstate.emit({
|
|
5970
|
+
type: "ready"
|
|
5971
|
+
}),
|
|
5664
5972
|
"clear pending events": xstate.assign({
|
|
5665
5973
|
pendingEvents: []
|
|
5666
5974
|
}),
|
|
@@ -5685,6 +5993,10 @@ const editorMachine = xstate.setup({
|
|
|
5685
5993
|
return;
|
|
5686
5994
|
}
|
|
5687
5995
|
const value = fromSlateValue(event.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(event.editor)), selection = toPortableTextRange(value, event.editor.selection, context.schema), editorContext = {
|
|
5996
|
+
activeDecorators: getActiveDecorators({
|
|
5997
|
+
schema: context.schema,
|
|
5998
|
+
slateEditorInstance: event.editor
|
|
5999
|
+
}),
|
|
5688
6000
|
keyGenerator: context.keyGenerator,
|
|
5689
6001
|
schema: context.schema,
|
|
5690
6002
|
selection,
|
|
@@ -5736,89 +6048,12 @@ const editorMachine = xstate.setup({
|
|
|
5736
6048
|
pendingEvents: [],
|
|
5737
6049
|
schema: input.schema,
|
|
5738
6050
|
selection: null,
|
|
5739
|
-
|
|
6051
|
+
initialReadOnly: (_b = input.readOnly) != null ? _b : !1,
|
|
5740
6052
|
maxBlocks: input.maxBlocks,
|
|
5741
6053
|
value: input.value
|
|
5742
6054
|
};
|
|
5743
6055
|
},
|
|
5744
6056
|
on: {
|
|
5745
|
-
"annotation.add": {
|
|
5746
|
-
actions: xstate.emit(({
|
|
5747
|
-
event
|
|
5748
|
-
}) => event),
|
|
5749
|
-
guard: ({
|
|
5750
|
-
context
|
|
5751
|
-
}) => !context.readOnly
|
|
5752
|
-
},
|
|
5753
|
-
"annotation.remove": {
|
|
5754
|
-
actions: xstate.emit(({
|
|
5755
|
-
event
|
|
5756
|
-
}) => event),
|
|
5757
|
-
guard: ({
|
|
5758
|
-
context
|
|
5759
|
-
}) => !context.readOnly
|
|
5760
|
-
},
|
|
5761
|
-
"annotation.toggle": {
|
|
5762
|
-
actions: xstate.emit(({
|
|
5763
|
-
event
|
|
5764
|
-
}) => event),
|
|
5765
|
-
guard: ({
|
|
5766
|
-
context
|
|
5767
|
-
}) => !context.readOnly
|
|
5768
|
-
},
|
|
5769
|
-
blur: {
|
|
5770
|
-
actions: xstate.emit(({
|
|
5771
|
-
event
|
|
5772
|
-
}) => event),
|
|
5773
|
-
guard: ({
|
|
5774
|
-
context
|
|
5775
|
-
}) => !context.readOnly
|
|
5776
|
-
},
|
|
5777
|
-
"decorator.*": {
|
|
5778
|
-
actions: xstate.emit(({
|
|
5779
|
-
event
|
|
5780
|
-
}) => event),
|
|
5781
|
-
guard: ({
|
|
5782
|
-
context
|
|
5783
|
-
}) => !context.readOnly
|
|
5784
|
-
},
|
|
5785
|
-
focus: {
|
|
5786
|
-
actions: xstate.emit(({
|
|
5787
|
-
event
|
|
5788
|
-
}) => event),
|
|
5789
|
-
guard: ({
|
|
5790
|
-
context
|
|
5791
|
-
}) => !context.readOnly
|
|
5792
|
-
},
|
|
5793
|
-
"insert.*": {
|
|
5794
|
-
actions: xstate.emit(({
|
|
5795
|
-
event
|
|
5796
|
-
}) => event),
|
|
5797
|
-
guard: ({
|
|
5798
|
-
context
|
|
5799
|
-
}) => !context.readOnly
|
|
5800
|
-
},
|
|
5801
|
-
"list item.*": {
|
|
5802
|
-
actions: xstate.emit(({
|
|
5803
|
-
event
|
|
5804
|
-
}) => event),
|
|
5805
|
-
guard: ({
|
|
5806
|
-
context
|
|
5807
|
-
}) => !context.readOnly
|
|
5808
|
-
},
|
|
5809
|
-
"style.*": {
|
|
5810
|
-
actions: xstate.emit(({
|
|
5811
|
-
event
|
|
5812
|
-
}) => event),
|
|
5813
|
-
guard: ({
|
|
5814
|
-
context
|
|
5815
|
-
}) => !context.readOnly
|
|
5816
|
-
},
|
|
5817
|
-
ready: {
|
|
5818
|
-
actions: xstate.emit(({
|
|
5819
|
-
event
|
|
5820
|
-
}) => event)
|
|
5821
|
-
},
|
|
5822
6057
|
unset: {
|
|
5823
6058
|
actions: xstate.emit(({
|
|
5824
6059
|
event
|
|
@@ -5886,18 +6121,6 @@ const editorMachine = xstate.setup({
|
|
|
5886
6121
|
}) => event.value
|
|
5887
6122
|
})
|
|
5888
6123
|
},
|
|
5889
|
-
"toggle readOnly": {
|
|
5890
|
-
actions: [xstate.assign({
|
|
5891
|
-
readOnly: ({
|
|
5892
|
-
context
|
|
5893
|
-
}) => !context.readOnly
|
|
5894
|
-
}), xstate.emit(({
|
|
5895
|
-
context
|
|
5896
|
-
}) => ({
|
|
5897
|
-
type: "readOnly toggled",
|
|
5898
|
-
readOnly: context.readOnly
|
|
5899
|
-
}))]
|
|
5900
|
-
},
|
|
5901
6124
|
"update maxBlocks": {
|
|
5902
6125
|
actions: xstate.assign({
|
|
5903
6126
|
maxBlocks: ({
|
|
@@ -5905,12 +6128,6 @@ const editorMachine = xstate.setup({
|
|
|
5905
6128
|
}) => event.maxBlocks
|
|
5906
6129
|
})
|
|
5907
6130
|
},
|
|
5908
|
-
"behavior event": {
|
|
5909
|
-
actions: "handle behavior event",
|
|
5910
|
-
guard: ({
|
|
5911
|
-
context
|
|
5912
|
-
}) => !context.readOnly
|
|
5913
|
-
},
|
|
5914
6131
|
"behavior action intends": {
|
|
5915
6132
|
actions: [({
|
|
5916
6133
|
context,
|
|
@@ -5939,49 +6156,160 @@ const editorMachine = xstate.setup({
|
|
|
5939
6156
|
})]
|
|
5940
6157
|
}
|
|
5941
6158
|
},
|
|
5942
|
-
|
|
6159
|
+
type: "parallel",
|
|
5943
6160
|
states: {
|
|
5944
|
-
|
|
5945
|
-
initial: "
|
|
6161
|
+
"edit mode": {
|
|
6162
|
+
initial: "read only",
|
|
5946
6163
|
states: {
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
6164
|
+
"read only": {
|
|
6165
|
+
initial: "determine initial edit mode",
|
|
6166
|
+
states: {
|
|
6167
|
+
"determine initial edit mode": {
|
|
6168
|
+
on: {
|
|
6169
|
+
"done syncing": [{
|
|
6170
|
+
target: "#editor.edit mode.read only.read only",
|
|
6171
|
+
guard: ({
|
|
6172
|
+
context
|
|
6173
|
+
}) => context.initialReadOnly
|
|
6174
|
+
}, {
|
|
6175
|
+
target: "#editor.edit mode.editable"
|
|
6176
|
+
}]
|
|
6177
|
+
}
|
|
5955
6178
|
},
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
6179
|
+
"read only": {
|
|
6180
|
+
on: {
|
|
6181
|
+
"update readOnly": {
|
|
6182
|
+
guard: ({
|
|
6183
|
+
event
|
|
6184
|
+
}) => !event.readOnly,
|
|
6185
|
+
target: "#editor.edit mode.editable",
|
|
6186
|
+
actions: ["emit editable"]
|
|
6187
|
+
}
|
|
6188
|
+
}
|
|
5959
6189
|
}
|
|
5960
6190
|
}
|
|
5961
6191
|
},
|
|
5962
|
-
|
|
6192
|
+
editable: {
|
|
5963
6193
|
on: {
|
|
5964
|
-
"
|
|
5965
|
-
|
|
6194
|
+
"update readOnly": {
|
|
6195
|
+
guard: ({
|
|
6196
|
+
event
|
|
6197
|
+
}) => event.readOnly,
|
|
6198
|
+
target: "#editor.edit mode.read only.read only",
|
|
6199
|
+
actions: ["emit read only"]
|
|
6200
|
+
},
|
|
6201
|
+
"behavior event": {
|
|
6202
|
+
actions: "handle behavior event"
|
|
6203
|
+
},
|
|
6204
|
+
"annotation.add": {
|
|
6205
|
+
actions: xstate.emit(({
|
|
6206
|
+
event
|
|
6207
|
+
}) => event)
|
|
6208
|
+
},
|
|
6209
|
+
"annotation.remove": {
|
|
6210
|
+
actions: xstate.emit(({
|
|
6211
|
+
event
|
|
6212
|
+
}) => event)
|
|
6213
|
+
},
|
|
6214
|
+
"annotation.toggle": {
|
|
6215
|
+
actions: xstate.emit(({
|
|
6216
|
+
event
|
|
6217
|
+
}) => event)
|
|
6218
|
+
},
|
|
6219
|
+
blur: {
|
|
6220
|
+
actions: xstate.emit(({
|
|
6221
|
+
event
|
|
6222
|
+
}) => event)
|
|
5966
6223
|
},
|
|
6224
|
+
"decorator.*": {
|
|
6225
|
+
actions: xstate.emit(({
|
|
6226
|
+
event
|
|
6227
|
+
}) => event)
|
|
6228
|
+
},
|
|
6229
|
+
focus: {
|
|
6230
|
+
actions: xstate.emit(({
|
|
6231
|
+
event
|
|
6232
|
+
}) => event)
|
|
6233
|
+
},
|
|
6234
|
+
"insert.*": {
|
|
6235
|
+
actions: xstate.emit(({
|
|
6236
|
+
event
|
|
6237
|
+
}) => event)
|
|
6238
|
+
},
|
|
6239
|
+
"list item.*": {
|
|
6240
|
+
actions: xstate.emit(({
|
|
6241
|
+
event
|
|
6242
|
+
}) => event)
|
|
6243
|
+
},
|
|
6244
|
+
"style.*": {
|
|
6245
|
+
actions: xstate.emit(({
|
|
6246
|
+
event
|
|
6247
|
+
}) => event)
|
|
6248
|
+
}
|
|
6249
|
+
}
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
},
|
|
6253
|
+
setup: {
|
|
6254
|
+
initial: "setting up",
|
|
6255
|
+
states: {
|
|
6256
|
+
"setting up": {
|
|
6257
|
+
exit: ["emit ready"],
|
|
6258
|
+
on: {
|
|
5967
6259
|
patch: {
|
|
5968
6260
|
actions: "defer event"
|
|
5969
6261
|
},
|
|
5970
6262
|
mutation: {
|
|
5971
6263
|
actions: "defer event"
|
|
6264
|
+
},
|
|
6265
|
+
"done syncing": {
|
|
6266
|
+
target: "pristine"
|
|
6267
|
+
}
|
|
6268
|
+
}
|
|
6269
|
+
},
|
|
6270
|
+
pristine: {
|
|
6271
|
+
initial: "idle",
|
|
6272
|
+
states: {
|
|
6273
|
+
idle: {
|
|
6274
|
+
on: {
|
|
6275
|
+
normalizing: {
|
|
6276
|
+
target: "normalizing"
|
|
6277
|
+
},
|
|
6278
|
+
patch: {
|
|
6279
|
+
actions: "defer event",
|
|
6280
|
+
target: "#editor.setup.dirty"
|
|
6281
|
+
},
|
|
6282
|
+
mutation: {
|
|
6283
|
+
actions: "defer event",
|
|
6284
|
+
target: "#editor.setup.dirty"
|
|
6285
|
+
}
|
|
6286
|
+
}
|
|
6287
|
+
},
|
|
6288
|
+
normalizing: {
|
|
6289
|
+
on: {
|
|
6290
|
+
"done normalizing": {
|
|
6291
|
+
target: "idle"
|
|
6292
|
+
},
|
|
6293
|
+
patch: {
|
|
6294
|
+
actions: "defer event"
|
|
6295
|
+
},
|
|
6296
|
+
mutation: {
|
|
6297
|
+
actions: "defer event"
|
|
6298
|
+
}
|
|
6299
|
+
}
|
|
5972
6300
|
}
|
|
5973
6301
|
}
|
|
5974
|
-
}
|
|
5975
|
-
}
|
|
5976
|
-
},
|
|
5977
|
-
dirty: {
|
|
5978
|
-
entry: ["emit pending events", "clear pending events"],
|
|
5979
|
-
on: {
|
|
5980
|
-
patch: {
|
|
5981
|
-
actions: "emit patch event"
|
|
5982
6302
|
},
|
|
5983
|
-
|
|
5984
|
-
|
|
6303
|
+
dirty: {
|
|
6304
|
+
entry: ["emit pending events", "clear pending events"],
|
|
6305
|
+
on: {
|
|
6306
|
+
patch: {
|
|
6307
|
+
actions: "emit patch event"
|
|
6308
|
+
},
|
|
6309
|
+
mutation: {
|
|
6310
|
+
actions: "emit mutation event"
|
|
6311
|
+
}
|
|
6312
|
+
}
|
|
5985
6313
|
}
|
|
5986
6314
|
}
|
|
5987
6315
|
}
|
|
@@ -6109,11 +6437,13 @@ class PortableTextEditor extends React.Component {
|
|
|
6109
6437
|
}), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
|
|
6110
6438
|
}
|
|
6111
6439
|
componentDidUpdate(prevProps) {
|
|
6440
|
+
var _a;
|
|
6112
6441
|
!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({
|
|
6113
6442
|
type: "update schema",
|
|
6114
6443
|
schema: this.schemaTypes
|
|
6115
6444
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
6116
|
-
type: "
|
|
6445
|
+
type: "update readOnly",
|
|
6446
|
+
readOnly: (_a = this.props.readOnly) != null ? _a : !1
|
|
6117
6447
|
}), this.props.maxBlocks !== prevProps.maxBlocks && this.editor._internal.editorActor.send({
|
|
6118
6448
|
type: "update maxBlocks",
|
|
6119
6449
|
maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
|
|
@@ -6130,7 +6460,7 @@ class PortableTextEditor extends React.Component {
|
|
|
6130
6460
|
/* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
|
|
6131
6461
|
this.props.editor || this.props.onChange(change), this.change$.next(change);
|
|
6132
6462
|
} }),
|
|
6133
|
-
/* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor: this.editor._internal.editorActor,
|
|
6463
|
+
/* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor: this.editor._internal.editorActor, slateEditor: this.editor._internal.slateEditor.instance }),
|
|
6134
6464
|
/* @__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 }) }) }) })
|
|
6135
6465
|
] });
|
|
6136
6466
|
}
|
|
@@ -6315,7 +6645,8 @@ function RouteEventsToChanges(props) {
|
|
|
6315
6645
|
case "list item.toggle":
|
|
6316
6646
|
case "style.toggle":
|
|
6317
6647
|
case "patches":
|
|
6318
|
-
case "
|
|
6648
|
+
case "editable":
|
|
6649
|
+
case "read only":
|
|
6319
6650
|
break bb5;
|
|
6320
6651
|
default:
|
|
6321
6652
|
handleChange(event);
|
|
@@ -6725,10 +7056,16 @@ function _insertFragment(editor, fragment, schemaTypes) {
|
|
|
6725
7056
|
})) : editor.insertFragment(fragment);
|
|
6726
7057
|
}), editor.onChange();
|
|
6727
7058
|
}
|
|
6728
|
-
function withSyncRangeDecorations(
|
|
7059
|
+
function withSyncRangeDecorations({
|
|
7060
|
+
editorActor,
|
|
7061
|
+
slateEditor,
|
|
7062
|
+
syncRangeDecorations
|
|
7063
|
+
}) {
|
|
6729
7064
|
const originalApply = slateEditor.apply;
|
|
6730
7065
|
return slateEditor.apply = (op) => {
|
|
6731
|
-
originalApply(op),
|
|
7066
|
+
originalApply(op), !editorActor.getSnapshot().matches({
|
|
7067
|
+
"edit mode": "read only"
|
|
7068
|
+
}) && op.type !== "set_selection" && syncRangeDecorations(op);
|
|
6732
7069
|
}, () => {
|
|
6733
7070
|
slateEditor.apply = originalApply;
|
|
6734
7071
|
};
|
|
@@ -6796,7 +7133,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6796
7133
|
"spellCheck"
|
|
6797
7134
|
]), portableTextEditor = usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), [rangeDecorationState, setRangeDecorationsState] = React.useState([]);
|
|
6798
7135
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
6799
|
-
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.
|
|
7136
|
+
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
7137
|
+
"edit mode": "read only"
|
|
7138
|
+
})), schemaTypes = react.useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name;
|
|
6800
7139
|
React.useMemo(() => {
|
|
6801
7140
|
const withInsertData = createWithInsertData(editorActor, schemaTypes);
|
|
6802
7141
|
if (readOnly)
|
|
@@ -6865,7 +7204,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6865
7204
|
}, [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]);
|
|
6866
7205
|
React.useEffect(() => {
|
|
6867
7206
|
const onReady = editorActor.on("ready", () => {
|
|
6868
|
-
restoreSelectionFromProps();
|
|
7207
|
+
syncRangeDecorations(), restoreSelectionFromProps();
|
|
6869
7208
|
}), onInvalidValue = editorActor.on("invalid value", () => {
|
|
6870
7209
|
setHasInvalidValue(!0);
|
|
6871
7210
|
}), onValueChanged = editorActor.on("value changed", () => {
|
|
@@ -6874,7 +7213,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6874
7213
|
return () => {
|
|
6875
7214
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
6876
7215
|
};
|
|
6877
|
-
}, [editorActor, restoreSelectionFromProps]), React.useEffect(() => {
|
|
7216
|
+
}, [editorActor, restoreSelectionFromProps, syncRangeDecorations]), React.useEffect(() => {
|
|
6878
7217
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
6879
7218
|
}, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
|
|
6880
7219
|
const [syncedRangeDecorations, setSyncedRangeDecorations] = React.useState(!1);
|
|
@@ -6883,9 +7222,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6883
7222
|
}, [syncRangeDecorations, syncedRangeDecorations]), React.useEffect(() => {
|
|
6884
7223
|
isEqual__default.default(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
|
|
6885
7224
|
}, [rangeDecorations, syncRangeDecorations]), React.useEffect(() => {
|
|
6886
|
-
const teardown = withSyncRangeDecorations(
|
|
7225
|
+
const teardown = withSyncRangeDecorations({
|
|
7226
|
+
editorActor,
|
|
7227
|
+
slateEditor,
|
|
7228
|
+
syncRangeDecorations
|
|
7229
|
+
});
|
|
6887
7230
|
return () => teardown();
|
|
6888
|
-
}, [slateEditor, syncRangeDecorations]);
|
|
7231
|
+
}, [editorActor, slateEditor, syncRangeDecorations]);
|
|
6889
7232
|
const handleCopy = React.useCallback((event) => {
|
|
6890
7233
|
onCopy ? onCopy(event) !== void 0 && event.preventDefault() : event.nativeEvent.clipboardData && editorActor.send({
|
|
6891
7234
|
type: "behavior event",
|
|
@@ -7074,7 +7417,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7074
7417
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
7075
7418
|
const EditorContext = React__default.default.createContext(void 0);
|
|
7076
7419
|
function EditorProvider(props) {
|
|
7077
|
-
const $ = reactCompilerRuntime.c(
|
|
7420
|
+
const $ = reactCompilerRuntime.c(28), editor = useCreateEditor(props.initialConfig), editorActor = editor._internal.editorActor, slateEditor = editor._internal.slateEditor;
|
|
7078
7421
|
let t0, t1;
|
|
7079
7422
|
$[0] !== editor ? (t1 = new PortableTextEditor({
|
|
7080
7423
|
editor
|
|
@@ -7087,21 +7430,21 @@ function EditorProvider(props) {
|
|
|
7087
7430
|
let t3;
|
|
7088
7431
|
$[4] !== editorActor || $[5] !== t2 ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { editorActor, onChange: t2 }), $[4] = editorActor, $[5] = t2, $[6] = t3) : t3 = $[6];
|
|
7089
7432
|
let t4;
|
|
7090
|
-
$[7] !==
|
|
7433
|
+
$[7] !== editorActor || $[8] !== slateEditor.instance ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor, slateEditor: slateEditor.instance }), $[7] = editorActor, $[8] = slateEditor.instance, $[9] = t4) : t4 = $[9];
|
|
7091
7434
|
let t5;
|
|
7092
|
-
$[
|
|
7435
|
+
$[10] !== editorActor || $[11] !== props.children ? (t5 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor, children: props.children }), $[10] = editorActor, $[11] = props.children, $[12] = t5) : t5 = $[12];
|
|
7093
7436
|
let t6;
|
|
7094
|
-
$[
|
|
7437
|
+
$[13] !== portableTextEditor || $[14] !== t5 ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: portableTextEditor, children: t5 }), $[13] = portableTextEditor, $[14] = t5, $[15] = t6) : t6 = $[15];
|
|
7095
7438
|
let t7;
|
|
7096
|
-
$[
|
|
7439
|
+
$[16] !== slateEditor.initialValue || $[17] !== slateEditor.instance || $[18] !== t6 ? (t7 = /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: slateEditor.instance, initialValue: slateEditor.initialValue, children: t6 }), $[16] = slateEditor.initialValue, $[17] = slateEditor.instance, $[18] = t6, $[19] = t7) : t7 = $[19];
|
|
7097
7440
|
let t8;
|
|
7098
|
-
$[
|
|
7441
|
+
$[20] !== editorActor || $[21] !== t7 ? (t8 = /* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: editorActor, children: t7 }), $[20] = editorActor, $[21] = t7, $[22] = t8) : t8 = $[22];
|
|
7099
7442
|
let t9;
|
|
7100
|
-
return $[
|
|
7443
|
+
return $[23] !== editor || $[24] !== t3 || $[25] !== t4 || $[26] !== t8 ? (t9 = /* @__PURE__ */ jsxRuntime.jsxs(EditorContext.Provider, { value: editor, children: [
|
|
7101
7444
|
t3,
|
|
7102
7445
|
t4,
|
|
7103
7446
|
t8
|
|
7104
|
-
] }), $[
|
|
7447
|
+
] }), $[23] = editor, $[24] = t3, $[25] = t4, $[26] = t8, $[27] = t9) : t9 = $[27], t9;
|
|
7105
7448
|
}
|
|
7106
7449
|
function useEditor() {
|
|
7107
7450
|
const editor = React__default.default.useContext(EditorContext);
|
|
@@ -7130,6 +7473,10 @@ function useEditorSelector(editor, selector, t0) {
|
|
|
7130
7473
|
let t1;
|
|
7131
7474
|
return $[0] !== editor || $[1] !== selector ? (t1 = (snapshot) => {
|
|
7132
7475
|
const context = {
|
|
7476
|
+
activeDecorators: getActiveDecorators({
|
|
7477
|
+
schema: snapshot.context.schema,
|
|
7478
|
+
slateEditorInstance: editor._internal.slateEditor.instance
|
|
7479
|
+
}),
|
|
7133
7480
|
keyGenerator: snapshot.context.keyGenerator,
|
|
7134
7481
|
schema: snapshot.context.schema,
|
|
7135
7482
|
selection: snapshot.context.selection,
|