@portabletext/editor 1.45.2 → 1.45.4
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.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +57 -57
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +4 -1
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +57 -57
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +4 -1
- package/lib/_chunks-es/parse-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +26 -36
- package/lib/behaviors/index.d.ts +26 -36
- package/lib/index.d.cts +26 -36
- package/lib/index.d.ts +26 -36
- package/lib/plugins/index.d.cts +26 -36
- package/lib/plugins/index.d.ts +26 -36
- package/lib/selectors/index.d.cts +26 -36
- package/lib/selectors/index.d.ts +26 -36
- package/lib/utils/index.d.cts +26 -36
- package/lib/utils/index.d.ts +26 -36
- package/package.json +6 -6
- package/src/behaviors/behavior.perform-event.ts +14 -16
- package/src/behaviors/behavior.types.action.ts +1 -6
- package/src/behaviors/behavior.types.guard.ts +1 -6
- package/src/editor/components/Synchronizer.tsx +6 -3
- package/src/editor/create-editor.ts +1 -1
- package/src/editor/editor-machine.ts +6 -4
- package/src/internal-utils/parse-blocks.ts +6 -1
|
@@ -25,7 +25,10 @@ export interface SynchronizerProps {
|
|
|
25
25
|
export function Synchronizer(props: SynchronizerProps) {
|
|
26
26
|
const {editorActor, slateEditor} = props
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const incomingValue = useSelector(
|
|
29
|
+
props.editorActor,
|
|
30
|
+
(s) => s.context.incomingValue,
|
|
31
|
+
)
|
|
29
32
|
const readOnly = useSelector(props.editorActor, (s) =>
|
|
30
33
|
s.matches({'edit mode': 'read only'}),
|
|
31
34
|
)
|
|
@@ -110,8 +113,8 @@ export function Synchronizer(props: SynchronizerProps) {
|
|
|
110
113
|
|
|
111
114
|
useEffect(() => {
|
|
112
115
|
debug('Value from props changed, syncing new value')
|
|
113
|
-
syncActorRef.send({type: 'update value', value})
|
|
114
|
-
}, [syncActorRef,
|
|
116
|
+
syncActorRef.send({type: 'update value', value: incomingValue})
|
|
117
|
+
}, [syncActorRef, incomingValue])
|
|
115
118
|
|
|
116
119
|
// Subscribe to, and handle changes from the editor
|
|
117
120
|
useEffect(() => {
|
|
@@ -213,7 +213,7 @@ export const editorMachine = setup({
|
|
|
213
213
|
initialReadOnly: boolean
|
|
214
214
|
maxBlocks: number | undefined
|
|
215
215
|
selection: EditorSelection
|
|
216
|
-
|
|
216
|
+
incomingValue: Array<PortableTextBlock> | undefined
|
|
217
217
|
internalDrag?: {
|
|
218
218
|
ghost?: HTMLElement
|
|
219
219
|
origin: Pick<EventPosition, 'selection'>
|
|
@@ -228,7 +228,7 @@ export const editorMachine = setup({
|
|
|
228
228
|
maxBlocks?: number
|
|
229
229
|
readOnly?: boolean
|
|
230
230
|
schema: EditorSchema
|
|
231
|
-
|
|
231
|
+
initialValue?: Array<PortableTextBlock>
|
|
232
232
|
},
|
|
233
233
|
tags: {} as 'dragging internally',
|
|
234
234
|
},
|
|
@@ -331,7 +331,7 @@ export const editorMachine = setup({
|
|
|
331
331
|
selection: null,
|
|
332
332
|
initialReadOnly: input.readOnly ?? false,
|
|
333
333
|
maxBlocks: input.maxBlocks,
|
|
334
|
-
|
|
334
|
+
incomingValue: input.initialValue,
|
|
335
335
|
}),
|
|
336
336
|
on: {
|
|
337
337
|
'notify.blurred': {
|
|
@@ -365,7 +365,9 @@ export const editorMachine = setup({
|
|
|
365
365
|
actions: assign({keyGenerator: ({event}) => event.keyGenerator}),
|
|
366
366
|
},
|
|
367
367
|
'update schema': {actions: 'assign schema'},
|
|
368
|
-
'update value': {
|
|
368
|
+
'update value': {
|
|
369
|
+
actions: assign({incomingValue: ({event}) => event.value}),
|
|
370
|
+
},
|
|
369
371
|
'update maxBlocks': {
|
|
370
372
|
actions: assign({maxBlocks: ({event}) => event.maxBlocks}),
|
|
371
373
|
},
|
|
@@ -369,7 +369,12 @@ function parseObject({
|
|
|
369
369
|
// the name of a field
|
|
370
370
|
const values = context.schemaType.fields.reduce<Record<string, unknown>>(
|
|
371
371
|
(fieldValues, field) => {
|
|
372
|
-
|
|
372
|
+
const fieldValue = object[field.name]
|
|
373
|
+
|
|
374
|
+
if (fieldValue !== undefined) {
|
|
375
|
+
fieldValues[field.name] = fieldValue
|
|
376
|
+
}
|
|
377
|
+
|
|
373
378
|
return fieldValues
|
|
374
379
|
},
|
|
375
380
|
{},
|