@portabletext/editor 1.36.0 → 1.36.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/editor-provider.cjs +25 -13
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +25 -13
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +7 -10
- package/lib/behaviors/index.d.ts +7 -10
- package/lib/index.cjs +140 -104
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +13 -26
- package/lib/index.d.ts +13 -26
- package/lib/index.js +142 -106
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +2 -7
- package/lib/plugins/index.d.ts +2 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +8 -13
- package/lib/selectors/index.d.ts +8 -13
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3 -6
- package/lib/utils/index.d.ts +3 -6
- package/lib/utils/index.js.map +1 -1
- package/package.json +14 -13
- package/src/behavior-actions/behavior.actions.ts +2 -2
- package/src/behaviors/behavior.decorator-pair.ts +2 -1
- package/src/behaviors/index.ts +0 -8
- package/src/converters/converter.text-html.deserialize.test.ts +1 -1
- package/src/converters/converter.text-html.serialize.test.ts +1 -1
- package/src/converters/converter.text-html.ts +8 -0
- package/src/converters/converter.text-plain.test.ts +1 -1
- package/src/converters/converter.text-plain.ts +8 -0
- package/src/editor/Editable.tsx +1 -1
- package/src/editor/__tests__/PortableTextEditor.test.tsx +16 -20
- package/src/editor/components/Element.tsx +26 -18
- package/src/editor/components/drop-indicator.tsx +14 -0
- package/src/editor/components/{DraggableBlock.tsx → use-draggable.ts} +42 -163
- package/src/editor/components/use-droppable.ts +135 -0
- package/src/editor/create-slate-editor.tsx +0 -3
- package/src/editor/sync-machine.ts +1 -0
- package/src/index.ts +48 -12
- package/src/internal-utils/create-test-snapshot.ts +1 -1
- package/src/plugins/plugin.decorator-shortcut.ts +1 -1
- package/src/plugins/plugin.markdown.tsx +1 -0
- package/src/selectors/index.ts +0 -8
- package/src/selectors/selector.get-active-annotations.test.ts +1 -1
- package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
- package/src/selectors/selector.get-selected-spans.test.ts +2 -1
- package/src/selectors/selector.get-selection-end-point.ts +1 -1
- package/src/selectors/selector.get-selection-start-point.ts +1 -1
- package/src/selectors/selector.get-selection-text.test.ts +1 -1
- package/src/selectors/selector.get-selection.ts +2 -1
- package/src/selectors/selector.get-value.ts +1 -1
- package/src/selectors/selector.is-active-decorator.test.ts +1 -1
- package/src/types/editor.ts +6 -16
- package/src/types/slate.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/util.block-offsets-to-selection.ts +1 -1
- package/src/utils/util.is-span.ts +1 -1
- package/src/utils/util.is-text-block.ts +1 -1
- package/src/utils/util.merge-text-blocks.ts +1 -1
- package/src/utils/util.slice-blocks.ts +1 -1
- package/src/utils/util.split-text-block.ts +4 -2
package/src/index.ts
CHANGED
|
@@ -4,17 +4,7 @@ export type {
|
|
|
4
4
|
PortableTextChild,
|
|
5
5
|
PortableTextSpan,
|
|
6
6
|
} from '@sanity/types'
|
|
7
|
-
export type {
|
|
8
|
-
Behavior,
|
|
9
|
-
BehaviorActionIntend,
|
|
10
|
-
BehaviorActionIntendSet,
|
|
11
|
-
BehaviorEvent,
|
|
12
|
-
BehaviorGuard,
|
|
13
|
-
NativeBehaviorEvent,
|
|
14
|
-
SyntheticBehaviorEvent,
|
|
15
|
-
} from './behaviors/index'
|
|
16
7
|
export type {Editor, EditorConfig, EditorEvent} from './editor/create-editor'
|
|
17
|
-
export type {SlateEditor} from './editor/create-slate-editor'
|
|
18
8
|
export {
|
|
19
9
|
defineSchema,
|
|
20
10
|
type BaseDefinition,
|
|
@@ -43,6 +33,52 @@ export {PortableTextEditor} from './editor/PortableTextEditor'
|
|
|
43
33
|
export type {PortableTextEditorProps} from './editor/PortableTextEditor'
|
|
44
34
|
export {EditorEventListener} from './editor-event-listener'
|
|
45
35
|
export type {BlockOffset} from './types/block-offset'
|
|
46
|
-
export
|
|
47
|
-
|
|
36
|
+
export type {
|
|
37
|
+
EditableAPIDeleteOptions,
|
|
38
|
+
EditableAPI,
|
|
39
|
+
EditorSelectionPoint,
|
|
40
|
+
EditorSelection,
|
|
41
|
+
MutationChange,
|
|
42
|
+
PatchChange,
|
|
43
|
+
ValueChange,
|
|
44
|
+
SelectionChange,
|
|
45
|
+
FocusChange,
|
|
46
|
+
UnsetChange,
|
|
47
|
+
BlurChange,
|
|
48
|
+
LoadingChange,
|
|
49
|
+
ReadyChange,
|
|
50
|
+
ErrorChange,
|
|
51
|
+
InvalidValueResolution,
|
|
52
|
+
InvalidValue,
|
|
53
|
+
UndoChange,
|
|
54
|
+
RedoChange,
|
|
55
|
+
ConnectionChange,
|
|
56
|
+
EditorChange,
|
|
57
|
+
EditorChanges,
|
|
58
|
+
OnPasteResult,
|
|
59
|
+
OnPasteResultOrPromise,
|
|
60
|
+
PasteData,
|
|
61
|
+
OnPasteFn,
|
|
62
|
+
OnBeforeInputFn,
|
|
63
|
+
OnCopyFn,
|
|
64
|
+
PatchObservable,
|
|
65
|
+
BlockRenderProps,
|
|
66
|
+
BlockChildRenderProps,
|
|
67
|
+
BlockAnnotationRenderProps,
|
|
68
|
+
BlockDecoratorRenderProps,
|
|
69
|
+
BlockListItemRenderProps,
|
|
70
|
+
RenderBlockFunction,
|
|
71
|
+
RenderChildFunction,
|
|
72
|
+
RenderEditableFunction,
|
|
73
|
+
RenderAnnotationFunction,
|
|
74
|
+
RenderPlaceholderFunction,
|
|
75
|
+
RenderStyleFunction,
|
|
76
|
+
BlockStyleRenderProps,
|
|
77
|
+
RenderListItemFunction,
|
|
78
|
+
RenderDecoratorFunction,
|
|
79
|
+
ScrollSelectionIntoViewFunction,
|
|
80
|
+
RangeDecorationOnMovedDetails,
|
|
81
|
+
RangeDecoration,
|
|
82
|
+
PortableTextMemberSchemaTypes,
|
|
83
|
+
} from './types/editor'
|
|
48
84
|
export type {HotkeyOptions} from './types/options'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type {EditorSnapshot} from '..'
|
|
1
2
|
import {compileSchemaDefinition, defineSchema} from '../editor/define-schema'
|
|
2
|
-
import type {EditorSnapshot} from '../selectors'
|
|
3
3
|
import {createTestKeyGenerator} from './test-key-generator'
|
|
4
4
|
|
|
5
5
|
export function createTestSnapshot(snapshot: {
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
import {createDecoratorPairBehavior} from '../behaviors/behavior.decorator-pair'
|
|
11
11
|
import {defineBehavior} from '../behaviors/behavior.types'
|
|
12
12
|
import type {Editor} from '../editor/create-editor'
|
|
13
|
+
import type {EditorSchema} from '../editor/define-schema'
|
|
13
14
|
import {useEditor} from '../editor/editor-provider'
|
|
14
|
-
import type {EditorSchema} from '../selectors'
|
|
15
15
|
import type {BlockOffset} from '../types/block-offset'
|
|
16
16
|
import * as utils from '../utils'
|
|
17
17
|
|
package/src/selectors/index.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
export type {EditorSchema} from '../editor/define-schema'
|
|
2
|
-
export type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
export type {EditorContext, EditorSnapshot} from '../editor/editor-snapshot'
|
|
4
|
-
export type {
|
|
5
|
-
EditorSelection,
|
|
6
|
-
EditorSelectionPoint,
|
|
7
|
-
PortableTextMemberSchemaTypes,
|
|
8
|
-
} from '../types/editor'
|
|
9
1
|
export {getActiveAnnotations} from './selector.get-active-annotations'
|
|
10
2
|
export {getActiveListItem} from './selector.get-active-list-item'
|
|
11
3
|
export {getActiveStyle} from './selector.get-active-style'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import {expect, test} from 'vitest'
|
|
3
|
+
import type {EditorSelection} from '..'
|
|
3
4
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
4
|
-
import type {EditorSelection} from '../utils'
|
|
5
5
|
import {getActiveAnnotations} from './selector.get-active-annotations'
|
|
6
6
|
|
|
7
7
|
function snapshot(value: Array<PortableTextBlock>, selection: EditorSelection) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import {describe, expect, test} from 'vitest'
|
|
3
|
+
import type {EditorSelection} from '..'
|
|
3
4
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
4
5
|
import {createTestKeyGenerator} from '../internal-utils/test-key-generator'
|
|
5
|
-
import type {EditorSelection} from '../utils'
|
|
6
6
|
import {getCaretWordSelection} from './selector.get-caret-word-selection'
|
|
7
7
|
|
|
8
8
|
const keyGenerator = createTestKeyGenerator()
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import {describe, expect, test} from 'vitest'
|
|
3
|
-
import
|
|
3
|
+
import type {EditorSelection} from '..'
|
|
4
4
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
5
|
+
import {getSelectedSpans} from './selector.get-selected-spans'
|
|
5
6
|
|
|
6
7
|
const fooBar = {
|
|
7
8
|
_type: 'block',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import {expect, test} from 'vitest'
|
|
3
|
-
import type {EditorSelection} from '
|
|
3
|
+
import type {EditorSelection} from '..'
|
|
4
4
|
import {compileSchemaDefinition, defineSchema} from '../editor/define-schema'
|
|
5
5
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
6
6
|
import {getSelectionText} from './selector.get-selection-text'
|
package/src/types/editor.ts
CHANGED
|
@@ -24,11 +24,7 @@ import type {
|
|
|
24
24
|
RefObject,
|
|
25
25
|
} from 'react'
|
|
26
26
|
import type {Observable, Subject} from 'rxjs'
|
|
27
|
-
import type {
|
|
28
|
-
Descendant,
|
|
29
|
-
Node as SlateNode,
|
|
30
|
-
Operation as SlateOperation,
|
|
31
|
-
} from 'slate'
|
|
27
|
+
import type {Descendant, Operation as SlateOperation} from 'slate'
|
|
32
28
|
import type {DOMNode} from 'slate-dom'
|
|
33
29
|
import type {ReactEditor} from 'slate-react'
|
|
34
30
|
import type {PortableTextEditableProps} from '../editor/Editable'
|
|
@@ -97,18 +93,12 @@ export interface EditableAPI {
|
|
|
97
93
|
undo: () => void
|
|
98
94
|
}
|
|
99
95
|
|
|
100
|
-
|
|
101
|
-
export type EditorNode = SlateNode & {
|
|
102
|
-
_key: string
|
|
103
|
-
_type: string
|
|
104
|
-
}
|
|
105
|
-
/** @internal */
|
|
106
|
-
export type HistoryItem = {
|
|
96
|
+
type HistoryItem = {
|
|
107
97
|
operations: SlateOperation[]
|
|
108
98
|
timestamp: Date
|
|
109
99
|
}
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
|
|
101
|
+
interface History {
|
|
112
102
|
redos: HistoryItem[]
|
|
113
103
|
undos: HistoryItem[]
|
|
114
104
|
}
|
|
@@ -121,7 +111,7 @@ export type EditorSelection = {
|
|
|
121
111
|
focus: EditorSelectionPoint
|
|
122
112
|
backward?: boolean
|
|
123
113
|
} | null
|
|
124
|
-
|
|
114
|
+
|
|
125
115
|
export interface PortableTextSlateEditor extends ReactEditor {
|
|
126
116
|
_key: 'editor'
|
|
127
117
|
_type: 'editor'
|
|
@@ -528,7 +518,7 @@ export interface RangeDecoration {
|
|
|
528
518
|
payload?: Record<string, unknown>
|
|
529
519
|
}
|
|
530
520
|
|
|
531
|
-
/** @
|
|
521
|
+
/** @beta */
|
|
532
522
|
export type PortableTextMemberSchemaTypes = {
|
|
533
523
|
annotations: (ObjectSchemaType & {i18nTitleKey?: string})[]
|
|
534
524
|
block: ObjectSchemaType
|
package/src/types/slate.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
|
|
2
2
|
import type {BaseEditor, Descendant} from 'slate'
|
|
3
3
|
import type {ReactEditor} from 'slate-react'
|
|
4
|
-
import type {PortableTextSlateEditor} from '
|
|
4
|
+
import type {PortableTextSlateEditor} from './editor'
|
|
5
5
|
|
|
6
6
|
export interface VoidElement {
|
|
7
7
|
_type: string
|
package/src/utils/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
|
-
import type {EditorSelection} from '
|
|
2
|
+
import type {EditorSelection} from '..'
|
|
3
3
|
import type {BlockOffset} from '../types/block-offset'
|
|
4
4
|
import {blockOffsetToSpanSelectionPoint} from './util.block-offset'
|
|
5
5
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type {PortableTextTextBlock} from '@sanity/types'
|
|
2
|
-
import
|
|
3
|
-
import type {EditorContext} from '../
|
|
2
|
+
import type {EditorSelectionPoint} from '..'
|
|
3
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
4
4
|
import {isSpan} from './util.is-span'
|
|
5
|
+
import {isTextBlock} from './util.is-text-block'
|
|
6
|
+
import {sliceBlocks} from './util.slice-blocks'
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* @beta
|