@portabletext/editor 1.40.2 → 1.40.4

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 (74) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +37 -16
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +22 -10
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +93 -100
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +6 -0
  8. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -0
  9. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +26 -0
  10. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +1 -0
  12. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  13. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  14. package/lib/_chunks-es/behavior.core.js +37 -16
  15. package/lib/_chunks-es/behavior.core.js.map +1 -1
  16. package/lib/_chunks-es/behavior.markdown.js +22 -10
  17. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  18. package/lib/_chunks-es/editor-provider.js +94 -101
  19. package/lib/_chunks-es/editor-provider.js.map +1 -1
  20. package/lib/_chunks-es/util.is-selection-collapsed.js +7 -0
  21. package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -0
  22. package/lib/_chunks-es/util.merge-text-blocks.js +27 -0
  23. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -0
  24. package/lib/_chunks-es/util.selection-point-to-block-offset.js +1 -0
  25. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  26. package/lib/behaviors/index.d.cts +3881 -5053
  27. package/lib/behaviors/index.d.ts +3881 -5053
  28. package/lib/index.cjs +47 -13
  29. package/lib/index.cjs.map +1 -1
  30. package/lib/index.d.cts +3402 -4440
  31. package/lib/index.d.ts +3402 -4440
  32. package/lib/index.js +49 -14
  33. package/lib/index.js.map +1 -1
  34. package/lib/plugins/index.cjs +9 -127
  35. package/lib/plugins/index.cjs.map +1 -1
  36. package/lib/plugins/index.d.cts +3404 -4441
  37. package/lib/plugins/index.d.ts +3404 -4441
  38. package/lib/plugins/index.js +11 -129
  39. package/lib/plugins/index.js.map +1 -1
  40. package/lib/selectors/index.d.cts +3401 -4440
  41. package/lib/selectors/index.d.ts +3401 -4440
  42. package/lib/utils/index.cjs +45 -7
  43. package/lib/utils/index.cjs.map +1 -1
  44. package/lib/utils/index.d.cts +3403 -4443
  45. package/lib/utils/index.d.ts +3403 -4443
  46. package/lib/utils/index.js +45 -5
  47. package/lib/utils/index.js.map +1 -1
  48. package/package.json +6 -6
  49. package/src/behavior-actions/behavior.action.delete.block.ts +2 -2
  50. package/src/behavior-actions/behavior.action.insert-blocks.ts +5 -1
  51. package/src/behavior-actions/behavior.actions.ts +0 -18
  52. package/src/behaviors/behavior.core.block-objects.ts +57 -7
  53. package/src/behaviors/behavior.core.insert-break.ts +0 -4
  54. package/src/behaviors/behavior.default.ts +1 -1
  55. package/src/behaviors/behavior.markdown.ts +22 -10
  56. package/src/behaviors/behavior.types.ts +171 -138
  57. package/src/editor/create-editor.ts +2 -0
  58. package/src/editor/editor-machine.ts +28 -28
  59. package/src/editor/plugins/create-with-event-listeners.ts +15 -0
  60. package/src/editor/plugins/createWithEditableAPI.ts +4 -4
  61. package/src/internal-utils/drag-selection.test.ts +74 -1
  62. package/src/internal-utils/drag-selection.ts +20 -4
  63. package/src/internal-utils/event-position.ts +38 -7
  64. package/src/internal-utils/slate-utils.ts +60 -1
  65. package/src/plugins/plugin.one-line.tsx +10 -128
  66. package/src/types/block-with-optional-key.ts +13 -0
  67. package/src/utils/util.is-keyed-segment.ts +2 -2
  68. package/src/utils/util.is-text-block.ts +4 -3
  69. package/lib/_chunks-cjs/util.split-text-block.cjs +0 -68
  70. package/lib/_chunks-cjs/util.split-text-block.cjs.map +0 -1
  71. package/lib/_chunks-es/util.split-text-block.js +0 -70
  72. package/lib/_chunks-es/util.split-text-block.js.map +0 -1
  73. package/src/behavior-actions/behavior.action.insert.block-object.ts +0 -20
  74. package/src/behavior-actions/behavior.action.insert.text-block.ts +0 -33
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.split-text-block.cjs","sources":["../../src/utils/util.is-text-block.ts","../../src/utils/util.merge-text-blocks.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {PortableTextBlock, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\n\n/**\n * @public\n */\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock,\n): block is PortableTextTextBlock {\n return block._type === context.schema.block.name\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\nimport {isTextBlock} from './util.is-text-block'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {refreshKeys: true},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n }).at(0)\n const after = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isTextBlock","context","block","_type","schema","name","mergeTextBlocks","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","options","refreshKeys","children","markDefs","splitTextBlock","point","firstChild","at","lastChild","length","before","sliceBlocks","blocks","selection","anchor","path","_key","offset","focus","after","isSpan","text"],"mappings":";;AAMgBA,SAAAA,YACdC,SACAC,OACgC;AAChC,SAAOA,MAAMC,UAAUF,QAAQG,OAAOF,MAAMG;AAC9C;ACHO,SAASC,gBAAgB;AAAA,EAC9BL;AAAAA,EACAM;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,iCAAAA,WAAW;AAAA,IACrCT;AAAAA,IACAC,OAAOM;AAAAA,IACPG,SAAS;AAAA,MAACC,aAAa;AAAA,IAAA;AAAA,EAAI,CAC5B;AAED,SAAI,CAACH,uBAAuB,CAACT,YAAYC,SAASQ,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHM,UAAU,CAAC,GAAGN,YAAYM,UAAU,GAAGJ,oBAAoBI,QAAQ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70 +0,0 @@
1
- import { parseBlock } from "./util.selection-point-to-block-offset.js";
2
- import { sliceBlocks, isSpan } from "./util.slice-blocks.js";
3
- function isTextBlock(context, block) {
4
- return block._type === context.schema.block.name;
5
- }
6
- function mergeTextBlocks({
7
- context,
8
- targetBlock,
9
- incomingBlock
10
- }) {
11
- const parsedIncomingBlock = parseBlock({
12
- context,
13
- block: incomingBlock,
14
- options: {
15
- refreshKeys: !0
16
- }
17
- });
18
- return !parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock) ? targetBlock : {
19
- ...targetBlock,
20
- children: [...targetBlock.children, ...parsedIncomingBlock.children],
21
- markDefs: [...targetBlock.markDefs ?? [], ...parsedIncomingBlock.markDefs ?? []]
22
- };
23
- }
24
- function splitTextBlock({
25
- context,
26
- block,
27
- point
28
- }) {
29
- const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
30
- if (!firstChild || !lastChild)
31
- return;
32
- const before = sliceBlocks({
33
- blocks: [block],
34
- selection: {
35
- anchor: {
36
- path: [{
37
- _key: block._key
38
- }, "children", {
39
- _key: firstChild._key
40
- }],
41
- offset: 0
42
- },
43
- focus: point
44
- }
45
- }).at(0), after = sliceBlocks({
46
- blocks: [block],
47
- selection: {
48
- anchor: point,
49
- focus: {
50
- path: [{
51
- _key: block._key
52
- }, "children", {
53
- _key: lastChild._key
54
- }],
55
- offset: isSpan(context, lastChild) ? lastChild.text.length : 0
56
- }
57
- }
58
- }).at(0);
59
- if (!(!before || !after) && !(!isTextBlock(context, before) || !isTextBlock(context, after)))
60
- return {
61
- before,
62
- after
63
- };
64
- }
65
- export {
66
- isTextBlock,
67
- mergeTextBlocks,
68
- splitTextBlock
69
- };
70
- //# sourceMappingURL=util.split-text-block.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.split-text-block.js","sources":["../../src/utils/util.is-text-block.ts","../../src/utils/util.merge-text-blocks.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {PortableTextBlock, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\n\n/**\n * @public\n */\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock,\n): block is PortableTextTextBlock {\n return block._type === context.schema.block.name\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\nimport {isTextBlock} from './util.is-text-block'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {refreshKeys: true},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n }).at(0)\n const after = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isTextBlock","context","block","_type","schema","name","mergeTextBlocks","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","options","refreshKeys","children","markDefs","splitTextBlock","point","firstChild","at","lastChild","length","before","sliceBlocks","blocks","selection","anchor","path","_key","offset","focus","after","isSpan","text"],"mappings":";;AAMgBA,SAAAA,YACdC,SACAC,OACgC;AAChC,SAAOA,MAAMC,UAAUF,QAAQG,OAAOF,MAAMG;AAC9C;ACHO,SAASC,gBAAgB;AAAA,EAC9BL;AAAAA,EACAM;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,WAAW;AAAA,IACrCT;AAAAA,IACAC,OAAOM;AAAAA,IACPG,SAAS;AAAA,MAACC,aAAa;AAAA,IAAA;AAAA,EAAI,CAC5B;AAED,SAAI,CAACH,uBAAuB,CAACT,YAAYC,SAASQ,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHM,UAAU,CAAC,GAAGN,YAAYM,UAAU,GAAGJ,oBAAoBI,QAAQ;AAAA,IACnEC,UAAU,CACR,GAAIP,YAAYO,YAAY,CAAA,GAC5B,GAAIL,oBAAoBK,YAAY,CAAG,CAAA;AAAA,EAE3C;AACF;ACzBO,SAASC,eAAe;AAAA,EAC7Bd;AAAAA,EACAC;AAAAA,EACAc;AAKF,GAA8E;AAC5E,QAAMC,aAAaf,MAAMW,SAASK,GAAG,CAAC,GAChCC,YAAYjB,MAAMW,SAASK,GAAGhB,MAAMW,SAASO,SAAS,CAAC;AAEzD,MAAA,CAACH,cAAc,CAACE;AAClB;AAGF,QAAME,SAASC,YAAY;AAAA,IACzBC,QAAQ,CAACrB,KAAK;AAAA,IACdsB,WAAW;AAAA,MACTC,QAAQ;AAAA,QACNC,MAAM,CAAC;AAAA,UAACC,MAAMzB,MAAMyB;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMV,WAAWU;AAAAA,QAAAA,CAAK;AAAA,QAC9DC,QAAQ;AAAA,MACV;AAAA,MACAC,OAAOb;AAAAA,IAAAA;AAAAA,EAEV,CAAA,EAAEE,GAAG,CAAC,GACDY,QAAQR,YAAY;AAAA,IACxBC,QAAQ,CAACrB,KAAK;AAAA,IACdsB,WAAW;AAAA,MACTC,QAAQT;AAAAA,MACRa,OAAO;AAAA,QACLH,MAAM,CAAC;AAAA,UAACC,MAAMzB,MAAMyB;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMR,UAAUQ;AAAAA,QAAAA,CAAK;AAAA,QAC7DC,QAAQG,OAAO9B,SAASkB,SAAS,IAAIA,UAAUa,KAAKZ,SAAS;AAAA,MAAA;AAAA,IAC/D;AAAA,EACF,CACD,EAAEF,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACS,UAIZ,EAAC9B,CAAAA,YAAYC,SAASoB,MAAM,KAAK,CAACrB,YAAYC,SAAS6B,KAAK;AAIzD,WAAA;AAAA,MAACT;AAAAA,MAAQS;AAAAA,IAAK;AACvB;"}
@@ -1,20 +0,0 @@
1
- import {insertBlockActionImplementation} from './behavior.action.insert.block'
2
- import type {BehaviorActionImplementation} from './behavior.actions'
3
-
4
- export const insertBlockObjectActionImplementation: BehaviorActionImplementation<
5
- 'insert.block object'
6
- > = ({context, action}) => {
7
- insertBlockActionImplementation({
8
- context,
9
- action: {
10
- type: 'insert.block',
11
- block: {
12
- _key: context.keyGenerator(),
13
- _type: action.blockObject.name,
14
- ...(action.blockObject.value ? action.blockObject.value : {}),
15
- },
16
- editor: action.editor,
17
- placement: action.placement,
18
- },
19
- })
20
- }
@@ -1,33 +0,0 @@
1
- import {insertBlockActionImplementation} from './behavior.action.insert.block'
2
- import type {BehaviorActionImplementation} from './behavior.actions'
3
-
4
- export const insertTextBlockActionImplementation: BehaviorActionImplementation<
5
- 'insert.text block'
6
- > = ({context, action}) => {
7
- insertBlockActionImplementation({
8
- context,
9
- action: {
10
- type: 'insert.block',
11
- block: {
12
- _key: context.keyGenerator(),
13
- _type: context.schema.block.name,
14
- children: action.textBlock?.children?.map((child) => ({
15
- ...child,
16
- _key: context.keyGenerator(),
17
- })) ?? [
18
- {
19
- _type: context.schema.span.name,
20
- _key: context.keyGenerator(),
21
- text: '',
22
- marks: [],
23
- },
24
- ],
25
- markDefs: [],
26
- style: context.schema.styles[0].value ?? 'normal',
27
- },
28
- editor: action.editor,
29
- placement: action.placement,
30
- select: 'start',
31
- },
32
- })
33
- }