@portabletext/editor 1.15.2 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +30 -28
- 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 +12 -10
- 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 +35 -35
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +40 -45
- package/lib/behaviors/index.d.ts +40 -45
- package/lib/behaviors/index.js +20 -20
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +868 -542
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3791 -4503
- package/lib/index.d.ts +3791 -4503
- package/lib/index.js +865 -541
- 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 +62 -17
- package/lib/selectors/index.d.ts +62 -17
- package/lib/selectors/index.js +154 -3
- package/lib/selectors/index.js.map +1 -1
- package/package.json +11 -11
- package/src/behavior-actions/behavior.action-utils.insert-block.ts +3 -5
- package/src/behavior-actions/behavior.actions.ts +6 -6
- package/src/behavior-actions/behavior.guards.ts +2 -6
- package/src/behaviors/behavior.code-editor.ts +5 -9
- package/src/behaviors/behavior.core.block-objects.ts +14 -20
- package/src/behaviors/behavior.core.lists.ts +13 -19
- package/src/behaviors/behavior.links.ts +6 -6
- package/src/behaviors/behavior.markdown.ts +27 -40
- package/src/behaviors/behavior.types.ts +7 -7
- package/src/behaviors/index.ts +1 -0
- package/src/editor/Editable.tsx +11 -4
- package/src/editor/PortableTextEditor.tsx +4 -5
- package/src/editor/{hooks/useSyncValue.test.tsx → __tests__/sync-value.test.tsx} +42 -23
- package/src/editor/components/Synchronizer.tsx +53 -80
- package/src/{utils/getPortableTextMemberSchemaTypes.ts → editor/create-editor-schema.ts} +3 -3
- package/src/editor/create-editor.ts +2 -2
- package/src/editor/define-schema.ts +8 -3
- package/src/editor/editor-machine.ts +136 -104
- package/src/editor/editor-provider.tsx +0 -3
- package/src/editor/editor-selector.ts +6 -13
- package/src/editor/editor-snapshot.ts +5 -6
- 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 +657 -0
- package/src/editor/withSyncRangeDecorations.ts +17 -5
- package/src/index.ts +3 -5
- package/src/selectors/_exports/index.ts +1 -0
- package/src/selectors/index.ts +10 -4
- 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/__tests__/operationToPatches.test.ts +2 -2
- package/src/utils/__tests__/patchToOperations.test.ts +2 -2
- package/src/utils/__tests__/values.test.ts +2 -2
- 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,12 +11,12 @@ 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),
|
|
19
|
-
function
|
|
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
|
+
function createEditorSchema(portableTextType) {
|
|
20
20
|
var _a, _b, _c;
|
|
21
21
|
if (!portableTextType)
|
|
22
22
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
@@ -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) {
|
|
@@ -144,11 +144,11 @@ function compileSchemaDefinition(definition) {
|
|
|
144
144
|
}]
|
|
145
145
|
}), schema$1 = schema.Schema.compile({
|
|
146
146
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
147
|
-
}).get("portable-text"), pteSchema =
|
|
148
|
-
return __spreadProps$j(__spreadValues$
|
|
149
|
-
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$
|
|
147
|
+
}).get("portable-text"), pteSchema = createEditorSchema(schema$1);
|
|
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
|
+
context
|
|
2286
|
+
}) => !context.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
|
+
"toggle 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,106 @@ 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(41), {
|
|
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
|
-
}
|
|
2431
|
-
|
|
2432
|
-
|
|
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));
|
|
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);
|
|
2433
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;
|
|
2701
|
+
$[25] !== syncActorRef ? (t11 = () => {
|
|
2702
|
+
syncActorRef.send({
|
|
2703
|
+
type: "toggle readOnly"
|
|
2704
|
+
});
|
|
2705
|
+
}, $[25] = syncActorRef, $[26] = t11) : t11 = $[26];
|
|
2706
|
+
let t12;
|
|
2707
|
+
$[27] !== readOnly || $[28] !== syncActorRef ? (t12 = [syncActorRef, readOnly], $[27] = readOnly, $[28] = syncActorRef, $[29] = t12) : t12 = $[29], React.useEffect(t11, t12);
|
|
2708
|
+
let t13, t14;
|
|
2709
|
+
$[30] !== syncActorRef || $[31] !== value ? (t13 = () => {
|
|
2710
|
+
debug$h("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2711
|
+
type: "update value",
|
|
2712
|
+
value
|
|
2713
|
+
});
|
|
2714
|
+
}, t14 = [syncActorRef, value], $[30] = syncActorRef, $[31] = value, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
|
|
2715
|
+
let t15;
|
|
2716
|
+
$[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
|
|
2434
2717
|
debug$h("Subscribing to patch events");
|
|
2435
|
-
const sub = editorActor.on("patch", (
|
|
2436
|
-
|
|
2718
|
+
const sub = editorActor.on("patch", (event_1) => {
|
|
2719
|
+
mutationActorRef.send(event_1);
|
|
2437
2720
|
});
|
|
2438
2721
|
return () => {
|
|
2439
2722
|
debug$h("Unsubscribing to patch events"), sub.unsubscribe();
|
|
2440
2723
|
};
|
|
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;
|
|
2724
|
+
}, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
|
|
2725
|
+
let t16;
|
|
2726
|
+
return $[37] !== editorActor || $[38] !== mutationActorRef || $[39] !== slateEditor ? (t16 = [editorActor, mutationActorRef, slateEditor], $[37] = editorActor, $[38] = mutationActorRef, $[39] = slateEditor, $[40] = t16) : t16 = $[40], React.useEffect(t15, t16), null;
|
|
2449
2727
|
}
|
|
2450
2728
|
function _temp2(s_0) {
|
|
2451
|
-
return s_0.
|
|
2729
|
+
return s_0.matches({
|
|
2730
|
+
"edit mode": "read only"
|
|
2731
|
+
});
|
|
2452
2732
|
}
|
|
2453
2733
|
function _temp(s) {
|
|
2454
|
-
return s.context.
|
|
2734
|
+
return s.context.value;
|
|
2455
2735
|
}
|
|
2456
2736
|
Synchronizer.displayName = "Synchronizer";
|
|
2457
|
-
var __defProp$
|
|
2737
|
+
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
2738
|
for (var prop in b || (b = {}))
|
|
2459
|
-
__hasOwnProp$
|
|
2460
|
-
if (__getOwnPropSymbols$
|
|
2461
|
-
for (var prop of __getOwnPropSymbols$
|
|
2462
|
-
__propIsEnum$
|
|
2739
|
+
__hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2740
|
+
if (__getOwnPropSymbols$l)
|
|
2741
|
+
for (var prop of __getOwnPropSymbols$l(b))
|
|
2742
|
+
__propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
2463
2743
|
return a;
|
|
2464
2744
|
}, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
|
|
2465
2745
|
const debug$g = debugWithName("operationToPatches");
|
|
@@ -2501,7 +2781,7 @@ function createOperationToPatches(types2) {
|
|
|
2501
2781
|
const block = editor.children[operation.path[0]];
|
|
2502
2782
|
if (typeof block._key != "string")
|
|
2503
2783
|
throw new Error("Expected block to have a _key");
|
|
2504
|
-
const setNode = omitBy__default.default(__spreadValues$
|
|
2784
|
+
const setNode = omitBy__default.default(__spreadValues$l(__spreadValues$l({}, editor.children[operation.path[0]]), operation.newProperties), isUndefined__default.default);
|
|
2505
2785
|
return [patches.set(fromSlateValue([setNode], textBlockName)[0], [{
|
|
2506
2786
|
_key: block._key
|
|
2507
2787
|
}])];
|
|
@@ -2541,7 +2821,7 @@ function createOperationToPatches(types2) {
|
|
|
2541
2821
|
_key: targetKey
|
|
2542
2822
|
}])] : [patches.setIfMissing(beforeValue, []), patches.insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
|
|
2543
2823
|
} 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$
|
|
2824
|
+
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = __spreadValues$l({}, operation.node);
|
|
2545
2825
|
!node._type && slate.Text.isText(node) && (node._type = "span", node.marks = []);
|
|
2546
2826
|
const child = fromSlateValue([{
|
|
2547
2827
|
_key: "bogus",
|
|
@@ -2580,7 +2860,7 @@ function createOperationToPatches(types2) {
|
|
|
2580
2860
|
if (operation.path.length === 2) {
|
|
2581
2861
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
2582
2862
|
if (editor.isTextSpan(splitSpan)) {
|
|
2583
|
-
const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$
|
|
2863
|
+
const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$l({}, splitBlock), {
|
|
2584
2864
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
2585
2865
|
})], textBlockName)[0].children;
|
|
2586
2866
|
patches$1.push(patches.insert(targetSpans, "after", [{
|
|
@@ -2891,7 +3171,9 @@ function createWithMaxBlocks(editorActor) {
|
|
|
2891
3171
|
} = editor;
|
|
2892
3172
|
return editor.apply = (operation) => {
|
|
2893
3173
|
var _a;
|
|
2894
|
-
if (editorActor.getSnapshot().
|
|
3174
|
+
if (editorActor.getSnapshot().matches({
|
|
3175
|
+
"edit mode": "read only"
|
|
3176
|
+
})) {
|
|
2895
3177
|
apply2(operation);
|
|
2896
3178
|
return;
|
|
2897
3179
|
}
|
|
@@ -2908,12 +3190,12 @@ function createWithMaxBlocks(editorActor) {
|
|
|
2908
3190
|
}, editor;
|
|
2909
3191
|
};
|
|
2910
3192
|
}
|
|
2911
|
-
var __defProp$
|
|
3193
|
+
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
3194
|
for (var prop in b || (b = {}))
|
|
2913
|
-
__hasOwnProp$
|
|
2914
|
-
if (__getOwnPropSymbols$
|
|
2915
|
-
for (var prop of __getOwnPropSymbols$
|
|
2916
|
-
__propIsEnum$
|
|
3195
|
+
__hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
3196
|
+
if (__getOwnPropSymbols$k)
|
|
3197
|
+
for (var prop of __getOwnPropSymbols$k(b))
|
|
3198
|
+
__propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
2917
3199
|
return a;
|
|
2918
3200
|
}, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
2919
3201
|
function createWithObjectKeys(editorActor, schemaTypes) {
|
|
@@ -2932,16 +3214,16 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
2932
3214
|
return;
|
|
2933
3215
|
}
|
|
2934
3216
|
if (operation.type === "split_node") {
|
|
2935
|
-
apply2(__spreadProps$e(__spreadValues$
|
|
2936
|
-
properties: __spreadProps$e(__spreadValues$
|
|
3217
|
+
apply2(__spreadProps$e(__spreadValues$k({}, operation), {
|
|
3218
|
+
properties: __spreadProps$e(__spreadValues$k({}, operation.properties), {
|
|
2937
3219
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
2938
3220
|
})
|
|
2939
3221
|
}));
|
|
2940
3222
|
return;
|
|
2941
3223
|
}
|
|
2942
3224
|
if (operation.type === "insert_node" && !slate.Editor.isEditor(operation.node)) {
|
|
2943
|
-
apply2(__spreadProps$e(__spreadValues$
|
|
2944
|
-
node: __spreadProps$e(__spreadValues$
|
|
3225
|
+
apply2(__spreadProps$e(__spreadValues$k({}, operation), {
|
|
3226
|
+
node: __spreadProps$e(__spreadValues$k({}, operation.node), {
|
|
2945
3227
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
2946
3228
|
})
|
|
2947
3229
|
}));
|
|
@@ -2981,20 +3263,20 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
2981
3263
|
}, editor;
|
|
2982
3264
|
};
|
|
2983
3265
|
}
|
|
2984
|
-
var __defProp$
|
|
3266
|
+
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
3267
|
for (var prop in b || (b = {}))
|
|
2986
|
-
__hasOwnProp$
|
|
2987
|
-
if (__getOwnPropSymbols$
|
|
2988
|
-
for (var prop of __getOwnPropSymbols$
|
|
2989
|
-
__propIsEnum$
|
|
3268
|
+
__hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
3269
|
+
if (__getOwnPropSymbols$j)
|
|
3270
|
+
for (var prop of __getOwnPropSymbols$j(b))
|
|
3271
|
+
__propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
2990
3272
|
return a;
|
|
2991
3273
|
}, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
|
|
2992
3274
|
var target = {};
|
|
2993
3275
|
for (var prop in source)
|
|
2994
|
-
__hasOwnProp$
|
|
2995
|
-
if (source != null && __getOwnPropSymbols$
|
|
2996
|
-
for (var prop of __getOwnPropSymbols$
|
|
2997
|
-
exclude.indexOf(prop) < 0 && __propIsEnum$
|
|
3276
|
+
__hasOwnProp$j.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
3277
|
+
if (source != null && __getOwnPropSymbols$j)
|
|
3278
|
+
for (var prop of __getOwnPropSymbols$j(source))
|
|
3279
|
+
exclude.indexOf(prop) < 0 && __propIsEnum$j.call(source, prop) && (target[prop] = source[prop]);
|
|
2998
3280
|
return target;
|
|
2999
3281
|
};
|
|
3000
3282
|
const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
|
|
@@ -3086,7 +3368,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3086
3368
|
} = patch;
|
|
3087
3369
|
if (!targetChild || !targetChildPath)
|
|
3088
3370
|
return debug$f("Child not found"), !1;
|
|
3089
|
-
const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$
|
|
3371
|
+
const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$j({}, targetBlock), {
|
|
3090
3372
|
children: items
|
|
3091
3373
|
})], {
|
|
3092
3374
|
schemaTypes
|
|
@@ -3145,7 +3427,7 @@ function setPatch(editor, patch) {
|
|
|
3145
3427
|
editor.apply({
|
|
3146
3428
|
type: "set_node",
|
|
3147
3429
|
path: blockPath,
|
|
3148
|
-
properties: __spreadValues$
|
|
3430
|
+
properties: __spreadValues$j({}, prevRest),
|
|
3149
3431
|
newProperties: nextRest
|
|
3150
3432
|
}), debug$f("Setting children"), block.children.forEach((c, cIndex) => {
|
|
3151
3433
|
editor.apply({
|
|
@@ -3162,7 +3444,7 @@ function setPatch(editor, patch) {
|
|
|
3162
3444
|
});
|
|
3163
3445
|
} else if (block && "value" in block) {
|
|
3164
3446
|
const newVal = patches.applyAll([block.value], [patch])[0];
|
|
3165
|
-
return slate.Transforms.setNodes(editor, __spreadProps$d(__spreadValues$
|
|
3447
|
+
return slate.Transforms.setNodes(editor, __spreadProps$d(__spreadValues$j({}, block), {
|
|
3166
3448
|
value: newVal
|
|
3167
3449
|
}), {
|
|
3168
3450
|
at: blockPath
|
|
@@ -3255,12 +3537,12 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3255
3537
|
childPath: void 0
|
|
3256
3538
|
};
|
|
3257
3539
|
}
|
|
3258
|
-
var __defProp$
|
|
3540
|
+
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
3541
|
for (var prop in b || (b = {}))
|
|
3260
|
-
__hasOwnProp$
|
|
3261
|
-
if (__getOwnPropSymbols$
|
|
3262
|
-
for (var prop of __getOwnPropSymbols$
|
|
3263
|
-
__propIsEnum$
|
|
3542
|
+
__hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3543
|
+
if (__getOwnPropSymbols$i)
|
|
3544
|
+
for (var prop of __getOwnPropSymbols$i(b))
|
|
3545
|
+
__propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3264
3546
|
return a;
|
|
3265
3547
|
}, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
3266
3548
|
const debug$e = debugWithName("plugin:withPatches");
|
|
@@ -3308,8 +3590,6 @@ function createWithPatches({
|
|
|
3308
3590
|
debug$e("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
3309
3591
|
};
|
|
3310
3592
|
}), editor.apply = (operation) => {
|
|
3311
|
-
if (editorActor.getSnapshot().context.readOnly)
|
|
3312
|
-
return apply2(operation), editor;
|
|
3313
3593
|
let patches$1 = [];
|
|
3314
3594
|
previousChildren = editor.children;
|
|
3315
3595
|
const editorWasEmpty = isEqualToEmptyEditor(previousChildren, schemaTypes);
|
|
@@ -3349,7 +3629,7 @@ function createWithPatches({
|
|
|
3349
3629
|
})), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0 && patches$1.forEach((patch) => {
|
|
3350
3630
|
editorActor.send({
|
|
3351
3631
|
type: "patch",
|
|
3352
|
-
patch: __spreadProps$c(__spreadValues$
|
|
3632
|
+
patch: __spreadProps$c(__spreadValues$i({}, patch), {
|
|
3353
3633
|
origin: "local"
|
|
3354
3634
|
})
|
|
3355
3635
|
});
|
|
@@ -3364,7 +3644,9 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3364
3644
|
apply: apply2
|
|
3365
3645
|
} = editor;
|
|
3366
3646
|
return editor.apply = (op) => {
|
|
3367
|
-
if (editorActor.getSnapshot().
|
|
3647
|
+
if (editorActor.getSnapshot().matches({
|
|
3648
|
+
"edit mode": "read only"
|
|
3649
|
+
})) {
|
|
3368
3650
|
apply2(op);
|
|
3369
3651
|
return;
|
|
3370
3652
|
}
|
|
@@ -3462,12 +3744,12 @@ function getNextSpan({
|
|
|
3462
3744
|
}
|
|
3463
3745
|
return nextSpan;
|
|
3464
3746
|
}
|
|
3465
|
-
var __defProp$
|
|
3747
|
+
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
3748
|
for (var prop in b || (b = {}))
|
|
3467
|
-
__hasOwnProp$
|
|
3468
|
-
if (__getOwnPropSymbols$
|
|
3469
|
-
for (var prop of __getOwnPropSymbols$
|
|
3470
|
-
__propIsEnum$
|
|
3749
|
+
__hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3750
|
+
if (__getOwnPropSymbols$h)
|
|
3751
|
+
for (var prop of __getOwnPropSymbols$h(b))
|
|
3752
|
+
__propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3471
3753
|
return a;
|
|
3472
3754
|
}, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
|
|
3473
3755
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
@@ -3669,21 +3951,21 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3669
3951
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
3670
3952
|
}), 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
3953
|
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && (_f = op.node.marks) != null && _f.some((mark) => annotationsEnding.includes(mark))) {
|
|
3672
|
-
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$
|
|
3954
|
+
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
|
|
3673
3955
|
marks: (_h = (_g = op.node.marks) == null ? void 0 : _g.filter((mark) => !annotationsEnding.includes(mark))) != null ? _h : []
|
|
3674
3956
|
}));
|
|
3675
3957
|
return;
|
|
3676
3958
|
}
|
|
3677
3959
|
const annotationsStarting = (_i = nextSpanAnnotations == null ? void 0 : nextSpanAnnotations.filter((annotation) => !(previousSpanAnnotations != null && previousSpanAnnotations.includes(annotation)))) != null ? _i : [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3678
3960
|
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && (_j = op.node.marks) != null && _j.some((mark) => annotationsStarting.includes(mark))) {
|
|
3679
|
-
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$
|
|
3961
|
+
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
|
|
3680
3962
|
marks: (_l = (_k = op.node.marks) == null ? void 0 : _k.filter((mark) => !annotationsStarting.includes(mark))) != null ? _l : []
|
|
3681
3963
|
}));
|
|
3682
3964
|
return;
|
|
3683
3965
|
}
|
|
3684
3966
|
const nextSpanDecorators = (_n = (_m = nextSpan == null ? void 0 : nextSpan.marks) == null ? void 0 : _m.filter((mark) => decorators.includes(mark))) != null ? _n : [];
|
|
3685
3967
|
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$
|
|
3968
|
+
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$h({}, op.node), {
|
|
3687
3969
|
marks: nextSpanDecorators
|
|
3688
3970
|
}));
|
|
3689
3971
|
return;
|
|
@@ -3801,7 +4083,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3801
4083
|
spanPath
|
|
3802
4084
|
}), 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
4085
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
3804
|
-
const marksWithoutAnnotationMarks = (__spreadValues$
|
|
4086
|
+
const marksWithoutAnnotationMarks = (__spreadValues$h({}, slate.Editor.marks(editor) || {}).marks || []).filter((mark) => decorators.includes(mark));
|
|
3805
4087
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
3806
4088
|
apply2(op), slate.Transforms.setNodes(editor, {
|
|
3807
4089
|
marks: marksWithoutAnnotationMarks
|
|
@@ -3874,7 +4156,7 @@ const addDecoratorActionImplementation = ({
|
|
|
3874
4156
|
match: (node) => editor.isTextSpan(node)
|
|
3875
4157
|
});
|
|
3876
4158
|
} else {
|
|
3877
|
-
const existingMarks = __spreadValues$
|
|
4159
|
+
const existingMarks = __spreadValues$h({}, slate.Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$h({}, slate.Editor.marks(editor) || {}), {
|
|
3878
4160
|
marks: [...existingMarks, mark]
|
|
3879
4161
|
});
|
|
3880
4162
|
editor.marks = marks;
|
|
@@ -3920,7 +4202,7 @@ const addDecoratorActionImplementation = ({
|
|
|
3920
4202
|
match: (node) => editor.isTextSpan(node)
|
|
3921
4203
|
});
|
|
3922
4204
|
} else {
|
|
3923
|
-
const existingMarks = __spreadValues$
|
|
4205
|
+
const existingMarks = __spreadValues$h({}, slate.Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$h({}, slate.Editor.marks(editor) || {}), {
|
|
3924
4206
|
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
3925
4207
|
});
|
|
3926
4208
|
editor.marks = {
|
|
@@ -3944,7 +4226,7 @@ function isDecoratorActive({
|
|
|
3944
4226
|
var _a;
|
|
3945
4227
|
const [node] = n;
|
|
3946
4228
|
return (_a = node.marks) == null ? void 0 : _a.includes(decorator);
|
|
3947
|
-
}) : (__spreadValues$
|
|
4229
|
+
}) : (__spreadValues$h({}, slate.Editor.marks(editor) || {}).marks || []).includes(decorator);
|
|
3948
4230
|
}
|
|
3949
4231
|
const toggleDecoratorActionImplementation = ({
|
|
3950
4232
|
context,
|
|
@@ -3998,16 +4280,18 @@ function createWithPortableTextSelections(editorActor, types2) {
|
|
|
3998
4280
|
} = editor;
|
|
3999
4281
|
return editor.onChange = () => {
|
|
4000
4282
|
const hasChanges = editor.operations.length > 0;
|
|
4001
|
-
onChange(), hasChanges &&
|
|
4283
|
+
onChange(), hasChanges && !editorActor.getSnapshot().matches({
|
|
4284
|
+
setup: "setting up"
|
|
4285
|
+
}) && emitPortableTextSelection();
|
|
4002
4286
|
}, editor;
|
|
4003
4287
|
};
|
|
4004
4288
|
}
|
|
4005
|
-
var __defProp$
|
|
4289
|
+
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
4290
|
for (var prop in b || (b = {}))
|
|
4007
|
-
__hasOwnProp$
|
|
4008
|
-
if (__getOwnPropSymbols$
|
|
4009
|
-
for (var prop of __getOwnPropSymbols$
|
|
4010
|
-
__propIsEnum$
|
|
4291
|
+
__hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4292
|
+
if (__getOwnPropSymbols$g)
|
|
4293
|
+
for (var prop of __getOwnPropSymbols$g(b))
|
|
4294
|
+
__propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
4011
4295
|
return a;
|
|
4012
4296
|
}, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
4013
4297
|
const debug$9 = debugWithName("plugin:withSchemaTypes");
|
|
@@ -4027,7 +4311,7 @@ function createWithSchemaTypes({
|
|
|
4027
4311
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4028
4312
|
editorActor.send({
|
|
4029
4313
|
type: "normalizing"
|
|
4030
|
-
}), slate.Transforms.setNodes(editor, __spreadProps$a(__spreadValues$
|
|
4314
|
+
}), slate.Transforms.setNodes(editor, __spreadProps$a(__spreadValues$g({}, span), {
|
|
4031
4315
|
_type: schemaTypes.span.name,
|
|
4032
4316
|
_key: key
|
|
4033
4317
|
}), {
|
|
@@ -4055,12 +4339,12 @@ function createWithSchemaTypes({
|
|
|
4055
4339
|
}, editor;
|
|
4056
4340
|
};
|
|
4057
4341
|
}
|
|
4058
|
-
var __defProp$
|
|
4342
|
+
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
4343
|
for (var prop in b || (b = {}))
|
|
4060
|
-
__hasOwnProp$
|
|
4061
|
-
if (__getOwnPropSymbols$
|
|
4062
|
-
for (var prop of __getOwnPropSymbols$
|
|
4063
|
-
__propIsEnum$
|
|
4344
|
+
__hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4345
|
+
if (__getOwnPropSymbols$f)
|
|
4346
|
+
for (var prop of __getOwnPropSymbols$f(b))
|
|
4347
|
+
__propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4064
4348
|
return a;
|
|
4065
4349
|
}, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
4066
4350
|
const debug$8 = debugWithName("plugin:withUtils");
|
|
@@ -4086,10 +4370,10 @@ function createWithUtils({
|
|
|
4086
4370
|
} = 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
4371
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4088
4372
|
debug$8("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
|
|
4089
|
-
anchor: __spreadProps$9(__spreadValues$
|
|
4373
|
+
anchor: __spreadProps$9(__spreadValues$f({}, selection.anchor), {
|
|
4090
4374
|
offset: newStartOffset
|
|
4091
4375
|
}),
|
|
4092
|
-
focus: __spreadProps$9(__spreadValues$
|
|
4376
|
+
focus: __spreadProps$9(__spreadValues$f({}, selection.focus), {
|
|
4093
4377
|
offset: newEndOffset
|
|
4094
4378
|
})
|
|
4095
4379
|
});
|
|
@@ -4097,7 +4381,7 @@ function createWithUtils({
|
|
|
4097
4381
|
}
|
|
4098
4382
|
debug$8("pteExpandToWord: Can't expand to word here");
|
|
4099
4383
|
}
|
|
4100
|
-
}, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$
|
|
4384
|
+
}, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$f(__spreadValues$f({
|
|
4101
4385
|
_type: schemaTypes.block.name,
|
|
4102
4386
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4103
4387
|
style: schemaTypes.styles[0].value || "normal"
|
|
@@ -4161,12 +4445,12 @@ function createSlateEditor(config) {
|
|
|
4161
4445
|
};
|
|
4162
4446
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4163
4447
|
}
|
|
4164
|
-
var __defProp$
|
|
4448
|
+
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
4449
|
for (var prop in b || (b = {}))
|
|
4166
|
-
__hasOwnProp$
|
|
4167
|
-
if (__getOwnPropSymbols$
|
|
4168
|
-
for (var prop of __getOwnPropSymbols$
|
|
4169
|
-
__propIsEnum$
|
|
4450
|
+
__hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4451
|
+
if (__getOwnPropSymbols$e)
|
|
4452
|
+
for (var prop of __getOwnPropSymbols$e(b))
|
|
4453
|
+
__propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4170
4454
|
return a;
|
|
4171
4455
|
}, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
4172
4456
|
const toggleListItemActionImplementation = ({
|
|
@@ -4178,12 +4462,12 @@ const toggleListItemActionImplementation = ({
|
|
|
4178
4462
|
listItem: action.listItem
|
|
4179
4463
|
}) ? removeListItemActionImplementation({
|
|
4180
4464
|
context,
|
|
4181
|
-
action: __spreadProps$8(__spreadValues$
|
|
4465
|
+
action: __spreadProps$8(__spreadValues$e({}, action), {
|
|
4182
4466
|
type: "list item.remove"
|
|
4183
4467
|
})
|
|
4184
4468
|
}) : addListItemActionImplementation({
|
|
4185
4469
|
context,
|
|
4186
|
-
action: __spreadProps$8(__spreadValues$
|
|
4470
|
+
action: __spreadProps$8(__spreadValues$e({}, action), {
|
|
4187
4471
|
type: "list item.add"
|
|
4188
4472
|
})
|
|
4189
4473
|
});
|
|
@@ -4193,7 +4477,7 @@ const toggleListItemActionImplementation = ({
|
|
|
4193
4477
|
}) => {
|
|
4194
4478
|
if (!action.editor.selection)
|
|
4195
4479
|
return;
|
|
4196
|
-
const guards =
|
|
4480
|
+
const guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
4197
4481
|
at: action.editor.selection,
|
|
4198
4482
|
match: (node) => guards.isListBlock(node)
|
|
4199
4483
|
})];
|
|
@@ -4207,7 +4491,7 @@ const toggleListItemActionImplementation = ({
|
|
|
4207
4491
|
}) => {
|
|
4208
4492
|
if (!action.editor.selection)
|
|
4209
4493
|
return;
|
|
4210
|
-
const guards =
|
|
4494
|
+
const guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
4211
4495
|
at: action.editor.selection,
|
|
4212
4496
|
match: (node) => guards.isTextBlock(node)
|
|
4213
4497
|
})];
|
|
@@ -4231,12 +4515,12 @@ function isListItemActive({
|
|
|
4231
4515
|
})];
|
|
4232
4516
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
4233
4517
|
}
|
|
4234
|
-
var __defProp$
|
|
4518
|
+
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
4519
|
for (var prop in b || (b = {}))
|
|
4236
|
-
__hasOwnProp$
|
|
4237
|
-
if (__getOwnPropSymbols$
|
|
4238
|
-
for (var prop of __getOwnPropSymbols$
|
|
4239
|
-
__propIsEnum$
|
|
4520
|
+
__hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4521
|
+
if (__getOwnPropSymbols$d)
|
|
4522
|
+
for (var prop of __getOwnPropSymbols$d(b))
|
|
4523
|
+
__propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4240
4524
|
return a;
|
|
4241
4525
|
}, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
4242
4526
|
const toggleStyleActionImplementation = ({
|
|
@@ -4248,12 +4532,12 @@ const toggleStyleActionImplementation = ({
|
|
|
4248
4532
|
style: action.style
|
|
4249
4533
|
}) ? removeStyleActionImplementation({
|
|
4250
4534
|
context,
|
|
4251
|
-
action: __spreadProps$7(__spreadValues$
|
|
4535
|
+
action: __spreadProps$7(__spreadValues$d({}, action), {
|
|
4252
4536
|
type: "style.remove"
|
|
4253
4537
|
})
|
|
4254
4538
|
}) : addStyleActionImplementation({
|
|
4255
4539
|
context,
|
|
4256
|
-
action: __spreadProps$7(__spreadValues$
|
|
4540
|
+
action: __spreadProps$7(__spreadValues$d({}, action), {
|
|
4257
4541
|
type: "style.add"
|
|
4258
4542
|
})
|
|
4259
4543
|
});
|
|
@@ -4263,7 +4547,7 @@ const toggleStyleActionImplementation = ({
|
|
|
4263
4547
|
}) => {
|
|
4264
4548
|
if (!action.editor.selection)
|
|
4265
4549
|
return;
|
|
4266
|
-
const defaultStyle = context.schema.styles[0].value, guards =
|
|
4550
|
+
const defaultStyle = context.schema.styles[0].value, guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
4267
4551
|
at: action.editor.selection,
|
|
4268
4552
|
match: (node) => guards.isTextBlock(node)
|
|
4269
4553
|
})];
|
|
@@ -4279,7 +4563,7 @@ const toggleStyleActionImplementation = ({
|
|
|
4279
4563
|
}) => {
|
|
4280
4564
|
if (!action.editor.selection)
|
|
4281
4565
|
return;
|
|
4282
|
-
const guards =
|
|
4566
|
+
const guards = selector_isSelectionCollapsed.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
4283
4567
|
at: action.editor.selection,
|
|
4284
4568
|
match: (node) => guards.isTextBlock(node)
|
|
4285
4569
|
})];
|
|
@@ -4302,12 +4586,12 @@ function isStyleActive({
|
|
|
4302
4586
|
})];
|
|
4303
4587
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
4304
4588
|
}
|
|
4305
|
-
var __defProp$
|
|
4589
|
+
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
4590
|
for (var prop in b || (b = {}))
|
|
4307
|
-
__hasOwnProp$
|
|
4308
|
-
if (__getOwnPropSymbols$
|
|
4309
|
-
for (var prop of __getOwnPropSymbols$
|
|
4310
|
-
__propIsEnum$
|
|
4591
|
+
__hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4592
|
+
if (__getOwnPropSymbols$c)
|
|
4593
|
+
for (var prop of __getOwnPropSymbols$c(b))
|
|
4594
|
+
__propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4311
4595
|
return a;
|
|
4312
4596
|
};
|
|
4313
4597
|
const debug$6 = debugWithName("API:editable");
|
|
@@ -4372,7 +4656,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4372
4656
|
return console.warn(err), !1;
|
|
4373
4657
|
}
|
|
4374
4658
|
},
|
|
4375
|
-
marks: () => __spreadValues$
|
|
4659
|
+
marks: () => __spreadValues$c({}, slate.Editor.marks(editor) || {}).marks || [],
|
|
4376
4660
|
undo: () => editor.undo(),
|
|
4377
4661
|
redo: () => editor.redo(),
|
|
4378
4662
|
select: (selection) => {
|
|
@@ -4420,7 +4704,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4420
4704
|
const child = toSlateValue([{
|
|
4421
4705
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4422
4706
|
_type: types2.block.name,
|
|
4423
|
-
children: [__spreadValues$
|
|
4707
|
+
children: [__spreadValues$c({
|
|
4424
4708
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4425
4709
|
_type: type.name
|
|
4426
4710
|
}, value || {})]
|
|
@@ -4684,7 +4968,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4684
4968
|
continue;
|
|
4685
4969
|
const annotationKey = context.keyGenerator(), markDefs = (_a = block.markDefs) != null ? _a : [];
|
|
4686
4970
|
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (slate.Transforms.setNodes(editor, {
|
|
4687
|
-
markDefs: [...markDefs, __spreadValues$
|
|
4971
|
+
markDefs: [...markDefs, __spreadValues$c({
|
|
4688
4972
|
_type: action.annotation.name,
|
|
4689
4973
|
_key: annotationKey
|
|
4690
4974
|
}, action.annotation.value)]
|
|
@@ -4861,19 +5145,19 @@ function insertBlock({
|
|
|
4861
5145
|
});
|
|
4862
5146
|
}
|
|
4863
5147
|
}
|
|
4864
|
-
var __defProp$
|
|
5148
|
+
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
5149
|
for (var prop in b || (b = {}))
|
|
4866
|
-
__hasOwnProp$
|
|
4867
|
-
if (__getOwnPropSymbols$
|
|
4868
|
-
for (var prop of __getOwnPropSymbols$
|
|
4869
|
-
__propIsEnum$
|
|
5150
|
+
__hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
5151
|
+
if (__getOwnPropSymbols$b)
|
|
5152
|
+
for (var prop of __getOwnPropSymbols$b(b))
|
|
5153
|
+
__propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
4870
5154
|
return a;
|
|
4871
5155
|
};
|
|
4872
5156
|
const insertBlockObjectActionImplementation = ({
|
|
4873
5157
|
context,
|
|
4874
5158
|
action
|
|
4875
5159
|
}) => {
|
|
4876
|
-
const block = toSlateValue([__spreadValues$
|
|
5160
|
+
const block = toSlateValue([__spreadValues$b({
|
|
4877
5161
|
_key: context.keyGenerator(),
|
|
4878
5162
|
_type: action.blockObject.name
|
|
4879
5163
|
}, action.blockObject.value ? action.blockObject.value : {})], {
|
|
@@ -4886,12 +5170,12 @@ const insertBlockObjectActionImplementation = ({
|
|
|
4886
5170
|
schema: context.schema
|
|
4887
5171
|
});
|
|
4888
5172
|
};
|
|
4889
|
-
var __defProp$
|
|
5173
|
+
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
5174
|
for (var prop in b || (b = {}))
|
|
4891
|
-
__hasOwnProp$
|
|
4892
|
-
if (__getOwnPropSymbols$
|
|
4893
|
-
for (var prop of __getOwnPropSymbols$
|
|
4894
|
-
__propIsEnum$
|
|
5175
|
+
__hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
5176
|
+
if (__getOwnPropSymbols$a)
|
|
5177
|
+
for (var prop of __getOwnPropSymbols$a(b))
|
|
5178
|
+
__propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
4895
5179
|
return a;
|
|
4896
5180
|
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
4897
5181
|
const insertBreakActionImplementation = ({
|
|
@@ -4987,7 +5271,7 @@ const insertBreakActionImplementation = ({
|
|
|
4987
5271
|
}
|
|
4988
5272
|
const newMarkDefs = nextNode.markDefs.map((markDef) => {
|
|
4989
5273
|
var _a3;
|
|
4990
|
-
return __spreadProps$6(__spreadValues$
|
|
5274
|
+
return __spreadProps$6(__spreadValues$a({}, markDef), {
|
|
4991
5275
|
_key: (_a3 = newMarkDefKeys.get(markDef._key)) != null ? _a3 : markDef._key
|
|
4992
5276
|
});
|
|
4993
5277
|
});
|
|
@@ -5011,17 +5295,17 @@ const insertBreakActionImplementation = ({
|
|
|
5011
5295
|
}) => {
|
|
5012
5296
|
insertBreakActionImplementation({
|
|
5013
5297
|
context,
|
|
5014
|
-
action: __spreadProps$6(__spreadValues$
|
|
5298
|
+
action: __spreadProps$6(__spreadValues$a({}, action), {
|
|
5015
5299
|
type: "insert.break"
|
|
5016
5300
|
})
|
|
5017
5301
|
});
|
|
5018
5302
|
};
|
|
5019
|
-
var __defProp$
|
|
5303
|
+
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
5304
|
for (var prop in b || (b = {}))
|
|
5021
|
-
__hasOwnProp$
|
|
5022
|
-
if (__getOwnPropSymbols$
|
|
5023
|
-
for (var prop of __getOwnPropSymbols$
|
|
5024
|
-
__propIsEnum$
|
|
5305
|
+
__hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5306
|
+
if (__getOwnPropSymbols$9)
|
|
5307
|
+
for (var prop of __getOwnPropSymbols$9(b))
|
|
5308
|
+
__propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
5025
5309
|
return a;
|
|
5026
5310
|
};
|
|
5027
5311
|
const insertInlineObjectActionImplementation = ({
|
|
@@ -5048,7 +5332,7 @@ const insertInlineObjectActionImplementation = ({
|
|
|
5048
5332
|
const block = toSlateValue([{
|
|
5049
5333
|
_type: context.schema.block.name,
|
|
5050
5334
|
_key: context.keyGenerator(),
|
|
5051
|
-
children: [__spreadValues$
|
|
5335
|
+
children: [__spreadValues$9({
|
|
5052
5336
|
_type: action.inlineObject.name,
|
|
5053
5337
|
_key: context.keyGenerator()
|
|
5054
5338
|
}, (_b = action.inlineObject.value) != null ? _b : {})]
|
|
@@ -5061,12 +5345,12 @@ const insertInlineObjectActionImplementation = ({
|
|
|
5061
5345
|
}
|
|
5062
5346
|
slate.Transforms.insertNodes(action.editor, child);
|
|
5063
5347
|
};
|
|
5064
|
-
var __defProp$
|
|
5348
|
+
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
5349
|
for (var prop in b || (b = {}))
|
|
5066
|
-
__hasOwnProp$
|
|
5067
|
-
if (__getOwnPropSymbols$
|
|
5068
|
-
for (var prop of __getOwnPropSymbols$
|
|
5069
|
-
__propIsEnum$
|
|
5350
|
+
__hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5351
|
+
if (__getOwnPropSymbols$8)
|
|
5352
|
+
for (var prop of __getOwnPropSymbols$8(b))
|
|
5353
|
+
__propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5070
5354
|
return a;
|
|
5071
5355
|
};
|
|
5072
5356
|
const insertSpanActionImplementation = ({
|
|
@@ -5086,7 +5370,7 @@ const insertSpanActionImplementation = ({
|
|
|
5086
5370
|
console.error("Unable to perform action without focus block", action);
|
|
5087
5371
|
return;
|
|
5088
5372
|
}
|
|
5089
|
-
const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$
|
|
5373
|
+
const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$8({
|
|
5090
5374
|
_type: annotation.name,
|
|
5091
5375
|
_key: context.keyGenerator()
|
|
5092
5376
|
}, annotation.value)) : void 0;
|
|
@@ -5099,12 +5383,12 @@ const insertSpanActionImplementation = ({
|
|
|
5099
5383
|
marks: [...(_c = annotations == null ? void 0 : annotations.map((annotation) => annotation._key)) != null ? _c : [], ...(_d = action.decorators) != null ? _d : []]
|
|
5100
5384
|
});
|
|
5101
5385
|
};
|
|
5102
|
-
var __defProp$
|
|
5386
|
+
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
5387
|
for (var prop in b || (b = {}))
|
|
5104
|
-
__hasOwnProp$
|
|
5105
|
-
if (__getOwnPropSymbols$
|
|
5106
|
-
for (var prop of __getOwnPropSymbols$
|
|
5107
|
-
__propIsEnum$
|
|
5388
|
+
__hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5389
|
+
if (__getOwnPropSymbols$7)
|
|
5390
|
+
for (var prop of __getOwnPropSymbols$7(b))
|
|
5391
|
+
__propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5108
5392
|
return a;
|
|
5109
5393
|
};
|
|
5110
5394
|
const textBlockSetActionImplementation = ({
|
|
@@ -5120,7 +5404,7 @@ const textBlockSetActionImplementation = ({
|
|
|
5120
5404
|
offset: 0
|
|
5121
5405
|
}
|
|
5122
5406
|
}, action.editor);
|
|
5123
|
-
slate.Transforms.setNodes(action.editor, __spreadValues$
|
|
5407
|
+
slate.Transforms.setNodes(action.editor, __spreadValues$7(__spreadValues$7(__spreadValues$7({}, action.style ? {
|
|
5124
5408
|
style: action.style
|
|
5125
5409
|
} : {}), action.listItem ? {
|
|
5126
5410
|
listItem: action.listItem
|
|
@@ -5146,12 +5430,12 @@ const textBlockSetActionImplementation = ({
|
|
|
5146
5430
|
at
|
|
5147
5431
|
});
|
|
5148
5432
|
};
|
|
5149
|
-
var __defProp$
|
|
5433
|
+
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
5434
|
for (var prop in b || (b = {}))
|
|
5151
|
-
__hasOwnProp$
|
|
5152
|
-
if (__getOwnPropSymbols$
|
|
5153
|
-
for (var prop of __getOwnPropSymbols$
|
|
5154
|
-
__propIsEnum$
|
|
5435
|
+
__hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5436
|
+
if (__getOwnPropSymbols$6)
|
|
5437
|
+
for (var prop of __getOwnPropSymbols$6(b))
|
|
5438
|
+
__propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5155
5439
|
return a;
|
|
5156
5440
|
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
5157
5441
|
const behaviorActionImplementations = {
|
|
@@ -5249,7 +5533,7 @@ const behaviorActionImplementations = {
|
|
|
5249
5533
|
_type: context.schema.block.name,
|
|
5250
5534
|
style: (_a = context.schema.styles[0].value) != null ? _a : "normal",
|
|
5251
5535
|
markDefs: [],
|
|
5252
|
-
children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$
|
|
5536
|
+
children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$6({}, child), {
|
|
5253
5537
|
_key: context.keyGenerator()
|
|
5254
5538
|
}))) != null ? _d : [{
|
|
5255
5539
|
_type: context.schema.span.name,
|
|
@@ -5315,7 +5599,7 @@ const behaviorActionImplementations = {
|
|
|
5315
5599
|
const newSelection = toSlateRange(action.selection, action.editor);
|
|
5316
5600
|
newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
|
|
5317
5601
|
},
|
|
5318
|
-
"select
|
|
5602
|
+
"select.previous block": ({
|
|
5319
5603
|
action
|
|
5320
5604
|
}) => {
|
|
5321
5605
|
if (!action.editor.selection) {
|
|
@@ -5330,7 +5614,7 @@ const behaviorActionImplementations = {
|
|
|
5330
5614
|
const previousBlockPath = slate.Path.previous(blockPath);
|
|
5331
5615
|
slate.Transforms.select(action.editor, previousBlockPath);
|
|
5332
5616
|
},
|
|
5333
|
-
"select
|
|
5617
|
+
"select.next block": ({
|
|
5334
5618
|
action
|
|
5335
5619
|
}) => {
|
|
5336
5620
|
if (!action.editor.selection) {
|
|
@@ -5344,7 +5628,7 @@ const behaviorActionImplementations = {
|
|
|
5344
5628
|
action
|
|
5345
5629
|
}) => {
|
|
5346
5630
|
const selection = action.editor.selection;
|
|
5347
|
-
selection && (slate.Transforms.select(action.editor, __spreadValues$
|
|
5631
|
+
selection && (slate.Transforms.select(action.editor, __spreadValues$6({}, selection)), action.editor.selection = __spreadValues$6({}, selection));
|
|
5348
5632
|
},
|
|
5349
5633
|
"style.toggle": toggleStyleActionImplementation,
|
|
5350
5634
|
"style.add": addStyleActionImplementation,
|
|
@@ -5436,15 +5720,15 @@ function performAction({
|
|
|
5436
5720
|
});
|
|
5437
5721
|
break;
|
|
5438
5722
|
}
|
|
5439
|
-
case "select
|
|
5440
|
-
behaviorActionImplementations["select
|
|
5723
|
+
case "select.previous block": {
|
|
5724
|
+
behaviorActionImplementations["select.previous block"]({
|
|
5441
5725
|
context,
|
|
5442
5726
|
action
|
|
5443
5727
|
});
|
|
5444
5728
|
break;
|
|
5445
5729
|
}
|
|
5446
|
-
case "select
|
|
5447
|
-
behaviorActionImplementations["select
|
|
5730
|
+
case "select.next block": {
|
|
5731
|
+
behaviorActionImplementations["select.next block"]({
|
|
5448
5732
|
context,
|
|
5449
5733
|
action
|
|
5450
5734
|
});
|
|
@@ -5616,6 +5900,22 @@ function performDefaultAction({
|
|
|
5616
5900
|
});
|
|
5617
5901
|
}
|
|
5618
5902
|
}
|
|
5903
|
+
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) => {
|
|
5904
|
+
for (var prop in b || (b = {}))
|
|
5905
|
+
__hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5906
|
+
if (__getOwnPropSymbols$5)
|
|
5907
|
+
for (var prop of __getOwnPropSymbols$5(b))
|
|
5908
|
+
__propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5909
|
+
return a;
|
|
5910
|
+
};
|
|
5911
|
+
function getActiveDecorators({
|
|
5912
|
+
schema: schema2,
|
|
5913
|
+
slateEditorInstance
|
|
5914
|
+
}) {
|
|
5915
|
+
var _a, _b;
|
|
5916
|
+
const decorators = schema2.decorators.map((decorator) => decorator.value);
|
|
5917
|
+
return ((_b = __spreadValues$5({}, (_a = slate.Editor.marks(slateEditorInstance)) != null ? _a : {}).marks) != null ? _b : []).filter((mark) => decorators.includes(mark));
|
|
5918
|
+
}
|
|
5619
5919
|
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
5920
|
for (var prop in b || (b = {}))
|
|
5621
5921
|
__hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
@@ -5648,6 +5948,12 @@ const editorMachine = xstate.setup({
|
|
|
5648
5948
|
"emit mutation event": xstate.emit(({
|
|
5649
5949
|
event
|
|
5650
5950
|
}) => (xstate.assertEvent(event, "mutation"), event)),
|
|
5951
|
+
"emit read only": xstate.emit({
|
|
5952
|
+
type: "read only"
|
|
5953
|
+
}),
|
|
5954
|
+
"emit editable": xstate.emit({
|
|
5955
|
+
type: "editable"
|
|
5956
|
+
}),
|
|
5651
5957
|
"defer event": xstate.assign({
|
|
5652
5958
|
pendingEvents: ({
|
|
5653
5959
|
context,
|
|
@@ -5661,6 +5967,9 @@ const editorMachine = xstate.setup({
|
|
|
5661
5967
|
for (const event of context.pendingEvents)
|
|
5662
5968
|
enqueue(xstate.emit(event));
|
|
5663
5969
|
}),
|
|
5970
|
+
"emit ready": xstate.emit({
|
|
5971
|
+
type: "ready"
|
|
5972
|
+
}),
|
|
5664
5973
|
"clear pending events": xstate.assign({
|
|
5665
5974
|
pendingEvents: []
|
|
5666
5975
|
}),
|
|
@@ -5684,18 +5993,11 @@ const editorMachine = xstate.setup({
|
|
|
5684
5993
|
});
|
|
5685
5994
|
return;
|
|
5686
5995
|
}
|
|
5687
|
-
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)
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
type: "behavior action intends",
|
|
5693
|
-
editor: event.editor,
|
|
5694
|
-
actionIntends: [defaultAction]
|
|
5695
|
-
});
|
|
5696
|
-
return;
|
|
5697
|
-
}
|
|
5698
|
-
const editorContext = {
|
|
5996
|
+
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 = {
|
|
5997
|
+
activeDecorators: getActiveDecorators({
|
|
5998
|
+
schema: context.schema,
|
|
5999
|
+
slateEditorInstance: event.editor
|
|
6000
|
+
}),
|
|
5699
6001
|
keyGenerator: context.keyGenerator,
|
|
5700
6002
|
schema: context.schema,
|
|
5701
6003
|
selection,
|
|
@@ -5746,90 +6048,13 @@ const editorMachine = xstate.setup({
|
|
|
5746
6048
|
keyGenerator: input.keyGenerator,
|
|
5747
6049
|
pendingEvents: [],
|
|
5748
6050
|
schema: input.schema,
|
|
5749
|
-
selection:
|
|
5750
|
-
|
|
6051
|
+
selection: null,
|
|
6052
|
+
initialReadOnly: (_b = input.readOnly) != null ? _b : !1,
|
|
5751
6053
|
maxBlocks: input.maxBlocks,
|
|
5752
6054
|
value: input.value
|
|
5753
6055
|
};
|
|
5754
6056
|
},
|
|
5755
6057
|
on: {
|
|
5756
|
-
"annotation.add": {
|
|
5757
|
-
actions: xstate.emit(({
|
|
5758
|
-
event
|
|
5759
|
-
}) => event),
|
|
5760
|
-
guard: ({
|
|
5761
|
-
context
|
|
5762
|
-
}) => !context.readOnly
|
|
5763
|
-
},
|
|
5764
|
-
"annotation.remove": {
|
|
5765
|
-
actions: xstate.emit(({
|
|
5766
|
-
event
|
|
5767
|
-
}) => event),
|
|
5768
|
-
guard: ({
|
|
5769
|
-
context
|
|
5770
|
-
}) => !context.readOnly
|
|
5771
|
-
},
|
|
5772
|
-
"annotation.toggle": {
|
|
5773
|
-
actions: xstate.emit(({
|
|
5774
|
-
event
|
|
5775
|
-
}) => event),
|
|
5776
|
-
guard: ({
|
|
5777
|
-
context
|
|
5778
|
-
}) => !context.readOnly
|
|
5779
|
-
},
|
|
5780
|
-
blur: {
|
|
5781
|
-
actions: xstate.emit(({
|
|
5782
|
-
event
|
|
5783
|
-
}) => event),
|
|
5784
|
-
guard: ({
|
|
5785
|
-
context
|
|
5786
|
-
}) => !context.readOnly
|
|
5787
|
-
},
|
|
5788
|
-
"decorator.*": {
|
|
5789
|
-
actions: xstate.emit(({
|
|
5790
|
-
event
|
|
5791
|
-
}) => event),
|
|
5792
|
-
guard: ({
|
|
5793
|
-
context
|
|
5794
|
-
}) => !context.readOnly
|
|
5795
|
-
},
|
|
5796
|
-
focus: {
|
|
5797
|
-
actions: xstate.emit(({
|
|
5798
|
-
event
|
|
5799
|
-
}) => event),
|
|
5800
|
-
guard: ({
|
|
5801
|
-
context
|
|
5802
|
-
}) => !context.readOnly
|
|
5803
|
-
},
|
|
5804
|
-
"insert.*": {
|
|
5805
|
-
actions: xstate.emit(({
|
|
5806
|
-
event
|
|
5807
|
-
}) => event),
|
|
5808
|
-
guard: ({
|
|
5809
|
-
context
|
|
5810
|
-
}) => !context.readOnly
|
|
5811
|
-
},
|
|
5812
|
-
"list item.*": {
|
|
5813
|
-
actions: xstate.emit(({
|
|
5814
|
-
event
|
|
5815
|
-
}) => event),
|
|
5816
|
-
guard: ({
|
|
5817
|
-
context
|
|
5818
|
-
}) => !context.readOnly
|
|
5819
|
-
},
|
|
5820
|
-
"style.*": {
|
|
5821
|
-
actions: xstate.emit(({
|
|
5822
|
-
event
|
|
5823
|
-
}) => event),
|
|
5824
|
-
guard: ({
|
|
5825
|
-
context
|
|
5826
|
-
}) => !context.readOnly
|
|
5827
|
-
},
|
|
5828
|
-
ready: {
|
|
5829
|
-
actions: xstate.emit(({
|
|
5830
|
-
event
|
|
5831
|
-
}) => event)
|
|
5832
|
-
},
|
|
5833
6058
|
unset: {
|
|
5834
6059
|
actions: xstate.emit(({
|
|
5835
6060
|
event
|
|
@@ -5854,10 +6079,7 @@ const editorMachine = xstate.setup({
|
|
|
5854
6079
|
actions: [xstate.assign({
|
|
5855
6080
|
selection: ({
|
|
5856
6081
|
event
|
|
5857
|
-
}) =>
|
|
5858
|
-
var _a;
|
|
5859
|
-
return (_a = event.selection) != null ? _a : void 0;
|
|
5860
|
-
}
|
|
6082
|
+
}) => event.selection
|
|
5861
6083
|
}), xstate.emit(({
|
|
5862
6084
|
event
|
|
5863
6085
|
}) => event)]
|
|
@@ -5900,18 +6122,6 @@ const editorMachine = xstate.setup({
|
|
|
5900
6122
|
}) => event.value
|
|
5901
6123
|
})
|
|
5902
6124
|
},
|
|
5903
|
-
"toggle readOnly": {
|
|
5904
|
-
actions: [xstate.assign({
|
|
5905
|
-
readOnly: ({
|
|
5906
|
-
context
|
|
5907
|
-
}) => !context.readOnly
|
|
5908
|
-
}), xstate.emit(({
|
|
5909
|
-
context
|
|
5910
|
-
}) => ({
|
|
5911
|
-
type: "readOnly toggled",
|
|
5912
|
-
readOnly: context.readOnly
|
|
5913
|
-
}))]
|
|
5914
|
-
},
|
|
5915
6125
|
"update maxBlocks": {
|
|
5916
6126
|
actions: xstate.assign({
|
|
5917
6127
|
maxBlocks: ({
|
|
@@ -5919,12 +6129,6 @@ const editorMachine = xstate.setup({
|
|
|
5919
6129
|
}) => event.maxBlocks
|
|
5920
6130
|
})
|
|
5921
6131
|
},
|
|
5922
|
-
"behavior event": {
|
|
5923
|
-
actions: "handle behavior event",
|
|
5924
|
-
guard: ({
|
|
5925
|
-
context
|
|
5926
|
-
}) => !context.readOnly
|
|
5927
|
-
},
|
|
5928
6132
|
"behavior action intends": {
|
|
5929
6133
|
actions: [({
|
|
5930
6134
|
context,
|
|
@@ -5953,49 +6157,154 @@ const editorMachine = xstate.setup({
|
|
|
5953
6157
|
})]
|
|
5954
6158
|
}
|
|
5955
6159
|
},
|
|
5956
|
-
|
|
6160
|
+
type: "parallel",
|
|
5957
6161
|
states: {
|
|
5958
|
-
|
|
5959
|
-
initial: "
|
|
6162
|
+
"edit mode": {
|
|
6163
|
+
initial: "read only",
|
|
5960
6164
|
states: {
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
6165
|
+
"read only": {
|
|
6166
|
+
initial: "determine initial edit mode",
|
|
6167
|
+
states: {
|
|
6168
|
+
"determine initial edit mode": {
|
|
6169
|
+
on: {
|
|
6170
|
+
"done syncing": [{
|
|
6171
|
+
target: "#editor.edit mode.read only.read only",
|
|
6172
|
+
guard: ({
|
|
6173
|
+
context
|
|
6174
|
+
}) => context.initialReadOnly
|
|
6175
|
+
}, {
|
|
6176
|
+
target: "#editor.edit mode.editable"
|
|
6177
|
+
}]
|
|
6178
|
+
}
|
|
5969
6179
|
},
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
6180
|
+
"read only": {
|
|
6181
|
+
on: {
|
|
6182
|
+
"toggle readOnly": {
|
|
6183
|
+
target: "#editor.edit mode.editable",
|
|
6184
|
+
actions: ["emit editable"]
|
|
6185
|
+
}
|
|
6186
|
+
}
|
|
5973
6187
|
}
|
|
5974
6188
|
}
|
|
5975
6189
|
},
|
|
5976
|
-
|
|
6190
|
+
editable: {
|
|
5977
6191
|
on: {
|
|
5978
|
-
"
|
|
5979
|
-
target: "
|
|
6192
|
+
"toggle readOnly": {
|
|
6193
|
+
target: "#editor.edit mode.read only.read only",
|
|
6194
|
+
actions: ["emit read only"]
|
|
6195
|
+
},
|
|
6196
|
+
"behavior event": {
|
|
6197
|
+
actions: "handle behavior event"
|
|
6198
|
+
},
|
|
6199
|
+
"annotation.add": {
|
|
6200
|
+
actions: xstate.emit(({
|
|
6201
|
+
event
|
|
6202
|
+
}) => event)
|
|
6203
|
+
},
|
|
6204
|
+
"annotation.remove": {
|
|
6205
|
+
actions: xstate.emit(({
|
|
6206
|
+
event
|
|
6207
|
+
}) => event)
|
|
6208
|
+
},
|
|
6209
|
+
"annotation.toggle": {
|
|
6210
|
+
actions: xstate.emit(({
|
|
6211
|
+
event
|
|
6212
|
+
}) => event)
|
|
6213
|
+
},
|
|
6214
|
+
blur: {
|
|
6215
|
+
actions: xstate.emit(({
|
|
6216
|
+
event
|
|
6217
|
+
}) => event)
|
|
6218
|
+
},
|
|
6219
|
+
"decorator.*": {
|
|
6220
|
+
actions: xstate.emit(({
|
|
6221
|
+
event
|
|
6222
|
+
}) => event)
|
|
6223
|
+
},
|
|
6224
|
+
focus: {
|
|
6225
|
+
actions: xstate.emit(({
|
|
6226
|
+
event
|
|
6227
|
+
}) => event)
|
|
6228
|
+
},
|
|
6229
|
+
"insert.*": {
|
|
6230
|
+
actions: xstate.emit(({
|
|
6231
|
+
event
|
|
6232
|
+
}) => event)
|
|
6233
|
+
},
|
|
6234
|
+
"list item.*": {
|
|
6235
|
+
actions: xstate.emit(({
|
|
6236
|
+
event
|
|
6237
|
+
}) => event)
|
|
5980
6238
|
},
|
|
6239
|
+
"style.*": {
|
|
6240
|
+
actions: xstate.emit(({
|
|
6241
|
+
event
|
|
6242
|
+
}) => event)
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
6246
|
+
}
|
|
6247
|
+
},
|
|
6248
|
+
setup: {
|
|
6249
|
+
initial: "setting up",
|
|
6250
|
+
states: {
|
|
6251
|
+
"setting up": {
|
|
6252
|
+
exit: ["emit ready"],
|
|
6253
|
+
on: {
|
|
5981
6254
|
patch: {
|
|
5982
6255
|
actions: "defer event"
|
|
5983
6256
|
},
|
|
5984
6257
|
mutation: {
|
|
5985
6258
|
actions: "defer event"
|
|
6259
|
+
},
|
|
6260
|
+
"done syncing": {
|
|
6261
|
+
target: "pristine"
|
|
6262
|
+
}
|
|
6263
|
+
}
|
|
6264
|
+
},
|
|
6265
|
+
pristine: {
|
|
6266
|
+
initial: "idle",
|
|
6267
|
+
states: {
|
|
6268
|
+
idle: {
|
|
6269
|
+
on: {
|
|
6270
|
+
normalizing: {
|
|
6271
|
+
target: "normalizing"
|
|
6272
|
+
},
|
|
6273
|
+
patch: {
|
|
6274
|
+
actions: "defer event",
|
|
6275
|
+
target: "#editor.setup.dirty"
|
|
6276
|
+
},
|
|
6277
|
+
mutation: {
|
|
6278
|
+
actions: "defer event",
|
|
6279
|
+
target: "#editor.setup.dirty"
|
|
6280
|
+
}
|
|
6281
|
+
}
|
|
6282
|
+
},
|
|
6283
|
+
normalizing: {
|
|
6284
|
+
on: {
|
|
6285
|
+
"done normalizing": {
|
|
6286
|
+
target: "idle"
|
|
6287
|
+
},
|
|
6288
|
+
patch: {
|
|
6289
|
+
actions: "defer event"
|
|
6290
|
+
},
|
|
6291
|
+
mutation: {
|
|
6292
|
+
actions: "defer event"
|
|
6293
|
+
}
|
|
6294
|
+
}
|
|
5986
6295
|
}
|
|
5987
6296
|
}
|
|
5988
|
-
}
|
|
5989
|
-
}
|
|
5990
|
-
},
|
|
5991
|
-
dirty: {
|
|
5992
|
-
entry: ["emit pending events", "clear pending events"],
|
|
5993
|
-
on: {
|
|
5994
|
-
patch: {
|
|
5995
|
-
actions: "emit patch event"
|
|
5996
6297
|
},
|
|
5997
|
-
|
|
5998
|
-
|
|
6298
|
+
dirty: {
|
|
6299
|
+
entry: ["emit pending events", "clear pending events"],
|
|
6300
|
+
on: {
|
|
6301
|
+
patch: {
|
|
6302
|
+
actions: "emit patch event"
|
|
6303
|
+
},
|
|
6304
|
+
mutation: {
|
|
6305
|
+
actions: "emit mutation event"
|
|
6306
|
+
}
|
|
6307
|
+
}
|
|
5999
6308
|
}
|
|
6000
6309
|
}
|
|
6001
6310
|
}
|
|
@@ -6044,7 +6353,7 @@ function editorConfigToMachineInput(config) {
|
|
|
6044
6353
|
keyGenerator: (_a = config.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6045
6354
|
maxBlocks: config.maxBlocks,
|
|
6046
6355
|
readOnly: config.readOnly,
|
|
6047
|
-
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) :
|
|
6356
|
+
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
6048
6357
|
value: config.initialValue
|
|
6049
6358
|
};
|
|
6050
6359
|
}
|
|
@@ -6123,7 +6432,7 @@ class PortableTextEditor extends React.Component {
|
|
|
6123
6432
|
}), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
|
|
6124
6433
|
}
|
|
6125
6434
|
componentDidUpdate(prevProps) {
|
|
6126
|
-
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes =
|
|
6435
|
+
!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({
|
|
6127
6436
|
type: "update schema",
|
|
6128
6437
|
schema: this.schemaTypes
|
|
6129
6438
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
@@ -6144,7 +6453,7 @@ class PortableTextEditor extends React.Component {
|
|
|
6144
6453
|
/* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
|
|
6145
6454
|
this.props.editor || this.props.onChange(change), this.change$.next(change);
|
|
6146
6455
|
} }),
|
|
6147
|
-
/* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor: this.editor._internal.editorActor,
|
|
6456
|
+
/* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor: this.editor._internal.editorActor, slateEditor: this.editor._internal.slateEditor.instance }),
|
|
6148
6457
|
/* @__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 }) }) }) })
|
|
6149
6458
|
] });
|
|
6150
6459
|
}
|
|
@@ -6329,7 +6638,8 @@ function RouteEventsToChanges(props) {
|
|
|
6329
6638
|
case "list item.toggle":
|
|
6330
6639
|
case "style.toggle":
|
|
6331
6640
|
case "patches":
|
|
6332
|
-
case "
|
|
6641
|
+
case "editable":
|
|
6642
|
+
case "read only":
|
|
6333
6643
|
break bb5;
|
|
6334
6644
|
default:
|
|
6335
6645
|
handleChange(event);
|
|
@@ -6739,10 +7049,16 @@ function _insertFragment(editor, fragment, schemaTypes) {
|
|
|
6739
7049
|
})) : editor.insertFragment(fragment);
|
|
6740
7050
|
}), editor.onChange();
|
|
6741
7051
|
}
|
|
6742
|
-
function withSyncRangeDecorations(
|
|
7052
|
+
function withSyncRangeDecorations({
|
|
7053
|
+
editorActor,
|
|
7054
|
+
slateEditor,
|
|
7055
|
+
syncRangeDecorations
|
|
7056
|
+
}) {
|
|
6743
7057
|
const originalApply = slateEditor.apply;
|
|
6744
7058
|
return slateEditor.apply = (op) => {
|
|
6745
|
-
originalApply(op),
|
|
7059
|
+
originalApply(op), !editorActor.getSnapshot().matches({
|
|
7060
|
+
"edit mode": "read only"
|
|
7061
|
+
}) && op.type !== "set_selection" && syncRangeDecorations(op);
|
|
6746
7062
|
}, () => {
|
|
6747
7063
|
slateEditor.apply = originalApply;
|
|
6748
7064
|
};
|
|
@@ -6810,7 +7126,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6810
7126
|
"spellCheck"
|
|
6811
7127
|
]), portableTextEditor = usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), [rangeDecorationState, setRangeDecorationsState] = React.useState([]);
|
|
6812
7128
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
6813
|
-
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.
|
|
7129
|
+
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
7130
|
+
"edit mode": "read only"
|
|
7131
|
+
})), schemaTypes = react.useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name;
|
|
6814
7132
|
React.useMemo(() => {
|
|
6815
7133
|
const withInsertData = createWithInsertData(editorActor, schemaTypes);
|
|
6816
7134
|
if (readOnly)
|
|
@@ -6879,7 +7197,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6879
7197
|
}, [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]);
|
|
6880
7198
|
React.useEffect(() => {
|
|
6881
7199
|
const onReady = editorActor.on("ready", () => {
|
|
6882
|
-
restoreSelectionFromProps();
|
|
7200
|
+
syncRangeDecorations(), restoreSelectionFromProps();
|
|
6883
7201
|
}), onInvalidValue = editorActor.on("invalid value", () => {
|
|
6884
7202
|
setHasInvalidValue(!0);
|
|
6885
7203
|
}), onValueChanged = editorActor.on("value changed", () => {
|
|
@@ -6888,7 +7206,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6888
7206
|
return () => {
|
|
6889
7207
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
6890
7208
|
};
|
|
6891
|
-
}, [editorActor, restoreSelectionFromProps]), React.useEffect(() => {
|
|
7209
|
+
}, [editorActor, restoreSelectionFromProps, syncRangeDecorations]), React.useEffect(() => {
|
|
6892
7210
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
6893
7211
|
}, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
|
|
6894
7212
|
const [syncedRangeDecorations, setSyncedRangeDecorations] = React.useState(!1);
|
|
@@ -6897,9 +7215,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6897
7215
|
}, [syncRangeDecorations, syncedRangeDecorations]), React.useEffect(() => {
|
|
6898
7216
|
isEqual__default.default(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
|
|
6899
7217
|
}, [rangeDecorations, syncRangeDecorations]), React.useEffect(() => {
|
|
6900
|
-
const teardown = withSyncRangeDecorations(
|
|
7218
|
+
const teardown = withSyncRangeDecorations({
|
|
7219
|
+
editorActor,
|
|
7220
|
+
slateEditor,
|
|
7221
|
+
syncRangeDecorations
|
|
7222
|
+
});
|
|
6901
7223
|
return () => teardown();
|
|
6902
|
-
}, [slateEditor, syncRangeDecorations]);
|
|
7224
|
+
}, [editorActor, slateEditor, syncRangeDecorations]);
|
|
6903
7225
|
const handleCopy = React.useCallback((event) => {
|
|
6904
7226
|
onCopy ? onCopy(event) !== void 0 && event.preventDefault() : event.nativeEvent.clipboardData && editorActor.send({
|
|
6905
7227
|
type: "behavior event",
|
|
@@ -7088,7 +7410,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7088
7410
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
7089
7411
|
const EditorContext = React__default.default.createContext(void 0);
|
|
7090
7412
|
function EditorProvider(props) {
|
|
7091
|
-
const $ = reactCompilerRuntime.c(
|
|
7413
|
+
const $ = reactCompilerRuntime.c(28), editor = useCreateEditor(props.initialConfig), editorActor = editor._internal.editorActor, slateEditor = editor._internal.slateEditor;
|
|
7092
7414
|
let t0, t1;
|
|
7093
7415
|
$[0] !== editor ? (t1 = new PortableTextEditor({
|
|
7094
7416
|
editor
|
|
@@ -7101,21 +7423,21 @@ function EditorProvider(props) {
|
|
|
7101
7423
|
let t3;
|
|
7102
7424
|
$[4] !== editorActor || $[5] !== t2 ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { editorActor, onChange: t2 }), $[4] = editorActor, $[5] = t2, $[6] = t3) : t3 = $[6];
|
|
7103
7425
|
let t4;
|
|
7104
|
-
$[7] !==
|
|
7426
|
+
$[7] !== editorActor || $[8] !== slateEditor.instance ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor, slateEditor: slateEditor.instance }), $[7] = editorActor, $[8] = slateEditor.instance, $[9] = t4) : t4 = $[9];
|
|
7105
7427
|
let t5;
|
|
7106
|
-
$[
|
|
7428
|
+
$[10] !== editorActor || $[11] !== props.children ? (t5 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor, children: props.children }), $[10] = editorActor, $[11] = props.children, $[12] = t5) : t5 = $[12];
|
|
7107
7429
|
let t6;
|
|
7108
|
-
$[
|
|
7430
|
+
$[13] !== portableTextEditor || $[14] !== t5 ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: portableTextEditor, children: t5 }), $[13] = portableTextEditor, $[14] = t5, $[15] = t6) : t6 = $[15];
|
|
7109
7431
|
let t7;
|
|
7110
|
-
$[
|
|
7432
|
+
$[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];
|
|
7111
7433
|
let t8;
|
|
7112
|
-
$[
|
|
7434
|
+
$[20] !== editorActor || $[21] !== t7 ? (t8 = /* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: editorActor, children: t7 }), $[20] = editorActor, $[21] = t7, $[22] = t8) : t8 = $[22];
|
|
7113
7435
|
let t9;
|
|
7114
|
-
return $[
|
|
7436
|
+
return $[23] !== editor || $[24] !== t3 || $[25] !== t4 || $[26] !== t8 ? (t9 = /* @__PURE__ */ jsxRuntime.jsxs(EditorContext.Provider, { value: editor, children: [
|
|
7115
7437
|
t3,
|
|
7116
7438
|
t4,
|
|
7117
7439
|
t8
|
|
7118
|
-
] }), $[
|
|
7440
|
+
] }), $[23] = editor, $[24] = t3, $[25] = t4, $[26] = t8, $[27] = t9) : t9 = $[27], t9;
|
|
7119
7441
|
}
|
|
7120
7442
|
function useEditor() {
|
|
7121
7443
|
const editor = React__default.default.useContext(EditorContext);
|
|
@@ -7144,6 +7466,10 @@ function useEditorSelector(editor, selector, t0) {
|
|
|
7144
7466
|
let t1;
|
|
7145
7467
|
return $[0] !== editor || $[1] !== selector ? (t1 = (snapshot) => {
|
|
7146
7468
|
const context = {
|
|
7469
|
+
activeDecorators: getActiveDecorators({
|
|
7470
|
+
schema: snapshot.context.schema,
|
|
7471
|
+
slateEditorInstance: editor._internal.slateEditor.instance
|
|
7472
|
+
}),
|
|
7147
7473
|
keyGenerator: snapshot.context.keyGenerator,
|
|
7148
7474
|
schema: snapshot.context.schema,
|
|
7149
7475
|
selection: snapshot.context.selection,
|