@portabletext/editor 1.10.1 → 1.10.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/index.d.mts +91 -855
- package/lib/index.d.ts +91 -855
- package/lib/index.esm.js +6 -64
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +5 -63
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +6 -64
- package/lib/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/editor/PortableTextEditor.tsx +2 -2
- package/src/editor/components/Synchronizer.tsx +0 -23
- package/src/editor/editor-machine.ts +0 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"is-hotkey-esm": "^1.0.0",
|
|
50
50
|
"lodash": "^4.17.21",
|
|
51
51
|
"lodash.startcase": "^4.4.0",
|
|
52
|
-
"react-compiler-runtime": "19.0.0-beta-
|
|
52
|
+
"react-compiler-runtime": "19.0.0-beta-0dec889-20241115",
|
|
53
53
|
"slate": "0.110.2",
|
|
54
54
|
"slate-dom": "^0.111.0",
|
|
55
55
|
"slate-react": "0.111.0",
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
"@typescript-eslint/parser": "^8.14.0",
|
|
75
75
|
"@vitejs/plugin-react": "^4.3.3",
|
|
76
76
|
"@vitest/browser": "^2.1.5",
|
|
77
|
-
"babel-plugin-react-compiler": "19.0.0-beta-
|
|
77
|
+
"babel-plugin-react-compiler": "19.0.0-beta-0dec889-20241115",
|
|
78
78
|
"eslint": "8.57.1",
|
|
79
|
-
"eslint-plugin-react-compiler": "19.0.0-beta-
|
|
79
|
+
"eslint-plugin-react-compiler": "19.0.0-beta-0dec889-20241115",
|
|
80
80
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
81
81
|
"jsdom": "^25.0.1",
|
|
82
82
|
"react": "^18.3.1",
|
|
@@ -50,7 +50,7 @@ const debug = debugWithName('component:PortableTextEditor')
|
|
|
50
50
|
export type PortableTextEditorProps<
|
|
51
51
|
TEditor extends Editor | undefined = undefined,
|
|
52
52
|
> = PropsWithChildren<
|
|
53
|
-
|
|
53
|
+
TEditor extends Editor
|
|
54
54
|
? {
|
|
55
55
|
/**
|
|
56
56
|
* @alpha
|
|
@@ -104,7 +104,7 @@ export type PortableTextEditorProps<
|
|
|
104
104
|
* A ref to the editor instance
|
|
105
105
|
*/
|
|
106
106
|
editorRef?: MutableRefObject<PortableTextEditor | null>
|
|
107
|
-
}
|
|
107
|
+
}
|
|
108
108
|
>
|
|
109
109
|
|
|
110
110
|
/**
|
|
@@ -125,14 +125,6 @@ export function Synchronizer(props: SynchronizerProps) {
|
|
|
125
125
|
handleChange({type: 'focus', event: event.event})
|
|
126
126
|
break
|
|
127
127
|
}
|
|
128
|
-
case 'offline': {
|
|
129
|
-
handleChange({type: 'connection', value: 'offline'})
|
|
130
|
-
break
|
|
131
|
-
}
|
|
132
|
-
case 'online': {
|
|
133
|
-
handleChange({type: 'connection', value: 'online'})
|
|
134
|
-
break
|
|
135
|
-
}
|
|
136
128
|
case 'value changed': {
|
|
137
129
|
handleChange({type: 'value', value: event.value})
|
|
138
130
|
break
|
|
@@ -168,21 +160,6 @@ export function Synchronizer(props: SynchronizerProps) {
|
|
|
168
160
|
}
|
|
169
161
|
}, [editorActor, handleChange, onFlushPendingPatches, slateEditor])
|
|
170
162
|
|
|
171
|
-
// Sync the value when going online
|
|
172
|
-
const handleOnline = useCallback(() => {
|
|
173
|
-
debug('Editor is online, syncing from props.value')
|
|
174
|
-
syncValue(value)
|
|
175
|
-
}, [syncValue, value])
|
|
176
|
-
|
|
177
|
-
// Notify about window online and offline status changes
|
|
178
|
-
useEffect(() => {
|
|
179
|
-
const subscription = editorActor.on('online', handleOnline)
|
|
180
|
-
|
|
181
|
-
return () => {
|
|
182
|
-
subscription.unsubscribe()
|
|
183
|
-
}
|
|
184
|
-
}, [handleOnline, editorActor])
|
|
185
|
-
|
|
186
163
|
// This hook must be set up after setting up the subscription above, or it will not pick up validation errors from the useSyncValue hook.
|
|
187
164
|
// This will cause the editor to not be able to signal a validation error and offer invalid value resolution of the initial value.
|
|
188
165
|
const isInitialValueFromProps = useRef(true)
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
assign,
|
|
8
8
|
emit,
|
|
9
9
|
enqueueActions,
|
|
10
|
-
fromCallback,
|
|
11
10
|
setup,
|
|
12
11
|
type ActorRefFrom,
|
|
13
12
|
} from 'xstate'
|
|
@@ -38,27 +37,6 @@ export * from 'xstate/guards'
|
|
|
38
37
|
*/
|
|
39
38
|
export type EditorActor = ActorRefFrom<typeof editorMachine>
|
|
40
39
|
|
|
41
|
-
const networkLogic = fromCallback(({sendBack}) => {
|
|
42
|
-
const onlineHandler = () => {
|
|
43
|
-
sendBack({type: 'online'})
|
|
44
|
-
}
|
|
45
|
-
const offlineHandler = () => {
|
|
46
|
-
sendBack({type: 'offline'})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (window) {
|
|
50
|
-
window.addEventListener('online', onlineHandler)
|
|
51
|
-
window.addEventListener('offline', offlineHandler)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return () => {
|
|
55
|
-
if (window) {
|
|
56
|
-
window.removeEventListener('online', onlineHandler)
|
|
57
|
-
window.removeEventListener('offline', offlineHandler)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
40
|
/**
|
|
63
41
|
* @internal
|
|
64
42
|
*/
|
|
@@ -149,8 +127,6 @@ export type InternalEditorEmittedEvent =
|
|
|
149
127
|
| {type: 'selection'; selection: EditorSelection}
|
|
150
128
|
| {type: 'blur'; event: FocusEvent<HTMLDivElement, Element>}
|
|
151
129
|
| {type: 'focused'; event: FocusEvent<HTMLDivElement, Element>}
|
|
152
|
-
| {type: 'online'}
|
|
153
|
-
| {type: 'offline'}
|
|
154
130
|
| {type: 'loading'}
|
|
155
131
|
| {type: 'done loading'}
|
|
156
132
|
| PickFromUnion<
|
|
@@ -313,9 +289,6 @@ export const editorMachine = setup({
|
|
|
313
289
|
}
|
|
314
290
|
}),
|
|
315
291
|
},
|
|
316
|
-
actors: {
|
|
317
|
-
networkLogic,
|
|
318
|
-
},
|
|
319
292
|
}).createMachine({
|
|
320
293
|
id: 'editor',
|
|
321
294
|
context: ({input}) => ({
|
|
@@ -327,10 +300,6 @@ export const editorMachine = setup({
|
|
|
327
300
|
maxBlocks: undefined,
|
|
328
301
|
value: input.value,
|
|
329
302
|
}),
|
|
330
|
-
invoke: {
|
|
331
|
-
id: 'networkLogic',
|
|
332
|
-
src: 'networkLogic',
|
|
333
|
-
},
|
|
334
303
|
on: {
|
|
335
304
|
'annotation.add': {
|
|
336
305
|
actions: emit(({event}) => event),
|
|
@@ -356,8 +325,6 @@ export const editorMachine = setup({
|
|
|
356
325
|
'selection': {actions: emit(({event}) => event)},
|
|
357
326
|
'blur': {actions: emit(({event}) => event)},
|
|
358
327
|
'focused': {actions: emit(({event}) => event)},
|
|
359
|
-
'online': {actions: emit({type: 'online'})},
|
|
360
|
-
'offline': {actions: emit({type: 'offline'})},
|
|
361
328
|
'loading': {actions: emit({type: 'loading'})},
|
|
362
329
|
'patches': {actions: emit(({event}) => event)},
|
|
363
330
|
'done loading': {actions: emit({type: 'done loading'})},
|