@portabletext/editor 1.55.7 → 1.55.9

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.
@@ -1,4 +1,4 @@
1
- import { getBlockKeyFromSelectionPoint, getSelectionStartPoint, getSelectionEndPoint, getChildKeyFromSelectionPoint, isSpan$1 as isSpan } from "./util.slice-blocks.js";
1
+ import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, isSpan$1 as isSpan, getSelectionStartPoint, getSelectionEndPoint } from "./util.slice-blocks.js";
2
2
  import { childSelectionPointToBlockOffset } from "./util.child-selection-point-to-block-offset.js";
3
3
  function isSelectionCollapsed(selection) {
4
4
  return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
package/lib/index.cjs CHANGED
@@ -859,17 +859,23 @@ function useCoreBlockElementBehaviors(t0) {
859
859
  }, t2 = [editorActor, key, onSetDragPositionBlock], $[0] = editorActor, $[1] = key, $[2] = onSetDragPositionBlock, $[3] = t1, $[4] = t2) : (t1 = $[3], t2 = $[4]), React.useEffect(t1, t2);
860
860
  }
861
861
  function RenderBlockObject(props) {
862
- const [dragPositionBlock, setDragPositionBlock] = React.useState(), blockObjectRef = React.useRef(null), selected = slateReact.useSelected(), focused = slateReact.useSlateSelector((editor) => selected && editor.selection !== null && slate.Range.isCollapsed(editor.selection)), editorActor = React.useContext(EditorActorContext);
862
+ const [dragPositionBlock, setDragPositionBlock] = React.useState(), blockObjectRef = React.useRef(null), selected = slateReact.useSelected(), focused = slateReact.useSlateSelector((editor) => selected && editor.selection !== null && slate.Range.isCollapsed(editor.selection));
863
863
  useCoreBlockElementBehaviors({
864
864
  key: props.element._key,
865
865
  onSetDragPositionBlock: setDragPositionBlock
866
866
  });
867
- const legacySchemaType = react.useSelector(editorActor, (s) => s.context.getLegacySchema().blockObjects.find((blockObject) => blockObject.name === props.element._type));
868
- return legacySchemaType || console.error(`Block object type ${props.element._type} not found in Schema`), /* @__PURE__ */ jsxRuntime.jsxs("div", { ...props.attributes, className: "pt-block pt-object-block", "data-block-key": props.element._key, "data-block-name": props.element._type, "data-block-type": "object", children: [
867
+ const legacySchemaType = props.legacySchema.blockObjects.find((blockObject) => blockObject.name === props.element._type);
868
+ legacySchemaType || console.error(`Unable to find Block Object "${props.element._type}" in Schema`);
869
+ const blockObject_0 = {
870
+ _key: props.element._key,
871
+ _type: props.element._type,
872
+ ..."value" in props.element && typeof props.element.value == "object" ? props.element.value : {}
873
+ };
874
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...props.attributes, className: "pt-block pt-object-block", "data-block-key": props.element._key, "data-block-name": props.element._type, "data-block-type": "object", children: [
869
875
  dragPositionBlock === "start" ? /* @__PURE__ */ jsxRuntime.jsx(DropIndicator, {}) : null,
870
876
  props.children,
871
877
  /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockObjectRef, contentEditable: !1, draggable: !props.readOnly, children: props.renderBlock && legacySchemaType ? props.renderBlock({
872
- children: /* @__PURE__ */ jsxRuntime.jsx(RenderDefaultBlockObject, { blockObject: props.blockObject }),
878
+ children: /* @__PURE__ */ jsxRuntime.jsx(RenderDefaultBlockObject, { blockObject: blockObject_0 }),
873
879
  editorElementRef: blockObjectRef,
874
880
  focused,
875
881
  path: [{
@@ -878,28 +884,34 @@ function RenderBlockObject(props) {
878
884
  schemaType: legacySchemaType,
879
885
  selected,
880
886
  type: legacySchemaType,
881
- value: props.blockObject
882
- }) : /* @__PURE__ */ jsxRuntime.jsx(RenderDefaultBlockObject, { blockObject: props.blockObject }) }),
887
+ value: blockObject_0
888
+ }) : /* @__PURE__ */ jsxRuntime.jsx(RenderDefaultBlockObject, { blockObject: blockObject_0 }) }),
883
889
  dragPositionBlock === "end" ? /* @__PURE__ */ jsxRuntime.jsx(DropIndicator, {}) : null
884
890
  ] });
885
891
  }
