@portabletext/editor 1.16.0 → 1.16.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/index.cjs +25 -18
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +154 -87
- package/lib/index.d.ts +154 -87
- package/lib/index.js +25 -18
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/PortableTextEditor.tsx +2 -1
- package/src/editor/components/Synchronizer.tsx +1 -1
- package/src/editor/create-editor.ts +4 -1
- package/src/editor/editor-machine.ts +8 -5
- package/src/editor/sync-machine.ts +7 -3
package/package.json
CHANGED
|
@@ -173,7 +173,8 @@ export class PortableTextEditor extends Component<
|
|
|
173
173
|
if (!this.props.editor && !prevProps.editor) {
|
|
174
174
|
if (this.props.readOnly !== prevProps.readOnly) {
|
|
175
175
|
this.editor._internal.editorActor.send({
|
|
176
|
-
type: '
|
|
176
|
+
type: 'update readOnly',
|
|
177
|
+
readOnly: this.props.readOnly ?? false,
|
|
177
178
|
})
|
|
178
179
|
}
|
|
179
180
|
|
|
@@ -71,7 +71,7 @@ export function Synchronizer(props: SynchronizerProps) {
|
|
|
71
71
|
}, [props.editorActor, syncActorRef])
|
|
72
72
|
|
|
73
73
|
useEffect(() => {
|
|
74
|
-
syncActorRef.send({type: '
|
|
74
|
+
syncActorRef.send({type: 'update readOnly', readOnly})
|
|
75
75
|
}, [syncActorRef, readOnly])
|
|
76
76
|
|
|
77
77
|
useEffect(() => {
|
|
@@ -33,6 +33,9 @@ import {createEditableAPI} from './plugins/createWithEditableAPI'
|
|
|
33
33
|
export type EditorConfig = {
|
|
34
34
|
behaviors?: Array<Behavior>
|
|
35
35
|
keyGenerator?: () => string
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Will be removed in the next major version
|
|
38
|
+
*/
|
|
36
39
|
maxBlocks?: number
|
|
37
40
|
readOnly?: boolean
|
|
38
41
|
initialValue?: Array<PortableTextBlock>
|
|
@@ -64,8 +67,8 @@ export type EditorEvent = PickFromUnion<
|
|
|
64
67
|
| 'list item.toggle'
|
|
65
68
|
| 'style.toggle'
|
|
66
69
|
| 'patches'
|
|
67
|
-
| 'toggle readOnly'
|
|
68
70
|
| 'update behaviors'
|
|
71
|
+
| 'update readOnly'
|
|
69
72
|
| 'update value'
|
|
70
73
|
>
|
|
71
74
|
|
|
@@ -81,6 +81,10 @@ export type InternalEditorEvent =
|
|
|
81
81
|
editor: PortableTextSlateEditor
|
|
82
82
|
actionIntends: Array<BehaviorActionIntend>
|
|
83
83
|
}
|
|
84
|
+
| {
|
|
85
|
+
type: 'update readOnly'
|
|
86
|
+
readOnly: boolean
|
|
87
|
+
}
|
|
84
88
|
| {
|
|
85
89
|
type: 'update schema'
|
|
86
90
|
schema: EditorSchema
|
|
@@ -93,9 +97,6 @@ export type InternalEditorEvent =
|
|
|
93
97
|
type: 'update value'
|
|
94
98
|
value: Array<PortableTextBlock> | undefined
|
|
95
99
|
}
|
|
96
|
-
| {
|
|
97
|
-
type: 'toggle readOnly'
|
|
98
|
-
}
|
|
99
100
|
| {
|
|
100
101
|
type: 'update maxBlocks'
|
|
101
102
|
maxBlocks: number | undefined
|
|
@@ -439,7 +440,8 @@ export const editorMachine = setup({
|
|
|
439
440
|
},
|
|
440
441
|
'read only': {
|
|
441
442
|
on: {
|
|
442
|
-
'
|
|
443
|
+
'update readOnly': {
|
|
444
|
+
guard: ({event}) => !event.readOnly,
|
|
443
445
|
target: '#editor.edit mode.editable',
|
|
444
446
|
actions: ['emit editable'],
|
|
445
447
|
},
|
|
@@ -449,7 +451,8 @@ export const editorMachine = setup({
|
|
|
449
451
|
},
|
|
450
452
|
'editable': {
|
|
451
453
|
on: {
|
|
452
|
-
'
|
|
454
|
+
'update readOnly': {
|
|
455
|
+
guard: ({event}) => event.readOnly,
|
|
453
456
|
target: '#editor.edit mode.read only.read only',
|
|
454
457
|
actions: ['emit read only'],
|
|
455
458
|
},
|
|
@@ -111,7 +111,8 @@ export const syncMachine = setup({
|
|
|
111
111
|
value: Array<PortableTextBlock> | undefined
|
|
112
112
|
}
|
|
113
113
|
| {
|
|
114
|
-
type: '
|
|
114
|
+
type: 'update readOnly'
|
|
115
|
+
readOnly: boolean
|
|
115
116
|
}
|
|
116
117
|
| SyncValueEvent,
|
|
117
118
|
emitted: {} as PickFromUnion<
|
|
@@ -122,7 +123,10 @@ export const syncMachine = setup({
|
|
|
122
123
|
},
|
|
123
124
|
actions: {
|
|
124
125
|
'assign readOnly': assign({
|
|
125
|
-
readOnly: ({
|
|
126
|
+
readOnly: ({event}) => {
|
|
127
|
+
assertEvent(event, 'update readOnly')
|
|
128
|
+
return event.readOnly
|
|
129
|
+
},
|
|
126
130
|
}),
|
|
127
131
|
'assign pending value': assign({
|
|
128
132
|
pendingValue: ({event}) => {
|
|
@@ -190,7 +194,7 @@ export const syncMachine = setup({
|
|
|
190
194
|
isProcessingLocalChanges: false,
|
|
191
195
|
}),
|
|
192
196
|
},
|
|
193
|
-
'
|
|
197
|
+
'update readOnly': {
|
|
194
198
|
actions: ['assign readOnly'],
|
|
195
199
|
},
|
|
196
200
|
},
|