wysimark-lite 0.25.32 → 0.25.34

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,1066 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as slate from 'slate';
3
+ import { Descendant, Editor, Element as Element$1, BaseEditor, NodeEntry, BaseRange, Location, Path, Text, BaseText } from 'slate';
4
+ import { HistoryEditor } from 'slate-history';
5
+ import { ReactEditor } from 'slate-react';
6
+ import { SetReturnType, SetOptional, UnionToIntersection, Simplify } from 'type-fest';
7
+ import react from 'react';
8
+ import { EditableProps as EditableProps$1, RenderElementProps, RenderLeafProps, RenderPlaceholderProps } from 'slate-react/dist/components/editable';
9
+
10
+ type OnImageChangeHandler = (file: File) => Promise<string>;
11
+ type OnFileSelectHandler = () => Promise<string | null>;
12
+ type ImageDialogState = {
13
+ url: string;
14
+ alt: string;
15
+ title: string;
16
+ imageSource: "url" | "file" | "select";
17
+ uploadedUrl?: string;
18
+ };
19
+ type WysimarkEditor = {
20
+ /**
21
+ * Private state for the wysimark editor.
22
+ */
23
+ wysimark: {
24
+ prevValue?: {
25
+ markdown: string;
26
+ children: Descendant[];
27
+ };
28
+ /**
29
+ * Handler for image change
30
+ */
31
+ onImageChange?: OnImageChangeHandler;
32
+ /**
33
+ * Handler for file selection (e.g. picking from Drive)
34
+ */
35
+ onFileSelect?: OnFileSelectHandler;
36
+ /**
37
+ * Persisted state for the image dialog
38
+ */
39
+ imageDialogState?: ImageDialogState;
40
+ /**
41
+ * Whether raw mode is disabled
42
+ */
43
+ disableRawMode?: boolean;
44
+ /**
45
+ * Whether task list is disabled
46
+ */
47
+ disableTaskList?: boolean;
48
+ /**
49
+ * Whether code block is disabled
50
+ */
51
+ disableCodeBlock?: boolean;
52
+ /**
53
+ * Whether highlight mark is disabled
54
+ */
55
+ disableHighlight?: boolean;
56
+ };
57
+ /**
58
+ * Public methods for the wysimark editor.
59
+ */
60
+ getMarkdown: () => string;
61
+ setMarkdown: (markdown: string) => void;
62
+ };
63
+
64
+ type UseEditorOptions = {
65
+ authToken?: string;
66
+ height?: string | number;
67
+ minHeight?: string | number;
68
+ maxHeight?: string | number;
69
+ /**
70
+ * Disable raw Markdown editing mode.
71
+ * When true, the raw mode toggle button will be hidden from the toolbar.
72
+ * Defaults to true (raw mode is disabled by default).
73
+ */
74
+ disableRawMode?: boolean;
75
+ /**
76
+ * Disable task list (checklist) functionality.
77
+ * When true, the task list button will be hidden from the toolbar.
78
+ */
79
+ disableTaskList?: boolean;
80
+ /**
81
+ * Disable code block functionality.
82
+ * When true, the code block button will be hidden from the toolbar.
83
+ */
84
+ disableCodeBlock?: boolean;
85
+ /**
86
+ * Disable highlight mark functionality.
87
+ * When true, the highlight button will be hidden from the toolbar.
88
+ * Defaults to true (highlight is disabled by default).
89
+ */
90
+ disableHighlight?: boolean;
91
+ };
92
+ declare function useEditor({ authToken, height, minHeight, maxHeight, disableRawMode, disableTaskList, disableCodeBlock, disableHighlight, }?: UseEditorOptions): Editor & ReactEditor & WysimarkEditor;
93
+
94
+ /**
95
+ * SinkEditor just adds a `sink` object where we drop all of our sink
96
+ * related data on.
97
+ */
98
+ type SinkEditor = {
99
+ /**
100
+ * a master Element is one that has one or more elements that are depedant
101
+ * on it. For example, a `table` Element. For clarity, a `table-row` Element
102
+ * is not considered a master Element. Only the top-most element is.
103
+ *
104
+ * One use for identify a master is for adding a block quote. We want the
105
+ * block quote to always surround the master Element. A block-quote that
106
+ * surrounded a table-row, for example, would not make sense.
107
+ */
108
+ isMaster: (node: Element$1) => boolean;
109
+ /**
110
+ * a slave Element is one that is dependant on another Element. For example,
111
+ * `table-row`, `table-cell` and `table-cotent` elements are all considered
112
+ * slave elements.
113
+ *
114
+ * At the time of writing, I haven't figured out a use case for a slave
115
+ * element actually...
116
+ */
117
+ isSlave: (node: Element$1) => boolean;
118
+ isStandalone: (node: Element$1) => boolean;
119
+ sink: {
120
+ plugins: BasePluginPolicy[];
121
+ };
122
+ };
123
+ type FullSinkEditor = SinkEditor & BaseEditor & ReactEditor & HistoryEditor;
124
+
125
+ /**
126
+ * On the editor, there are several methods that return void that are used to
127
+ * override default editor behaviors.
128
+ *
129
+ * These are referred to as Overrideable core actions in the docs.
130
+ *
131
+ * - deleteBackward
132
+ * - deleteForward
133
+ * - deleteFragment
134
+ * - insertBreak
135
+ * - insertFragment
136
+ * - insertNode
137
+ * - insertText
138
+ * - normalizeNode
139
+ *
140
+ * When there are plugins, Sink tries to find a plugin to handle the event and
141
+ * if it cannot, uses the previously defined handler. For example, the user may
142
+ * have specified `editor.insertBreak` on the `editor` earlier and that will
143
+ * be called after all the plugins have been searched.
144
+ *
145
+ * We search through the plugins from the first to the last plugin.
146
+ *
147
+ * In a plugin, we specify the functions like we don on the editor but the
148
+ * return value informs us how the plugin should proceed after. The return
149
+ * value generally indicates whether the plugin has handled the event with one
150
+ * special case:
151
+ *
152
+ * - `true`: If the return type is `true` then the plugin has indicated it has
153
+ * handled the event and no further processing is required. The handlers in
154
+ * all remaining plugins are skipped.
155
+ *
156
+ * - `false`: If the return type is `false` then the plugin has indicated it has
157
+ * not handled the event and will continue through the rest of the plugins
158
+ * looking for a plugin to handle the event.
159
+ *
160
+ * - `() => void`: If the return tyep is a function, the plugin has indicated
161
+ * it has not handled the event, but that it would like to register another
162
+ * function that should execute after the actual event handler has been
163
+ * executed. In particular, this is used when in certain situations we may
164
+ * want a normalizer to execute after the event handler has triggered. This
165
+ * is used in the `normalize-after-delete-plugin` for example.
166
+ *
167
+ * NOTE:
168
+ *
169
+ * This seems like an unusual specification at first glance and a purist might
170
+ * argue, this could be handled more succinctly with a `next` function passed
171
+ * in as the final argument.
172
+ *
173
+ * Here's why I elected to go this route but it boils down to the fact that
174
+ * `next` functions make the function difficult to reason about.
175
+ *
176
+ * - 99% of the true, we want to indicate whether we handled the function or
177
+ * not and for that use case, true/false is simple to understand and natural.
178
+ * In the case where we need something to happen after, returning a function
179
+ * is unusual, but still easy to reason about. Also, the exclusivity of
180
+ * the function return is nice in that it assumes that the event wasn't
181
+ * handled, and of course, the function return would only ever be used if the
182
+ * function indeed wasn't handled. For if it was handled, there would be no
183
+ * need to have the after function because that could just be in the original
184
+ * function handler.
185
+ *
186
+ * - To use this, you have to build nested contexts that are always hard to
187
+ * reason about because you are passing a set of contexts from inner child
188
+ * to outer parent. This created difficult to comprehend complexity in the
189
+ * old Slate plugins architecture and is probably why it was abandoned.
190
+ *
191
+ * - It's also harder to type properly and to reason about it. The argument
192
+ * list changes in length depending on the function; furthermore, in some
193
+ * cases it is natural to ignore the arguments but we'd have to accept blank
194
+ * arguments that are unused to access the `next` function.
195
+ *
196
+ * - It's hard to debug. The plugin system as it currently is designed to
197
+ * execute linearly, instead of in a nested fashion. This makes it easy to
198
+ * add debug code, and know what happens before and after each step.
199
+ */
200
+ type VoidActionReturn = boolean | (() => void);
201
+
202
+ type RenderEditableProps = {
203
+ attributes: EditableProps$1;
204
+ Editable: react.ComponentType<EditableProps$1>;
205
+ };
206
+ type RenderEditable = (props: RenderEditableProps) => react.ReactElement;
207
+ /**
208
+ * The return type of the BasePluginFn which specifies how the Plugin is
209
+ * supposed to behave.
210
+ */
211
+ type BasePluginPolicy = {
212
+ name: string;
213
+ editor?: {
214
+ isInline?: (element: Element) => boolean | void;
215
+ isVoid?: (element: Element) => boolean | void;
216
+ isMaster?: (element: Element) => boolean | void;
217
+ isSlave?: (element: Element) => boolean | void;
218
+ isStandalone?: (element: Element) => boolean | void;
219
+ deleteBackward?: (unit: "character" | "word" | "line" | "block") => VoidActionReturn;
220
+ deleteForward?: (unit: "character" | "word" | "line" | "block") => VoidActionReturn;
221
+ deleteFragment?: () => VoidActionReturn;
222
+ insertBreak?: () => VoidActionReturn;
223
+ insertFragment?: (fragment: Node[]) => VoidActionReturn;
224
+ insertNode?: (node: Node) => VoidActionReturn;
225
+ insertText?: (text: string) => VoidActionReturn;
226
+ normalizeNode?: (entry: NodeEntry) => VoidActionReturn;
227
+ };
228
+ renderEditable?: RenderEditable;
229
+ editableProps?: {
230
+ decorate?: ((entry: NodeEntry) => BaseRange[]) | undefined;
231
+ renderElement?: (props: RenderElementProps) => react.ReactElement | undefined;
232
+ renderLeaf?: (props: RenderLeafProps) => react.ReactElement | undefined;
233
+ renderPlaceholder?: (props: RenderPlaceholderProps) => react.ReactElement;
234
+ onKeyDown?: EditableVoidToBooleanHandlerType<"onKeyDown">;
235
+ onKeyUp?: EditableVoidToBooleanHandlerType<"onKeyDown">;
236
+ onPaste?: EditableVoidToBooleanHandlerType<"onPaste">;
237
+ onDrop?: EditableVoidToBooleanHandlerType<"onDrop">;
238
+ };
239
+ };
240
+ type EditableVoidToBooleanHandlerType<K extends keyof EditableProps$1> = SetReturnType<NonNullable<EditableProps$1[K]>, boolean>;
241
+
242
+ /**
243
+ * IMPORTANT!
244
+ *
245
+ * NEVER!
246
+ *
247
+ * refer to a type that is defined in the `slate` package. This is because
248
+ * any reference to a Slate type will cause a circular reference type error that
249
+ * is very hard to track down.
250
+ *
251
+ * NOTE: This kind of happens in that `Element` will often have a reference to
252
+ * `Descendant` but it looks like this is okay; however, let's not tempt fate
253
+ * by only using it where the definition is absolutely necessary.
254
+ *
255
+ * ALWAYS!
256
+ *
257
+ * Be explicity about return types. If they are inferred through the return
258
+ * type, because we need to provide `Editor` as an argument in certain cases,
259
+ * we don't want to accidentally have `Editor` be provided as a return type
260
+ * or this will create the circular reference.
261
+ */
262
+ type BasePluginSchema = {
263
+ Name: string;
264
+ Options: Record<string, unknown>;
265
+ Editor: Record<string, unknown>;
266
+ Element: {
267
+ type: string;
268
+ };
269
+ Text: Record<string, unknown>;
270
+ };
271
+ /**
272
+ * These are the PluginTypes that are accepted as inputs into `createPlugin`
273
+ * which has the same basic signature as `BasePluginTypes` but some of the
274
+ * types are optional.
275
+ *
276
+ * These `InputPluginTypes` need to have their optional types filled in with
277
+ * defaults before they can be used.
278
+ *
279
+ * See `NormalizeInputPluginTypes`
280
+ */
281
+ type InputPluginSchema = SetOptional<BasePluginSchema, "Options" | "Editor" | "Element" | "Text">;
282
+ /**
283
+ * Takes an `InputPluginSchema` (that has some optional types) and turns them
284
+ * into a regular PluginTypes with any missing types filled in with defaults.
285
+ */
286
+ type NormalizeInputPluginSchema<T extends InputPluginSchema> = {
287
+ Name: T["Name"];
288
+ Options: T["Options"] extends object ? T["Options"] : Record<never, never>;
289
+ Editor: T["Editor"] extends object ? T["Editor"] : Record<never, never>;
290
+ Element: T["Element"] extends object ? T["Element"] : never;
291
+ Text: T["Text"] extends object ? T["Text"] : Record<never, never>;
292
+ };
293
+
294
+ /**
295
+ * Shape of a PluginFn (Plugin Function).
296
+ */
297
+ type BasePluginFn = (editor: FullSinkEditor, options: Record<string, unknown>, helpers: {
298
+ createPolicy: (value: unknown) => unknown;
299
+ }) => BasePluginPolicy;
300
+
301
+ /**
302
+ * IMPORTANT!
303
+ *
304
+ * NEVER!
305
+ *
306
+ * refer to a type that is defined in the `slate` package. This is because
307
+ * any reference to a Slate type will cause a circular reference type error that
308
+ * is very hard to track down.
309
+ *
310
+ * NOTE: This kind of happens in that `Element` will often have a reference to
311
+ * `Descendant` but it looks like this is okay; however, let's not tempt fate
312
+ * by only using it where the definition is absolutely necessary.
313
+ *
314
+ * ALWAYS!
315
+ *
316
+ * Be explicity about return types. If they are inferred through the return
317
+ * type, because we need to provide `Editor` as an argument in certain cases,
318
+ * we don't want to accidentally have `Editor` be provided as a return type
319
+ * or this will create the circular reference.
320
+ */
321
+
322
+ /**
323
+ * When a Plugin is created using the `createPlugin` method, it returns a
324
+ * Plugin.
325
+ */
326
+ type BasePlugin = {
327
+ fn: BasePluginFn;
328
+ __types__: BasePluginSchema;
329
+ };
330
+ /**
331
+ * When a Plugin is created using `createPlugin` we must
332
+ */
333
+ type TypedPlugin<T extends InputPluginSchema> = {
334
+ fn: BasePluginFn;
335
+ __types__: NormalizeInputPluginSchema<T>;
336
+ };
337
+
338
+ type ExtractCustomTypes<TA extends Array<BasePlugin>> =
339
+ /**
340
+ * This code takes an array of types and merges them together into a union.
341
+ */
342
+ TA extends Array<{
343
+ __types__: infer U;
344
+ }> ? {
345
+ Editor: SinkEditor & BaseEditor & ReactEditor & HistoryEditor & UnionToIntersection<U extends {
346
+ Editor: infer E;
347
+ } ? E : never>;
348
+ Element: U extends {
349
+ Element: infer E;
350
+ } ? E : never;
351
+ Text: Simplify<UnionToIntersection<U extends {
352
+ Text: infer T;
353
+ } ? T : never>>;
354
+ Options: Simplify<UnionToIntersection<U extends {
355
+ Options: infer T;
356
+ } ? T : never>>;
357
+ } : never;
358
+
359
+ /**
360
+ * Defines a value you'd find in a function's parameters as a replacement for
361
+ * `at`. The benefit of using `BetterAt` is that it allows you to search
362
+ * using an `Element`.
363
+ */
364
+ type BetterAt = Location | Element$1 | null;
365
+
366
+ /**
367
+ * The TargetElement can be specified either as the actual value or as a
368
+ * function that takes a srcElement and returns the targetElement.
369
+ */
370
+ type TargetElement<T extends Element$1 = Element$1> = Omit<T, "children"> | ((srcElement: Element$1) => Omit<T, "children">);
371
+
372
+ type PlaceholderEditor = {
373
+ placeholder: Record<string, never>;
374
+ };
375
+ type PlaceholderPluginCustomTypes = {
376
+ Name: "placeholder";
377
+ Editor: PlaceholderEditor;
378
+ };
379
+
380
+ declare function createImageMethods(editor: Editor): {
381
+ noop: () => void;
382
+ insertImageFromUrl: (url: string, alt?: string | undefined, title?: string | undefined) => void;
383
+ };
384
+
385
+ type ImageSize = {
386
+ width: number;
387
+ height: number;
388
+ };
389
+ type ImageMethods = ReturnType<typeof createImageMethods>;
390
+ type ImagePluginConfig = {
391
+ /**
392
+ * When an image is uploaded, the plugin needs to decide whether the image
393
+ * should be an inline image (like an icon that displays within a line of
394
+ * text) or a block image (like a photo that appears as its own block).
395
+ *
396
+ * This setting is the maximum size of an image for it to be defaulted to an
397
+ * inline image.
398
+ *
399
+ * NOTE:
400
+ *
401
+ * The user can convert an image from one image type to the other manually.
402
+ */
403
+ maxInitialInlineImageSize: ImageSize;
404
+ /**
405
+ * When an image is first uploaded, it may come in at a large size but for
406
+ * some applications, you don't want the image to overwhelm the page,
407
+ * like when the editor is visually a small size.
408
+ *
409
+ * This specifies the maximum initial size when an image is first uploaded
410
+ * to the page. The user can resize to a larger size.
411
+ *
412
+ * If the value is null, the image will be displayed at full size.
413
+ *
414
+ * NOTE:
415
+ *
416
+ * This is the displayed image width. On retina displays, the actualy image
417
+ * file delivered to the browser may be a multiple of the provided value.
418
+ */
419
+ maxInitialImageSize: ImageSize | null;
420
+ /**
421
+ * When an image is displayed at full size, you may still want to limit the
422
+ * size of the image file.
423
+ *
424
+ * NOTE:
425
+ *
426
+ * This is the maximum visual image
427
+ */
428
+ maxImageSize: ImageSize;
429
+ imageBlockPresets: ImageSizePreset[];
430
+ imageInlinePresets: ImageSizePreset[];
431
+ };
432
+ type ImagePluginOptions = {
433
+ image: Partial<ImagePluginConfig>;
434
+ };
435
+ type ImageEditor = {
436
+ image: ImageMethods & ImagePluginConfig;
437
+ };
438
+ type ImageSharedElement = {
439
+ /**
440
+ * The `url` represents either
441
+ *
442
+ * - a `hashUrl` that begins with a `#` during the upload process which
443
+ * represents a unique id reference to a Zustand store where the actual
444
+ * information about the upload is kept.
445
+ * - The actual `url` of the uploaded file. When the file is saved, the
446
+ * `hashUrl` will be converted to the actual `url` of the file.
447
+ */
448
+ url: string;
449
+ title?: string;
450
+ alt?: string;
451
+ bytes?: number;
452
+ /**
453
+ * If the `maxWidth` and `maxHeight` are present, it indicates that the image
454
+ * is resizable.
455
+ *
456
+ * If they are not present, it indicates that the `width` and `height` should
457
+ * be used, but they cannot be resized.
458
+ *
459
+ * If the `width` and `height` are also not present, it indicates we are not
460
+ * aware of the current size of the image, so just display it.
461
+ */
462
+ srcWidth?: number;
463
+ srcHeight?: number;
464
+ width?: number;
465
+ height?: number;
466
+ children: Descendant[];
467
+ };
468
+ /**
469
+ * Default for larger images, over 48px
470
+ *
471
+ * Larger images can be converted to inline images though.
472
+ */
473
+ type ImageBlockElement = {
474
+ type: "image-block";
475
+ } & ImageSharedElement;
476
+ /**
477
+ * Default for smaller images, 48px and less
478
+ *
479
+ * Smaller images can be converted to block images though.
480
+ */
481
+ type ImageInlineElement = {
482
+ type: "image-inline";
483
+ } & ImageSharedElement;
484
+ type ImagePluginCustomTypes = {
485
+ Name: "image";
486
+ Editor: ImageEditor;
487
+ Element: ImageBlockElement | ImageInlineElement;
488
+ Options: ImagePluginOptions;
489
+ };
490
+ /**
491
+ * A preset is defined either as a bound or as a scale:
492
+ *
493
+ * - bounds: The image will be placed within the bounds.
494
+ * - scale: The image will be scaled to the given `scale` value. The max
495
+ * value should be `1`.
496
+ */
497
+ type ImageSizePreset = {
498
+ name: string;
499
+ title: string;
500
+ type: "bounds";
501
+ width: number;
502
+ height: number;
503
+ } | {
504
+ name: string;
505
+ title: string;
506
+ type: "scale";
507
+ scale: number;
508
+ };
509
+
510
+ type ToolbarEditor = {
511
+ toolbar: {
512
+ height?: string | number;
513
+ minHeight?: string | number;
514
+ maxHeight?: string | number;
515
+ showUploadButtons?: boolean;
516
+ };
517
+ };
518
+ type ToolbarOptions = {
519
+ toolbar: {
520
+ height?: string | number;
521
+ minHeight?: string | number;
522
+ maxHeight?: string | number;
523
+ showUploadButtons?: boolean;
524
+ };
525
+ };
526
+ type ToolbarPluginCustomTypes = {
527
+ Name: "toolbar";
528
+ Editor: ToolbarEditor;
529
+ Options: ToolbarOptions;
530
+ };
531
+
532
+ type ThemeEditor = {
533
+ theme: true;
534
+ };
535
+ type ThemePluginCustomTypes = {
536
+ Name: "theme";
537
+ Editor: ThemeEditor;
538
+ };
539
+
540
+ type CollapsibleParagraphEditor = {
541
+ collapsibleParagraph: {
542
+ convertParagraph: () => void;
543
+ };
544
+ };
545
+ type ParagraphElement = {
546
+ type: "paragraph";
547
+ __collapsible?: true;
548
+ children: Descendant[];
549
+ };
550
+ type CollapsibleParagraphPluginCustomTypes = {
551
+ Name: "collapsible-paragraph";
552
+ Editor: CollapsibleParagraphEditor;
553
+ Element: ParagraphElement;
554
+ };
555
+
556
+ type NormalizeAfterDeleteEditor = {
557
+ normalizeAfterDelete: true;
558
+ };
559
+ type NormalizeAfterDeletePluginCustomTypes = {
560
+ Name: "normalize-after-delete";
561
+ Editor: NormalizeAfterDeleteEditor;
562
+ };
563
+
564
+ type AtomicDeleteEditor = {
565
+ atomicDelete: true;
566
+ };
567
+ type AtomicDeletePluginCustomTypes = {
568
+ Name: "atomic-delete";
569
+ Editor: AtomicDeleteEditor;
570
+ };
571
+
572
+ declare function createListMethods(editor: Editor): {
573
+ indent: () => boolean;
574
+ outdent: () => boolean;
575
+ convertUnorderedList: (allowToggle: boolean) => void;
576
+ convertOrderedList: (allowToggle: boolean) => void;
577
+ convertTaskList: (allowToggle: boolean) => void;
578
+ insertBreak: () => boolean;
579
+ toggleTaskListItem: (args_0?: {
580
+ at?: BetterAt | undefined;
581
+ } | undefined) => boolean;
582
+ getListDepth: () => number;
583
+ canIncreaseDepth: () => boolean;
584
+ canDecreaseDepth: () => boolean;
585
+ increaseDepth: () => void;
586
+ decreaseDepth: () => void;
587
+ };
588
+
589
+ /**
590
+ * List Editor
591
+ */
592
+ type ListEditor = {
593
+ list: ReturnType<typeof createListMethods>;
594
+ };
595
+ /**
596
+ * Ordered List Item Element
597
+ */
598
+ type OrderedListItemElement = {
599
+ type: "ordered-list-item";
600
+ depth: number;
601
+ __firstAtDepth?: boolean;
602
+ children: Descendant[];
603
+ };
604
+ /**
605
+ * Unordered List Item Element
606
+ */
607
+ type UnorderedListItemElement = {
608
+ type: "unordered-list-item";
609
+ depth: number;
610
+ __firstAtDepth?: boolean;
611
+ children: Descendant[];
612
+ };
613
+ /**
614
+ * Checkable Task List Item Element
615
+ */
616
+ type TaskListItemElement = {
617
+ type: "task-list-item";
618
+ depth: number;
619
+ __firstAtDepth?: boolean;
620
+ checked: boolean;
621
+ children: Descendant[];
622
+ };
623
+ /**
624
+ * List Plugins Custom Types
625
+ */
626
+ type ListPluginCustomTypes = {
627
+ Name: "list";
628
+ Editor: ListEditor;
629
+ Element: OrderedListItemElement | UnorderedListItemElement | TaskListItemElement;
630
+ };
631
+
632
+ declare function createHorizontalRuleMethods(editor: Editor): {
633
+ insertHorizontalRule: () => boolean;
634
+ };
635
+
636
+ type HorizontalRuleMethods = ReturnType<typeof createHorizontalRuleMethods>;
637
+ type HorizontalRuleEditor = {
638
+ horizontalRule: HorizontalRuleMethods;
639
+ };
640
+ type HorizontalRuleElement = {
641
+ type: "horizontal-rule";
642
+ children: [{
643
+ text: string;
644
+ }];
645
+ };
646
+ type HorizontalRulePluginCustomTypes = {
647
+ Name: "horizontal-rule";
648
+ Editor: HorizontalRuleEditor;
649
+ Element: HorizontalRuleElement;
650
+ };
651
+
652
+ /**
653
+ * Alignment of Table Columns
654
+ */
655
+ type TableColumnAlign = "left" | "center" | "right";
656
+ /**
657
+ * Table Column values
658
+ */
659
+ type TableColumn = {
660
+ align: TableColumnAlign;
661
+ };
662
+ /**
663
+ * Table Element
664
+ */
665
+ type TableElement = {
666
+ type: "table";
667
+ columns: TableColumn[];
668
+ children: TableRowElement[];
669
+ };
670
+ /**
671
+ * Table Row Element
672
+ */
673
+ type TableRowElement = {
674
+ type: "table-row";
675
+ children: TableCellElement[];
676
+ };
677
+ /**
678
+ * Table Cell Element
679
+ *
680
+ * The children of a `TdElement` is exactly one `ParagraphElement`.
681
+ *
682
+ * This is a good choice for Slate because copying and pasting a range of
683
+ * elements will split the lowest child element by default. If the child of
684
+ * a `TdElement` is a leaf, then we split the `TdElement` which is never what
685
+ * we want.
686
+ *
687
+ * Instead, by having a lower level element, the `ParagraphElement`, we allow
688
+ * that to be split.
689
+ *
690
+ * But of course, insertion means we have many child elements in the `TdElement`
691
+ * but these are easier to fix using normalization. We can keep iterating
692
+ * through normalizations until we end up with a single Paragraph.
693
+ */
694
+ type TableCellElement = {
695
+ type: "table-cell";
696
+ x?: number;
697
+ y?: number;
698
+ children: TableContentElement[];
699
+ };
700
+ type TableContentElement = {
701
+ type: "table-content";
702
+ children: Descendant[];
703
+ };
704
+
705
+ /**
706
+ * The TableInfo object that includes quick access information starting from a
707
+ * cell in a table including information about the row and the table.
708
+ *
709
+ * NOTE:
710
+ *
711
+ * This is flat and not nested because it makes destructuring easier, for
712
+ * example, in the table methods.
713
+ */
714
+ type TableInfo = {
715
+ tableElement: TableElement;
716
+ tablePath: Path;
717
+ tableColumns: TableColumn[];
718
+ rowElement: TableRowElement;
719
+ rowPath: Path;
720
+ rowIndex: number;
721
+ rowCount: number;
722
+ cellElement: TableCellElement;
723
+ cellPath: Path;
724
+ cellIndex: number;
725
+ cellCount: number;
726
+ };
727
+
728
+ declare function createAnchorMethods(editor: Editor): {
729
+ insertLink: (args_0: string, args_1?: string | undefined, args_2?: {
730
+ select?: boolean | undefined;
731
+ title?: string | undefined;
732
+ } | undefined) => void;
733
+ removeLink: (args_0: {
734
+ at?: BetterAt | undefined;
735
+ }) => boolean;
736
+ editLink: (args_0: {
737
+ href: string;
738
+ title?: string | undefined;
739
+ text?: string | undefined;
740
+ }, args_1: {
741
+ at?: BetterAt | undefined;
742
+ }) => boolean;
743
+ };
744
+
745
+ type AnchorMethods = ReturnType<typeof createAnchorMethods>;
746
+ type AnchorEditor = {
747
+ anchor: AnchorMethods;
748
+ };
749
+ type AnchorElement = {
750
+ type: "anchor";
751
+ href: string;
752
+ target?: string;
753
+ title?: string;
754
+ children: Descendant[];
755
+ };
756
+ type AnchorPluginCustomTypes = {
757
+ Name: "anchor";
758
+ Editor: AnchorEditor;
759
+ Element: AnchorElement;
760
+ };
761
+
762
+ declare function createHeadingMethods(editor: Editor): {
763
+ convertHeading: (level: 1 | 2 | 3 | 4 | 5 | 6, allowToggle: boolean) => void;
764
+ isHeadingActive: (level: 1 | 2 | 3 | 4 | 5 | 6) => boolean;
765
+ };
766
+
767
+ type HeadingEditor = {
768
+ heading: ReturnType<typeof createHeadingMethods>;
769
+ };
770
+ type HeadingElement = {
771
+ type: "heading";
772
+ /**
773
+ * NOTE:
774
+ *
775
+ * Don't extract these into a new type. It's easier to just repeat this and
776
+ * there's less indirection.
777
+ */
778
+ level: 1 | 2 | 3 | 4 | 5 | 6;
779
+ children: Descendant[];
780
+ };
781
+ type HeadingPluginCustomTypes = {
782
+ Name: "heading";
783
+ Editor: HeadingEditor;
784
+ Element: HeadingElement;
785
+ };
786
+
787
+ type BlockQuoteEditor = {
788
+ supportsBlockQuote: true;
789
+ blockQuotePlugin: {
790
+ indent: () => void;
791
+ outdent: () => void;
792
+ isActive: () => boolean;
793
+ increaseDepth: () => void;
794
+ decreaseDepth: () => void;
795
+ canIncreaseDepth: () => boolean;
796
+ canDecreaseDepth: () => boolean;
797
+ };
798
+ };
799
+ type BlockQuoteElement = {
800
+ type: "block-quote";
801
+ children: Descendant[];
802
+ };
803
+ type BlockQuotePluginCustomTypes = {
804
+ Name: "block-quote";
805
+ Editor: BlockQuoteEditor;
806
+ Element: BlockQuoteElement;
807
+ };
808
+
809
+ declare function createCodeBlockMethods(editor: Editor): {
810
+ createCodeBlock: (args_0: {
811
+ language: BuiltInLanguage;
812
+ }) => void;
813
+ setCodeBlockLanguage: (language: BuiltInLanguage, options?: {
814
+ at?: BetterAt | undefined;
815
+ } | undefined) => boolean;
816
+ };
817
+
818
+ type CodeBlockMethods = ReturnType<typeof createCodeBlockMethods>;
819
+ type BuiltInLanguage = "text" | "html" | "svg" | "markup" | "css" | "javascript" | "js" | "java" | "c" | "clike";
820
+ type CodeBlockEditor = {
821
+ codeBlock: CodeBlockMethods;
822
+ };
823
+ /**
824
+ * The code block element is the root element of a code block.
825
+ */
826
+ type CodeBlockElement = {
827
+ type: "code-block";
828
+ /**
829
+ * The language of the code block. Can accept any string because Markdown can
830
+ * accept any string; however, the built-in Prism languages are defined in:
831
+ * `BuiltInLanguage`
832
+ */
833
+ language: string;
834
+ children: CodeBlockLineElement[];
835
+ };
836
+ type CodeBlockLineElement = {
837
+ type: "code-block-line";
838
+ children: Text[];
839
+ };
840
+ type CodeBlockPluginCustomTypes = {
841
+ Name: "code-block";
842
+ Editor: CodeBlockEditor;
843
+ Element: CodeBlockElement | CodeBlockLineElement;
844
+ Text: {
845
+ text: string;
846
+ prismToken?: string;
847
+ };
848
+ };
849
+
850
+ /**
851
+ * HTML block element for preserving raw HTML content
852
+ */
853
+ type HtmlBlockElement = {
854
+ type: "html-block";
855
+ /**
856
+ * The raw HTML content
857
+ */
858
+ html: string;
859
+ children: Text[];
860
+ };
861
+ type HtmlBlockPluginCustomTypes = {
862
+ Name: "html-block";
863
+ Editor: Record<string, never>;
864
+ Element: HtmlBlockElement;
865
+ };
866
+
867
+ declare function createTableMethods(editor: Editor): {
868
+ getTableInfo: (args_0?: {
869
+ at?: ImageBlockElement | ImageInlineElement | ParagraphElement | OrderedListItemElement | UnorderedListItemElement | TaskListItemElement | HorizontalRuleElement | TableElement | TableRowElement | TableCellElement | TableContentElement | HtmlBlockElement | CodeBlockElement | CodeBlockLineElement | BlockQuoteElement | HeadingElement | AnchorElement | slate.Location | null | undefined;
870
+ } | undefined) => TableInfo | undefined;
871
+ insertTable: (args_0: number, args_1: number, args_2?: {
872
+ at?: slate.Location | null | undefined;
873
+ } | undefined) => boolean;
874
+ insertColumn: (args_0?: {
875
+ offset?: 0 | 1 | undefined;
876
+ at?: BetterAt | undefined;
877
+ } | undefined) => boolean;
878
+ insertRow: (args_0?: {
879
+ at?: BetterAt | undefined;
880
+ offset?: 0 | 1 | undefined;
881
+ } | undefined) => boolean;
882
+ removeTable: () => boolean;
883
+ removeColumn: (args_0?: {
884
+ at?: BetterAt | undefined;
885
+ } | undefined) => boolean | undefined;
886
+ removeRow: (args_0?: {
887
+ at?: BetterAt | undefined;
888
+ } | undefined) => boolean;
889
+ tabForward: () => boolean;
890
+ tabBackward: () => boolean | undefined;
891
+ shiftEnterForward: () => boolean;
892
+ selectCell: (args_0?: {
893
+ at?: BetterAt | undefined;
894
+ } | undefined) => boolean;
895
+ down: () => boolean;
896
+ up: () => boolean;
897
+ setTableColumnAlign: (options: {
898
+ align: "center" | "left" | "right";
899
+ }) => boolean;
900
+ };
901
+
902
+ type TableEditor = {
903
+ supportsTable: true;
904
+ tablePlugin: ReturnType<typeof createTableMethods>;
905
+ };
906
+ type TablePluginCustomTypes = {
907
+ Name: "table";
908
+ Editor: TableEditor;
909
+ Element: TableElement | TableRowElement | TableCellElement | TableContentElement;
910
+ };
911
+
912
+ type InlineCodeEditor = {
913
+ inlineCode: {
914
+ toggleInlineCode: () => void;
915
+ };
916
+ };
917
+ type InlineCodeText = {
918
+ text: string;
919
+ code?: true;
920
+ };
921
+ type InlineCodePluginCustomTypes = {
922
+ Name: "inline-code";
923
+ Editor: InlineCodeEditor;
924
+ Text: InlineCodeText;
925
+ };
926
+
927
+ declare function createMarksMethods(editor: Editor): {
928
+ removeMarks: (args_0?: {
929
+ at?: slate.Location | null | undefined;
930
+ } | undefined) => void;
931
+ toggleMark: (args_0: "bold" | "strike" | "text" | "prismToken" | "code" | "italic" | "underline" | "highlight", args_1?: "bold" | "strike" | "text" | "prismToken" | "code" | "italic" | "underline" | "highlight" | undefined, args_2?: {
932
+ at?: slate.Location | null | undefined;
933
+ } | undefined) => void;
934
+ toggleBold: () => void;
935
+ toggleItalic: () => void;
936
+ toggleUnderline: () => void;
937
+ toggleStrike: () => void;
938
+ toggleHighlight: () => void;
939
+ };
940
+
941
+ type MarksEditor = {
942
+ /**
943
+ * IMPORTANT:
944
+ *
945
+ * This cannot be named `marks` because it conflicts with the `editor.marks`
946
+ * built into the BaseEditor.j
947
+ */
948
+ marksPlugin: ReturnType<typeof createMarksMethods>;
949
+ activeMarks?: {
950
+ bold?: boolean;
951
+ italic?: boolean;
952
+ underline?: boolean;
953
+ strike?: boolean;
954
+ highlight?: boolean;
955
+ };
956
+ };
957
+ type MarksText = {
958
+ text: string;
959
+ bold?: true;
960
+ italic?: true;
961
+ underline?: true;
962
+ strike?: true;
963
+ highlight?: true;
964
+ };
965
+ type MarksPluginCustomTypes = {
966
+ Name: "marks";
967
+ Editor: MarksEditor;
968
+ Text: MarksText;
969
+ };
970
+
971
+ /**
972
+ * A type with generic for `convertElements` (below) to be used with the curry
973
+ * method. TypeScript, unfortunately, cannot automatically curry generics for
974
+ * us so we have to do it manually.
975
+ */
976
+ type CurriedConvertElements = <T extends Element$1 = Element$1>(matchForToggle: (element: Element$1) => boolean, targetElement: TargetElement<T>, allowToggle: boolean) => void;
977
+
978
+ declare function createConvertElementMethods(editor: Editor): {
979
+ convertElementTypes: string[];
980
+ addConvertElementType: (type: "anchor" | "heading" | "block-quote" | "html-block" | "table" | "horizontal-rule" | "code-block" | "paragraph" | "image-block" | "image-inline" | "ordered-list-item" | "unordered-list-item" | "task-list-item" | "table-row" | "table-cell" | "table-content" | "code-block-line" | ("anchor" | "heading" | "block-quote" | "html-block" | "table" | "horizontal-rule" | "code-block" | "paragraph" | "image-block" | "image-inline" | "ordered-list-item" | "unordered-list-item" | "task-list-item" | "table-row" | "table-cell" | "table-content" | "code-block-line")[]) => void;
981
+ isConvertibleElement: (element: ImageBlockElement | ImageInlineElement | ParagraphElement | OrderedListItemElement | UnorderedListItemElement | TaskListItemElement | HorizontalRuleElement | TableElement | TableRowElement | TableCellElement | TableContentElement | HtmlBlockElement | CodeBlockElement | CodeBlockLineElement | BlockQuoteElement | HeadingElement | AnchorElement) => boolean;
982
+ convertElements: CurriedConvertElements;
983
+ };
984
+
985
+ type ConvertElementEditor = {
986
+ convertElement: ReturnType<typeof createConvertElementMethods>;
987
+ };
988
+ type ConvertElementPluginCustomTypes = {
989
+ Name: "convert-element";
990
+ Editor: ConvertElementEditor;
991
+ };
992
+
993
+ declare function createPasteMarkdownMethods(editor: Editor): {
994
+ pasteMarkdown: (markdown: string) => void;
995
+ };
996
+
997
+ type PasteMarkdownMethods = ReturnType<typeof createPasteMarkdownMethods>;
998
+ type PasteMarkdownEditor = {
999
+ pasteMarkdown: PasteMarkdownMethods;
1000
+ };
1001
+ type PasteMarkdownPluginCustomTypes = {
1002
+ Name: "paste-markdown";
1003
+ Editor: PasteMarkdownEditor;
1004
+ };
1005
+
1006
+ declare const plugins: (TypedPlugin<PasteMarkdownPluginCustomTypes> | TypedPlugin<ConvertElementPluginCustomTypes> | TypedPlugin<AnchorPluginCustomTypes> | TypedPlugin<HeadingPluginCustomTypes> | TypedPlugin<MarksPluginCustomTypes> | TypedPlugin<InlineCodePluginCustomTypes> | TypedPlugin<BlockQuotePluginCustomTypes> | TypedPlugin<CodeBlockPluginCustomTypes> | TypedPlugin<HtmlBlockPluginCustomTypes> | TypedPlugin<TablePluginCustomTypes> | TypedPlugin<HorizontalRulePluginCustomTypes> | TypedPlugin<{
1007
+ Name: "trailing-block";
1008
+ Editor: {
1009
+ allowTrailingBlock: true;
1010
+ };
1011
+ }> | TypedPlugin<ListPluginCustomTypes> | TypedPlugin<AtomicDeletePluginCustomTypes> | TypedPlugin<NormalizeAfterDeletePluginCustomTypes> | TypedPlugin<CollapsibleParagraphPluginCustomTypes> | TypedPlugin<ThemePluginCustomTypes> | TypedPlugin<ToolbarPluginCustomTypes> | TypedPlugin<ImagePluginCustomTypes> | TypedPlugin<PlaceholderPluginCustomTypes>)[];
1012
+ type PluginTypes = ExtractCustomTypes<typeof plugins>;
1013
+ type CustomEditor = PluginTypes["Editor"];
1014
+ type CustomElement = PluginTypes["Element"];
1015
+ type CustomText = PluginTypes["Text"];
1016
+ declare module "slate" {
1017
+ interface CustomTypes {
1018
+ Editor: BaseEditor & ReactEditor & HistoryEditor & CustomEditor & WysimarkEditor;
1019
+ Element: CustomElement;
1020
+ Text: BaseText & CustomText;
1021
+ }
1022
+ }
1023
+
1024
+ type EditableProps = {
1025
+ editor: Editor;
1026
+ value: string;
1027
+ onChange: (markdown: string) => void;
1028
+ throttleInMs?: number;
1029
+ placeholder?: string;
1030
+ className?: string;
1031
+ style?: React.CSSProperties;
1032
+ onImageChange?: OnImageChangeHandler;
1033
+ onFileSelect?: OnFileSelectHandler;
1034
+ };
1035
+ declare function Editable({ editor, value, onChange, throttleInMs, placeholder, className, style, onImageChange, onFileSelect, }: EditableProps): react_jsx_runtime.JSX.Element;
1036
+
1037
+ /**
1038
+ * Remove inline escape backslashes added by the serializer's escapeText.
1039
+ * Matches `\` followed by any of: \ ` * _ [ ] ~ | <
1040
+ * and replaces with just the character itself.
1041
+ */
1042
+ declare function unescapeMarkdown(text: string): string;
1043
+
1044
+ /**
1045
+ * The options passed into the standalone version of Wysimark.
1046
+ */
1047
+ type StandaloneOptions = Parameters<typeof useEditor>[0] & {
1048
+ onChange?: (markdown: string) => void;
1049
+ placeholder?: string;
1050
+ initialMarkdown?: string;
1051
+ className?: string;
1052
+ };
1053
+ /**
1054
+ * The object returned by `createWysimark`
1055
+ */
1056
+ type Wysimark = {
1057
+ unmount: () => void;
1058
+ getMarkdown: () => string;
1059
+ setMarkdown: (markdown: string) => void;
1060
+ };
1061
+ /**
1062
+ * The primary entry point for the standalone version of Wysimark.
1063
+ */
1064
+ declare function createWysimark(containerElement: HTMLElement, options: StandaloneOptions): Wysimark;
1065
+
1066
+ export { Editable, type OnImageChangeHandler, type UseEditorOptions, type Wysimark, createWysimark, unescapeMarkdown, useEditor };