@portabletext/editor 1.26.3 → 1.28.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.
- package/README.md +5 -5
- package/lib/_chunks-cjs/behavior.markdown.cjs +327 -0
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -0
- package/lib/_chunks-cjs/plugin.event-listener.cjs +6827 -0
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +88 -88
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +332 -0
- package/lib/_chunks-es/behavior.markdown.js.map +1 -0
- package/lib/_chunks-es/plugin.event-listener.js +6851 -0
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +88 -88
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/behaviors/index.cjs +2 -325
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +1 -1
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/behaviors/index.js +2 -326
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +261 -6782
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3509 -2161
- package/lib/index.d.ts +3509 -2161
- package/lib/index.js +223 -6761
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +29 -0
- package/lib/plugins/index.cjs.map +1 -0
- package/lib/plugins/index.d.cts +19411 -0
- package/lib/plugins/index.d.ts +19411 -0
- package/lib/plugins/index.js +29 -0
- package/lib/plugins/index.js.map +1 -0
- package/lib/selectors/index.cjs +15 -3
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +19 -1
- package/lib/selectors/index.d.ts +19 -1
- package/lib/selectors/index.js +17 -4
- package/lib/selectors/index.js.map +1 -1
- package/package.json +14 -8
- package/src/behavior-actions/behavior.action.insert-break.ts +93 -83
- package/src/editor/Editable.tsx +6 -6
- package/src/editor/PortableTextEditor.tsx +288 -1
- package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -1
- package/src/editor/components/DefaultObject.tsx +21 -0
- package/src/editor/components/Element.tsx +5 -5
- package/src/editor/components/Leaf.tsx +1 -6
- package/src/editor/components/Synchronizer.tsx +16 -1
- package/src/editor/create-editor.ts +8 -48
- package/src/editor/editor-machine.ts +118 -131
- package/src/editor/plugins/create-with-event-listeners.ts +19 -38
- package/src/editor/plugins/createWithPatches.ts +1 -1
- package/src/editor/plugins/createWithPortableTextSelections.ts +2 -2
- package/src/editor/sync-machine.ts +3 -5
- package/src/index.ts +5 -11
- package/src/plugins/_exports/index.ts +1 -0
- package/src/plugins/index.ts +3 -0
- package/src/plugins/plugin.editor-ref.tsx +17 -0
- package/src/{editor/editor-event-listener.tsx → plugins/plugin.event-listener.tsx} +7 -6
- package/src/plugins/plugin.markdown.tsx +70 -0
- package/src/selectors/index.ts +4 -2
- package/src/selectors/selector.get-active-annotations.test.ts +122 -0
- package/src/selectors/selector.get-active-annotations.ts +30 -0
- package/src/selectors/selector.get-selection.ts +8 -0
- package/src/selectors/selector.get-value.ts +11 -0
- package/src/type-utils.ts +12 -2
- package/src/editor/nodes/DefaultAnnotation.tsx +0 -20
- package/src/editor/nodes/DefaultObject.tsx +0 -18
|
@@ -261,12 +261,32 @@ export class PortableTextEditor extends Component<
|
|
|
261
261
|
)
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
|
|
264
|
+
/**
|
|
265
|
+
* @deprecated
|
|
266
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
267
|
+
*
|
|
268
|
+
* ```
|
|
269
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
270
|
+
* const editor = useEditor()
|
|
271
|
+
* const isActive = useEditorSelector(editor, selectors.getActiveAnnotations)
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
265
274
|
static activeAnnotations = (
|
|
266
275
|
editor: PortableTextEditor,
|
|
267
276
|
): PortableTextObject[] => {
|
|
268
277
|
return editor && editor.editable ? editor.editable.activeAnnotations() : []
|
|
269
278
|
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* @deprecated
|
|
282
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
283
|
+
*
|
|
284
|
+
* ```
|
|
285
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
286
|
+
* const editor = useEditor()
|
|
287
|
+
* const isActive = useEditorSelector(editor, selectors.isActiveAnnotation(...))
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
270
290
|
static isAnnotationActive = (
|
|
271
291
|
editor: PortableTextEditor,
|
|
272
292
|
annotationType: PortableTextObject['_type'],
|
|
@@ -275,60 +295,224 @@ export class PortableTextEditor extends Component<
|
|
|
275
295
|
? editor.editable.isAnnotationActive(annotationType)
|
|
276
296
|
: false
|
|
277
297
|
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @deprecated
|
|
301
|
+
* Use `editor.send(...)` instead
|
|
302
|
+
*
|
|
303
|
+
* ```
|
|
304
|
+
* const editor = useEditor()
|
|
305
|
+
* editor.send({
|
|
306
|
+
* type: 'annotation.add',
|
|
307
|
+
* annotation: {
|
|
308
|
+
* name: '...',
|
|
309
|
+
* value: {...},
|
|
310
|
+
* }
|
|
311
|
+
* })
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
278
314
|
static addAnnotation = <TSchemaType extends {name: string}>(
|
|
279
315
|
editor: PortableTextEditor,
|
|
280
316
|
type: TSchemaType,
|
|
281
317
|
value?: {[prop: string]: unknown},
|
|
282
318
|
): AddedAnnotationPaths | undefined =>
|
|
283
319
|
editor.editable?.addAnnotation(type, value)
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @deprecated
|
|
323
|
+
* Use `editor.send(...)` instead
|
|
324
|
+
*
|
|
325
|
+
* ```
|
|
326
|
+
* const editor = useEditor()
|
|
327
|
+
* editor.send({
|
|
328
|
+
* type: 'blur',
|
|
329
|
+
* })
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
284
332
|
static blur = (editor: PortableTextEditor): void => {
|
|
285
333
|
debug('Host blurred')
|
|
286
334
|
editor.editable?.blur()
|
|
287
335
|
}
|
|
336
|
+
|
|
288
337
|
static delete = (
|
|
289
338
|
editor: PortableTextEditor,
|
|
290
339
|
selection: EditorSelection,
|
|
291
340
|
options?: EditableAPIDeleteOptions,
|
|
292
341
|
) => editor.editable?.delete(selection, options)
|
|
342
|
+
|
|
293
343
|
static findDOMNode = (
|
|
294
344
|
editor: PortableTextEditor,
|
|
295
345
|
element: PortableTextBlock | PortableTextChild,
|
|
296
346
|
) => {
|
|
297
347
|
return editor.editable?.findDOMNode(element)
|
|
298
348
|
}
|
|
349
|
+
|
|
299
350
|
static findByPath = (editor: PortableTextEditor, path: Path) => {
|
|
300
351
|
return editor.editable?.findByPath(path) || []
|
|
301
352
|
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* @deprecated
|
|
356
|
+
* Use `editor.send(...)` instead
|
|
357
|
+
*
|
|
358
|
+
* ```
|
|
359
|
+
* const editor = useEditor()
|
|
360
|
+
* editor.send({
|
|
361
|
+
* type: 'focus',
|
|
362
|
+
* })
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
302
365
|
static focus = (editor: PortableTextEditor): void => {
|
|
303
366
|
debug('Host requesting focus')
|
|
304
367
|
editor.editable?.focus()
|
|
305
368
|
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* @deprecated
|
|
372
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
373
|
+
*
|
|
374
|
+
* ```
|
|
375
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
376
|
+
* const editor = useEditor()
|
|
377
|
+
* const focusBlock = useEditorSelector(editor, selectors.getFocusBlock)
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
306
380
|
static focusBlock = (editor: PortableTextEditor) => {
|
|
307
381
|
return editor.editable?.focusBlock()
|
|
308
382
|
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @deprecated
|
|
386
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
387
|
+
*
|
|
388
|
+
* ```
|
|
389
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
390
|
+
* const editor = useEditor()
|
|
391
|
+
* const focusChild = useEditorSelector(editor, selectors.getFocusChild)
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
309
394
|
static focusChild = (
|
|
310
395
|
editor: PortableTextEditor,
|
|
311
396
|
): PortableTextChild | undefined => {
|
|
312
397
|
return editor.editable?.focusChild()
|
|
313
398
|
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* @deprecated
|
|
402
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
403
|
+
*
|
|
404
|
+
* ```
|
|
405
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
406
|
+
* const editor = useEditor()
|
|
407
|
+
* const selection = useEditorSelector(editor, selectors.getSelection)
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
314
410
|
static getSelection = (editor: PortableTextEditor) => {
|
|
315
411
|
return editor.editable ? editor.editable.getSelection() : null
|
|
316
412
|
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* @deprecated
|
|
416
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
417
|
+
*
|
|
418
|
+
* ```
|
|
419
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
420
|
+
* const editor = useEditor()
|
|
421
|
+
* const value = useEditorSelector(editor, selectors.getValue)
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
317
424
|
static getValue = (editor: PortableTextEditor) => {
|
|
318
425
|
return editor.editable?.getValue()
|
|
319
426
|
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* @deprecated
|
|
430
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
431
|
+
*
|
|
432
|
+
* ```
|
|
433
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
434
|
+
* const editor = useEditor()
|
|
435
|
+
* const isActive = useEditorSelector(editor, selectors.isActiveStyle(...))
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
320
438
|
static hasBlockStyle = (editor: PortableTextEditor, blockStyle: string) => {
|
|
321
439
|
return editor.editable?.hasBlockStyle(blockStyle)
|
|
322
440
|
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* @deprecated
|
|
444
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
445
|
+
*
|
|
446
|
+
* ```
|
|
447
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
448
|
+
* const editor = useEditor()
|
|
449
|
+
* const isActive = useEditorSelector(editor, selectors.isActiveListItem(...))
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
323
452
|
static hasListStyle = (editor: PortableTextEditor, listStyle: string) => {
|
|
324
453
|
return editor.editable?.hasListStyle(listStyle)
|
|
325
454
|
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* @deprecated
|
|
458
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
459
|
+
*
|
|
460
|
+
* ```
|
|
461
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
462
|
+
* const editor = useEditor()
|
|
463
|
+
* const isSelectionCollapsed = useEditorSelector(editor, selectors.isSelectionCollapsed)
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
326
466
|
static isCollapsedSelection = (editor: PortableTextEditor) =>
|
|
327
467
|
editor.editable?.isCollapsedSelection()
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* @deprecated
|
|
471
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
472
|
+
*
|
|
473
|
+
* ```
|
|
474
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
475
|
+
* const editor = useEditor()
|
|
476
|
+
* const isSelectionExpanded = useEditorSelector(editor, selectors.isSelectionExpanded)
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
328
479
|
static isExpandedSelection = (editor: PortableTextEditor) =>
|
|
329
480
|
editor.editable?.isExpandedSelection()
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* @deprecated
|
|
484
|
+
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
485
|
+
*
|
|
486
|
+
* ```
|
|
487
|
+
* import * as selectors from '@portabletext/editor/selectors'
|
|
488
|
+
* const editor = useEditor()
|
|
489
|
+
* const isActive = useEditorSelector(editor, selectors.isActiveDecorator(...))
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
330
492
|
static isMarkActive = (editor: PortableTextEditor, mark: string) =>
|
|
331
493
|
editor.editable?.isMarkActive(mark)
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* @deprecated
|
|
497
|
+
* Use `editor.send(...)` instead
|
|
498
|
+
*
|
|
499
|
+
* ```
|
|
500
|
+
* const editor = useEditor()
|
|
501
|
+
* editor.send({
|
|
502
|
+
* type: 'insert.span',
|
|
503
|
+
* text: '...',
|
|
504
|
+
* annotations: [{name: '...', value: {...}}],
|
|
505
|
+
* decorators: ['...'],
|
|
506
|
+
* })
|
|
507
|
+
* editor.send({
|
|
508
|
+
* type: 'insert.inline object',
|
|
509
|
+
* inlineObject: {
|
|
510
|
+
* name: '...',
|
|
511
|
+
* value: {...},
|
|
512
|
+
* },
|
|
513
|
+
* })
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
332
516
|
static insertChild = <TSchemaType extends {name: string}>(
|
|
333
517
|
editor: PortableTextEditor,
|
|
334
518
|
type: TSchemaType,
|
|
@@ -337,6 +521,23 @@ export class PortableTextEditor extends Component<
|
|
|
337
521
|
debug(`Host inserting child`)
|
|
338
522
|
return editor.editable?.insertChild(type, value)
|
|
339
523
|
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* @deprecated
|
|
527
|
+
* Use `editor.send(...)` instead
|
|
528
|
+
*
|
|
529
|
+
* ```
|
|
530
|
+
* const editor = useEditor()
|
|
531
|
+
* editor.send({
|
|
532
|
+
* type: 'insert.block object',
|
|
533
|
+
* blockObject: {
|
|
534
|
+
* name: '...',
|
|
535
|
+
* value: {...},
|
|
536
|
+
* },
|
|
537
|
+
* placement: 'auto' | 'after' | 'before',
|
|
538
|
+
* })
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
340
541
|
static insertBlock = <TSchemaType extends {name: string}>(
|
|
341
542
|
editor: PortableTextEditor,
|
|
342
543
|
type: TSchemaType,
|
|
@@ -344,24 +545,52 @@ export class PortableTextEditor extends Component<
|
|
|
344
545
|
): Path | undefined => {
|
|
345
546
|
return editor.editable?.insertBlock(type, value)
|
|
346
547
|
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* @deprecated
|
|
551
|
+
* Use `editor.send(...)` instead
|
|
552
|
+
*
|
|
553
|
+
* ```
|
|
554
|
+
* const editor = useEditor()
|
|
555
|
+
* editor.send({
|
|
556
|
+
* type: 'insert.break',
|
|
557
|
+
* })
|
|
558
|
+
* ```
|
|
559
|
+
*/
|
|
347
560
|
static insertBreak = (editor: PortableTextEditor): void => {
|
|
348
561
|
return editor.editable?.insertBreak()
|
|
349
562
|
}
|
|
563
|
+
|
|
350
564
|
static isVoid = (
|
|
351
565
|
editor: PortableTextEditor,
|
|
352
566
|
element: PortableTextBlock | PortableTextChild,
|
|
353
567
|
) => {
|
|
354
568
|
return editor.editable?.isVoid(element)
|
|
355
569
|
}
|
|
570
|
+
|
|
356
571
|
static isObjectPath = (_editor: PortableTextEditor, path: Path): boolean => {
|
|
357
572
|
if (!path || !Array.isArray(path)) return false
|
|
358
573
|
const isChildObjectEditPath = path.length > 3 && path[1] === 'children'
|
|
359
574
|
const isBlockObjectEditPath = path.length > 1 && path[1] !== 'children'
|
|
360
575
|
return isBlockObjectEditPath || isChildObjectEditPath
|
|
361
576
|
}
|
|
577
|
+
|
|
362
578
|
static marks = (editor: PortableTextEditor) => {
|
|
363
579
|
return editor.editable?.marks()
|
|
364
580
|
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* @deprecated
|
|
584
|
+
* Use `editor.send(...)` instead
|
|
585
|
+
*
|
|
586
|
+
* ```
|
|
587
|
+
* const editor = useEditor()
|
|
588
|
+
* editor.send({
|
|
589
|
+
* type: 'select',
|
|
590
|
+
* selection: {...},
|
|
591
|
+
* })
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
365
594
|
static select = (
|
|
366
595
|
editor: PortableTextEditor,
|
|
367
596
|
selection: EditorSelection | null,
|
|
@@ -369,10 +598,38 @@ export class PortableTextEditor extends Component<
|
|
|
369
598
|
debug(`Host setting selection`, selection)
|
|
370
599
|
editor.editable?.select(selection)
|
|
371
600
|
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* @deprecated
|
|
604
|
+
* Use `editor.send(...)` instead
|
|
605
|
+
*
|
|
606
|
+
* ```
|
|
607
|
+
* const editor = useEditor()
|
|
608
|
+
* editor.send({
|
|
609
|
+
* type: 'annotation.remove',
|
|
610
|
+
* annotation: {
|
|
611
|
+
* name: '...',
|
|
612
|
+
* },
|
|
613
|
+
* })
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
372
616
|
static removeAnnotation = <TSchemaType extends {name: string}>(
|
|
373
617
|
editor: PortableTextEditor,
|
|
374
618
|
type: TSchemaType,
|
|
375
619
|
) => editor.editable?.removeAnnotation(type)
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* @deprecated
|
|
623
|
+
* Use `editor.send(...)` instead
|
|
624
|
+
*
|
|
625
|
+
* ```
|
|
626
|
+
* const editor = useEditor()
|
|
627
|
+
* editor.send({
|
|
628
|
+
* type: 'style.toggle',
|
|
629
|
+
* style: '...',
|
|
630
|
+
* })
|
|
631
|
+
* ```
|
|
632
|
+
*/
|
|
376
633
|
static toggleBlockStyle = (
|
|
377
634
|
editor: PortableTextEditor,
|
|
378
635
|
blockStyle: string,
|
|
@@ -380,27 +637,57 @@ export class PortableTextEditor extends Component<
|
|
|
380
637
|
debug(`Host is toggling block style`)
|
|
381
638
|
return editor.editable?.toggleBlockStyle(blockStyle)
|
|
382
639
|
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* @deprecated
|
|
643
|
+
* Use `editor.send(...)` instead
|
|
644
|
+
*
|
|
645
|
+
* ```
|
|
646
|
+
* const editor = useEditor()
|
|
647
|
+
* editor.send({
|
|
648
|
+
* type: 'list item.toggle',
|
|
649
|
+
* listItem: '...',
|
|
650
|
+
* })
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
383
653
|
static toggleList = (editor: PortableTextEditor, listStyle: string): void => {
|
|
384
654
|
return editor.editable?.toggleList(listStyle)
|
|
385
655
|
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* @deprecated
|
|
659
|
+
* Use `editor.send(...)` instead
|
|
660
|
+
*
|
|
661
|
+
* ```
|
|
662
|
+
* const editor = useEditor()
|
|
663
|
+
* editor.send({
|
|
664
|
+
* type: 'decorator.toggle',
|
|
665
|
+
* decorator: '...',
|
|
666
|
+
* })
|
|
667
|
+
* ```
|
|
668
|
+
*/
|
|
386
669
|
static toggleMark = (editor: PortableTextEditor, mark: string): void => {
|
|
387
670
|
debug(`Host toggling mark`, mark)
|
|
388
671
|
editor.editable?.toggleMark(mark)
|
|
389
672
|
}
|
|
673
|
+
|
|
390
674
|
static getFragment = (
|
|
391
675
|
editor: PortableTextEditor,
|
|
392
676
|
): PortableTextBlock[] | undefined => {
|
|
393
677
|
debug(`Host getting fragment`)
|
|
394
678
|
return editor.editable?.getFragment()
|
|
395
679
|
}
|
|
680
|
+
|
|
396
681
|
static undo = (editor: PortableTextEditor): void => {
|
|
397
682
|
debug('Host undoing')
|
|
398
683
|
editor.editable?.undo()
|
|
399
684
|
}
|
|
685
|
+
|
|
400
686
|
static redo = (editor: PortableTextEditor): void => {
|
|
401
687
|
debug('Host redoing')
|
|
402
688
|
editor.editable?.redo()
|
|
403
689
|
}
|
|
690
|
+
|
|
404
691
|
static isSelectionsOverlapping = (
|
|
405
692
|
editor: PortableTextEditor,
|
|
406
693
|
selectionA: EditorSelection,
|
|
@@ -32,7 +32,6 @@ describe('initialization', () => {
|
|
|
32
32
|
await waitFor(() => {
|
|
33
33
|
expect(editorRef.current).not.toBe(null)
|
|
34
34
|
expect(onChange).toHaveBeenCalledWith({type: 'ready'})
|
|
35
|
-
expect(onChange).toHaveBeenCalledWith({type: 'value', value: undefined})
|
|
36
35
|
expect(container).toMatchInlineSnapshot(`
|
|
37
36
|
<div>
|
|
38
37
|
<div
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {PortableTextBlock, PortableTextChild} from '@sanity/types'
|
|
2
|
+
|
|
3
|
+
export function DefaultBlockObject(props: {
|
|
4
|
+
value: PortableTextBlock | PortableTextChild
|
|
5
|
+
}) {
|
|
6
|
+
return (
|
|
7
|
+
<div style={{userSelect: 'none'}}>
|
|
8
|
+
[{props.value._type}: {props.value._key}]
|
|
9
|
+
</div>
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function DefaultInlineObject(props: {
|
|
14
|
+
value: PortableTextBlock | PortableTextChild
|
|
15
|
+
}) {
|
|
16
|
+
return (
|
|
17
|
+
<span style={{userSelect: 'none'}}>
|
|
18
|
+
[{props.value._type}: {props.value._key}]
|
|
19
|
+
</span>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -29,7 +29,7 @@ import type {
|
|
|
29
29
|
RenderListItemFunction,
|
|
30
30
|
RenderStyleFunction,
|
|
31
31
|
} from '../../types/editor'
|
|
32
|
-
import
|
|
32
|
+
import {DefaultBlockObject, DefaultInlineObject} from './DefaultObject'
|
|
33
33
|
import {DraggableBlock} from './DraggableBlock'
|
|
34
34
|
|
|
35
35
|
const debug = debugWithName('components:Element')
|
|
@@ -137,7 +137,7 @@ export const Element: FunctionComponent<ElementProps> = ({
|
|
|
137
137
|
{renderChild &&
|
|
138
138
|
renderChild({
|
|
139
139
|
annotations: EMPTY_ANNOTATIONS, // These inline objects currently doesn't support annotations. This is a limitation of the current PT spec/model.
|
|
140
|
-
children: <
|
|
140
|
+
children: <DefaultInlineObject value={value} />,
|
|
141
141
|
editorElementRef: inlineBlockObjectRef,
|
|
142
142
|
focused,
|
|
143
143
|
path: elmPath,
|
|
@@ -146,7 +146,7 @@ export const Element: FunctionComponent<ElementProps> = ({
|
|
|
146
146
|
type: schemaType,
|
|
147
147
|
value: value as PortableTextChild,
|
|
148
148
|
})}
|
|
149
|
-
{!renderChild && <
|
|
149
|
+
{!renderChild && <DefaultInlineObject value={value} />}
|
|
150
150
|
</span>
|
|
151
151
|
</span>
|
|
152
152
|
)
|
|
@@ -280,7 +280,7 @@ export const Element: FunctionComponent<ElementProps> = ({
|
|
|
280
280
|
if (renderBlock) {
|
|
281
281
|
const _props: Omit<BlockRenderProps, 'type'> = Object.defineProperty(
|
|
282
282
|
{
|
|
283
|
-
children: <
|
|
283
|
+
children: <DefaultBlockObject value={value} />,
|
|
284
284
|
editorElementRef: blockRef,
|
|
285
285
|
focused,
|
|
286
286
|
path: blockPath,
|
|
@@ -310,7 +310,7 @@ export const Element: FunctionComponent<ElementProps> = ({
|
|
|
310
310
|
{renderedBlockFromProps ? (
|
|
311
311
|
renderedBlockFromProps
|
|
312
312
|
) : (
|
|
313
|
-
<
|
|
313
|
+
<DefaultBlockObject value={value} />
|
|
314
314
|
)}
|
|
315
315
|
</div>
|
|
316
316
|
</DraggableBlock>
|
|
@@ -27,7 +27,6 @@ import type {
|
|
|
27
27
|
} from '../../types/editor'
|
|
28
28
|
import type {EditorActor} from '../editor-machine'
|
|
29
29
|
import {usePortableTextEditor} from '../hooks/usePortableTextEditor'
|
|
30
|
-
import {DefaultAnnotation} from '../nodes/DefaultAnnotation'
|
|
31
30
|
import {PortableTextEditor} from '../PortableTextEditor'
|
|
32
31
|
|
|
33
32
|
const debug = debugWithName('components:Leaf')
|
|
@@ -264,11 +263,7 @@ export const Leaf = (props: LeafProps) => {
|
|
|
264
263
|
</span>
|
|
265
264
|
)
|
|
266
265
|
} else {
|
|
267
|
-
returnedChildren =
|
|
268
|
-
<DefaultAnnotation annotation={annotation}>
|
|
269
|
-
<span ref={spanRef}>{returnedChildren}</span>
|
|
270
|
-
</DefaultAnnotation>
|
|
271
|
-
)
|
|
266
|
+
returnedChildren = <span ref={spanRef}>{returnedChildren}</span>
|
|
272
267
|
}
|
|
273
268
|
}
|
|
274
269
|
})
|
|
@@ -67,7 +67,22 @@ export function Synchronizer(props: SynchronizerProps) {
|
|
|
67
67
|
|
|
68
68
|
useEffect(() => {
|
|
69
69
|
const subscription = syncActorRef.on('*', (event) => {
|
|
70
|
-
|
|
70
|
+
switch (event.type) {
|
|
71
|
+
case 'invalid value':
|
|
72
|
+
props.editorActor.send({
|
|
73
|
+
...event,
|
|
74
|
+
type: 'notify.invalid value',
|
|
75
|
+
})
|
|
76
|
+
break
|
|
77
|
+
case 'value changed':
|
|
78
|
+
props.editorActor.send({
|
|
79
|
+
...event,
|
|
80
|
+
type: 'notify.value changed',
|
|
81
|
+
})
|
|
82
|
+
break
|
|
83
|
+
default:
|
|
84
|
+
props.editorActor.send(event)
|
|
85
|
+
}
|
|
71
86
|
})
|
|
72
87
|
|
|
73
88
|
return () => {
|
|
@@ -11,10 +11,13 @@ import {
|
|
|
11
11
|
type EventObject,
|
|
12
12
|
type Snapshot,
|
|
13
13
|
} from 'xstate'
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
Behavior,
|
|
16
|
+
CustomBehaviorEvent,
|
|
17
|
+
SyntheticBehaviorEvent,
|
|
18
|
+
} from '../behaviors/behavior.types'
|
|
15
19
|
import {coreConverters} from '../converters/converters.core'
|
|
16
20
|
import {compileType} from '../internal-utils/schema'
|
|
17
|
-
import type {PickFromUnion} from '../type-utils'
|
|
18
21
|
import type {EditableAPI} from '../types/editor'
|
|
19
22
|
import {createEditorSchema} from './create-editor-schema'
|
|
20
23
|
import {createSlateEditor, type SlateEditor} from './create-slate-editor'
|
|
@@ -23,7 +26,7 @@ import {
|
|
|
23
26
|
editorMachine,
|
|
24
27
|
type EditorActor,
|
|
25
28
|
type EditorEmittedEvent,
|
|
26
|
-
type
|
|
29
|
+
type ExternalEditorEvent,
|
|
27
30
|
} from './editor-machine'
|
|
28
31
|
import {getEditorSnapshot} from './editor-selector'
|
|
29
32
|
import type {EditorSnapshot} from './editor-snapshot'
|
|
@@ -60,51 +63,8 @@ export type EditorConfig = {
|
|
|
60
63
|
* @public
|
|
61
64
|
*/
|
|
62
65
|
export type EditorEvent =
|
|
63
|
-
|
|
|
64
|
-
|
|
65
|
-
'type',
|
|
66
|
-
| 'annotation.add'
|
|
67
|
-
| 'annotation.remove'
|
|
68
|
-
| 'annotation.toggle'
|
|
69
|
-
| 'block.set'
|
|
70
|
-
| 'block.unset'
|
|
71
|
-
| 'blur'
|
|
72
|
-
| 'data transfer.set'
|
|
73
|
-
| 'decorator.add'
|
|
74
|
-
| 'decorator.remove'
|
|
75
|
-
| 'decorator.toggle'
|
|
76
|
-
| 'delete.block'
|
|
77
|
-
| 'delete.text'
|
|
78
|
-
| 'deserialization.failure'
|
|
79
|
-
| 'deserialization.success'
|
|
80
|
-
| 'focus'
|
|
81
|
-
| 'insert.block'
|
|
82
|
-
| 'insert.block object'
|
|
83
|
-
| 'insert.inline object'
|
|
84
|
-
| 'insert.span'
|
|
85
|
-
| 'insert.text block'
|
|
86
|
-
| 'list item.add'
|
|
87
|
-
| 'list item.remove'
|
|
88
|
-
| 'list item.toggle'
|
|
89
|
-
| 'move.block'
|
|
90
|
-
| 'move.block down'
|
|
91
|
-
| 'move.block up'
|
|
92
|
-
| 'select'
|
|
93
|
-
| 'select.next block'
|
|
94
|
-
| 'select.previous block'
|
|
95
|
-
| 'serialization.failure'
|
|
96
|
-
| 'serialization.success'
|
|
97
|
-
| 'style.add'
|
|
98
|
-
| 'style.remove'
|
|
99
|
-
| 'style.toggle'
|
|
100
|
-
| 'text block.set'
|
|
101
|
-
| 'text block.unset'
|
|
102
|
-
| 'patches'
|
|
103
|
-
| 'update behaviors'
|
|
104
|
-
| 'update key generator'
|
|
105
|
-
| 'update readOnly'
|
|
106
|
-
| 'update value'
|
|
107
|
-
>
|
|
66
|
+
| ExternalEditorEvent
|
|
67
|
+
| SyntheticBehaviorEvent
|
|
108
68
|
| CustomBehaviorEvent
|
|
109
69
|
|
|
110
70
|
/**
|