@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.
package/lib/index.js CHANGED
@@ -888,17 +888,23 @@ function useCoreBlockElementBehaviors(t0) {
888
888
  }, t2 = [editorActor, key, onSetDragPositionBlock], $[0] = editorActor, $[1] = key, $[2] = onSetDragPositionBlock, $[3] = t1, $[4] = t2) : (t1 = $[3], t2 = $[4]), useEffect(t1, t2);
889
889
  }
890
890
  function RenderBlockObject(props) {
891
- const [dragPositionBlock, setDragPositionBlock] = useState(), blockObjectRef = useRef(null), selected = useSelected(), focused = useSlateSelector((editor) => selected && editor.selection !== null && Range.isCollapsed(editor.selection)), editorActor = useContext(EditorActorContext);
891
+ const [dragPositionBlock, setDragPositionBlock] = useState(), blockObjectRef = useRef(null), selected = useSelected(), focused = useSlateSelector((editor) => selected && editor.selection !== null && Range.isCollapsed(editor.selection));
892
892
  useCoreBlockElementBehaviors({
893
893
  key: props.element._key,
894
894
  onSetDragPositionBlock: setDragPositionBlock
895
895
  });
896
- const legacySchemaType = useSelector(editorActor, (s) => s.context.getLegacySchema().blockObjects.find((blockObject) => blockObject.name === props.element._type));
897
- return legacySchemaType || console.error(`Block object type ${props.element._type} not found in Schema`), /* @__PURE__ */ 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: [
896
+ const legacySchemaType = props.legacySchema.blockObjects.find((blockObject) => blockObject.name === props.element._type);
897
+ legacySchemaType || console.error(`Unable to find Block Object "${props.element._type}" in Schema`);
898
+ const blockObject_0 = {
899
+ _key: props.element._key,
900
+ _type: props.element._type,
901
+ ..."value" in props.element && typeof props.element.value == "object" ? props.element.value : {}
902
+ };
903
+ return /* @__PURE__ */ 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: [
898
904
  dragPositionBlock === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null,
899
905
  props.children,
900
906
  /* @__PURE__ */ jsx("div", { ref: blockObjectRef, contentEditable: !1, draggable: !props.readOnly, children: props.renderBlock && legacySchemaType ? props.renderBlock({
901
- children: /* @__PURE__ */ jsx(RenderDefaultBlockObject, { blockObject: props.blockObject }),
907
+ children: /* @__PURE__ */ jsx(RenderDefaultBlockObject, { blockObject: blockObject_0 }),
902
908
  editorElementRef: blockObjectRef,
903
909
  focused,
904
910
  path: [{
@@ -907,28 +913,34 @@ function RenderBlockObject(props) {
907
913
  schemaType: legacySchemaType,
908
914
  selected,
909
915
  type: legacySchemaType,
910
- value: props.blockObject
911
- }) : /* @__PURE__ */ jsx(RenderDefaultBlockObject, { blockObject: props.blockObject }) }),
916
+ value: blockObject_0
917
+ }) : /* @__PURE__ */ jsx(RenderDefaultBlockObject, { blockObject: blockObject_0 }) }),
912
918
  dragPositionBlock === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
913
919
  ] });
914
920
  }
