@portabletext/editor 1.15.0 → 1.15.2
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.
- package/lib/_chunks-cjs/behavior.core.cjs +494 -0
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +12 -232
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selectors.cjs +234 -0
- package/lib/_chunks-cjs/selectors.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js +496 -0
- package/lib/_chunks-es/behavior.core.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +14 -234
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selectors.js +235 -0
- package/lib/_chunks-es/selectors.js.map +1 -0
- package/lib/behaviors/index.cjs +460 -0
- package/lib/behaviors/index.cjs.map +1 -0
- package/lib/behaviors/index.d.cts +875 -0
- package/lib/behaviors/index.d.ts +875 -0
- package/lib/behaviors/index.js +464 -0
- package/lib/behaviors/index.js.map +1 -0
- package/lib/index.cjs +843 -1489
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +17 -536
- package/lib/index.d.ts +17 -536
- package/lib/index.js +837 -1482
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +16 -16
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +3 -2
- package/lib/selectors/index.js.map +1 -1
- package/package.json +13 -7
- package/src/{editor/behavior → behavior-actions}/behavior.action-utils.insert-block.ts +2 -2
- package/src/{editor/behavior → behavior-actions}/behavior.action.insert-block-object.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.action.insert-break.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.action.insert-inline-object.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.action.list-item.ts +2 -2
- package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.set.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.unset.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.actions.ts +14 -14
- package/src/{editor/behavior → behavior-actions}/behavior.guards.ts +1 -1
- package/src/{editor/behavior → behaviors}/behavior.code-editor.ts +4 -4
- package/src/{editor/behavior → behaviors}/behavior.core.block-objects.ts +5 -5
- package/src/{editor/behavior → behaviors}/behavior.core.decorators.ts +6 -16
- package/src/{editor/behavior → behaviors}/behavior.core.lists.ts +15 -15
- package/src/{editor/behavior → behaviors}/behavior.links.ts +4 -4
- package/src/{editor/behavior → behaviors}/behavior.markdown.ts +15 -25
- package/src/{editor/behavior → behaviors}/behavior.types.ts +32 -39
- package/src/behaviors/index.ts +28 -0
- package/src/editor/create-editor.ts +26 -46
- package/src/editor/editor-machine.ts +14 -12
- package/src/editor/plugins/createWithEditableAPI.ts +3 -3
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -1
- package/src/editor/utils/utils.block-offset.ts +1 -1
- package/src/index.ts +11 -26
- package/src/selectors/selector.get-active-list-item.ts +1 -1
- package/src/selectors/selectors.ts +1 -1
- package/src/type-utils.ts +17 -0
- package/src/utils/__tests__/operationToPatches.test.ts +1 -1
- package/src/utils/__tests__/patchToOperations.test.ts +1 -1
- /package/src/{editor/behavior → behavior-actions}/behavior.action.insert-span.ts +0 -0
- /package/src/{editor/behavior → behavior-actions}/behavior.action.style.ts +0 -0
- /package/src/{editor/behavior → behaviors}/behavior.core.ts +0 -0
package/lib/selectors/index.cjs
CHANGED
|
@@ -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 =
|
|
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 '../
|
|
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;;;;;;;;;;;;;;;;;;"}
|
package/lib/selectors/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { getSelectedBlocks, createGuards } from "../_chunks-es/
|
|
2
|
-
import {
|
|
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 '../
|
|
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.
|
|
3
|
+
"version": "1.15.2",
|
|
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,10 +61,10 @@
|
|
|
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-
|
|
59
|
-
"slate": "0.
|
|
64
|
+
"react-compiler-runtime": "19.0.0-beta-37ed2a7-20241206",
|
|
65
|
+
"slate": "0.112.0",
|
|
60
66
|
"slate-dom": "^0.111.0",
|
|
61
|
-
"slate-react": "0.
|
|
67
|
+
"slate-react": "0.112.0",
|
|
62
68
|
"use-effect-event": "^1.0.2",
|
|
63
69
|
"xstate": "^5.19.0"
|
|
64
70
|
},
|
|
@@ -74,16 +80,16 @@
|
|
|
74
80
|
"@types/debug": "^4.1.5",
|
|
75
81
|
"@types/lodash": "^4.17.13",
|
|
76
82
|
"@types/lodash.startcase": "^4.4.9",
|
|
77
|
-
"@types/react": "^19.0.
|
|
83
|
+
"@types/react": "^19.0.1",
|
|
78
84
|
"@types/react-dom": "^19.0.1",
|
|
79
85
|
"@typescript-eslint/eslint-plugin": "^8.17.0",
|
|
80
86
|
"@typescript-eslint/parser": "^8.17.0",
|
|
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-
|
|
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-
|
|
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",
|
|
@@ -2,8 +2,8 @@ import {Editor, Transforms, type Descendant} from 'slate'
|
|
|
2
2
|
import type {
|
|
3
3
|
PortableTextMemberSchemaTypes,
|
|
4
4
|
PortableTextSlateEditor,
|
|
5
|
-
} from '
|
|
6
|
-
import {isEqualToEmptyEditor} from '
|
|
5
|
+
} from '../types/editor'
|
|
6
|
+
import {isEqualToEmptyEditor} from '../utils/values'
|
|
7
7
|
|
|
8
8
|
export function insertBlock({
|
|
9
9
|
block,
|
|
@@ -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 '
|
|
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 '
|
|
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 '
|
|
3
|
-
import {createGuards} from '
|
|
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 '
|
|
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 '
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
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,
|
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
getFirstBlock,
|
|
3
3
|
getLastBlock,
|
|
4
4
|
getSelectedBlocks,
|
|
5
|
-
} from '
|
|
6
|
-
import {isHotkey} from '
|
|
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 '
|
|
9
|
-
import {isHotkey} from '
|
|
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({
|
|
@@ -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
|
-
({
|
|
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
|
-
({
|
|
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
|
-
({
|
|
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 '
|
|
8
|
-
import {isHotkey} from '
|
|
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
|
|
@@ -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'],
|
|
@@ -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 (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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 '
|
|
2
|
-
import type {PortableTextMemberSchemaTypes} from '
|
|
1
|
+
import {getFocusSpan, selectionIsCollapsed} from '../selectors/selectors'
|
|
2
|
+
import type {PortableTextMemberSchemaTypes} from '../types/editor'
|
|
3
3
|
import {defineBehavior} from './behavior.types'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -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,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {isPortableTextTextBlock} from '@sanity/types'
|
|
2
|
-
import {
|
|
2
|
+
import {getTextBlockText} from '../editor/utils/utils'
|
|
3
|
+
import {spanSelectionPointToBlockOffset} from '../editor/utils/utils.block-offset'
|
|
4
|
+
import {getBlockTextBefore} from '../selectors/selector.get-text-before'
|
|
3
5
|
import {
|
|
4
6
|
getFocusBlock,
|
|
5
7
|
getFocusSpan,
|
|
6
8
|
getFocusTextBlock,
|
|
7
9
|
selectionIsCollapsed,
|
|
8
|
-
} from '
|
|
9
|
-
import type {PortableTextMemberSchemaTypes} from '
|
|
10
|
-
import {getTextBlockText} from '../utils/utils'
|
|
11
|
-
import {spanSelectionPointToBlockOffset} from '../utils/utils.block-offset'
|
|
10
|
+
} from '../selectors/selectors'
|
|
11
|
+
import type {PortableTextMemberSchemaTypes} from '../types/editor'
|
|
12
12
|
import {defineBehavior} from './behavior.types'
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -95,7 +95,7 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
95
95
|
text: ' ',
|
|
96
96
|
},
|
|
97
97
|
],
|
|
98
|
-
({focusTextBlock, style}) => [
|
|
98
|
+
(_, {focusTextBlock, style}) => [
|
|
99
99
|
{
|
|
100
100
|
type: 'text block.unset',
|
|
101
101
|
props: ['listItem', 'level'],
|
|
@@ -163,13 +163,13 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
163
163
|
return false
|
|
164
164
|
},
|
|
165
165
|
actions: [
|
|
166
|
-
({hrCharacter}) => [
|
|
166
|
+
(_, {hrCharacter}) => [
|
|
167
167
|
{
|
|
168
168
|
type: 'insert.text',
|
|
169
169
|
text: hrCharacter,
|
|
170
170
|
},
|
|
171
171
|
],
|
|
172
|
-
({hrObject, hrBlockOffsets}) => [
|
|
172
|
+
(_, {hrObject, hrBlockOffsets}) => [
|
|
173
173
|
{
|
|
174
174
|
type: 'insert.block object',
|
|
175
175
|
placement: 'before',
|
|
@@ -198,13 +198,13 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
198
198
|
return {hrCharacters, hrObject, focusBlock}
|
|
199
199
|
},
|
|
200
200
|
actions: [
|
|
201
|
-
({hrCharacters}) => [
|
|
201
|
+
(_, {hrCharacters}) => [
|
|
202
202
|
{
|
|
203
203
|
type: 'insert.text',
|
|
204
204
|
text: hrCharacters,
|
|
205
205
|
},
|
|
206
206
|
],
|
|
207
|
-
({hrObject, focusBlock}) =>
|
|
207
|
+
(_, {hrObject, focusBlock}) =>
|
|
208
208
|
isPortableTextTextBlock(focusBlock.node)
|
|
209
209
|
? [
|
|
210
210
|
{
|
|
@@ -288,13 +288,8 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
288
288
|
return false
|
|
289
289
|
},
|
|
290
290
|
actions: [
|
|
291
|
-
() => [
|
|
292
|
-
|
|
293
|
-
type: 'insert.text',
|
|
294
|
-
text: ' ',
|
|
295
|
-
},
|
|
296
|
-
],
|
|
297
|
-
({focusTextBlock, style, level}) => [
|
|
291
|
+
({event}) => [event],
|
|
292
|
+
(_, {focusTextBlock, style, level}) => [
|
|
298
293
|
{
|
|
299
294
|
type: 'text block.unset',
|
|
300
295
|
props: ['listItem', 'level'],
|
|
@@ -347,7 +342,7 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
347
342
|
return false
|
|
348
343
|
},
|
|
349
344
|
actions: [
|
|
350
|
-
({defaultStyle, focusTextBlock}) => [
|
|
345
|
+
(_, {defaultStyle, focusTextBlock}) => [
|
|
351
346
|
{
|
|
352
347
|
type: 'text block.set',
|
|
353
348
|
style: defaultStyle,
|
|
@@ -430,13 +425,8 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
430
425
|
return false
|
|
431
426
|
},
|
|
432
427
|
actions: [
|
|
433
|
-
() => [
|
|
434
|
-
|
|
435
|
-
type: 'insert.text',
|
|
436
|
-
text: ' ',
|
|
437
|
-
},
|
|
438
|
-
],
|
|
439
|
-
({focusTextBlock, style, listItem, listItemLength}) => [
|
|
428
|
+
({event}) => [event],
|
|
429
|
+
(_, {focusTextBlock, style, listItem, listItemLength}) => [
|
|
440
430
|
{
|
|
441
431
|
type: 'text block.set',
|
|
442
432
|
listItem,
|