@portabletext/editor 1.40.4 → 1.41.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.
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ function getSelectionEndPoint(selection) {
3
+ return selection ? selection.backward ? selection.anchor : selection.focus : null;
4
+ }
2
5
  function isSelectionCollapsed(selection) {
3
6
  return selection ? selection.anchor.path.join() === selection.focus.path.join() && selection.anchor.offset === selection.focus.offset : !1;
4
7
  }
8
+ exports.getSelectionEndPoint = getSelectionEndPoint;
5
9
  exports.isSelectionCollapsed = isSelectionCollapsed;
6
10
  //# sourceMappingURL=util.is-selection-collapsed.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.is-selection-collapsed.cjs","sources":["../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["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":["isSelectionCollapsed","selection","anchor","path","join","focus","offset"],"mappings":";AAKO,SAASA,qBAAqBC,WAA4B;AAC/D,SAAKA,YAKHA,UAAUC,OAAOC,KAAKC,KAAAA,MAAWH,UAAUI,MAAMF,KAAKC,KAAAA,KACtDH,UAAUC,OAAOI,WAAWL,UAAUI,MAAMC,SALrC;AAOX;;"}
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;;;"}
@@ -356,14 +356,17 @@ function getFocusChild({
356
356
  const focusChild = Node.child(focusBlock, childIndex);
357
357
  return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
358
358
  }
359
+ function getFirstBlock({
360
+ editor
361
+ }) {
362
+ const firstBlockPath = Editor.start(editor, []).path.at(0);
363
+ return firstBlockPath !== void 0 ? Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
364
+ }
359
365
  function getLastBlock({
360
366
  editor
361
367
  }) {
362
- return Array.from(Editor.nodes(editor, {
363
- match: (n) => !Editor.isEditor(n),
364
- at: [],
365
- reverse: !0
366
- })).at(0) ?? [void 0, void 0];
368
+ const lastBlockPath = Editor.end(editor, []).path.at(0);
369
+ return lastBlockPath !== void 0 ? Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
367
370
  }
368
371
  function getNodeBlock({
369
372
  editor,
@@ -2616,7 +2619,7 @@ const converterJson = {
2616
2619
  data: sliceBlocks({
2617
2620
  blocks: snapshot.context.value,
2618
2621
  selection
2619
- }).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : "").join("") : "").filter((block) => block !== "").join(`
2622
+ }).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
2620
2623
 
2621
2624
  `),
2622
2625
  mimeType: "text/plain",
@@ -7730,6 +7733,8 @@ export {
7730
7733
  defineSchema,
7731
7734
  fromSlateValue,
7732
7735
  getEditorSnapshot,
7736
+ getFirstBlock,
7737
+ getLastBlock,
7733
7738
  getNodeBlock,
7734
7739
  isEqualToEmptyEditor,
7735
7740
  moveRangeByOperation,