886
892
  function RenderInlineObject(props) {
887
- const inlineObjectRef = React.useRef(null), slateEditor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), editorActor = React.useContext(EditorActorContext), legacySchemaType = react.useSelector(editorActor, (s) => s.context.getLegacySchema().inlineObjects.find((inlineObject) => inlineObject.name === props.element._type));
888
- legacySchemaType || console.error(`Inline object type ${props.element._type} not found in Schema`);
889
- const focused = selected && slateEditor.selection !== null && slate.Range.isCollapsed(slateEditor.selection), path = slateDom.DOMEditor.findPath(slateEditor, props.element), [block] = getPointBlock({
893
+ const inlineObjectRef = React.useRef(null), slateEditor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), focused = slateReact.useSlateSelector((editor) => selected && editor.selection !== null && slate.Range.isCollapsed(editor.selection)), legacySchemaType = props.legacySchema.inlineObjects.find((inlineObject) => inlineObject.name === props.element._type);
894
+ legacySchemaType || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
895
+ const path = slateDom.DOMEditor.findPath(slateEditor, props.element), [block] = getPointBlock({
890
896
  editor: slateEditor,
891
897
  point: {
892
898
  path,
893
899
  offset: 0
894
900
  }
895
901
  });
896
- return block || console.error(`Unable to find parent block of inline object ${props.element._key}`), /* @__PURE__ */ jsxRuntime.jsxs("span", { ...props.attributes, draggable: !props.readOnly, className: "pt-inline-object", "data-child-key": props.inlineObject._key, "data-child-name": props.inlineObject._type, "data-child-type": "object", children: [
902
+ block || console.error(`Unable to find parent block of inline object ${props.element._key}`);
903
+ const inlineObject_0 = {
904
+ _key: props.element._key,
905
+ _type: props.element._type,
906
+ ..."value" in props.element && typeof props.element.value == "object" ? props.element.value : {}
907
+ };
908
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { ...props.attributes, draggable: !props.readOnly, className: "pt-inline-object", "data-child-key": inlineObject_0._key, "data-child-name": inlineObject_0._type, "data-child-type": "object", children: [
897
909
  props.children,
898
910
  /* @__PURE__ */ jsxRuntime.jsx("span", { ref: inlineObjectRef, style: {
899
911
  display: "inline-block"
900
912
  }, children: props.renderChild && block && legacySchemaType ? props.renderChild({
901
913
  annotations: [],
902
- children: /* @__PURE__ */ jsxRuntime.jsx(RenderDefaultInlineObject, { inlineObject: props.inlineObject }),
914
+ children: /* @__PURE__ */ jsxRuntime.jsx(RenderDefaultInlineObject, { inlineObject: inlineObject_0 }),
903
915
  editorElementRef: inlineObjectRef,
904
916
  selected,
905
917
  focused,
@@ -909,22 +921,30 @@ function RenderInlineObject(props) {
909
921
  _key: props.element._key
910
922
  }],
911
923
  schemaType: legacySchemaType,
912
- value: props.inlineObject,
924
+ value: inlineObject_0,
913
925
  type: legacySchemaType
914
- }) : /* @__PURE__ */ jsxRuntime.jsx(RenderDefaultInlineObject, { inlineObject: props.inlineObject }) })
926
+ }) : /* @__PURE__ */ jsxRuntime.jsx(RenderDefaultInlineObject, { inlineObject: inlineObject_0 }) })
915
927
  ] });
916
928
  }
