@myedit/core 0.0.0-stage → 0.2.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,95 @@
1
+ type MyEditTheme = "light" | "dark" | "auto";
2
+ type AlertType = "note" | "tip" | "important" | "warning" | "caution";
3
+ interface CursorPosition {
4
+ /** 1-based line number */
5
+ line: number;
6
+ /** 1-based column number */
7
+ column: number;
8
+ /** 0-based document offset */
9
+ offset: number;
10
+ }
11
+ interface MyEditSelection {
12
+ from: number;
13
+ to: number;
14
+ text: string;
15
+ }
16
+ interface WikiLinkItem {
17
+ /** Target page name (inserted inside [[...]]) */
18
+ title: string;
19
+ /** Optional subtitle / path shown in autocomplete */
20
+ detail?: string;
21
+ }
22
+ interface WikiLinkOptions {
23
+ /** Resolve whether a wikilink target exists (true -> blue, false -> red) */
24
+ resolve?: (target: string) => boolean;
25
+ /** Return completion candidates when typing `[[query` */
26
+ complete?: (query: string) => WikiLinkItem[] | Promise<WikiLinkItem[]>;
27
+ /** Called when a wikilink is clicked */
28
+ onClick?: (target: string) => void;
29
+ }
30
+ interface MyEditFeatures {
31
+ /** YAML frontmatter properties editor (default: true) */
32
+ frontmatter?: boolean;
33
+ /** Mermaid diagram rendering via Pele (default: true) */
34
+ mermaid?: boolean;
35
+ /** KaTeX math rendering for $...$ and $$...$$ (default: true) */
36
+ math?: boolean;
37
+ /** Interactive TanStack Table editor for GFM tables (default: true) */
38
+ table?: boolean;
39
+ /** Rich iframe embeds for YouTube, X, CodePen, etc. (default: true) */
40
+ embeds?: boolean;
41
+ /** GitHub Repo & generic URL link cards (default: true) */
42
+ linkCards?: boolean;
43
+ /** WikiLink [[Page]] syntax & completion (default: true) */
44
+ wikilink?: boolean;
45
+ /** Highlight ==text== syntax (default: true) */
46
+ highlight?: boolean;
47
+ /** Subscript ~text~ and Superscript ^text^ syntax (default: true) */
48
+ subSup?: boolean;
49
+ /** Slash commands (/) for block insertion (default: true) */
50
+ slashCommands?: boolean;
51
+ /** Markdown formatting shortcuts, smart lists & wrap (default: true) */
52
+ shortcuts?: boolean;
53
+ /** Search & replace panel (Cmd/Ctrl+F) (default: true) */
54
+ search?: boolean;
55
+ }
56
+ interface MyEditOptions {
57
+ /** Initial Markdown content */
58
+ value?: string;
59
+ /** Color theme: 'light', 'dark', or 'auto' (follows prefers-color-scheme) */
60
+ theme?: MyEditTheme;
61
+ /** Placeholder text when editor is empty */
62
+ placeholder?: string;
63
+ /** Whether the editor is read-only */
64
+ readOnly?: boolean;
65
+ /** Enable or disable specific syntax & editor features (all enabled by default) */
66
+ features?: MyEditFeatures;
67
+ /** External WikiLink resolution, completion, and click handling */
68
+ wikilink?: WikiLinkOptions;
69
+ /** Called whenever the document content changes */
70
+ onChange?: (value: string) => void;
71
+ /** Called whenever the cursor position changes */
72
+ onCursorChange?: (pos: CursorPosition) => void;
73
+ }
74
+ declare class MyEdit {
75
+ private readonly container;
76
+ private readonly root;
77
+ private readonly view;
78
+ private readonly readOnlyCompartment;
79
+ private theme;
80
+ private mediaQuery;
81
+ private readonly onMediaChange;
82
+ constructor(container: HTMLElement, options?: MyEditOptions);
83
+ private applyThemeAttribute;
84
+ getValue(): string;
85
+ setValue(value: string): void;
86
+ setTheme(theme: MyEditTheme): void;
87
+ setReadOnly(readOnly: boolean): void;
88
+ getCursorPosition(): CursorPosition;
89
+ getSelection(): MyEditSelection;
90
+ insertText(text: string): void;
91
+ focus(): void;
92
+ destroy(): void;
93
+ }
94
+ export declare function createMyEdit(container: HTMLElement, options?: MyEditOptions): MyEdit;
95
+ export type { AlertType, CursorPosition, MyEdit, MyEditFeatures, MyEditOptions, MyEditSelection, MyEditTheme, WikiLinkItem, WikiLinkOptions };