@portabletext/editor 1.49.11 → 1.49.13

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.
@@ -811,6 +811,12 @@ declare const editorMachine: StateMachine<
811
811
  | {
812
812
  type: 'editable'
813
813
  }
814
+ | {
815
+ type: 'error'
816
+ name: string
817
+ description: string
818
+ data: unknown
819
+ }
814
820
  | {
815
821
  type: 'focused'
816
822
  event: FocusEvent_2<HTMLDivElement, Element>
@@ -1235,6 +1241,142 @@ declare const editorMachine: StateMachine<
1235
1241
  never,
1236
1242
  never
1237
1243
  >,
1244
+ ActionFunction<
1245
+ {
1246
+ behaviors: Set<BehaviorConfig>
1247
+ converters: Set<Converter>
1248
+ getLegacySchema: () => PortableTextMemberSchemaTypes
1249
+ keyGenerator: () => string
1250
+ pendingEvents: Array<InternalPatchEvent | MutationEvent>
1251
+ pendingIncomingPatchesEvents: Array<PatchesEvent>
1252
+ schema: EditorSchema
1253
+ initialReadOnly: boolean
1254
+ maxBlocks: number | undefined
1255
+ selection: EditorSelection
1256
+ initialValue: Array<PortableTextBlock> | undefined
1257
+ internalDrag?: {
1258
+ ghost?: HTMLElement
1259
+ origin: Pick<EventPosition, 'selection'>
1260
+ }
1261
+ slateEditor?: PortableTextSlateEditor
1262
+ },
1263
+ {
1264
+ type: 'update selection'
1265
+ selection: EditorSelection
1266
+ },
1267
+ | InternalPatchEvent
1268
+ | MutationEvent
1269
+ | PatchesEvent
1270
+ | {
1271
+ type: 'update readOnly'
1272
+ readOnly: boolean
1273
+ }
1274
+ | {
1275
+ type: 'update maxBlocks'
1276
+ maxBlocks: number | undefined
1277
+ }
1278
+ | {
1279
+ type: 'add behavior'
1280
+ behaviorConfig: BehaviorConfig
1281
+ }
1282
+ | {
1283
+ type: 'remove behavior'
1284
+ behaviorConfig: BehaviorConfig
1285
+ }
1286
+ | {
1287
+ type: 'blur'
1288
+ editor: PortableTextSlateEditor
1289
+ }
1290
+ | {
1291
+ type: 'focus'
1292
+ editor: PortableTextSlateEditor
1293
+ }
1294
+ | {
1295
+ type: 'normalizing'
1296
+ }
1297
+ | {
1298
+ type: 'update selection'
1299
+ selection: EditorSelection
1300
+ }
1301
+ | {
1302
+ type: 'done normalizing'
1303
+ }
1304
+ | {
1305
+ type: 'done syncing value'
1306
+ }
1307
+ | {
1308
+ type: 'syncing value'
1309
+ }
1310
+ | {
1311
+ type: 'behavior event'
1312
+ behaviorEvent: BehaviorEvent
1313
+ editor: PortableTextSlateEditor
1314
+ nativeEvent?: {
1315
+ preventDefault: () => void
1316
+ }
1317
+ }
1318
+ | {
1319
+ type: 'dragstart'
1320
+ origin: Pick<EventPosition, 'selection'>
1321
+ ghost?: HTMLElement
1322
+ }
1323
+ | {
1324
+ type: 'dragend'
1325
+ }
1326
+ | {
1327
+ type: 'drop'
1328
+ },
1329
+ undefined,
1330
+ never,
1331
+ never,
1332
+ never,
1333
+ never,
1334
+ | InternalPatchEvent
1335
+ | MutationEvent
1336
+ | PatchesEvent
1337
+ | {
1338
+ type: 'blurred'
1339
+ event: FocusEvent_2<HTMLDivElement, Element>
1340
+ }
1341
+ | {
1342
+ type: 'done loading'
1343
+ }
1344
+ | {
1345
+ type: 'editable'
1346
+ }
1347
+ | {
1348
+ type: 'error'
1349
+ name: string
1350
+ description: string
1351
+ data: unknown
1352
+ }
1353
+ | {
1354
+ type: 'focused'
1355
+ event: FocusEvent_2<HTMLDivElement, Element>
1356
+ }
1357
+ | {
1358
+ type: 'invalid value'
1359
+ resolution: InvalidValueResolution | null
1360
+ value: Array<PortableTextBlock> | undefined
1361
+ }
1362
+ | {
1363
+ type: 'loading'
1364
+ }
1365
+ | {
1366
+ type: 'read only'
1367
+ }
1368
+ | {
1369
+ type: 'ready'
1370
+ }
1371
+ | {
1372
+ type: 'selection'
1373
+ selection: EditorSelection
1374
+ }
1375
+ | {
1376
+ type: 'value changed'
1377
+ value: Array<PortableTextBlock> | undefined
1378
+ }
1379
+ >,
1238
1380
  ]
