@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.
Files changed (79) hide show
  1. package/README.md +5 -5
  2. package/lib/_chunks-cjs/behavior.core.cjs +40 -37
  3. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  4. package/lib/_chunks-cjs/parse-blocks.cjs +79 -0
  5. package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
  6. package/lib/_chunks-cjs/plugin.event-listener.cjs +357 -140
  7. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
  8. package/lib/_chunks-cjs/selector.get-selection-start-point.cjs +15 -0
  9. package/lib/_chunks-cjs/selector.get-selection-start-point.cjs.map +1 -0
  10. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +88 -88
  11. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  12. package/lib/_chunks-es/behavior.core.js +40 -37
  13. package/lib/_chunks-es/behavior.core.js.map +1 -1
  14. package/lib/_chunks-es/parse-blocks.js +80 -0
  15. package/lib/_chunks-es/parse-blocks.js.map +1 -0
  16. package/lib/_chunks-es/plugin.event-listener.js +359 -141
  17. package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
  18. package/lib/_chunks-es/selector.get-selection-start-point.js +16 -0
  19. package/lib/_chunks-es/selector.get-selection-start-point.js.map +1 -0
  20. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +88 -88
  21. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  22. package/lib/behaviors/index.d.cts +196 -124
  23. package/lib/behaviors/index.d.ts +196 -124
  24. package/lib/index.cjs +22 -21
  25. package/lib/index.cjs.map +1 -1
  26. package/lib/index.d.cts +505 -0
  27. package/lib/index.d.ts +505 -0
  28. package/lib/index.js +22 -21
  29. package/lib/index.js.map +1 -1
  30. package/lib/plugins/index.cjs +249 -1
  31. package/lib/plugins/index.cjs.map +1 -1
  32. package/lib/plugins/index.d.cts +246 -1
  33. package/lib/plugins/index.d.ts +246 -1
  34. package/lib/plugins/index.js +257 -3
  35. package/lib/plugins/index.js.map +1 -1
  36. package/lib/selectors/index.cjs +42 -3
  37. package/lib/selectors/index.cjs.map +1 -1
  38. package/lib/selectors/index.d.cts +39 -0
  39. package/lib/selectors/index.d.ts +39 -0
  40. package/lib/selectors/index.js +45 -4
  41. package/lib/selectors/index.js.map +1 -1
  42. package/lib/utils/index.cjs +70 -1
  43. package/lib/utils/index.cjs.map +1 -1
  44. package/lib/utils/index.d.cts +168 -2
  45. package/lib/utils/index.d.ts +168 -2
  46. package/lib/utils/index.js +71 -1
  47. package/lib/utils/index.js.map +1 -1
  48. package/package.json +4 -4
  49. package/src/behavior-actions/behavior.action.delete.ts +18 -0
  50. package/src/behavior-actions/behavior.action.insert-break.ts +96 -91
  51. package/src/behavior-actions/behavior.actions.ts +9 -0
  52. package/src/behaviors/_exports/index.ts +1 -0
  53. package/src/behaviors/behavior.core.deserialize.ts +52 -38
  54. package/src/behaviors/behavior.core.ts +4 -11
  55. package/src/behaviors/behavior.types.ts +4 -0
  56. package/src/editor/PortableTextEditor.tsx +308 -1
  57. package/src/editor/components/DefaultObject.tsx +21 -0
  58. package/src/editor/components/Element.tsx +5 -5
  59. package/src/editor/components/Leaf.tsx +1 -6
  60. package/src/internal-utils/__tests__/patchToOperations.test.ts +19 -21
  61. package/src/internal-utils/applyPatch.ts +11 -3
  62. package/src/plugins/index.ts +2 -0
  63. package/src/plugins/plugin.behavior.tsx +22 -0
  64. package/src/plugins/plugin.one-line.tsx +225 -0
  65. package/src/selectors/index.ts +7 -2
  66. package/src/selectors/selector.get-active-annotations.test.ts +122 -0
  67. package/src/selectors/selector.get-active-annotations.ts +30 -0
  68. package/src/selectors/selector.get-selection-end-point.ts +17 -0
  69. package/src/selectors/selector.get-selection-start-point.ts +17 -0
  70. package/src/selectors/selector.get-selection.ts +8 -0
  71. package/src/selectors/selector.get-value.ts +11 -0
  72. package/src/selectors/selector.is-overlapping-selection.ts +46 -0
  73. package/src/utils/index.ts +4 -0
  74. package/src/utils/util.is-span.ts +12 -0
  75. package/src/utils/util.is-text-block.ts +12 -0
  76. package/src/utils/util.merge-text-blocks.ts +36 -0
  77. package/src/utils/util.split-text-block.ts +55 -0
  78. package/src/editor/nodes/DefaultAnnotation.tsx +0 -20
  79. package/src/editor/nodes/DefaultObject.tsx +0 -18
