@lapismd/mira-react 0.0.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.
- package/CHANGELOG.md +7 -0
- package/LICENSE.md +4 -0
- package/README.md +30 -0
- package/dist/index.d.ts +280 -0
- package/dist/index.js +2169 -0
- package/dist/styles.css +68 -0
- package/package.json +60 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @lapismd/mira-react
|
|
2
|
+
|
|
3
|
+
React components for Mira.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { MiraEditor } from "@lapismd/mira-react";
|
|
8
|
+
import "@lapismd/mira-react/styles.css";
|
|
9
|
+
|
|
10
|
+
export function Editor() {
|
|
11
|
+
const [value, setValue] = useState("# Hello");
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<MiraEditor
|
|
15
|
+
value={value}
|
|
16
|
+
defaultEditMode="live-preview"
|
|
17
|
+
onChange={setValue}
|
|
18
|
+
features={{ mermaid: true, "split-mode": true }}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Exports:
|
|
25
|
+
|
|
26
|
+
- `Mira`: composable editor component.
|
|
27
|
+
- `MiraEditor`: batteries-included editor plus toolbar.
|
|
28
|
+
- `MiraEditorToolbar`: standalone toolbar for custom shells.
|
|
29
|
+
|
|
30
|
+
Imperative DOM factories live in `@lapismd/mira-vanilla`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
import { MiraMarkdownActionId, MiraEditorSelection } from '@lapismd/mira/core';
|
|
4
|
+
export { MiraMarkdownActionId } from '@lapismd/mira/core';
|
|
5
|
+
import * as _lapismd_mira_extensions from '@lapismd/mira/extensions';
|
|
6
|
+
import { MiraMode, MiraExtension, MiraBlockControlsOptions, MiraTheme, MiraColorMode, MiraLinkResolver, MiraAssetResolver, MiraFileAdapter, MiraImageConfig, MiraMarkdownAuthoringConfig, MiraCommand, MiraTemplateSelection, MiraToolbarPlacement, MiraMarkdownBlockRange, MiraMarkdownBlockHandle, MiraTextRange, MiraBlockToolbarConfig } from '@lapismd/mira/extensions';
|
|
7
|
+
import { MiraEditorSlashCommandConfig } from '@lapismd/mira-editor';
|
|
8
|
+
export { MiraEditorSlashCommandConfig, MiraEditorSlashCommandId } from '@lapismd/mira-editor';
|
|
9
|
+
import { FrontmatterConfig, MarkdownOutlineVariant } from '@lapismd/mira/preview';
|
|
10
|
+
import * as _lapismd_mira from '@lapismd/mira';
|
|
11
|
+
|
|
12
|
+
type MiraFrontmatterConfig = FrontmatterConfig;
|
|
13
|
+
type MiraOutlineVariant = MarkdownOutlineVariant;
|
|
14
|
+
type MiraReactIcon = ComponentType<{
|
|
15
|
+
"aria-hidden"?: boolean | "true" | "false";
|
|
16
|
+
className?: string;
|
|
17
|
+
}>;
|
|
18
|
+
type MiraEditorEditMode = Extract<MiraMode, "live-preview" | "source">;
|
|
19
|
+
type MiraHandle = {
|
|
20
|
+
applyMarkdownAction: (action: MiraMarkdownActionId) => boolean;
|
|
21
|
+
executeCommand: (commandId: string) => boolean;
|
|
22
|
+
focus: () => void;
|
|
23
|
+
getCommands: () => readonly MiraCommand[];
|
|
24
|
+
getMarkdown: () => string;
|
|
25
|
+
getMode: () => MiraMode;
|
|
26
|
+
getSelection: () => MiraEditorSelection | null;
|
|
27
|
+
insertImage: () => void;
|
|
28
|
+
insertMarkdown: (markdown: string, selection?: MiraTemplateSelection) => void;
|
|
29
|
+
isCommandEnabled: (commandId: string) => boolean;
|
|
30
|
+
setMarkdown: (markdown: string) => void;
|
|
31
|
+
setMode: (mode: MiraMode) => void;
|
|
32
|
+
setReadonly: (readonly: boolean) => void;
|
|
33
|
+
setSelection: (selection: MiraEditorSelection) => void;
|
|
34
|
+
};
|
|
35
|
+
type MiraProps = {
|
|
36
|
+
value?: string;
|
|
37
|
+
defaultValue?: string;
|
|
38
|
+
mode?: MiraMode;
|
|
39
|
+
defaultMode?: MiraMode;
|
|
40
|
+
extensions?: MiraExtension[];
|
|
41
|
+
readonly?: boolean;
|
|
42
|
+
defaultReadonly?: boolean;
|
|
43
|
+
placeholder?: string;
|
|
44
|
+
lineWrapping?: boolean;
|
|
45
|
+
spellcheck?: boolean;
|
|
46
|
+
blockControls?: boolean | MiraBlockControlsOptions;
|
|
47
|
+
indentGuides?: boolean;
|
|
48
|
+
indentWithTabs?: boolean;
|
|
49
|
+
indentWidth?: number;
|
|
50
|
+
theme?: MiraTheme;
|
|
51
|
+
colorMode?: MiraColorMode;
|
|
52
|
+
sourcePath?: string;
|
|
53
|
+
className?: string;
|
|
54
|
+
toolbar?: boolean;
|
|
55
|
+
linkResolver?: MiraLinkResolver;
|
|
56
|
+
assetResolver?: MiraAssetResolver;
|
|
57
|
+
fileAdapter?: MiraFileAdapter;
|
|
58
|
+
imageConfig?: MiraImageConfig;
|
|
59
|
+
authoring?: MiraMarkdownAuthoringConfig;
|
|
60
|
+
frontmatterOpen?: boolean;
|
|
61
|
+
frontmatterConfig?: MiraFrontmatterConfig;
|
|
62
|
+
headingIds?: boolean;
|
|
63
|
+
headingIdPrefix?: string;
|
|
64
|
+
htmlPolicy?: "trusted" | "safe";
|
|
65
|
+
emoji?: boolean;
|
|
66
|
+
outline?: boolean;
|
|
67
|
+
outlineVariant?: MiraOutlineVariant;
|
|
68
|
+
onChange?: (value: string) => void;
|
|
69
|
+
onModeChange?: (mode: MiraMode) => void;
|
|
70
|
+
onReadonlyChange?: (readonly: boolean) => void;
|
|
71
|
+
onFrontmatterChange?: (nextYaml: string, nextValue: string) => void;
|
|
72
|
+
};
|
|
73
|
+
type MiraFeatureName = "toolbar" | "mode-switch" | "formatting" | "headings" | "lists" | "links" | "tables" | "grid-tables" | "mermaid" | "code" | "math" | "frontmatter" | "images" | "embeds" | "wikilinks" | "tags" | "slash-commands" | "block-controls" | "source-mode" | "live-preview-mode" | "preview-mode" | "split-mode";
|
|
74
|
+
type MiraFeatureFlags = Partial<Record<MiraFeatureName, boolean>>;
|
|
75
|
+
type ResolvedMiraEditorFeatures = Record<MiraFeatureName, boolean>;
|
|
76
|
+
type MiraEditorToolbarItem = "heading" | "bold" | "italic" | "strikethrough" | "inlineCode" | "quote" | "bulletList" | "numberedList" | "taskList" | "link" | "image" | "table" | "gridTable" | "code" | "math" | "mermaid";
|
|
77
|
+
type MiraEditorToolbarActionContext = {
|
|
78
|
+
value: string;
|
|
79
|
+
mode: MiraMode;
|
|
80
|
+
readonly: boolean;
|
|
81
|
+
applyMarkdownAction?: (action: MiraMarkdownActionId) => boolean;
|
|
82
|
+
focus: () => void;
|
|
83
|
+
getIndentGuides?: () => boolean;
|
|
84
|
+
getIndentWidth?: () => number;
|
|
85
|
+
getIndentWithTabs?: () => boolean;
|
|
86
|
+
getMarkdown: () => string;
|
|
87
|
+
getMode: () => MiraMode;
|
|
88
|
+
getSelection: () => MiraEditorSelection | null;
|
|
89
|
+
insertImage: () => void;
|
|
90
|
+
insertMarkdown: (markdown: string) => void;
|
|
91
|
+
setIndentGuides?: (enabled: boolean) => void;
|
|
92
|
+
setIndentWidth?: (width: number) => void;
|
|
93
|
+
setIndentWithTabs?: (enabled: boolean) => void;
|
|
94
|
+
setMarkdown: (markdown: string) => void;
|
|
95
|
+
setMode: (mode: MiraMode) => void;
|
|
96
|
+
setReadonly: (readonly: boolean) => void;
|
|
97
|
+
setSelection: (selection: MiraEditorSelection) => void;
|
|
98
|
+
block?: MiraMarkdownBlockRange;
|
|
99
|
+
blocks?: MiraMarkdownBlockRange[];
|
|
100
|
+
handle?: MiraMarkdownBlockHandle;
|
|
101
|
+
affectedRange?: MiraMarkdownBlockRange;
|
|
102
|
+
replaceRange?: (markdown: string, range: MiraTextRange, selection?: MiraTemplateSelection) => void;
|
|
103
|
+
};
|
|
104
|
+
type MiraEditorToolbarPlacement = MiraToolbarPlacement;
|
|
105
|
+
type MiraEditorToolbarDynamicBoolean = boolean | ((context: MiraEditorToolbarActionContext) => boolean);
|
|
106
|
+
type MiraEditorToolbarMenuAction = {
|
|
107
|
+
type?: "item";
|
|
108
|
+
id: string;
|
|
109
|
+
label: string;
|
|
110
|
+
icon?: MiraReactIcon;
|
|
111
|
+
shortcut?: string;
|
|
112
|
+
checked?: MiraEditorToolbarDynamicBoolean;
|
|
113
|
+
disabled?: MiraEditorToolbarDynamicBoolean;
|
|
114
|
+
run: (context: MiraEditorToolbarActionContext) => void;
|
|
115
|
+
};
|
|
116
|
+
type MiraEditorToolbarMenuLabel = {
|
|
117
|
+
type: "label";
|
|
118
|
+
id?: string;
|
|
119
|
+
label: string;
|
|
120
|
+
};
|
|
121
|
+
type MiraEditorToolbarMenuSeparator = {
|
|
122
|
+
type: "separator";
|
|
123
|
+
id?: string;
|
|
124
|
+
};
|
|
125
|
+
type MiraEditorToolbarMenuItem = MiraEditorToolbarMenuAction | MiraEditorToolbarMenuLabel | MiraEditorToolbarMenuSeparator;
|
|
126
|
+
type MiraEditorToolbarButtonAction = {
|
|
127
|
+
type?: "button";
|
|
128
|
+
id: string;
|
|
129
|
+
label: string;
|
|
130
|
+
icon: MiraReactIcon;
|
|
131
|
+
group?: string;
|
|
132
|
+
placements?: readonly MiraEditorToolbarPlacement[];
|
|
133
|
+
shortcut?: string;
|
|
134
|
+
tooltip?: string;
|
|
135
|
+
disabled?: MiraEditorToolbarDynamicBoolean;
|
|
136
|
+
pressed?: MiraEditorToolbarDynamicBoolean;
|
|
137
|
+
run: (context: MiraEditorToolbarActionContext) => void;
|
|
138
|
+
};
|
|
139
|
+
type MiraEditorToolbarDropdownAction = {
|
|
140
|
+
type: "dropdown";
|
|
141
|
+
id: string;
|
|
142
|
+
label: string;
|
|
143
|
+
icon: MiraReactIcon;
|
|
144
|
+
tooltip?: string;
|
|
145
|
+
disabled?: MiraEditorToolbarDynamicBoolean;
|
|
146
|
+
items: MiraEditorToolbarMenuItem[];
|
|
147
|
+
};
|
|
148
|
+
type MiraEditorToolbarAction = MiraEditorToolbarButtonAction | MiraEditorToolbarDropdownAction;
|
|
149
|
+
type MiraEditorToolbarDefinition = {
|
|
150
|
+
id: string;
|
|
151
|
+
label?: string;
|
|
152
|
+
align?: "start" | "end";
|
|
153
|
+
items: MiraEditorToolbarAction[];
|
|
154
|
+
};
|
|
155
|
+
type MiraEditorToolbarConfig = {
|
|
156
|
+
items?: MiraEditorToolbarItem[];
|
|
157
|
+
actions?: MiraEditorToolbarAction[];
|
|
158
|
+
toolbars?: MiraEditorToolbarDefinition[];
|
|
159
|
+
};
|
|
160
|
+
type MiraEditorMermaidConfig = {
|
|
161
|
+
enabled?: boolean;
|
|
162
|
+
};
|
|
163
|
+
type MiraEditorBlockControlsConfig = {
|
|
164
|
+
enabled?: boolean;
|
|
165
|
+
toolbar?: boolean | MiraBlockToolbarConfig;
|
|
166
|
+
};
|
|
167
|
+
type MiraEditorFeatureConfigs = {
|
|
168
|
+
toolbar?: MiraEditorToolbarConfig;
|
|
169
|
+
mermaid?: MiraEditorMermaidConfig;
|
|
170
|
+
"block-controls"?: MiraEditorBlockControlsConfig;
|
|
171
|
+
"slash-commands"?: MiraEditorSlashCommandConfig;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
type MiraEditorToolbarProps = {
|
|
175
|
+
value?: string;
|
|
176
|
+
mode?: MiraMode;
|
|
177
|
+
defaultEditMode?: MiraEditorEditMode;
|
|
178
|
+
readonly?: boolean;
|
|
179
|
+
className?: string;
|
|
180
|
+
features?: MiraFeatureFlags;
|
|
181
|
+
featureConfigs?: MiraEditorFeatureConfigs;
|
|
182
|
+
toolbarActions?: MiraEditorToolbarAction[];
|
|
183
|
+
toolbars?: MiraEditorToolbarDefinition[];
|
|
184
|
+
modeOptions?: MiraMode[];
|
|
185
|
+
showModeSwitch?: boolean;
|
|
186
|
+
indentGuides?: boolean;
|
|
187
|
+
indentWithTabs?: boolean;
|
|
188
|
+
indentWidth?: number;
|
|
189
|
+
context?: MiraEditorToolbarActionContext;
|
|
190
|
+
onModeChange?: (mode: MiraMode) => void;
|
|
191
|
+
onInsertMarkdown?: (markdown: string) => void;
|
|
192
|
+
onInsertImage?: () => void;
|
|
193
|
+
onIndentGuidesChange?: (enabled: boolean) => void;
|
|
194
|
+
onIndentWidthChange?: (width: number) => void;
|
|
195
|
+
onIndentWithTabsChange?: (enabled: boolean) => void;
|
|
196
|
+
};
|
|
197
|
+
type MiraEditorProps = Omit<MiraProps, "toolbar"> & {
|
|
198
|
+
defaultEditMode?: MiraEditorEditMode;
|
|
199
|
+
editorClassName?: string;
|
|
200
|
+
features?: MiraFeatureFlags;
|
|
201
|
+
featureConfigs?: MiraEditorFeatureConfigs;
|
|
202
|
+
toolbarActions?: MiraEditorToolbarAction[];
|
|
203
|
+
toolbars?: MiraEditorToolbarDefinition[];
|
|
204
|
+
onIndentGuidesChange?: (enabled: boolean) => void;
|
|
205
|
+
onIndentWidthChange?: (width: number) => void;
|
|
206
|
+
onIndentWithTabsChange?: (enabled: boolean) => void;
|
|
207
|
+
};
|
|
208
|
+
type MiraEditorHandle = MiraHandle;
|
|
209
|
+
|
|
210
|
+
declare const Mira: react.ForwardRefExoticComponent<MiraProps & react.RefAttributes<MiraHandle>>;
|
|
211
|
+
|
|
212
|
+
declare const MiraEditor: react.ForwardRefExoticComponent<Omit<MiraProps, "toolbar"> & {
|
|
213
|
+
defaultEditMode?: MiraEditorEditMode;
|
|
214
|
+
editorClassName?: string;
|
|
215
|
+
features?: MiraFeatureFlags;
|
|
216
|
+
featureConfigs?: MiraEditorFeatureConfigs;
|
|
217
|
+
toolbarActions?: MiraEditorToolbarAction[];
|
|
218
|
+
toolbars?: MiraEditorToolbarDefinition[];
|
|
219
|
+
onIndentGuidesChange?: (enabled: boolean) => void;
|
|
220
|
+
onIndentWidthChange?: (width: number) => void;
|
|
221
|
+
onIndentWithTabsChange?: (enabled: boolean) => void;
|
|
222
|
+
} & react.RefAttributes<MiraHandle>>;
|
|
223
|
+
|
|
224
|
+
declare function MiraEditorToolbar({ className, context, defaultEditMode, featureConfigs, features, indentGuides, indentWithTabs, indentWidth, mode, modeOptions: modeOptionsProp, onIndentGuidesChange, onIndentWidthChange, onIndentWithTabsChange, onInsertMarkdown, onInsertImage, onModeChange, readonly, showModeSwitch, toolbarActions, toolbars, value, }: MiraEditorToolbarProps): React.ReactElement;
|
|
225
|
+
|
|
226
|
+
declare const MiraFeature: {
|
|
227
|
+
readonly Toolbar: "toolbar";
|
|
228
|
+
readonly ModeSwitch: "mode-switch";
|
|
229
|
+
readonly Formatting: "formatting";
|
|
230
|
+
readonly Headings: "headings";
|
|
231
|
+
readonly Lists: "lists";
|
|
232
|
+
readonly Links: "links";
|
|
233
|
+
readonly Tables: "tables";
|
|
234
|
+
readonly GridTables: "grid-tables";
|
|
235
|
+
readonly Mermaid: "mermaid";
|
|
236
|
+
readonly Code: "code";
|
|
237
|
+
readonly Math: "math";
|
|
238
|
+
readonly Frontmatter: "frontmatter";
|
|
239
|
+
readonly Images: "images";
|
|
240
|
+
readonly Embeds: "embeds";
|
|
241
|
+
readonly Wikilinks: "wikilinks";
|
|
242
|
+
readonly Tags: "tags";
|
|
243
|
+
readonly SlashCommands: "slash-commands";
|
|
244
|
+
readonly BlockControls: "block-controls";
|
|
245
|
+
readonly SourceMode: "source-mode";
|
|
246
|
+
readonly LivePreviewMode: "live-preview-mode";
|
|
247
|
+
readonly PreviewMode: "preview-mode";
|
|
248
|
+
readonly SplitMode: "split-mode";
|
|
249
|
+
};
|
|
250
|
+
declare const defaultMiraEditorFeatures: ResolvedMiraEditorFeatures;
|
|
251
|
+
declare const defaultMiraEditorEditMode: MiraEditorEditMode;
|
|
252
|
+
declare function resolveMiraEditorFeatures(features?: MiraFeatureFlags): ResolvedMiraEditorFeatures;
|
|
253
|
+
declare function resolveMiraEditorBlockControls(options?: {
|
|
254
|
+
featureConfigs?: MiraEditorFeatureConfigs;
|
|
255
|
+
features?: MiraFeatureFlags;
|
|
256
|
+
}): boolean | _lapismd_mira.MiraBlockControlsOptions;
|
|
257
|
+
declare function createMiraEditorExtensions({ featureConfigs, features, }?: {
|
|
258
|
+
featureConfigs?: MiraEditorFeatureConfigs;
|
|
259
|
+
features?: MiraFeatureFlags;
|
|
260
|
+
}): MiraExtension[];
|
|
261
|
+
declare function resolveMiraEditorSlashCommands({ featureConfigs, features, }?: {
|
|
262
|
+
featureConfigs?: MiraEditorFeatureConfigs;
|
|
263
|
+
features?: MiraFeatureFlags;
|
|
264
|
+
}): _lapismd_mira_extensions.MiraSlashCommand[];
|
|
265
|
+
declare function resolveMiraEditorToolbarItems({ featureConfigs, features, }?: {
|
|
266
|
+
featureConfigs?: MiraEditorFeatureConfigs;
|
|
267
|
+
features?: MiraFeatureFlags;
|
|
268
|
+
}): MiraEditorToolbarItem[];
|
|
269
|
+
declare function resolveMiraEditorToolbarActions({ featureConfigs, toolbarActions, }?: {
|
|
270
|
+
featureConfigs?: MiraEditorFeatureConfigs;
|
|
271
|
+
toolbarActions?: MiraEditorToolbarAction[];
|
|
272
|
+
}): MiraEditorToolbarAction[];
|
|
273
|
+
declare function resolveMiraEditorToolbarDefinitions({ featureConfigs, toolbars, }?: {
|
|
274
|
+
featureConfigs?: MiraEditorFeatureConfigs;
|
|
275
|
+
toolbars?: MiraEditorToolbarDefinition[];
|
|
276
|
+
}): MiraEditorToolbarDefinition[];
|
|
277
|
+
declare function resolveMiraEditorModes(features?: MiraFeatureFlags): MiraMode[];
|
|
278
|
+
declare function resolveMiraEditorEditMode(defaultEditMode?: MiraEditorEditMode, modeOptions?: MiraMode[]): MiraEditorEditMode;
|
|
279
|
+
|
|
280
|
+
export { Mira, MiraEditor, type MiraEditorBlockControlsConfig, type MiraEditorEditMode, type MiraEditorFeatureConfigs, type MiraEditorHandle, type MiraEditorMermaidConfig, type MiraEditorProps, MiraEditorToolbar, type MiraEditorToolbarAction, type MiraEditorToolbarActionContext, type MiraEditorToolbarButtonAction, type MiraEditorToolbarConfig, type MiraEditorToolbarDefinition, type MiraEditorToolbarDropdownAction, type MiraEditorToolbarItem, type MiraEditorToolbarMenuAction, type MiraEditorToolbarMenuItem, type MiraEditorToolbarMenuLabel, type MiraEditorToolbarMenuSeparator, type MiraEditorToolbarPlacement, type MiraEditorToolbarProps, MiraFeature, type MiraFeatureFlags, type MiraFeatureName, type MiraFrontmatterConfig, type MiraHandle, type MiraOutlineVariant, type MiraProps, type MiraReactIcon, type ResolvedMiraEditorFeatures, createMiraEditorExtensions, Mira as default, defaultMiraEditorEditMode, defaultMiraEditorFeatures, resolveMiraEditorBlockControls, resolveMiraEditorEditMode, resolveMiraEditorFeatures, resolveMiraEditorModes, resolveMiraEditorSlashCommands, resolveMiraEditorToolbarActions, resolveMiraEditorToolbarDefinitions, resolveMiraEditorToolbarItems };
|