929
+ function RenderObject(props) {
930
+ const $ = reactCompilerRuntime.c(16);
931
+ if ("__inline" in props.element && props.element.__inline === !0) {
932
+ let t02;
933
+ return $[0] !== props.attributes || $[1] !== props.children || $[2] !== props.element || $[3] !== props.legacySchema || $[4] !== props.readOnly || $[5] !== props.renderChild || $[6] !== props.schema ? (t02 = /* @__PURE__ */ jsxRuntime.jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, legacySchema: props.legacySchema, readOnly: props.readOnly, renderChild: props.renderChild, schema: props.schema, children: props.children }), $[0] = props.attributes, $[1] = props.children, $[2] = props.element, $[3] = props.legacySchema, $[4] = props.readOnly, $[5] = props.renderChild, $[6] = props.schema, $[7] = t02) : t02 = $[7], t02;
934
+ }
935
+ let t0;
936
+ return $[8] !== props.attributes || $[9] !== props.children || $[10] !== props.element || $[11] !== props.legacySchema || $[12] !== props.readOnly || $[13] !== props.renderBlock || $[14] !== props.schema ? (t0 = /* @__PURE__ */ jsxRuntime.jsx(RenderBlockObject, { attributes: props.attributes, element: props.element, legacySchema: props.legacySchema, readOnly: props.readOnly, renderBlock: props.renderBlock, schema: props.schema, children: props.children }), $[8] = props.attributes, $[9] = props.children, $[10] = props.element, $[11] = props.legacySchema, $[12] = props.readOnly, $[13] = props.renderBlock, $[14] = props.schema, $[15] = t0) : t0 = $[15], t0;
937
+ }
917
938
  function RenderTextBlock(props) {
918
- const [dragPositionBlock, setDragPositionBlock] = React.useState(), blockRef = React.useRef(null), selected = slateReact.useSelected(), focused = slateReact.useSlateSelector((editor) => selected && editor.selection !== null && slate.Range.isCollapsed(editor.selection)), editorActor = React.useContext(EditorActorContext);
939
+ const [dragPositionBlock, setDragPositionBlock] = React.useState(), blockRef = React.useRef(null), selected = slateReact.useSelected(), focused = slateReact.useSlateSelector((editor) => selected && editor.selection !== null && slate.Range.isCollapsed(editor.selection));
919
940
  useCoreBlockElementBehaviors({
920
941
  key: props.element._key,
921
942
  onSetDragPositionBlock: setDragPositionBlock
922
943
  });
923
- const legacySchema = react.useSelector(editorActor, (s) => s.context.getLegacySchema()), listIndex = slateReact.useSlateSelector((editor_0) => editor_0.listIndexMap.get(props.textBlock._key));
944
+ const listIndex = slateReact.useSlateSelector((editor_0) => editor_0.listIndexMap.get(props.textBlock._key));
924
945
  let children = props.children;
925
- const legacyBlockSchemaType = legacySchema.block;
926
946
  if (props.renderStyle && props.textBlock.style) {
927
- const legacyStyleSchemaType = props.textBlock.style !== void 0 ? legacySchema.styles.find((style) => style.value === props.textBlock.style) : void 0;
947
+ const legacyStyleSchemaType = props.textBlock.style !== void 0 ? props.legacySchema.styles.find((style) => style.value === props.textBlock.style) : void 0;
928
948
  legacyStyleSchemaType ? children = props.renderStyle({
929
949
  block: props.textBlock,
930
950
  children,
@@ -939,7 +959,7 @@ function RenderTextBlock(props) {
939
959
  }) : console.error(`Unable to find Schema type for text block style ${props.textBlock.style}`);
940
960
  }
941
961
  if (props.renderListItem && props.textBlock.listItem) {
942
- const legacyListItemSchemaType = legacySchema.lists.find((list) => list.value === props.textBlock.listItem);
962
+ const legacyListItemSchemaType = props.legacySchema.lists.find((list) => list.value === props.textBlock.listItem);
943
963
  legacyListItemSchemaType ? children = props.renderListItem({
944
964
  block: props.textBlock,
945
965
  children,
@@ -974,58 +994,27 @@ function RenderTextBlock(props) {
974
994
  _key: props.textBlock._key
975
995
  }],
976
996
  selected,
977
- schemaType: legacyBlockSchemaType,
997
+ schemaType: props.legacySchema.block,
978
998
  style: props.textBlock.style,
979
- type: legacyBlockSchemaType,
999
+ type: props.legacySchema.block,
980
1000
  value: props.textBlock
981
1001
  }) : children }),
982
1002
  dragPositionBlock === "end" ? /* @__PURE__ */ jsxRuntime.jsx(DropIndicator, {}) : null
983
1003
  ] });
984
1004
  }