1239
1381
  }
1240
1382
  }
@@ -2087,6 +2229,12 @@ declare const editorMachine: StateMachine<
2087
2229
  | {
2088
2230
  type: 'editable'
2089
2231
  }
2232
+ | {
2233
+ type: 'error'
2234
+ name: string
2235
+ description: string
2236
+ data: unknown
2237
+ }
2090
2238
  | {
2091
2239
  type: 'focused'
2092
2240
  event: FocusEvent_2<HTMLDivElement, Element>
@@ -811,6 +811,12 @@ declare const editorMachine: StateMachine<
811
811
  | {
812
812
  type: 'editable'
813
813
  }
814
+ | {
815
+ type: 'error'
816
+ name: string
817
+ description: string
818
+ data: unknown
819
+ }
814
820
  | {
815
821
  type: 'focused'
816
822
  event: FocusEvent_2<HTMLDivElement, Element>
@@ -1235,6 +1241,142 @@ declare const editorMachine: StateMachine<
1235
1241
  never,
1236
1242
  never
1237
1243
  >,
1244
+ ActionFunction<
1245
+ {
1246
+ behaviors: Set<BehaviorConfig>
1247
+ converters: Set<Converter>
1248
+ getLegacySchema: () => PortableTextMemberSchemaTypes
1249
+ keyGenerator: () => string
1250
+ pendingEvents: Array<InternalPatchEvent | MutationEvent>
1251
+ pendingIncomingPatchesEvents: Array<PatchesEvent>
1252
+ schema: EditorSchema
1253
+ initialReadOnly: boolean
1254
+ maxBlocks: number | undefined
1255
+ selection: EditorSelection
1256
+ initialValue: Array<PortableTextBlock> | undefined
1257
+ internalDrag?: {
1258
+ ghost?: HTMLElement
1259
+ origin: Pick<EventPosition, 'selection'>
1260
+ }
1261
+ slateEditor?: PortableTextSlateEditor
1262
+ },
1263
+ {
1264
+ type: 'update selection'
1265
+ selection: EditorSelection
1266
+ },
1267
+ | InternalPatchEvent
1268
+ | MutationEvent
1269
+ | PatchesEvent
1270
+ | {
1271
+ type: 'update readOnly'
1272
+ readOnly: boolean
1273
+ }
1274
+ | {
1275
+ type: 'update maxBlocks'
1276
+ maxBlocks: number | undefined
1277
+ }
1278
+ | {
1279
+ type: 'add behavior'
1280
+ behaviorConfig: BehaviorConfig
1281
+ }
1282
+ | {
1283
+ type: 'remove behavior'
1284
+ behaviorConfig: BehaviorConfig
1285
+ }
1286
+ | {
1287
+ type: 'blur'
1288
+ editor: PortableTextSlateEditor
1289
+ }
1290
+ | {
1291
+ type: 'focus'
1292
+ editor: PortableTextSlateEditor
1293
+ }
1294
+ | {
1295
+ type: 'normalizing'
1296
+ }
1297
+ | {
1298
+ type: 'update selection'
1299
+ selection: EditorSelection
1300
+ }
1301
+ | {
1302
+ type: 'done normalizing'
1303
+ }
1304
+ | {
1305
+ type: 'done syncing value'
1306
+ }
1307
+ | {
1308
+ type: 'syncing value'
1309
+ }
1310
+ | {
1311
+ type: 'behavior event'
1312
+ behaviorEvent: BehaviorEvent
1313
+ editor: PortableTextSlateEditor
1314
+ nativeEvent?: {
1315
+ preventDefault: () => void
1316
+ }
1317
+ }
1318
+ | {
1319
+ type: 'dragstart'
1320
+ origin: Pick<EventPosition, 'selection'>
1321
+ ghost?: HTMLElement
1322
+ }
1323
+ | {
1324
+ type: 'dragend'
1325
+ }
1326
+ | {
1327
+ type: 'drop'
1328
+ },
1329
+ undefined,
1330
+ never,
1331
+ never,
1332
+ never,
1333
+ never,
1334
+ | InternalPatchEvent
1335
+ | MutationEvent
1336
+ | PatchesEvent
1337
+ | {
1338
+ type: 'blurred'
1339
+ event: FocusEvent_2<HTMLDivElement, Element>
1340
+ }
1341
+ | {
1342
+ type: 'done loading'
1343
+ }
1344
+ | {
1345
+ type: 'editable'
1346
+ }
1347
+ | {
1348
+ type: 'error'
1349
+ name: string
1350
+ description: string
1351
+ data: unknown
1352
+ }
1353
+ | {
1354
+ type: 'focused'
1355
+ event: FocusEvent_2<HTMLDivElement, Element>
1356
+ }
1357
+ | {
1358
+ type: 'invalid value'
1359
+ resolution: InvalidValueResolution | null
1360
+ value: Array<PortableTextBlock> | undefined
1361
+ }
1362
+ | {
1363
+ type: 'loading'
1364
+ }
1365
+ | {
1366
+ type: 'read only'
1367
+ }
1368
+ | {
1369
+ type: 'ready'
1370
+ }
1371
+ | {
1372
+ type: 'selection'
1373
+ selection: EditorSelection
1374
+ }
1375
+ | {
1376
+ type: 'value changed'
1377
+ value: Array<PortableTextBlock> | undefined
1378
+ }
1379
+ >,
1238
1380
  ]
1239
1381
  }
