@portabletext/editor 1.50.3 → 1.50.4
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/behaviors/index.d.cts +1 -0
- package/lib/behaviors/index.d.ts +1 -0
- package/lib/index.cjs +322 -55
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +323 -55
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +1 -0
- package/lib/plugins/index.d.ts +1 -0
- package/lib/selectors/index.d.cts +1 -0
- package/lib/selectors/index.d.ts +1 -0
- package/lib/utils/index.d.cts +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/package.json +2 -1
- package/src/editor/PortableTextEditor.tsx +22 -22
- package/src/editor/create-slate-editor.tsx +9 -1
- package/src/editor/editor-selector.ts +1 -5
- package/src/editor/editor-snapshot.ts +1 -3
- package/src/editor/plugins/slate-plugin.update-value.ts +30 -0
- package/src/editor/plugins/with-plugins.ts +8 -1
- package/src/internal-utils/apply-operation-to-portable-text.test.ts +175 -0
- package/src/internal-utils/apply-operation-to-portable-text.ts +435 -0
- package/src/internal-utils/create-placeholder-block.ts +20 -0
- package/src/internal-utils/portable-text-node.ts +209 -0
- package/src/types/editor.ts +1 -0
- package/src/internal-utils/__tests__/patchToOperations.test.ts +0 -312
- package/src/internal-utils/slate-children-to-blocks.ts +0 -49
|
@@ -2670,6 +2670,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
2670
2670
|
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
2671
2671
|
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
2672
2672
|
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
2673
|
+
value: Array<PortableTextBlock>
|
|
2673
2674
|
/**
|
|
2674
2675
|
* Use hotkeys
|
|
2675
2676
|
*/
|
package/lib/behaviors/index.d.ts
CHANGED
|
@@ -2670,6 +2670,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
2670
2670
|
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
2671
2671
|
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
2672
2672
|
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
2673
|
+
value: Array<PortableTextBlock>
|
|
2673
2674
|
/**
|
|
2674
2675
|
* Use hotkeys
|
|
2675
2676
|
*/
|
package/lib/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$i = require("debug"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$i = require("debug"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -1348,6 +1348,20 @@ function compileType(rawType) {
|
|
|
1348
1348
|
types: [rawType]
|
|
1349
1349
|
}).get(rawType.name);
|
|
1350
1350
|
}
|
|
1351
|
+
function createPlaceholderBlock(context) {
|
|
1352
|
+
return {
|
|
1353
|
+
_type: context.schema.block.name,
|
|
1354
|
+
_key: context.keyGenerator(),
|
|
1355
|
+
style: context.schema.styles[0].name ?? "normal",
|
|
1356
|
+
markDefs: [],
|
|
1357
|
+
children: [{
|
|
1358
|
+
_type: context.schema.span.name,
|
|
1359
|
+
_key: context.keyGenerator(),
|
|
1360
|
+
text: "",
|
|
1361
|
+
marks: []
|
|
1362
|
+
}]
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1351
1365
|
const insertTextOperationImplementation = ({
|
|
1352
1366
|
operation
|
|
1353
1367
|
}) => {
|
|
@@ -4716,6 +4730,289 @@ function createWithUtils({
|
|
|
4716
4730
|
})[0], editor;
|
|
4717
4731
|
};
|
|
4718
4732
|
}
|
|
4733
|
+
function isEditorNode(node) {
|
|
4734
|
+
return typeof node == "object" && node !== null ? !("_type" in node) && "children" in node && Array.isArray(node.children) : !1;
|
|
4735
|
+
}
|
|
4736
|
+
function isTextBlockNode(context, node) {
|
|
4737
|
+
return util_sliceBlocks.isTypedObject(node) && node._type === context.schema.block.name;
|
|
4738
|
+
}
|
|
4739
|
+
function isSpanNode(context, node) {
|
|
4740
|
+
return typeof node != "object" || node === null || "children" in node ? !1 : "_type" in node ? node._type === context.schema.span.name : "text" in node;
|
|
4741
|
+
}
|
|
4742
|
+
function isPartialSpanNode(node) {
|
|
4743
|
+
return typeof node == "object" && node !== null && "text" in node && typeof node.text == "string";
|
|
4744
|
+
}
|
|
4745
|
+
function isObjectNode(context, node) {
|
|
4746
|
+
return !isEditorNode(node) && !isTextBlockNode(context, node) && !isSpanNode(context, node) && !isPartialSpanNode(node);
|
|
4747
|
+
}
|
|
4748
|
+
function getBlock(root, path) {
|
|
4749
|
+
const index = path.at(0);
|
|
4750
|
+
if (!(index === void 0 || path.length !== 1))
|
|
4751
|
+
return root.children.at(index);
|
|
4752
|
+
}
|
|
4753
|
+
function getNode(context, root, path) {
|
|
4754
|
+
if (path.length === 0)
|
|
4755
|
+
return root;
|
|
4756
|
+
if (path.length === 1)
|
|
4757
|
+
return getBlock(root, path);
|
|
4758
|
+
if (path.length === 2) {
|
|
4759
|
+
const block = getBlock(root, path.slice(0, 1));
|
|
4760
|
+
return !block || !isTextBlockNode(context, block) ? void 0 : block.children.at(path[1]) || void 0;
|
|
4761
|
+
}
|
|
4762
|
+
}
|
|
4763
|
+
function getSpan(context, root, path) {
|
|
4764
|
+
const node = getNode(context, root, path);
|
|
4765
|
+
if (node && isSpanNode(context, node))
|
|
4766
|
+
return node;
|
|
4767
|
+
}
|
|
4768
|
+
function getParent(context, root, path) {
|
|
4769
|
+
if (path.length === 0)
|
|
4770
|
+
return;
|
|
4771
|
+
const parentPath = path.slice(0, -1);
|
|
4772
|
+
if (parentPath.length === 0)
|
|
4773
|
+
return root;
|
|
4774
|
+
const blockIndex = parentPath.at(0);
|
|
4775
|
+
if (blockIndex === void 0 || parentPath.length !== 1)
|
|
4776
|
+
return;
|
|
4777
|
+
const block = root.children.at(blockIndex);
|
|
4778
|
+
if (block && isTextBlockNode(context, block))
|
|
4779
|
+
return block;
|
|
4780
|
+
}
|
|
4781
|
+
function applyOperationToPortableText(context, value, operation) {
|
|
4782
|
+
const draft = immer.createDraft({
|
|
4783
|
+
children: value
|
|
4784
|
+
});
|
|
4785
|
+
try {
|
|
4786
|
+
applyOperationToPortableTextDraft(context, draft, operation);
|
|
4787
|
+
} catch (e) {
|
|
4788
|
+
console.error(e);
|
|
4789
|
+
}
|
|
4790
|
+
return immer.finishDraft(draft).children;
|
|
4791
|
+
}
|
|
4792
|
+
function applyOperationToPortableTextDraft(context, root, operation) {
|
|
4793
|
+
switch (operation.type) {
|
|
4794
|
+
case "insert_node": {
|
|
4795
|
+
const {
|
|
4796
|
+
path,
|
|
4797
|
+
node: insertedNode
|
|
4798
|
+
} = operation, parent = getParent(context, root, path), index = path[path.length - 1];
|
|
4799
|
+
if (!parent || index > parent.children.length)
|
|
4800
|
+
break;
|
|
4801
|
+
if (path.length === 1) {
|
|
4802
|
+
if (isTextBlockNode(context, insertedNode)) {
|
|
4803
|
+
parent.children.splice(index, 0, {
|
|
4804
|
+
...insertedNode,
|
|
4805
|
+
children: insertedNode.children.map((child) => "__inline" in child ? {
|
|
4806
|
+
_key: child._key,
|
|
4807
|
+
_type: child._type,
|
|
4808
|
+
..."value" in child && typeof child.value == "object" ? child.value : {}
|
|
4809
|
+
} : child)
|
|
4810
|
+
});
|
|
4811
|
+
break;
|
|
4812
|
+
}
|
|
4813
|
+
if (slate.Element.isElement(insertedNode) && !("__inline" in insertedNode)) {
|
|
4814
|
+
parent.children.splice(index, 0, {
|
|
4815
|
+
_key: insertedNode._key,
|
|
4816
|
+
_type: insertedNode._type,
|
|
4817
|
+
..."value" in insertedNode && typeof insertedNode.value == "object" ? insertedNode.value : {}
|
|
4818
|
+
});
|
|
4819
|
+
break;
|
|
4820
|
+
}
|
|
4821
|
+
}
|
|
4822
|
+
if (path.length === 2) {
|
|
4823
|
+
if (!isTextBlockNode(context, parent))
|
|
4824
|
+
break;
|
|
4825
|
+
if (isPartialSpanNode(insertedNode)) {
|
|
4826
|
+
parent.children.splice(index, 0, insertedNode);
|
|
4827
|
+
break;
|
|
4828
|
+
}
|
|
4829
|
+
if ("__inline" in insertedNode) {
|
|
4830
|
+
parent.children.splice(index, 0, {
|
|
4831
|
+
_key: insertedNode._key,
|
|
4832
|
+
_type: insertedNode._type,
|
|
4833
|
+
..."value" in insertedNode && typeof insertedNode.value == "object" ? insertedNode.value : {}
|
|
4834
|
+
});
|
|
4835
|
+
break;
|
|
4836
|
+
}
|
|
4837
|
+
}
|
|
4838
|
+
break;
|
|
4839
|
+
}
|
|
4840
|
+
case "insert_text": {
|
|
4841
|
+
const {
|
|
4842
|
+
path,
|
|
4843
|
+
offset,
|
|
4844
|
+
text
|
|
4845
|
+
} = operation;
|
|
4846
|
+
if (text.length === 0) break;
|
|
4847
|
+
const span = getSpan(context, root, path);
|
|
4848
|
+
if (!span)
|
|
4849
|
+
break;
|
|
4850
|
+
const before = span.text.slice(0, offset), after = span.text.slice(offset);
|
|
4851
|
+
span.text = before + text + after;
|
|
4852
|
+
break;
|
|
4853
|
+
}
|
|
4854
|
+
case "merge_node": {
|
|
4855
|
+
const {
|
|
4856
|
+
path
|
|
4857
|
+
} = operation, node = getNode(context, root, path), prevPath = slate.Path.previous(path), prev = getNode(context, root, prevPath), parent = getParent(context, root, path);
|
|
4858
|
+
if (!node || !prev || !parent)
|
|
4859
|
+
break;
|
|
4860
|
+
const index = path[path.length - 1];
|
|
4861
|
+
if (isPartialSpanNode(node) && isPartialSpanNode(prev))
|
|
4862
|
+
prev.text += node.text;
|
|
4863
|
+
else if (isTextBlockNode(context, node) && isTextBlockNode(context, prev))
|
|
4864
|
+
prev.children.push(...node.children);
|
|
4865
|
+
else
|
|
4866
|
+
break;
|
|
4867
|
+
parent.children.splice(index, 1);
|
|
4868
|
+
break;
|
|
4869
|
+
}
|
|
4870
|
+
case "move_node": {
|
|
4871
|
+
const {
|
|
4872
|
+
path,
|
|
4873
|
+
newPath
|
|
4874
|
+
} = operation;
|
|
4875
|
+
if (slate.Path.isAncestor(path, newPath))
|
|
4876
|
+
break;
|
|
4877
|
+
const node = getNode(context, root, path), parent = getParent(context, root, path), index = path[path.length - 1];
|
|
4878
|
+
if (!node || !parent)
|
|
4879
|
+
break;
|
|
4880
|
+
parent.children.splice(index, 1);
|
|
4881
|
+
const truePath = slate.Path.transform(path, operation), newParent = getNode(context, root, slate.Path.parent(truePath)), newIndex = truePath[truePath.length - 1];
|
|
4882
|
+
if (!newParent || !("children" in newParent) || !Array.isArray(newParent.children))
|
|
4883
|
+
break;
|
|
4884
|
+
newParent.children.splice(newIndex, 0, node);
|
|
4885
|
+
break;
|
|
4886
|
+
}
|
|
4887
|
+
case "remove_node": {
|
|
4888
|
+
const {
|
|
4889
|
+
path
|
|
4890
|
+
} = operation, index = path[path.length - 1];
|
|
4891
|
+
getParent(context, root, path)?.children.splice(index, 1);
|
|
4892
|
+
break;
|
|
4893
|
+
}
|
|
4894
|
+
case "remove_text": {
|
|
4895
|
+
const {
|
|
4896
|
+
path,
|
|
4897
|
+
offset,
|
|
4898
|
+
text
|
|
4899
|
+
} = operation;
|
|
4900
|
+
if (text.length === 0)
|
|
4901
|
+
break;
|
|
4902
|
+
const span = getSpan(context, root, path);
|
|
4903
|
+
if (!span)
|
|
4904
|
+
break;
|
|
4905
|
+
const before = span.text.slice(0, offset), after = span.text.slice(offset + text.length);
|
|
4906
|
+
span.text = before + after;
|
|
4907
|
+
break;
|
|
4908
|
+
}
|
|
4909
|
+
case "set_node": {
|
|
4910
|
+
const {
|
|
4911
|
+
path,
|
|
4912
|
+
properties,
|
|
4913
|
+
newProperties
|
|
4914
|
+
} = operation, node = getNode(context, root, path);
|
|
4915
|
+
if (!node || isEditorNode(node))
|
|
4916
|
+
break;
|
|
4917
|
+
if (isObjectNode(context, node)) {
|
|
4918
|
+
const valueBefore = "value" in properties && typeof properties.value == "object" ? properties.value : {}, valueAfter = "value" in newProperties && typeof newProperties.value == "object" ? newProperties.value : {};
|
|
4919
|
+
for (const key in newProperties) {
|
|
4920
|
+
if (key === "value")
|
|
4921
|
+
continue;
|
|
4922
|
+
const value = newProperties[key];
|
|
4923
|
+
value == null ? delete node[key] : node[key] = value;
|
|
4924
|
+
}
|
|
4925
|
+
for (const key in properties)
|
|
4926
|
+
key !== "value" && (newProperties.hasOwnProperty(key) || delete node[key]);
|
|
4927
|
+
for (const key in valueAfter) {
|
|
4928
|
+
const value = valueAfter[key];
|
|
4929
|
+
value == null ? delete node[key] : node[key] = value;
|
|
4930
|
+
}
|
|
4931
|
+
for (const key in valueBefore)
|
|
4932
|
+
valueAfter.hasOwnProperty(key) || delete node[key];
|
|
4933
|
+
break;
|
|
4934
|
+
}
|
|
4935
|
+
if (isTextBlockNode(context, node)) {
|
|
4936
|
+
for (const key in newProperties) {
|
|
4937
|
+
if (key === "children" || key === "text")
|
|
4938
|
+
break;
|
|
4939
|
+
const value = newProperties[key];
|
|
4940
|
+
value == null ? delete node[key] : node[key] = value;
|
|
4941
|
+
}
|
|
4942
|
+
for (const key in properties)
|
|
4943
|
+
newProperties.hasOwnProperty(key) || delete node[key];
|
|
4944
|
+
break;
|
|
4945
|
+
}
|
|
4946
|
+
if (isPartialSpanNode(node)) {
|
|
4947
|
+
for (const key in newProperties) {
|
|
4948
|
+
if (key === "text")
|
|
4949
|
+
break;
|
|
4950
|
+
const value = newProperties[key];
|
|
4951
|
+
value == null ? delete node[key] : node[key] = value;
|
|
4952
|
+
}
|
|
4953
|
+
for (const key in properties)
|
|
4954
|
+
newProperties.hasOwnProperty(key) || delete node[key];
|
|
4955
|
+
break;
|
|
4956
|
+
}
|
|
4957
|
+
break;
|
|
4958
|
+
}
|
|
4959
|
+
case "split_node": {
|
|
4960
|
+
const {
|
|
4961
|
+
path,
|
|
4962
|
+
position,
|
|
4963
|
+
properties
|
|
4964
|
+
} = operation;
|
|
4965
|
+
if (path.length === 0)
|
|
4966
|
+
break;
|
|
4967
|
+
const parent = getParent(context, root, path), index = path[path.length - 1];
|
|
4968
|
+
if (!parent)
|
|
4969
|
+
break;
|
|
4970
|
+
if (isEditorNode(parent)) {
|
|
4971
|
+
const block = getBlock(root, path);
|
|
4972
|
+
if (!block || !isTextBlockNode(context, block))
|
|
4973
|
+
break;
|
|
4974
|
+
const before = block.children.slice(0, position), after = block.children.slice(position);
|
|
4975
|
+
block.children = before;
|
|
4976
|
+
const newTextBlockNode = {
|
|
4977
|
+
...properties,
|
|
4978
|
+
children: after,
|
|
4979
|
+
_type: context.schema.block.name
|
|
4980
|
+
};
|
|
4981
|
+
parent.children.splice(index + 1, 0, newTextBlockNode);
|
|
4982
|
+
break;
|
|
4983
|
+
}
|
|
4984
|
+
if (isTextBlockNode(context, parent)) {
|
|
4985
|
+
const node = getNode(context, root, path);
|
|
4986
|
+
if (!node || !isSpanNode(context, node))
|
|
4987
|
+
break;
|
|
4988
|
+
const before = node.text.slice(0, position), after = node.text.slice(position);
|
|
4989
|
+
node.text = before;
|
|
4990
|
+
const newSpanNode = {
|
|
4991
|
+
...properties,
|
|
4992
|
+
text: after
|
|
4993
|
+
};
|
|
4994
|
+
parent.children.splice(index + 1, 0, newSpanNode);
|
|
4995
|
+
}
|
|
4996
|
+
break;
|
|
4997
|
+
}
|
|
4998
|
+
}
|
|
4999
|
+
return root;
|
|
5000
|
+
}
|
|
5001
|
+
function pluginUpdateValue(context, editor) {
|
|
5002
|
+
const {
|
|
5003
|
+
apply: apply2
|
|
5004
|
+
} = editor;
|
|
5005
|
+
return editor.apply = (operation) => {
|
|
5006
|
+
if (operation.type === "set_selection") {
|
|
5007
|
+
apply2(operation);
|
|
5008
|
+
return;
|
|
5009
|
+
}
|
|
5010
|
+
editor.value = applyOperationToPortableText({
|
|
5011
|
+
keyGenerator: context.keyGenerator,
|
|
5012
|
+
schema: context.schema
|
|
5013
|
+
}, editor.value, operation), apply2(operation);
|
|
5014
|
+
}, editor;
|
|
5015
|
+
}
|
|
4719
5016
|
const withPlugins = (editor, options) => {
|
|
4720
5017
|
const e = editor, {
|
|
4721
5018
|
editorActor,
|
|
@@ -4732,7 +5029,7 @@ const withPlugins = (editor, options) => {
|
|
|
4732
5029
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
4733
5030
|
editorActor
|
|
4734
5031
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
4735
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5032
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(pluginUpdateValue(editorActor.getSnapshot().context, e))))))))))));
|
|
4736
5033
|
}, debug$a = debugWithName("setup");
|
|
4737
5034
|
function createSlateEditor(config) {
|
|
4738
5035
|
debug$a("Creating new Slate editor instance");
|
|
@@ -4741,10 +5038,10 @@ function createSlateEditor(config) {
|
|
|
4741
5038
|
relayActor: config.relayActor,
|
|
4742
5039
|
subscriptions: config.subscriptions
|
|
4743
5040
|
});
|
|
4744
|
-
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {});
|
|
4745
|
-
const initialValue =
|
|
4746
|
-
|
|
4747
|
-
})
|
|
5041
|
+
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.value = [createPlaceholderBlock(config.editorActor.getSnapshot().context)];
|
|
5042
|
+
const initialValue = toSlateValue(instance.value, {
|
|
5043
|
+
schemaTypes: config.editorActor.getSnapshot().context.schema
|
|
5044
|
+
});
|
|
4748
5045
|
return {
|
|
4749
5046
|
instance,
|
|
4750
5047
|
initialValue
|
|
@@ -6536,34 +6833,6 @@ function sortByPriority(items) {
|
|
|
6536
6833
|
result.includes(item) || result.push(item);
|
|
6537
6834
|
return [...result, ...itemsWithoutPriority];
|
|
6538
6835
|
}
|
|
6539
|
-
function slateChildrenToBlocks(schema2, value) {
|
|
6540
|
-
const blocks = new Array(value.length);
|
|
6541
|
-
for (let blockIndex = 0; blockIndex < value.length; blockIndex++) {
|
|
6542
|
-
const descendant = value[blockIndex];
|
|
6543
|
-
if (descendant._type !== schema2.block.name) {
|
|
6544
|
-
blocks[blockIndex] = {
|
|
6545
|
-
_key: descendant._key,
|
|
6546
|
-
_type: descendant._type,
|
|
6547
|
-
..."value" in descendant && typeof descendant.value == "object" ? descendant.value : {}
|
|
6548
|
-
};
|
|
6549
|
-
continue;
|
|
6550
|
-
}
|
|
6551
|
-
const children = "children" in descendant ? descendant.children : [], processedChildren = new Array(children.length);
|
|
6552
|
-
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
6553
|
-
const child = children[childIndex];
|
|
6554
|
-
processedChildren[childIndex] = child._type === schema2.span.name ? child : {
|
|
6555
|
-
_key: child._key,
|
|
6556
|
-
_type: child._type,
|
|
6557
|
-
..."value" in child && typeof child.value == "object" ? child.value : {}
|
|
6558
|
-
};
|
|
6559
|
-
}
|
|
6560
|
-
blocks[blockIndex] = {
|
|
6561
|
-
...descendant,
|
|
6562
|
-
children: processedChildren
|
|
6563
|
-
};
|
|
6564
|
-
}
|
|
6565
|
-
return blocks;
|
|
6566
|
-
}
|
|
6567
6836
|
function getActiveDecorators({
|
|
6568
6837
|
schema: schema2,
|
|
6569
6838
|
slateEditorInstance
|
|
@@ -6582,7 +6851,7 @@ function createEditorSnapshot({
|
|
|
6582
6851
|
hasTag,
|
|
6583
6852
|
internalDrag
|
|
6584
6853
|
}) {
|
|
6585
|
-
const
|
|
6854
|
+
const selection = editor.selection ? slateRangeToSelection({
|
|
6586
6855
|
schema: schema2,
|
|
6587
6856
|
editor,
|
|
6588
6857
|
range: editor.selection
|
|
@@ -6598,7 +6867,7 @@ function createEditorSnapshot({
|
|
|
6598
6867
|
readOnly,
|
|
6599
6868
|
schema: schema2,
|
|
6600
6869
|
selection,
|
|
6601
|
-
value
|
|
6870
|
+
value: editor.value
|
|
6602
6871
|
},
|
|
6603
6872
|
beta: {
|
|
6604
6873
|
hasTag,
|
|
@@ -7314,7 +7583,7 @@ function getEditorSnapshot({
|
|
|
7314
7583
|
}),
|
|
7315
7584
|
schema: editorActorSnapshot.context.schema,
|
|
7316
7585
|
selection: editorActorSnapshot.context.selection,
|
|
7317
|
-
value:
|
|
7586
|
+
value: slateEditorInstance.value
|
|
7318
7587
|
},
|
|
7319
7588
|
beta: {
|
|
7320
7589
|
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
@@ -7701,8 +7970,8 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7701
7970
|
}]
|
|
7702
7971
|
}], {
|
|
7703
7972
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
7704
|
-
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2),
|
|
7705
|
-
return
|
|
7973
|
+
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode2 = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
7974
|
+
return isSpanNode2 && focusNode._type !== types2.span.name && (debug$6("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
7706
7975
|
distance: 1,
|
|
7707
7976
|
unit: "character"
|
|
7708
7977
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
@@ -8742,8 +9011,8 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
8742
9011
|
debug$5("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
8743
9012
|
at: path
|
|
8744
9013
|
});
|
|
8745
|
-
const
|
|
8746
|
-
|
|
9014
|
+
const isSpanNode2 = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
9015
|
+
isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && slate.Transforms.delete(slateEditor, {
|
|
8747
9016
|
at: {
|
|
8748
9017
|
focus: {
|
|
8749
9018
|
path,
|
|
@@ -8756,7 +9025,7 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
8756
9025
|
}
|
|
8757
9026
|
}), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
8758
9027
|
at: path
|
|
8759
|
-
}), slateEditor.onChange()) :
|
|
9028
|
+
}), slateEditor.onChange()) : isSpanNode2 || (debug$5("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
|
|
8760
9029
|
_key: VOID_CHILD_KEY
|
|
8761
9030
|
}, {
|
|
8762
9031
|
at: [...path, 0],
|
|
@@ -9126,6 +9395,7 @@ class PortableTextEditor extends React.Component {
|
|
|
9126
9395
|
/*
|
|
9127
9396
|
* The editor API (currently implemented with Slate).
|
|
9128
9397
|
*/
|
|
9398
|
+
subscriptions = [];
|
|
9129
9399
|
unsubscribers = [];
|
|
9130
9400
|
constructor(props) {
|
|
9131
9401
|
if (super(props), props.editor)
|
|
@@ -9142,23 +9412,20 @@ class PortableTextEditor extends React.Component {
|
|
|
9142
9412
|
readOnly: props.readOnly,
|
|
9143
9413
|
schema: props.schemaType
|
|
9144
9414
|
});
|
|
9145
|
-
this.
|
|
9146
|
-
const subscription = actors.relayActor.on("*", (event) => {
|
|
9147
|
-
const change = eventToChange(event);
|
|
9148
|
-
change && (props.onChange(change), this.change$.next(change));
|
|
9149
|
-
});
|
|
9150
|
-
return () => {
|
|
9151
|
-
subscription.unsubscribe();
|
|
9152
|
-
};
|
|
9153
|
-
})());
|
|
9154
|
-
for (const subscription of subscriptions)
|
|
9155
|
-
this.unsubscribers.push(subscription());
|
|
9156
|
-
this.actors = actors, this.editor = editor, this.schemaTypes = actors.editorActor.getSnapshot().context.getLegacySchema();
|
|
9415
|
+
this.subscriptions = subscriptions, this.actors = actors, this.editor = editor, this.schemaTypes = actors.editorActor.getSnapshot().context.getLegacySchema();
|
|
9157
9416
|
}
|
|
9158
9417
|
this.editable = this.editor._internal.editable;
|
|
9159
9418
|
}
|
|
9160
9419
|
componentDidMount() {
|
|
9161
|
-
|
|
9420
|
+
if (!this.actors)
|
|
9421
|
+
return;
|
|
9422
|
+
for (const subscription of this.subscriptions)
|
|
9423
|
+
this.unsubscribers.push(subscription());
|
|
9424
|
+
const relayActorSubscription = this.actors.relayActor.on("*", (event) => {
|
|
9425
|
+
const change = eventToChange(event);
|
|
9426
|
+
change && (this.props.editor || this.props.onChange(change), this.change$.next(change));
|
|
9427
|
+
});
|
|
9428
|
+
this.unsubscribers.push(relayActorSubscription.unsubscribe), this.actors.editorActor.start(), this.actors.mutationActor.start(), this.actors.relayActor.start(), this.actors.syncActor.start();
|
|
9162
9429
|
}
|
|
9163
9430
|
componentDidUpdate(prevProps) {
|
|
9164
9431
|
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && console.warn("Updating schema type is no longer supported"), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|