@portabletext/editor 1.53.1 → 1.54.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/lib/_chunks-cjs/selection-point.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
- package/lib/_chunks-es/selection-point.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +68 -9
- package/lib/behaviors/index.d.ts +68 -9
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +529 -289
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +69 -13
- package/lib/index.d.ts +69 -13
- package/lib/index.js +533 -293
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +69 -9
- package/lib/plugins/index.d.ts +69 -9
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +31 -16
- package/lib/selectors/index.d.ts +31 -16
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +27 -5
- package/lib/utils/index.d.ts +27 -5
- package/package.json +3 -3
- package/src/behaviors/behavior.abstract.annotation.ts +51 -0
- package/src/behaviors/behavior.abstract.delete.ts +55 -0
- package/src/behaviors/behavior.perform-event.ts +6 -15
- package/src/behaviors/behavior.types.action.ts +1 -1
- package/src/behaviors/behavior.types.event.ts +32 -8
- package/src/behaviors/behavior.types.guard.ts +1 -1
- package/src/editor/Editable.tsx +3 -0
- package/src/editor/PortableTextEditor.tsx +1 -6
- package/src/editor/create-editor.ts +5 -0
- package/src/{internal-utils/selection-elements.ts → editor/editor-dom.ts} +29 -21
- package/src/editor/editor-provider.tsx +1 -6
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +6 -46
- package/src/editor/plugins/createWithPatches.ts +1 -5
- package/src/editor.ts +2 -0
- package/src/index.ts +2 -0
- package/src/operations/behavior.operation.child.set.ts +103 -0
- package/src/operations/behavior.operation.child.unset.ts +89 -0
- package/src/operations/behavior.operations.ts +18 -0
- package/src/selectors/selector.get-anchor-block.ts +3 -2
- package/src/selectors/selector.get-anchor-child.ts +2 -2
- package/src/selectors/selector.get-anchor-span.ts +2 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -2
- package/src/selectors/selector.get-focus-child.ts +3 -6
- package/src/selectors/selector.get-focus-inline-object.ts +3 -7
- package/src/selectors/selector.get-focus-span.ts +3 -3
- package/src/selectors/selector.get-next-inline-object.ts +4 -7
- package/src/selectors/selector.get-previous-block.ts +2 -2
- package/src/selectors/selector.get-previous-inline-object.ts +4 -7
- package/src/selectors/selector.get-selected-blocks.ts +2 -3
- package/src/selectors/selector.get-selected-spans.test.ts +96 -0
- package/src/selectors/selector.get-selected-spans.ts +4 -3
- package/src/selectors/selector.get-selected-text-blocks.ts +4 -3
- package/src/selectors/selector.is-at-the-end-of-block.ts +3 -2
- package/src/selectors/selector.is-at-the-start-of-block.ts +3 -2
- package/src/types/block-offset.ts +2 -2
- package/src/types/paths.ts +13 -0
- package/src/utils/util.block-offset.ts +2 -4
- package/src/utils/util.get-block-end-point.ts +3 -2
- package/src/utils/util.get-block-start-point.ts +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/behaviors/behavior.types.action.ts","../../src/behaviors/behavior.types.behavior.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/behaviors/behavior.types.action.ts","../../src/behaviors/behavior.types.behavior.ts"],"sourcesContent":["import type {EditorDom} from '../editor/editor-dom'\nimport type {EditorSnapshot} from '../editor/editor-snapshot'\nimport type {PickFromUnion} from '../type-utils'\nimport type {\n CustomBehaviorEvent,\n NativeBehaviorEvent,\n SyntheticBehaviorEvent,\n} from './behavior.types.event'\n\n/**\n * @beta\n */\nexport type BehaviorAction =\n | {\n type: 'execute'\n event: SyntheticBehaviorEvent\n }\n | {\n type: 'forward'\n event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent\n }\n | {\n type: 'raise'\n event: SyntheticBehaviorEvent | CustomBehaviorEvent\n }\n | {\n type: 'effect'\n effect: () => void\n }\n\n/**\n * @beta\n */\nexport function execute(\n event: SyntheticBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'execute'> {\n return {type: 'execute', event}\n}\n\n/**\n * @beta\n */\nexport function forward(\n event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'forward'> {\n return {type: 'forward', event}\n}\n\n/**\n * @beta\n */\nexport function raise(\n event: SyntheticBehaviorEvent | CustomBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'raise'> {\n return {type: 'raise', event}\n}\n\n/**\n * @beta\n */\nexport function effect(\n effect: () => void,\n): PickFromUnion<BehaviorAction, 'type', 'effect'> {\n return {type: 'effect', effect}\n}\n\n/**\n * @beta\n */\nexport type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (\n payload: {\n snapshot: EditorSnapshot\n event: TBehaviorEvent\n dom: EditorDom\n },\n guardResponse: TGuardResponse,\n) => Array<BehaviorAction>\n","import type {BehaviorActionSet} from './behavior.types.action'\nimport type {\n BehaviorEvent,\n BehaviorEventTypeNamespace,\n CustomBehaviorEvent,\n ResolveBehaviorEvent,\n} from './behavior.types.event'\nimport type {BehaviorGuard} from './behavior.types.guard'\n\n/**\n * @beta\n */\nexport type Behavior<\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] =\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'],\n TGuardResponse = true,\n TBehaviorEvent extends\n ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>,\n> = {\n /**\n * Editor Event that triggers this Behavior.\n */\n on: TBehaviorEventType\n /**\n * Predicate function that determines if the Behavior should be executed.\n * Returning a non-nullable value from the guard will pass the value to the\n * actions and execute them.\n */\n guard?: BehaviorGuard<TBehaviorEvent, TGuardResponse>\n /**\n * Array of Behavior Action sets.\n * Each set represents a step in the history stack.\n */\n actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>\n}\n\n/**\n * @beta\n *\n * @example\n *\n * ```tsx\n * const noLowerCaseA = defineBehavior({\n * on: 'insert.text',\n * guard: ({event, snapshot}) => event.text === 'a',\n * actions: [({event, snapshot}) => [{type: 'insert.text', text: 'A'}]],\n * })\n * ```\n *\n */\nexport function defineBehavior<\n TPayload extends Record<string, unknown>,\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] = CustomBehaviorEvent['type'],\n TGuardResponse = true,\n>(\n behavior: Behavior<\n TBehaviorEventType,\n TGuardResponse,\n ResolveBehaviorEvent<TBehaviorEventType, TPayload>\n >,\n): Behavior\nexport function defineBehavior<\n TPayload extends never = never,\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] = BehaviorEvent['type'],\n TGuardResponse = true,\n TBehaviorEvent extends ResolveBehaviorEvent<\n TBehaviorEventType,\n TPayload\n > = ResolveBehaviorEvent<TBehaviorEventType, TPayload>,\n>(\n behavior: Behavior<TBehaviorEventType, TGuardResponse, TBehaviorEvent>,\n): Behavior {\n return behavior as unknown as Behavior\n}\n"],"names":["execute","event","type","forward","raise","effect","defineBehavior","behavior"],"mappings":";;AAiCO,SAASA,QACdC,OACkD;AAC3C,SAAA;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAK;AAChC;AAKO,SAASE,QACdF,OACkD;AAC3C,SAAA;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAK;AAChC;AAKO,SAASG,MACdH,OACgD;AACzC,SAAA;AAAA,IAACC,MAAM;AAAA,IAASD;AAAAA,EAAK;AAC9B;AAKO,SAASI,OACdA,SACiD;AAC1C,SAAA;AAAA,IAACH,MAAM;AAAA,IAAUG,QAAAA;AAAAA,EAAM;AAChC;ACKO,SAASC,eAYdC,UACU;AACHA,SAAAA;AACT;;;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
KeyedSegment,
|
|
3
2
|
Path,
|
|
4
3
|
PortableTextBlock,
|
|
5
4
|
PortableTextObject,
|
|
@@ -7,6 +6,11 @@ import type {
|
|
|
7
6
|
} from '@sanity/types'
|
|
8
7
|
|
|
9
8
|
declare type AbstractBehaviorEvent =
|
|
9
|
+
| {
|
|
10
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
|
|
11
|
+
at: AnnotationPath
|
|
12
|
+
props: Record<string, unknown>
|
|
13
|
+
}
|
|
10
14
|
| {
|
|
11
15
|
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
|
|
12
16
|
annotation: {
|
|
@@ -30,7 +34,11 @@ declare type AbstractBehaviorEvent =
|
|
|
30
34
|
}
|
|
31
35
|
| {
|
|
32
36
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
|
|
33
|
-
at:
|
|
37
|
+
at: BlockPath
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
|
|
41
|
+
at: ChildPath
|
|
34
42
|
}
|
|
35
43
|
| {
|
|
36
44
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
@@ -131,11 +139,11 @@ declare type AbstractBehaviorEvent =
|
|
|
131
139
|
}
|
|
132
140
|
| {
|
|
133
141
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
|
|
134
|
-
at:
|
|
142
|
+
at: BlockPath
|
|
135
143
|
}
|
|
136
144
|
| {
|
|
137
145
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
|
|
138
|
-
at:
|
|
146
|
+
at: BlockPath
|
|
139
147
|
}
|
|
140
148
|
| {
|
|
141
149
|
type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
|
|
@@ -165,10 +173,12 @@ declare type AbstractBehaviorEvent =
|
|
|
165
173
|
* Abstract events
|
|
166
174
|
**************************************/
|
|
167
175
|
declare const abstractBehaviorEventTypes: readonly [
|
|
176
|
+
'annotation.set',
|
|
168
177
|
'annotation.toggle',
|
|
169
178
|
'decorator.toggle',
|
|
170
179
|
'delete.backward',
|
|
171
180
|
'delete.block',
|
|
181
|
+
'delete.child',
|
|
172
182
|
'delete.forward',
|
|
173
183
|
'delete.text',
|
|
174
184
|
'deserialize',
|
|
@@ -193,6 +203,19 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
193
203
|
'style.toggle',
|
|
194
204
|
]
|
|
195
205
|
|
|
206
|
+
/**
|
|
207
|
+
* @public
|
|
208
|
+
*/
|
|
209
|
+
declare type AnnotationPath = [
|
|
210
|
+
{
|
|
211
|
+
_key: string
|
|
212
|
+
},
|
|
213
|
+
'markDefs',
|
|
214
|
+
{
|
|
215
|
+
_key: string
|
|
216
|
+
},
|
|
217
|
+
]
|
|
218
|
+
|
|
196
219
|
/**
|
|
197
220
|
* @public
|
|
198
221
|
*/
|
|
@@ -292,14 +315,36 @@ export declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
|
|
|
292
315
|
* @beta
|
|
293
316
|
*/
|
|
294
317
|
declare type BlockOffset = {
|
|
295
|
-
path:
|
|
318
|
+
path: BlockPath
|
|
296
319
|
offset: number
|
|
297
320
|
}
|
|
298
321
|
|
|
322
|
+
/**
|
|
323
|
+
* @public
|
|
324
|
+
*/
|
|
325
|
+
declare type BlockPath = [
|
|
326
|
+
{
|
|
327
|
+
_key: string
|
|
328
|
+
},
|
|
329
|
+
]
|
|
330
|
+
|
|
299
331
|
declare type BlockWithOptionalKey =
|
|
300
332
|
| TextBlockWithOptionalKey
|
|
301
333
|
| ObjectBlockWithOptionalKey
|
|
302
334
|
|
|
335
|
+
/**
|
|
336
|
+
* @public
|
|
337
|
+
*/
|
|
338
|
+
declare type ChildPath = [
|
|
339
|
+
{
|
|
340
|
+
_key: string
|
|
341
|
+
},
|
|
342
|
+
'children',
|
|
343
|
+
{
|
|
344
|
+
_key: string
|
|
345
|
+
},
|
|
346
|
+
]
|
|
347
|
+
|
|
303
348
|
declare type ClipboardBehaviorEvent =
|
|
304
349
|
| {
|
|
305
350
|
type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
|
|
@@ -798,12 +843,24 @@ export declare type SyntheticBehaviorEvent =
|
|
|
798
843
|
}
|
|
799
844
|
| {
|
|
800
845
|
type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
|
|
801
|
-
at:
|
|
846
|
+
at: BlockPath
|
|
802
847
|
props: Record<string, unknown>
|
|
803
848
|
}
|
|
804
849
|
| {
|
|
805
850
|
type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
|
|
806
|
-
at:
|
|
851
|
+
at: BlockPath
|
|
852
|
+
props: Array<string>
|
|
853
|
+
}
|
|
854
|
+
| {
|
|
855
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'child.set'>
|
|
856
|
+
at: ChildPath
|
|
857
|
+
props: {
|
|
858
|
+
[prop: string]: unknown
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
| {
|
|
862
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'child.unset'>
|
|
863
|
+
at: ChildPath
|
|
807
864
|
props: Array<string>
|
|
808
865
|
}
|
|
809
866
|
| {
|
|
@@ -872,8 +929,8 @@ export declare type SyntheticBehaviorEvent =
|
|
|
872
929
|
}
|
|
873
930
|
| {
|
|
874
931
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
875
|
-
at:
|
|
876
|
-
to:
|
|
932
|
+
at: BlockPath
|
|
933
|
+
to: BlockPath
|
|
877
934
|
}
|
|
878
935
|
| {
|
|
879
936
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
@@ -900,6 +957,8 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
900
957
|
'annotation.remove',
|
|
901
958
|
'block.set',
|
|
902
959
|
'block.unset',
|
|
960
|
+
'child.set',
|
|
961
|
+
'child.unset',
|
|
903
962
|
'decorator.add',
|
|
904
963
|
'decorator.remove',
|
|
905
964
|
'delete',
|
package/lib/behaviors/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
KeyedSegment,
|
|
3
2
|
Path,
|
|
4
3
|
PortableTextBlock,
|
|
5
4
|
PortableTextObject,
|
|
@@ -7,6 +6,11 @@ import type {
|
|
|
7
6
|
} from '@sanity/types'
|
|
8
7
|
|
|
9
8
|
declare type AbstractBehaviorEvent =
|
|
9
|
+
| {
|
|
10
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
|
|
11
|
+
at: AnnotationPath
|
|
12
|
+
props: Record<string, unknown>
|
|
13
|
+
}
|
|
10
14
|
| {
|
|
11
15
|
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
|
|
12
16
|
annotation: {
|
|
@@ -30,7 +34,11 @@ declare type AbstractBehaviorEvent =
|
|
|
30
34
|
}
|
|
31
35
|
| {
|
|
32
36
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
|
|
33
|
-
at:
|
|
37
|
+
at: BlockPath
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
|
|
41
|
+
at: ChildPath
|
|
34
42
|
}
|
|
35
43
|
| {
|
|
36
44
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
@@ -131,11 +139,11 @@ declare type AbstractBehaviorEvent =
|
|
|
131
139
|
}
|
|
132
140
|
| {
|
|
133
141
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
|
|
134
|
-
at:
|
|
142
|
+
at: BlockPath
|
|
135
143
|
}
|
|
136
144
|
| {
|
|
137
145
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
|
|
138
|
-
at:
|
|
146
|
+
at: BlockPath
|
|
139
147
|
}
|
|
140
148
|
| {
|
|
141
149
|
type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
|
|
@@ -165,10 +173,12 @@ declare type AbstractBehaviorEvent =
|
|
|
165
173
|
* Abstract events
|
|
166
174
|
**************************************/
|
|
167
175
|
declare const abstractBehaviorEventTypes: readonly [
|
|
176
|
+
'annotation.set',
|
|
168
177
|
'annotation.toggle',
|
|
169
178
|
'decorator.toggle',
|
|
170
179
|
'delete.backward',
|
|
171
180
|
'delete.block',
|
|
181
|
+
'delete.child',
|
|
172
182
|
'delete.forward',
|
|
173
183
|
'delete.text',
|
|
174
184
|
'deserialize',
|
|
@@ -193,6 +203,19 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
193
203
|
'style.toggle',
|
|
194
204
|
]
|
|
195
205
|
|
|
206
|
+
/**
|
|
207
|
+
* @public
|
|
208
|
+
*/
|
|
209
|
+
declare type AnnotationPath = [
|
|
210
|
+
{
|
|
211
|
+
_key: string
|
|
212
|
+
},
|
|
213
|
+
'markDefs',
|
|
214
|
+
{
|
|
215
|
+
_key: string
|
|
216
|
+
},
|
|
217
|
+
]
|
|
218
|
+
|
|
196
219
|
/**
|
|
197
220
|
* @public
|
|
198
221
|
*/
|
|
@@ -292,14 +315,36 @@ export declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
|
|
|
292
315
|
* @beta
|
|
293
316
|
*/
|
|
294
317
|
declare type BlockOffset = {
|
|
295
|
-
path:
|
|
318
|
+
path: BlockPath
|
|
296
319
|
offset: number
|
|
297
320
|
}
|
|
298
321
|
|
|
322
|
+
/**
|
|
323
|
+
* @public
|
|
324
|
+
*/
|
|
325
|
+
declare type BlockPath = [
|
|
326
|
+
{
|
|
327
|
+
_key: string
|
|
328
|
+
},
|
|
329
|
+
]
|
|
330
|
+
|
|
299
331
|
declare type BlockWithOptionalKey =
|
|
300
332
|
| TextBlockWithOptionalKey
|
|
301
333
|
| ObjectBlockWithOptionalKey
|
|
302
334
|
|
|
335
|
+
/**
|
|
336
|
+
* @public
|
|
337
|
+
*/
|
|
338
|
+
declare type ChildPath = [
|
|
339
|
+
{
|
|
340
|
+
_key: string
|
|
341
|
+
},
|
|
342
|
+
'children',
|
|
343
|
+
{
|
|
344
|
+
_key: string
|
|
345
|
+
},
|
|
346
|
+
]
|
|
347
|
+
|
|
303
348
|
declare type ClipboardBehaviorEvent =
|
|
304
349
|
| {
|
|
305
350
|
type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
|
|
@@ -798,12 +843,24 @@ export declare type SyntheticBehaviorEvent =
|
|
|
798
843
|
}
|
|
799
844
|
| {
|
|
800
845
|
type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
|
|
801
|
-
at:
|
|
846
|
+
at: BlockPath
|
|
802
847
|
props: Record<string, unknown>
|
|
803
848
|
}
|
|
804
849
|
| {
|
|
805
850
|
type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
|
|
806
|
-
at:
|
|
851
|
+
at: BlockPath
|
|
852
|
+
props: Array<string>
|
|
853
|
+
}
|
|
854
|
+
| {
|
|
855
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'child.set'>
|
|
856
|
+
at: ChildPath
|
|
857
|
+
props: {
|
|
858
|
+
[prop: string]: unknown
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
| {
|
|
862
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'child.unset'>
|
|
863
|
+
at: ChildPath
|
|
807
864
|
props: Array<string>
|
|
808
865
|
}
|
|
809
866
|
| {
|
|
@@ -872,8 +929,8 @@ export declare type SyntheticBehaviorEvent =
|
|
|
872
929
|
}
|
|
873
930
|
| {
|
|
874
931
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
875
|
-
at:
|
|
876
|
-
to:
|
|
932
|
+
at: BlockPath
|
|
933
|
+
to: BlockPath
|
|
877
934
|
}
|
|
878
935
|
| {
|
|
879
936
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
@@ -900,6 +957,8 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
900
957
|
'annotation.remove',
|
|
901
958
|
'block.set',
|
|
902
959
|
'block.unset',
|
|
960
|
+
'child.set',
|
|
961
|
+
'child.unset',
|
|
903
962
|
'decorator.add',
|
|
904
963
|
'decorator.remove',
|
|
905
964
|
'delete',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/behaviors/behavior.types.action.ts","../../src/behaviors/behavior.types.behavior.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/behaviors/behavior.types.action.ts","../../src/behaviors/behavior.types.behavior.ts"],"sourcesContent":["import type {EditorDom} from '../editor/editor-dom'\nimport type {EditorSnapshot} from '../editor/editor-snapshot'\nimport type {PickFromUnion} from '../type-utils'\nimport type {\n CustomBehaviorEvent,\n NativeBehaviorEvent,\n SyntheticBehaviorEvent,\n} from './behavior.types.event'\n\n/**\n * @beta\n */\nexport type BehaviorAction =\n | {\n type: 'execute'\n event: SyntheticBehaviorEvent\n }\n | {\n type: 'forward'\n event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent\n }\n | {\n type: 'raise'\n event: SyntheticBehaviorEvent | CustomBehaviorEvent\n }\n | {\n type: 'effect'\n effect: () => void\n }\n\n/**\n * @beta\n */\nexport function execute(\n event: SyntheticBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'execute'> {\n return {type: 'execute', event}\n}\n\n/**\n * @beta\n */\nexport function forward(\n event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'forward'> {\n return {type: 'forward', event}\n}\n\n/**\n * @beta\n */\nexport function raise(\n event: SyntheticBehaviorEvent | CustomBehaviorEvent,\n): PickFromUnion<BehaviorAction, 'type', 'raise'> {\n return {type: 'raise', event}\n}\n\n/**\n * @beta\n */\nexport function effect(\n effect: () => void,\n): PickFromUnion<BehaviorAction, 'type', 'effect'> {\n return {type: 'effect', effect}\n}\n\n/**\n * @beta\n */\nexport type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (\n payload: {\n snapshot: EditorSnapshot\n event: TBehaviorEvent\n dom: EditorDom\n },\n guardResponse: TGuardResponse,\n) => Array<BehaviorAction>\n","import type {BehaviorActionSet} from './behavior.types.action'\nimport type {\n BehaviorEvent,\n BehaviorEventTypeNamespace,\n CustomBehaviorEvent,\n ResolveBehaviorEvent,\n} from './behavior.types.event'\nimport type {BehaviorGuard} from './behavior.types.guard'\n\n/**\n * @beta\n */\nexport type Behavior<\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] =\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'],\n TGuardResponse = true,\n TBehaviorEvent extends\n ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>,\n> = {\n /**\n * Editor Event that triggers this Behavior.\n */\n on: TBehaviorEventType\n /**\n * Predicate function that determines if the Behavior should be executed.\n * Returning a non-nullable value from the guard will pass the value to the\n * actions and execute them.\n */\n guard?: BehaviorGuard<TBehaviorEvent, TGuardResponse>\n /**\n * Array of Behavior Action sets.\n * Each set represents a step in the history stack.\n */\n actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>\n}\n\n/**\n * @beta\n *\n * @example\n *\n * ```tsx\n * const noLowerCaseA = defineBehavior({\n * on: 'insert.text',\n * guard: ({event, snapshot}) => event.text === 'a',\n * actions: [({event, snapshot}) => [{type: 'insert.text', text: 'A'}]],\n * })\n * ```\n *\n */\nexport function defineBehavior<\n TPayload extends Record<string, unknown>,\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] = CustomBehaviorEvent['type'],\n TGuardResponse = true,\n>(\n behavior: Behavior<\n TBehaviorEventType,\n TGuardResponse,\n ResolveBehaviorEvent<TBehaviorEventType, TPayload>\n >,\n): Behavior\nexport function defineBehavior<\n TPayload extends never = never,\n TBehaviorEventType extends\n | '*'\n | `${BehaviorEventTypeNamespace}.*`\n | BehaviorEvent['type'] = BehaviorEvent['type'],\n TGuardResponse = true,\n TBehaviorEvent extends ResolveBehaviorEvent<\n TBehaviorEventType,\n TPayload\n > = ResolveBehaviorEvent<TBehaviorEventType, TPayload>,\n>(\n behavior: Behavior<TBehaviorEventType, TGuardResponse, TBehaviorEvent>,\n): Behavior {\n return behavior as unknown as Behavior\n}\n"],"names":["execute","event","type","forward","raise","effect","defineBehavior","behavior"],"mappings":"AAiCO,SAASA,QACdC,OACkD;AAC3C,SAAA;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAK;AAChC;AAKO,SAASE,QACdF,OACkD;AAC3C,SAAA;AAAA,IAACC,MAAM;AAAA,IAAWD;AAAAA,EAAK;AAChC;AAKO,SAASG,MACdH,OACgD;AACzC,SAAA;AAAA,IAACC,MAAM;AAAA,IAASD;AAAAA,EAAK;AAC9B;AAKO,SAASI,OACdA,SACiD;AAC1C,SAAA;AAAA,IAACH,MAAM;AAAA,IAAUG,QAAAA;AAAAA,EAAM;AAChC;ACKO,SAASC,eAYdC,UACU;AACHA,SAAAA;AACT;"}
|