@@ -5,7 +5,7 @@ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
5
5
  import { withReact, ReactEditor, Slate } from "slate-react";
6
6
  import { useSelector, useActorRef } from "@xstate/react";
7
7
  import debug$f from "debug";
8
- import { Editor, Element, Range, Point, Text, Operation, Transforms, Path, Node, createEditor as createEditor$1, deleteBackward, deleteForward, insertText } from "slate";
8
+ import { Editor, Element, Range, Point, Text, Operation, Transforms, Path, Node, createEditor as createEditor$1, select, deleteFragment, insertText, deleteBackward, deleteForward } from "slate";
9
9
  import { setup, emit, assign, fromCallback, assertEvent, enqueueActions, createActor } from "xstate";
10
10
  import isEqual from "lodash/isEqual.js";
11
11
  import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
@@ -13,6 +13,7 @@ import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPorta
13
13
  import flatten from "lodash/flatten.js";
14
14
  import isPlainObject from "lodash/isPlainObject.js";
15
15
  import uniq from "lodash/uniq.js";
16
+ import { parseBlock } from "./parse-blocks.js";
16
17
  import { sliceBlocks } from "./util.slice-blocks.js";
17
18
  import { htmlToBlocks } from "@portabletext/block-tools";
18
19
  import { toHTML } from "@portabletext/to-html";
@@ -2236,83 +2237,7 @@ const converterJson = {
2236
2237
  reason: "No application/x-portable-text Converter found"
2237
2238
  };
2238
2239
  }
