@portabletext/editor 1.16.2 → 1.16.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.16.2",
3
+ "version": "1.16.3",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -61,7 +61,7 @@
61
61
  "get-random-values-esm": "^1.0.2",
62
62
  "lodash": "^4.17.21",
63
63
  "lodash.startcase": "^4.4.0",
64
- "react-compiler-runtime": "19.0.0-beta-37ed2a7-20241206",
64
+ "react-compiler-runtime": "19.0.0-beta-201e55d-20241215",
65
65
  "slate": "0.112.0",
66
66
  "slate-dom": "^0.111.0",
67
67
  "slate-react": "0.112.0",
@@ -87,9 +87,9 @@
87
87
  "@vitejs/plugin-react": "^4.3.4",
88
88
  "@vitest/browser": "^2.1.8",
89
89
  "@vitest/coverage-istanbul": "^2.1.8",
90
- "babel-plugin-react-compiler": "19.0.0-beta-37ed2a7-20241206",
90
+ "babel-plugin-react-compiler": "19.0.0-beta-201e55d-20241215",
91
91
  "eslint": "8.57.1",
92
- "eslint-plugin-react-compiler": "19.0.0-beta-37ed2a7-20241206",
92
+ "eslint-plugin-react-compiler": "19.0.0-beta-201e55d-20241215",
93
93
  "eslint-plugin-react-hooks": "^5.1.0",
94
94
  "jsdom": "^25.0.1",
95
95
  "react": "^19.0.0",
@@ -23,7 +23,6 @@ import {
23
23
  } from '../editor/plugins/createWithPortableTextMarkModel'
24
24
  import {blockOffsetToSpanSelectionPoint} from '../editor/utils/utils.block-offset'
25
25
  import type {PickFromUnion} from '../type-utils'
26
- import debug from '../utils/debug'
27
26
  import {toSlatePath} from '../utils/paths'
28
27
  import {toSlateRange} from '../utils/ranges'
29
28
  import {fromSlateValue, toSlateValue} from '../utils/values'
