@portabletext/editor 2.17.1 → 2.18.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 (46) hide show
  1. package/lib/_chunks-dts/{behavior.types.action.d.cts → index.d.ts} +9 -9
  2. package/lib/_chunks-es/util.get-text-block-text.js +1 -2
  3. package/lib/_chunks-es/util.get-text-block-text.js.map +1 -1
  4. package/lib/behaviors/index.d.ts +1 -1
  5. package/lib/index.d.ts +1 -1
  6. package/lib/plugins/index.d.ts +2 -2
  7. package/lib/selectors/index.d.ts +2 -2
  8. package/lib/utils/index.d.ts +3 -3
  9. package/package.json +18 -30
  10. package/src/test/vitest/step-definitions.tsx +2 -0
  11. package/src/test/vitest/test-editor.tsx +18 -4
  12. package/src/utils/key-generator.ts +1 -3
  13. package/lib/_chunks-cjs/selector.get-selection-text.cjs +0 -89
  14. package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +0 -1
  15. package/lib/_chunks-cjs/selector.get-text-before.cjs +0 -34
  16. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +0 -1
  17. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +0 -875
  18. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +0 -1
  19. package/lib/_chunks-cjs/use-editor.cjs +0 -28
  20. package/lib/_chunks-cjs/use-editor.cjs.map +0 -1
  21. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +0 -79
  22. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +0 -1
  23. package/lib/_chunks-cjs/util.get-text-block-text.cjs +0 -477
  24. package/lib/_chunks-cjs/util.get-text-block-text.cjs.map +0 -1
  25. package/lib/_chunks-cjs/util.is-empty-text-block.cjs +0 -38
  26. package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +0 -1
  27. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +0 -23
  28. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +0 -1
  29. package/lib/_chunks-cjs/util.slice-text-block.cjs +0 -63
  30. package/lib/_chunks-cjs/util.slice-text-block.cjs.map +0 -1
  31. package/lib/_chunks-dts/behavior.types.action.d.ts +0 -3650
  32. package/lib/behaviors/index.cjs +0 -35
  33. package/lib/behaviors/index.cjs.map +0 -1
  34. package/lib/behaviors/index.d.cts +0 -2
  35. package/lib/index.cjs +0 -12952
  36. package/lib/index.cjs.map +0 -1
  37. package/lib/index.d.cts +0 -2
  38. package/lib/plugins/index.cjs +0 -826
  39. package/lib/plugins/index.cjs.map +0 -1
  40. package/lib/plugins/index.d.cts +0 -196
  41. package/lib/selectors/index.cjs +0 -243
  42. package/lib/selectors/index.cjs.map +0 -1
  43. package/lib/selectors/index.d.cts +0 -357
  44. package/lib/utils/index.cjs +0 -97
  45. package/lib/utils/index.cjs.map +0 -1
  46. package/lib/utils/index.d.cts +0 -186
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var schema = require("@portabletext/schema"), util_getTextBlockText = require("./util.get-text-block-text.cjs"), types = require("@sanity/types");
3
- const getFocusBlock = (snapshot) => {
4
- if (!snapshot.context.selection)
5
- return;
6
- const key = util_getTextBlockText.getBlockKeyFromSelectionPoint(snapshot.context.selection.focus), index = key ? snapshot.blockIndexMap.get(key) : void 0, node = index !== void 0 ? snapshot.context.value.at(index) : void 0;
7
- return node && key ? {
8
- node,
9
- path: [{
10
- _key: key
11
- }]
12
- } : void 0;
13
- }, getFocusTextBlock = (snapshot) => {
14
- const focusBlock = getFocusBlock(snapshot);
15
- return focusBlock && schema.isTextBlock(snapshot.context, focusBlock.node) ? {
16
- node: focusBlock.node,
17
- path: focusBlock.path
18
- } : void 0;
19
- }, getFocusChild = (snapshot) => {
20
- if (!snapshot.context.selection)
21
- return;
22
- const focusBlock = getFocusTextBlock(snapshot);
23
- if (!focusBlock)
24
- return;
25
- const key = util_getTextBlockText.getChildKeyFromSelectionPoint(snapshot.context.selection.focus), node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
26
- return node && key ? {
27
- node,
28
- path: [...focusBlock.path, "children", {
29
- _key: key
30
- }]
31
- } : void 0;
32
- }, getFocusSpan = (snapshot) => {
33
- const focusChild = getFocusChild(snapshot);
34
- return focusChild && schema.isSpan(snapshot.context, focusChild.node) ? {
35
- node: focusChild.node,
36
- path: focusChild.path
37
- } : void 0;
38
- }, getSelectionStartPoint = (snapshot) => {
39
- if (snapshot.context.selection)
40
- return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
41
- }, isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), getSelectedValue = (snapshot) => {
42
- const selection = snapshot.context.selection;
43
- if (!selection)
44
- return [];
45
- const startPoint = util_getTextBlockText.getSelectionStartPoint(selection), endPoint = util_getTextBlockText.getSelectionEndPoint(selection), startBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(endPoint);
46
- if (!startBlockKey || !endBlockKey)
47
- return [];
48
- const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
49
- if (startBlockIndex === void 0 || endBlockIndex === void 0)
50
- return [];
51
- const startBlock = snapshot.context.value.at(startBlockIndex), slicedStartBlock = startBlock ? util_getTextBlockText.sliceBlocks({
52
- context: snapshot.context,
53
- blocks: [startBlock]
54
- }).at(0) : void 0;
55
- if (startBlockIndex === endBlockIndex)
56
- return slicedStartBlock ? [slicedStartBlock] : [];
57
- const endBlock = snapshot.context.value.at(endBlockIndex), slicedEndBlock = endBlock ? util_getTextBlockText.sliceBlocks({
58
- context: snapshot.context,
59
- blocks: [endBlock]
60
- }).at(0) : void 0, middleBlocks = snapshot.context.value.slice(startBlockIndex + 1, endBlockIndex);
61
- return [...slicedStartBlock ? [slicedStartBlock] : [], ...middleBlocks, ...slicedEndBlock ? [slicedEndBlock] : []];
62
- }, getPreviousInlineObject = (snapshot) => {
63
- const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
64
- if (!focusTextBlock || !selectionStartPointChildKey)
65
- return;
66
- let inlineObject;
67
- for (const child of focusTextBlock.node.children) {
68
- if (child._key === selectionStartPointChildKey)
69
- break;
70
- schema.isSpan(snapshot.context, child) || (inlineObject = {
71
- node: child,
72
- path: [...focusTextBlock.path, "children", {
73
- _key: child._key
74
- }]
75
- });
76
- }
77
- return inlineObject;
78
- }, getSelectionText = (snapshot) => getSelectedValue(snapshot).reduce((text, block) => schema.isTextBlock(snapshot.context, block) ? text + block.children.reduce((text2, child) => schema.isSpan(snapshot.context, child) ? text2 + child.text : text2, "") : text, "");
79
- exports.getFocusBlock = getFocusBlock;
80
- exports.getFocusChild = getFocusChild;
81
- exports.getFocusSpan = getFocusSpan;
82
- exports.getFocusTextBlock = getFocusTextBlock;
83
- exports.getPreviousInlineObject = getPreviousInlineObject;
84
- exports.getSelectedValue = getSelectedValue;
85
- exports.getSelectionStartPoint = getSelectionStartPoint;
86
- exports.getSelectionText = getSelectionText;
87
- exports.isSelectionCollapsed = isSelectionCollapsed;
88
- exports.isSelectionExpanded = isSelectionExpanded;
89
- //# sourceMappingURL=selector.get-selection-text.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"selector.get-selection-text.cjs","sources":["../../src/selectors/selector.get-focus-block.ts","../../src/selectors/selector.get-focus-text-block.ts","../../src/selectors/selector.get-focus-child.ts","../../src/selectors/selector.get-focus-span.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-selected-value.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selection-text.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return snapshot.context.selection !== null && !isSelectionCollapsed(snapshot)\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {sliceBlocks} from '../utils/util.slice-blocks'\n\n/**\n * @public\n */\nexport const getSelectedValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return []\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return []\n }\n\n const startBlock = snapshot.context.value.at(startBlockIndex)\n const slicedStartBlock = startBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [startBlock],\n }).at(0)\n : undefined\n\n if (startBlockIndex === endBlockIndex) {\n return slicedStartBlock ? [slicedStartBlock] : []\n }\n\n const endBlock = snapshot.context.value.at(endBlockIndex)\n const slicedEndBlock = endBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [endBlock],\n }).at(0)\n : undefined\n\n const middleBlocks = snapshot.context.value.slice(\n startBlockIndex + 1,\n endBlockIndex,\n )\n\n return [\n ...(slicedStartBlock ? [slicedStartBlock] : []),\n ...middleBlocks,\n ...(slicedEndBlock ? [slicedEndBlock] : []),\n ]\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedValue = getSelectedValue(snapshot)\n\n return selectedValue.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n"],"names":["getFocusBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","focus","index","blockIndexMap","get","undefined","node","value","at","path","_key","getFocusTextBlock","focusBlock","isTextBlock","getFocusChild","getChildKeyFromSelectionPoint","children","find","span","getFocusSpan","focusChild","isSpan","getSelectionStartPoint","backward","anchor","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getSelectedValue","startPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startBlockIndex","endBlockIndex","startBlock","slicedStartBlock","sliceBlocks","blocks","endBlock","slicedEndBlock","middleBlocks","slice","getPreviousInlineObject","focusTextBlock","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectionText","reduce","text","block"],"mappings":";;AAQO,MAAMA,gBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAAS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;;;;;;;;;;;"}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var util_getTextBlockText = require("./util.get-text-block-text.cjs"), selector_getSelectionText = require("./selector.get-selection-text.cjs");
3
- const getBlockTextBefore = (snapshot) => {
4
- if (!snapshot.context.selection)
5
- return "";
6
- const startPoint = util_getTextBlockText.getSelectionStartPoint(snapshot.context.selection), block = selector_getSelectionText.getFocusBlock({
7
- ...snapshot,
8
- context: {
9
- ...snapshot.context,
10
- selection: {
11
- anchor: startPoint,
12
- focus: startPoint
13
- }
14
- }
15
- });
16
- if (!block)
17
- return "";
18
- const startOfBlock = util_getTextBlockText.getBlockStartPoint({
19
- context: snapshot.context,
20
- block
21
- });
22
- return selector_getSelectionText.getSelectionText({
23
- ...snapshot,
24
- context: {
25
- ...snapshot.context,
26
- selection: {
27
- anchor: startOfBlock,
28
- focus: startPoint
29
- }
30
- }
31
- });
32
- };
33
- exports.getBlockTextBefore = getBlockTextBefore;
34
- //# sourceMappingURL=selector.get-text-before.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAAA,aAAa;AACtE,MAAI,CAACA,SAASC,QAAQC;AACpB,WAAO;AAGT,QAAMC,aAAaC,sBAAAA,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,wCAAc;AAAA,IAC1B,GAAGN;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQJ;AAAAA,QACRK,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACE;AACH,WAAO;AAGT,QAAMI,eAAeC,sBAAAA,mBAAmB;AAAA,IACtCT,SAASD,SAASC;AAAAA,IAClBI;AAAAA,EAAAA,CACD;AAED,SAAOM,2CAAiB;AAAA,IACtB,GAAGX;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQE;AAAAA,QACRD,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;"}