@portabletext/toolbar 0.0.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.
@@ -0,0 +1,614 @@
1
+ import {
2
+ AnnotationPath,
3
+ AnnotationSchemaType,
4
+ BlockObjectSchemaType,
5
+ BlockPath,
6
+ ChildPath,
7
+ DecoratorDefinition,
8
+ DecoratorSchemaType,
9
+ InlineObjectSchemaType,
10
+ ListSchemaType,
11
+ PortableTextObject,
12
+ StyleSchemaType,
13
+ } from '@portabletext/editor'
14
+ import {InsertPlacement} from '@portabletext/editor/behaviors'
15
+ import type {KeyboardShortcut} from '@portabletext/keyboard-shortcuts'
16
+ import type {RefObject} from 'react'
17
+
18
+ declare type ActiveContext = {
19
+ annotations: Array<{
20
+ value: PortableTextObject
21
+ schemaType: ToolbarAnnotationSchemaType
22
+ at: AnnotationPath
23
+ }>
24
+ elementRef: RefObject<Element | null>
25
+ }
26
+
27
+ declare type ActiveContext_2 = {
28
+ blockObjects: Array<{
29
+ value: PortableTextObject
30
+ schemaType: ToolbarBlockObjectSchemaType
31
+ at: BlockPath
32
+ }>
33
+ elementRef: RefObject<Element | null>
34
+ }
35
+
36
+ declare type ActiveContext_3 = {
37
+ inlineObjects: Array<{
38
+ value: PortableTextObject
39
+ schemaType: ToolbarInlineObjectSchemaType
40
+ at: ChildPath
41
+ }>
42
+ elementRef: RefObject<Element | null>
43
+ }
44
+
45
+ /**
46
+ * @beta
47
+ */
48
+ export declare type AnnotationButton = {
49
+ snapshot: {
50
+ matches: (
51
+ state:
52
+ | 'disabled'
53
+ | 'enabled'
54
+ | {
55
+ disabled: 'inactive'
56
+ }
57
+ | {
58
+ disabled: 'active'
59
+ }
60
+ | {
61
+ enabled: 'inactive'
62
+ }
63
+ | {
64
+ enabled: {
65
+ inactive: 'idle'
66
+ }
67
+ }
68
+ | {
69
+ enabled: {
70
+ inactive: 'showing dialog'
71
+ }
72
+ }
73
+ | {
74
+ enabled: 'active'
75
+ },
76
+ ) => boolean
77
+ }
78
+ send: (event: AnnotationButtonEvent) => void
79
+ }
80
+
81
+ /**
82
+ * @beta
83
+ */
84
+ export declare type AnnotationButtonEvent =
85
+ | {
86
+ type: 'close dialog'
87
+ }
88
+ | {
89
+ type: 'open dialog'
90
+ }
91
+ | {
92
+ type: 'add'
93
+ annotation: {
94
+ value: Record<string, unknown>
95
+ }
96
+ }
97
+ | {
98
+ type: 'remove'
99
+ }
100
+
101
+ /**
102
+ * @beta
103
+ */
104
+ export declare type AnnotationPopover = {
105
+ snapshot: {
106
+ context: ActiveContext
107
+ matches: (
108
+ state:
109
+ | 'disabled'
110
+ | 'enabled'
111
+ | {
112
+ enabled: 'inactive' | 'active'
113
+ },
114
+ ) => boolean
115
+ }
116
+ send: (event: AnnotationPopoverEvent) => void
117
+ }
118
+
119
+ /**
120
+ * @beta
121
+ */
122
+ export declare type AnnotationPopoverEvent =
123
+ | {
124
+ type: 'remove'
125
+ schemaType: AnnotationSchemaType
126
+ }
127
+ | {
128
+ type: 'edit'
129
+ at: AnnotationPath
130
+ props: {
131
+ [key: string]: unknown
132
+ }
133
+ }
134
+ | {
135
+ type: 'close'
136
+ }
137
+
138
+ /**
139
+ * @beta
140
+ */
141
+ export declare type BlockObjectButton = {
142
+ snapshot: {
143
+ matches: (
144
+ state:
145
+ | 'disabled'
146
+ | 'enabled'
147
+ | {
148
+ enabled: 'idle'
149
+ }
150
+ | {
151
+ enabled: 'showing dialog'
152
+ },
153
+ ) => boolean
154
+ }
155
+ send: (event: BlockObjectButtonEvent) => void
156
+ }
157
+
158
+ /**
159
+ * @beta
160
+ */
161
+ export declare type BlockObjectButtonEvent =
162
+ | {
163
+ type: 'close dialog'
164
+ }
165
+ | {
166
+ type: 'open dialog'
167
+ }
168
+ | {
169
+ type: 'insert'
170
+ value: {
171
+ [key: string]: unknown
172
+ }
173
+ placement: InsertPlacement | undefined
174
+ }
175
+
176
+ /**
177
+ * @beta
178
+ */
179
+ export declare type BlockObjectPopover = {
180
+ snapshot: {
181
+ context: ActiveContext_2
182
+ matches: (
183
+ state:
184
+ | 'disabled'
185
+ | 'enabled'
186
+ | {
187
+ enabled: 'inactive' | 'active'
188
+ },
189
+ ) => boolean
190
+ }
191
+ send: (event: BlockObjectPopoverEvent) => void
192
+ }
193
+
194
+ /**
195
+ * @beta
196
+ */
197
+ export declare type BlockObjectPopoverEvent =
198
+ | {
199
+ type: 'remove'
200
+ at: BlockPath
201
+ }
202
+ | {
203
+ type: 'edit'
204
+ at: BlockPath
205
+ props: {
206
+ [key: string]: unknown
207
+ }
208
+ }
209
+ | {
210
+ type: 'close'
211
+ }
212
+
213
+ /**
214
+ * @beta
215
+ */
216
+ export declare type DecoratorButton = {
217
+ snapshot: {
218
+ matches: (
219
+ state:
220
+ | 'disabled'
221
+ | 'enabled'
222
+ | {
223
+ disabled: 'inactive'
224
+ }
225
+ | {
226
+ disabled: 'active'
227
+ }
228
+ | {
229
+ enabled: 'inactive'
230
+ }
231
+ | {
232
+ enabled: 'active'
233
+ },
234
+ ) => boolean
235
+ }
236
+ send: (event: DecoratorButtonEvent) => void
237
+ }
238
+
239
+ /**
240
+ * @beta
241
+ */
242
+ export declare type DecoratorButtonEvent = {
243
+ type: 'toggle'
244
+ }
245
+
246
+ /**
247
+ * @beta
248
+ */
249
+ export declare type ExtendAnnotationSchemaType = (
250
+ annotation: AnnotationSchemaType,
251
+ ) => ToolbarAnnotationSchemaType
252
+
253
+ /**
254
+ * @beta
255
+ */
256
+ export declare type ExtendBlockObjectSchemaType = (
257
+ blockObject: BlockObjectSchemaType,
258
+ ) => ToolbarBlockObjectSchemaType
259
+
260
+ /**
261
+ * @beta
262
+ */
263
+ export declare type ExtendDecoratorSchemaType = (
264
+ decorator: DecoratorSchemaType,
265
+ ) => ToolbarDecoratorSchemaType
266
+
267
+ /**
268
+ * @beta
269
+ */
270
+ export declare type ExtendInlineObjectSchemaType = (
271
+ inlineObject: InlineObjectSchemaType,
272
+ ) => ToolbarInlineObjectSchemaType
273
+
274
+ /**
275
+ * @beta
276
+ */
277
+ export declare type ExtendListSchemaType = (
278
+ list: ListSchemaType,
279
+ ) => ToolbarListSchemaType
280
+
281
+ /**
282
+ * @beta
283
+ */
284
+ export declare type ExtendStyleSchemaType = (
285
+ style: StyleSchemaType,
286
+ ) => ToolbarStyleSchemaType
287
+
288
+ /**
289
+ * @beta
290
+ */
291
+ export declare type HistoryButtons = {
292
+ snapshot: {
293
+ matches: (state: 'disabled' | 'enabled') => boolean
294
+ }
295
+ send: (event: HistoryButtonsEvent) => void
296
+ }
297
+
298
+ /**
299
+ * @beta
300
+ */
301
+ export declare type HistoryButtonsEvent =
302
+ | {
303
+ type: 'history.undo'
304
+ }
305
+ | {
306
+ type: 'history.redo'
307
+ }
308
+
309
+ /**
310
+ * @beta
311
+ */
312
+ export declare type InlineObjectButton = {
313
+ snapshot: {
314
+ matches: (
315
+ state:
316
+ | 'disabled'
317
+ | 'enabled'
318
+ | {
319
+ enabled: 'idle'
320
+ }
321
+ | {
322
+ enabled: 'showing dialog'
323
+ },
324
+ ) => boolean
325
+ }
326
+ send: (event: InlineObjectButtonEvent) => void
327
+ }
328
+
329
+ /**
330
+ * @beta
331
+ */
332
+ export declare type InlineObjectButtonEvent =
333
+ | {
334
+ type: 'close dialog'
335
+ }
336
+ | {
337
+ type: 'open dialog'
338
+ }
339
+ | {
340
+ type: 'insert'
341
+ value: {
342
+ [key: string]: unknown
343
+ }
344
+ }
345
+
346
+ /**
347
+ * @beta
348
+ */
349
+ export declare type InlineObjectPopover = {
350
+ snapshot: {
351
+ context: ActiveContext_3
352
+ matches: (
353
+ state:
354
+ | 'disabled'
355
+ | 'enabled'
356
+ | {
357
+ enabled: 'inactive' | 'active'
358
+ },
359
+ ) => boolean
360
+ }
361
+ send: (event: InlineObjectPopoverEvent) => void
362
+ }
363
+
364
+ /**
365
+ * @beta
366
+ */
367
+ export declare type InlineObjectPopoverEvent =
368
+ | {
369
+ type: 'remove'
370
+ at: ChildPath
371
+ }
372
+ | {
373
+ type: 'edit'
374
+ at: ChildPath
375
+ props: {
376
+ [key: string]: unknown
377
+ }
378
+ }
379
+ | {
380
+ type: 'close'
381
+ }
382
+
383
+ /**
384
+ * @beta
385
+ */
386
+ export declare type ListButton = {
387
+ snapshot: {
388
+ matches: (
389
+ state:
390
+ | 'disabled'
391
+ | 'enabled'
392
+ | {
393
+ disabled: 'inactive'
394
+ }
395
+ | {
396
+ disabled: 'active'
397
+ }
398
+ | {
399
+ enabled: 'inactive'
400
+ }
401
+ | {
402
+ enabled: 'active'
403
+ },
404
+ ) => boolean
405
+ }
406
+ send: (event: ListButtonEvent) => void
407
+ }
408
+
409
+ /**
410
+ * @beta
411
+ */
412
+ export declare type ListButtonEvent = {
413
+ type: 'toggle'
414
+ }
415
+
416
+ /**
417
+ * @beta
418
+ */
419
+ export declare type StyleSelector = {
420
+ snapshot: {
421
+ matches: (state: 'disabled' | 'enabled') => boolean
422
+ context: {
423
+ activeStyle: StyleSchemaType['name'] | undefined
424
+ }
425
+ }
426
+ send: (event: StyleSelectorEvent) => void
427
+ }
428
+
429
+ /**
430
+ * @beta
431
+ */
432
+ export declare type StyleSelectorEvent = {
433
+ type: 'toggle'
434
+ style: StyleSchemaType['name']
435
+ }
436
+
437
+ /**
438
+ * @beta
439
+ */
440
+ export declare type ToolbarAnnotationSchemaType = AnnotationSchemaType & {
441
+ icon?: React.ComponentType
442
+ defaultValues?: Record<string, unknown>
443
+ shortcut?: KeyboardShortcut
444
+ }
445
+
446
+ /**
447
+ * @beta
448
+ */
449
+ export declare type ToolbarBlockObjectSchemaType = BlockObjectSchemaType & {
450
+ icon?: React.ComponentType
451
+ defaultValues?: Record<string, unknown>
452
+ shortcut?: KeyboardShortcut
453
+ }
454
+
455
+ /**
456
+ * @beta
457
+ */
458
+ export declare type ToolbarDecoratorSchemaType = DecoratorSchemaType & {
459
+ icon?: React.ComponentType
460
+ shortcut?: KeyboardShortcut
461
+ mutuallyExclusive?: ReadonlyArray<DecoratorDefinition['name']>
462
+ }
463
+
464
+ /**
465
+ * @beta
466
+ */
467
+ export declare type ToolbarInlineObjectSchemaType = InlineObjectSchemaType & {
468
+ icon?: React.ComponentType
469
+ defaultValues?: Record<string, unknown>
470
+ shortcut?: KeyboardShortcut
471
+ }
472
+
473
+ /**
474
+ * @beta
475
+ */
476
+ export declare type ToolbarListSchemaType = ListSchemaType & {
477
+ icon?: React.ComponentType
478
+ }
479
+
480
+ /**
481
+ * @beta
482
+ */
483
+ export declare type ToolbarSchema = {
484
+ decorators?: ReadonlyArray<ToolbarDecoratorSchemaType>
485
+ annotations?: ReadonlyArray<ToolbarAnnotationSchemaType>
486
+ lists?: ReadonlyArray<ToolbarListSchemaType>
487
+ blockObjects?: ReadonlyArray<ToolbarBlockObjectSchemaType>
488
+ inlineObjects?: ReadonlyArray<ToolbarInlineObjectSchemaType>
489
+ styles?: ReadonlyArray<ToolbarStyleSchemaType>
490
+ }
491
+
492
+ /**
493
+ * @beta
494
+ */
495
+ export declare type ToolbarStyleSchemaType = StyleSchemaType & {
496
+ icon?: React.ComponentType
497
+ shortcut?: KeyboardShortcut
498
+ }
499
+
500
+ /**
501
+ * @beta
502
+ * Manages the state, keyboard shortcut and available events for an annotation
503
+ * button.
504
+ *
505
+ * Note: This hook assumes that the button triggers a dialog for inputting
506
+ * the annotation value.
507
+ */
508
+ export declare function useAnnotationButton(props: {
509
+ schemaType: ToolbarAnnotationSchemaType
510
+ }): AnnotationButton
511
+
512
+ /**
513
+ * @beta
514
+ * Manages the state and available events for an annotation popover.
515
+ */
516
+ export declare function useAnnotationPopover(props: {
517
+ schemaTypes: ReadonlyArray<ToolbarAnnotationSchemaType>
518
+ }): AnnotationPopover
519
+
520
+ /**
521
+ * @beta
522
+ * Manages the state, keyboard shortcut and available events for a block
523
+ * object button.
524
+ *
525
+ * Note: This hook assumes that the button triggers a dialog for inputting
526
+ * the block object value.
527
+ */
528
+ export declare function useBlockObjectButton(props: {
529
+ schemaType: ToolbarBlockObjectSchemaType
530
+ }): BlockObjectButton
531
+
532
+ /**
533
+ * @beta
534
+ * Manages the state and available events for a block object popover.
535
+ */
536
+ export declare function useBlockObjectPopover(props: {
537
+ schemaTypes: ReadonlyArray<ToolbarBlockObjectSchemaType>
538
+ }): BlockObjectPopover
539
+
540
+ /**
541
+ * @beta
542
+ * Manages the state, keyboard shortcuts and available events for a decorator
543
+ * button and sets up mutually exclusive decorator behaviors.
544
+ */
545
+ export declare function useDecoratorButton(props: {
546
+ schemaType: ToolbarDecoratorSchemaType
547
+ }): DecoratorButton
548
+
549
+ /**
550
+ * @beta
551
+ */
552
+ export declare function useHistoryButtons(): HistoryButtons
553
+
554
+ /**
555
+ * @beta
556
+ * Manages the state, keyboard shortcut and available events for an inline
557
+ * object button.
558
+ *
559
+ * Note: This hook assumes that the button triggers a dialog for inputting
560
+ * the inline object value.
561
+ */
562
+ export declare function useInlineObjectButton(props: {
563
+ schemaType: ToolbarInlineObjectSchemaType
564
+ }): InlineObjectButton
565
+
566
+ /**
567
+ * @beta
568
+ * Manages the state and available events for an inline object popover.
569
+ */
570
+ export declare function useInlineObjectPopover(props: {
571
+ schemaTypes: ReadonlyArray<ToolbarInlineObjectSchemaType>
572
+ }): InlineObjectPopover
573
+
574
+ /**
575
+ * @beta
576
+ * Manages the state, keyboard shortcuts and available events for a list button.
577
+ */
578
+ export declare function useListButton(props: {
579
+ schemaType: ToolbarListSchemaType
580
+ }): ListButton
581
+
582
+ /**
583
+ * @beta
584
+ * Manages the state, keyboard shortcuts and available events for a style
585
+ * selector.
586
+ */
587
+ export declare function useStyleSelector(props: {
588
+ schemaTypes: ReadonlyArray<ToolbarStyleSchemaType>
589
+ }): StyleSelector
590
+
591
+ /**
592
+ * @beta
593
+ * Extend the editor's schema with default values, icons, shortcuts and more.
594
+ * This makes it easier to use the schema to render toolbars, forms and other
595
+ * UI components.
596
+ */
597
+ export declare function useToolbarSchema(props: {
598
+ extendDecorator?: (
599
+ decorator: DecoratorSchemaType,
600
+ ) => ToolbarDecoratorSchemaType
601
+ extendAnnotation?: (
602
+ annotation: AnnotationSchemaType,
603
+ ) => ToolbarAnnotationSchemaType
604
+ extendList?: (list: ListSchemaType) => ToolbarListSchemaType
605
+ extendBlockObject?: (
606
+ blockObject: BlockObjectSchemaType,
607
+ ) => ToolbarBlockObjectSchemaType
608
+ extendInlineObject?: (
609
+ inlineObject: InlineObjectSchemaType,
610
+ ) => ToolbarInlineObjectSchemaType
611
+ extendStyle?: (style: StyleSchemaType) => ToolbarStyleSchemaType
612
+ }): ToolbarSchema
613
+
614
+ export {}