@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.
- package/lib/behaviors/index.d.cts +148 -0
- package/lib/behaviors/index.d.ts +148 -0
- package/lib/index.cjs +19 -23
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +159 -0
- package/lib/index.d.ts +159 -0
- package/lib/index.js +19 -23
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +159 -0
- package/lib/plugins/index.d.ts +159 -0
- package/lib/selectors/index.d.cts +148 -0
- package/lib/selectors/index.d.ts +148 -0
- package/lib/utils/index.d.cts +148 -0
- package/lib/utils/index.d.ts +148 -0
- package/package.json +3 -3
- package/src/editor/Editable.tsx +6 -6
- package/src/editor/__tests__/self-solving.test.tsx +9 -9
- package/src/editor/create-editor.ts +1 -15
- package/src/editor/editor-machine.ts +4 -1
- package/src/editor/plugins/createWithPortableTextSelections.ts +2 -4
- package/src/editor/plugins/with-plugins.ts +2 -4
- package/src/editor/relay-machine.ts +11 -0
package/lib/selectors/index.d.ts
CHANGED
|
@@ -780,6 +780,12 @@ declare const editorMachine: StateMachine<
|
|
|
780
780
|
| {
|
|
781
781
|
type: 'editable'
|
|
782
782
|
}
|
|
783
|
+
| {
|
|
784
|
+
type: 'error'
|
|
785
|
+
name: string
|
|
786
|
+
description: string
|
|
787
|
+
data: unknown
|
|
788
|
+
}
|
|
783
789
|
| {
|
|
784
790
|
type: 'focused'
|
|
785
791
|
event: FocusEvent_2<HTMLDivElement, Element>
|
|
@@ -1204,6 +1210,142 @@ declare const editorMachine: StateMachine<
|
|
|
1204
1210
|
never,
|
|
1205
1211
|
never
|
|
1206
1212
|
>,
|
|
1213
|
+
ActionFunction<
|
|
1214
|
+
{
|
|
1215
|
+
behaviors: Set<BehaviorConfig>
|
|
1216
|
+
converters: Set<Converter>
|
|
1217
|
+
getLegacySchema: () => PortableTextMemberSchemaTypes
|
|
1218
|
+
keyGenerator: () => string
|
|
1219
|
+
pendingEvents: Array<InternalPatchEvent | MutationEvent>
|
|
1220
|
+
pendingIncomingPatchesEvents: Array<PatchesEvent>
|
|
1221
|
+
schema: EditorSchema
|
|
1222
|
+
initialReadOnly: boolean
|
|
1223
|
+
maxBlocks: number | undefined
|
|
1224
|
+
selection: EditorSelection
|
|
1225
|
+
initialValue: Array<PortableTextBlock> | undefined
|
|
1226
|
+
internalDrag?: {
|
|
1227
|
+
ghost?: HTMLElement
|
|
1228
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1229
|
+
}
|
|
1230
|
+
slateEditor?: PortableTextSlateEditor
|
|
1231
|
+
},
|
|
1232
|
+
{
|
|
1233
|
+
type: 'update selection'
|
|
1234
|
+
selection: EditorSelection
|
|
1235
|
+
},
|
|
1236
|
+
| InternalPatchEvent
|
|
1237
|
+
| MutationEvent
|
|
1238
|
+
| PatchesEvent
|
|
1239
|
+
| {
|
|
1240
|
+
type: 'update readOnly'
|
|
1241
|
+
readOnly: boolean
|
|
1242
|
+
}
|
|
1243
|
+
| {
|
|
1244
|
+
type: 'update maxBlocks'
|
|
1245
|
+
maxBlocks: number | undefined
|
|
1246
|
+
}
|
|
1247
|
+
| {
|
|
1248
|
+
type: 'add behavior'
|
|
1249
|
+
behaviorConfig: BehaviorConfig
|
|
1250
|
+
}
|
|
1251
|
+
| {
|
|
1252
|
+
type: 'remove behavior'
|
|
1253
|
+
behaviorConfig: BehaviorConfig
|
|
1254
|
+
}
|
|
1255
|
+
| {
|
|
1256
|
+
type: 'blur'
|
|
1257
|
+
editor: PortableTextSlateEditor
|
|
1258
|
+
}
|
|
1259
|
+
| {
|
|
1260
|
+
type: 'focus'
|
|
1261
|
+
editor: PortableTextSlateEditor
|
|
1262
|
+
}
|
|
1263
|
+
| {
|
|
1264
|
+
type: 'normalizing'
|
|
1265
|
+
}
|
|
1266
|
+
| {
|
|
1267
|
+
type: 'update selection'
|
|
1268
|
+
selection: EditorSelection
|
|
1269
|
+
}
|
|
1270
|
+
| {
|
|
1271
|
+
type: 'done normalizing'
|
|
1272
|
+
}
|
|
1273
|
+
| {
|
|
1274
|
+
type: 'done syncing value'
|
|
1275
|
+
}
|
|
1276
|
+
| {
|
|
1277
|
+
type: 'syncing value'
|
|
1278
|
+
}
|
|
1279
|
+
| {
|
|
1280
|
+
type: 'behavior event'
|
|
1281
|
+
behaviorEvent: BehaviorEvent
|
|
1282
|
+
editor: PortableTextSlateEditor
|
|
1283
|
+
nativeEvent?: {
|
|
1284
|
+
preventDefault: () => void
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
| {
|
|
1288
|
+
type: 'dragstart'
|
|
1289
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1290
|
+
ghost?: HTMLElement
|
|
1291
|
+
}
|
|
1292
|
+
| {
|
|
1293
|
+
type: 'dragend'
|
|
1294
|
+
}
|
|
1295
|
+
| {
|
|
1296
|
+
type: 'drop'
|
|
1297
|
+
},
|
|
1298
|
+
undefined,
|
|
1299
|
+
never,
|
|
1300
|
+
never,
|
|
1301
|
+
never,
|
|
1302
|
+
never,
|
|
1303
|
+
| InternalPatchEvent
|
|
1304
|
+
| MutationEvent
|
|
1305
|
+
| PatchesEvent
|
|
1306
|
+
| {
|
|
1307
|
+
type: 'blurred'
|
|
1308
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1309
|
+
}
|
|
1310
|
+
| {
|
|
1311
|
+
type: 'done loading'
|
|
1312
|
+
}
|
|
1313
|
+
| {
|
|
1314
|
+
type: 'editable'
|
|
1315
|
+
}
|
|
1316
|
+
| {
|
|
1317
|
+
type: 'error'
|
|
1318
|
+
name: string
|
|
1319
|
+
description: string
|
|
1320
|
+
data: unknown
|
|
1321
|
+
}
|
|
1322
|
+
| {
|
|
1323
|
+
type: 'focused'
|
|
1324
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1325
|
+
}
|
|
1326
|
+
| {
|
|
1327
|
+
type: 'invalid value'
|
|
1328
|
+
resolution: InvalidValueResolution | null
|
|
1329
|
+
value: Array<PortableTextBlock> | undefined
|
|
1330
|
+
}
|
|
1331
|
+
| {
|
|
1332
|
+
type: 'loading'
|
|
1333
|
+
}
|
|
1334
|
+
| {
|
|
1335
|
+
type: 'read only'
|
|
1336
|
+
}
|
|
1337
|
+
| {
|
|
1338
|
+
type: 'ready'
|
|
1339
|
+
}
|
|
1340
|
+
| {
|
|
1341
|
+
type: 'selection'
|
|
1342
|
+
selection: EditorSelection
|
|
1343
|
+
}
|
|
1344
|
+
| {
|
|
1345
|
+
type: 'value changed'
|
|
1346
|
+
value: Array<PortableTextBlock> | undefined
|
|
1347
|
+
}
|
|
1348
|
+
>,
|
|
1207
1349
|
]
|
|
1208
1350
|
}
|
|
1209
1351
|
}
|
|
@@ -2056,6 +2198,12 @@ declare const editorMachine: StateMachine<
|
|
|
2056
2198
|
| {
|
|
2057
2199
|
type: 'editable'
|
|
2058
2200
|
}
|
|
2201
|
+
| {
|
|
2202
|
+
type: 'error'
|
|
2203
|
+
name: string
|
|
2204
|
+
description: string
|
|
2205
|
+
data: unknown
|
|
2206
|
+
}
|
|
2059
2207
|
| {
|
|
2060
2208
|
type: 'focused'
|
|
2061
2209
|
event: FocusEvent_2<HTMLDivElement, Element>
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -850,6 +850,12 @@ declare const editorMachine: StateMachine<
|
|
|
850
850
|
| {
|
|
851
851
|
type: 'editable'
|
|
852
852
|
}
|
|
853
|
+
| {
|
|
854
|
+
type: 'error'
|
|
855
|
+
name: string
|
|
856
|
+
description: string
|
|
857
|
+
data: unknown
|
|
858
|
+
}
|
|
853
859
|
| {
|
|
854
860
|
type: 'focused'
|
|
855
861
|
event: FocusEvent_2<HTMLDivElement, Element>
|
|
@@ -1274,6 +1280,142 @@ declare const editorMachine: StateMachine<
|
|
|
1274
1280
|
never,
|
|
1275
1281
|
never
|
|
1276
1282
|
>,
|
|
1283
|
+
ActionFunction<
|
|
1284
|
+
{
|
|
1285
|
+
behaviors: Set<BehaviorConfig>
|
|
1286
|
+
converters: Set<Converter>
|
|
1287
|
+
getLegacySchema: () => PortableTextMemberSchemaTypes
|
|
1288
|
+
keyGenerator: () => string
|
|
1289
|
+
pendingEvents: Array<InternalPatchEvent | MutationEvent>
|
|
1290
|
+
pendingIncomingPatchesEvents: Array<PatchesEvent>
|
|
1291
|
+
schema: EditorSchema
|
|
1292
|
+
initialReadOnly: boolean
|
|
1293
|
+
maxBlocks: number | undefined
|
|
1294
|
+
selection: EditorSelection
|
|
1295
|
+
initialValue: Array<PortableTextBlock> | undefined
|
|
1296
|
+
internalDrag?: {
|
|
1297
|
+
ghost?: HTMLElement
|
|
1298
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1299
|
+
}
|
|
1300
|
+
slateEditor?: PortableTextSlateEditor
|
|
1301
|
+
},
|
|
1302
|
+
{
|
|
1303
|
+
type: 'update selection'
|
|
1304
|
+
selection: EditorSelection
|
|
1305
|
+
},
|
|
1306
|
+
| InternalPatchEvent
|
|
1307
|
+
| MutationEvent
|
|
1308
|
+
| PatchesEvent
|
|
1309
|
+
| {
|
|
1310
|
+
type: 'update readOnly'
|
|
1311
|
+
readOnly: boolean
|
|
1312
|
+
}
|
|
1313
|
+
| {
|
|
1314
|
+
type: 'update maxBlocks'
|
|
1315
|
+
maxBlocks: number | undefined
|
|
1316
|
+
}
|
|
1317
|
+
| {
|
|
1318
|
+
type: 'add behavior'
|
|
1319
|
+
behaviorConfig: BehaviorConfig
|
|
1320
|
+
}
|
|
1321
|
+
| {
|
|
1322
|
+
type: 'remove behavior'
|
|
1323
|
+
behaviorConfig: BehaviorConfig
|
|
1324
|
+
}
|
|
1325
|
+
| {
|
|
1326
|
+
type: 'blur'
|
|
1327
|
+
editor: PortableTextSlateEditor
|
|
1328
|
+
}
|
|
1329
|
+
| {
|
|
1330
|
+
type: 'focus'
|
|
1331
|
+
editor: PortableTextSlateEditor
|
|
1332
|
+
}
|
|
1333
|
+
| {
|
|
1334
|
+
type: 'normalizing'
|
|
1335
|
+
}
|
|
1336
|
+
| {
|
|
1337
|
+
type: 'update selection'
|
|
1338
|
+
selection: EditorSelection
|
|
1339
|
+
}
|
|
1340
|
+
| {
|
|
1341
|
+
type: 'done normalizing'
|
|
1342
|
+
}
|
|
1343
|
+
| {
|
|
1344
|
+
type: 'done syncing value'
|
|
1345
|
+
}
|
|
1346
|
+
| {
|
|
1347
|
+
type: 'syncing value'
|
|
1348
|
+
}
|
|
1349
|
+
| {
|
|
1350
|
+
type: 'behavior event'
|
|
1351
|
+
behaviorEvent: BehaviorEvent
|
|
1352
|
+
editor: PortableTextSlateEditor
|
|
1353
|
+
nativeEvent?: {
|
|
1354
|
+
preventDefault: () => void
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
| {
|
|
1358
|
+
type: 'dragstart'
|
|
1359
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1360
|
+
ghost?: HTMLElement
|
|
1361
|
+
}
|
|
1362
|
+
| {
|
|
1363
|
+
type: 'dragend'
|
|
1364
|
+
}
|
|
1365
|
+
| {
|
|
1366
|
+
type: 'drop'
|
|
1367
|
+
},
|
|
1368
|
+
undefined,
|
|
1369
|
+
never,
|
|
1370
|
+
never,
|
|
1371
|
+
never,
|
|
1372
|
+
never,
|
|
1373
|
+
| InternalPatchEvent
|
|
1374
|
+
| MutationEvent
|
|
1375
|
+
| PatchesEvent
|
|
1376
|
+
| {
|
|
1377
|
+
type: 'blurred'
|
|
1378
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1379
|
+
}
|
|
1380
|
+
| {
|
|
1381
|
+
type: 'done loading'
|
|
1382
|
+
}
|
|
1383
|
+
| {
|
|
1384
|
+
type: 'editable'
|
|
1385
|
+
}
|
|
1386
|
+
| {
|
|
1387
|
+
type: 'error'
|
|
1388
|
+
name: string
|
|
1389
|
+
description: string
|
|
1390
|
+
data: unknown
|
|
1391
|
+
}
|
|
1392
|
+
| {
|
|
1393
|
+
type: 'focused'
|
|
1394
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1395
|
+
}
|
|
1396
|
+
| {
|
|
1397
|
+
type: 'invalid value'
|
|
1398
|
+
resolution: InvalidValueResolution | null
|
|
1399
|
+
value: Array<PortableTextBlock> | undefined
|
|
1400
|
+
}
|
|
1401
|
+
| {
|
|
1402
|
+
type: 'loading'
|
|
1403
|
+
}
|
|
1404
|
+
| {
|
|
1405
|
+
type: 'read only'
|
|
1406
|
+
}
|
|
1407
|
+
| {
|
|
1408
|
+
type: 'ready'
|
|
1409
|
+
}
|
|
1410
|
+
| {
|
|
1411
|
+
type: 'selection'
|
|
1412
|
+
selection: EditorSelection
|
|
1413
|
+
}
|
|
1414
|
+
| {
|
|
1415
|
+
type: 'value changed'
|
|
1416
|
+
value: Array<PortableTextBlock> | undefined
|
|
1417
|
+
}
|
|
1418
|
+
>,
|
|
1277
1419
|
]
|
|
1278
1420
|
}
|
|
1279
1421
|
}
|
|
@@ -2126,6 +2268,12 @@ declare const editorMachine: StateMachine<
|
|
|
2126
2268
|
| {
|
|
2127
2269
|
type: 'editable'
|
|
2128
2270
|
}
|
|
2271
|
+
| {
|
|
2272
|
+
type: 'error'
|
|
2273
|
+
name: string
|
|
2274
|
+
description: string
|
|
2275
|
+
data: unknown
|
|
2276
|
+
}
|
|
2129
2277
|
| {
|
|
2130
2278
|
type: 'focused'
|
|
2131
2279
|
event: FocusEvent_2<HTMLDivElement, Element>
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -850,6 +850,12 @@ declare const editorMachine: StateMachine<
|
|
|
850
850
|
| {
|
|
851
851
|
type: 'editable'
|
|
852
852
|
}
|
|
853
|
+
| {
|
|
854
|
+
type: 'error'
|
|
855
|
+
name: string
|
|
856
|
+
description: string
|
|
857
|
+
data: unknown
|
|
858
|
+
}
|
|
853
859
|
| {
|
|
854
860
|
type: 'focused'
|
|
855
861
|
event: FocusEvent_2<HTMLDivElement, Element>
|
|
@@ -1274,6 +1280,142 @@ declare const editorMachine: StateMachine<
|
|
|
1274
1280
|
never,
|
|
1275
1281
|
never
|
|
1276
1282
|
>,
|
|
1283
|
+
ActionFunction<
|
|
1284
|
+
{
|
|
1285
|
+
behaviors: Set<BehaviorConfig>
|
|
1286
|
+
converters: Set<Converter>
|
|
1287
|
+
getLegacySchema: () => PortableTextMemberSchemaTypes
|
|
1288
|
+
keyGenerator: () => string
|
|
1289
|
+
pendingEvents: Array<InternalPatchEvent | MutationEvent>
|
|
1290
|
+
pendingIncomingPatchesEvents: Array<PatchesEvent>
|
|
1291
|
+
schema: EditorSchema
|
|
1292
|
+
initialReadOnly: boolean
|
|
1293
|
+
maxBlocks: number | undefined
|
|
1294
|
+
selection: EditorSelection
|
|
1295
|
+
initialValue: Array<PortableTextBlock> | undefined
|
|
1296
|
+
internalDrag?: {
|
|
1297
|
+
ghost?: HTMLElement
|
|
1298
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1299
|
+
}
|
|
1300
|
+
slateEditor?: PortableTextSlateEditor
|
|
1301
|
+
},
|
|
1302
|
+
{
|
|
1303
|
+
type: 'update selection'
|
|
1304
|
+
selection: EditorSelection
|
|
1305
|
+
},
|
|
1306
|
+
| InternalPatchEvent
|
|
1307
|
+
| MutationEvent
|
|
1308
|
+
| PatchesEvent
|
|
1309
|
+
| {
|
|
1310
|
+
type: 'update readOnly'
|
|
1311
|
+
readOnly: boolean
|
|
1312
|
+
}
|
|
1313
|
+
| {
|
|
1314
|
+
type: 'update maxBlocks'
|
|
1315
|
+
maxBlocks: number | undefined
|
|
1316
|
+
}
|
|
1317
|
+
| {
|
|
1318
|
+
type: 'add behavior'
|
|
1319
|
+
behaviorConfig: BehaviorConfig
|
|
1320
|
+
}
|
|
1321
|
+
| {
|
|
1322
|
+
type: 'remove behavior'
|
|
1323
|
+
behaviorConfig: BehaviorConfig
|
|
1324
|
+
}
|
|
1325
|
+
| {
|
|
1326
|
+
type: 'blur'
|
|
1327
|
+
editor: PortableTextSlateEditor
|
|
1328
|
+
}
|
|
1329
|
+
| {
|
|
1330
|
+
type: 'focus'
|
|
1331
|
+
editor: PortableTextSlateEditor
|
|
1332
|
+
}
|
|
1333
|
+
| {
|
|
1334
|
+
type: 'normalizing'
|
|
1335
|
+
}
|
|
1336
|
+
| {
|
|
1337
|
+
type: 'update selection'
|
|
1338
|
+
selection: EditorSelection
|
|
1339
|
+
}
|
|
1340
|
+
| {
|
|
1341
|
+
type: 'done normalizing'
|
|
1342
|
+
}
|
|
1343
|
+
| {
|
|
1344
|
+
type: 'done syncing value'
|
|
1345
|
+
}
|
|
1346
|
+
| {
|
|
1347
|
+
type: 'syncing value'
|
|
1348
|
+
}
|
|
1349
|
+
| {
|
|
1350
|
+
type: 'behavior event'
|
|
1351
|
+
behaviorEvent: BehaviorEvent
|
|
1352
|
+
editor: PortableTextSlateEditor
|
|
1353
|
+
nativeEvent?: {
|
|
1354
|
+
preventDefault: () => void
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
| {
|
|
1358
|
+
type: 'dragstart'
|
|
1359
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1360
|
+
ghost?: HTMLElement
|
|
1361
|
+
}
|
|
1362
|
+
| {
|
|
1363
|
+
type: 'dragend'
|
|
1364
|
+
}
|
|
1365
|
+
| {
|
|
1366
|
+
type: 'drop'
|
|
1367
|
+
},
|
|
1368
|
+
undefined,
|
|
1369
|
+
never,
|
|
1370
|
+
never,
|
|
1371
|
+
never,
|
|
1372
|
+
never,
|
|
1373
|
+
| InternalPatchEvent
|
|
1374
|
+
| MutationEvent
|
|
1375
|
+
| PatchesEvent
|
|
1376
|
+
| {
|
|
1377
|
+
type: 'blurred'
|
|
1378
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1379
|
+
}
|
|
1380
|
+
| {
|
|
1381
|
+
type: 'done loading'
|
|
1382
|
+
}
|
|
1383
|
+
| {
|
|
1384
|
+
type: 'editable'
|
|
1385
|
+
}
|
|
1386
|
+
| {
|
|
1387
|
+
type: 'error'
|
|
1388
|
+
name: string
|
|
1389
|
+
description: string
|
|
1390
|
+
data: unknown
|
|
1391
|
+
}
|
|
1392
|
+
| {
|
|
1393
|
+
type: 'focused'
|
|
1394
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1395
|
+
}
|
|
1396
|
+
| {
|
|
1397
|
+
type: 'invalid value'
|
|
1398
|
+
resolution: InvalidValueResolution | null
|
|
1399
|
+
value: Array<PortableTextBlock> | undefined
|
|
1400
|
+
}
|
|
1401
|
+
| {
|
|
1402
|
+
type: 'loading'
|
|
1403
|
+
}
|
|
1404
|
+
| {
|
|
1405
|
+
type: 'read only'
|
|
1406
|
+
}
|
|
1407
|
+
| {
|
|
1408
|
+
type: 'ready'
|
|
1409
|
+
}
|
|
1410
|
+
| {
|
|
1411
|
+
type: 'selection'
|
|
1412
|
+
selection: EditorSelection
|
|
1413
|
+
}
|
|
1414
|
+
| {
|
|
1415
|
+
type: 'value changed'
|
|
1416
|
+
value: Array<PortableTextBlock> | undefined
|
|
1417
|
+
}
|
|
1418
|
+
>,
|
|
1277
1419
|
]
|
|
1278
1420
|
}
|
|
1279
1421
|
}
|
|
@@ -2126,6 +2268,12 @@ declare const editorMachine: StateMachine<
|
|
|
2126
2268
|
| {
|
|
2127
2269
|
type: 'editable'
|
|
2128
2270
|
}
|
|
2271
|
+
| {
|
|
2272
|
+
type: 'error'
|
|
2273
|
+
name: string
|
|
2274
|
+
description: string
|
|
2275
|
+
data: unknown
|
|
2276
|
+
}
|
|
2129
2277
|
| {
|
|
2130
2278
|
type: 'focused'
|
|
2131
2279
|
event: FocusEvent_2<HTMLDivElement, Element>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.49.
|
|
3
|
+
"version": "1.49.13",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"slate-react": "0.114.2",
|
|
80
80
|
"use-effect-event": "^1.0.2",
|
|
81
81
|
"xstate": "^5.19.2",
|
|
82
|
-
"@portabletext/
|
|
83
|
-
"@portabletext/
|
|
82
|
+
"@portabletext/patches": "1.1.3",
|
|
83
|
+
"@portabletext/block-tools": "1.1.26"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@portabletext/toolkit": "^2.0.17",
|
package/src/editor/Editable.tsx
CHANGED
|
@@ -284,8 +284,8 @@ export const PortableTextEditable = forwardRef<
|
|
|
284
284
|
// Output selection here in those cases where the editor selection was the same, and there are no set_selection operations made.
|
|
285
285
|
// The selection is usually automatically emitted to change$ by the withPortableTextSelections plugin whenever there is a set_selection operation applied.
|
|
286
286
|
if (!slateEditor.operations.some((o) => o.type === 'set_selection')) {
|
|
287
|
-
|
|
288
|
-
type: 'selection',
|
|
287
|
+
editorActor.send({
|
|
288
|
+
type: 'update selection',
|
|
289
289
|
selection: normalizedSelection,
|
|
290
290
|
})
|
|
291
291
|
}
|
|
@@ -293,7 +293,7 @@ export const PortableTextEditable = forwardRef<
|
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
|
-
}, [editorActor, propsSelection,
|
|
296
|
+
}, [editorActor, propsSelection, slateEditor])
|
|
297
297
|
|
|
298
298
|
// Restore selection from props when the editor has been initialized properly with it's value
|
|
299
299
|
useEffect(() => {
|
|
@@ -550,14 +550,14 @@ export const PortableTextEditable = forwardRef<
|
|
|
550
550
|
const newSelection = PortableTextEditor.getSelection(portableTextEditor)
|
|
551
551
|
// If the selection is the same, emit it explicitly here as there is no actual onChange event triggered.
|
|
552
552
|
if (selection === newSelection) {
|
|
553
|
-
|
|
554
|
-
type: 'selection',
|
|
553
|
+
editorActor.send({
|
|
554
|
+
type: 'update selection',
|
|
555
555
|
selection,
|
|
556
556
|
})
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
559
|
},
|
|
560
|
-
[onFocus, slateEditor, portableTextEditor, relayActor],
|
|
560
|
+
[editorActor, onFocus, slateEditor, portableTextEditor, relayActor],
|
|
561
561
|
)
|
|
562
562
|
|
|
563
563
|
const handleClick = useCallback(
|
|
@@ -127,24 +127,24 @@ describe('Feature: Self-solving', () => {
|
|
|
127
127
|
},
|
|
128
128
|
})
|
|
129
129
|
expect(onChange).toHaveBeenNthCalledWith(4, {
|
|
130
|
-
type: 'selection',
|
|
131
|
-
selection: {
|
|
132
|
-
...getTextSelection(initialValue, 'foo'),
|
|
133
|
-
backward: false,
|
|
134
|
-
},
|
|
135
|
-
})
|
|
136
|
-
expect(onChange).toHaveBeenNthCalledWith(5, {
|
|
137
130
|
type: 'patch',
|
|
138
131
|
patch: spanPatch,
|
|
139
132
|
})
|
|
140
|
-
expect(onChange).toHaveBeenNthCalledWith(
|
|
133
|
+
expect(onChange).toHaveBeenNthCalledWith(5, {
|
|
141
134
|
type: 'patch',
|
|
142
135
|
patch: blockPatch,
|
|
143
136
|
})
|
|
144
|
-
expect(onChange).toHaveBeenNthCalledWith(
|
|
137
|
+
expect(onChange).toHaveBeenNthCalledWith(6, {
|
|
145
138
|
type: 'patch',
|
|
146
139
|
patch: strongPatch,
|
|
147
140
|
})
|
|
141
|
+
expect(onChange).toHaveBeenNthCalledWith(7, {
|
|
142
|
+
type: 'selection',
|
|
143
|
+
selection: {
|
|
144
|
+
...getTextSelection(initialValue, 'foo'),
|
|
145
|
+
backward: false,
|
|
146
|
+
},
|
|
147
|
+
})
|
|
148
148
|
expect(onChange).toHaveBeenNthCalledWith(8, {
|
|
149
149
|
type: 'mutation',
|
|
150
150
|
patches: [spanPatch, blockPatch],
|
|
@@ -271,21 +271,6 @@ function createActors(config: {
|
|
|
271
271
|
}
|
|
272
272
|
})
|
|
273
273
|
|
|
274
|
-
config.subscriptions.push(() => {
|
|
275
|
-
const subscription = config.relayActor.on('*', (event) => {
|
|
276
|
-
if (event.type === 'selection') {
|
|
277
|
-
config.editorActor.send({
|
|
278
|
-
type: 'update selection',
|
|
279
|
-
selection: event.selection,
|
|
280
|
-
})
|
|
281
|
-
}
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
return () => {
|
|
285
|
-
subscription.unsubscribe()
|
|
286
|
-
}
|
|
287
|
-
})
|
|
288
|
-
|
|
289
274
|
config.subscriptions.push(() => {
|
|
290
275
|
const subscription = syncActor.on('*', (event) => {
|
|
291
276
|
switch (event.type) {
|
|
@@ -340,6 +325,7 @@ function createActors(config: {
|
|
|
340
325
|
case 'mutation':
|
|
341
326
|
case 'ready':
|
|
342
327
|
case 'read only':
|
|
328
|
+
case 'selection':
|
|
343
329
|
config.relayActor.send(event)
|
|
344
330
|
break
|
|
345
331
|
case 'internal.patch':
|
|
@@ -319,7 +319,10 @@ export const editorMachine = setup({
|
|
|
319
319
|
actions: assign({maxBlocks: ({event}) => event.maxBlocks}),
|
|
320
320
|
},
|
|
321
321
|
'update selection': {
|
|
322
|
-
actions: [
|
|
322
|
+
actions: [
|
|
323
|
+
assign({selection: ({event}) => event.selection}),
|
|
324
|
+
emit(({event}) => ({...event, type: 'selection'})),
|
|
325
|
+
],
|
|
323
326
|
},
|
|
324
327
|
},
|
|
325
328
|
type: 'parallel',
|
|
@@ -4,7 +4,6 @@ import {slateRangeToSelection} from '../../internal-utils/slate-utils'
|
|
|
4
4
|
import {SLATE_TO_PORTABLE_TEXT_RANGE} from '../../internal-utils/weakMaps'
|
|
5
5
|
import type {EditorSelection, PortableTextSlateEditor} from '../../types/editor'
|
|
6
6
|
import type {EditorActor} from '../editor-machine'
|
|
7
|
-
import type {RelayActor} from '../relay-machine'
|
|
8
7
|
|
|
9
8
|
const debug = debugWithName('plugin:withPortableTextSelections')
|
|
10
9
|
const debugVerbose = debug.enabled && false
|
|
@@ -12,7 +11,6 @@ const debugVerbose = debug.enabled && false
|
|
|
12
11
|
// This plugin will make sure that we emit a PT selection whenever the editor has changed.
|
|
13
12
|
export function createWithPortableTextSelections(
|
|
14
13
|
editorActor: EditorActor,
|
|
15
|
-
relayActor: RelayActor,
|
|
16
14
|
): (editor: PortableTextSlateEditor) => PortableTextSlateEditor {
|
|
17
15
|
let prevSelection: BaseRange | null = null
|
|
18
16
|
return function withPortableTextSelections(
|
|
@@ -42,9 +40,9 @@ export function createWithPortableTextSelections(
|
|
|
42
40
|
)
|
|
43
41
|
}
|
|
44
42
|
if (ptRange) {
|
|
45
|
-
|
|
43
|
+
editorActor.send({type: 'update selection', selection: ptRange})
|
|
46
44
|
} else {
|
|
47
|
-
|
|
45
|
+
editorActor.send({type: 'update selection', selection: null})
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
prevSelection = editor.selection
|
|
@@ -58,10 +58,8 @@ export const withPlugins = <T extends Editor>(
|
|
|
58
58
|
const withUtils = createWithUtils({
|
|
59
59
|
editorActor,
|
|
60
60
|
})
|
|
61
|
-
const withPortableTextSelections =
|
|
62
|
-
editorActor
|
|
63
|
-
relayActor,
|
|
64
|
-
)
|
|
61
|
+
const withPortableTextSelections =
|
|
62
|
+
createWithPortableTextSelections(editorActor)
|
|
65
63
|
const withEventListeners = createWithEventListeners(editorActor)
|
|
66
64
|
|
|
67
65
|
// Ordering is important here, selection dealing last, data manipulation in the middle and core model stuff first.
|