wysimark-lite 0.15.0 → 0.15.1

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