1240
1382
  }
@@ -2087,6 +2229,12 @@ declare const editorMachine: StateMachine<
2087
2229
  | {
2088
2230
  type: 'editable'
2089
2231
  }
2232
+ | {
2233
+ type: 'error'
2234
+ name: string
2235
+ description: string
2236
+ data: unknown
2237
+ }
2090
2238
  | {
2091
2239
  type: 'focused'
2092
2240
  event: FocusEvent_2<HTMLDivElement, Element>
package/lib/index.cjs CHANGED
@@ -4569,7 +4569,7 @@ function createWithPortableTextBlockStyle(editorActor) {
4569
4569
  };
4570
4570
  }
4571
4571
  debugWithName("plugin:withPortableTextSelections");
4572
- function createWithPortableTextSelections(editorActor, relayActor) {
4572
+ function createWithPortableTextSelections(editorActor) {
4573
4573
  let prevSelection = null;
4574
4574
  return function(editor) {
4575
4575
  const emitPortableTextSelection = () => {
@@ -4583,11 +4583,11 @@ function createWithPortableTextSelections(editorActor, relayActor) {
4583
4583
  range: editor.selection
4584
4584
  }), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange));
4585
4585
  }
4586
- ptRange ? relayActor.send({
4587
- type: "selection",
4586
+ ptRange ? editorActor.send({
4587
+ type: "update selection",
4588
4588
  selection: ptRange
4589
- }) : relayActor.send({
4590
- type: "selection",
4589
+ }) : editorActor.send({
4590
+ type: "update selection",
4591
4591
  selection: null
4592
4592
  });
4593
4593
  }
@@ -4691,7 +4691,7 @@ const withPlugins = (editor, options) => {
4691
4691
  subscriptions: options.subscriptions
4692
4692
  }), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
