wysimark-lite 0.27.0 → 0.27.2

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.mts CHANGED
@@ -1,5 +1,5 @@
1
- import * as react from 'react';
2
- import react__default from 'react';
1
+ import * as React$1 from 'react';
2
+ import React__default, { ReactNode } from 'react';
3
3
  import * as slate from 'slate';
4
4
  import { Descendant, Editor, Element as Element$1, BaseEditor, NodeEntry, BaseRange, Location, Path, Text, BaseText } from 'slate';
5
5
  import { HistoryEditor } from 'slate-history';
@@ -9,6 +9,8 @@ import { EditableProps as EditableProps$1, RenderElementProps, RenderLeafProps,
9
9
 
10
10
  type OnImageChangeHandler = (file: File) => Promise<string>;
11
11
  type OnFileSelectHandler = () => Promise<string | null>;
12
+ type RenderInternalLinkPreview = (target: string) => ReactNode;
13
+ type RenderInternalEmbed = (spec: string) => ReactNode;
12
14
  type ImageDialogState = {
13
15
  url: string;
14
16
  alt: string;
@@ -53,6 +55,18 @@ type WysimarkEditor = {
53
55
  * Whether highlight mark is disabled
54
56
  */
55
57
  disableHighlight?: boolean;
58
+ /**
59
+ * Whether Obsidian-style internal links are enabled
60
+ */
61
+ enableInternalLinks?: boolean;
62
+ /**
63
+ * Render preview content for an internal link target.
64
+ */
65
+ renderInternalLinkPreview?: RenderInternalLinkPreview;
66
+ /**
67
+ * Render inline content for an internal embed (`![[spec]]`).
68
+ */
69
+ renderInternalEmbed?: RenderInternalEmbed;
56
70
  };
57
71
  /**
58
72
  * Public methods for the wysimark editor.
@@ -88,8 +102,16 @@ type UseEditorOptions = {
88
102
  * Defaults to true (highlight is disabled by default).
89
103
  */
90
104
  disableHighlight?: boolean;
105
+ /**
106
+ * Enable Obsidian-style internal links and embeds.
107
+ * When true, [[Page]] and ![[file.png]] are parsed and serialized as
108
+ * internal links. Defaults to false.
109
+ */
110
+ enableInternalLinks?: boolean;
111
+ renderInternalLinkPreview?: RenderInternalLinkPreview;
112
+ renderInternalEmbed?: RenderInternalEmbed;
91
113
  };
92
- declare function useEditor({ authToken, height, minHeight, maxHeight, disableRawMode, disableTaskList, disableCodeBlock, disableHighlight, }?: UseEditorOptions): Editor & ReactEditor & WysimarkEditor;
114
+ declare function useEditor({ authToken, height, minHeight, maxHeight, disableRawMode, disableTaskList, disableCodeBlock, disableHighlight, enableInternalLinks, renderInternalLinkPreview, renderInternalEmbed, }?: UseEditorOptions): Editor & ReactEditor & WysimarkEditor;
93
115
 
94
116
  /**
95
117
  * SinkEditor just adds a `sink` object where we drop all of our sink
@@ -201,9 +223,9 @@ type VoidActionReturn = boolean | (() => void);
201
223
 
202
224
  type RenderEditableProps = {
203
225
  attributes: EditableProps$1;
204
- Editable: react__default.ComponentType<EditableProps$1>;
226
+ Editable: React__default.ComponentType<EditableProps$1>;
205
227
  };
206
- type RenderEditable = (props: RenderEditableProps) => react__default.ReactElement;
228
+ type RenderEditable = (props: RenderEditableProps) => React__default.ReactElement;
207
229
  /**
208
230
  * The return type of the BasePluginFn which specifies how the Plugin is
209
231
  * supposed to behave.
@@ -228,9 +250,9 @@ type BasePluginPolicy = {
228
250
  renderEditable?: RenderEditable;
229
251
  editableProps?: {
230
252
  decorate?: ((entry: NodeEntry) => BaseRange[]) | undefined;
231
- renderElement?: (props: RenderElementProps) => react__default.ReactElement | undefined;
232
- renderLeaf?: (props: RenderLeafProps) => react__default.ReactElement | undefined;
233
- renderPlaceholder?: (props: RenderPlaceholderProps) => react__default.ReactElement;
253
+ renderElement?: (props: RenderElementProps) => React__default.ReactElement | undefined;
254
+ renderLeaf?: (props: RenderLeafProps) => React__default.ReactElement | undefined;
255
+ renderPlaceholder?: (props: RenderPlaceholderProps) => React__default.ReactElement;
234
256
  onKeyDown?: EditableVoidToBooleanHandlerType<"onKeyDown">;
235
257
  onKeyUp?: EditableVoidToBooleanHandlerType<"onKeyDown">;
236
258
  onPaste?: EditableVoidToBooleanHandlerType<"onPaste">;
@@ -577,7 +599,7 @@ declare function createListMethods(editor: Editor): {
577
599
  convertTaskList: (allowToggle: boolean) => void;
578
600
  insertBreak: () => boolean;
579
601
  toggleTaskListItem: (args_0?: {
580
- at?: BetterAt | undefined;
602
+ at?: BetterAt;
581
603
  } | undefined) => boolean;
582
604
  getListDepth: () => number;
583
605
  canIncreaseDepth: () => boolean;
@@ -725,85 +747,66 @@ type TableInfo = {
725
747
  cellCount: number;
726
748
  };
727
749
 
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;
750
+ declare function createTableMethods(editor: Editor): {
751
+ getTableInfo: (args_0?: {
752
+ at?: slate.Location | slate.Element | null;
753
+ } | undefined) => TableInfo | undefined;
754
+ insertTable: (columnCount: number, rowCount: number, args_2?: {
755
+ at?: slate.Location | null;
756
+ } | undefined) => boolean;
757
+ insertColumn: (args_0?: {
758
+ offset?: 0 | 1;
759
+ at?: BetterAt;
760
+ } | undefined) => boolean;
761
+ insertRow: (args_0?: {
762
+ at?: BetterAt;
763
+ offset?: 0 | 1;
764
+ } | undefined) => boolean;
765
+ removeTable: () => boolean;
766
+ removeColumn: (args_0?: {
767
+ at?: BetterAt;
768
+ } | undefined) => boolean | undefined;
769
+ removeRow: (args_0?: {
770
+ at?: BetterAt;
771
+ } | undefined) => boolean;
772
+ tabForward: () => boolean;
773
+ tabBackward: () => boolean | undefined;
774
+ shiftEnterForward: () => boolean;
775
+ selectCell: (args_0?: {
776
+ at?: BetterAt;
777
+ } | undefined) => boolean;
778
+ down: () => boolean;
779
+ up: () => boolean;
780
+ setTableColumnAlign: (options: {
781
+ align: "left" | "center" | "right";
742
782
  }) => boolean;
743
783
  };
744
784
 
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;
785
+ type TableEditor = {
786
+ supportsTable: true;
787
+ tablePlugin: ReturnType<typeof createTableMethods>;
760
788
  };
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;
789
+ type TablePluginCustomTypes = {
790
+ Name: "table";
791
+ Editor: TableEditor;
792
+ Element: TableElement | TableRowElement | TableCellElement | TableContentElement;
765
793
  };
766
794
 
767
- type HeadingEditor = {
768
- heading: ReturnType<typeof createHeadingMethods>;
769
- };
770
- type HeadingElement = {
771
- type: "heading";
795
+ /**
796
+ * HTML block element for preserving raw HTML content
797
+ */
798
+ type HtmlBlockElement = {
799
+ type: "html-block";
772
800
  /**
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.
801
+ * The raw HTML content
777
802
  */
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[];
803
+ html: string;
804
+ children: Text[];
802
805
  };
803
- type BlockQuotePluginCustomTypes = {
804
- Name: "block-quote";
805
- Editor: BlockQuoteEditor;
806
- Element: BlockQuoteElement;
806
+ type HtmlBlockPluginCustomTypes = {
807
+ Name: "html-block";
808
+ Editor: Record<string, never>;
809
+ Element: HtmlBlockElement;
807
810
  };
808
811
 
809
812
  declare function createCodeBlockMethods(editor: Editor): {
@@ -811,7 +814,7 @@ declare function createCodeBlockMethods(editor: Editor): {
811
814
  language: BuiltInLanguage;
812
815
  }) => void;
813
816
  setCodeBlockLanguage: (language: BuiltInLanguage, options?: {
814
- at?: BetterAt | undefined;
817
+ at?: BetterAt;
815
818
  } | undefined) => boolean;
816
819
  };
817
820
 
@@ -847,66 +850,26 @@ type CodeBlockPluginCustomTypes = {
847
850
  };
848
851
  };
