@lapismd/mira-vanilla 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 +19 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +144 -0
- package/package.json +47 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# `@lapismd/mira-vanilla`
|
|
2
|
+
|
|
3
|
+
Plain JavaScript mounting factories for both public editor products.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createMiraEditor } from "@lapismd/mira-vanilla";
|
|
7
|
+
import "@lapismd/mira-editor/styles.css";
|
|
8
|
+
|
|
9
|
+
const editor = createMiraEditor({
|
|
10
|
+
root: document.getElementById("editor")!,
|
|
11
|
+
value: "# Hello Mira",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
editor.setMode("preview");
|
|
15
|
+
editor.destroy();
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Use `createMira(target, props)` for the composable editor and
|
|
19
|
+
`createMiraEditor(options)` for the batteries-included editor.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MiraProps } from '@lapismd/mira';
|
|
2
|
+
export { MiraMarkdownActionId, MiraProps } from '@lapismd/mira';
|
|
3
|
+
import { MiraMode } from '@lapismd/mira/extensions';
|
|
4
|
+
import { MiraEditorHandle, MiraEditorProps } from '@lapismd/mira-editor';
|
|
5
|
+
export { MiraEditorHandle, MiraEditorProps } from '@lapismd/mira-editor';
|
|
6
|
+
|
|
7
|
+
type MiraInstance = {
|
|
8
|
+
update: (props: Partial<MiraProps>) => void;
|
|
9
|
+
destroy: () => void;
|
|
10
|
+
};
|
|
11
|
+
declare function createMira(target: HTMLElement, props: MiraProps): MiraInstance;
|
|
12
|
+
type MiraEditorOptions = Omit<MiraEditorProps, "class"> & {
|
|
13
|
+
root: HTMLElement;
|
|
14
|
+
class?: string;
|
|
15
|
+
};
|
|
16
|
+
type MiraEditorEventMap = {
|
|
17
|
+
change: string;
|
|
18
|
+
modeChange: MiraMode;
|
|
19
|
+
readonlyChange: boolean;
|
|
20
|
+
};
|
|
21
|
+
type MiraEditorEventName = keyof MiraEditorEventMap;
|
|
22
|
+
type MiraEditorEventHandler<EventName extends MiraEditorEventName> = (payload: MiraEditorEventMap[EventName]) => void;
|
|
23
|
+
type MiraEditorInstance = MiraEditorHandle & {
|
|
24
|
+
destroy: () => void;
|
|
25
|
+
on: <EventName extends MiraEditorEventName>(event: EventName, handler: MiraEditorEventHandler<EventName>) => () => void;
|
|
26
|
+
update: (props: Partial<Omit<MiraEditorOptions, "root">>) => void;
|
|
27
|
+
};
|
|
28
|
+
declare function createMiraEditor(options: MiraEditorOptions): MiraEditorInstance;
|
|
29
|
+
|
|
30
|
+
export { type MiraEditorEventHandler, type MiraEditorEventMap, type MiraEditorEventName, type MiraEditorInstance, type MiraEditorOptions, type MiraInstance, createMira, createMiraEditor, createMira as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { mount, unmount } from "svelte";
|
|
3
|
+
import Mira from "@lapismd/mira";
|
|
4
|
+
import MiraEditor from "@lapismd/mira-editor";
|
|
5
|
+
function createMira(target, props) {
|
|
6
|
+
let currentProps = { ...props };
|
|
7
|
+
let component = mount(Mira, {
|
|
8
|
+
target,
|
|
9
|
+
props: currentProps
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
update(nextProps) {
|
|
13
|
+
currentProps = {
|
|
14
|
+
...currentProps,
|
|
15
|
+
...nextProps
|
|
16
|
+
};
|
|
17
|
+
unmount(component);
|
|
18
|
+
component = mount(Mira, {
|
|
19
|
+
target,
|
|
20
|
+
props: currentProps
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
destroy() {
|
|
24
|
+
unmount(component);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function createMiraEditor(options) {
|
|
29
|
+
const { root, ...initialProps } = options;
|
|
30
|
+
let currentProps = { ...initialProps };
|
|
31
|
+
let currentValue = initialProps.value ?? "";
|
|
32
|
+
let currentMode = initialProps.mode ?? initialProps.defaultEditMode ?? "live-preview";
|
|
33
|
+
let currentReadonly = initialProps.readonly ?? false;
|
|
34
|
+
const listeners = {
|
|
35
|
+
change: /* @__PURE__ */ new Set(),
|
|
36
|
+
modeChange: /* @__PURE__ */ new Set(),
|
|
37
|
+
readonlyChange: /* @__PURE__ */ new Set()
|
|
38
|
+
};
|
|
39
|
+
let component = mountComponent();
|
|
40
|
+
function mountComponent() {
|
|
41
|
+
return mount(MiraEditor, {
|
|
42
|
+
target: root,
|
|
43
|
+
props: {
|
|
44
|
+
...currentProps,
|
|
45
|
+
value: currentValue,
|
|
46
|
+
mode: currentMode,
|
|
47
|
+
readonly: currentReadonly,
|
|
48
|
+
onChange(value) {
|
|
49
|
+
currentValue = value;
|
|
50
|
+
currentProps.onChange?.(value);
|
|
51
|
+
emit("change", value);
|
|
52
|
+
},
|
|
53
|
+
onModeChange(mode) {
|
|
54
|
+
currentMode = mode;
|
|
55
|
+
currentProps.onModeChange?.(mode);
|
|
56
|
+
emit("modeChange", mode);
|
|
57
|
+
},
|
|
58
|
+
onReadonlyChange(readonly) {
|
|
59
|
+
currentReadonly = readonly;
|
|
60
|
+
currentProps.onReadonlyChange?.(readonly);
|
|
61
|
+
emit("readonlyChange", readonly);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function emit(event, payload) {
|
|
67
|
+
for (const listener of listeners[event]) {
|
|
68
|
+
listener(payload);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function remount() {
|
|
72
|
+
unmount(component);
|
|
73
|
+
component = mountComponent();
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
applyMarkdownAction(action) {
|
|
77
|
+
return component.applyMarkdownAction(action);
|
|
78
|
+
},
|
|
79
|
+
destroy() {
|
|
80
|
+
unmount(component);
|
|
81
|
+
},
|
|
82
|
+
executeCommand(commandId) {
|
|
83
|
+
return component.executeCommand(commandId);
|
|
84
|
+
},
|
|
85
|
+
focus() {
|
|
86
|
+
component.focus();
|
|
87
|
+
},
|
|
88
|
+
getCommands() {
|
|
89
|
+
return component.getCommands();
|
|
90
|
+
},
|
|
91
|
+
getMarkdown() {
|
|
92
|
+
return component.getMarkdown?.() ?? currentValue;
|
|
93
|
+
},
|
|
94
|
+
getMode() {
|
|
95
|
+
return component.getMode?.() ?? currentMode;
|
|
96
|
+
},
|
|
97
|
+
getSelection() {
|
|
98
|
+
return component.getSelection?.() ?? null;
|
|
99
|
+
},
|
|
100
|
+
insertMarkdown(markdown, selection) {
|
|
101
|
+
component.insertMarkdown(markdown, selection);
|
|
102
|
+
},
|
|
103
|
+
insertImage() {
|
|
104
|
+
component.insertImage();
|
|
105
|
+
},
|
|
106
|
+
isCommandEnabled(commandId) {
|
|
107
|
+
return component.isCommandEnabled(commandId);
|
|
108
|
+
},
|
|
109
|
+
on(event, handler) {
|
|
110
|
+
listeners[event].add(handler);
|
|
111
|
+
return () => {
|
|
112
|
+
listeners[event].delete(handler);
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
setMarkdown(markdown) {
|
|
116
|
+
currentValue = markdown;
|
|
117
|
+
component.setMarkdown(markdown);
|
|
118
|
+
},
|
|
119
|
+
setMode(mode) {
|
|
120
|
+
component.setMode(mode);
|
|
121
|
+
currentMode = component.getMode();
|
|
122
|
+
},
|
|
123
|
+
setReadonly(readonly) {
|
|
124
|
+
currentReadonly = readonly;
|
|
125
|
+
component.setReadonly(readonly);
|
|
126
|
+
},
|
|
127
|
+
setSelection(selection) {
|
|
128
|
+
component.setSelection(selection);
|
|
129
|
+
},
|
|
130
|
+
update(props) {
|
|
131
|
+
currentProps = { ...currentProps, ...props };
|
|
132
|
+
if (props.value !== void 0) currentValue = props.value;
|
|
133
|
+
if (props.mode !== void 0) currentMode = props.mode;
|
|
134
|
+
if (props.readonly !== void 0) currentReadonly = props.readonly;
|
|
135
|
+
remount();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
var index_default = createMira;
|
|
140
|
+
export {
|
|
141
|
+
createMira,
|
|
142
|
+
createMiraEditor,
|
|
143
|
+
index_default as default
|
|
144
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lapismd/mira-vanilla",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Plain JavaScript factories for the composable Mira and batteries-included Mira Editor surfaces.",
|
|
5
|
+
"author": "Steve Juma <help@lapis.md>",
|
|
6
|
+
"license": "AGPL-3.0-or-later",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/lapismd/mira-mde.git",
|
|
10
|
+
"directory": "packages/mira-vanilla"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"files": [
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@lapismd/mira-editor": "~0.0.1",
|
|
26
|
+
"@lapismd/mira": "~0.0.1"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"svelte": "^5.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"svelte": "^5.46.1"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
40
|
+
"check": "pnpm check:format && pnpm check:svelte && pnpm check:types",
|
|
41
|
+
"check:format": "prettier --ignore-path ../../.prettierignore . --check",
|
|
42
|
+
"check:types": "tsc -p tsconfig.json --noEmit",
|
|
43
|
+
"check:svelte": "echo \"no svelte files\"",
|
|
44
|
+
"lint": "eslint src --ext .ts",
|
|
45
|
+
"test": "vitest run"
|
|
46
|
+
}
|
|
47
|
+
}
|