@portabletext/editor 1.15.1 → 1.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +496 -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 +498 -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 +869 -0
- package/lib/behaviors/index.d.ts +869 -0
- package/lib/behaviors/index.js +464 -0
- package/lib/behaviors/index.js.map +1 -0
- package/lib/index.cjs +51 -1035
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +146 -669
- package/lib/index.d.ts +146 -669
- package/lib/index.js +44 -1027
- 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.d.cts +8 -12
- package/lib/selectors/index.d.ts +8 -12
- package/lib/selectors/index.js +3 -2
- package/lib/selectors/index.js.map +1 -1
- package/package.json +11 -5
- package/src/{editor/behavior → behavior-actions}/behavior.action-utils.insert-block.ts +4 -6
- 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 +20 -20
- package/src/{editor/behavior → behavior-actions}/behavior.guards.ts +2 -6
- package/src/{editor/behavior → behaviors}/behavior.code-editor.ts +4 -4
- package/src/{editor/behavior → behaviors}/behavior.core.block-objects.ts +6 -6
- package/src/{editor/behavior → behaviors}/behavior.core.decorators.ts +6 -16
- package/src/{editor/behavior → behaviors}/behavior.core.lists.ts +17 -17
- package/src/{editor/behavior → behaviors}/behavior.links.ts +5 -5
- package/src/{editor/behavior → behaviors}/behavior.markdown.ts +25 -43
- package/src/{editor/behavior → behaviors}/behavior.types.ts +39 -46
- package/src/behaviors/index.ts +29 -0
- package/src/editor/PortableTextEditor.tsx +2 -2
- package/src/{utils/getPortableTextMemberSchemaTypes.ts → editor/create-editor-schema.ts} +3 -3
- package/src/editor/create-editor.ts +28 -48
- package/src/editor/define-schema.ts +8 -3
- package/src/editor/editor-machine.ts +21 -36
- package/src/editor/editor-selector.ts +1 -13
- package/src/editor/editor-snapshot.ts +4 -6
- 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 +14 -31
- package/src/selectors/index.ts +2 -4
- 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 +3 -3
- package/src/utils/__tests__/patchToOperations.test.ts +3 -3
- package/src/utils/__tests__/values.test.ts +2 -2
- /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,16 +1,14 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
PortableTextMemberSchemaTypes,
|
|
5
|
-
} from '../types/editor'
|
|
2
|
+
import type {EditorSelection} from '../types/editor'
|
|
3
|
+
import type {EditorSchema} from './define-schema'
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* @alpha
|
|
9
7
|
*/
|
|
10
8
|
export type EditorContext = {
|
|
11
9
|
keyGenerator: () => string
|
|
12
|
-
schema:
|
|
13
|
-
selection:
|
|
10
|
+
schema: EditorSchema
|
|
11
|
+
selection: EditorSelection
|
|
14
12
|
value: Array<PortableTextBlock>
|
|
15
13
|
}
|
|
16
14
|
|
|
@@ -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 {
|
|
@@ -33,6 +17,8 @@ export {
|
|
|
33
17
|
type BaseDefinition,
|
|
34
18
|
type SchemaDefinition,
|
|
35
19
|
} from './editor/define-schema'
|
|
20
|
+
export type {PortableTextMemberSchemaTypes} from './types/editor'
|
|
21
|
+
export type {EditorSchema} from './editor/define-schema'
|
|
36
22
|
export {PortableTextEditable} from './editor/Editable'
|
|
37
23
|
export type {PortableTextEditableProps} from './editor/Editable'
|
|
38
24
|
export {EditorEventListener} from './editor/editor-event-listener'
|
|
@@ -51,11 +37,7 @@ export {
|
|
|
51
37
|
useEditor,
|
|
52
38
|
type EditorProviderProps,
|
|
53
39
|
} from './editor/editor-provider'
|
|
54
|
-
export {
|
|
55
|
-
useEditorSelector,
|
|
56
|
-
type EditorSelector,
|
|
57
|
-
type EditorSelectorSnapshot,
|
|
58
|
-
} from './editor/editor-selector'
|
|
40
|
+
export {useEditorSelector, type EditorSelector} from './editor/editor-selector'
|
|
59
41
|
export type {EditorContext, EditorSnapshot} from './editor/editor-snapshot'
|
|
60
42
|
export {usePortableTextEditor} from './editor/hooks/usePortableTextEditor'
|
|
61
43
|
export {usePortableTextEditorSelection} from './editor/hooks/usePortableTextEditorSelection'
|
|
@@ -63,5 +45,6 @@ export {defaultKeyGenerator as keyGenerator} from './editor/key-generator'
|
|
|
63
45
|
export type {AddedAnnotationPaths} from './editor/plugins/createWithEditableAPI'
|
|
64
46
|
export {PortableTextEditor} from './editor/PortableTextEditor'
|
|
65
47
|
export type {PortableTextEditorProps} from './editor/PortableTextEditor'
|
|
48
|
+
export type {OmitFromUnion, PickFromUnion} from './type-utils'
|
|
66
49
|
export * from './types/editor'
|
|
67
50
|
export type {HotkeyOptions} from './types/options'
|
package/src/selectors/index.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
EditorSelector,
|
|
3
|
-
EditorSelectorSnapshot,
|
|
4
|
-
} from '../editor/editor-selector'
|
|
1
|
+
export type {EditorSelector} from '../editor/editor-selector'
|
|
5
2
|
export type {EditorContext, EditorSnapshot} from '../editor/editor-snapshot'
|
|
6
3
|
export type {
|
|
7
4
|
EditorSelection,
|
|
@@ -13,3 +10,4 @@ export {getActiveListItem} from './selector.get-active-list-item'
|
|
|
13
10
|
export {getSelectionText} from './selector.get-selection-text'
|
|
14
11
|
export {getBlockTextBefore} from './selector.get-text-before'
|
|
15
12
|
export * from './selectors'
|
|
13
|
+
export type {EditorSchema} from '../editor/define-schema'
|
|
@@ -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,15 +2,15 @@ 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 {
|
|
7
|
+
import {createEditorSchema} from '../../editor/create-editor-schema'
|
|
7
8
|
import {editorMachine} from '../../editor/editor-machine'
|
|
8
9
|
import {defaultKeyGenerator} from '../../editor/key-generator'
|
|
9
10
|
import {withPlugins} from '../../editor/plugins/with-plugins'
|
|
10
|
-
import {getPortableTextMemberSchemaTypes} from '../getPortableTextMemberSchemaTypes'
|
|
11
11
|
import {createOperationToPatches} from '../operationToPatches'
|
|
12
12
|
|
|
13
|
-
const schemaTypes =
|
|
13
|
+
const schemaTypes = createEditorSchema(schemaType)
|
|
14
14
|
|
|
15
15
|
const operationToPatches = createOperationToPatches(schemaTypes)
|
|
16
16
|
|
|
@@ -2,16 +2,16 @@ 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 {
|
|
7
|
+
import {createEditorSchema} from '../../editor/create-editor-schema'
|
|
7
8
|
import {editorMachine} from '../../editor/editor-machine'
|
|
8
9
|
import {defaultKeyGenerator} from '../../editor/key-generator'
|
|
9
10
|
import {withPlugins} from '../../editor/plugins/with-plugins'
|
|
10
11
|
import {createApplyPatch} from '../applyPatch'
|
|
11
|
-
import {getPortableTextMemberSchemaTypes} from '../getPortableTextMemberSchemaTypes'
|
|
12
12
|
import {VOID_CHILD_KEY} from '../values'
|
|
13
13
|
|
|
14
|
-
const schemaTypes =
|
|
14
|
+
const schemaTypes = createEditorSchema(schemaType)
|
|
15
15
|
|
|
16
16
|
const patchToOperations = createApplyPatch(schemaTypes)
|
|
17
17
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {describe, expect, it} from 'vitest'
|
|
2
2
|
import {schemaType} from '../../editor/__tests__/PortableTextEditorTester'
|
|
3
|
-
import {
|
|
3
|
+
import {createEditorSchema} from '../../editor/create-editor-schema'
|
|
4
4
|
import {fromSlateValue, toSlateValue} from '../values'
|
|
5
5
|
|
|
6
|
-
const schemaTypes =
|
|
6
|
+
const schemaTypes = createEditorSchema(schemaType)
|
|
7
7
|
|
|
8
8
|
describe('toSlateValue', () => {
|
|
9
9
|
it('checks undefined', () => {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|