915
921
  function RenderInlineObject(props) {
916
- const inlineObjectRef = useRef(null), slateEditor = useSlateStatic(), selected = useSelected(), editorActor = useContext(EditorActorContext), legacySchemaType = useSelector(editorActor, (s) => s.context.getLegacySchema().inlineObjects.find((inlineObject) => inlineObject.name === props.element._type));
917
- legacySchemaType || console.error(`Inline object type ${props.element._type} not found in Schema`);
918
- const focused = selected && slateEditor.selection !== null && Range.isCollapsed(slateEditor.selection), path = DOMEditor.findPath(slateEditor, props.element), [block] = getPointBlock({
922
+ const inlineObjectRef = useRef(null), slateEditor = useSlateStatic(), selected = useSelected(), focused = useSlateSelector((editor) => selected && editor.selection !== null && Range.isCollapsed(editor.selection)), legacySchemaType = props.legacySchema.inlineObjects.find((inlineObject) => inlineObject.name === props.element._type);
923
+ legacySchemaType || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
924
+ const path = DOMEditor.findPath(slateEditor, props.element), [block] = getPointBlock({
919
925
  editor: slateEditor,
920
926
  point: {
921
927
  path,
922
928
  offset: 0
923
929
  }
924
930
  });
925
- return block || console.error(`Unable to find parent block of inline object ${props.element._key}`), /* @__PURE__ */ 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: [
931
+ block || console.error(`Unable to find parent block of inline object ${props.element._key}`);
932
+ const inlineObject_0 = {
933
+ _key: props.element._key,
934
+ _type: props.element._type,
935
+ ..."value" in props.element && typeof props.element.value == "object" ? props.element.value : {}
936
+ };
937
+ return /* @__PURE__ */ 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: [
926
938
  props.children,
927
939
  /* @__PURE__ */ jsx("span", { ref: inlineObjectRef, style: {
928
940
  display: "inline-block"
929
941
  }, children: props.renderChild && block && legacySchemaType ? props.renderChild({
930
942
  annotations: [],
931
- children: /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: props.inlineObject }),
943
+ children: /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: inlineObject_0 }),
932
944
  editorElementRef: inlineObjectRef,
933
945
  selected,
934
946
  focused,
@@ -938,22 +950,30 @@ function RenderInlineObject(props) {
938
950
  _key: props.element._key
939
951
  }],
940
952
  schemaType: legacySchemaType,
941
- value: props.inlineObject,
953
+ value: inlineObject_0,
942
954
  type: legacySchemaType
943
- }) : /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: props.inlineObject }) })
955
+ }) : /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: inlineObject_0 }) })
944
956
  ] });
945
957
  }
958
+ function RenderObject(props) {
959
+ const $ = c(16);
960
+ if ("__inline" in props.element && props.element.__inline === !0) {
961
+ let t02;
962
+ return $[0] !== props.attributes || $[1] !== props.children || $[2] !== props.element || $[3] !== props.legacySchema || $[4] !== props.readOnly || $[5] !== props.renderChild || $[6] !== props.schema ? (t02 = /* @__PURE__ */ 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;
963
+ }
964
+ let t0;
965
+ return $[8] !== props.attributes || $[9] !== props.children || $[10] !== props.element || $[11] !== props.legacySchema || $[12] !== props.readOnly || $[13] !== props.renderBlock || $[14] !== props.schema ? (t0 = /* @__PURE__ */ 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;
966
+ }
946
967
  function RenderTextBlock(props) {
947
- const [dragPositionBlock, setDragPositionBlock] = useState(), blockRef = useRef(null), selected = useSelected(), focused = useSlateSelector((editor) => selected && editor.selection !== null && Range.isCollapsed(editor.selection)), editorActor = useContext(EditorActorContext);
968
+ const [dragPositionBlock, setDragPositionBlock] = useState(), blockRef = useRef(null), selected = useSelected(), focused = useSlateSelector((editor) => selected && editor.selection !== null && Range.isCollapsed(editor.selection));
948
969
  useCoreBlockElementBehaviors({
949
970
  key: props.element._key,
950
971
  onSetDragPositionBlock: setDragPositionBlock
951
972
  });
952
- const legacySchema = useSelector(editorActor, (s) => s.context.getLegacySchema()), listIndex = useSlateSelector((editor_0) => editor_0.listIndexMap.get(props.textBlock._key));
973
+ const listIndex = useSlateSelector((editor_0) => editor_0.listIndexMap.get(props.textBlock._key));
953
974
  let children = props.children;
954
- const legacyBlockSchemaType = legacySchema.block;
955
975
  if (props.renderStyle && props.textBlock.style) {
956
- const legacyStyleSchemaType = props.textBlock.style !== void 0 ? legacySchema.styles.find((style) => style.value === props.textBlock.style) : void 0;
976
+ const legacyStyleSchemaType = props.textBlock.style !== void 0 ? props.legacySchema.styles.find((style) => style.value === props.textBlock.style) : void 0;
957
977
  legacyStyleSchemaType ? children = props.renderStyle({
958
978
  block: props.textBlock,
959
979
  children,
@@ -968,7 +988,7 @@ function RenderTextBlock(props) {
968
988
  }) : console.error(`Unable to find Schema type for text block style ${props.textBlock.style}`);
969
989
  }
970
990
  if (props.renderListItem && props.textBlock.listItem) {
971
- const legacyListItemSchemaType = legacySchema.lists.find((list) => list.value === props.textBlock.listItem);
991
+ const legacyListItemSchemaType = props.legacySchema.lists.find((list) => list.value === props.textBlock.listItem);
972
992
  legacyListItemSchemaType ? children = props.renderListItem({
973
993
  block: props.textBlock,
974
994
  children,
@@ -1003,58 +1023,27 @@ function RenderTextBlock(props) {
1003
1023
  _key: props.textBlock._key
1004
1024
  }],
1005
1025
  selected,
1006
- schemaType: legacyBlockSchemaType,
1026
+ schemaType: props.legacySchema.block,
1007
1027
  style: props.textBlock.style,
1008
- type: legacyBlockSchemaType,
1028
+ type: props.legacySchema.block,
1009
1029
  value: props.textBlock
1010
1030
  }) : children }),
1011
1031
  dragPositionBlock === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
1012
1032
  ] });
