@portabletext/editor 1.15.1 → 1.15.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.
Files changed (69) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +496 -0
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -0
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +0 -231
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selectors.cjs +234 -0
  6. package/lib/_chunks-cjs/selectors.cjs.map +1 -0
  7. package/lib/_chunks-es/behavior.core.js +498 -0
  8. package/lib/_chunks-es/behavior.core.js.map +1 -0
  9. package/lib/_chunks-es/selector.get-text-before.js +2 -233
  10. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  11. package/lib/_chunks-es/selectors.js +235 -0
  12. package/lib/_chunks-es/selectors.js.map +1 -0
  13. package/lib/behaviors/index.cjs +460 -0
  14. package/lib/behaviors/index.cjs.map +1 -0
  15. package/lib/behaviors/index.d.cts +869 -0
  16. package/lib/behaviors/index.d.ts +869 -0
  17. package/lib/behaviors/index.js +464 -0
  18. package/lib/behaviors/index.js.map +1 -0
  19. package/lib/index.cjs +51 -1035
  20. package/lib/index.cjs.map +1 -1
  21. package/lib/index.d.cts +146 -669
  22. package/lib/index.d.ts +146 -669
  23. package/lib/index.js +44 -1027
  24. package/lib/index.js.map +1 -1
  25. package/lib/selectors/index.cjs +16 -16
  26. package/lib/selectors/index.cjs.map +1 -1
  27. package/lib/selectors/index.d.cts +8 -12
  28. package/lib/selectors/index.d.ts +8 -12
  29. package/lib/selectors/index.js +3 -2
  30. package/lib/selectors/index.js.map +1 -1
  31. package/package.json +11 -5
  32. package/src/{editor/behavior → behavior-actions}/behavior.action-utils.insert-block.ts +4 -6
  33. package/src/{editor/behavior → behavior-actions}/behavior.action.insert-block-object.ts +1 -1
  34. package/src/{editor/behavior → behavior-actions}/behavior.action.insert-break.ts +1 -1
  35. package/src/{editor/behavior → behavior-actions}/behavior.action.insert-inline-object.ts +1 -1
  36. package/src/{editor/behavior → behavior-actions}/behavior.action.list-item.ts +2 -2
  37. package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.set.ts +1 -1
  38. package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.unset.ts +1 -1
  39. package/src/{editor/behavior → behavior-actions}/behavior.actions.ts +20 -20
  40. package/src/{editor/behavior → behavior-actions}/behavior.guards.ts +2 -6
  41. package/src/{editor/behavior → behaviors}/behavior.code-editor.ts +4 -4
  42. package/src/{editor/behavior → behaviors}/behavior.core.block-objects.ts +6 -6
  43. package/src/{editor/behavior → behaviors}/behavior.core.decorators.ts +6 -16
  44. package/src/{editor/behavior → behaviors}/behavior.core.lists.ts +17 -17
  45. package/src/{editor/behavior → behaviors}/behavior.links.ts +5 -5
  46. package/src/{editor/behavior → behaviors}/behavior.markdown.ts +25 -43
  47. package/src/{editor/behavior → behaviors}/behavior.types.ts +39 -46
  48. package/src/behaviors/index.ts +29 -0
  49. package/src/editor/PortableTextEditor.tsx +2 -2
  50. package/src/{utils/getPortableTextMemberSchemaTypes.ts → editor/create-editor-schema.ts} +3 -3
  51. package/src/editor/create-editor.ts +28 -48
  52. package/src/editor/define-schema.ts +8 -3
  53. package/src/editor/editor-machine.ts +21 -36
  54. package/src/editor/editor-selector.ts +1 -13
  55. package/src/editor/editor-snapshot.ts +4 -6
  56. package/src/editor/plugins/createWithEditableAPI.ts +3 -3
  57. package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -1
  58. package/src/editor/utils/utils.block-offset.ts +1 -1
  59. package/src/index.ts +14 -31
  60. package/src/selectors/index.ts +2 -4
  61. package/src/selectors/selector.get-active-list-item.ts +1 -1
  62. package/src/selectors/selectors.ts +1 -1
  63. package/src/type-utils.ts +17 -0
  64. package/src/utils/__tests__/operationToPatches.test.ts +3 -3
  65. package/src/utils/__tests__/patchToOperations.test.ts +3 -3
  66. package/src/utils/__tests__/values.test.ts +2 -2
  67. /package/src/{editor/behavior → behavior-actions}/behavior.action.insert-span.ts +0 -0
  68. /package/src/{editor/behavior → behavior-actions}/behavior.action.style.ts +0 -0
  69. /package/src/{editor/behavior → behaviors}/behavior.core.ts +0 -0
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
3
+ var selectors = require("../_chunks-cjs/selectors.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
4
4
  const getActiveListItem = ({
5
5
  context
6
6
  }) => {
7
7
  if (!context.selection)
8
8
  return;
9
- const guards = selector_getTextBefore.createGuards(context), selectedTextBlocks = selector_getTextBefore.getSelectedBlocks({
9
+ const guards = selectors.createGuards(context), selectedTextBlocks = selectors.getSelectedBlocks({
10
10
  context
11
11
  }).map((block) => block.node).filter(guards.isTextBlock), firstTextBlock = selectedTextBlocks.at(0);
12
12
  if (!firstTextBlock)
@@ -15,21 +15,21 @@ const getActiveListItem = ({
15
15
  if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
16
16
  return firstListItem;
17
17
  };
18
+ exports.getFirstBlock = selectors.getFirstBlock;
19
+ exports.getFocusBlock = selectors.getFocusBlock;
20
+ exports.getFocusBlockObject = selectors.getFocusBlockObject;
21
+ exports.getFocusChild = selectors.getFocusChild;
22
+ exports.getFocusListBlock = selectors.getFocusListBlock;
23
+ exports.getFocusSpan = selectors.getFocusSpan;
24
+ exports.getFocusTextBlock = selectors.getFocusTextBlock;
25
+ exports.getLastBlock = selectors.getLastBlock;
26
+ exports.getNextBlock = selectors.getNextBlock;
27
+ exports.getPreviousBlock = selectors.getPreviousBlock;
28
+ exports.getSelectedBlocks = selectors.getSelectedBlocks;
29
+ exports.getSelectionEndBlock = selectors.getSelectionEndBlock;
30
+ exports.getSelectionStartBlock = selectors.getSelectionStartBlock;
31
+ exports.selectionIsCollapsed = selectors.selectionIsCollapsed;
18
32
  exports.getBlockTextBefore = selector_getTextBefore.getBlockTextBefore;
19
- exports.getFirstBlock = selector_getTextBefore.getFirstBlock;
20
- exports.getFocusBlock = selector_getTextBefore.getFocusBlock;
21
- exports.getFocusBlockObject = selector_getTextBefore.getFocusBlockObject;
22
- exports.getFocusChild = selector_getTextBefore.getFocusChild;
23
- exports.getFocusListBlock = selector_getTextBefore.getFocusListBlock;
24
- exports.getFocusSpan = selector_getTextBefore.getFocusSpan;
25
- exports.getFocusTextBlock = selector_getTextBefore.getFocusTextBlock;
26
- exports.getLastBlock = selector_getTextBefore.getLastBlock;
27
- exports.getNextBlock = selector_getTextBefore.getNextBlock;
28
- exports.getPreviousBlock = selector_getTextBefore.getPreviousBlock;
29
- exports.getSelectedBlocks = selector_getTextBefore.getSelectedBlocks;
30
- exports.getSelectionEndBlock = selector_getTextBefore.getSelectionEndBlock;
31
- exports.getSelectionStartBlock = selector_getTextBefore.getSelectionStartBlock;
32
33
  exports.getSelectionText = selector_getTextBefore.getSelectionText;
33
- exports.selectionIsCollapsed = selector_getTextBefore.selectionIsCollapsed;
34
34
  exports.getActiveListItem = getActiveListItem;
35
35
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-list-item.ts"],"sourcesContent":["import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../editor/behavior/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @alpha\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n"],"names":["getActiveListItem","context","selection","guards","createGuards","selectedTextBlocks","getSelectedBlocks","map","block","node","filter","isTextBlock","firstTextBlock","at","firstListItem","listItem","every"],"mappings":";;;AAQO,MAAMA,oBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,uBAAAA,aAAaH,OAAO,GAE7BI,qBADiBC,uBAAAA,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAME,gBAAgBF,eAAeG;AAErC,MAAKD,iBAIDT,mBAAmBW,MAAOR,CAAUA,UAAAA,MAAMO,aAAaD,aAAa;AAC/DA,WAAAA;AAIX;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-list-item.ts"],"sourcesContent":["import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @alpha\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n"],"names":["getActiveListItem","context","selection","guards","createGuards","selectedTextBlocks","getSelectedBlocks","map","block","node","filter","isTextBlock","firstTextBlock","at","firstListItem","listItem","every"],"mappings":";;;AAQO,MAAMA,oBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,UAAAA,aAAaH,OAAO,GAE7BI,qBADiBC,UAAAA,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAME,gBAAgBF,eAAeG;AAErC,MAAKD,iBAIDT,mBAAmBW,MAAOR,CAAUA,UAAAA,MAAMO,aAAaD,aAAa;AAC/DA,WAAAA;AAIX;;;;;;;;;;;;;;;;;;"}
@@ -20,11 +20,16 @@ import {
20
20
  */
21
21
  export declare type EditorContext = {
22
22
  keyGenerator: () => string
23
- schema: PortableTextMemberSchemaTypes
24
- selection: NonNullable<EditorSelection>
23
+ schema: EditorSchema
24
+ selection: EditorSelection
25
25
  value: Array<PortableTextBlock>
26
26
  }
27
27
 
28
+ /**
29
+ * @alpha
30
+ */
31
+ export declare type EditorSchema = PortableTextMemberSchemaTypes
32
+
28
33
  /** @beta */
29
34
  export declare type EditorSelection = {
30
35
  anchor: EditorSelectionPoint
@@ -42,18 +47,9 @@ export declare type EditorSelectionPoint = {
42
47
  * @alpha
43
48
  */
44
49
  export declare type EditorSelector<TSelected> = (
45
- snapshot: EditorSelectorSnapshot,
50
+ snapshot: EditorSnapshot,
46
51
  ) => TSelected
47
52
 
48
- /**
49
- * @alpha
50
- */
51
- export declare type EditorSelectorSnapshot = {
52
- context: Omit<EditorSnapshot['context'], 'selection'> & {
53
- selection?: NonNullable<EditorSelection>
54
- }
55
- }
56
-
57
53
  /**
58
54
  * @alpha
59
55
  */
@@ -20,11 +20,16 @@ import {
20
20
  */
21
21
  export declare type EditorContext = {
22
22
  keyGenerator: () => string
23
- schema: PortableTextMemberSchemaTypes
24
- selection: NonNullable<EditorSelection>
23
+ schema: EditorSchema
24
+ selection: EditorSelection
25
25
  value: Array<PortableTextBlock>
26
26
  }
27
27
 
28
+ /**
29
+ * @alpha
30
+ */
31
+ export declare type EditorSchema = PortableTextMemberSchemaTypes
32
+
28
33
  /** @beta */
29
34
  export declare type EditorSelection = {
30
35
  anchor: EditorSelectionPoint
@@ -42,18 +47,9 @@ export declare type EditorSelectionPoint = {
42
47
  * @alpha
43
48
  */
44
49
  export declare type EditorSelector<TSelected> = (
45
- snapshot: EditorSelectorSnapshot,
50
+ snapshot: EditorSnapshot,
46
51
  ) => TSelected
47
52
 
48
- /**
49
- * @alpha
50
- */
51
- export declare type EditorSelectorSnapshot = {
52
- context: Omit<EditorSnapshot['context'], 'selection'> & {
53
- selection?: NonNullable<EditorSelection>
54
- }
55
- }
56
-
57
53
  /**
58
54
  * @alpha
59
55
  */
@@ -1,5 +1,6 @@
1
- import { getSelectedBlocks, createGuards } from "../_chunks-es/selector.get-text-before.js";
2
- import { getBlockTextBefore, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, selectionIsCollapsed } from "../_chunks-es/selector.get-text-before.js";
1
+ import { getSelectedBlocks, createGuards } from "../_chunks-es/selectors.js";
2
+ import { getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getSelectionEndBlock, getSelectionStartBlock, selectionIsCollapsed } from "../_chunks-es/selectors.js";
3
+ import { getBlockTextBefore, getSelectionText } from "../_chunks-es/selector.get-text-before.js";
3
4
  const getActiveListItem = ({
4
5
  context
5
6
  }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-list-item.ts"],"sourcesContent":["import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../editor/behavior/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @alpha\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n"],"names":["getActiveListItem","context","selection","guards","createGuards","selectedTextBlocks","getSelectedBlocks","map","block","node","filter","isTextBlock","firstTextBlock","at","firstListItem","listItem","every"],"mappings":";;AAQO,MAAMA,oBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,aAAaH,OAAO,GAE7BI,qBADiBC,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAME,gBAAgBF,eAAeG;AAErC,MAAKD,iBAIDT,mBAAmBW,MAAOR,CAAUA,UAAAA,MAAMO,aAAaD,aAAa;AAC/DA,WAAAA;AAIX;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-list-item.ts"],"sourcesContent":["import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @alpha\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n"],"names":["getActiveListItem","context","selection","guards","createGuards","selectedTextBlocks","getSelectedBlocks","map","block","node","filter","isTextBlock","firstTextBlock","at","firstListItem","listItem","every"],"mappings":";;;AAQO,MAAMA,oBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,aAAaH,OAAO,GAE7BI,qBADiBC,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAME,gBAAgBF,eAAeG;AAErC,MAAKD,iBAIDT,mBAAmBW,MAAOR,CAAUA,UAAAA,MAAMO,aAAaD,aAAa;AAC/DA,WAAAA;AAIX;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.15.1",
3
+ "version": "1.15.3",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -33,6 +33,12 @@
33
33
  "require": "./lib/index.cjs",
34
34
  "default": "./lib/index.js"
35
35
  },
36
+ "./behaviors": {
37
+ "source": "./src/behaviors/index.ts",
38
+ "import": "./lib/behaviors/index.js",
39
+ "require": "./lib/behaviors/index.cjs",
40
+ "default": "./lib/behaviors/index.js"
41
+ },
36
42
  "./selectors": {
37
43
  "source": "./src/selectors/index.ts",
38
44
  "import": "./lib/selectors/index.js",
@@ -55,7 +61,7 @@
55
61
  "get-random-values-esm": "^1.0.2",
56
62
  "lodash": "^4.17.21",
57
63
  "lodash.startcase": "^4.4.0",
58
- "react-compiler-runtime": "19.0.0-beta-df7b47d-20241124",
64
+ "react-compiler-runtime": "19.0.0-beta-37ed2a7-20241206",
59
65
  "slate": "0.112.0",
60
66
  "slate-dom": "^0.111.0",
61
67
  "slate-react": "0.112.0",
@@ -66,7 +72,7 @@
66
72
  "@portabletext/toolkit": "^2.0.16",
67
73
  "@sanity/block-tools": "^3.66.1",
68
74
  "@sanity/diff-match-patch": "^3.1.1",
69
- "@sanity/pkg-utils": "^6.11.14",
75
+ "@sanity/pkg-utils": "^6.11.15",
70
76
  "@sanity/schema": "^3.66.1",
71
77
  "@sanity/types": "^3.66.1",
72
78
  "@testing-library/jest-dom": "^6.6.3",
@@ -81,9 +87,9 @@
81
87
  "@vitejs/plugin-react": "^4.3.4",
82
88
  "@vitest/browser": "^2.1.8",
83
89
  "@vitest/coverage-istanbul": "^2.1.8",
84
- "babel-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
90
+ "babel-plugin-react-compiler": "19.0.0-beta-37ed2a7-20241206",
85
91
  "eslint": "8.57.1",
86
- "eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
92
+ "eslint-plugin-react-compiler": "19.0.0-beta-37ed2a7-20241206",
87
93
  "eslint-plugin-react-hooks": "^5.1.0",
88
94
  "jsdom": "^25.0.1",
89
95
  "react": "^19.0.0",
@@ -1,9 +1,7 @@
1
1
  import {Editor, Transforms, type Descendant} from 'slate'
2
- import type {
3
- PortableTextMemberSchemaTypes,
4
- PortableTextSlateEditor,
5
- } from '../../types/editor'
6
- import {isEqualToEmptyEditor} from '../../utils/values'
2
+ import type {EditorSchema} from '../editor/define-schema'
3
+ import type {PortableTextSlateEditor} from '../types/editor'
4
+ import {isEqualToEmptyEditor} from '../utils/values'
7
5
 
8
6
  export function insertBlock({
9
7
  block,
@@ -14,7 +12,7 @@ export function insertBlock({
14
12
  block: Descendant
15
13
  placement: 'auto' | 'after' | 'before'
16
14
  editor: PortableTextSlateEditor
17
- schema: PortableTextMemberSchemaTypes
15
+ schema: EditorSchema
18
16
  }) {
19
17
  if (!editor.selection) {
20
18
  const lastBlock = Array.from(
@@ -1,4 +1,4 @@
1
- import {toSlateValue} from '../../utils/values'
1
+ import {toSlateValue} from '../utils/values'
2
2
  import {insertBlock} from './behavior.action-utils.insert-block'
3
3
  import type {BehaviorActionImplementation} from './behavior.actions'
4
4
 
@@ -1,6 +1,6 @@
1
1
  import {isEqual} from 'lodash'
2
2
  import {Editor, Node, Path, Range, Transforms} from 'slate'
3
- import type {SlateTextBlock, VoidElement} from '../../types/slate'
3
+ import type {SlateTextBlock, VoidElement} from '../types/slate'
4
4
  import type {BehaviorActionImplementation} from './behavior.actions'
5
5
 
6
6
  export const insertBreakActionImplementation: BehaviorActionImplementation<
@@ -1,5 +1,5 @@
1
1
  import {Editor, Transforms, type Element} from 'slate'
2
- import {toSlateValue} from '../../utils/values'
2
+ import {toSlateValue} from '../utils/values'
3
3
  import type {BehaviorActionImplementation} from './behavior.actions'
4
4
 
5
5
  export const insertInlineObjectActionImplementation: BehaviorActionImplementation<
@@ -1,6 +1,6 @@
1
1
  import {Editor, Transforms} from 'slate'
2
- import type {BehaviorActionImplementation} from '../behavior/behavior.actions'
3
- import {createGuards} from '../behavior/behavior.guards'
2
+ import type {BehaviorActionImplementation} from './behavior.actions'
3
+ import {createGuards} from './behavior.guards'
4
4
 
5
5
  export const toggleListItemActionImplementation: BehaviorActionImplementation<
6
6
  'list item.toggle'
@@ -1,5 +1,5 @@
1
1
  import {Transforms} from 'slate'
2
- import {toSlateRange} from '../../utils/ranges'
2
+ import {toSlateRange} from '../utils/ranges'
3
3
  import type {BehaviorActionImplementation} from './behavior.actions'
4
4
 
5
5
  export const textBlockSetActionImplementation: BehaviorActionImplementation<
@@ -1,5 +1,5 @@
1
1
  import {Transforms} from 'slate'
2
- import {toSlateRange} from '../../utils/ranges'
2
+ import {toSlateRange} from '../utils/ranges'
3
3
  import type {BehaviorActionImplementation} from './behavior.actions'
4
4
 
5
5
  export const textBlockUnsetActionImplementation: BehaviorActionImplementation<
@@ -6,23 +6,28 @@ import {
6
6
  Transforms,
7
7
  } from 'slate'
8
8
  import {ReactEditor} from 'slate-react'
9
- import debug from '../../utils/debug'
10
- import {toSlatePath} from '../../utils/paths'
11
- import {toSlateRange} from '../../utils/ranges'
12
- import {fromSlateValue, toSlateValue} from '../../utils/values'
13
- import {KEY_TO_VALUE_ELEMENT} from '../../utils/weakMaps'
14
- import type {EditorContext} from '../editor-snapshot'
9
+ import type {
10
+ BehaviorAction,
11
+ SyntheticBehaviorEvent,
12
+ } from '../behaviors/behavior.types'
13
+ import type {EditorContext} from '../editor/editor-snapshot'
15
14
  import {
16
15
  addAnnotationActionImplementation,
17
16
  removeAnnotationActionImplementation,
18
17
  toggleAnnotationActionImplementation,
19
- } from '../plugins/createWithEditableAPI'
18
+ } from '../editor/plugins/createWithEditableAPI'
20
19
  import {
21
20
  addDecoratorActionImplementation,
22
21
  removeDecoratorActionImplementation,
23
22
  toggleDecoratorActionImplementation,
24
- } from '../plugins/createWithPortableTextMarkModel'
25
- import {blockOffsetToSpanSelectionPoint} from '../utils/utils.block-offset'
23
+ } from '../editor/plugins/createWithPortableTextMarkModel'
24
+ import {blockOffsetToSpanSelectionPoint} from '../editor/utils/utils.block-offset'
25
+ import type {PickFromUnion} from '../type-utils'
26
+ import debug from '../utils/debug'
27
+ import {toSlatePath} from '../utils/paths'
28
+ import {toSlateRange} from '../utils/ranges'
29
+ import {fromSlateValue, toSlateValue} from '../utils/values'
30
+ import {KEY_TO_VALUE_ELEMENT} from '../utils/weakMaps'
26
31
  import {insertBlock} from './behavior.action-utils.insert-block'
27
32
  import {insertBlockObjectActionImplementation} from './behavior.action.insert-block-object'
28
33
  import {
@@ -43,11 +48,6 @@ import {
43
48
  } from './behavior.action.style'
44
49
  import {textBlockSetActionImplementation} from './behavior.action.text-block.set'
45
50
  import {textBlockUnsetActionImplementation} from './behavior.action.text-block.unset'
46
- import type {
47
- BehaviorAction,
48
- PickFromUnion,
49
- SyntheticBehaviorEvent,
50
- } from './behavior.types'
51
51
 
52
52
  export type BehaviorActionImplementationContext = Pick<
53
53
  EditorContext,
@@ -233,7 +233,7 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
233
233
  Transforms.deselect(action.editor)
234
234
  }
235
235
  },
236
- 'select previous block': ({action}) => {
236
+ 'select.previous block': ({action}) => {
237
237
  if (!action.editor.selection) {
238
238
  console.error('Unable to select previous block without a selection')
239
239
  return
@@ -250,7 +250,7 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
250
250
 
251
251
  Transforms.select(action.editor, previousBlockPath)
252
252
  },
253
- 'select next block': ({action}) => {
253
+ 'select.next block': ({action}) => {
254
254
  if (!action.editor.selection) {
255
255
  console.error('Unable to select next block without a selection')
256
256
  return
@@ -370,15 +370,15 @@ export function performAction({
370
370
  })
371
371
  break
372
372
  }
373
- case 'select previous block': {
374
- behaviorActionImplementations['select previous block']({
373
+ case 'select.previous block': {
374
+ behaviorActionImplementations['select.previous block']({
375
375
  context,
376
376
  action,
377
377
  })
378
378
  break
379
379
  }
380
- case 'select next block': {
381
- behaviorActionImplementations['select next block']({
380
+ case 'select.next block': {
381
+ behaviorActionImplementations['select.next block']({
382
382
  context,
383
383
  action,
384
384
  })
@@ -4,18 +4,14 @@ import {
4
4
  type PortableTextListBlock,
5
5
  type PortableTextTextBlock,
6
6
  } from '@sanity/types'
7
- import type {PortableTextMemberSchemaTypes} from '../../types/editor'
7
+ import type {EditorSchema} from '../editor/define-schema'
8
8
 
9
9
  /**
10
10
  * @alpha
11
11
  */
12
12
  export type BehaviorGuards = ReturnType<typeof createGuards>
13
13
 
14
- export function createGuards({
15
- schema,
16
- }: {
17
- schema: PortableTextMemberSchemaTypes
18
- }) {
14
+ export function createGuards({schema}: {schema: EditorSchema}) {
19
15
  function isListBlock(block: unknown): block is PortableTextListBlock {
20
16
  return isPortableTextListBlock(block) && block._type === schema.block.name
21
17
  }
@@ -2,8 +2,8 @@ import {
2
2
  getFirstBlock,
3
3
  getLastBlock,
4
4
  getSelectedBlocks,
5
- } from '../../selectors/selectors'
6
- import {isHotkey} from '../../utils/is-hotkey'
5
+ } from '../selectors/selectors'
6
+ import {isHotkey} from '../utils/is-hotkey'
7
7
  import {defineBehavior} from './behavior.types'
8
8
 
9
9
  /**
@@ -38,7 +38,7 @@ export function createCodeEditorBehaviors(config: CodeEditorBehaviorsConfig) {
38
38
  return {paths: selectedBlocks.map((block) => block.path)}
39
39
  },
40
40
  actions: [
41
- ({paths}) =>
41
+ (_, {paths}) =>
42
42
  paths.map((at) => ({
43
43
  type: 'move.block up',
44
44
  at,
@@ -65,7 +65,7 @@ export function createCodeEditorBehaviors(config: CodeEditorBehaviorsConfig) {
65
65
  return {paths: selectedBlocks.map((block) => block.path).reverse()}
66
66
  },
67
67
  actions: [
68
- ({paths}) =>
68
+ (_, {paths}) =>
69
69
  paths.map((at) => ({
70
70
  type: 'move.block down',
71
71
  at,
@@ -1,13 +1,13 @@
1
1
  import {isPortableTextTextBlock} from '@sanity/types'
2
+ import {isEmptyTextBlock} from '../editor/utils/utils'
2
3
  import {
3
4
  getFocusBlockObject,
4
5
  getFocusTextBlock,
5
6
  getNextBlock,
6
7
  getPreviousBlock,
7
8
  selectionIsCollapsed,
8
- } from '../../selectors/selectors'
9
- import {isHotkey} from '../../utils/is-hotkey'
10
- import {isEmptyTextBlock} from '../utils/utils'
9
+ } from '../selectors/selectors'
10
+ import {isHotkey} from '../utils/is-hotkey'
11
11
  import {defineBehavior} from './behavior.types'
12
12
 
13
13
  const arrowDownOnLonelyBlockObject = defineBehavior({
@@ -34,7 +34,7 @@ const arrowUpOnLonelyBlockObject = defineBehavior({
34
34
  actions: [
35
35
  () => [
36
36
  {type: 'insert.text block', placement: 'before'},
37
- {type: 'select previous block'},
37
+ {type: 'select.previous block'},
38
38
  ],
39
39
  ],
40
40
  })
@@ -71,7 +71,7 @@ const deletingEmptyTextBlockAfterBlockObject = defineBehavior({
71
71
  return false
72
72
  },
73
73
  actions: [
74
- ({focusTextBlock, previousBlock}) => [
74
+ (_, {focusTextBlock, previousBlock}) => [
75
75
  {
76
76
  type: 'delete.block',
77
77
  blockPath: focusTextBlock.path,
@@ -108,7 +108,7 @@ const deletingEmptyTextBlockBeforeBlockObject = defineBehavior({
108
108
  return false
109
109
  },
110
110
  actions: [
111
- ({focusTextBlock, nextBlock}) => [
111
+ (_, {focusTextBlock, nextBlock}) => [
112
112
  {
113
113
  type: 'delete.block',
114
114
  blockPath: focusTextBlock.path,
@@ -2,13 +2,9 @@ import {defineBehavior} from './behavior.types'
2
2
 
3
3
  const decoratorAdd = defineBehavior({
4
4
  on: 'decorator.add',
5
- guard: ({event}) => ({decorator: event.decorator}),
6
5
  actions: [
7
- ({decorator}) => [
8
- {
9
- type: 'decorator.add',
10
- decorator,
11
- },
6
+ ({event}) => [
7
+ event,
12
8
  {
13
9
  type: 'reselect',
14
10
  },
@@ -20,11 +16,8 @@ const decoratorRemove = defineBehavior({
20
16
  on: 'decorator.remove',
21
17
  guard: ({event}) => ({decorator: event.decorator}),
22
18
  actions: [
23
- ({decorator}) => [
24
- {
25
- type: 'decorator.remove',
26
- decorator,
27
- },
19
+ ({event}) => [
20
+ event,
28
21
  {
29
22
  type: 'reselect',
30
23
  },
@@ -36,11 +29,8 @@ const decoratorToggle = defineBehavior({
36
29
  on: 'decorator.toggle',
37
30
  guard: ({event}) => ({decorator: event.decorator}),
38
31
  actions: [
39
- ({decorator}) => [
40
- {
41
- type: 'decorator.toggle',
42
- decorator,
43
- },
32
+ ({event}) => [
33
+ event,
44
34
  {
45
35
  type: 'reselect',
46
36
  },
@@ -1,13 +1,13 @@
1
+ import {createGuards} from '../behavior-actions/behavior.guards'
2
+ import {isEmptyTextBlock} from '../editor/utils/utils'
1
3
  import {
2
4
  getFocusListBlock,
3
5
  getFocusSpan,
4
6
  getFocusTextBlock,
5
7
  getSelectedBlocks,
6
8
  selectionIsCollapsed,
7
- } from '../../selectors/selectors'
8
- import {isHotkey} from '../../utils/is-hotkey'
9
- import {isEmptyTextBlock} from '../utils/utils'
10
- import {createGuards} from './behavior.guards'
9
+ } from '../selectors/selectors'
10
+ import {isHotkey} from '../utils/is-hotkey'
11
11
  import {defineBehavior} from './behavior.types'
12
12
 
13
13
  const MAX_LIST_LEVEL = 10
@@ -25,7 +25,7 @@ const clearListOnBackspace = defineBehavior({
25
25
 
26
26
  const atTheBeginningOfBLock =
27
27
  focusTextBlock.node.children[0]._key === focusSpan.node._key &&
28
- context.selection.focus.offset === 0
28
+ context.selection?.focus.offset === 0
29
29
 
30
30
  if (atTheBeginningOfBLock && focusTextBlock.node.level === 1) {
31
31
  return {focusTextBlock}
@@ -34,7 +34,7 @@ const clearListOnBackspace = defineBehavior({
34
34
  return false
35
35
  },
36
36
  actions: [
37
- ({focusTextBlock}) => [
37
+ (_, {focusTextBlock}) => [
38
38
  {
39
39
  type: 'text block.unset',
40
40
  props: ['listItem', 'level'],
@@ -57,7 +57,7 @@ const unindentListOnBackspace = defineBehavior({
57
57
 
58
58
  const atTheBeginningOfBLock =
59
59
  focusTextBlock.node.children[0]._key === focusSpan.node._key &&
60
- context.selection.focus.offset === 0
60
+ context.selection?.focus.offset === 0
61
61
 
62
62
  if (
63
63
  atTheBeginningOfBLock &&
@@ -70,7 +70,7 @@ const unindentListOnBackspace = defineBehavior({
70
70
  return false
71
71
  },
72
72
  actions: [
73
- ({focusTextBlock, level}) => [
73
+ (_, {focusTextBlock, level}) => [
74
74
  {
75
75
  type: 'text block.set',
76
76
  level,
@@ -83,21 +83,21 @@ const unindentListOnBackspace = defineBehavior({
83
83
  const clearListOnEnter = defineBehavior({
84
84
  on: 'insert.break',
85
85
  guard: ({context}) => {
86
- const focusListBlock = getFocusListBlock({context})
87
86
  const selectionCollapsed = selectionIsCollapsed({context})
87
+ const focusListBlock = getFocusListBlock({context})
88
88
 
89
- if (!focusListBlock || !selectionCollapsed) {
90
- return false
91
- }
92
-
93
- if (!isEmptyTextBlock(focusListBlock.node)) {
89
+ if (
90
+ !selectionCollapsed ||
91
+ !focusListBlock ||
92
+ !isEmptyTextBlock(focusListBlock.node)
93
+ ) {
94
94
  return false
95
95
  }
96
96
 
97
97
  return {focusListBlock}
98
98
  },
99
99
  actions: [
100
- ({focusListBlock}) => [
100
+ (_, {focusListBlock}) => [
101
101
  {
102
102
  type: 'text block.unset',
103
103
  props: ['listItem', 'level'],
@@ -136,7 +136,7 @@ const indentListOnTab = defineBehavior({
136
136
  return false
137
137
  },
138
138
  actions: [
139
- ({selectedListBlocks}) =>
139
+ (_, {selectedListBlocks}) =>
140
140
  selectedListBlocks.map((selectedListBlock) => ({
141
141
  type: 'text block.set',
142
142
  level: Math.min(
@@ -177,7 +177,7 @@ const unindentListOnShiftTab = defineBehavior({
177
177
  return false
178
178
  },
179
179
  actions: [
180
- ({selectedListBlocks}) =>
180
+ (_, {selectedListBlocks}) =>
181
181
  selectedListBlocks.map((selectedListBlock) => ({
182
182
  type: 'text block.set',
183
183
  level: Math.min(
@@ -1,5 +1,5 @@
1
- import {getFocusSpan, selectionIsCollapsed} from '../../selectors/selectors'
2
- import type {PortableTextMemberSchemaTypes} from '../../types/editor'
1
+ import type {EditorSchema} from '../editor/define-schema'
2
+ import {getFocusSpan, selectionIsCollapsed} from '../selectors/selectors'
3
3
  import {defineBehavior} from './behavior.types'
4
4
 
5
5
  /**
@@ -7,7 +7,7 @@ import {defineBehavior} from './behavior.types'
7
7
  */
8
8
  export type LinkBehaviorsConfig = {
9
9
  linkAnnotation?: (context: {
10
- schema: PortableTextMemberSchemaTypes
10
+ schema: EditorSchema
11
11
  url: string
12
12
  }) => {name: string; value: {[prop: string]: unknown}} | undefined
13
13
  }
@@ -34,7 +34,7 @@ export function createLinkBehaviors(config: LinkBehaviorsConfig) {
34
34
  return false
35
35
  },
36
36
  actions: [
37
- ({annotation}) => [
37
+ (_, {annotation}) => [
38
38
  {
39
39
  type: 'annotation.add',
40
40
  annotation,
@@ -66,7 +66,7 @@ export function createLinkBehaviors(config: LinkBehaviorsConfig) {
66
66
  return false
67
67
  },
68
68
  actions: [
69
- ({annotation, url}) => [
69
+ (_, {annotation, url}) => [
70
70
  {
71
71
  type: 'insert.span',
72
72
  text: url,