@portabletext/editor
Advanced tools
Comparing version 1.14.1 to 1.14.2
{ | ||
"name": "@portabletext/editor", | ||
"version": "1.14.1", | ||
"version": "1.14.2", | ||
"description": "Portable Text Editor made in React", | ||
@@ -67,9 +67,9 @@ "keywords": [ | ||
"@portabletext/toolkit": "^2.0.16", | ||
"@sanity/block-tools": "^3.66.0", | ||
"@sanity/block-tools": "^3.66.1", | ||
"@sanity/diff-match-patch": "^3.1.1", | ||
"@sanity/pkg-utils": "^6.11.14", | ||
"@sanity/schema": "^3.66.0", | ||
"@sanity/types": "^3.66.0", | ||
"@sanity/schema": "^3.66.1", | ||
"@sanity/types": "^3.66.1", | ||
"@testing-library/jest-dom": "^6.6.3", | ||
"@testing-library/react": "^16.0.1", | ||
"@testing-library/react": "^16.1.0", | ||
"@types/debug": "^4.1.5", | ||
@@ -80,6 +80,6 @@ "@types/lodash": "^4.17.13", | ||
"@types/react-dom": "^18.3.2", | ||
"@typescript-eslint/eslint-plugin": "^8.16.0", | ||
"@typescript-eslint/parser": "^8.16.0", | ||
"@typescript-eslint/eslint-plugin": "^8.17.0", | ||
"@typescript-eslint/parser": "^8.17.0", | ||
"@vitejs/plugin-react": "^4.3.4", | ||
"@vitest/browser": "^2.1.5", | ||
"@vitest/browser": "^2.1.8", | ||
"@vitest/coverage-istanbul": "^2.1.8", | ||
@@ -89,3 +89,3 @@ "babel-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124", | ||
"eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124", | ||
"eslint-plugin-react-hooks": "^5.0.0", | ||
"eslint-plugin-react-hooks": "^5.1.0", | ||
"jsdom": "^25.0.1", | ||
@@ -98,3 +98,3 @@ "react": "^18.3.1", | ||
"vite": "^5.4.11", | ||
"vitest": "^2.1.5", | ||
"vitest": "^2.1.8", | ||
"vitest-browser-react": "^0.0.4", | ||
@@ -104,5 +104,5 @@ "racejar": "1.1.0" | ||
"peerDependencies": { | ||
"@sanity/block-tools": "^3.66.0", | ||
"@sanity/schema": "^3.66.0", | ||
"@sanity/types": "^3.66.0", | ||
"@sanity/block-tools": "^3.66.1", | ||
"@sanity/schema": "^3.66.1", | ||
"@sanity/types": "^3.66.1", | ||
"react": "^16.9 || ^17 || ^18", | ||
@@ -109,0 +109,0 @@ "rxjs": "^7.8.1", |
@@ -48,4 +48,4 @@ import { | ||
BehaviorAction, | ||
BehaviorEvent, | ||
PickFromUnion, | ||
SyntheticBehaviorEvent, | ||
} from './behavior.types' | ||
@@ -86,3 +86,2 @@ | ||
}, | ||
'copy': () => {}, | ||
'delete.backward': ({action}) => { | ||
@@ -191,4 +190,2 @@ deleteBackward(action.editor, action.unit) | ||
}, | ||
'key.down': () => {}, | ||
'key.up': () => {}, | ||
'list item.add': addListItemActionImplementation, | ||
@@ -233,3 +230,2 @@ 'list item.remove': removeListItemActionImplementation, | ||
'noop': () => {}, | ||
'paste': () => {}, | ||
'select': ({action}) => { | ||
@@ -441,3 +437,3 @@ const newSelection = toSlateRange(action.selection, action.editor) | ||
context: BehaviorActionImplementationContext | ||
action: PickFromUnion<BehaviorAction, 'type', BehaviorEvent['type']> | ||
action: PickFromUnion<BehaviorAction, 'type', SyntheticBehaviorEvent['type']> | ||
}) { | ||
@@ -473,9 +469,2 @@ switch (action.type) { | ||
} | ||
case 'copy': { | ||
behaviorActionImplementations.copy({ | ||
context, | ||
action, | ||
}) | ||
break | ||
} | ||
case 'decorator.add': { | ||
@@ -558,16 +547,2 @@ behaviorActionImplementations['decorator.add']({ | ||
} | ||
case 'key.down': { | ||
behaviorActionImplementations['key.down']({ | ||
context, | ||
action, | ||
}) | ||
break | ||
} | ||
case 'key.up': { | ||
behaviorActionImplementations['key.up']({ | ||
context, | ||
action, | ||
}) | ||
break | ||
} | ||
case 'list item.toggle': { | ||
@@ -580,9 +555,2 @@ behaviorActionImplementations['list item.toggle']({ | ||
} | ||
case 'paste': { | ||
behaviorActionImplementations.paste({ | ||
context, | ||
action, | ||
}) | ||
break | ||
} | ||
default: { | ||
@@ -589,0 +557,0 @@ behaviorActionImplementations['style.toggle']({ |
@@ -10,3 +10,3 @@ import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types' | ||
*/ | ||
export type BehaviorEvent = | ||
export type SyntheticBehaviorEvent = | ||
| { | ||
@@ -36,6 +36,2 @@ type: 'annotation.add' | ||
| { | ||
type: 'copy' | ||
data: DataTransfer | ||
} | ||
| { | ||
type: 'decorator.add' | ||
@@ -90,3 +86,16 @@ decorator: string | ||
| { | ||
type: 'paste' | ||
type: 'list item.toggle' | ||
listItem: string | ||
} | ||
| { | ||
type: 'style.toggle' | ||
style: string | ||
} | ||
/** | ||
* @alpha | ||
*/ | ||
export type NativeBehaviorEvent = | ||
| { | ||
type: 'copy' | ||
data: DataTransfer | ||
@@ -109,9 +118,5 @@ } | ||
| { | ||
type: 'list item.toggle' | ||
listItem: string | ||
type: 'paste' | ||
data: DataTransfer | ||
} | ||
| { | ||
type: 'style.toggle' | ||
style: string | ||
} | ||
@@ -122,3 +127,3 @@ /** | ||
export type BehaviorGuard< | ||
TBehaviorEvent extends BehaviorEvent, | ||
TAnyBehaviorEvent extends BehaviorEvent, | ||
TGuardResponse, | ||
@@ -130,3 +135,3 @@ > = ({ | ||
context: EditorContext | ||
event: TBehaviorEvent | ||
event: TAnyBehaviorEvent | ||
}) => TGuardResponse | false | ||
@@ -138,3 +143,3 @@ | ||
export type BehaviorActionIntend = | ||
| BehaviorEvent | ||
| SyntheticBehaviorEvent | ||
| { | ||
@@ -237,4 +242,9 @@ type: 'insert.span' | ||
*/ | ||
export type BehaviorEvent = SyntheticBehaviorEvent | NativeBehaviorEvent | ||
/** | ||
* @alpha | ||
*/ | ||
export type Behavior< | ||
TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'], | ||
TAnyBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'], | ||
TGuardResponse = true, | ||
@@ -245,3 +255,3 @@ > = { | ||
*/ | ||
on: TBehaviorEventType | ||
on: TAnyBehaviorEventType | ||
/** | ||
@@ -253,3 +263,3 @@ * Predicate function that determines if the behavior should be executed. | ||
guard?: BehaviorGuard< | ||
PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>, | ||
PickFromUnion<BehaviorEvent, 'type', TAnyBehaviorEventType>, | ||
TGuardResponse | ||
@@ -268,9 +278,3 @@ > | ||
guardResponse: TGuardResponse, | ||
) => Array< | ||
OmitFromUnion< | ||
BehaviorActionIntend, | ||
'type', | ||
'copy' | 'key.down' | 'key.up' | 'paste' | ||
> | ||
> | ||
) => Array<BehaviorActionIntend> | ||
@@ -281,5 +285,5 @@ /** | ||
export function defineBehavior< | ||
TBehaviorEventType extends BehaviorEvent['type'], | ||
TAnyBehaviorEventType extends BehaviorEvent['type'], | ||
TGuardResponse = true, | ||
>(behavior: Behavior<TBehaviorEventType, TGuardResponse>): Behavior { | ||
>(behavior: Behavior<TAnyBehaviorEventType, TGuardResponse>): Behavior { | ||
return behavior as unknown as Behavior | ||
@@ -286,0 +290,0 @@ } |
@@ -29,5 +29,6 @@ import type {Patch} from '@portabletext/patches' | ||
BehaviorActionIntend, | ||
BehaviorEvent, | ||
NativeBehaviorEvent, | ||
OmitFromUnion, | ||
PickFromUnion, | ||
SyntheticBehaviorEvent, | ||
} from './behavior/behavior.types' | ||
@@ -74,3 +75,3 @@ import type {EditorContext} from './editor-snapshot' | ||
type: 'behavior event' | ||
behaviorEvent: BehaviorEvent | ||
behaviorEvent: SyntheticBehaviorEvent | NativeBehaviorEvent | ||
editor: PortableTextSlateEditor | ||
@@ -159,3 +160,3 @@ nativeEvent?: {preventDefault: () => void} | ||
| PickFromUnion< | ||
BehaviorEvent, | ||
SyntheticBehaviorEvent, | ||
'type', | ||
@@ -242,6 +243,12 @@ | 'annotation.add' | ||
const defaultAction = { | ||
...event.behaviorEvent, | ||
editor: event.editor, | ||
} satisfies BehaviorAction | ||
const defaultAction = | ||
event.behaviorEvent.type === 'copy' || | ||
event.behaviorEvent.type === 'key.down' || | ||
event.behaviorEvent.type === 'key.up' || | ||
event.behaviorEvent.type === 'paste' | ||
? undefined | ||
: ({ | ||
...event.behaviorEvent, | ||
editor: event.editor, | ||
} satisfies BehaviorAction) | ||
@@ -253,2 +260,6 @@ const eventBehaviors = context.behaviors.filter( | ||
if (eventBehaviors.length === 0) { | ||
if (!defaultAction) { | ||
return | ||
} | ||
enqueue.raise({ | ||
@@ -277,2 +288,7 @@ type: 'behavior action intends', | ||
) | ||
if (!defaultAction) { | ||
return | ||
} | ||
enqueue.raise({ | ||
@@ -333,2 +349,6 @@ type: 'behavior action intends', | ||
if (!behaviorOverwritten) { | ||
if (!defaultAction) { | ||
return | ||
} | ||
enqueue.raise({ | ||
@@ -335,0 +355,0 @@ type: 'behavior action intends', |
@@ -18,10 +18,12 @@ export type {Patch} from '@portabletext/patches' | ||
defineBehavior, | ||
type BehaviorEvent, | ||
type Behavior, | ||
type BehaviorActionIntend, | ||
type BehaviorActionIntendSet, | ||
type BehaviorEvent, | ||
type SyntheticBehaviorEvent, | ||
type BehaviorGuard, | ||
type BlockOffset, | ||
type NativeBehaviorEvent, | ||
type OmitFromUnion, | ||
type PickFromUnion, | ||
type BlockOffset, | ||
} from './editor/behavior/behavior.types' | ||
@@ -28,0 +30,0 @@ export type {Editor, EditorConfig, EditorEvent} from './editor/create-editor' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
3226479
46143