2239
- };
2240
- function isTypedObject(object) {
2241
- return isRecord(object) && typeof object._type == "string";
2242
- }
2243
- function isRecord(value) {
2244
- return !!value && (typeof value == "object" || typeof value == "function");
2245
- }
2246
- function parseBlock({
2247
- context,
2248
- block,
2249
- options
2250
- }) {
2251
- if (!isTypedObject(block) || block._type !== context.schema.block.name && !context.schema.blockObjects.some((blockObject) => blockObject.name === block._type))
2252
- return;
2253
- if (block._type !== context.schema.block.name) {
2254
- const _key = options.refreshKeys ? context.keyGenerator() : typeof block._key == "string" ? block._key : context.keyGenerator();
2255
- return {
2256
- ...block,
2257
- _key
2258
- };
2259
- }
2260
- if (!isPortableTextTextBlock(block))
2261
- return {
2262
- _type: context.schema.block.name,
2263
- _key: options.refreshKeys ? context.keyGenerator() : typeof block._key == "string" ? block._key : context.keyGenerator(),
2264
- children: [{
2265
- _key: context.keyGenerator(),
2266
- _type: context.schema.span.name,
2267
- text: "",
2268
- marks: []
2269
- }],
2270
- markDefs: [],
2271
- style: context.schema.styles[0].value
2272
- };
2273
- const markDefKeyMap = /* @__PURE__ */ new Map(), markDefs = (block.markDefs ?? []).flatMap((markDef) => {
2274
- if (context.schema.annotations.some((annotation) => annotation.name === markDef._type)) {
2275
- const _key = options.refreshKeys ? context.keyGenerator() : markDef._key;
2276
- return markDefKeyMap.set(markDef._key, _key), [{
2277
- ...markDef,
2278
- _key
2279
- }];
2280
- }
2281
- return [];
2282
- }), children = block.children.flatMap((child) => {
2283
- if (!isTypedObject(child))
2284
- return [];
2285
- if (child._type !== context.schema.span.name && !context.schema.inlineObjects.some((inlineObject) => inlineObject.name === child._type))
2286
- return [];
2287
- if (!isPortableTextSpan$1(child))
2288
- return [{
2289
- ...child,
2290
- _key: options.refreshKeys ? context.keyGenerator() : child._key
2291
- }];
2292
- const marks = (child.marks ?? []).flatMap((mark) => markDefKeyMap.has(mark) ? [markDefKeyMap.get(mark)] : context.schema.decorators.some((decorator) => decorator.value === mark) ? [mark] : []);
2293
- return [{
2294
- ...child,
2295
- _key: options.refreshKeys ? context.keyGenerator() : child._key,
2296
- marks
2297
- }];
2298
- }), parsedBlock = {
2299
- ...block,
2300
- _key: options.refreshKeys ? context.keyGenerator() : block._key,
2301
- children: children.length > 0 ? children : [{
2302
- _key: context.keyGenerator(),
2303
- _type: context.schema.span.name,
2304
- text: "",
2305
- marks: []
2306
- }],
2307
- markDefs
2308
- };
2309
- if (!context.schema.styles.find((style) => style.value === block.style)) {
2310
- const defaultStyle = context.schema.styles[0].value;
2311
- defaultStyle !== void 0 ? parsedBlock.style = defaultStyle : delete parsedBlock.style;
2312
- }
2313
- return context.schema.lists.find((list) => list.value === block.listItem) || (delete parsedBlock.listItem, delete parsedBlock.level), parsedBlock;
2314
- }
2315
- const converterPortableText = {
2240
+ }, converterPortableText = {
2316
2241
  mimeType: "application/x-portable-text",
2317
2242
  serialize: ({
2318
2243
  context,
@@ -2742,7 +2667,7 @@ function createWithEventListeners(editorActor, subscriptions) {
2742
2667
  insertData,
2743
2668
  insertSoftBreak,
2744
2669
  insertText: insertText2,
2745
- select,
2670
+ select: select2,
2746
2671
  setFragmentData
2747
2672
  } = editor;
2748
2673
  return editor.deleteBackward = (unit) => {
@@ -2827,7 +2752,7 @@ function createWithEventListeners(editorActor, subscriptions) {
2827
2752
  });
2828
2753
  }, editor.select = (location) => {
2829
2754
  if (isApplyingBehaviorActions(editor)) {
2830
- select(location);
2755
+ select2(location);
2831
2756
  return;
2832
2757
  }
2833
2758
  const range = Editor.range(editor, location);
@@ -2839,7 +2764,7 @@ function createWithEventListeners(editorActor, subscriptions) {
2839
2764
  },
2840
2765
  editor,
2841
2766
  defaultActionCallback: () => {
2842
- select(location);
2767
+ select2(location);
2843
2768
  }
2844
2769
  });
2845
2770
  }, editor.setFragmentData = (dataTransfer, originEvent) => {
@@ -3125,15 +3050,20 @@ function setPatch(editor, patch) {
3125
3050
  node: c2
3126
3051
  });
3127
3052
  });
3128
- } else if (block && "value" in block) {
3129
- const newVal = applyAll([block.value], [patch])[0];
3130
- return Transforms.setNodes(editor, {
3131
- ...block,
3132
- value: newVal
3133
- }, {
3134
- at: blockPath
3135
- }), !0;
3136
- }
3053
+ } else if (block && "value" in block)
3054
+ if (patch.path.length > 1 && patch.path[1] !== "children") {
3055
+ const newVal = applyAll(block.value, [{
3056
+ ...patch,
3057
+ path: patch.path.slice(1)
3058
+ }]);
3059
+ Transforms.setNodes(editor, {
3060
+ ...block,
3061
+ value: newVal
3062
+ }, {
3063
+ at: blockPath
3064
+ });
3065
+ } else
3066
+ return !1;
3137
3067
  return debugState(editor, "after"), !0;
3138
3068
  }
