rme 0.3.0-beta.3 → 0.3.0-beta.31

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/dist/index.d.ts CHANGED
@@ -6,19 +6,65 @@ import { Compartment, Extension } from '@codemirror/state';
6
6
  import { EditorView, EditorViewConfig } from '@codemirror/view';
7
7
  import { ProsemirrorNode, EditorView as EditorView$1 } from '@rme-sdk/pm';
8
8
  import * as react from 'react';
9
- import react__default, { CSSProperties, ReactNode, MouseEvent, JSX, FC } from 'react';
9
+ import react__default, { CSSProperties, ComponentType, ReactNode, MouseEvent, JSX, FC } from 'react';
10
10
  import { RemirrorEventListenerProps, Extension as Extension$1, RemirrorManager as RemirrorManager$1, AnyExtension as AnyExtension$1 } from '@rme-sdk/main';
11
- import { AnyExtension, RemirrorManager, CommandDecoratorMessageProps, CoreIcon } from '@rme-sdk/core';
12
- import { Node, Schema, NodeType, Mark } from '@rme-sdk/pm/model';
11
+ import * as _rme_sdk_core from '@rme-sdk/core';
12
+ import { AnyExtension, RemirrorManager, DelayedPromiseCreator, ProsemirrorAttributes, NodeExtension, EditorView as EditorView$2, ApplySchemaAttributes, NodeSpecOverride, NodeExtensionSpec, PrimitiveSelection, CommandFunction, ExtensionCommandReturn, InputRule as InputRule$1, KeyBindings, ProsemirrorPlugin, ProsemirrorNode as ProsemirrorNode$1, CommandDecoratorMessageProps, CoreIcon } from '@rme-sdk/core';
13
+ import { Node, Schema, NodeType, Mark, NodeRange } from '@rme-sdk/pm/model';
13
14
  import { ReactFrameworkOutput } from '@rme-sdk/react-core';
14
- import { Token as Token$1 } from 'markdown-it/index.js';
15
+ import { InputRule } from '@rme-sdk/pm/inputrules';
16
+ import { PasteRule } from '@rme-sdk/pm/paste-rules';
15
17
  import Token from 'markdown-it/lib/token.mjs';
18
+ import { Token as Token$1 } from 'markdown-it/index.js';
19
+ import { NodeViewComponentProps } from '@rme-sdk/react';
16
20
  export { useCommands, useHelpers, useKeymap, useRemirrorContext } from '@rme-sdk/react';
17
21
  import * as styled_components from 'styled-components';
18
22
  import * as styled_components_dist_types from 'styled-components/dist/types';
23
+ import { IndentListOptions, DedentListOptions, UnwrapListOptions, ToggleCollapsedOptions } from '@rme-sdk/prosemirror-flat-list';
19
24
 
20
25
  type LoadLanguage = (lang: string) => Promise<LanguageSupport> | LanguageSupport | void;
21
26
 
27
+ type ClipboardReadFunction = typeof clipboardRead;
28
+ declare function clipboardRead(): Promise<{
29
+ html: string;
30
+ text: string;
31
+ }>;
32
+
33
+ interface CommandKeymapOptions {
34
+ /**
35
+ * Override default keyboard shortcuts
36
+ * @example
37
+ * { toggleStrong: 'mod-shift-b', toggleEmphasis: 'ctrl-i' }
38
+ */
39
+ overrideShortcutMap?: Partial<Record<CommandName, string>>;
40
+ /**
41
+ * Disable all built-in shortcuts
42
+ * @default false
43
+ */
44
+ disableAllBuildInShortcuts?: boolean;
45
+ clipboardReadFunction?: ClipboardReadFunction;
46
+ }
47
+ type CommandName = keyof typeof defaultCommandShortcutMap;
48
+ declare const defaultCommandShortcutMap: {
49
+ readonly copy: "mod-c";
50
+ readonly paste: "mod-v";
51
+ readonly undo: "mod-z";
52
+ readonly redo: "mod-shift-z";
53
+ readonly cut: "mod-x";
54
+ readonly toggleH1: "mod-1";
55
+ readonly toggleH2: "mod-2";
56
+ readonly toggleH3: "mod-3";
57
+ readonly toggleH4: "mod-4";
58
+ readonly toggleH5: "mod-5";
59
+ readonly toggleH6: "mod-6";
60
+ readonly toggleStrong: "mod-b";
61
+ readonly toggleEmphasis: "mod-i";
62
+ readonly toggleCodeText: "mod-e";
63
+ readonly toggleDelete: "mod-shift-s";
64
+ readonly insertLink: "mod-k";
65
+ readonly insertImage: "mod-alt-i";
66
+ };
67
+
22
68
  type CustomCopyFunction = (code: string) => Promise<boolean> | boolean;
