@portabletext/editor 1.15.1 → 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 +0 -231
- 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 +2 -233
- 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 +38 -1008
- 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 +31 -1000
- 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 +10 -4
- 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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'
|
|
2
2
|
import type {TextUnit} from 'slate'
|
|
3
3
|
import type {TextInsertTextOptions} from 'slate/dist/interfaces/transforms/text'
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
4
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
5
|
+
import type {PickFromUnion} from '../type-utils'
|
|
6
|
+
import type {EditorSelection, PortableTextSlateEditor} from '../types/editor'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @alpha
|
|
@@ -116,20 +117,6 @@ export type NativeBehaviorEvent =
|
|
|
116
117
|
data: DataTransfer
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
/**
|
|
120
|
-
* @alpha
|
|
121
|
-
*/
|
|
122
|
-
export type BehaviorGuard<
|
|
123
|
-
TAnyBehaviorEvent extends BehaviorEvent,
|
|
124
|
-
TGuardResponse,
|
|
125
|
-
> = ({
|
|
126
|
-
context,
|
|
127
|
-
event,
|
|
128
|
-
}: {
|
|
129
|
-
context: EditorContext
|
|
130
|
-
event: TAnyBehaviorEvent
|
|
131
|
-
}) => TGuardResponse | false
|
|
132
|
-
|
|
133
120
|
/**
|
|
134
121
|
* @alpha
|
|
135
122
|
*/
|
|
@@ -238,32 +225,56 @@ export type BehaviorEvent = SyntheticBehaviorEvent | NativeBehaviorEvent
|
|
|
238
225
|
* @alpha
|
|
239
226
|
*/
|
|
240
227
|
export type Behavior<
|
|
241
|
-
|
|
228
|
+
TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
|
|
242
229
|
TGuardResponse = true,
|
|
243
230
|
> = {
|
|
244
231
|
/**
|
|
245
232
|
* The internal editor event that triggers this behavior.
|
|
246
233
|
*/
|
|
247
|
-
on:
|
|
234
|
+
on: TBehaviorEventType
|
|
248
235
|
/**
|
|
249
236
|
* Predicate function that determines if the behavior should be executed.
|
|
250
237
|
* Returning a non-nullable value from the guard will pass the value to the
|
|
251
238
|
* actions and execute them.
|
|
252
239
|
*/
|
|
253
240
|
guard?: BehaviorGuard<
|
|
254
|
-
PickFromUnion<BehaviorEvent, 'type',
|
|
241
|
+
PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>,
|
|
255
242
|
TGuardResponse
|
|
256
243
|
>
|
|
257
244
|
/**
|
|
258
245
|
* Array of behavior action sets.
|
|
259
246
|
*/
|
|
260
|
-
actions: Array<BehaviorActionIntendSet<TGuardResponse>>
|
|
247
|
+
actions: Array<BehaviorActionIntendSet<TBehaviorEventType, TGuardResponse>>
|
|
261
248
|
}
|
|
262
249
|
|
|
263
250
|
/**
|
|
264
251
|
* @alpha
|
|
265
252
|
*/
|
|
266
|
-
export type
|
|
253
|
+
export type BehaviorGuard<
|
|
254
|
+
TBehaviorEvent extends BehaviorEvent,
|
|
255
|
+
TGuardResponse,
|
|
256
|
+
> = ({
|
|
257
|
+
context,
|
|
258
|
+
event,
|
|
259
|
+
}: {
|
|
260
|
+
context: EditorContext
|
|
261
|
+
event: TBehaviorEvent
|
|
262
|
+
}) => TGuardResponse | false
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @alpha
|
|
266
|
+
*/
|
|
267
|
+
export type BehaviorActionIntendSet<
|
|
268
|
+
TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
|
|
269
|
+
TGuardResponse = true,
|
|
270
|
+
> = (
|
|
271
|
+
{
|
|
272
|
+
context,
|
|
273
|
+
event,
|
|
274
|
+
}: {
|
|
275
|
+
context: EditorContext
|
|
276
|
+
event: PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
|
|
277
|
+
},
|
|
267
278
|
guardResponse: TGuardResponse,
|
|
268
279
|
) => Array<BehaviorActionIntend>
|
|
269
280
|
|
|
@@ -284,21 +295,3 @@ export type BlockOffset = {
|
|
|
284
295
|
path: [KeyedSegment]
|
|
285
296
|
offset: number
|
|
286
297
|
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* @alpha
|
|
290
|
-
*/
|
|
291
|
-
export type PickFromUnion<
|
|
292
|
-
TUnion,
|
|
293
|
-
TTagKey extends keyof TUnion,
|
|
294
|
-
TPickedTags extends TUnion[TTagKey],
|
|
295
|
-
> = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* @alpha
|
|
299
|
-
*/
|
|
300
|
-
export type OmitFromUnion<
|
|
301
|
-
TUnion,
|
|
302
|
-
TTagKey extends keyof TUnion,
|
|
303
|
-
TOmittedTags extends TUnion[TTagKey],
|
|
304
|
-
> = TUnion extends Record<TTagKey, TOmittedTags> ? never : TUnion
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type {EditorContext} from '../editor/editor-snapshot'
|
|
2
|
+
export type {PickFromUnion} from '../type-utils'
|
|
3
|
+
export type {
|
|
4
|
+
EditorSelection,
|
|
5
|
+
EditorSelectionPoint,
|
|
6
|
+
PortableTextMemberSchemaTypes,
|
|
7
|
+
} from '../types/editor'
|
|
8
|
+
export {
|
|
9
|
+
createCodeEditorBehaviors,
|
|
10
|
+
type CodeEditorBehaviorsConfig,
|
|
11
|
+
} from './behavior.code-editor'
|
|
12
|
+
export {coreBehavior, coreBehaviors} from './behavior.core'
|
|
13
|
+
export {createLinkBehaviors, type LinkBehaviorsConfig} from './behavior.links'
|
|
14
|
+
export {
|
|
15
|
+
createMarkdownBehaviors,
|
|
16
|
+
type MarkdownBehaviorsConfig,
|
|
17
|
+
} from './behavior.markdown'
|
|
18
|
+
export {
|
|
19
|
+
defineBehavior,
|
|
20
|
+
type Behavior,
|
|
21
|
+
type BehaviorActionIntend,
|
|
22
|
+
type BehaviorActionIntendSet,
|
|
23
|
+
type BehaviorEvent,
|
|
24
|
+
type BehaviorGuard,
|
|
25
|
+
type BlockOffset,
|
|
26
|
+
type NativeBehaviorEvent,
|
|
27
|
+
type SyntheticBehaviorEvent,
|
|
28
|
+
} from './behavior.types'
|
|
@@ -11,10 +11,11 @@ import {
|
|
|
11
11
|
type EventObject,
|
|
12
12
|
type Snapshot,
|
|
13
13
|
} from 'xstate'
|
|
14
|
+
import type {Behavior} from '../behaviors/behavior.types'
|
|
15
|
+
import type {PickFromUnion} from '../type-utils'
|
|
14
16
|
import type {EditableAPI} from '../types/editor'
|
|
15
17
|
import {getPortableTextMemberSchemaTypes} from '../utils/getPortableTextMemberSchemaTypes'
|
|
16
18
|
import {compileType} from '../utils/schema'
|
|
17
|
-
import type {Behavior, PickFromUnion} from './behavior/behavior.types'
|
|
18
19
|
import {createSlateEditor, type SlateEditor} from './create-slate-editor'
|
|
19
20
|
import {compileSchemaDefinition, type SchemaDefinition} from './define-schema'
|
|
20
21
|
import {
|
|
@@ -81,64 +82,21 @@ export type Editor = {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
/**
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
85
|
export function createEditor(config: EditorConfig): Editor {
|
|
88
86
|
const editorActor = createActor(editorMachine, {
|
|
89
87
|
input: editorConfigToMachineInput(config),
|
|
90
88
|
})
|
|
91
|
-
|
|
92
89
|
editorActor.start()
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
const editable = createEditableAPI(slateEditor.instance, editorActor)
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
send: (event) => {
|
|
99
|
-
editorActor.send(event)
|
|
100
|
-
},
|
|
101
|
-
on: (event, listener) =>
|
|
102
|
-
editorActor.on(
|
|
103
|
-
event,
|
|
104
|
-
// @ts-expect-error
|
|
105
|
-
listener,
|
|
106
|
-
),
|
|
107
|
-
_internal: {
|
|
108
|
-
editable,
|
|
109
|
-
editorActor,
|
|
110
|
-
slateEditor,
|
|
111
|
-
},
|
|
112
|
-
}
|
|
91
|
+
return createEditorFromActor(editorActor)
|
|
113
92
|
}
|
|
114
93
|
|
|
115
94
|
export function useCreateEditor(config: EditorConfig): Editor {
|
|
116
95
|
const editorActor = useActorRef(editorMachine, {
|
|
117
96
|
input: editorConfigToMachineInput(config),
|
|
118
97
|
})
|
|
119
|
-
const editor: Editor = useMemo(() => {
|
|
120
|
-
const slateEditor = createSlateEditor({editorActor})
|
|
121
|
-
const editable = createEditableAPI(slateEditor.instance, editorActor)
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
send: (event: EditorEvent) => {
|
|
125
|
-
editorActor.send(event)
|
|
126
|
-
},
|
|
127
|
-
on: (event, listener) =>
|
|
128
|
-
editorActor.on(
|
|
129
|
-
event,
|
|
130
|
-
// @ts-expect-error
|
|
131
|
-
listener,
|
|
132
|
-
),
|
|
133
|
-
_internal: {
|
|
134
|
-
editable,
|
|
135
|
-
editorActor,
|
|
136
|
-
slateEditor,
|
|
137
|
-
},
|
|
138
|
-
}
|
|
139
|
-
}, [editorActor])
|
|
140
98
|
|
|
141
|
-
return
|
|
99
|
+
return useMemo(() => createEditorFromActor(editorActor), [editorActor])
|
|
142
100
|
}
|
|
143
101
|
|
|
144
102
|
function editorConfigToMachineInput(config: EditorConfig) {
|
|
@@ -157,3 +115,25 @@ function editorConfigToMachineInput(config: EditorConfig) {
|
|
|
157
115
|
value: config.initialValue,
|
|
158
116
|
} as const
|
|
159
117
|
}
|
|
118
|
+
|
|
119
|
+
function createEditorFromActor(editorActor: EditorActor): Editor {
|
|
120
|
+
const slateEditor = createSlateEditor({editorActor})
|
|
121
|
+
const editable = createEditableAPI(slateEditor.instance, editorActor)
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
send: (event) => {
|
|
125
|
+
editorActor.send(event)
|
|
126
|
+
},
|
|
127
|
+
on: (event, listener) =>
|
|
128
|
+
editorActor.on(
|
|
129
|
+
event,
|
|
130
|
+
// @ts-expect-error
|
|
131
|
+
listener,
|
|
132
|
+
),
|
|
133
|
+
_internal: {
|
|
134
|
+
editable,
|
|
135
|
+
editorActor,
|
|
136
|
+
slateEditor,
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -10,6 +10,16 @@ import {
|
|
|
10
10
|
setup,
|
|
11
11
|
type ActorRefFrom,
|
|
12
12
|
} from 'xstate'
|
|
13
|
+
import {performAction} from '../behavior-actions/behavior.actions'
|
|
14
|
+
import {coreBehaviors} from '../behaviors/behavior.core'
|
|
15
|
+
import type {
|
|
16
|
+
Behavior,
|
|
17
|
+
BehaviorAction,
|
|
18
|
+
BehaviorActionIntend,
|
|
19
|
+
NativeBehaviorEvent,
|
|
20
|
+
SyntheticBehaviorEvent,
|
|
21
|
+
} from '../behaviors/behavior.types'
|
|
22
|
+
import type {OmitFromUnion, PickFromUnion} from '../type-utils'
|
|
13
23
|
import type {
|
|
14
24
|
EditorSelection,
|
|
15
25
|
InvalidValueResolution,
|
|
@@ -20,17 +30,6 @@ import debug from '../utils/debug'
|
|
|
20
30
|
import {toPortableTextRange} from '../utils/ranges'
|
|
21
31
|
import {fromSlateValue} from '../utils/values'
|
|
22
32
|
import {KEY_TO_VALUE_ELEMENT} from '../utils/weakMaps'
|
|
23
|
-
import {performAction} from './behavior/behavior.actions'
|
|
24
|
-
import {coreBehaviors} from './behavior/behavior.core'
|
|
25
|
-
import type {
|
|
26
|
-
Behavior,
|
|
27
|
-
BehaviorAction,
|
|
28
|
-
BehaviorActionIntend,
|
|
29
|
-
NativeBehaviorEvent,
|
|
30
|
-
OmitFromUnion,
|
|
31
|
-
PickFromUnion,
|
|
32
|
-
SyntheticBehaviorEvent,
|
|
33
|
-
} from './behavior/behavior.types'
|
|
34
33
|
import type {EditorContext} from './editor-snapshot'
|
|
35
34
|
|
|
36
35
|
export * from 'xstate/guards'
|
|
@@ -315,7 +314,10 @@ export const editorMachine = setup({
|
|
|
315
314
|
}
|
|
316
315
|
|
|
317
316
|
const actionIntendSets = eventBehavior.actions.map((actionSet) =>
|
|
318
|
-
actionSet(
|
|
317
|
+
actionSet(
|
|
318
|
+
{context: editorContext, event: event.behaviorEvent},
|
|
319
|
+
shouldRun,
|
|
320
|
+
),
|
|
319
321
|
)
|
|
320
322
|
|
|
321
323
|
for (const actionIntends of actionIntendSets) {
|
|
@@ -18,6 +18,9 @@ import {
|
|
|
18
18
|
} from 'slate'
|
|
19
19
|
import type {DOMNode} from 'slate-dom'
|
|
20
20
|
import {ReactEditor} from 'slate-react'
|
|
21
|
+
import {isListItemActive} from '../../behavior-actions/behavior.action.list-item'
|
|
22
|
+
import {isStyleActive} from '../../behavior-actions/behavior.action.style'
|
|
23
|
+
import type {BehaviorActionImplementation} from '../../behavior-actions/behavior.actions'
|
|
21
24
|
import type {
|
|
22
25
|
EditableAPI,
|
|
23
26
|
EditableAPIDeleteOptions,
|
|
@@ -31,9 +34,6 @@ import {
|
|
|
31
34
|
KEY_TO_VALUE_ELEMENT,
|
|
32
35
|
SLATE_TO_PORTABLE_TEXT_RANGE,
|
|
33
36
|
} from '../../utils/weakMaps'
|
|
34
|
-
import {isListItemActive} from '../behavior/behavior.action.list-item'
|
|
35
|
-
import {isStyleActive} from '../behavior/behavior.action.style'
|
|
36
|
-
import type {BehaviorActionImplementation} from '../behavior/behavior.actions'
|
|
37
37
|
import type {EditorActor} from '../editor-machine'
|
|
38
38
|
import {isDecoratorActive} from './createWithPortableTextMarkModel'
|
|
39
39
|
|
|
@@ -8,6 +8,7 @@ import {isPortableTextBlock, isPortableTextSpan} from '@portabletext/toolkit'
|
|
|
8
8
|
import type {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
9
9
|
import {isEqual, uniq} from 'lodash'
|
|
10
10
|
import {Editor, Element, Node, Path, Range, Text, Transforms} from 'slate'
|
|
11
|
+
import type {BehaviorActionImplementation} from '../../behavior-actions/behavior.actions'
|
|
11
12
|
import type {
|
|
12
13
|
PortableTextMemberSchemaTypes,
|
|
13
14
|
PortableTextSlateEditor,
|
|
@@ -16,7 +17,6 @@ import {debugWithName} from '../../utils/debug'
|
|
|
16
17
|
import {getNextSpan, getPreviousSpan} from '../../utils/sibling-utils'
|
|
17
18
|
import {isChangingRemotely} from '../../utils/withChanges'
|
|
18
19
|
import {isRedoing, isUndoing} from '../../utils/withUndoRedo'
|
|
19
|
-
import type {BehaviorActionImplementation} from '../behavior/behavior.actions'
|
|
20
20
|
import type {EditorActor} from '../editor-machine'
|
|
21
21
|
|
|
22
22
|
const debug = debugWithName('plugin:withPortableTextMarkModel')
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type KeyedSegment,
|
|
5
5
|
type PortableTextBlock,
|
|
6
6
|
} from '@sanity/types'
|
|
7
|
-
import type {BlockOffset} from '
|
|
7
|
+
import type {BlockOffset} from '../../behaviors/behavior.types'
|
|
8
8
|
|
|
9
9
|
export function blockOffsetToSpanSelectionPoint({
|
|
10
10
|
value,
|
package/src/index.ts
CHANGED
|
@@ -1,31 +1,15 @@
|
|
|
1
1
|
export type {Patch} from '@portabletext/patches'
|
|
2
2
|
export type {PortableTextBlock, PortableTextChild} from '@sanity/types'
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
createMarkdownBehaviors,
|
|
14
|
-
type MarkdownBehaviorsConfig,
|
|
15
|
-
} from './editor/behavior/behavior.markdown'
|
|
16
|
-
export {
|
|
17
|
-
defineBehavior,
|
|
18
|
-
type BehaviorEvent,
|
|
19
|
-
type Behavior,
|
|
20
|
-
type BehaviorActionIntend,
|
|
21
|
-
type BehaviorActionIntendSet,
|
|
22
|
-
type SyntheticBehaviorEvent,
|
|
23
|
-
type BehaviorGuard,
|
|
24
|
-
type BlockOffset,
|
|
25
|
-
type NativeBehaviorEvent,
|
|
26
|
-
type OmitFromUnion,
|
|
27
|
-
type PickFromUnion,
|
|
28
|
-
} from './editor/behavior/behavior.types'
|
|
3
|
+
export type {
|
|
4
|
+
Behavior,
|
|
5
|
+
BehaviorActionIntend,
|
|
6
|
+
BehaviorActionIntendSet,
|
|
7
|
+
BehaviorEvent,
|
|
8
|
+
BehaviorGuard,
|
|
9
|
+
BlockOffset,
|
|
10
|
+
NativeBehaviorEvent,
|
|
11
|
+
SyntheticBehaviorEvent,
|
|
12
|
+
} from './behaviors/index'
|
|
29
13
|
export type {Editor, EditorConfig, EditorEvent} from './editor/create-editor'
|
|
30
14
|
export type {SlateEditor} from './editor/create-slate-editor'
|
|
31
15
|
export {
|
|
@@ -63,5 +47,6 @@ export {defaultKeyGenerator as keyGenerator} from './editor/key-generator'
|
|
|
63
47
|
export type {AddedAnnotationPaths} from './editor/plugins/createWithEditableAPI'
|
|
64
48
|
export {PortableTextEditor} from './editor/PortableTextEditor'
|
|
65
49
|
export type {PortableTextEditorProps} from './editor/PortableTextEditor'
|
|
50
|
+
export type {OmitFromUnion, PickFromUnion} from './type-utils'
|
|
66
51
|
export * from './types/editor'
|
|
67
52
|
export type {HotkeyOptions} from './types/options'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {PortableTextListBlock} from '@sanity/types'
|
|
2
|
-
import {createGuards} from '../
|
|
2
|
+
import {createGuards} from '../behavior-actions/behavior.guards'
|
|
3
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
4
4
|
import {getSelectedBlocks} from './selectors'
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type PortableTextSpan,
|
|
10
10
|
type PortableTextTextBlock,
|
|
11
11
|
} from '@sanity/types'
|
|
12
|
-
import {createGuards} from '../
|
|
12
|
+
import {createGuards} from '../behavior-actions/behavior.guards'
|
|
13
13
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @alpha
|
|
3
|
+
*/
|
|
4
|
+
export type PickFromUnion<
|
|
5
|
+
TUnion,
|
|
6
|
+
TTagKey extends keyof TUnion,
|
|
7
|
+
TPickedTags extends TUnion[TTagKey],
|
|
8
|
+
> = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @alpha
|
|
12
|
+
*/
|
|
13
|
+
export type OmitFromUnion<
|
|
14
|
+
TUnion,
|
|
15
|
+
TTagKey extends keyof TUnion,
|
|
16
|
+
TOmittedTags extends TUnion[TTagKey],
|
|
17
|
+
> = TUnion extends Record<TTagKey, TOmittedTags> ? never : TUnion
|
|
@@ -2,8 +2,8 @@ import type {PortableTextTextBlock} from '@sanity/types'
|
|
|
2
2
|
import {createEditor, type Descendant} from 'slate'
|
|
3
3
|
import {beforeEach, describe, expect, it} from 'vitest'
|
|
4
4
|
import {createActor} from 'xstate'
|
|
5
|
+
import {coreBehaviors} from '../../behaviors/behavior.core'
|
|
5
6
|
import {schemaType} from '../../editor/__tests__/PortableTextEditorTester'
|
|
6
|
-
import {coreBehaviors} from '../../editor/behavior/behavior.core'
|
|
7
7
|
import {editorMachine} from '../../editor/editor-machine'
|
|
8
8
|
import {defaultKeyGenerator} from '../../editor/key-generator'
|
|
9
9
|
import {withPlugins} from '../../editor/plugins/with-plugins'
|
|
@@ -2,8 +2,8 @@ import type {Patch} from '@portabletext/patches'
|
|
|
2
2
|
import {createEditor, type Descendant} from 'slate'
|
|
3
3
|
import {beforeEach, describe, expect, it} from 'vitest'
|
|
4
4
|
import {createActor} from 'xstate'
|
|
5
|
+
import {coreBehaviors} from '../../behaviors/behavior.core'
|
|
5
6
|
import {schemaType} from '../../editor/__tests__/PortableTextEditorTester'
|
|
6
|
-
import {coreBehaviors} from '../../editor/behavior/behavior.core'
|
|
7
7
|
import {editorMachine} from '../../editor/editor-machine'
|
|
8
8
|
import {defaultKeyGenerator} from '../../editor/key-generator'
|
|
9
9
|
import {withPlugins} from '../../editor/plugins/with-plugins'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|