1013
1033
  }
1014
1034
  function RenderElement(props) {
1015
- const $ = c(43), editorActor = useContext(EditorActorContext), schema = useSelector(editorActor, _temp$1);
1016
- if ("__inline" in props.element && props.element.__inline === !0) {
1017
- let t02;
1018
- $[0] !== props.element ? (t02 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[0] = props.element, $[1] = t02) : t02 = $[1];
1019
- let t12;
1020
- $[2] !== props.element._key || $[3] !== props.element._type || $[4] !== t02 ? (t12 = {
1021
- _key: props.element._key,
1022
- _type: props.element._type,
1023
- ...t02
1024
- }, $[2] = props.element._key, $[3] = props.element._type, $[4] = t02, $[5] = t12) : t12 = $[5];
1025
- const inlineObject = t12;
1026
- schema.inlineObjects.find((inlineObject_0) => inlineObject_0.name === props.element._type) || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
1027
- let t22;
1028
- $[6] !== inlineObject || $[7] !== props.element._key || $[8] !== props.element._type ? (t22 = inlineObject ?? {
1029
- _key: props.element._key,
1030
- _type: props.element._type
1031
- }, $[6] = inlineObject, $[7] = props.element._key, $[8] = props.element._type, $[9] = t22) : t22 = $[9];
1032
- let t32;
1033
- return $[10] !== props.attributes || $[11] !== props.children || $[12] !== props.element || $[13] !== props.readOnly || $[14] !== props.renderChild || $[15] !== t22 ? (t32 = /* @__PURE__ */ 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;
1034
- }
1035
+ const $ = c(19), editorActor = useContext(EditorActorContext), schema = useSelector(editorActor, _temp$1), legacySchema = useSelector(editorActor, _temp2);
1035
1036
  if (isTextBlock({
1036
1037
  schema
1037
1038
  }, props.element)) {
1038
1039
  let t02;
1039
- 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__ */ 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;
1040
+ 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__ */ 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;
1040
1041
  }
1041
1042
  let t0;
1042
- $[26] !== props.element ? (t0 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[26] = props.element, $[27] = t0) : t0 = $[27];
1043
- let t1;
1044
- $[28] !== props.element._key || $[29] !== props.element._type || $[30] !== t0 ? (t1 = {
1045
- _key: props.element._key,
1046
- _type: props.element._type,
1047
- ...t0
1048
- }, $[28] = props.element._key, $[29] = props.element._type, $[30] = t0, $[31] = t1) : t1 = $[31];
1049
- const blockObject = t1;
1050
- schema.blockObjects.find((blockObject_0) => blockObject_0.name === props.element._type) || console.error(`Unable to find Block Object "${props.element._type}" in Schema`);
1051
- let t2;
1052
- $[32] !== blockObject || $[33] !== props.element._key || $[34] !== props.element._type ? (t2 = blockObject ?? {
1053
- _key: props.element._key,
1054
- _type: props.element._type
1055
- }, $[32] = blockObject, $[33] = props.element._key, $[34] = props.element._type, $[35] = t2) : t2 = $[35];
1056
- let t3;
1057
- return $[36] !== props.attributes || $[37] !== props.children || $[38] !== props.element || $[39] !== props.readOnly || $[40] !== props.renderBlock || $[41] !== t2 ? (t3 = /* @__PURE__ */ 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;
1043
+ return $[10] !== legacySchema || $[11] !== props.attributes || $[12] !== props.children || $[13] !== props.element || $[14] !== props.readOnly || $[15] !== props.renderBlock || $[16] !== props.renderChild || $[17] !== schema ? (t0 = /* @__PURE__ */ jsx(RenderObject, { attributes: props.attributes, element: props.element, legacySchema, readOnly: props.readOnly, renderBlock: props.renderBlock, renderChild: props.renderChild, schema, children: props.children }), $[10] = legacySchema, $[11] = props.attributes, $[12] = props.children, $[13] = props.element, $[14] = props.readOnly, $[15] = props.renderBlock, $[16] = props.renderChild, $[17] = schema, $[18] = t0) : t0 = $[18], t0;
1044
+ }
1045
+ function _temp2(s_0) {
1046
+ return s_0.context.getLegacySchema();
1058
1047
  }
1059
1048
  function _temp$1(s) {
1060
1049
  return s.context.schema;
@@ -5240,7 +5229,11 @@ function pluginUpdateValue(context, editor) {
5240
5229
  apply2(operation);
5241
5230
  return;
5242
5231
  }
5243
- editor.value = applyOperationToPortableText(context, editor.value, operation), buildIndexMaps({
5232
+ if (editor.value = applyOperationToPortableText(context, editor.value, operation), operation.type === "insert_text" || operation.type === "remove_text") {
5233
+ apply2(operation);
5234
+ return;
5235
+ }
5236
+ buildIndexMaps({
5244
5237
  schema: context.schema,
5245
5238
  value: editor.value
5246
5239
  }, {
@@ -7669,7 +7662,8 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
7669
7662
  behaviors: ({
7670
7663
  context,
7671
7664
  event
7672
- }) => (assertEvent(event, "add behavior"), /* @__PURE__ */ new Set([...context.behaviors, event.behaviorConfig]))
7665
+ }) => (assertEvent(event, "add behavior"), /* @__PURE__ */ new Set([...context.behaviors, event.behaviorConfig])),
7666
+ behaviorsSorted: !1
7673
7667
  }),
7674
7668
  "remove behavior from context": assign({
7675
7669
  behaviors: ({
@@ -7758,7 +7752,7 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
7758
7752
  }) => {
7759
7753
  assertEvent(event, ["behavior event"]);
7760
7754
  try {
7761
- const behaviors = sortByPriority([...context.behaviors.values(), ...coreBehaviorsConfig]).map((config) => config.behavior);
7755
+ const behaviors = [...context.behaviors.values()].map((config) => config.behavior);
7762
7756
  performEvent({
7763
7757
  mode: "raise",
7764
7758
  behaviors,
@@ -7782,7 +7776,13 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
7782
7776
  } catch (error) {
7783
7777
  console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`));
7784
7778
  }
7785
- }
7779
+ },
7780
+ "sort behaviors": assign({
7781
+ behaviors: ({
7782
+ context
7783
+ }) => context.behaviorsSorted ? context.behaviors : new Set(sortByPriority([...context.behaviors.values()])),
7784
+ behaviorsSorted: !0
7785
+ })
7786
7786
  },
7787
7787
  guards: {
7788
7788
  "slate is busy": ({
@@ -7794,7 +7794,8 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
7794
7794
  context: ({
7795
7795
  input
7796
7796
  }) => ({
7797
- behaviors: /* @__PURE__ */ new Set([]),
7797
+ behaviors: new Set(coreBehaviorsConfig),
7798
+ behaviorsSorted: !1,
7798
7799
  converters: new Set(input.converters ?? []),
7799
7800
  getLegacySchema: input.getLegacySchema,
7800
7801
  keyGenerator: input.keyGenerator,
@@ -7849,7 +7850,7 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
7849
7850
  initial: "determine initial edit mode",
7850
7851
  on: {
7851
7852
  "behavior event": {
7852
- actions: "handle behavior event",
7853
+ actions: ["sort behaviors", "handle behavior event"],
7853
7854
  guard: ({
7854
7855
  event
7855
7856
  }) => 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"
@@ -7903,7 +7904,7 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
7903
7904
  actions: ["emit read only"]
7904
7905
  },
7905
7906
  "behavior event": {
7906
- actions: "handle behavior event"
7907
+ actions: ["sort behaviors", "handle behavior event"]
7907
7908
  },
7908
7909
  blur: {
7909
7910
  actions: "handle blur"