@portabletext/editor 1.27.0 → 1.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/lib/_chunks-cjs/behavior.core.cjs +40 -37
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +79 -0
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
- package/lib/_chunks-cjs/plugin.event-listener.cjs +357 -140
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-selection-start-point.cjs +15 -0
- package/lib/_chunks-cjs/selector.get-selection-start-point.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +88 -88
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +40 -37
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +80 -0
- package/lib/_chunks-es/parse-blocks.js.map +1 -0
- package/lib/_chunks-es/plugin.event-listener.js +359 -141
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/selector.get-selection-start-point.js +16 -0
- package/lib/_chunks-es/selector.get-selection-start-point.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +88 -88
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/behaviors/index.d.cts +196 -124
- package/lib/behaviors/index.d.ts +196 -124
- package/lib/index.cjs +22 -21
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +505 -0
- package/lib/index.d.ts +505 -0
- package/lib/index.js +22 -21
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +249 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +246 -1
- package/lib/plugins/index.d.ts +246 -1
- package/lib/plugins/index.js +257 -3
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +42 -3
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +39 -0
- package/lib/selectors/index.d.ts +39 -0
- package/lib/selectors/index.js +45 -4
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +70 -1
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +168 -2
- package/lib/utils/index.d.ts +168 -2
- package/lib/utils/index.js +71 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +4 -4
- package/src/behavior-actions/behavior.action.delete.ts +18 -0
- package/src/behavior-actions/behavior.action.insert-break.ts +96 -91
- package/src/behavior-actions/behavior.actions.ts +9 -0
- package/src/behaviors/_exports/index.ts +1 -0
- package/src/behaviors/behavior.core.deserialize.ts +52 -38
- package/src/behaviors/behavior.core.ts +4 -11
- package/src/behaviors/behavior.types.ts +4 -0
- package/src/editor/PortableTextEditor.tsx +308 -1
- package/src/editor/components/DefaultObject.tsx +21 -0
- package/src/editor/components/Element.tsx +5 -5
- package/src/editor/components/Leaf.tsx +1 -6
- package/src/internal-utils/__tests__/patchToOperations.test.ts +19 -21
- package/src/internal-utils/applyPatch.ts +11 -3
- package/src/plugins/index.ts +2 -0
- package/src/plugins/plugin.behavior.tsx +22 -0
- package/src/plugins/plugin.one-line.tsx +225 -0
- package/src/selectors/index.ts +7 -2
- package/src/selectors/selector.get-active-annotations.test.ts +122 -0
- package/src/selectors/selector.get-active-annotations.ts +30 -0
- package/src/selectors/selector.get-selection-end-point.ts +17 -0
- package/src/selectors/selector.get-selection-start-point.ts +17 -0
- package/src/selectors/selector.get-selection.ts +8 -0
- package/src/selectors/selector.get-value.ts +11 -0
- package/src/selectors/selector.is-overlapping-selection.ts +46 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/util.is-span.ts +12 -0
- package/src/utils/util.is-text-block.ts +12 -0
- package/src/utils/util.merge-text-blocks.ts +36 -0
- package/src/utils/util.split-text-block.ts +55 -0
- package/src/editor/nodes/DefaultAnnotation.tsx +0 -20
- package/src/editor/nodes/DefaultObject.tsx +0 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), jsxRuntime = require("react/jsx-runtime"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$f = require("debug"), slate = require("slate"), xstate = require("xstate"), isEqual = require("lodash/isEqual.js"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), startCase = require("lodash.startcase"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), util_isEmptyTextBlock = require("./util.is-empty-text-block.cjs"), behavior_core = require("./behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), rxjs = require("rxjs");
|
|
2
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), jsxRuntime = require("react/jsx-runtime"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$f = require("debug"), slate = require("slate"), xstate = require("xstate"), isEqual = require("lodash/isEqual.js"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), parseBlocks = require("./parse-blocks.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), startCase = require("lodash.startcase"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), util_isEmptyTextBlock = require("./util.is-empty-text-block.cjs"), behavior_core = require("./behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), rxjs = require("rxjs");
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
@@ -2214,83 +2214,7 @@ const converterJson = {
|
|
|
2214
2214
|
reason: "No application/x-portable-text Converter found"
|
|
2215
2215
|
};
|
|
2216
2216
|
}
|
|
2217
|
-
}
|
|
2218
|
-
function isTypedObject(object) {
|
|
2219
|
-
return isRecord(object) && typeof object._type == "string";
|
|
2220
|
-
}
|
|
2221
|
-
function isRecord(value) {
|
|
2222
|
-
return !!value && (typeof value == "object" || typeof value == "function");
|
|
2223
|
-
}
|
|
2224
|
-
function parseBlock({
|
|
2225
|
-
context,
|
|
2226
|
-
block,
|
|
2227
|
-
options
|
|
2228
|
-
}) {
|
|
2229
|
-
if (!isTypedObject(block) || block._type !== context.schema.block.name && !context.schema.blockObjects.some((blockObject) => blockObject.name === block._type))
|
|
2230
|
-
return;
|
|
2231
|
-
if (block._type !== context.schema.block.name) {
|
|
2232
|
-
const _key = options.refreshKeys ? context.keyGenerator() : typeof block._key == "string" ? block._key : context.keyGenerator();
|
|
2233
|
-
return {
|
|
2234
|
-
...block,
|
|
2235
|
-
_key
|
|
2236
|
-
};
|
|
2237
|
-
}
|
|
2238
|
-
if (!types.isPortableTextTextBlock(block))
|
|
2239
|
-
return {
|
|
2240
|
-
_type: context.schema.block.name,
|
|
2241
|
-
_key: options.refreshKeys ? context.keyGenerator() : typeof block._key == "string" ? block._key : context.keyGenerator(),
|
|
2242
|
-
children: [{
|
|
2243
|
-
_key: context.keyGenerator(),
|
|
2244
|
-
_type: context.schema.span.name,
|
|
2245
|
-
text: "",
|
|
2246
|
-
marks: []
|
|
2247
|
-
}],
|
|
2248
|
-
markDefs: [],
|
|
2249
|
-
style: context.schema.styles[0].value
|
|
2250
|
-
};
|
|
2251
|
-
const markDefKeyMap = /* @__PURE__ */ new Map(), markDefs = (block.markDefs ?? []).flatMap((markDef) => {
|
|
2252
|
-
if (context.schema.annotations.some((annotation) => annotation.name === markDef._type)) {
|
|
2253
|
-
const _key = options.refreshKeys ? context.keyGenerator() : markDef._key;
|
|
2254
|
-
return markDefKeyMap.set(markDef._key, _key), [{
|
|
2255
|
-
...markDef,
|
|
2256
|
-
_key
|
|
2257
|
-
}];
|
|
2258
|
-
}
|
|
2259
|
-
return [];
|
|
2260
|
-
}), children = block.children.flatMap((child) => {
|
|
2261
|
-
if (!isTypedObject(child))
|
|
2262
|
-
return [];
|
|
2263
|
-
if (child._type !== context.schema.span.name && !context.schema.inlineObjects.some((inlineObject) => inlineObject.name === child._type))
|
|
2264
|
-
return [];
|
|
2265
|
-
if (!types.isPortableTextSpan(child))
|
|
2266
|
-
return [{
|
|
2267
|
-
...child,
|
|
2268
|
-
_key: options.refreshKeys ? context.keyGenerator() : child._key
|
|
2269
|
-
}];
|
|
2270
|
-
const marks = (child.marks ?? []).flatMap((mark) => markDefKeyMap.has(mark) ? [markDefKeyMap.get(mark)] : context.schema.decorators.some((decorator) => decorator.value === mark) ? [mark] : []);
|
|
2271
|
-
return [{
|
|
2272
|
-
...child,
|
|
2273
|
-
_key: options.refreshKeys ? context.keyGenerator() : child._key,
|
|
2274
|
-
marks
|
|
2275
|
-
}];
|
|
2276
|
-
}), parsedBlock = {
|
|
2277
|
-
...block,
|
|
2278
|
-
_key: options.refreshKeys ? context.keyGenerator() : block._key,
|
|
2279
|
-
children: children.length > 0 ? children : [{
|
|
2280
|
-
_key: context.keyGenerator(),
|
|
2281
|
-
_type: context.schema.span.name,
|
|
2282
|
-
text: "",
|
|
2283
|
-
marks: []
|
|
2284
|
-
}],
|
|
2285
|
-
markDefs
|
|
2286
|
-
};
|
|
2287
|
-
if (!context.schema.styles.find((style) => style.value === block.style)) {
|
|
2288
|
-
const defaultStyle = context.schema.styles[0].value;
|
|
2289
|
-
defaultStyle !== void 0 ? parsedBlock.style = defaultStyle : delete parsedBlock.style;
|
|
2290
|
-
}
|
|
2291
|
-
return context.schema.lists.find((list) => list.value === block.listItem) || (delete parsedBlock.listItem, delete parsedBlock.level), parsedBlock;
|
|
2292
|
-
}
|
|
2293
|
-
const converterPortableText = {
|
|
2217
|
+
}, converterPortableText = {
|
|
2294
2218
|
mimeType: "application/x-portable-text",
|
|
2295
2219
|
serialize: ({
|
|
2296
2220
|
context,
|
|
@@ -2326,7 +2250,7 @@ const converterPortableText = {
|
|
|
2326
2250
|
reason: "Data is not an array"
|
|
2327
2251
|
};
|
|
2328
2252
|
const parsedBlocks = blocks.flatMap((block) => {
|
|
2329
|
-
const parsedBlock = parseBlock({
|
|
2253
|
+
const parsedBlock = parseBlocks.parseBlock({
|
|
2330
2254
|
context,
|
|
2331
2255
|
block,
|
|
2332
2256
|
options: {
|
|
@@ -3103,15 +3027,20 @@ function setPatch(editor, patch) {
|
|
|
3103
3027
|
node: c
|
|
3104
3028
|
});
|
|
3105
3029
|
});
|
|
3106
|
-
} else if (block && "value" in block)
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3030
|
+
} else if (block && "value" in block)
|
|
3031
|
+
if (patch.path.length > 1 && patch.path[1] !== "children") {
|
|
3032
|
+
const newVal = patches.applyAll(block.value, [{
|
|
3033
|
+
...patch,
|
|
3034
|
+
path: patch.path.slice(1)
|
|
3035
|
+
}]);
|
|
3036
|
+
slate.Transforms.setNodes(editor, {
|
|
3037
|
+
...block,
|
|
3038
|
+
value: newVal
|
|
3039
|
+
}, {
|
|
3040
|
+
at: blockPath
|
|
3041
|
+
});
|
|
3042
|
+
} else
|
|
3043
|
+
return !1;
|
|
3115
3044
|
return debugState(editor, "after"), !0;
|
|
3116
3045
|
}
|
|
3117
3046
|
function unsetPatch(editor, patch) {
|
|
@@ -4793,6 +4722,13 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4793
4722
|
action
|
|
4794
4723
|
}) => {
|
|
4795
4724
|
action.dataTransfer.setData(action.mimeType, action.data);
|
|
4725
|
+
}, deleteActionImplementation = ({
|
|
4726
|
+
action
|
|
4727
|
+
}) => {
|
|
4728
|
+
const range = toSlateRange(action.selection, action.editor);
|
|
4729
|
+
if (!range)
|
|
4730
|
+
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.selection)}`);
|
|
4731
|
+
slate.select(action.editor, range), slate.deleteFragment(action.editor);
|
|
4796
4732
|
}, insertBlockObjectActionImplementation = ({
|
|
4797
4733
|
context,
|
|
4798
4734
|
action
|
|
@@ -4848,67 +4784,64 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4848
4784
|
return;
|
|
4849
4785
|
const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
4850
4786
|
if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
4851
|
-
slate.
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
const newMarkDefs = nextNode.markDefs.map((markDef) => ({
|
|
4885
|
-
...markDef,
|
|
4886
|
-
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
4887
|
-
}));
|
|
4888
|
-
isEqual__default.default(nextNode.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
4889
|
-
markDefs: newMarkDefs
|
|
4787
|
+
slate.Transforms.splitNodes(editor, {
|
|
4788
|
+
at: editor.selection
|
|
4789
|
+
});
|
|
4790
|
+
const [nextBlock, nextBlockPath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
|
|
4791
|
+
depth: 1
|
|
4792
|
+
}), nextChild = slate.Node.child(nextBlock, 0);
|
|
4793
|
+
if (!editor.isTextSpan(nextChild) && slate.Transforms.insertNodes(editor, {
|
|
4794
|
+
_key: context.keyGenerator(),
|
|
4795
|
+
_type: "span",
|
|
4796
|
+
text: "",
|
|
4797
|
+
marks: []
|
|
4798
|
+
}, {
|
|
4799
|
+
at: [nextBlockPath[0], 0]
|
|
4800
|
+
}), slate.Transforms.setSelection(editor, {
|
|
4801
|
+
anchor: {
|
|
4802
|
+
path: [...nextBlockPath, 0],
|
|
4803
|
+
offset: 0
|
|
4804
|
+
},
|
|
4805
|
+
focus: {
|
|
4806
|
+
path: [...nextBlockPath, 0],
|
|
4807
|
+
offset: 0
|
|
4808
|
+
}
|
|
4809
|
+
}), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
|
|
4810
|
+
const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(slate.Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextBlockPath);
|
|
4811
|
+
for (const [child, childPath] of children) {
|
|
4812
|
+
if (!editor.isTextSpan(child))
|
|
4813
|
+
continue;
|
|
4814
|
+
const marks = child.marks ?? [];
|
|
4815
|
+
for (const mark of marks)
|
|
4816
|
+
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
4817
|
+
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
4818
|
+
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
4819
|
+
marks: newMarks
|
|
4890
4820
|
}, {
|
|
4891
|
-
at:
|
|
4892
|
-
match: (node) => editor.isTextBlock(node)
|
|
4821
|
+
at: childPath
|
|
4893
4822
|
});
|
|
4894
4823
|
}
|
|
4895
|
-
|
|
4824
|
+
const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
|
|
4825
|
+
...markDef,
|
|
4826
|
+
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
4827
|
+
}));
|
|
4828
|
+
isEqual__default.default(nextBlock.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
4829
|
+
markDefs: newMarkDefs
|
|
4830
|
+
}, {
|
|
4831
|
+
at: nextBlockPath,
|
|
4832
|
+
match: (node) => editor.isTextBlock(node)
|
|
4833
|
+
});
|
|
4834
|
+
}
|
|
4896
4835
|
return;
|
|
4897
4836
|
}
|
|
4898
4837
|
slate.Transforms.splitNodes(editor, {
|
|
4899
4838
|
always: !0
|
|
4900
4839
|
});
|
|
4901
4840
|
}, insertSoftBreakActionImplementation = ({
|
|
4902
|
-
context,
|
|
4903
4841
|
action
|
|
4904
4842
|
}) => {
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
action: {
|
|
4908
|
-
...action,
|
|
4909
|
-
type: "insert.break"
|
|
4910
|
-
}
|
|
4911
|
-
});
|
|
4843
|
+
slate.insertText(action.editor, `
|
|
4844
|
+
`);
|
|
4912
4845
|
}, insertInlineObjectActionImplementation = ({
|
|
4913
4846
|
context,
|
|
4914
4847
|
action
|
|
@@ -4978,7 +4911,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4978
4911
|
context,
|
|
4979
4912
|
action
|
|
4980
4913
|
}) => {
|
|
4981
|
-
const parsedBlock = parseBlock({
|
|
4914
|
+
const parsedBlock = parseBlocks.parseBlock({
|
|
4982
4915
|
block: action.block,
|
|
4983
4916
|
context,
|
|
4984
4917
|
options: {
|
|
@@ -5060,6 +4993,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
5060
4993
|
}) => {
|
|
5061
4994
|
slateReact.ReactEditor.focus(action.editor);
|
|
5062
4995
|
},
|
|
4996
|
+
delete: deleteActionImplementation,
|
|
5063
4997
|
"delete.backward": ({
|
|
5064
4998
|
action
|
|
5065
4999
|
}) => {
|
|
@@ -5368,6 +5302,13 @@ function performDefaultAction({
|
|
|
5368
5302
|
});
|
|
5369
5303
|
break;
|
|
5370
5304
|
}
|
|
5305
|
+
case "delete": {
|
|
5306
|
+
behaviorActionImplementations.delete({
|
|
5307
|
+
context,
|
|
5308
|
+
action
|
|
5309
|
+
});
|
|
5310
|
+
break;
|
|
5311
|
+
}
|
|
5371
5312
|
case "delete.backward": {
|
|
5372
5313
|
behaviorActionImplementations["delete.backward"]({
|
|
5373
5314
|
context,
|
|
@@ -6346,30 +6287,224 @@ class PortableTextEditor extends React.Component {
|
|
|
6346
6287
|
/* @__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 }) }) }) })
|
|
6347
6288
|
] });
|
|
6348
6289
|
}
|
|
6349
|
-
|
|
6290
|
+
/**
|
|
6291
|
+
* @deprecated
|
|
6292
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6293
|
+
*
|
|
6294
|
+
* ```
|
|
6295
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6296
|
+
* const editor = useEditor()
|
|
6297
|
+
* const isActive = useEditorSelector(editor, selectors.getActiveAnnotations)
|
|
6298
|
+
* ```
|
|
6299
|
+
*/
|
|
6350
6300
|
static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
|
|
6301
|
+
/**
|
|
6302
|
+
* @deprecated
|
|
6303
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6304
|
+
*
|
|
6305
|
+
* ```
|
|
6306
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6307
|
+
* const editor = useEditor()
|
|
6308
|
+
* const isActive = useEditorSelector(editor, selectors.isActiveAnnotation(...))
|
|
6309
|
+
* ```
|
|
6310
|
+
*/
|
|
6351
6311
|
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6312
|
+
/**
|
|
6313
|
+
* @deprecated
|
|
6314
|
+
* Use `editor.send(...)` instead
|
|
6315
|
+
*
|
|
6316
|
+
* ```
|
|
6317
|
+
* const editor = useEditor()
|
|
6318
|
+
* editor.send({
|
|
6319
|
+
* type: 'annotation.add',
|
|
6320
|
+
* annotation: {
|
|
6321
|
+
* name: '...',
|
|
6322
|
+
* value: {...},
|
|
6323
|
+
* }
|
|
6324
|
+
* })
|
|
6325
|
+
* ```
|
|
6326
|
+
*/
|
|
6352
6327
|
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6328
|
+
/**
|
|
6329
|
+
* @deprecated
|
|
6330
|
+
* Use `editor.send(...)` instead
|
|
6331
|
+
*
|
|
6332
|
+
* ```
|
|
6333
|
+
* const editor = useEditor()
|
|
6334
|
+
* editor.send({
|
|
6335
|
+
* type: 'blur',
|
|
6336
|
+
* })
|
|
6337
|
+
* ```
|
|
6338
|
+
*/
|
|
6353
6339
|
static blur = (editor) => {
|
|
6354
6340
|
debug("Host blurred"), editor.editable?.blur();
|
|
6355
6341
|
};
|
|
6356
6342
|
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6357
6343
|
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6358
6344
|
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6345
|
+
/**
|
|
6346
|
+
* @deprecated
|
|
6347
|
+
* Use `editor.send(...)` instead
|
|
6348
|
+
*
|
|
6349
|
+
* ```
|
|
6350
|
+
* const editor = useEditor()
|
|
6351
|
+
* editor.send({
|
|
6352
|
+
* type: 'focus',
|
|
6353
|
+
* })
|
|
6354
|
+
* ```
|
|
6355
|
+
*/
|
|
6359
6356
|
static focus = (editor) => {
|
|
6360
6357
|
debug("Host requesting focus"), editor.editable?.focus();
|
|
6361
6358
|
};
|
|
6359
|
+
/**
|
|
6360
|
+
* @deprecated
|
|
6361
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6362
|
+
*
|
|
6363
|
+
* ```
|
|
6364
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6365
|
+
* const editor = useEditor()
|
|
6366
|
+
* const focusBlock = useEditorSelector(editor, selectors.getFocusBlock)
|
|
6367
|
+
* ```
|
|
6368
|
+
*/
|
|
6362
6369
|
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6370
|
+
/**
|
|
6371
|
+
* @deprecated
|
|
6372
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6373
|
+
*
|
|
6374
|
+
* ```
|
|
6375
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6376
|
+
* const editor = useEditor()
|
|
6377
|
+
* const focusChild = useEditorSelector(editor, selectors.getFocusChild)
|
|
6378
|
+
* ```
|
|
6379
|
+
*/
|
|
6363
6380
|
static focusChild = (editor) => editor.editable?.focusChild();
|
|
6381
|
+
/**
|
|
6382
|
+
* @deprecated
|
|
6383
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6384
|
+
*
|
|
6385
|
+
* ```
|
|
6386
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6387
|
+
* const editor = useEditor()
|
|
6388
|
+
* const selection = useEditorSelector(editor, selectors.getSelection)
|
|
6389
|
+
* ```
|
|
6390
|
+
*/
|
|
6364
6391
|
static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
|
|
6392
|
+
/**
|
|
6393
|
+
* @deprecated
|
|
6394
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6395
|
+
*
|
|
6396
|
+
* ```
|
|
6397
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6398
|
+
* const editor = useEditor()
|
|
6399
|
+
* const value = useEditorSelector(editor, selectors.getValue)
|
|
6400
|
+
* ```
|
|
6401
|
+
*/
|
|
6365
6402
|
static getValue = (editor) => editor.editable?.getValue();
|
|
6403
|
+
/**
|
|
6404
|
+
* @deprecated
|
|
6405
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6406
|
+
*
|
|
6407
|
+
* ```
|
|
6408
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6409
|
+
* const editor = useEditor()
|
|
6410
|
+
* const isActive = useEditorSelector(editor, selectors.isActiveStyle(...))
|
|
6411
|
+
* ```
|
|
6412
|
+
*/
|
|
6366
6413
|
static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
|
|
6414
|
+
/**
|
|
6415
|
+
* @deprecated
|
|
6416
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6417
|
+
*
|
|
6418
|
+
* ```
|
|
6419
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6420
|
+
* const editor = useEditor()
|
|
6421
|
+
* const isActive = useEditorSelector(editor, selectors.isActiveListItem(...))
|
|
6422
|
+
* ```
|
|
6423
|
+
*/
|
|
6367
6424
|
static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
|
|
6425
|
+
/**
|
|
6426
|
+
* @deprecated
|
|
6427
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6428
|
+
*
|
|
6429
|
+
* ```
|
|
6430
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6431
|
+
* const editor = useEditor()
|
|
6432
|
+
* const isSelectionCollapsed = useEditorSelector(editor, selectors.isSelectionCollapsed)
|
|
6433
|
+
* ```
|
|
6434
|
+
*/
|
|
6368
6435
|
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6436
|
+
/**
|
|
6437
|
+
* @deprecated
|
|
6438
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6439
|
+
*
|
|
6440
|
+
* ```
|
|
6441
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6442
|
+
* const editor = useEditor()
|
|
6443
|
+
* const isSelectionExpanded = useEditorSelector(editor, selectors.isSelectionExpanded)
|
|
6444
|
+
* ```
|
|
6445
|
+
*/
|
|
6369
6446
|
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6447
|
+
/**
|
|
6448
|
+
* @deprecated
|
|
6449
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6450
|
+
*
|
|
6451
|
+
* ```
|
|
6452
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6453
|
+
* const editor = useEditor()
|
|
6454
|
+
* const isActive = useEditorSelector(editor, selectors.isActiveDecorator(...))
|
|
6455
|
+
* ```
|
|
6456
|
+
*/
|
|
6370
6457
|
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6458
|
+
/**
|
|
6459
|
+
* @deprecated
|
|
6460
|
+
* Use `editor.send(...)` instead
|
|
6461
|
+
*
|
|
6462
|
+
* ```
|
|
6463
|
+
* const editor = useEditor()
|
|
6464
|
+
* editor.send({
|
|
6465
|
+
* type: 'insert.span',
|
|
6466
|
+
* text: '...',
|
|
6467
|
+
* annotations: [{name: '...', value: {...}}],
|
|
6468
|
+
* decorators: ['...'],
|
|
6469
|
+
* })
|
|
6470
|
+
* editor.send({
|
|
6471
|
+
* type: 'insert.inline object',
|
|
6472
|
+
* inlineObject: {
|
|
6473
|
+
* name: '...',
|
|
6474
|
+
* value: {...},
|
|
6475
|
+
* },
|
|
6476
|
+
* })
|
|
6477
|
+
* ```
|
|
6478
|
+
*/
|
|
6371
6479
|
static insertChild = (editor, type, value) => (debug("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6480
|
+
/**
|
|
6481
|
+
* @deprecated
|
|
6482
|
+
* Use `editor.send(...)` instead
|
|
6483
|
+
*
|
|
6484
|
+
* ```
|
|
6485
|
+
* const editor = useEditor()
|
|
6486
|
+
* editor.send({
|
|
6487
|
+
* type: 'insert.block object',
|
|
6488
|
+
* blockObject: {
|
|
6489
|
+
* name: '...',
|
|
6490
|
+
* value: {...},
|
|
6491
|
+
* },
|
|
6492
|
+
* placement: 'auto' | 'after' | 'before',
|
|
6493
|
+
* })
|
|
6494
|
+
* ```
|
|
6495
|
+
*/
|
|
6372
6496
|
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6497
|
+
/**
|
|
6498
|
+
* @deprecated
|
|
6499
|
+
* Use `editor.send(...)` instead
|
|
6500
|
+
*
|
|
6501
|
+
* ```
|
|
6502
|
+
* const editor = useEditor()
|
|
6503
|
+
* editor.send({
|
|
6504
|
+
* type: 'insert.break',
|
|
6505
|
+
* })
|
|
6506
|
+
* ```
|
|
6507
|
+
*/
|
|
6373
6508
|
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6374
6509
|
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
6375
6510
|
static isObjectPath = (_editor, path) => {
|
|
@@ -6378,15 +6513,87 @@ class PortableTextEditor extends React.Component {
|
|
|
6378
6513
|
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6379
6514
|
};
|
|
6380
6515
|
static marks = (editor) => editor.editable?.marks();
|
|
6516
|
+
/**
|
|
6517
|
+
* @deprecated
|
|
6518
|
+
* Use `editor.send(...)` instead
|
|
6519
|
+
*
|
|
6520
|
+
* ```
|
|
6521
|
+
* const editor = useEditor()
|
|
6522
|
+
* editor.send({
|
|
6523
|
+
* type: 'select',
|
|
6524
|
+
* selection: {...},
|
|
6525
|
+
* })
|
|
6526
|
+
* ```
|
|
6527
|
+
*/
|
|
6381
6528
|
static select = (editor, selection) => {
|
|
6382
6529
|
debug("Host setting selection", selection), editor.editable?.select(selection);
|
|
6383
6530
|
};
|
|
6531
|
+
/**
|
|
6532
|
+
* @deprecated
|
|
6533
|
+
* Use `editor.send(...)` instead
|
|
6534
|
+
*
|
|
6535
|
+
* ```
|
|
6536
|
+
* const editor = useEditor()
|
|
6537
|
+
* editor.send({
|
|
6538
|
+
* type: 'annotation.remove',
|
|
6539
|
+
* annotation: {
|
|
6540
|
+
* name: '...',
|
|
6541
|
+
* },
|
|
6542
|
+
* })
|
|
6543
|
+
* ```
|
|
6544
|
+
*/
|
|
6384
6545
|
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6546
|
+
/**
|
|
6547
|
+
* @deprecated
|
|
6548
|
+
* Use `editor.send(...)` instead
|
|
6549
|
+
*
|
|
6550
|
+
* ```
|
|
6551
|
+
* const editor = useEditor()
|
|
6552
|
+
* editor.send({
|
|
6553
|
+
* type: 'style.toggle',
|
|
6554
|
+
* style: '...',
|
|
6555
|
+
* })
|
|
6556
|
+
* ```
|
|
6557
|
+
*/
|
|
6385
6558
|
static toggleBlockStyle = (editor, blockStyle) => (debug("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6559
|
+
/**
|
|
6560
|
+
* @deprecated
|
|
6561
|
+
* Use `editor.send(...)` instead
|
|
6562
|
+
*
|
|
6563
|
+
* ```
|
|
6564
|
+
* const editor = useEditor()
|
|
6565
|
+
* editor.send({
|
|
6566
|
+
* type: 'list item.toggle',
|
|
6567
|
+
* listItem: '...',
|
|
6568
|
+
* })
|
|
6569
|
+
* ```
|
|
6570
|
+
*/
|
|
6386
6571
|
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6572
|
+
/**
|
|
6573
|
+
* @deprecated
|
|
6574
|
+
* Use `editor.send(...)` instead
|
|
6575
|
+
*
|
|
6576
|
+
* ```
|
|
6577
|
+
* const editor = useEditor()
|
|
6578
|
+
* editor.send({
|
|
6579
|
+
* type: 'decorator.toggle',
|
|
6580
|
+
* decorator: '...',
|
|
6581
|
+
* })
|
|
6582
|
+
* ```
|
|
6583
|
+
*/
|
|
6387
6584
|
static toggleMark = (editor, mark) => {
|
|
6388
6585
|
debug("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6389
6586
|
};
|
|
6587
|
+
/**
|
|
6588
|
+
* @deprecated
|
|
6589
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6590
|
+
*
|
|
6591
|
+
* ```
|
|
6592
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6593
|
+
* const editor = useEditor()
|
|
6594
|
+
* const selectedSlice = useEditorSelector(editor, selectors.getSelectedSlice)
|
|
6595
|
+
* ```
|
|
6596
|
+
*/
|
|
6390
6597
|
static getFragment = (editor) => (debug("Host getting fragment"), editor.editable?.getFragment());
|
|
6391
6598
|
static undo = (editor) => {
|
|
6392
6599
|
debug("Host undoing"), editor.editable?.undo();
|
|
@@ -6394,6 +6601,16 @@ class PortableTextEditor extends React.Component {
|
|
|
6394
6601
|
static redo = (editor) => {
|
|
6395
6602
|
debug("Host redoing"), editor.editable?.redo();
|
|
6396
6603
|
};
|
|
6604
|
+
/**
|
|
6605
|
+
* @deprecated
|
|
6606
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
6607
|
+
*
|
|
6608
|
+
* ```
|
|
6609
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
6610
|
+
* const editor = useEditor()
|
|
6611
|
+
* const isOverlapping = useEditorSelector(editor, selectors.isOverlappingSelection(selectionB))
|
|
6612
|
+
* ```
|
|
6613
|
+
*/
|
|
6397
6614
|
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6398
6615
|
}
|
|
6399
6616
|
function RoutePatchesObservableToEditorActor(props) {
|