3139
3069
  function unsetPatch(editor, patch) {
@@ -4815,6 +4745,13 @@ const blockSetBehaviorActionImplementation = ({
4815
4745
  action
4816
4746
  }) => {
4817
4747
  action.dataTransfer.setData(action.mimeType, action.data);
4748
+ }, deleteActionImplementation = ({
4749
+ action
4750
+ }) => {
4751
+ const range = toSlateRange(action.selection, action.editor);
4752
+ if (!range)
4753
+ throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.selection)}`);
4754
+ select(action.editor, range), deleteFragment(action.editor);
4818
4755
  }, insertBlockObjectActionImplementation = ({
4819
4756
  context,
4820
4757
  action
@@ -4870,67 +4807,64 @@ const blockSetBehaviorActionImplementation = ({
4870
4807
  return;
4871
4808
  const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
4872
4809
  if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
4873
- Editor.withoutNormalizing(editor, () => {
4874
- if (!editor.selection)
4875
- return;
4876
- Transforms.splitNodes(editor, {
4877
- at: editor.selection
4878
- });
4879
- const [nextNode, nextNodePath] = Editor.node(editor, Path.next(focusBlockPath), {
4880
- depth: 1
4881
- });
4882
- if (Transforms.setSelection(editor, {
4883
- anchor: {
4884
- path: [...nextNodePath, 0],
4885
- offset: 0
4886
- },
4887
- focus: {
4888
- path: [...nextNodePath, 0],
4889
- offset: 0
4890
- }
4891
- }), editor.isTextBlock(nextNode) && nextNode.markDefs && nextNode.markDefs.length > 0) {
4892
- const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = Node.children(editor, nextNodePath);
4893
- for (const [child, childPath] of children) {
4894
- if (!editor.isTextSpan(child))
4895
- continue;
4896
- const marks = child.marks ?? [];
4897
- for (const mark of marks)
4898
- schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
4899
- const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
4900
- isEqual(marks, newMarks) || Transforms.setNodes(editor, {
4901
- marks: newMarks
4902
- }, {
4903
- at: childPath
4904
- });
4905
- }
4906
- const newMarkDefs = nextNode.markDefs.map((markDef) => ({
4907
- ...markDef,
4908
- _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
4909
- }));
4910
- isEqual(nextNode.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
4911
- markDefs: newMarkDefs
4810
+ Transforms.splitNodes(editor, {
4811
+ at: editor.selection
4812
+ });
4813
+ const [nextBlock, nextBlockPath] = Editor.node(editor, Path.next(focusBlockPath), {
4814
+ depth: 1
4815
+ }), nextChild = Node.child(nextBlock, 0);
4816
+ if (!editor.isTextSpan(nextChild) && Transforms.insertNodes(editor, {
4817
+ _key: context.keyGenerator(),
4818
+ _type: "span",
4819
+ text: "",
4820
+ marks: []
4821
+ }, {
4822
+ at: [nextBlockPath[0], 0]
4823
+ }), Transforms.setSelection(editor, {
4824
+ anchor: {
4825
+ path: [...nextBlockPath, 0],
4826
+ offset: 0
4827
+ },
4828
+ focus: {
4829
+ path: [...nextBlockPath, 0],
4830
+ offset: 0
4831
+ }
4832
+ }), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
4833
+ const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = Node.children(editor, nextBlockPath);
4834
+ for (const [child, childPath] of children) {
4835
+ if (!editor.isTextSpan(child))
4836
+ continue;
4837
+ const marks = child.marks ?? [];
4838
+ for (const mark of marks)
4839
+ schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
4840
+ const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
4841
+ isEqual(marks, newMarks) || Transforms.setNodes(editor, {
4842
+ marks: newMarks
4912
4843
  }, {
4913
- at: nextNodePath,
4914
- match: (node) => editor.isTextBlock(node)
4844
+ at: childPath
4915
4845
  });
4916
4846
  }
4917
- }), editor.onChange();
4847
+ const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
4848
+ ...markDef,
4849
+ _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
4850
+ }));
4851
+ isEqual(nextBlock.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
4852
+ markDefs: newMarkDefs
4853
+ }, {
4854
+ at: nextBlockPath,
4855
+ match: (node) => editor.isTextBlock(node)
4856
+ });
4857
+ }
4918
4858
  return;
4919
4859
  }
4920
4860
  Transforms.splitNodes(editor, {
4921
4861
  always: !0
4922
4862
  });
4923
4863
  }, insertSoftBreakActionImplementation = ({
4924
- context,
4925
4864
  action
4926
4865
  }) => {
4927
- insertBreakActionImplementation({
4928
- context,
4929
- action: {
4930
- ...action,
4931
- type: "insert.break"
4932
- }
4933
- });
4866
+ insertText(action.editor, `
4867
+ `);
4934
4868
  }, insertInlineObjectActionImplementation = ({
4935
4869
  context,
4936
4870
  action
@@ -5082,6 +5016,7 @@ const blockSetBehaviorActionImplementation = ({
5082
5016
  }) => {
5083
5017
  ReactEditor.focus(action.editor);
5084
5018
  },
5019
+ delete: deleteActionImplementation,
5085
5020
  "delete.backward": ({
5086
5021
  action
5087
5022
  }) => {
@@ -5390,6 +5325,13 @@ function performDefaultAction({
5390
5325
  });
5391
5326
  break;
5392
5327
  }
5328
+ case "delete": {
5329
+ behaviorActionImplementations.delete({
5330
+ context,
5331
+ action
5332
+ });
5333
+ break;
5334
+ }
5393
5335
  case "delete.backward": {
5394
5336
  behaviorActionImplementations["delete.backward"]({
5395
5337
  context,
@@ -6368,30 +6310,224 @@ class PortableTextEditor extends Component {
6368
6310
  /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsx(Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
6369
6311
  ] });
6370
6312
  }
6371
- // Static API methods
6313
+ /**
6314
+ * @deprecated
6315
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6316
+ *
6317
+ * ```
6318
+ * import * as selectors from '@portabletext/editor/selectors'
6319
+ * const editor = useEditor()
6320
+ * const isActive = useEditorSelector(editor, selectors.getActiveAnnotations)
6321
+ * ```
6322
+ */
6372
6323
  static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
6324
+ /**
6325
+ * @deprecated
6326
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6327
+ *
6328
+ * ```
6329
+ * import * as selectors from '@portabletext/editor/selectors'
6330
+ * const editor = useEditor()
6331
+ * const isActive = useEditorSelector(editor, selectors.isActiveAnnotation(...))
6332
+ * ```
6333
+ */
6373
6334
  static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
6335
+ /**
6336
+ * @deprecated
6337
+ * Use `editor.send(...)` instead
6338
+ *
6339
+ * ```
6340
+ * const editor = useEditor()
6341
+ * editor.send({
6342
+ * type: 'annotation.add',
6343
+ * annotation: {
6344
+ * name: '...',
6345
+ * value: {...},
6346
+ * }
6347
+ * })
6348
+ * ```
6349
+ */
6374
6350
  static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
6351
+ /**
6352
+ * @deprecated
6353
+ * Use `editor.send(...)` instead
6354
+ *
6355
+ * ```
6356
+ * const editor = useEditor()
6357
+ * editor.send({
6358
+ * type: 'blur',
6359
+ * })
6360
+ * ```
6361
+ */
6375
6362
  static blur = (editor) => {
6376
6363
  debug("Host blurred"), editor.editable?.blur();
6377
6364
  };
6378
6365
  static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
6379
6366
  static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
6380
6367
  static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
6368
+ /**
6369
+ * @deprecated
6370
+ * Use `editor.send(...)` instead
6371
+ *
6372
+ * ```
6373
+ * const editor = useEditor()
6374
+ * editor.send({
6375
+ * type: 'focus',
6376
+ * })
6377
+ * ```
6378
+ */
6381
6379
  static focus = (editor) => {
6382
6380
  debug("Host requesting focus"), editor.editable?.focus();
6383
6381
  };
6382
+ /**
6383
+ * @deprecated
6384
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6385
+ *
6386
+ * ```
6387
+ * import * as selectors from '@portabletext/editor/selectors'
6388
+ * const editor = useEditor()
6389
+ * const focusBlock = useEditorSelector(editor, selectors.getFocusBlock)
6390
+ * ```
6391
+ */
6384
6392
  static focusBlock = (editor) => editor.editable?.focusBlock();
6393
+ /**
6394
+ * @deprecated
6395
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6396
+ *
6397
+ * ```
6398
+ * import * as selectors from '@portabletext/editor/selectors'
6399
+ * const editor = useEditor()
6400
+ * const focusChild = useEditorSelector(editor, selectors.getFocusChild)
6401
+ * ```
6402
+ */
6385
6403
  static focusChild = (editor) => editor.editable?.focusChild();
6404
+ /**
6405
+ * @deprecated
6406
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6407
+ *
6408
+ * ```
6409
+ * import * as selectors from '@portabletext/editor/selectors'
6410
+ * const editor = useEditor()
6411
+ * const selection = useEditorSelector(editor, selectors.getSelection)
6412
+ * ```
6413
+ */
6386
6414
  static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
6415
+ /**
6416
+ * @deprecated
6417
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6418
+ *
6419
+ * ```
6420
+ * import * as selectors from '@portabletext/editor/selectors'
6421
+ * const editor = useEditor()
6422
+ * const value = useEditorSelector(editor, selectors.getValue)
6423
+ * ```
6424
+ */
6387
6425
  static getValue = (editor) => editor.editable?.getValue();
6426
+ /**
6427
+ * @deprecated
6428
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6429
+ *
6430
+ * ```
6431
+ * import * as selectors from '@portabletext/editor/selectors'
6432
+ * const editor = useEditor()
6433
+ * const isActive = useEditorSelector(editor, selectors.isActiveStyle(...))
6434
+ * ```
6435
+ */
6388
6436
  static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
6437
+ /**
6438
+ * @deprecated
6439
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6440
+ *
6441
+ * ```
6442
+ * import * as selectors from '@portabletext/editor/selectors'
6443
+ * const editor = useEditor()
6444
+ * const isActive = useEditorSelector(editor, selectors.isActiveListItem(...))
6445
+ * ```
6446
+ */
6389
6447
  static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
6448
+ /**
6449
+ * @deprecated
6450
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6451
+ *
6452
+ * ```
6453
+ * import * as selectors from '@portabletext/editor/selectors'
6454
+ * const editor = useEditor()
6455
+ * const isSelectionCollapsed = useEditorSelector(editor, selectors.isSelectionCollapsed)
6456
+ * ```
6457
+ */
6390
6458
  static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
6459
+ /**
6460
+ * @deprecated
6461
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6462
+ *
6463
+ * ```
6464
+ * import * as selectors from '@portabletext/editor/selectors'
6465
+ * const editor = useEditor()
6466
+ * const isSelectionExpanded = useEditorSelector(editor, selectors.isSelectionExpanded)
6467
+ * ```
6468
+ */
6391
6469
  static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
6470
+ /**
6471
+ * @deprecated
6472
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6473
+ *
6474
+ * ```
6475
+ * import * as selectors from '@portabletext/editor/selectors'
6476
+ * const editor = useEditor()
6477
+ * const isActive = useEditorSelector(editor, selectors.isActiveDecorator(...))
6478
+ * ```
6479
+ */
6392
6480
  static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
6481
+ /**
6482
+ * @deprecated
6483
+ * Use `editor.send(...)` instead
6484
+ *
6485
+ * ```
6486
+ * const editor = useEditor()
6487
+ * editor.send({
6488
+ * type: 'insert.span',
6489
+ * text: '...',
6490
+ * annotations: [{name: '...', value: {...}}],
6491
+ * decorators: ['...'],
6492
+ * })
6493
+ * editor.send({
6494
+ * type: 'insert.inline object',
6495
+ * inlineObject: {
6496
+ * name: '...',
6497
+ * value: {...},
6498
+ * },
6499
+ * })
6500
+ * ```
6501
+ */
6393
6502
  static insertChild = (editor, type, value) => (debug("Host inserting child"), editor.editable?.insertChild(type, value));
6503
+ /**
6504
+ * @deprecated
6505
+ * Use `editor.send(...)` instead
6506
+ *
6507
+ * ```
6508
+ * const editor = useEditor()
6509
+ * editor.send({
6510
+ * type: 'insert.block object',
6511
+ * blockObject: {
6512
+ * name: '...',
6513
+ * value: {...},
6514
+ * },
6515
+ * placement: 'auto' | 'after' | 'before',
6516
+ * })
6517
+ * ```
6518
+ */
6394
6519
  static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
6520
+ /**
6521
+ * @deprecated
6522
+ * Use `editor.send(...)` instead
6523
+ *
6524
+ * ```
6525
+ * const editor = useEditor()
6526
+ * editor.send({
6527
+ * type: 'insert.break',
6528
+ * })
6529
+ * ```
6530
+ */
6395
6531
  static insertBreak = (editor) => editor.editable?.insertBreak();
6396
6532
  static isVoid = (editor, element) => editor.editable?.isVoid(element);
6397
6533
  static isObjectPath = (_editor, path) => {
@@ -6400,15 +6536,87 @@ class PortableTextEditor extends Component {
6400
6536
  return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
6401
6537
  };
6402
6538
  static marks = (editor) => editor.editable?.marks();
6539
+ /**
6540
+ * @deprecated
6541
+ * Use `editor.send(...)` instead
6542
+ *
6543
+ * ```
6544
+ * const editor = useEditor()
6545
+ * editor.send({
6546
+ * type: 'select',
6547
+ * selection: {...},
6548
+ * })
6549
+ * ```
6550
+ */
6403
6551
  static select = (editor, selection) => {
6404
6552
  debug("Host setting selection", selection), editor.editable?.select(selection);
6405
6553
  };
6554
+ /**
6555
+ * @deprecated
6556
+ * Use `editor.send(...)` instead
6557
+ *
6558
+ * ```
6559
+ * const editor = useEditor()
6560
+ * editor.send({
6561
+ * type: 'annotation.remove',
6562
+ * annotation: {
6563
+ * name: '...',
6564
+ * },
6565
+ * })
6566
+ * ```
6567
+ */
6406
6568
  static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
6569
+ /**
6570
+ * @deprecated
6571
+ * Use `editor.send(...)` instead
6572
+ *
6573
+ * ```
6574
+ * const editor = useEditor()
6575
+ * editor.send({
6576
+ * type: 'style.toggle',
6577
+ * style: '...',
6578
+ * })
6579
+ * ```
6580
+ */
6407
6581
  static toggleBlockStyle = (editor, blockStyle) => (debug("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
6582
+ /**
6583
+ * @deprecated
6584
+ * Use `editor.send(...)` instead
6585
+ *
6586
+ * ```
6587
+ * const editor = useEditor()
6588
+ * editor.send({
6589
+ * type: 'list item.toggle',
6590
+ * listItem: '...',
6591
+ * })
6592
+ * ```
6593
+ */
6408
6594
  static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
6595
+ /**
6596
+ * @deprecated
6597
+ * Use `editor.send(...)` instead
6598
+ *
6599
+ * ```
6600
+ * const editor = useEditor()
6601
+ * editor.send({
6602
+ * type: 'decorator.toggle',
6603
+ * decorator: '...',
6604
+ * })
6605
+ * ```
6606
+ */
6409
6607
  static toggleMark = (editor, mark) => {
6410
6608
  debug("Host toggling mark", mark), editor.editable?.toggleMark(mark);
6411
6609
  };
6610
+ /**
6611
+ * @deprecated
6612
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6613
+ *
6614
+ * ```
6615
+ * import * as selectors from '@portabletext/editor/selectors'
6616
+ * const editor = useEditor()
6617
+ * const selectedSlice = useEditorSelector(editor, selectors.getSelectedSlice)
6618
+ * ```
6619
+ */
6412
6620
  static getFragment = (editor) => (debug("Host getting fragment"), editor.editable?.getFragment());
6413
6621
  static undo = (editor) => {
6414
6622
  debug("Host undoing"), editor.editable?.undo();
@@ -6416,6 +6624,16 @@ class PortableTextEditor extends Component {
6416
6624
  static redo = (editor) => {
6417
6625
  debug("Host redoing"), editor.editable?.redo();
6418
6626
  };
6627
+ /**
6628
+ * @deprecated
6629
+ * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
6630
+ *
6631
+ * ```
6632
+ * import * as selectors from '@portabletext/editor/selectors'
6633
+ * const editor = useEditor()
6634
+ * const isOverlapping = useEditorSelector(editor, selectors.isOverlappingSelection(selectionB))
6635
+ * ```
6636
+ */
6419
6637
  static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
6420
6638
  }
6421
6639
  function RoutePatchesObservableToEditorActor(props) {