@portabletext/editor 1.49.12 → 1.50.0

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.
@@ -1241,6 +1241,142 @@ declare const editorMachine: StateMachine<
1241
1241
  never,
1242
1242
  never
1243
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
+ >,
1244
1380
  ]
1245
1381
  }
1246
1382
  }
@@ -1241,6 +1241,142 @@ declare const editorMachine: StateMachine<
1241
1241
  never,
1242
1242
  never
1243
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
+ >,
1244
1380
  ]
1245
1381
  }
1246
1382
  }
package/lib/index.cjs CHANGED
@@ -950,7 +950,13 @@ function RenderTextBlock(props) {
950
950
  schemaType: legacyListItemSchemaType
951
951
  }) : console.error(`Unable to find Schema type for text block list item ${props.textBlock.listItem}`);
952
952
  }
953
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...props.attributes, className: ["pt-block", "pt-text-block", ...props.textBlock.style ? [`pt-text-block-style-${props.textBlock.style}`] : [], ...props.textBlock.listItem ? ["pt-list-item", `pt-list-item-${props.textBlock.listItem}`, `pt-list-item-level-${props.textBlock.level ?? 1}`] : []].join(" "), spellCheck: props.spellCheck, "data-block-key": props.textBlock._key, "data-block-name": props.textBlock._type, "data-block-type": "text", children: [
953
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...props.attributes, className: ["pt-block", "pt-text-block", ...props.textBlock.style ? [`pt-text-block-style-${props.textBlock.style}`] : [], ...props.textBlock.listItem ? ["pt-list-item", `pt-list-item-${props.textBlock.listItem}`, `pt-list-item-level-${props.textBlock.level ?? 1}`] : []].join(" "), spellCheck: props.spellCheck, "data-block-key": props.textBlock._key, "data-block-name": props.textBlock._type, "data-block-type": "text", ...props.textBlock.listItem !== void 0 ? {
954
+ "data-list-item": props.textBlock.listItem
955
+ } : {}, ...props.textBlock.level !== void 0 ? {
956
+ "data-level": props.textBlock.level
957
+ } : {}, ...props.textBlock.style !== void 0 ? {
958
+ "data-style": props.textBlock.style
959
+ } : {}, children: [
954
960
  dragPositionBlock === "start" ? /* @__PURE__ */ jsxRuntime.jsx(DropIndicator, {}) : null,
955
961
  /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, children: props.renderBlock ? props.renderBlock({
956
962
  children,
@@ -4569,7 +4575,7 @@ function createWithPortableTextBlockStyle(editorActor) {
4569
4575
  };
4570
4576
  }
4571
4577
  debugWithName("plugin:withPortableTextSelections");
4572
- function createWithPortableTextSelections(editorActor, relayActor) {
4578
+ function createWithPortableTextSelections(editorActor) {
4573
4579
  let prevSelection = null;
4574
4580
  return function(editor) {
4575
4581
  const emitPortableTextSelection = () => {
@@ -4583,11 +4589,11 @@ function createWithPortableTextSelections(editorActor, relayActor) {
4583
4589
  range: editor.selection
4584
4590
  }), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange));
4585
4591
  }
4586
- ptRange ? relayActor.send({
4587
- type: "selection",
4592
+ ptRange ? editorActor.send({
4593
+ type: "update selection",
4588
4594
  selection: ptRange
4589
- }) : relayActor.send({
4590
- type: "selection",
4595
+ }) : editorActor.send({
4596
+ type: "update selection",
4591
4597
  selection: null
4592
4598
  });
4593
4599
  }
@@ -4691,7 +4697,7 @@ const withPlugins = (editor, options) => {
4691
4697
  subscriptions: options.subscriptions
4692
4698
  }), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
4693
4699
  editorActor
4694
- }), withPortableTextSelections = createWithPortableTextSelections(editorActor, relayActor);
4700
+ }), withPortableTextSelections = createWithPortableTextSelections(editorActor);
4695
4701
  return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
4696
4702
  }, debug$a = debugWithName("setup");
4697
4703
  function createSlateEditor(config) {
@@ -6736,7 +6742,12 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
6736
6742
  selection: ({
6737
6743
  event
6738
6744
  }) => event.selection
6739
- })]
6745
+ }), xstate.emit(({
6746
+ event
6747
+ }) => ({
6748
+ ...event,
6749
+ type: "selection"
6750
+ }))]
6740
6751
  }
6741
6752
  },
6742
6753
  type: "parallel",
@@ -8908,16 +8919,6 @@ function createActors(config) {
8908
8919
  return () => {
8909
8920
  subscription.unsubscribe();
8910
8921
  };
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
8922
  }), config.subscriptions.push(() => {
8922
8923
  const subscription = syncActor.on("*", (event) => {
8923
8924
  switch (event.type) {
@@ -8969,6 +8970,7 @@ function createActors(config) {
8969
8970
  case "mutation":
8970
8971
  case "ready":
8971
8972
  case "read only":
8973
+ case "selection":
8972
8974
  config.relayActor.send(event);
8973
8975
  break;
8974
8976
  case "internal.patch":
@@ -10033,13 +10035,13 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10033
10035
  if (normalizedSelection !== null) {
10034
10036
  debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
10035
10037
  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",
10038
+ slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") || editorActor.send({
10039
+ type: "update selection",
10038
10040
  selection: normalizedSelection
10039
10041
  }), slateEditor.onChange());
10040
10042
  }
10041
10043
  }
10042
- }, [editorActor, propsSelection, relayActor, slateEditor]);
10044
+ }, [editorActor, propsSelection, slateEditor]);
10043
10045
  React.useEffect(() => {
10044
10046
  const onReady = editorActor.on("ready", () => {
10045
10047
  rangeDecorationsActor.send({
@@ -10201,12 +10203,12 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10201
10203
  event: event_2
10202
10204
  });
10203
10205
  const newSelection = PortableTextEditor.getSelection(portableTextEditor);
10204
- selection_3 === newSelection && relayActor.send({
10205
- type: "selection",
10206
+ selection_3 === newSelection && editorActor.send({
10207
+ type: "update selection",
10206
10208
  selection: selection_3
10207
10209
  });
10208
10210
  }
10209
- }, [onFocus, slateEditor, portableTextEditor, relayActor]), handleClick = React.useCallback((event_3) => {
10211
+ }, [editorActor, onFocus, slateEditor, portableTextEditor, relayActor]), handleClick = React.useCallback((event_3) => {
10210
10212
  if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
10211
10213
  return;
10212
10214
  const position_3 = getEventPosition({