985
1005
  function RenderElement(props) {
986
- const $ = reactCompilerRuntime.c(43), editorActor = React.useContext(EditorActorContext), schema2 = react.useSelector(editorActor, _temp$1);
987
- if ("__inline" in props.element && props.element.__inline === !0) {
988
- let t02;
989
- $[0] !== props.element ? (t02 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[0] = props.element, $[1] = t02) : t02 = $[1];
990
- let t12;
991
- $[2] !== props.element._key || $[3] !== props.element._type || $[4] !== t02 ? (t12 = {
992
- _key: props.element._key,
993
- _type: props.element._type,
994
- ...t02
995
- }, $[2] = props.element._key, $[3] = props.element._type, $[4] = t02, $[5] = t12) : t12 = $[5];
996
- const inlineObject = t12;
997
- schema2.inlineObjects.find((inlineObject_0) => inlineObject_0.name === props.element._type) || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
998
- let t22;
999
- $[6] !== inlineObject || $[7] !== props.element._key || $[8] !== props.element._type ? (t22 = inlineObject ?? {
1000
- _key: props.element._key,
1001
- _type: props.element._type
1002
- }, $[6] = inlineObject, $[7] = props.element._key, $[8] = props.element._type, $[9] = t22) : t22 = $[9];
1003
- let t32;
1004
- return $[10] !== props.attributes || $[11] !== props.children || $[12] !== props.element || $[13] !== props.readOnly || $[14] !== props.renderChild || $[15] !== t22 ? (t32 = /* @__PURE__ */ jsxRuntime.jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, inlineObject: t22, readOnly: props.readOnly, renderChild: props.renderChild, children: props.children }), $[10] = props.attributes, $[11] = props.children, $[12] = props.element, $[13] = props.readOnly, $[14] = props.renderChild, $[15] = t22, $[16] = t32) : t32 = $[16], t32;
1005
- }
1006
+ const $ = reactCompilerRuntime.c(19), editorActor = React.useContext(EditorActorContext), schema2 = react.useSelector(editorActor, _temp$1), legacySchema = react.useSelector(editorActor, _temp2);
1006
1007
  if (util_sliceBlocks.isTextBlock({
1007
1008
  schema: schema2
1008
1009
  }, props.element)) {
1009
1010
  let t02;
1010
- return $[17] !== props.attributes || $[18] !== props.children || $[19] !== props.element || $[20] !== props.readOnly || $[21] !== props.renderBlock || $[22] !== props.renderListItem || $[23] !== props.renderStyle || $[24] !== props.spellCheck ? (t02 = /* @__PURE__ */ jsxRuntime.jsx(RenderTextBlock, { attributes: props.attributes, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, spellCheck: props.spellCheck, textBlock: props.element, children: props.children }), $[17] = props.attributes, $[18] = props.children, $[19] = props.element, $[20] = props.readOnly, $[21] = props.renderBlock, $[22] = props.renderListItem, $[23] = props.renderStyle, $[24] = props.spellCheck, $[25] = t02) : t02 = $[25], t02;
1011
+ return $[0] !== legacySchema || $[1] !== props.attributes || $[2] !== props.children || $[3] !== props.element || $[4] !== props.readOnly || $[5] !== props.renderBlock || $[6] !== props.renderListItem || $[7] !== props.renderStyle || $[8] !== props.spellCheck ? (t02 = /* @__PURE__ */ jsxRuntime.jsx(RenderTextBlock, { attributes: props.attributes, element: props.element, legacySchema, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, spellCheck: props.spellCheck, textBlock: props.element, children: props.children }), $[0] = legacySchema, $[1] = props.attributes, $[2] = props.children, $[3] = props.element, $[4] = props.readOnly, $[5] = props.renderBlock, $[6] = props.renderListItem, $[7] = props.renderStyle, $[8] = props.spellCheck, $[9] = t02) : t02 = $[9], t02;
1011
1012
  }
1012
1013
  let t0;
1013
- $[26] !== props.element ? (t0 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[26] = props.element, $[27] = t0) : t0 = $[27];
1014
- let t1;
1015
- $[28] !== props.element._key || $[29] !== props.element._type || $[30] !== t0 ? (t1 = {
1016
- _key: props.element._key,
1017
- _type: props.element._type,
1018
- ...t0
1019
- }, $[28] = props.element._key, $[29] = props.element._type, $[30] = t0, $[31] = t1) : t1 = $[31];
1020
- const blockObject = t1;
1021
- schema2.blockObjects.find((blockObject_0) => blockObject_0.name === props.element._type) || console.error(`Unable to find Block Object "${props.element._type}" in Schema`);
1022
- let t2;
1023
- $[32] !== blockObject || $[33] !== props.element._key || $[34] !== props.element._type ? (t2 = blockObject ?? {
1024
- _key: props.element._key,
1025
- _type: props.element._type
1026
- }, $[32] = blockObject, $[33] = props.element._key, $[34] = props.element._type, $[35] = t2) : t2 = $[35];
1027
- let t3;
1028
- return $[36] !== props.attributes || $[37] !== props.children || $[38] !== props.element || $[39] !== props.readOnly || $[40] !== props.renderBlock || $[41] !== t2 ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(RenderBlockObject, { attributes: props.attributes, blockObject: t2, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, children: props.children }), $[36] = props.attributes, $[37] = props.children, $[38] = props.element, $[39] = props.readOnly, $[40] = props.renderBlock, $[41] = t2, $[42] = t3) : t3 = $[42], t3;
1014
+ return $[10] !== legacySchema || $[11] !== props.attributes || $[12] !== props.children || $[13] !== props.element || $[14] !== props.readOnly || $[15] !== props.renderBlock || $[16] !== props.renderChild || $[17] !== schema2 ? (t0 = /* @__PURE__ */ jsxRuntime.jsx(RenderObject, { attributes: props.attributes, element: props.element, legacySchema, readOnly: props.readOnly, renderBlock: props.renderBlock, renderChild: props.renderChild, schema: schema2, children: props.children }), $[10] = legacySchema, $[11] = props.attributes, $[12] = props.children, $[13] = props.element, $[14] = props.readOnly, $[15] = props.renderBlock, $[16] = props.renderChild, $[17] = schema2, $[18] = t0) : t0 = $[18], t0;
1015
+ }
1016
+ function _temp2(s_0) {
1017
+ return s_0.context.getLegacySchema();
1029
1018
  }