@@ -283,8 +282,6 @@ export function performAction({
283
282
  context: BehaviorActionImplementationContext
284
283
  action: BehaviorAction
285
284
  }) {
286
- debug('Behavior action', action)
287
-
288
285
  switch (action.type) {
289
286
  case 'delete.block': {
290
287
  behaviorActionImplementations['delete.block']({
@@ -25,7 +25,6 @@ import type {
25
25
  InvalidValueResolution,
26
26
  PortableTextSlateEditor,
27
27
  } from '../types/editor'
28
- import debug from '../utils/debug'
29
28
  import {toPortableTextRange} from '../utils/ranges'
30
29
  import {fromSlateValue} from '../utils/values'
31
30
  import {KEY_TO_VALUE_ELEMENT} from '../utils/weakMaps'
@@ -69,7 +68,7 @@ export type MutationEvent = {
69
68
  export type InternalEditorEvent =
70
69
  | {type: 'normalizing'}
71
70
  | {type: 'done normalizing'}
72
- | {type: 'done syncing'}
71
+ | {type: 'done syncing initial value'}
73
72
  | {
74
73
  type: 'behavior event'
75
74
  behaviorEvent: SyntheticBehaviorEvent | NativeBehaviorEvent
@@ -101,7 +100,11 @@ export type InternalEditorEvent =
101
100
  type: 'update maxBlocks'
102
101
  maxBlocks: number | undefined
103
102
  }
104
- | OmitFromUnion<InternalEditorEmittedEvent, 'type', 'read only' | 'editable'>
103
+ | OmitFromUnion<
104
+ InternalEditorEmittedEvent,
105
+ 'type',
106
+ 'ready' | 'read only' | 'editable'
107
+ >
105
108
 
106
109
  /**
107
110
  * @alpha
@@ -242,8 +245,6 @@ export const editorMachine = setup({
242
245
  'handle behavior event': enqueueActions(({context, event, enqueue}) => {
243
246
  assertEvent(event, ['behavior event'])
244
247
 
245
- debug('Behavior event', event)
246
-
247
248
  const defaultAction =
248
249
  event.behaviorEvent.type === 'copy' ||
249
250
  event.behaviorEvent.type === 'key.down' ||
@@ -427,7 +428,7 @@ export const editorMachine = setup({
427
428
  states: {
428
429
  'determine initial edit mode': {
429
430
  on: {
430
- 'done syncing': [
431
+ 'done syncing initial value': [
431
432
  {
432
433
  target: '#editor.edit mode.read only.read only',
433
434
  guard: ({context}) => context.initialReadOnly,
@@ -502,7 +503,7 @@ export const editorMachine = setup({
502
503
  'mutation': {
503
504
  actions: 'defer event',
504
505
  },
505
- 'done syncing': {
506
+ 'done syncing initial value': {
506
507
  target: 'pristine',
507
508
  },
508
509
  },
@@ -3,13 +3,10 @@ import type {PortableTextBlock} from '@sanity/types'
3
3
  import {isEqual} from 'lodash'
4
4
  import {Editor, Text, Transforms, type Descendant, type Node} from 'slate'
5
5
  import {
6
- and,
7
6
  assertEvent,
8
7
  assign,
9
8
  emit,
10
9
  fromCallback,
11
- not,
12
- or,
13
10
  setup,
14
11
  type AnyEventObject,
15
12
  type CallbackLogicFunction,
@@ -118,11 +115,13 @@ export const syncMachine = setup({
118
115
  readOnly: boolean
119
116
  }
120
117
  | SyncValueEvent,
121
- emitted: {} as PickFromUnion<
122
- SyncValueEvent,
123
- 'type',
124
- 'done syncing' | 'invalid value' | 'patch' | 'value changed'
125
- >,
118
+ emitted: {} as
119
+ | PickFromUnion<
120
+ SyncValueEvent,
121
+ 'type',
122
+ 'invalid value' | 'patch' | 'value changed'
123
+ >
124
+ | {type: 'done syncing initial value'},
126
125
  },
127
126
  actions: {
128
127
  'assign initial value synced': assign({
@@ -149,21 +148,19 @@ export const syncMachine = setup({
149
148
  return event.value
150
149
  },
151
150
  }),
152
- 'emit done syncing': emit(({event}) => {
153
- assertEvent(event, 'done syncing')
154
- return event
151
+ 'emit done syncing initial value': emit({
152
+ type: 'done syncing initial value',
155
153
  }),
156
154
  },
157
155
  guards: {
158
- 'is readOnly': ({context}) => context.readOnly,
159
- 'is processing local changes': ({context}) =>
160
- context.isProcessingLocalChanges,
161
- 'is processing remote changes': ({context}) =>
162
- isChangingRemotely(context.slateEditor) ?? false,
163
- 'is busy': and([
164
- not('is readOnly'),
165
- or(['is processing local changes', 'is processing remote changes']),
166
- ]),
156
+ 'initial value synced': ({context}) => context.initialValueSynced,
157
+ 'is busy': ({context}) => {
158
+ return (
159
+ !context.readOnly &&
160
+ (context.isProcessingLocalChanges ||
161
+ (isChangingRemotely(context.slateEditor) ?? false))
162
+ )
163
+ },
167
164
  'value changed while syncing': ({context, event}) => {
168
165
  assertEvent(event, 'done syncing')
169
166
  return context.pendingValue !== event.value
@@ -189,7 +186,6 @@ export const syncMachine = setup({
189
186
  pendingValue: undefined,
190
187
  previousValue: undefined,
191
188
  }),
192
- initial: 'idle',
193
189
  on: {
194
190
  'has pending patches': {
195
191
  actions: assign({
@@ -205,103 +201,117 @@ export const syncMachine = setup({
205
201
  actions: ['assign readOnly'],
206
202
  },
207
203
  },
204
+ type: 'parallel',
208
205
  states: {
209
- idle: {
210
- on: {
211
- 'update value': [
212
- {
213
- guard: 'is busy',
214
- target: 'busy',
215
- actions: ['assign pending value'],
216
- },
217
- {
218
- target: 'syncing',
219
- actions: ['assign pending value'],
206
+ 'setting up': {
207
+ initial: 'syncing initial value',
208
+ states: {
209
+ 'syncing initial value': {
210
+ always: {
211
+ guard: 'initial value synced',
212
+ target: 'done syncing initial value',
220
213
  },
221
- ],
222
- },
223
- },
224
- busy: {
225
- after: {
226
- 1000: {
227
- target: 'syncing',
228
214
  },
229
- },
230
- on: {
231
- 'update value': [
232
- {
233
- guard: 'is busy',
234
- actions: ['assign pending value'],
235
- reenter: true,
236
- },
237
- {
238
- target: 'syncing',
239
- actions: ['assign pending value'],
240
- },
241
- ],
242
- },
243
- },
244
- syncing: {
245
- invoke: {
246
- src: 'sync value',
247
- id: 'sync value',
248
- input: ({context}) => {
249
- return {
250
- context: {
251
- keyGenerator: context.keyGenerator,
252
- previousValue: context.previousValue,
253
- readOnly: context.readOnly,
254
- schema: context.schema,
255
- },
256
- slateEditor: context.slateEditor,
257
- streamBlocks: !context.initialValueSynced,
258
- value: context.pendingValue ?? undefined,
259
- }
215
+ 'done syncing initial value': {
216
+ entry: ['emit done syncing initial value'],
217
+ type: 'final',
260
218
  },
261
219
  },
262
- always: {
263
- guard: 'pending value equals previous value',
264
- actions: [
265
- emit(({context}) => ({
266
- type: 'done syncing',
267
- value: context.previousValue,
268
- })),
269
- ],
270
- target: 'idle',
271
- },
272
- on: {
273
- 'update value': {
274
- actions: ['assign pending value'],
275
- },
276
- 'patch': {
277
- actions: [emit(({event}) => event)],
278
- },
279
- 'invalid value': {
280
- actions: [emit(({event}) => event)],
281
- },
282
- 'value changed': {
283
- actions: [emit(({event}) => event)],
220
+ },
221
+ 'syncing': {
222
+ initial: 'idle',
223
+ states: {
224
+ idle: {
225
+ on: {
226
+ 'update value': [
227
+ {
228
+ guard: 'is busy',
229
+ target: 'busy',
230
+ actions: ['assign pending value'],
231
+ },
232
+ {
233
+ target: 'syncing',
234
+ actions: ['assign pending value'],
235
+ },
236
+ ],
237
+ },
284
238
  },
285
- 'done syncing': [
286
- {
287
- guard: 'value changed while syncing',
288
- actions: [
289
- 'assign previous value',
290
- 'emit done syncing',
291
- 'assign initial value synced',
239
+ busy: {
240
+ after: {
241
+ 1000: [
242
+ {
243
+ guard: 'is busy',
244
+ reenter: true,
245
+ },
246
+ {
247
+ target: 'syncing',
248
+ },
249
+ ],
250
+ },
251
+ on: {
252
+ 'update value': [
253
+ {
254
+ actions: ['assign pending value'],
255
+ },
292
256
  ],
293
- reenter: true,
294
257
  },
295
- {
258
+ },
259
+ syncing: {
260
+ always: {
261
+ guard: 'pending value equals previous value',
296
262
  target: 'idle',
297
- actions: [
298
- 'clear pending value',
299
- 'assign previous value',
300
- 'emit done syncing',
301
- 'assign initial value synced',
263
+ actions: ['clear pending value', 'assign initial value synced'],
264
+ },
265
+ invoke: {
266
+ src: 'sync value',
267
+ id: 'sync value',
268
+ input: ({context}) => {
269
+ return {
270
+ context: {
271
+ keyGenerator: context.keyGenerator,
272
+ previousValue: context.previousValue,
273
+ readOnly: context.readOnly,
274
+ schema: context.schema,
275
+ },
276
+ slateEditor: context.slateEditor,
277
+ streamBlocks: !context.initialValueSynced,
278
+ value: context.pendingValue,
279
+ }
280
+ },
281
+ },
282
+ on: {
283
+ 'update value': {
284
+ actions: ['assign pending value'],
285
+ },
286
+ 'patch': {
287
+ actions: [emit(({event}) => event)],
288
+ },
289
+ 'invalid value': {
290
+ actions: [emit(({event}) => event)],
291
+ },
292
+ 'value changed': {
293
+ actions: [emit(({event}) => event)],
294
+ },
295
+ 'done syncing': [
296
+ {
297
+ guard: 'value changed while syncing',
298
+ actions: [
299
+ 'assign previous value',
300
+ 'assign initial value synced',
301
+ ],
302
+ reenter: true,
303
+ },
304
+ {
305
+ target: 'idle',
306
+ actions: [
307
+ 'clear pending value',
308
+ 'assign previous value',
309
+ 'assign initial value synced',
310
+ ],
311
+ },
302
312
  ],
303
313
  },
304
- ],
314
+ },
305
315
  },
306
316
  },
307
317
  },