849
852
 
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;
853
+ type BlockQuoteEditor = {
854
+ supportsBlockQuote: true;
855
+ blockQuotePlugin: {
856
+ indent: () => void;
857
+ outdent: () => void;
858
+ isActive: () => boolean;
859
+ increaseDepth: () => void;
860
+ decreaseDepth: () => void;
861
+ canIncreaseDepth: () => boolean;
862
+ canDecreaseDepth: () => boolean;
863
+ };
900
864
  };
901
-
902
- type TableEditor = {
903
- supportsTable: true;
904
- tablePlugin: ReturnType<typeof createTableMethods>;
865
+ type BlockQuoteElement = {
866
+ type: "block-quote";
867
+ children: Descendant[];
905
868
  };
906
- type TablePluginCustomTypes = {
907
- Name: "table";
908
- Editor: TableEditor;
909
- Element: TableElement | TableRowElement | TableCellElement | TableContentElement;
869
+ type BlockQuotePluginCustomTypes = {
870
+ Name: "block-quote";
871
+ Editor: BlockQuoteEditor;
872
+ Element: BlockQuoteElement;
910
873
  };
911
874
 
912
875
  type InlineCodeEditor = {
@@ -926,10 +889,10 @@ type InlineCodePluginCustomTypes = {
926
889
 
927
890
  declare function createMarksMethods(editor: Editor): {
928
891
  removeMarks: (args_0?: {
929
- at?: slate.Location | null | undefined;
892
+ at?: slate.Location | null;
930
893
  } | 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;
894
+ toggleMark: (markKey: "bold" | "strike" | "text" | "prismToken" | "code" | "italic" | "underline" | "highlight", unsetKey?: "bold" | "strike" | "text" | "prismToken" | "code" | "italic" | "underline" | "highlight" | undefined, args_2?: {
895
+ at?: slate.Location | null;
933
896
  } | undefined) => void;
934
897
  toggleBold: () => void;
935
898
  toggleItalic: () => void;
@@ -968,6 +931,68 @@ type MarksPluginCustomTypes = {
968
931
  Text: MarksText;
969
932
  };
970
933
 
934
+ declare function createHeadingMethods(editor: Editor): {
935
+ convertHeading: (level: 1 | 2 | 3 | 4 | 5 | 6, allowToggle: boolean) => void;
936
+ isHeadingActive: (level: 1 | 2 | 3 | 4 | 5 | 6) => boolean;
937
+ };
938
+
939
+ type HeadingEditor = {
940
+ heading: ReturnType<typeof createHeadingMethods>;
941
+ };
942
+ type HeadingElement = {
943
+ type: "heading";
944
+ /**
945
+ * NOTE:
946
+ *
947
+ * Don't extract these into a new type. It's easier to just repeat this and
948
+ * there's less indirection.
949
+ */
950
+ level: 1 | 2 | 3 | 4 | 5 | 6;
951
+ children: Descendant[];
952
+ };
953
+ type HeadingPluginCustomTypes = {
954
+ Name: "heading";
955
+ Editor: HeadingEditor;
956
+ Element: HeadingElement;
957
+ };
958
+
959
+ declare function createAnchorMethods(editor: Editor): {
960
+ insertLink: (href: string, text?: string | undefined, args_2?: {
961
+ select?: boolean;
962
+ title?: string;
963
+ } | undefined) => void;
964
+ removeLink: (args_0: {
965
+ at?: BetterAt;
966
+ }) => boolean;
967
+ editLink: (args_0: {
968
+ href: string;
969
+ title?: string;
970
+ text?: string;
971
+ }, args_1: {
972
+ at?: BetterAt;
973
+ }) => boolean;
974
+ convertToEmbed: (spec: string, args_1: {
975
+ at?: BetterAt;
976
+ }) => boolean;
977
+ };
978
+
979
+ type AnchorMethods = ReturnType<typeof createAnchorMethods>;
980
+ type AnchorEditor = {
981
+ anchor: AnchorMethods;
982
+ };
983
+ type AnchorElement = {
984
+ type: "anchor";
985
+ href: string;
986
+ target?: string;
987
+ title?: string;
988
+ children: Descendant[];
989
+ };
990
+ type AnchorPluginCustomTypes = {
991
+ Name: "anchor";
992
+ Editor: AnchorEditor;
993
+ Element: AnchorElement;
994
+ };
995
+
971
996
  /**
972
997
  * A type with generic for `convertElements` (below) to be used with the curry
973
998
  * method. TypeScript, unfortunately, cannot automatically curry generics for
@@ -1032,7 +1057,7 @@ type EditableProps = {
1032
1057
  onImageChange?: OnImageChangeHandler;
1033
1058
  onFileSelect?: OnFileSelectHandler;
1034
1059
  };
1035
- declare function Editable({ editor, value, onChange, throttleInMs, placeholder, className, style, onImageChange, onFileSelect, }: EditableProps): react.JSX.Element;
1060
+ declare function Editable({ editor, value, onChange, throttleInMs, placeholder, className, style, onImageChange, onFileSelect, }: EditableProps): React$1.JSX.Element;
1036
1061
 
1037
1062
  /**
1038
1063
  * Remove inline escape backslashes added by the serializer's escapeText.