1030
1019
  function _temp$1(s) {
1031
1020
  return s.context.schema;
@@ -5211,7 +5200,11 @@ function pluginUpdateValue(context, editor) {
5211
5200
  apply2(operation);
5212
5201
  return;
5213
5202
  }
5214
- editor.value = applyOperationToPortableText(context, editor.value, operation), buildIndexMaps({
5203
+ if (editor.value = applyOperationToPortableText(context, editor.value, operation), operation.type === "insert_text" || operation.type === "remove_text") {
5204
+ apply2(operation);
5205
+ return;
5206
+ }
5207
+ buildIndexMaps({
5215
5208
  schema: context.schema,
5216
5209
  value: editor.value
5217
5210
  }, {
@@ -7640,7 +7633,8 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
7640
7633
  behaviors: ({
7641
7634
  context,
7642
7635
  event
7643
- }) => (xstate.assertEvent(event, "add behavior"), /* @__PURE__ */ new Set([...context.behaviors, event.behaviorConfig]))
7636
+ }) => (xstate.assertEvent(event, "add behavior"), /* @__PURE__ */ new Set([...context.behaviors, event.behaviorConfig])),
7637
+ behaviorsSorted: !1
7644
7638
  }),
7645
7639
  "remove behavior from context": xstate.assign({
7646
7640
  behaviors: ({
@@ -7729,7 +7723,7 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
7729
7723
  }) => {
7730
7724
  xstate.assertEvent(event, ["behavior event"]);
7731
7725
  try {
7732
- const behaviors = sortByPriority([...context.behaviors.values(), ...coreBehaviorsConfig]).map((config) => config.behavior);
7726
+ const behaviors = [...context.behaviors.values()].map((config) => config.behavior);
7733
7727
  performEvent({
7734
7728
  mode: "raise",
7735
7729
  behaviors,
@@ -7753,7 +7747,13 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
7753
7747
  } catch (error) {
7754
7748
  console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`));
7755
7749
  }
7756
- }
7750
+ },
7751
+ "sort behaviors": xstate.assign({
7752
+ behaviors: ({
7753
+ context
7754
+ }) => context.behaviorsSorted ? context.behaviors : new Set(sortByPriority([...context.behaviors.values()])),
7755
+ behaviorsSorted: !0
7756
+ })
7757
7757
  },
7758
7758
  guards: {
7759
7759
  "slate is busy": ({
@@ -7765,7 +7765,8 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
7765
7765
  context: ({
7766
7766
  input
7767
7767
  }) => ({
7768
- behaviors: /* @__PURE__ */ new Set([]),
7768
+ behaviors: new Set(coreBehaviorsConfig),
7769
+ behaviorsSorted: !1,
7769
7770
  converters: new Set(input.converters ?? []),
7770
7771
  getLegacySchema: input.getLegacySchema,
7771
7772
  keyGenerator: input.keyGenerator,
@@ -7820,7 +7821,7 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
7820
7821
  initial: "determine initial edit mode",
7821
7822
  on: {
7822
7823
  "behavior event": {
7823
- actions: "handle behavior event",
7824
+ actions: ["sort behaviors", "handle behavior event"],
7824
7825
  guard: ({
7825
7826
  event
7826
7827
  }) => event.behaviorEvent.type === "clipboard.copy" || event.behaviorEvent.type === "mouse.click" || event.behaviorEvent.type === "serialize" || event.behaviorEvent.type === "serialization.failure" || event.behaviorEvent.type === "serialization.success" || event.behaviorEvent.type === "select"
@@ -7874,7 +7875,7 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
7874
7875
  actions: ["emit read only"]
7875
7876
  },
7876
7877
  "behavior event": {
7877
- actions: "handle behavior event"
7878
+ actions: ["sort behaviors", "handle behavior event"]
7878
7879
  },
7879
7880
  blur: {
7880
7881
  actions: "handle blur"