@portabletext/editor 1.47.2 → 1.47.3

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,10 +1,15 @@
1
1
  "use strict";
2
+ var util_sliceBlocks = require("./util.slice-blocks.cjs");
2
3
  function getSelectionEndPoint(selection) {
3
4
  return selection ? selection.backward ? selection.anchor : selection.focus : null;
4
5
  }
6
+ function isEqualSelections(a, b) {
7
+ return !a && !b ? !0 : !a || !b ? !1 : util_sliceBlocks.isEqualSelectionPoints(a.anchor, b.anchor) && util_sliceBlocks.isEqualSelectionPoints(a.focus, b.focus);
8
+ }
5
9
  function isSelectionCollapsed(selection) {
6
10
  return selection ? selection.anchor.path.join() === selection.focus.path.join() && selection.anchor.offset === selection.focus.offset : !1;
7
11
  }
8
12
  exports.getSelectionEndPoint = getSelectionEndPoint;
13
+ exports.isEqualSelections = isEqualSelections;
9
14
  exports.isSelectionCollapsed = isSelectionCollapsed;
10
15
  //# sourceMappingURL=util.is-selection-collapsed.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.is-selection-collapsed.cjs","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","isSelectionCollapsed","path","join","offset"],"mappings":";AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACdO,SAASC,qBAAqBJ,WAA4B;AAC/D,SAAKA,YAKHA,UAAUE,OAAOG,KAAKC,KAAAA,MAAWN,UAAUG,MAAME,KAAKC,KAAAA,KACtDN,UAAUE,OAAOK,WAAWP,UAAUG,MAAMI,SALrC;AAOX;;;"}
1
+ {"version":3,"file":"util.is-selection-collapsed.cjs","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.is-equal-selections.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","isEqualSelections","a","b","isEqualSelectionPoints","isSelectionCollapsed","path","join","offset"],"mappings":";;AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACbgBC,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,iBAAAA,uBAAuBF,EAAEH,QAAQI,EAAEJ,MAAM,KACzCK,wCAAuBF,EAAEF,OAAOG,EAAEH,KAAK;AAE3C;ACdO,SAASK,qBAAqBR,WAA4B;AAC/D,SAAKA,YAKHA,UAAUE,OAAOO,KAAKC,KAAAA,MAAWV,UAAUG,MAAMM,KAAKC,KAAAA,KACtDV,UAAUE,OAAOS,WAAWX,UAAUG,MAAMQ,SALrC;AAOX;;;;"}
@@ -1,11 +1,16 @@
1
+ import { isEqualSelectionPoints } from "./util.slice-blocks.js";
1
2
  function getSelectionEndPoint(selection) {
2
3
  return selection ? selection.backward ? selection.anchor : selection.focus : null;
3
4
  }
5
+ function isEqualSelections(a, b) {
6
+ return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
7
+ }
4
8
  function isSelectionCollapsed(selection) {
5
9
  return selection ? selection.anchor.path.join() === selection.focus.path.join() && selection.anchor.offset === selection.focus.offset : !1;
6
10
  }
7
11
  export {
8
12
  getSelectionEndPoint,
13
+ isEqualSelections,
9
14
  isSelectionCollapsed
10
15
  };
11
16
  //# sourceMappingURL=util.is-selection-collapsed.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.is-selection-collapsed.js","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","isSelectionCollapsed","path","join","offset"],"mappings":"AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACdO,SAASC,qBAAqBJ,WAA4B;AAC/D,SAAKA,YAKHA,UAAUE,OAAOG,KAAKC,KAAAA,MAAWN,UAAUG,MAAME,KAAKC,KAAAA,KACtDN,UAAUE,OAAOK,WAAWP,UAAUG,MAAMI,SALrC;AAOX;"}
1
+ {"version":3,"file":"util.is-selection-collapsed.js","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.is-equal-selections.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","isEqualSelections","a","b","isEqualSelectionPoints","isSelectionCollapsed","path","join","offset"],"mappings":";AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACbgBC,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEH,QAAQI,EAAEJ,MAAM,KACzCK,uBAAuBF,EAAEF,OAAOG,EAAEH,KAAK;AAE3C;ACdO,SAASK,qBAAqBR,WAA4B;AAC/D,SAAKA,YAKHA,UAAUE,OAAOO,KAAKC,KAAAA,MAAWV,UAAUG,MAAMM,KAAKC,KAAAA,KACtDV,UAAUE,OAAOS,WAAWX,UAAUG,MAAMQ,SALrC;AAOX;"}
package/lib/index.cjs CHANGED
@@ -1164,7 +1164,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
1164
1164
  });
1165
1165
  }
1166
1166
  }, [onCut, editorActor, slateEditor]), handlePaste = React.useCallback((event_1) => {
1167
- const value = editorProvider.PortableTextEditor.getValue(portableTextEditor), path = (slateEditor.selection ? editorProvider.slateRangeToSelection({
1167
+ const value = editorProvider.fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name, editorProvider.KEY_TO_VALUE_ELEMENT.get(slateEditor)), path = (slateEditor.selection ? editorProvider.slateRangeToSelection({
1168
1168
  schema: editorActor.getSnapshot().context.schema,
1169
1169
  editor: slateEditor,
1170
1170
  range: slateEditor.selection
@@ -1247,18 +1247,26 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
1247
1247
  debug("No result from custom paste handler, pasting normally");
1248
1248
  }, [editorActor, onPaste, portableTextEditor, slateEditor]), handleOnFocus = React.useCallback((event_2) => {
1249
1249
  if (onFocus && onFocus(event_2), !event_2.isDefaultPrevented()) {
1250
- const selection_3 = editorProvider.PortableTextEditor.getSelection(portableTextEditor);
1251
- selection_3 === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
1250
+ const selectionBefore = slateEditor.selection ? editorProvider.slateRangeToSelection({
1251
+ schema: editorActor.getSnapshot().context.schema,
1252
+ editor: slateEditor,
1253
+ range: slateEditor.selection
1254
+ }) : null;
1255
+ editorActor.send({
1252
1256
  type: "notify.focused",
1253
1257
  event: event_2
1254
1258
  });
1255
- const newSelection = editorProvider.PortableTextEditor.getSelection(portableTextEditor);
1256
- selection_3 === newSelection && editorActor.send({
1259
+ const selectionAfter = slateEditor.selection ? editorProvider.slateRangeToSelection({
1260
+ schema: editorActor.getSnapshot().context.schema,
1261
+ editor: slateEditor,
1262
+ range: slateEditor.selection
1263
+ }) : null;
1264
+ selectionBefore && selectionAfter && util_isSelectionCollapsed.isEqualSelections(selectionBefore, selectionAfter) && editorActor.send({
1257
1265
  type: "notify.selection",
1258
- selection: selection_3
1266
+ selection: selectionBefore
1259
1267
  });
1260
1268
  }
1261
- }, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = React.useCallback((event_3) => {
1269
+ }, [editorActor, onFocus, slateEditor]), handleClick = React.useCallback((event_3) => {
1262
1270
  if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
1263
1271
  return;
1264
1272
  const position_3 = getEventPosition({