@portabletext/editor 1.12.3 → 1.14.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.
- package/README.md +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +320 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +321 -0
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -0
- package/lib/{index.esm.js → index.cjs} +1954 -1513
- package/lib/index.cjs.map +1 -0
- package/lib/{index.d.mts → index.d.cts} +4249 -304
- package/lib/index.d.ts +4249 -304
- package/lib/index.js +1974 -1488
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +35 -0
- package/lib/selectors/index.cjs.map +1 -0
- package/lib/selectors/index.d.cts +243 -0
- package/lib/selectors/index.d.ts +243 -0
- package/lib/selectors/index.js +36 -0
- package/lib/selectors/index.js.map +1 -0
- package/package.json +25 -17
- package/src/editor/Editable.tsx +61 -6
- package/src/editor/PortableTextEditor.tsx +19 -4
- package/src/editor/__tests__/handleClick.test.tsx +4 -4
- package/src/editor/behavior/behavior.action.insert-block-object.ts +1 -1
- package/src/editor/behavior/behavior.action.insert-break.ts +24 -27
- package/src/editor/behavior/behavior.action.insert-inline-object.ts +58 -0
- package/src/editor/behavior/behavior.action.insert-span.ts +1 -1
- package/src/editor/behavior/behavior.action.list-item.ts +100 -0
- package/src/editor/behavior/behavior.action.style.ts +108 -0
- package/src/editor/behavior/behavior.action.text-block.set.ts +25 -0
- package/src/editor/behavior/behavior.action.text-block.unset.ts +17 -0
- package/src/editor/behavior/behavior.actions.ts +266 -75
- package/src/editor/behavior/behavior.code-editor.ts +76 -0
- package/src/editor/behavior/behavior.core.block-objects.ts +52 -19
- package/src/editor/behavior/behavior.core.decorators.ts +9 -6
- package/src/editor/behavior/behavior.core.lists.ts +139 -17
- package/src/editor/behavior/behavior.core.ts +7 -2
- package/src/editor/behavior/behavior.guards.ts +28 -0
- package/src/editor/behavior/behavior.links.ts +9 -9
- package/src/editor/behavior/behavior.markdown.ts +69 -80
- package/src/editor/behavior/behavior.types.ts +121 -60
- package/src/editor/{use-editor.ts → create-editor.ts} +13 -8
- package/src/editor/editor-event-listener.tsx +2 -2
- package/src/editor/editor-machine.ts +57 -15
- package/src/editor/editor-provider.tsx +5 -5
- package/src/editor/editor-selector.ts +49 -0
- package/src/editor/editor-snapshot.ts +22 -0
- package/src/editor/get-value.ts +11 -0
- package/src/editor/plugins/create-with-event-listeners.ts +93 -5
- package/src/editor/plugins/createWithEditableAPI.ts +69 -20
- package/src/editor/plugins/createWithHotKeys.ts +0 -101
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +1 -55
- package/src/editor/plugins/with-plugins.ts +4 -8
- package/src/editor/{behavior/behavior.utils.block-offset.test.ts → utils/utils.block-offset.test.ts} +1 -1
- package/src/editor/{behavior/behavior.utils.block-offset.ts → utils/utils.block-offset.ts} +1 -8
- package/src/editor/{behavior/behavior.utils.reverse-selection.ts → utils/utils.reverse-selection.ts} +3 -5
- package/src/editor/utils/utils.ts +21 -0
- package/src/index.ts +13 -9
- package/src/selectors/index.ts +15 -0
- package/src/selectors/selector.get-active-list-item.ts +37 -0
- package/src/{editor/behavior/behavior.utils.get-selection-text.ts → selectors/selector.get-selection-text.ts} +10 -15
- package/src/selectors/selector.get-text-before.ts +41 -0
- package/src/selectors/selectors.ts +329 -0
- package/src/types/editor.ts +0 -60
- package/src/utils/is-hotkey.test.ts +99 -46
- package/src/utils/is-hotkey.ts +1 -1
- package/src/utils/operationToPatches.ts +5 -0
- package/src/utils/paths.ts +4 -11
- package/src/utils/ranges.ts +3 -3
- package/lib/index.esm.js.map +0 -1
- package/lib/index.mjs +0 -7372
- package/lib/index.mjs.map +0 -1
- package/src/editor/behavior/behavior.utils.ts +0 -218
- package/src/editor/behavior/behavior.utilts.get-text-before.ts +0 -31
- package/src/editor/plugins/createWithPortableTextLists.ts +0 -172
- /package/src/editor/{behavior/behavior.utils.get-start-point.ts → utils/utils.get-start-point.ts} +0 -0
- /package/src/editor/{behavior/behavior.utils.is-keyed-segment.ts → utils/utils.is-keyed-segment.ts} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
+
var selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
|
|
4
|
+
const getActiveListItem = ({
|
|
5
|
+
context
|
|
6
|
+
}) => {
|
|
7
|
+
if (!context.selection)
|
|
8
|
+
return;
|
|
9
|
+
const guards = selector_getTextBefore.createGuards(context), selectedTextBlocks = selector_getTextBefore.getSelectedBlocks({
|
|
10
|
+
context
|
|
11
|
+
}).map((block) => block.node).filter(guards.isTextBlock), firstTextBlock = selectedTextBlocks.at(0);
|
|
12
|
+
if (!firstTextBlock)
|
|
13
|
+
return;
|
|
14
|
+
const firstListItem = firstTextBlock.listItem;
|
|
15
|
+
if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
|
|
16
|
+
return firstListItem;
|
|
17
|
+
};
|
|
18
|
+
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
|
+
exports.getSelectionText = selector_getTextBefore.getSelectionText;
|
|
33
|
+
exports.selectionIsCollapsed = selector_getTextBefore.selectionIsCollapsed;
|
|
34
|
+
exports.getActiveListItem = getActiveListItem;
|
|
35
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ArraySchemaType,
|
|
3
|
+
BlockDecoratorDefinition,
|
|
4
|
+
BlockListDefinition,
|
|
5
|
+
BlockStyleDefinition,
|
|
6
|
+
ObjectSchemaType,
|
|
7
|
+
Path,
|
|
8
|
+
} from '@sanity/types'
|
|
9
|
+
import {
|
|
10
|
+
KeyedSegment,
|
|
11
|
+
PortableTextBlock,
|
|
12
|
+
PortableTextListBlock,
|
|
13
|
+
PortableTextObject,
|
|
14
|
+
PortableTextSpan,
|
|
15
|
+
PortableTextTextBlock,
|
|
16
|
+
} from '@sanity/types'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @alpha
|
|
20
|
+
*/
|
|
21
|
+
export declare type EditorContext = {
|
|
22
|
+
keyGenerator: () => string
|
|
23
|
+
schema: PortableTextMemberSchemaTypes
|
|
24
|
+
selection: NonNullable<EditorSelection>
|
|
25
|
+
value: Array<PortableTextBlock>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @beta */
|
|
29
|
+
export declare type EditorSelection = {
|
|
30
|
+
anchor: EditorSelectionPoint
|
|
31
|
+
focus: EditorSelectionPoint
|
|
32
|
+
backward?: boolean
|
|
33
|
+
} | null
|
|
34
|
+
|
|
35
|
+
/** @beta */
|
|
36
|
+
export declare type EditorSelectionPoint = {
|
|
37
|
+
path: Path
|
|
38
|
+
offset: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @alpha
|
|
43
|
+
*/
|
|
44
|
+
export declare type EditorSelector<TSelected> = (
|
|
45
|
+
snapshot: EditorSelectorSnapshot,
|
|
46
|
+
) => TSelected
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @alpha
|
|
50
|
+
*/
|
|
51
|
+
export declare type EditorSelectorSnapshot = {
|
|
52
|
+
context: Omit<EditorSnapshot['context'], 'selection'> & {
|
|
53
|
+
selection?: NonNullable<EditorSelection>
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @alpha
|
|
59
|
+
*/
|
|
60
|
+
export declare type EditorSnapshot = {
|
|
61
|
+
context: EditorContext
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @alpha
|
|
66
|
+
*/
|
|
67
|
+
export declare const getActiveListItem: EditorSelector<
|
|
68
|
+
PortableTextListBlock['listItem'] | undefined
|
|
69
|
+
>
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @alpha
|
|
73
|
+
*/
|
|
74
|
+
export declare const getBlockTextBefore: EditorSelector<string>
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @alpha
|
|
78
|
+
*/
|
|
79
|
+
export declare const getFirstBlock: EditorSelector<
|
|
80
|
+
| {
|
|
81
|
+
node: PortableTextBlock
|
|
82
|
+
path: [KeyedSegment]
|
|
83
|
+
}
|
|
84
|
+
| undefined
|
|
85
|
+
>
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @alpha
|
|
89
|
+
*/
|
|
90
|
+
export declare const getFocusBlock: EditorSelector<
|
|
91
|
+
| {
|
|
92
|
+
node: PortableTextBlock
|
|
93
|
+
path: [KeyedSegment]
|
|
94
|
+
}
|
|
95
|
+
| undefined
|
|
96
|
+
>
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @alpha
|
|
100
|
+
*/
|
|
101
|
+
export declare const getFocusBlockObject: EditorSelector<
|
|
102
|
+
| {
|
|
103
|
+
node: PortableTextObject
|
|
104
|
+
path: [KeyedSegment]
|
|
105
|
+
}
|
|
106
|
+
| undefined
|
|
107
|
+
>
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @alpha
|
|
111
|
+
*/
|
|
112
|
+
export declare const getFocusChild: EditorSelector<
|
|
113
|
+
| {
|
|
114
|
+
node: PortableTextObject | PortableTextSpan
|
|
115
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
116
|
+
}
|
|
117
|
+
| undefined
|
|
118
|
+
>
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @alpha
|
|
122
|
+
*/
|
|
123
|
+
export declare const getFocusListBlock: EditorSelector<
|
|
124
|
+
| {
|
|
125
|
+
node: PortableTextListBlock
|
|
126
|
+
path: [KeyedSegment]
|
|
127
|
+
}
|
|
128
|
+
| undefined
|
|
129
|
+
>
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @alpha
|
|
133
|
+
*/
|
|
134
|
+
export declare const getFocusSpan: EditorSelector<
|
|
135
|
+
| {
|
|
136
|
+
node: PortableTextSpan
|
|
137
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
138
|
+
}
|
|
139
|
+
| undefined
|
|
140
|
+
>
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @alpha
|
|
144
|
+
*/
|
|
145
|
+
export declare const getFocusTextBlock: EditorSelector<
|
|
146
|
+
| {
|
|
147
|
+
node: PortableTextTextBlock
|
|
148
|
+
path: [KeyedSegment]
|
|
149
|
+
}
|
|
150
|
+
| undefined
|
|
151
|
+
>
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @alpha
|
|
155
|
+
*/
|
|
156
|
+
export declare const getLastBlock: EditorSelector<
|
|
157
|
+
| {
|
|
158
|
+
node: PortableTextBlock
|
|
159
|
+
path: [KeyedSegment]
|
|
160
|
+
}
|
|
161
|
+
| undefined
|
|
162
|
+
>
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @alpha
|
|
166
|
+
*/
|
|
167
|
+
export declare const getNextBlock: EditorSelector<
|
|
168
|
+
| {
|
|
169
|
+
node: PortableTextBlock
|
|
170
|
+
path: [KeyedSegment]
|
|
171
|
+
}
|
|
172
|
+
| undefined
|
|
173
|
+
>
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @alpha
|
|
177
|
+
*/
|
|
178
|
+
export declare const getPreviousBlock: EditorSelector<
|
|
179
|
+
| {
|
|
180
|
+
node: PortableTextBlock
|
|
181
|
+
path: [KeyedSegment]
|
|
182
|
+
}
|
|
183
|
+
| undefined
|
|
184
|
+
>
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @alpha
|
|
188
|
+
*/
|
|
189
|
+
export declare const getSelectedBlocks: EditorSelector<
|
|
190
|
+
Array<{
|
|
191
|
+
node: PortableTextBlock
|
|
192
|
+
path: [KeyedSegment]
|
|
193
|
+
}>
|
|
194
|
+
>
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @alpha
|
|
198
|
+
*/
|
|
199
|
+
export declare const getSelectionEndBlock: EditorSelector<
|
|
200
|
+
| {
|
|
201
|
+
node: PortableTextBlock
|
|
202
|
+
path: [KeyedSegment]
|
|
203
|
+
}
|
|
204
|
+
| undefined
|
|
205
|
+
>
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @alpha
|
|
209
|
+
*/
|
|
210
|
+
export declare const getSelectionStartBlock: EditorSelector<
|
|
211
|
+
| {
|
|
212
|
+
node: PortableTextBlock
|
|
213
|
+
path: [KeyedSegment]
|
|
214
|
+
}
|
|
215
|
+
| undefined
|
|
216
|
+
>
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @alpha
|
|
220
|
+
*/
|
|
221
|
+
export declare const getSelectionText: EditorSelector<string>
|
|
222
|
+
|
|
223
|
+
/** @internal */
|
|
224
|
+
export declare type PortableTextMemberSchemaTypes = {
|
|
225
|
+
annotations: (ObjectSchemaType & {
|
|
226
|
+
i18nTitleKey?: string
|
|
227
|
+
})[]
|
|
228
|
+
block: ObjectSchemaType
|
|
229
|
+
blockObjects: ObjectSchemaType[]
|
|
230
|
+
decorators: BlockDecoratorDefinition[]
|
|
231
|
+
inlineObjects: ObjectSchemaType[]
|
|
232
|
+
portableText: ArraySchemaType<PortableTextBlock>
|
|
233
|
+
span: ObjectSchemaType
|
|
234
|
+
styles: BlockStyleDefinition[]
|
|
235
|
+
lists: BlockListDefinition[]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @alpha
|
|
240
|
+
*/
|
|
241
|
+
export declare const selectionIsCollapsed: EditorSelector<boolean>
|
|
242
|
+
|
|
243
|
+
export {}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ArraySchemaType,
|
|
3
|
+
BlockDecoratorDefinition,
|
|
4
|
+
BlockListDefinition,
|
|
5
|
+
BlockStyleDefinition,
|
|
6
|
+
ObjectSchemaType,
|
|
7
|
+
Path,
|
|
8
|
+
} from '@sanity/types'
|
|
9
|
+
import {
|
|
10
|
+
KeyedSegment,
|
|
11
|
+
PortableTextBlock,
|
|
12
|
+
PortableTextListBlock,
|
|
13
|
+
PortableTextObject,
|
|
14
|
+
PortableTextSpan,
|
|
15
|
+
PortableTextTextBlock,
|
|
16
|
+
} from '@sanity/types'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @alpha
|
|
20
|
+
*/
|
|
21
|
+
export declare type EditorContext = {
|
|
22
|
+
keyGenerator: () => string
|
|
23
|
+
schema: PortableTextMemberSchemaTypes
|
|
24
|
+
selection: NonNullable<EditorSelection>
|
|
25
|
+
value: Array<PortableTextBlock>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @beta */
|
|
29
|
+
export declare type EditorSelection = {
|
|
30
|
+
anchor: EditorSelectionPoint
|
|
31
|
+
focus: EditorSelectionPoint
|
|
32
|
+
backward?: boolean
|
|
33
|
+
} | null
|
|
34
|
+
|
|
35
|
+
/** @beta */
|
|
36
|
+
export declare type EditorSelectionPoint = {
|
|
37
|
+
path: Path
|
|
38
|
+
offset: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @alpha
|
|
43
|
+
*/
|
|
44
|
+
export declare type EditorSelector<TSelected> = (
|
|
45
|
+
snapshot: EditorSelectorSnapshot,
|
|
46
|
+
) => TSelected
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @alpha
|
|
50
|
+
*/
|
|
51
|
+
export declare type EditorSelectorSnapshot = {
|
|
52
|
+
context: Omit<EditorSnapshot['context'], 'selection'> & {
|
|
53
|
+
selection?: NonNullable<EditorSelection>
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @alpha
|
|
59
|
+
*/
|
|
60
|
+
export declare type EditorSnapshot = {
|
|
61
|
+
context: EditorContext
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @alpha
|
|
66
|
+
*/
|
|
67
|
+
export declare const getActiveListItem: EditorSelector<
|
|
68
|
+
PortableTextListBlock['listItem'] | undefined
|
|
69
|
+
>
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @alpha
|
|
73
|
+
*/
|
|
74
|
+
export declare const getBlockTextBefore: EditorSelector<string>
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @alpha
|
|
78
|
+
*/
|
|
79
|
+
export declare const getFirstBlock: EditorSelector<
|
|
80
|
+
| {
|
|
81
|
+
node: PortableTextBlock
|
|
82
|
+
path: [KeyedSegment]
|
|
83
|
+
}
|
|
84
|
+
| undefined
|
|
85
|
+
>
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @alpha
|
|
89
|
+
*/
|
|
90
|
+
export declare const getFocusBlock: EditorSelector<
|
|
91
|
+
| {
|
|
92
|
+
node: PortableTextBlock
|
|
93
|
+
path: [KeyedSegment]
|
|
94
|
+
}
|
|
95
|
+
| undefined
|
|
96
|
+
>
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @alpha
|
|
100
|
+
*/
|
|
101
|
+
export declare const getFocusBlockObject: EditorSelector<
|
|
102
|
+
| {
|
|
103
|
+
node: PortableTextObject
|
|
104
|
+
path: [KeyedSegment]
|
|
105
|
+
}
|
|
106
|
+
| undefined
|
|
107
|
+
>
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @alpha
|
|
111
|
+
*/
|
|
112
|
+
export declare const getFocusChild: EditorSelector<
|
|
113
|
+
| {
|
|
114
|
+
node: PortableTextObject | PortableTextSpan
|
|
115
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
116
|
+
}
|
|
117
|
+
| undefined
|
|
118
|
+
>
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @alpha
|
|
122
|
+
*/
|
|
123
|
+
export declare const getFocusListBlock: EditorSelector<
|
|
124
|
+
| {
|
|
125
|
+
node: PortableTextListBlock
|
|
126
|
+
path: [KeyedSegment]
|
|
127
|
+
}
|
|
128
|
+
| undefined
|
|
129
|
+
>
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @alpha
|
|
133
|
+
*/
|
|
134
|
+
export declare const getFocusSpan: EditorSelector<
|
|
135
|
+
| {
|
|
136
|
+
node: PortableTextSpan
|
|
137
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
138
|
+
}
|
|
139
|
+
| undefined
|
|
140
|
+
>
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @alpha
|
|
144
|
+
*/
|
|
145
|
+
export declare const getFocusTextBlock: EditorSelector<
|
|
146
|
+
| {
|
|
147
|
+
node: PortableTextTextBlock
|
|
148
|
+
path: [KeyedSegment]
|
|
149
|
+
}
|
|
150
|
+
| undefined
|
|
151
|
+
>
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @alpha
|
|
155
|
+
*/
|
|
156
|
+
export declare const getLastBlock: EditorSelector<
|
|
157
|
+
| {
|
|
158
|
+
node: PortableTextBlock
|
|
159
|
+
path: [KeyedSegment]
|
|
160
|
+
}
|
|
161
|
+
| undefined
|
|
162
|
+
>
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @alpha
|
|
166
|
+
*/
|
|
167
|
+
export declare const getNextBlock: EditorSelector<
|
|
168
|
+
| {
|
|
169
|
+
node: PortableTextBlock
|
|
170
|
+
path: [KeyedSegment]
|
|
171
|
+
}
|
|
172
|
+
| undefined
|
|
173
|
+
>
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @alpha
|
|
177
|
+
*/
|
|
178
|
+
export declare const getPreviousBlock: EditorSelector<
|
|
179
|
+
| {
|
|
180
|
+
node: PortableTextBlock
|
|
181
|
+
path: [KeyedSegment]
|
|
182
|
+
}
|
|
183
|
+
| undefined
|
|
184
|
+
>
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @alpha
|
|
188
|
+
*/
|
|
189
|
+
export declare const getSelectedBlocks: EditorSelector<
|
|
190
|
+
Array<{
|
|
191
|
+
node: PortableTextBlock
|
|
192
|
+
path: [KeyedSegment]
|
|
193
|
+
}>
|
|
194
|
+
>
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @alpha
|
|
198
|
+
*/
|
|
199
|
+
export declare const getSelectionEndBlock: EditorSelector<
|
|
200
|
+
| {
|
|
201
|
+
node: PortableTextBlock
|
|
202
|
+
path: [KeyedSegment]
|
|
203
|
+
}
|
|
204
|
+
| undefined
|
|
205
|
+
>
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @alpha
|
|
209
|
+
*/
|
|
210
|
+
export declare const getSelectionStartBlock: EditorSelector<
|
|
211
|
+
| {
|
|
212
|
+
node: PortableTextBlock
|
|
213
|
+
path: [KeyedSegment]
|
|
214
|
+
}
|
|
215
|
+
| undefined
|
|
216
|
+
>
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @alpha
|
|
220
|
+
*/
|
|
221
|
+
export declare const getSelectionText: EditorSelector<string>
|
|
222
|
+
|
|
223
|
+
/** @internal */
|
|
224
|
+
export declare type PortableTextMemberSchemaTypes = {
|
|
225
|
+
annotations: (ObjectSchemaType & {
|
|
226
|
+
i18nTitleKey?: string
|
|
227
|
+
})[]
|
|
228
|
+
block: ObjectSchemaType
|
|
229
|
+
blockObjects: ObjectSchemaType[]
|
|
230
|
+
decorators: BlockDecoratorDefinition[]
|
|
231
|
+
inlineObjects: ObjectSchemaType[]
|
|
232
|
+
portableText: ArraySchemaType<PortableTextBlock>
|
|
233
|
+
span: ObjectSchemaType
|
|
234
|
+
styles: BlockStyleDefinition[]
|
|
235
|
+
lists: BlockListDefinition[]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @alpha
|
|
240
|
+
*/
|
|
241
|
+
export declare const selectionIsCollapsed: EditorSelector<boolean>
|
|
242
|
+
|
|
243
|
+
export {}
|
|
@@ -0,0 +1,36 @@
|
|
|
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";
|
|
3
|
+
const getActiveListItem = ({
|
|
4
|
+
context
|
|
5
|
+
}) => {
|
|
6
|
+
if (!context.selection)
|
|
7
|
+
return;
|
|
8
|
+
const guards = createGuards(context), selectedTextBlocks = getSelectedBlocks({
|
|
9
|
+
context
|
|
10
|
+
}).map((block) => block.node).filter(guards.isTextBlock), firstTextBlock = selectedTextBlocks.at(0);
|
|
11
|
+
if (!firstTextBlock)
|
|
12
|
+
return;
|
|
13
|
+
const firstListItem = firstTextBlock.listItem;
|
|
14
|
+
if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
|
|
15
|
+
return firstListItem;
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
getActiveListItem,
|
|
19
|
+
getBlockTextBefore,
|
|
20
|
+
getFirstBlock,
|
|
21
|
+
getFocusBlock,
|
|
22
|
+
getFocusBlockObject,
|
|
23
|
+
getFocusChild,
|
|
24
|
+
getFocusListBlock,
|
|
25
|
+
getFocusSpan,
|
|
26
|
+
getFocusTextBlock,
|
|
27
|
+
getLastBlock,
|
|
28
|
+
getNextBlock,
|
|
29
|
+
getPreviousBlock,
|
|
30
|
+
getSelectedBlocks,
|
|
31
|
+
getSelectionEndBlock,
|
|
32
|
+
getSelectionStartBlock,
|
|
33
|
+
getSelectionText,
|
|
34
|
+
selectionIsCollapsed
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -25,17 +25,24 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"author": "Sanity.io <hello@sanity.io>",
|
|
27
27
|
"sideEffects": false,
|
|
28
|
+
"type": "module",
|
|
28
29
|
"exports": {
|
|
29
30
|
".": {
|
|
30
31
|
"source": "./src/index.ts",
|
|
31
|
-
"import": "./lib/index.
|
|
32
|
-
"require": "./lib/index.
|
|
32
|
+
"import": "./lib/index.js",
|
|
33
|
+
"require": "./lib/index.cjs",
|
|
33
34
|
"default": "./lib/index.js"
|
|
34
35
|
},
|
|
36
|
+
"./selectors": {
|
|
37
|
+
"source": "./src/selectors/index.ts",
|
|
38
|
+
"import": "./lib/selectors/index.js",
|
|
39
|
+
"require": "./lib/selectors/index.cjs",
|
|
40
|
+
"default": "./lib/selectors/index.js"
|
|
41
|
+
},
|
|
35
42
|
"./package.json": "./package.json"
|
|
36
43
|
},
|
|
37
|
-
"main": "./lib/index.
|
|
38
|
-
"module": "./lib/index.
|
|
44
|
+
"main": "./lib/index.cjs",
|
|
45
|
+
"module": "./lib/index.js",
|
|
39
46
|
"types": "./lib/index.d.ts",
|
|
40
47
|
"files": [
|
|
41
48
|
"lib",
|
|
@@ -57,22 +64,23 @@
|
|
|
57
64
|
},
|
|
58
65
|
"devDependencies": {
|
|
59
66
|
"@portabletext/toolkit": "^2.0.16",
|
|
60
|
-
"@sanity/block-tools": "^3.
|
|
67
|
+
"@sanity/block-tools": "^3.66.0",
|
|
61
68
|
"@sanity/diff-match-patch": "^3.1.1",
|
|
62
|
-
"@sanity/pkg-utils": "^6.11.
|
|
63
|
-
"@sanity/schema": "^3.
|
|
64
|
-
"@sanity/types": "^3.
|
|
69
|
+
"@sanity/pkg-utils": "^6.11.14",
|
|
70
|
+
"@sanity/schema": "^3.66.0",
|
|
71
|
+
"@sanity/types": "^3.66.0",
|
|
65
72
|
"@testing-library/jest-dom": "^6.6.3",
|
|
66
73
|
"@testing-library/react": "^16.0.1",
|
|
67
74
|
"@types/debug": "^4.1.5",
|
|
68
75
|
"@types/lodash": "^4.17.13",
|
|
69
76
|
"@types/lodash.startcase": "^4.4.9",
|
|
70
|
-
"@types/react": "^18.3.
|
|
71
|
-
"@types/react-dom": "^18.3.
|
|
72
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
73
|
-
"@typescript-eslint/parser": "^8.
|
|
77
|
+
"@types/react": "^18.3.14",
|
|
78
|
+
"@types/react-dom": "^18.3.2",
|
|
79
|
+
"@typescript-eslint/eslint-plugin": "^8.16.0",
|
|
80
|
+
"@typescript-eslint/parser": "^8.16.0",
|
|
74
81
|
"@vitejs/plugin-react": "^4.3.4",
|
|
75
82
|
"@vitest/browser": "^2.1.5",
|
|
83
|
+
"@vitest/coverage-istanbul": "^2.1.8",
|
|
76
84
|
"babel-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
|
|
77
85
|
"eslint": "8.57.1",
|
|
78
86
|
"eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
|
|
@@ -86,12 +94,12 @@
|
|
|
86
94
|
"vite": "^5.4.11",
|
|
87
95
|
"vitest": "^2.1.5",
|
|
88
96
|
"vitest-browser-react": "^0.0.4",
|
|
89
|
-
"racejar": "1.0
|
|
97
|
+
"racejar": "1.1.0"
|
|
90
98
|
},
|
|
91
99
|
"peerDependencies": {
|
|
92
|
-
"@sanity/block-tools": "^3.
|
|
93
|
-
"@sanity/schema": "^3.
|
|
94
|
-
"@sanity/types": "^3.
|
|
100
|
+
"@sanity/block-tools": "^3.66.0",
|
|
101
|
+
"@sanity/schema": "^3.66.0",
|
|
102
|
+
"@sanity/types": "^3.66.0",
|
|
95
103
|
"react": "^16.9 || ^17 || ^18",
|
|
96
104
|
"rxjs": "^7.8.1",
|
|
97
105
|
"styled-components": "^6.1.13"
|