23
69
 
24
70
  declare const changeTheme: (theme: CreateThemeOptions) => void;
@@ -44,6 +90,10 @@ type CreateCodemirrorOptions = {
44
90
  */
45
91
  customCopyFunction?: CustomCopyFunction;
46
92
  };
93
+ /**
94
+ * Command keymap options for customizing keyboard shortcuts
95
+ */
96
+ commandKeymapOptions?: CommandKeymapOptions;
47
97
  };
48
98
  declare class MfCodemirrorView {
49
99
  private readonly view;
@@ -231,6 +281,18 @@ type EditorContext = ReactFrameworkOutput<Remirror.Extensions>;
231
281
  type CreateSourceCodeManagerOptions = {
232
282
  language?: string;
233
283
  onCodemirrorViewLoad: (cm: MfCodemirrorView) => void;
284
+ /**
285
+ * Override default keyboard shortcuts
286
+ * @example
287
+ * { toggleStrong: 'mod-shift-b', toggleEmphasis: 'ctrl-i' }
288
+ */
289
+ overrideShortcutMap?: Partial<Record<CommandName, string>>;
290
+ /**
291
+ * Disable all built-in shortcuts
292
+ * @default false
293
+ */
294
+ disableAllBuildInShortcuts?: boolean;
295
+ clipboardReadFunction?: ClipboardReadFunction;
234
296
  };
235
297
  declare function createSourceCodeManager(options?: CreateSourceCodeManagerOptions): RemirrorManager$1<any>;
236
298
  declare const createSourceCodeDelegate: (options?: CreateSourceCodeManagerOptions) => EditorDelegate<any>;
@@ -250,6 +312,10 @@ interface AIOptions {
250
312
  }) => Promise<string | null>;
251
313
  }
252
314
 
315
+ type CodemirrorOptions = {
316
+ lineWrapping?: boolean;
317
+ };
318
+
253
319
  type MarkdownItToken = string;
