@portabletext/editor 1.46.0 → 1.47.1
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 +7 -7
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +411 -327
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +4 -4
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +7 -7
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +412 -328
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +4 -4
- package/lib/_chunks-es/parse-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +590 -28
- package/lib/behaviors/index.d.ts +590 -28
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +4 -4
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +71 -3
- package/lib/index.d.ts +71 -3
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +78 -23
- package/lib/plugins/index.d.ts +78 -23
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +79 -27
- package/lib/selectors/index.d.ts +79 -27
- package/lib/utils/index.d.cts +84 -29
- package/lib/utils/index.d.ts +84 -29
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action.insert.block.ts +1 -1
- package/src/behavior-actions/behavior.action.move.backward.ts +12 -0
- package/src/behavior-actions/behavior.action.move.forward.ts +11 -0
- package/src/behavior-actions/behavior.action.split.block.ts +1 -1
- package/src/behavior-actions/behavior.actions.ts +18 -0
- package/src/behavior-actions/behavior.guards.ts +1 -1
- package/src/behaviors/behavior.core.decorators.ts +4 -4
- package/src/behaviors/behavior.core.insert-break.ts +4 -4
- package/src/behaviors/behavior.decorator-pair.ts +1 -1
- package/src/behaviors/behavior.links.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +1 -1
- package/src/behaviors/behavior.perform-event.ts +1 -1
- package/src/behaviors/behavior.types.event.ts +10 -0
- package/src/converters/converter.portable-text.deserialize.test.ts +2 -3
- package/src/converters/converter.text-html.deserialize.test.ts +62 -5
- package/src/converters/converter.text-html.serialize.test.ts +9 -5
- package/src/converters/converter.text-html.ts +66 -64
- package/src/converters/converter.text-plain.test.ts +9 -4
- package/src/converters/converter.text-plain.ts +91 -87
- package/src/converters/converters.core.ts +13 -8
- package/src/editor/Editable.tsx +10 -5
- package/src/editor/PortableTextEditor.tsx +5 -5
- package/src/editor/__tests__/PortableTextEditorTester.tsx +4 -3
- package/src/editor/__tests__/insert-block.test.tsx +10 -10
- package/src/editor/__tests__/self-solving.test.tsx +2 -2
- package/src/editor/components/Synchronizer.tsx +1 -1
- package/src/editor/create-editor.ts +51 -18
- package/src/editor/editor-machine.ts +1 -1
- package/src/editor/{define-schema.ts → editor-schema.ts} +114 -5
- package/src/editor/editor-snapshot.ts +1 -1
- package/src/editor/get-active-decorators.ts +2 -2
- package/src/editor/{create-editor-schema.ts → legacy-schema.ts} +3 -3
- package/src/editor/mutation-machine.ts +1 -1
- package/src/editor/plugins/createWithObjectKeys.ts +6 -9
- package/src/editor/plugins/createWithPatches.ts +12 -11
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +2 -6
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +15 -12
- package/src/editor/plugins/createWithSchemaTypes.ts +24 -16
- package/src/editor/plugins/createWithUndoRedo.ts +3 -4
- package/src/editor/plugins/createWithUtils.ts +12 -10
- package/src/editor/plugins/with-plugins.ts +5 -15
- package/src/editor/range-decorations-machine.ts +1 -1
- package/src/editor/sync-machine.ts +1 -1
- package/src/index.ts +2 -2
- package/src/internal-utils/__tests__/operationToPatches.test.ts +12 -10
- package/src/internal-utils/__tests__/patchToOperations.test.ts +3 -2
- package/src/internal-utils/__tests__/values.test.ts +3 -2
- package/src/internal-utils/applyPatch.ts +7 -9
- package/src/internal-utils/create-test-snapshot.ts +1 -1
- package/src/internal-utils/drag-selection.test.ts +1 -1
- package/src/internal-utils/operationToPatches.ts +4 -6
- package/src/internal-utils/parse-blocks.test.ts +1 -1
- package/src/internal-utils/parse-blocks.ts +8 -7
- package/src/internal-utils/slate-children-to-blocks.ts +1 -1
- package/src/internal-utils/slate-utils.ts +1 -1
- package/src/internal-utils/validateValue.ts +4 -6
- package/src/internal-utils/values.ts +5 -5
- package/src/plugins/plugin.decorator-shortcut.ts +1 -1
- package/src/plugins/plugin.markdown.test.tsx +1 -1
- package/src/plugins/plugin.markdown.tsx +1 -1
- package/src/selectors/selector.get-selection-text.test.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
package/lib/utils/index.d.cts
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import type {Patch} from '@portabletext/patches'
|
|
2
|
-
import type {
|
|
3
|
-
ArraySchemaType,
|
|
4
|
-
BlockDecoratorDefinition,
|
|
5
|
-
BlockListDefinition,
|
|
6
|
-
BlockStyleDefinition,
|
|
7
|
-
ObjectSchemaType,
|
|
8
|
-
Path,
|
|
9
|
-
PortableTextChild,
|
|
10
|
-
PortableTextListBlock,
|
|
11
|
-
PortableTextTextBlock,
|
|
12
|
-
} from '@sanity/types'
|
|
13
2
|
import {
|
|
14
3
|
KeyedSegment,
|
|
15
4
|
PortableTextBlock,
|
|
16
5
|
PortableTextObject,
|
|
17
6
|
PortableTextSpan,
|
|
18
7
|
} from '@sanity/types'
|
|
8
|
+
import type {
|
|
9
|
+
Path,
|
|
10
|
+
PortableTextChild,
|
|
11
|
+
PortableTextListBlock,
|
|
12
|
+
PortableTextTextBlock,
|
|
13
|
+
} from '@sanity/types'
|
|
19
14
|
import type {
|
|
20
15
|
FocusEvent as FocusEvent_2,
|
|
21
16
|
KeyboardEvent as KeyboardEvent_2,
|
|
@@ -44,7 +39,6 @@ import {
|
|
|
44
39
|
Values,
|
|
45
40
|
} from 'xstate'
|
|
46
41
|
import {GuardArgs} from 'xstate/guards'
|
|
47
|
-
import {PortableTextMemberSchemaTypes as PortableTextMemberSchemaTypes_2} from '..'
|
|
48
42
|
|
|
49
43
|
declare type AbstractBehaviorEvent =
|
|
50
44
|
| {
|
|
@@ -219,6 +213,14 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
219
213
|
'style.toggle',
|
|
220
214
|
]
|
|
221
215
|
|
|
216
|
+
/**
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
declare type BaseDefinition = {
|
|
220
|
+
name: string
|
|
221
|
+
title?: string
|
|
222
|
+
}
|
|
223
|
+
|
|
222
224
|
/**
|
|
223
225
|
* @beta
|
|
224
226
|
*/
|
|
@@ -1222,7 +1224,7 @@ declare const editorMachine: StateMachine<
|
|
|
1222
1224
|
converters: Set<Converter>
|
|
1223
1225
|
keyGenerator: () => string
|
|
1224
1226
|
pendingEvents: never[]
|
|
1225
|
-
schema:
|
|
1227
|
+
schema: EditorSchema
|
|
1226
1228
|
selection: null
|
|
1227
1229
|
initialReadOnly: boolean
|
|
1228
1230
|
maxBlocks: number | undefined
|
|
@@ -4702,7 +4704,65 @@ declare const editorMachine: StateMachine<
|
|
|
4702
4704
|
/**
|
|
4703
4705
|
* @public
|
|
4704
4706
|
*/
|
|
4705
|
-
declare type EditorSchema =
|
|
4707
|
+
declare type EditorSchema = {
|
|
4708
|
+
annotations: ReadonlyArray<
|
|
4709
|
+
BaseDefinition & {
|
|
4710
|
+
fields: ReadonlyArray<{
|
|
4711
|
+
name: string
|
|
4712
|
+
type: string
|
|
4713
|
+
}>
|
|
4714
|
+
}
|
|
4715
|
+
>
|
|
4716
|
+
block: {
|
|
4717
|
+
name: string
|
|
4718
|
+
}
|
|
4719
|
+
blockObjects: ReadonlyArray<
|
|
4720
|
+
BaseDefinition & {
|
|
4721
|
+
fields: ReadonlyArray<{
|
|
4722
|
+
name: string
|
|
4723
|
+
type: string
|
|
4724
|
+
}>
|
|
4725
|
+
}
|
|
4726
|
+
>
|
|
4727
|
+
decorators: ReadonlyArray<
|
|
4728
|
+
BaseDefinition & {
|
|
4729
|
+
/**
|
|
4730
|
+
* @deprecated
|
|
4731
|
+
* Use `name` instead
|
|
4732
|
+
*/
|
|
4733
|
+
value: string
|
|
4734
|
+
}
|
|
4735
|
+
>
|
|
4736
|
+
inlineObjects: ReadonlyArray<
|
|
4737
|
+
BaseDefinition & {
|
|
4738
|
+
fields: ReadonlyArray<{
|
|
4739
|
+
name: string
|
|
4740
|
+
type: string
|
|
4741
|
+
}>
|
|
4742
|
+
}
|
|
4743
|
+
>
|
|
4744
|
+
span: {
|
|
4745
|
+
name: string
|
|
4746
|
+
}
|
|
4747
|
+
styles: ReadonlyArray<
|
|
4748
|
+
BaseDefinition & {
|
|
4749
|
+
/**
|
|
4750
|
+
* @deprecated
|
|
4751
|
+
* Use `name` instead
|
|
4752
|
+
*/
|
|
4753
|
+
value: string
|
|
4754
|
+
}
|
|
4755
|
+
>
|
|
4756
|
+
lists: ReadonlyArray<
|
|
4757
|
+
BaseDefinition & {
|
|
4758
|
+
/**
|
|
4759
|
+
* @deprecated
|
|
4760
|
+
* Use `name` instead
|
|
4761
|
+
*/
|
|
4762
|
+
value: string
|
|
4763
|
+
}
|
|
4764
|
+
>
|
|
4765
|
+
}
|
|
4706
4766
|
|
|
4707
4767
|
/** @public */
|
|
4708
4768
|
declare type EditorSelection = {
|
|
@@ -5038,21 +5098,6 @@ declare type PickFromUnion<
|
|
|
5038
5098
|
TPickedTags extends TUnion[TTagKey],
|
|
5039
5099
|
> = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
|
|
5040
5100
|
|
|
5041
|
-
/** @beta */
|
|
5042
|
-
declare type PortableTextMemberSchemaTypes = {
|
|
5043
|
-
annotations: (ObjectSchemaType & {
|
|
5044
|
-
i18nTitleKey?: string
|
|
5045
|
-
})[]
|
|
5046
|
-
block: ObjectSchemaType
|
|
5047
|
-
blockObjects: ObjectSchemaType[]
|
|
5048
|
-
decorators: BlockDecoratorDefinition[]
|
|
5049
|
-
inlineObjects: ObjectSchemaType[]
|
|
5050
|
-
portableText: ArraySchemaType<PortableTextBlock>
|
|
5051
|
-
span: ObjectSchemaType
|
|
5052
|
-
styles: BlockStyleDefinition[]
|
|
5053
|
-
lists: BlockListDefinition[]
|
|
5054
|
-
}
|
|
5055
|
-
|
|
5056
5101
|
declare interface PortableTextSlateEditor extends ReactEditor {
|
|
5057
5102
|
_key: 'editor'
|
|
5058
5103
|
_type: 'editor'
|
|
@@ -5282,11 +5327,19 @@ declare type SyntheticBehaviorEvent =
|
|
|
5282
5327
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
|
|
5283
5328
|
text: string
|
|
5284
5329
|
}
|
|
5330
|
+
| {
|
|
5331
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>
|
|
5332
|
+
distance: number
|
|
5333
|
+
}
|
|
5285
5334
|
| {
|
|
5286
5335
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
5287
5336
|
at: [KeyedSegment]
|
|
5288
5337
|
to: [KeyedSegment]
|
|
5289
5338
|
}
|
|
5339
|
+
| {
|
|
5340
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
5341
|
+
distance: number
|
|
5342
|
+
}
|
|
5290
5343
|
| {
|
|
5291
5344
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5292
5345
|
at: EditorSelection
|
|
@@ -5323,7 +5376,9 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5323
5376
|
'insert.block',
|
|
5324
5377
|
'insert.span',
|
|
5325
5378
|
'insert.text',
|
|
5379
|
+
'move.backward',
|
|
5326
5380
|
'move.block',
|
|
5381
|
+
'move.forward',
|
|
5327
5382
|
'select',
|
|
5328
5383
|
'split.block',
|
|
5329
5384
|
]
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import type {Patch} from '@portabletext/patches'
|
|
2
|
-
import type {
|
|
3
|
-
ArraySchemaType,
|
|
4
|
-
BlockDecoratorDefinition,
|
|
5
|
-
BlockListDefinition,
|
|
6
|
-
BlockStyleDefinition,
|
|
7
|
-
ObjectSchemaType,
|
|
8
|
-
Path,
|
|
9
|
-
PortableTextChild,
|
|
10
|
-
PortableTextListBlock,
|
|
11
|
-
PortableTextTextBlock,
|
|
12
|
-
} from '@sanity/types'
|
|
13
2
|
import {
|
|
14
3
|
KeyedSegment,
|
|
15
4
|
PortableTextBlock,
|
|
16
5
|
PortableTextObject,
|
|
17
6
|
PortableTextSpan,
|
|
18
7
|
} from '@sanity/types'
|
|
8
|
+
import type {
|
|
9
|
+
Path,
|
|
10
|
+
PortableTextChild,
|
|
11
|
+
PortableTextListBlock,
|
|
12
|
+
PortableTextTextBlock,
|
|
13
|
+
} from '@sanity/types'
|
|
19
14
|
import type {
|
|
20
15
|
FocusEvent as FocusEvent_2,
|
|
21
16
|
KeyboardEvent as KeyboardEvent_2,
|
|
@@ -44,7 +39,6 @@ import {
|
|
|
44
39
|
Values,
|
|
45
40
|
} from 'xstate'
|
|
46
41
|
import {GuardArgs} from 'xstate/guards'
|
|
47
|
-
import {PortableTextMemberSchemaTypes as PortableTextMemberSchemaTypes_2} from '..'
|
|
48
42
|
|
|
49
43
|
declare type AbstractBehaviorEvent =
|
|
50
44
|
| {
|
|
@@ -219,6 +213,14 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
219
213
|
'style.toggle',
|
|
220
214
|
]
|
|
221
215
|
|
|
216
|
+
/**
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
declare type BaseDefinition = {
|
|
220
|
+
name: string
|
|
221
|
+
title?: string
|
|
222
|
+
}
|
|
223
|
+
|
|
222
224
|
/**
|
|
223
225
|
* @beta
|
|
224
226
|
*/
|
|
@@ -1222,7 +1224,7 @@ declare const editorMachine: StateMachine<
|
|
|
1222
1224
|
converters: Set<Converter>
|
|
1223
1225
|
keyGenerator: () => string
|
|
1224
1226
|
pendingEvents: never[]
|
|
1225
|
-
schema:
|
|
1227
|
+
schema: EditorSchema
|
|
1226
1228
|
selection: null
|
|
1227
1229
|
initialReadOnly: boolean
|
|
1228
1230
|
maxBlocks: number | undefined
|
|
@@ -4702,7 +4704,65 @@ declare const editorMachine: StateMachine<
|
|
|
4702
4704
|
/**
|
|
4703
4705
|
* @public
|
|
4704
4706
|
*/
|
|
4705
|
-
declare type EditorSchema =
|
|
4707
|
+
declare type EditorSchema = {
|
|
4708
|
+
annotations: ReadonlyArray<
|
|
4709
|
+
BaseDefinition & {
|
|
4710
|
+
fields: ReadonlyArray<{
|
|
4711
|
+
name: string
|
|
4712
|
+
type: string
|
|
4713
|
+
}>
|
|
4714
|
+
}
|
|
4715
|
+
>
|
|
4716
|
+
block: {
|
|
4717
|
+
name: string
|
|
4718
|
+
}
|
|
4719
|
+
blockObjects: ReadonlyArray<
|
|
4720
|
+
BaseDefinition & {
|
|
4721
|
+
fields: ReadonlyArray<{
|
|
4722
|
+
name: string
|
|
4723
|
+
type: string
|
|
4724
|
+
}>
|
|
4725
|
+
}
|
|
4726
|
+
>
|
|
4727
|
+
decorators: ReadonlyArray<
|
|
4728
|
+
BaseDefinition & {
|
|
4729
|
+
/**
|
|
4730
|
+
* @deprecated
|
|
4731
|
+
* Use `name` instead
|
|
4732
|
+
*/
|
|
4733
|
+
value: string
|
|
4734
|
+
}
|
|
4735
|
+
>
|
|
4736
|
+
inlineObjects: ReadonlyArray<
|
|
4737
|
+
BaseDefinition & {
|
|
4738
|
+
fields: ReadonlyArray<{
|
|
4739
|
+
name: string
|
|
4740
|
+
type: string
|
|
4741
|
+
}>
|
|
4742
|
+
}
|
|
4743
|
+
>
|
|
4744
|
+
span: {
|
|
4745
|
+
name: string
|
|
4746
|
+
}
|
|
4747
|
+
styles: ReadonlyArray<
|
|
4748
|
+
BaseDefinition & {
|
|
4749
|
+
/**
|
|
4750
|
+
* @deprecated
|
|
4751
|
+
* Use `name` instead
|
|
4752
|
+
*/
|
|
4753
|
+
value: string
|
|
4754
|
+
}
|
|
4755
|
+
>
|
|
4756
|
+
lists: ReadonlyArray<
|
|
4757
|
+
BaseDefinition & {
|
|
4758
|
+
/**
|
|
4759
|
+
* @deprecated
|
|
4760
|
+
* Use `name` instead
|
|
4761
|
+
*/
|
|
4762
|
+
value: string
|
|
4763
|
+
}
|
|
4764
|
+
>
|
|
4765
|
+
}
|
|
4706
4766
|
|
|
4707
4767
|
/** @public */
|
|
4708
4768
|
declare type EditorSelection = {
|
|
@@ -5038,21 +5098,6 @@ declare type PickFromUnion<
|
|
|
5038
5098
|
TPickedTags extends TUnion[TTagKey],
|
|
5039
5099
|
> = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
|
|
5040
5100
|
|
|
5041
|
-
/** @beta */
|
|
5042
|
-
declare type PortableTextMemberSchemaTypes = {
|
|
5043
|
-
annotations: (ObjectSchemaType & {
|
|
5044
|
-
i18nTitleKey?: string
|
|
5045
|
-
})[]
|
|
5046
|
-
block: ObjectSchemaType
|
|
5047
|
-
blockObjects: ObjectSchemaType[]
|
|
5048
|
-
decorators: BlockDecoratorDefinition[]
|
|
5049
|
-
inlineObjects: ObjectSchemaType[]
|
|
5050
|
-
portableText: ArraySchemaType<PortableTextBlock>
|
|
5051
|
-
span: ObjectSchemaType
|
|
5052
|
-
styles: BlockStyleDefinition[]
|
|
5053
|
-
lists: BlockListDefinition[]
|
|
5054
|
-
}
|
|
5055
|
-
|
|
5056
5101
|
declare interface PortableTextSlateEditor extends ReactEditor {
|
|
5057
5102
|
_key: 'editor'
|
|
5058
5103
|
_type: 'editor'
|
|
@@ -5282,11 +5327,19 @@ declare type SyntheticBehaviorEvent =
|
|
|
5282
5327
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
|
|
5283
5328
|
text: string
|
|
5284
5329
|
}
|
|
5330
|
+
| {
|
|
5331
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>
|
|
5332
|
+
distance: number
|
|
5333
|
+
}
|
|
5285
5334
|
| {
|
|
5286
5335
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
5287
5336
|
at: [KeyedSegment]
|
|
5288
5337
|
to: [KeyedSegment]
|
|
5289
5338
|
}
|
|
5339
|
+
| {
|
|
5340
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
5341
|
+
distance: number
|
|
5342
|
+
}
|
|
5290
5343
|
| {
|
|
5291
5344
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5292
5345
|
at: EditorSelection
|
|
@@ -5323,7 +5376,9 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5323
5376
|
'insert.block',
|
|
5324
5377
|
'insert.span',
|
|
5325
5378
|
'insert.text',
|
|
5379
|
+
'move.backward',
|
|
5326
5380
|
'move.block',
|
|
5381
|
+
'move.forward',
|
|
5327
5382
|
'select',
|
|
5328
5383
|
'split.block',
|
|
5329
5384
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.47.1",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -79,15 +79,15 @@
|
|
|
79
79
|
"slate-react": "0.112.1",
|
|
80
80
|
"use-effect-event": "^1.0.2",
|
|
81
81
|
"xstate": "^5.19.2",
|
|
82
|
-
"@portabletext/block-tools": "1.1.
|
|
82
|
+
"@portabletext/block-tools": "1.1.18",
|
|
83
83
|
"@portabletext/patches": "1.1.3"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@portabletext/toolkit": "^2.0.17",
|
|
87
87
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
88
88
|
"@sanity/pkg-utils": "^7.2.2",
|
|
89
|
-
"@sanity/schema": "^3.
|
|
90
|
-
"@sanity/types": "^3.
|
|
89
|
+
"@sanity/schema": "^3.84.0",
|
|
90
|
+
"@sanity/types": "^3.84.0",
|
|
91
91
|
"@testing-library/jest-dom": "^6.6.3",
|
|
92
92
|
"@testing-library/react": "^16.3.0",
|
|
93
93
|
"@types/debug": "^4.1.12",
|
|
@@ -115,8 +115,8 @@
|
|
|
115
115
|
"racejar": "1.2.3"
|
|
116
116
|
},
|
|
117
117
|
"peerDependencies": {
|
|
118
|
-
"@sanity/schema": "^3.
|
|
119
|
-
"@sanity/types": "^3.
|
|
118
|
+
"@sanity/schema": "^3.84.0",
|
|
119
|
+
"@sanity/types": "^3.84.0",
|
|
120
120
|
"react": "^16.9 || ^17 || ^18 || ^19",
|
|
121
121
|
"rxjs": "^7.8.2"
|
|
122
122
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Editor, Path, Point, Range, Transforms, type Descendant} from 'slate'
|
|
2
2
|
import {DOMEditor} from 'slate-dom'
|
|
3
|
-
import type {EditorSchema} from '../editor/
|
|
3
|
+
import type {EditorSchema} from '../editor/editor-schema'
|
|
4
4
|
import {parseBlock} from '../internal-utils/parse-blocks'
|
|
5
5
|
import {
|
|
6
6
|
getFocusBlock,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Transforms} from 'slate'
|
|
2
|
+
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
3
|
+
|
|
4
|
+
export const moveBackwardActionImplementation: BehaviorActionImplementation<
|
|
5
|
+
'move.backward'
|
|
6
|
+
> = ({action}) => {
|
|
7
|
+
Transforms.move(action.editor, {
|
|
8
|
+
unit: 'character',
|
|
9
|
+
distance: action.distance,
|
|
10
|
+
reverse: true,
|
|
11
|
+
})
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {Transforms} from 'slate'
|
|
2
|
+
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
3
|
+
|
|
4
|
+
export const moveForwardActionImplementation: BehaviorActionImplementation<
|
|
5
|
+
'move.forward'
|
|
6
|
+
> = ({action}) => {
|
|
7
|
+
Transforms.move(action.editor, {
|
|
8
|
+
unit: 'character',
|
|
9
|
+
distance: action.distance,
|
|
10
|
+
})
|
|
11
|
+
}
|
|
@@ -88,7 +88,7 @@ export const splitBlockActionImplementation: BehaviorActionImplementation<
|
|
|
88
88
|
// previous block
|
|
89
89
|
for (const mark of marks) {
|
|
90
90
|
if (
|
|
91
|
-
schema.decorators.some((decorator) => decorator.
|
|
91
|
+
schema.decorators.some((decorator) => decorator.name === mark)
|
|
92
92
|
) {
|
|
93
93
|
continue
|
|
94
94
|
}
|
|
@@ -24,7 +24,9 @@ import {insertInlineObjectActionImplementation} from './behavior.action.insert-i
|
|
|
24
24
|
import {insertSpanActionImplementation} from './behavior.action.insert-span'
|
|
25
25
|
import {insertBlockActionImplementation} from './behavior.action.insert.block'
|
|
26
26
|
import {insertTextActionImplementation} from './behavior.action.insert.text'
|
|
27
|
+
import {moveBackwardActionImplementation} from './behavior.action.move.backward'
|
|
27
28
|
import {moveBlockActionImplementation} from './behavior.action.move.block'
|
|
29
|
+
import {moveForwardActionImplementation} from './behavior.action.move.forward'
|
|
28
30
|
import {noopActionImplementation} from './behavior.action.noop'
|
|
29
31
|
import {selectActionImplementation} from './behavior.action.select'
|
|
30
32
|
import {splitBlockActionImplementation} from './behavior.action.split.block'
|
|
@@ -71,7 +73,9 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
|
|
|
71
73
|
'insert.span': insertSpanActionImplementation,
|
|
72
74
|
'insert.text': insertTextActionImplementation,
|
|
73
75
|
'effect': effectActionImplementation,
|
|
76
|
+
'move.backward': moveBackwardActionImplementation,
|
|
74
77
|
'move.block': moveBlockActionImplementation,
|
|
78
|
+
'move.forward': moveForwardActionImplementation,
|
|
75
79
|
'noop': noopActionImplementation,
|
|
76
80
|
'select': selectActionImplementation,
|
|
77
81
|
'split.block': splitBlockActionImplementation,
|
|
@@ -220,6 +224,13 @@ export function performAction({
|
|
|
220
224
|
})
|
|
221
225
|
break
|
|
222
226
|
}
|
|
227
|
+
case 'move.backward': {
|
|
228
|
+
behaviorActionImplementations['move.backward']({
|
|
229
|
+
context,
|
|
230
|
+
action,
|
|
231
|
+
})
|
|
232
|
+
break
|
|
233
|
+
}
|
|
223
234
|
case 'move.block': {
|
|
224
235
|
behaviorActionImplementations['move.block']({
|
|
225
236
|
context,
|
|
@@ -227,6 +238,13 @@ export function performAction({
|
|
|
227
238
|
})
|
|
228
239
|
break
|
|
229
240
|
}
|
|
241
|
+
case 'move.forward': {
|
|
242
|
+
behaviorActionImplementations['move.forward']({
|
|
243
|
+
context,
|
|
244
|
+
action,
|
|
245
|
+
})
|
|
246
|
+
break
|
|
247
|
+
}
|
|
230
248
|
case 'noop': {
|
|
231
249
|
behaviorActionImplementations.noop({
|
|
232
250
|
context,
|
|
@@ -8,7 +8,7 @@ export const coreDecoratorBehaviors = {
|
|
|
8
8
|
guard: ({snapshot, event}) =>
|
|
9
9
|
isHotkey('mod+b', event.originEvent) &&
|
|
10
10
|
snapshot.context.schema.decorators.some(
|
|
11
|
-
(decorator) => decorator.
|
|
11
|
+
(decorator) => decorator.name === 'strong',
|
|
12
12
|
),
|
|
13
13
|
actions: [() => [raise({type: 'decorator.toggle', decorator: 'strong'})]],
|
|
14
14
|
}),
|
|
@@ -17,7 +17,7 @@ export const coreDecoratorBehaviors = {
|
|
|
17
17
|
guard: ({snapshot, event}) =>
|
|
18
18
|
isHotkey('mod+i', event.originEvent) &&
|
|
19
19
|
snapshot.context.schema.decorators.some(
|
|
20
|
-
(decorator) => decorator.
|
|
20
|
+
(decorator) => decorator.name === 'em',
|
|
21
21
|
),
|
|
22
22
|
actions: [() => [raise({type: 'decorator.toggle', decorator: 'em'})]],
|
|
23
23
|
}),
|
|
@@ -26,7 +26,7 @@ export const coreDecoratorBehaviors = {
|
|
|
26
26
|
guard: ({snapshot, event}) =>
|
|
27
27
|
isHotkey('mod+u', event.originEvent) &&
|
|
28
28
|
snapshot.context.schema.decorators.some(
|
|
29
|
-
(decorator) => decorator.
|
|
29
|
+
(decorator) => decorator.name === 'underline',
|
|
30
30
|
),
|
|
31
31
|
actions: [
|
|
32
32
|
() => [raise({type: 'decorator.toggle', decorator: 'underline'})],
|
|
@@ -37,7 +37,7 @@ export const coreDecoratorBehaviors = {
|
|
|
37
37
|
guard: ({snapshot, event}) =>
|
|
38
38
|
isHotkey("mod+'", event.originEvent) &&
|
|
39
39
|
snapshot.context.schema.decorators.some(
|
|
40
|
-
(decorator) => decorator.
|
|
40
|
+
(decorator) => decorator.name === 'code',
|
|
41
41
|
),
|
|
42
42
|
actions: [() => [raise({type: 'decorator.toggle', decorator: 'code'})]],
|
|
43
43
|
}),
|
|
@@ -40,7 +40,7 @@ const breakingAtTheEndOfTextBlock = defineBehavior({
|
|
|
40
40
|
markDefs: [],
|
|
41
41
|
listItem: focusListItem,
|
|
42
42
|
level: focusLevel,
|
|
43
|
-
style: snapshot.context.schema.styles[0]?.
|
|
43
|
+
style: snapshot.context.schema.styles[0]?.name,
|
|
44
44
|
},
|
|
45
45
|
placement: 'after',
|
|
46
46
|
}),
|
|
@@ -63,14 +63,14 @@ const breakingAtTheStartOfTextBlock = defineBehavior({
|
|
|
63
63
|
const focusDecorators = focusSpan?.node.marks?.filter(
|
|
64
64
|
(mark) =>
|
|
65
65
|
snapshot.context.schema.decorators.some(
|
|
66
|
-
(decorator) => decorator.
|
|
66
|
+
(decorator) => decorator.name === mark,
|
|
67
67
|
) ?? [],
|
|
68
68
|
)
|
|
69
69
|
const focusAnnotations =
|
|
70
70
|
focusSpan?.node.marks?.filter(
|
|
71
71
|
(mark) =>
|
|
72
72
|
!snapshot.context.schema.decorators.some(
|
|
73
|
-
(decorator) => decorator.
|
|
73
|
+
(decorator) => decorator.name === mark,
|
|
74
74
|
),
|
|
75
75
|
) ?? []
|
|
76
76
|
const focusListItem = focusTextBlock.node.listItem
|
|
@@ -103,7 +103,7 @@ const breakingAtTheStartOfTextBlock = defineBehavior({
|
|
|
103
103
|
],
|
|
104
104
|
listItem: focusListItem,
|
|
105
105
|
level: focusLevel,
|
|
106
|
-
style: snapshot.context.schema.styles[0]?.
|
|
106
|
+
style: snapshot.context.schema.styles[0]?.name,
|
|
107
107
|
},
|
|
108
108
|
placement: 'before',
|
|
109
109
|
select: 'none',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {EditorSchema} from '../editor/
|
|
1
|
+
import type {EditorSchema} from '../editor/editor-schema'
|
|
2
2
|
import {createPairRegex} from '../internal-utils/get-text-to-emphasize'
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
4
|
import type {BlockOffset} from '../types/block-offset'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {EditorSchema} from '../editor/
|
|
1
|
+
import type {EditorSchema} from '../editor/editor-schema'
|
|
2
2
|
import {looksLikeUrl} from '../internal-utils/looks-like-url'
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
4
|
import {execute} from './behavior.types.action'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {isPortableTextTextBlock} from '@sanity/types'
|
|
2
|
-
import type {EditorSchema} from '../editor/
|
|
2
|
+
import type {EditorSchema} from '../editor/editor-schema'
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
4
|
import {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'
|
|
5
5
|
import {getTextBlockText} from '../utils/util.get-text-block-text'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {Behavior, BehaviorEvent} from '.'
|
|
2
2
|
import {performAction} from '../behavior-actions/behavior.actions'
|
|
3
|
-
import type {EditorSchema} from '../editor/
|
|
3
|
+
import type {EditorSchema} from '../editor/editor-schema'
|
|
4
4
|
import type {EditorSnapshot} from '../editor/editor-snapshot'
|
|
5
5
|
import {
|
|
6
6
|
withApplyingBehaviorActions,
|
|
@@ -75,7 +75,9 @@ const syntheticBehaviorEventTypes = [
|
|
|
75
75
|
'insert.block',
|
|
76
76
|
'insert.span',
|
|
77
77
|
'insert.text',
|
|
78
|
+
'move.backward',
|
|
78
79
|
'move.block',
|
|
80
|
+
'move.forward',
|
|
79
81
|
'select',
|
|
80
82
|
'split.block',
|
|
81
83
|
] as const
|
|
@@ -178,11 +180,19 @@ export type SyntheticBehaviorEvent =
|
|
|
178
180
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
|
|
179
181
|
text: string
|
|
180
182
|
}
|
|
183
|
+
| {
|
|
184
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>
|
|
185
|
+
distance: number
|
|
186
|
+
}
|
|
181
187
|
| {
|
|
182
188
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
183
189
|
at: [KeyedSegment]
|
|
184
190
|
to: [KeyedSegment]
|
|
185
191
|
}
|
|
192
|
+
| {
|
|
193
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
194
|
+
distance: number
|
|
195
|
+
}
|
|
186
196
|
| {
|
|
187
197
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
188
198
|
at: EditorSelection
|
|
@@ -3,15 +3,14 @@ import {
|
|
|
3
3
|
compileSchemaDefinition,
|
|
4
4
|
defineSchema,
|
|
5
5
|
type SchemaDefinition,
|
|
6
|
-
} from '../editor/
|
|
6
|
+
} from '../editor/editor-schema'
|
|
7
7
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
8
8
|
import {converterPortableText} from './converter.portable-text'
|
|
9
|
-
import {coreConverters} from './converters.core'
|
|
10
9
|
|
|
11
10
|
function createSnapshot(schema: SchemaDefinition) {
|
|
12
11
|
return createTestSnapshot({
|
|
13
12
|
context: {
|
|
14
|
-
converters:
|
|
13
|
+
converters: [],
|
|
15
14
|
schema: compileSchemaDefinition(schema),
|
|
16
15
|
},
|
|
17
16
|
})
|