@myedit/preact 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yusuke Nakada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,208 @@
1
- # Temporary Holding Version
1
+ # myedit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A lightweight WYSIWYG Markdown editor library with an Obsidian-like live preview.
4
+
5
+ English | [日本語](REAMDE.ja.md)
6
+
7
+ myedit is a lightweight Markdown editor library featuring an Obsidian-like live preview. Built on CodeMirror 6, it provides a framework-agnostic core along with adapters for React, Preact, Vue, and Svelte.
8
+
9
+ ## Features
10
+
11
+ - UI framework-agnostic
12
+ - Adapters for React / Preact / Vue / Svelte
13
+ - GitHub Flavored Markdown (GFM) support
14
+ - Mermaid and math rendering support
15
+ - Interactive table editor
16
+ - Embeds for major services
17
+ - YouTube / X (Twitter) / Docswell / SlideShare / Speaker Deck / CodePen / CodeSandbox / Figma / Spotify / Vimeo / Loom
18
+ - GitHub repository cards and generic link cards
19
+ - WikiLink syntax and `[[` autocompletion
20
+ - Slash command `/` autocompletion
21
+
22
+ ## Packages
23
+
24
+ | Package | npm | Description |
25
+ | :--------------- | :-------------------------------------------------------------------------------------------------- | :--------------------------------- |
26
+ | `@myedit/core` | [![npm](https://img.shields.io/npm/v/@myedit/core)](https://www.npmjs.com/package/@myedit/core) | Framework-agnostic core library |
27
+ | `@myedit/react` | [![npm](https://img.shields.io/npm/v/@myedit/react)](https://www.npmjs.com/package/@myedit/react) | Components & hooks for React |
28
+ | `@myedit/preact` | [![npm](https://img.shields.io/npm/v/@myedit/preact)](https://www.npmjs.com/package/@myedit/preact) | Components & hooks for Preact |
29
+ | `@myedit/vue` | [![npm](https://img.shields.io/npm/v/@myedit/vue)](https://www.npmjs.com/package/@myedit/vue) | Components & composables for Vue 3 |
30
+ | `@myedit/svelte` | [![npm](https://img.shields.io/npm/v/@myedit/svelte)](https://www.npmjs.com/package/@myedit/svelte) | Actions for Svelte |
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ npm add @myedit/core
36
+
37
+ npm add @myedit/react
38
+ npm add @myedit/preact
39
+ npm add @myedit/vue
40
+ npm add @myedit/svelte
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ ### Vanilla TypeScript
46
+
47
+ ```ts
48
+ import { createMyEdit } from "@myedit/core";
49
+ import "@myedit/core/styles.css";
50
+
51
+ const editor = createMyEdit(document.getElementById("editor")!, {
52
+ value: "# Hello, myedit\n",
53
+ theme: "auto",
54
+ onChange: (markdown) => {
55
+ console.log(markdown);
56
+ },
57
+ });
58
+
59
+ // cleanup
60
+ // editor.destroy();
61
+ ```
62
+
63
+ ### React
64
+
65
+ ```tsx
66
+ import { MyEditEditor } from "@myedit/react";
67
+ import "@myedit/core/styles.css";
68
+
69
+ export function App() {
70
+ return <MyEditEditor value="# Hello React" theme="light" onChange={(md) => console.log(md)} />;
71
+ }
72
+ ```
73
+
74
+ ### Preact
75
+
76
+ ```tsx
77
+ import { MyEditEditor } from "@myedit/preact";
78
+ import "@myedit/core/styles.css";
79
+
80
+ export function App() {
81
+ return <MyEditEditor value="# Hello Preact" theme="light" onChange={(md) => console.log(md)} />;
82
+ }
83
+ ```
84
+
85
+ ### Vue 3
86
+
87
+ ```vue
88
+ <script setup lang="ts">
89
+ import { ref } from "vue";
90
+ import { MyEditEditor } from "@myedit/vue";
91
+ import "@myedit/core/styles.css";
92
+
93
+ const content = ref("# Hello Vue");
94
+ </script>
95
+
96
+ <template>
97
+ <MyEditEditor v-model="content" theme="light" />
98
+ </template>
99
+ ```
100
+
101
+ ### Svelte
102
+
103
+ ```svelte
104
+ <script lang="ts">
105
+ import { myedit } from '@myedit/svelte';
106
+ import '@myedit/core/styles.css';
107
+
108
+ let value = '# Hello Svelte';
109
+ </script>
110
+
111
+ <div use:myedit={{ value, theme: 'light', onChange: (v) => (value = v) }}></div>
112
+ ```
113
+
114
+ ## API Reference
115
+
116
+ ### `createMyEdit(container, options?)`
117
+
118
+ #### `MyEditOptions`
119
+
120
+ | Option | Type | Default | Description |
121
+ | :--------------- | :------------------------------ | :---------- | :------------------------------------------------ |
122
+ | `value` | `string` | `''` | Markdown text |
123
+ | `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | Color theme |
124
+ | `placeholder` | `string` | `undefined` | Placeholder shown when empty |
125
+ | `readOnly` | `boolean` | `false` | Read-only mode |
126
+ | `features` | `MyEditFeatures` | All `true` | Enable/disable syntax, commands, and features |
127
+ | `wikilink` | `WikiLinkOptions` | `undefined` | WikiLink resolution, completion, and click config |
128
+ | `onChange` | `(value: string) => void` | `undefined` | Callback fired when the document changes |
129
+ | `onCursorChange` | `(pos: CursorPosition) => void` | `undefined` | Callback fired when the cursor position changes |
130
+
131
+ #### `MyEditFeatures`
132
+
133
+ ```ts
134
+ interface MyEditFeatures {
135
+ mermaid?: boolean;
136
+ math?: boolean;
137
+ table?: boolean;
138
+ embeds?: boolean;
139
+ linkCards?: boolean;
140
+ wikilink?: boolean;
141
+ highlight?: boolean;
142
+ subSup?: boolean;
143
+ slashCommands?: boolean;
144
+ shortcuts?: boolean;
145
+ search?: boolean;
146
+ }
147
+ ```
148
+
149
+ #### `WikiLinkOptions`
150
+
151
+ ```ts
152
+ interface WikiLinkOptions {
153
+ resolve?: (target: string) => boolean;
154
+ complete?: (query: string) => WikiLinkItem[] | Promise<WikiLinkItem[]>;
155
+ onClick?: (target: string) => void;
156
+ }
157
+ ```
158
+
159
+ #### `MyEdit`
160
+
161
+ | Method | Description |
162
+ | :------------------------------------- | :----------------------------------------------------------- |
163
+ | `getValue(): string` | Get the current Markdown text |
164
+ | `setValue(value: string): void` | Set the Markdown text |
165
+ | `setTheme(theme: MyEditTheme): void` | Switch the theme |
166
+ | `setReadOnly(readOnly: boolean): void` | Toggle read-only mode |
167
+ | `getCursorPosition(): CursorPosition` | Get the current cursor position (`line`, `column`, `offset`) |
168
+ | `getSelection(): MyEditSelection` | Get the current selection range (`from`, `to`, `text`) |
169
+ | `insertText(text: string): void` | Insert text at the current cursor position |
170
+ | `focus(): void` | Focus the editor |
171
+ | `destroy(): void` | Destroy the editor and release DOM elements and listeners |
172
+
173
+ ## Shortcuts & Slash Commands
174
+
175
+ ### Keyboard Shortcuts
176
+
177
+ | Key | Action |
178
+ | :-------------------------------------- | :------------------------ |
179
+ | `Cmd/Ctrl + B` | Bold (`**...**`) |
180
+ | `Cmd/Ctrl + I` | Italic (`*...*`) |
181
+ | `Cmd/Ctrl + E` | Inline code (`` `...` ``) |
182
+ | `Cmd/Ctrl + Shift + S` | Strikethrough (`~~...~~`) |
183
+ | `Cmd/Ctrl + Shift + H` | Highlight (`==...==`) |
184
+ | `Cmd/Ctrl + K` | Link (`[text](url)`) |
185
+ | `Cmd/Ctrl + F` | Search & replace |
186
+ | `Cmd/Ctrl + Z` / `Cmd/Ctrl + Shift + Z` | Undo / Redo |
187
+
188
+ ### Slash Commands (`/`)
189
+
190
+ `/h1`–`/h6`, `/bullet`, `/number`, `/task`, `/image`, `/code`, `/mermaid`, `/math`, `/table`, `/quote`, `/note`, `/tip`, `/important`, `/warning`, `/caution`, `/hr`
191
+
192
+ ## Theme Customization
193
+
194
+ You can customize colors, fonts, and max width by overriding the CSS custom properties on `.myedit-root`.
195
+
196
+ ```css
197
+ .myedit-root {
198
+ --myedit-bg: #ffffff;
199
+ --myedit-fg: #1c1c1e;
200
+ --myedit-accent: #2563eb;
201
+ --myedit-link: #2563eb;
202
+ --myedit-max-width: 780px;
203
+ }
204
+ ```
205
+
206
+ ## License
207
+
208
+ myedit is released under the [MIT License](LICENSE).
@@ -0,0 +1,13 @@
1
+ import { JSX, RefObject, h } from "preact";
2
+ import { MyEdit, MyEditOptions } from "@myedit/core";
3
+ export interface MyEditProps extends MyEditOptions {
4
+ class?: string;
5
+ style?: JSX.CSSProperties;
6
+ editorRef?: RefObject<MyEdit | null>;
7
+ }
8
+ export declare function useMyEdit(containerRef: RefObject<HTMLElement | null>, options?: MyEditOptions): RefObject<MyEdit | null>;
9
+ export declare function MyEditEditor(props: MyEditProps): import("preact").VNode<import("preact").ClassAttributes<HTMLDivElement> & {
10
+ ref: import("preact/hooks").MutableRef<HTMLDivElement | null>;
11
+ class: string | undefined;
12
+ style: h.JSX.CSSProperties | undefined;
13
+ }>;
package/dist/index.mjs ADDED
@@ -0,0 +1,62 @@
1
+ import { h } from "preact";
2
+ import { useEffect, useRef } from "preact/hooks";
3
+ import { createMyEdit } from "@myedit/core";
4
+ // src/index.ts
5
+ function useMyEdit(containerRef, options = {}) {
6
+ const instanceRef = useRef(null);
7
+ const mountedRef = useRef(false);
8
+ const optionsRef = useRef(options);
9
+ optionsRef.current = options;
10
+ useEffect(() => {
11
+ const el = containerRef.current;
12
+ if (!el) return;
13
+ const initial = optionsRef.current;
14
+ const editor = createMyEdit(el, {
15
+ value: initial.value,
16
+ theme: initial.theme,
17
+ placeholder: initial.placeholder,
18
+ readOnly: initial.readOnly,
19
+ features: initial.features,
20
+ wikilink: initial.wikilink,
21
+ onChange: (val) => optionsRef.current.onChange?.(val),
22
+ onCursorChange: (pos) => optionsRef.current.onCursorChange?.(pos)
23
+ });
24
+ instanceRef.current = editor;
25
+ mountedRef.current = true;
26
+ return () => {
27
+ mountedRef.current = false;
28
+ editor.destroy();
29
+ instanceRef.current = null;
30
+ };
31
+ }, [containerRef]);
32
+ useEffect(() => {
33
+ if (mountedRef.current && options.value !== void 0) instanceRef.current?.setValue(options.value);
34
+ }, [options.value]);
35
+ useEffect(() => {
36
+ if (mountedRef.current && options.theme !== void 0) instanceRef.current?.setTheme(options.theme);
37
+ }, [options.theme]);
38
+ useEffect(() => {
39
+ if (mountedRef.current && options.readOnly !== void 0) instanceRef.current?.setReadOnly(options.readOnly);
40
+ }, [options.readOnly]);
41
+ return instanceRef;
42
+ }
43
+ function MyEditEditor(props) {
44
+ const { class: className, style, editorRef, ...options } = props;
45
+ const containerRef = useRef(null);
46
+ const instanceRef = useMyEdit(containerRef, options);
47
+ useEffect(() => {
48
+ if (!editorRef) return;
49
+ editorRef.current = instanceRef.current;
50
+ return () => {
51
+ editorRef.current = null;
52
+ };
53
+ }, [editorRef, instanceRef]);
54
+ return h("div", {
55
+ ref: containerRef,
56
+ class: className,
57
+ style
58
+ });
59
+ }
60
+ export { MyEditEditor, useMyEdit };
61
+
62
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { h, type JSX, type RefObject } from \"preact\";\nimport { useEffect, useRef } from \"preact/hooks\";\nimport { createMyEdit, type MyEdit, type MyEditOptions } from \"@myedit/core\";\n\nexport interface MyEditProps extends MyEditOptions {\n class?: string;\n style?: JSX.CSSProperties;\n editorRef?: RefObject<MyEdit | null>;\n}\n\nexport function useMyEdit(\n containerRef: RefObject<HTMLElement | null>,\n options: MyEditOptions = {},\n): RefObject<MyEdit | null> {\n const instanceRef = useRef<MyEdit | null>(null);\n const mountedRef = useRef(false);\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n\n const initial = optionsRef.current;\n const editor = createMyEdit(el, {\n value: initial.value,\n theme: initial.theme,\n placeholder: initial.placeholder,\n readOnly: initial.readOnly,\n features: initial.features,\n wikilink: initial.wikilink,\n onChange: (val) => optionsRef.current.onChange?.(val),\n onCursorChange: (pos) => optionsRef.current.onCursorChange?.(pos),\n });\n instanceRef.current = editor;\n mountedRef.current = true;\n\n return () => {\n mountedRef.current = false;\n editor.destroy();\n instanceRef.current = null;\n };\n }, [containerRef]);\n\n useEffect(() => {\n if (mountedRef.current && options.value !== undefined) {\n instanceRef.current?.setValue(options.value);\n }\n }, [options.value]);\n\n useEffect(() => {\n if (mountedRef.current && options.theme !== undefined) {\n instanceRef.current?.setTheme(options.theme);\n }\n }, [options.theme]);\n\n useEffect(() => {\n if (mountedRef.current && options.readOnly !== undefined) {\n instanceRef.current?.setReadOnly(options.readOnly);\n }\n }, [options.readOnly]);\n\n return instanceRef;\n}\n\nexport function MyEditEditor(props: MyEditProps) {\n const { class: className, style, editorRef, ...options } = props;\n const containerRef = useRef<HTMLDivElement | null>(null);\n const instanceRef = useMyEdit(containerRef, options);\n\n useEffect(() => {\n if (!editorRef) return;\n editorRef.current = instanceRef.current;\n return () => {\n editorRef.current = null;\n };\n }, [editorRef, instanceRef]);\n\n return h(\"div\", { ref: containerRef, class: className, style });\n}\n"],"mappings":";;;;AAUA,SAAgB,UACd,cACA,UAAyB,CAAC,GACA;CAC1B,MAAM,cAAc,OAAsB,IAAI;CAC9C,MAAM,aAAa,OAAO,KAAK;CAC/B,MAAM,aAAa,OAAO,OAAO;CACjC,WAAW,UAAU;CAErB,gBAAgB;EAC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package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@myedit/preact",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Preact adapter for myedit Markdown Editor",
5
+ "keywords": [
6
+ "editor",
7
+ "markdown",
8
+ "myedit",
9
+ "preact"
10
+ ],
11
+ "homepage": "https://github.com/nuskey8/myedit#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/nuskey8/myedit/issues"
14
+ },
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/nuskey8/myedit.git",
19
+ "directory": "packages/preact"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "main": "./dist/index.mjs",
27
+ "module": "./dist/index.mjs",
28
+ "types": "./dist/index.d.mts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.mts",
32
+ "import": "./dist/index.mjs"
33
+ }
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "vp pack"
40
+ },
41
+ "devDependencies": {
42
+ "@myedit/core": "0.1.0",
43
+ "preact": "^10.26.4"
44
+ },
45
+ "peerDependencies": {
46
+ "@myedit/core": "^0.1.0",
47
+ "preact": ">=10"
48
+ }
49
+ }