4693
4693
  editorActor
4694
- }), withPortableTextSelections = createWithPortableTextSelections(editorActor, relayActor);
4694
+ }), withPortableTextSelections = createWithPortableTextSelections(editorActor);
4695
4695
  return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
4696
4696
  }, debug$a = debugWithName("setup");
4697
4697
  function createSlateEditor(config) {
@@ -6736,7 +6736,12 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
6736
6736
  selection: ({
6737
6737
  event
6738
6738
  }) => event.selection
6739
- })]
6739
+ }), xstate.emit(({
6740
+ event
6741
+ }) => ({
6742
+ ...event,
6743
+ type: "selection"
6744
+ }))]
6740
6745
  }
6741
6746
  },
6742
6747
  type: "parallel",
@@ -8908,16 +8913,6 @@ function createActors(config) {
8908
8913
  return () => {
8909
8914
  subscription.unsubscribe();
8910
8915
  };
8911
- }), config.subscriptions.push(() => {
8912
- const subscription = config.relayActor.on("*", (event) => {
8913
- event.type === "selection" && config.editorActor.send({
8914
- type: "update selection",
8915
- selection: event.selection
8916
- });
8917
- });
8918
- return () => {
8919
- subscription.unsubscribe();
8920
- };
8921
8916
  }), config.subscriptions.push(() => {
8922
8917
  const subscription = syncActor.on("*", (event) => {
8923
8918
  switch (event.type) {
@@ -8969,6 +8964,7 @@ function createActors(config) {
8969
8964
  case "mutation":
8970
8965
  case "ready":
8971
8966
  case "read only":
8967
+ case "selection":
8972
8968
  config.relayActor.send(event);
8973
8969
  break;
8974
8970
  case "internal.patch":
@@ -10033,13 +10029,13 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10033
10029
  if (normalizedSelection !== null) {
10034
10030
  debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
10035
10031
  const slateRange = toSlateRange(normalizedSelection, slateEditor);
10036
- slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") || relayActor.send({
10037
- type: "selection",
10032
+ slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") || editorActor.send({
10033
+ type: "update selection",
10038
10034
  selection: normalizedSelection
10039
10035
  }), slateEditor.onChange());
10040
10036
  }
10041
10037
  }
10042
- }, [editorActor, propsSelection, relayActor, slateEditor]);
10038
+ }, [editorActor, propsSelection, slateEditor]);
10043
10039
  React.useEffect(() => {
10044
10040
  const onReady = editorActor.on("ready", () => {
10045
10041
  rangeDecorationsActor.send({
@@ -10201,12 +10197,12 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10201
10197
  event: event_2
10202
10198
  });
10203
10199
  const newSelection = PortableTextEditor.getSelection(portableTextEditor);
10204
- selection_3 === newSelection && relayActor.send({
10205
- type: "selection",
10200
+ selection_3 === newSelection && editorActor.send({
10201
+ type: "update selection",
10206
10202
  selection: selection_3
10207
10203
  });
10208
10204
  }
10209
- }, [onFocus, slateEditor, portableTextEditor, relayActor]), handleClick = React.useCallback((event_3) => {
10205
+ }, [editorActor, onFocus, slateEditor, portableTextEditor, relayActor]), handleClick = React.useCallback((event_3) => {
10210
10206
  if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
10211
10207
  return;
10212
10208
  const position_3 = getEventPosition({