@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.
@@ -25,7 +25,10 @@ export interface SynchronizerProps {
25
25
  export function Synchronizer(props: SynchronizerProps) {
26
26
  const {editorActor, slateEditor} = props
27
27
 
28
- const value = useSelector(props.editorActor, (s) => s.context.value)
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, value])
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(() => {
@@ -116,7 +116,7 @@ function editorConfigToMachineInput(config: EditorConfig) {
116
116
  ? config.schema
117
117
  : compileType(config.schema),
118
118
  ),
119
- value: config.initialValue,
119
+ initialValue: config.initialValue,
120
120
  } as const
121
121
  }
122
122
 
@@ -213,7 +213,7 @@ export const editorMachine = setup({
213
213
  initialReadOnly: boolean
214
214
  maxBlocks: number | undefined
215
215
  selection: EditorSelection
216
- value: Array<PortableTextBlock> | undefined
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
- value?: Array<PortableTextBlock>
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
- value: input.value,
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': {actions: assign({value: ({event}) => event.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
- fieldValues[field.name] = object[field.name]
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
  {},