254
320
  declare enum ParserRuleType {
255
321
  text = 1,
@@ -381,14 +447,276 @@ declare class MarkdownSerializer {
381
447
  serialize(content: Node): string;
382
448
  }
383
449
 
450
+ interface ImageNodeViewProps extends NodeViewComponentProps {
451
+ resizeable?: boolean;
452
+ defaultSyntaxType?: 'html' | 'md';
453
+ handleViewImgSrcUrl?: ExtensionsOptions['handleViewImgSrcUrl'];
454
+ imagePasteHandler?: ExtensionsOptions['imagePasteHandler'];
455
+ imageHostingHandler?: (src: string) => Promise<string>;
456
+ }
457
+
458
+ type DelayedImage$1 = DelayedPromiseCreator<ImageAttributes$1>;
459
+ interface ImageOptions$1 {
460
+ createPlaceholder?: (view: EditorView$2, pos: number) => HTMLElement;
461
+ updatePlaceholder?: (view: EditorView$2, pos: number, element: HTMLElement, progress: number) => void;
462
+ handleViewImgSrcUrl?: ExtensionsOptions['handleViewImgSrcUrl'];
463
+ imagePasteHandler?: ExtensionsOptions['imagePasteHandler'];
464
+ destroyPlaceholder?: (view: EditorView$2, element: HTMLElement) => void;
465
+ /**
466
+ * The upload handler for the image extension.
467
+ *
468
+ * It receives a list of dropped or pasted files and returns a promise for the
469
+ * attributes which should be used to insert the image into the editor.
470
+ *
471
+ * @param files - a list of files to upload.
472
+ * @param setProgress - the progress handler.
473
+ */
474
+ uploadHandler?: (files: FileWithProgress$1[]) => DelayedImage$1[];
475
+ /**
476
+ * The image hosting service upload handler.
477
+ * It receives the image src and returns a promise for the new src after uploading to image hosting service.
478
+ *
479
+ * @param src - the original image src
480
+ * @returns Promise<string> - the new image src after uploading
481
+ */
482
+ imageHostingHandler?: (src: string) => Promise<string>;
483
+ /**
484
+ * When pasting mixed text and image content (usually from Microsoft Office products) the content on the clipboard is either:
485
+ *
486
+ * a. one large image: containing effectively a screenshot of the original content (an image with text in it).
487
+ * b. HTML content: containing usable text, but images with file protocol URLs (which cannot be resolved due to browser security restrictions).
488
+ *
489
+ * If true, this will extract the text from the clipboard data, and drop the images.
490
+ * If false, the "screenshot" image will be used and the text will be dropped.
491
+ *
492
+ * @defaultValue true
493
+ */
494
+ preferPastedTextContent?: boolean;
495
+ }
496
+ interface FileWithProgress$1 {
497
+ file: File;
498
+ progress: SetProgress$1;
499
+ }
500
+ /**
501
+ * Set the progress.
502
+ *
503
+ * @param progress - a value between `0` and `1`.
504
+ */
505
+ type SetProgress$1 = (progress: number) => void;
506
+ /**
507
+ * The image extension for placing images into your editor.
508
+ *
509
+ * TODO ->
510
+ * - Captions https://glitch.com/edit/#!/pet-figcaption?path=index.js%3A27%3A1 into a preset
511
+ *
512
+ * TODO => Split this into an image upload extension and image extension.
513
+ * - Add a base64 image
514
+ */
515
+ declare class MdImgUriExtension extends NodeExtension<ImageOptions$1> {
516
+ get name(): "md_image";
517
+ ReactComponent: ComponentType<ImageNodeViewProps> | undefined;
518
+ createTags(): ("inline" | "media")[];
519
+ createNodeSpec(extra: ApplySchemaAttributes, override: NodeSpecOverride): NodeExtensionSpec;
520
+ insertMarkdownImage(attributes: ImageAttributes$1, selection?: PrimitiveSelection): CommandFunction;
521
+ uploadImage: (value: DelayedPromiseCreator<ImageAttributes$1>, onElement?: ((element: HTMLElement) => void) | undefined) => CommandFunction;
522
+ /**
523
+ * Insert an image once the provide promise resolves.
524
+ */
525
+ createCommands(): ExtensionCommandReturn;
526
+ private fileUploadFileHandler;
527
+ createPasteRules(): PasteRule[];
528
+ createInputRules(): InputRule[];
529
+ fromMarkdown(): readonly [{
530
+ readonly type: ParserRuleType.inline;
531
+ readonly token: "md_image";
532
+ readonly node: "md_image";
533
+ }];
534
+ toMarkdown({ state, node }: NodeSerializerOptions): void;
535
+ }
536
+ type ImageAttributes$1 = ProsemirrorAttributes<ImageExtensionAttributes$1>;
537
+ interface ImageExtensionAttributes$1 {
538
+ align?: 'center' | 'end' | 'justify' | 'left' | 'match-parent' | 'right' | 'start';
539
+ alt?: string;
540
+ height?: string | number;
541
+ width?: string | number;
542
+ rotate?: string;
543
+ src: string;
544
+ title?: string;
545
+ /** The file name used to create the image. */
546
+ 'data-file-name'?: string;
547
+ }
548
+
549
+ type DelayedImage = DelayedPromiseCreator<ImageAttributes>;
550
+ interface ImageOptions {
551
+ createPlaceholder?: (view: EditorView$2, pos: number) => HTMLElement;
552
+ updatePlaceholder?: (view: EditorView$2, pos: number, element: HTMLElement, progress: number) => void;
553
+ handleViewImgSrcUrl?: ExtensionsOptions['handleViewImgSrcUrl'];
554
+ imagePasteHandler?: ExtensionsOptions['imagePasteHandler'];
555
+ destroyPlaceholder?: (view: EditorView$2, element: HTMLElement) => void;
556
+ /**
557
+ * The upload handler for the image extension.
558
+ *
559
+ * It receives a list of dropped or pasted files and returns a promise for the
560
+ * attributes which should be used to insert the image into the editor.
561
+ *
562
+ * @param files - a list of files to upload.
563
+ * @param setProgress - the progress handler.
564
+ */
565
+ uploadHandler?: (files: FileWithProgress[]) => DelayedImage[];
566
+ /**
567
+ * The image hosting service upload handler.
568
+ * It receives the image src and returns a promise for the new src after uploading to image hosting service.
569
+ *
570
+ * @param src - the original image src
571
+ * @returns Promise<string> - the new image src after uploading
572
+ */
573
+ imageHostingHandler?: (src: string) => Promise<string>;
574
+ /**
575
+ * When pasting mixed text and image content (usually from Microsoft Office products) the content on the clipboard is either:
576
+ *
577
+ * a. one large image: containing effectively a screenshot of the original content (an image with text in it).
578
+ * b. HTML content: containing usable text, but images with file protocol URLs (which cannot be resolved due to browser security restrictions).
579
+ *
580
+ * If true, this will extract the text from the clipboard data, and drop the images.
581
+ * If false, the "screenshot" image will be used and the text will be dropped.
582
+ *
583
+ * @defaultValue true
584
+ */
585
+ preferPastedTextContent?: boolean;
586
+ }
587
+ interface FileWithProgress {
588
+ file: File;
589
+ progress: SetProgress;
590
+ }
591
+ /**
592
+ * Set the progress.
593
+ *
594
+ * @param progress - a value between `0` and `1`.
595
+ */
596
+ type SetProgress = (progress: number) => void;
597
+ /**
598
+ * The image extension for placing images into your editor.
599
+ *
600
+ * TODO ->
601
+ * - Captions https://glitch.com/edit/#!/pet-figcaption?path=index.js%3A27%3A1 into a preset
602
+ *
603
+ * TODO => Split this into an image upload extension and image extension.
604
+ * - Add a base64 image
605
+ */
606
+ declare class HtmlImageExtension extends NodeExtension<ImageOptions> {
607
+ get name(): "html_image";
608
+ ReactComponent: ComponentType<ImageNodeViewProps> | undefined;
609
+ createTags(): ("inline" | "media")[];
610
+ createNodeSpec(extra: ApplySchemaAttributes, override: NodeSpecOverride): NodeExtensionSpec;
611
+ insertImage(attributes: ImageAttributes, selection?: PrimitiveSelection): CommandFunction;
612
+ createInputRules(): InputRule$1[];
613
+ fromMarkdown(): readonly [{
614
+ readonly type: ParserRuleType.inline;
615
+ readonly token: "html_image";
616
+ readonly node: "html_image";
617
+ }];
618
+ toMarkdown({ state, node }: NodeSerializerOptions): void;
619
+ }
620
+ type ImageAttributes = ProsemirrorAttributes<ImageExtensionAttributes>;
621
+ interface ImageExtensionAttributes {
622
+ align?: 'center' | 'end' | 'justify' | 'left' | 'match-parent' | 'right' | 'start';
623
+ alt?: string;
624
+ height?: string | number;
625
+ width?: string | number;
626
+ rotate?: string;
627
+ src: string;
628
+ title?: string;
629
+ /** The file name used to create the image. */
630
+ 'data-file-name'?: string;
631
+ }
632
+ /**
633
+ * True when the provided file is an image file.
634
+ */
635
+ declare function isImageFileType(file: File): boolean;
636
+
637
+ /**
638
+ * @public @group Schema
639
+ */
640
+ interface ListAttributes {
641
+ kind?: string;
642
+ order?: number | null;
643
+ checked?: boolean;
644
+ collapsed?: boolean;
645
+ }
646
+
647
+ declare abstract class MarkdownNodeExtension {
648
+ abstract fromMarkdown: () => readonly ParserRule[];
649
+ abstract toMarkdown: NodeSerializerSpec;
650
+ }
651
+
652
+ /**
653
+ * A Remirror extension for creating lists. It's a simple wrapper around the API from `prosemirror-flat-list`.
654
+ *
655
+ * @public
656
+ */
657
+ declare class LineListExtension extends NodeExtension {
658
+ static disableExtraAttributes: boolean;
659
+ get name(): "list";
660
+ createInputRules(): InputRule$1[];
661
+ createTags(): "block"[];
662
+ createNodeSpec(): NodeExtensionSpec;
663
+ createKeymap(): KeyBindings;
664
+ createExternalPlugins(): ProsemirrorPlugin[];
665
+ createCommands(): {
666
+ readonly indentList: (props?: IndentListOptions) => _rme_sdk_core.CommandFunction<object>;
667
+ readonly dedentList: (props?: DedentListOptions) => _rme_sdk_core.CommandFunction<object>;
668
+ readonly unwrapList: (options?: UnwrapListOptions) => _rme_sdk_core.CommandFunction<object>;
669
+ readonly wrapInList: (getAttrs: ListAttributes | ((range: NodeRange) => ListAttributes | null)) => _rme_sdk_core.CommandFunction<object>;
670
+ readonly moveList: (direction: 'up' | 'down') => _rme_sdk_core.CommandFunction<object>;
671
+ readonly splitList: () => _rme_sdk_core.CommandFunction<object>;
672
+ readonly protectCollapsed: () => _rme_sdk_core.CommandFunction<object>;
673
+ readonly toggleCollapsed: (props?: ToggleCollapsedOptions) => _rme_sdk_core.CommandFunction<object>;
674
+ readonly toggleList: (attrs: ListAttributes) => _rme_sdk_core.CommandFunction<object>;
675
+ };
676
+ fromMarkdown(): readonly [{
677
+ readonly type: ParserRuleType.free;
678
+ readonly token: "list_item_open";
679
+ readonly handler: (state: MarkdownParseState) => void;
680
+ }, {
681
+ readonly type: ParserRuleType.free;
682
+ readonly token: "list_checkbox";
683
+ readonly handler: (state: MarkdownParseState, tok: Token) => void;
684
+ }, {
685
+ readonly type: ParserRuleType.free;
686
+ readonly token: "list_item_close";
687
+ readonly handler: (state: MarkdownParseState) => void;
688
+ }, {
689
+ readonly type: ParserRuleType.context;
690
+ readonly token: "bullet_list";
691
+ readonly context: "bullet_list";
692
+ }, {
693
+ readonly type: ParserRuleType.context;
694
+ readonly token: "ordered_list";
695
+ readonly context: "ordered_list";
696
+ }];
697
+ toMarkdown({ state, node, counter }: NodeSerializerOptions): void;
698
+ }
699
+ /**
700
+ * Wrap the giving command function so that it always returns `true`. This is
701
+ * useful when we want pressing `Tab` and `Shift-Tab` won't blur the editor even
702
+ * if the keybinding command returns `false`
703
+ *
704
+ * @public
705
+ */
706
+ declare function alwaysTrue<T extends unknown[]>(func: (...args: T) => boolean): (...args: T) => boolean;
707
+ declare function isOrderedListNode(node: ProsemirrorNode$1): boolean;
708
+
384
709
  type ExtensionsOptions = {
385
710
  disableAllBuildInShortcuts?: boolean;
386
711
  handleViewImgSrcUrl?: (src: string) => Promise<string>;
387
712
  imageHostingHandler?: (src: string) => Promise<string>;
388
- imageCopyHandler?: (src: string) => Promise<string>;
713
+ imagePasteHandler?: (src: string) => Promise<string>;
389
714
  ai?: AIOptions;
390
715
  customCopyFunction?: CustomCopyFunction;
391
716
  overrideShortcutMap?: Record<string, string>;
717
+ clipboardReadFunction?: ClipboardReadFunction;
718
+ codemirrorOptions?: CodemirrorOptions;
719
+ uploadImageHandler?: (files: FileWithProgress$1[]) => DelayedImage$1[];
392
720
  };
393
721
  declare function extensions(options: ExtensionsOptions): any[];
394
722
 
@@ -495,6 +823,7 @@ declare const darkTheme: {
495
823
  contextMenuBgColorHover: string;
496
824
  slashMenuBorderColor: string;
497
825
  editorToolbarBgColor: string;
826
+ selectionMatchBgColor: string;
498
827
  lineHeightBase: string;
499
828
  titleBarHeight: string;
500
829
  titleBarControlBtnWidth: string;
@@ -562,6 +891,7 @@ declare const lightTheme: {
562
891
  contextMenuBgColorHover: string;
563
892
  slashMenuBorderColor: string;
564
893
  editorToolbarBgColor: string;
894
+ selectionMatchBgColor: string;
565
895
  lineHeightBase: string;
566
896
  titleBarHeight: string;
567
897
  titleBarControlBtnWidth: string;
@@ -615,5 +945,5 @@ type WysiwygToolbarProps = {
615
945
  };
616
946
  declare const WysiwygToolbar: FC<WysiwygToolbarProps>;
617
947
 
618
- export { CommandButton, CommandButtonIcon, Editor, extensions as EditorExtensions, EditorViewType, MfCodemirrorView, Preview, SourceCodeThemeWrapper, _default$1 as SourceEditor, ThemeProvider, _default as WysiwygEditor, WysiwygThemeWrapper, WysiwygToolbar, buildMarkdownParser, buildMarkdownSerializer, changeTheme, common, computeChange, createSourceCodeDelegate, createSourceCodeManager, createWysiwygDelegate, darkTheme, defaultStyleToken, extractMatches, getLanguageMap, lightTheme, loadLanguage, tableSelectorSize };
619
- export type { CommandButtonIconProps, CommandButtonProps, CreateCodemirrorOptions, CreateWysiwygDelegateOptions, DocToString, EditorChangeEventParams, EditorChangeHandler, EditorContext, EditorDelegate, EditorProps, EditorRef, EditorState, HTMLAstNode, Note, StringToDoc, WysiwygToolbarProps };
948
+ export { CommandButton, CommandButtonIcon, Editor, extensions as EditorExtensions, EditorViewType, HtmlImageExtension, LineListExtension, MarkdownNodeExtension, MdImgUriExtension, MfCodemirrorView, Preview, SourceCodeThemeWrapper, _default$1 as SourceEditor, ThemeProvider, _default as WysiwygEditor, WysiwygThemeWrapper, WysiwygToolbar, alwaysTrue, buildMarkdownParser, buildMarkdownSerializer, changeTheme, common, computeChange, createSourceCodeDelegate, createSourceCodeManager, createWysiwygDelegate, darkTheme, defaultStyleToken, extractMatches, getLanguageMap, isImageFileType, isOrderedListNode, lightTheme, loadLanguage, tableSelectorSize };
949
+ export type { CommandButtonIconProps, CommandButtonProps, CreateCodemirrorOptions, CreateWysiwygDelegateOptions, DelayedImage$1 as DelayedImage, DocToString, EditorChangeEventParams, EditorChangeHandler, EditorContext, EditorDelegate, EditorProps, EditorRef, EditorState, ExtensionsOptions, FileWithProgress$1 as FileWithProgress, HTMLAstNode, ImageAttributes, ImageExtensionAttributes, ImageOptions, Note, StringToDoc, WysiwygToolbarProps };