@watalabs/lasee-mditor 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 WataLabs
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,253 @@
1
- # Temporary Holding Version
1
+ # @watalabs/lasee-mditor
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 WYSIWYG Markdown document editor: **edit what you see, keep Markdown as the source of truth.**
4
+ It is the editor from [MDitor LaSee](https://lasee.watalabs.com/en/), packaged as a library. It runs entirely in the browser — no server needed.
5
+
6
+ - Framework-free core, an optional **React** wrapper, and a `<script>` bundle (UMD)
7
+ - English and Korean UI (every string can be replaced)
8
+ - The output Markdown is always one canonical form: the same document gives the same Markdown, byte for byte the same as the MDitor server that renders the PDF
9
+
10
+ **Source:** [github.com/madorik/mditor-lasee](https://github.com/madorik/mditor-lasee/tree/main/web/packages/lasee-mditor) · **License:** MIT
11
+
12
+ ## Features
13
+
14
+ - **Toolbar** — undo/redo · block type (body, heading, subheading, list, note, code block, document title) · bold · italic · underline · strikethrough · text color (palette or color code) · shade · highlight · link · inline code · superscript/subscript · clear formatting · bulleted, numbered and to-do lists · indent/outdent · paragraph alignment · tables (pick a size) · images (URL, file, paste, drag and drop) · code block · horizontal line · page break · special characters · find and replace · Markdown source mode · preview on/off · full screen
15
+ - **Tables** — insert/delete rows and columns, merge and split cells, cell shading, column alignment (a table toolbar appears when the cursor is in a table)
16
+ - **Input rules** — `- ` bullets, `1. ` numbers, `[ ] ` to-dos, `## ` `### ` headings, `> ` note, ```` ``` ```` code block, `---` line, `**bold**`, `==highlight==`, `` `code` ``
17
+ - **Smart paste** — pasted Markdown is parsed into the document (Shift-paste keeps plain text). Tables, lists and links pasted from Word or Google Docs are kept.
18
+ - **Paste limits** — cap the characters per paste and the document length, so one huge paste can't freeze the page or your server
19
+ - **Status bar** with character and word counts · **read-only mode** · **automatic page-break marks** fed by your own page layout
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm install @watalabs/lasee-mditor
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Plain JavaScript / TypeScript (ESM)
30
+
31
+ ```ts
32
+ import { createMDitor } from "@watalabs/lasee-mditor";
33
+ import "@watalabs/lasee-mditor/style.css";
34
+
35
+ const mditor = createMDitor({
36
+ element: document.querySelector("#mditor")!,
37
+ markdown: "# Title\n\nBody text\n",
38
+ locale: "en", // UI language: "en" | "ko" (default "ko")
39
+ preview: true, // open the preview pane (users toggle it from the toolbar)
40
+ maxPaste: 5000, // reject pastes longer than 5,000 characters
41
+ onChange: (md) => console.log(md),
42
+ });
43
+
44
+ mditor.getMarkdown();
45
+ mditor.setMarkdown("## New text\n");
46
+ ```
47
+
48
+ Give the editor a height — it fills its container (`.mde` is a flex column with a minimum height of 320px):
49
+
50
+ ```css
51
+ #mditor .mde { height: 600px; }
52
+ ```
53
+
54
+ ### One `<script>` tag (UMD)
55
+
56
+ ```html
57
+ <link rel="stylesheet" href="https://unpkg.com/@watalabs/lasee-mditor/dist/style.css" />
58
+ <script src="https://unpkg.com/@watalabs/lasee-mditor/dist/lasee-mditor.umd.js"></script>
59
+
60
+ <div id="mditor" style="height: 600px"></div>
61
+ <script>
62
+ const mditor = LaSeeMDitor.createMDitor({
63
+ element: document.getElementById("mditor"),
64
+ markdown: "# Hello\n",
65
+ locale: "en",
66
+ });
67
+ </script>
68
+ ```
69
+
70
+ The bundle defines the global `LaSeeMDitor` with everything the ESM entry exports. Pin a version in production (`…/lasee-mditor@0.2.0/dist/…`).
71
+
72
+ ### React
73
+
74
+ ```tsx
75
+ import { useState } from "react";
76
+ import { MDitorView } from "@watalabs/lasee-mditor/react";
77
+ import "@watalabs/lasee-mditor/style.css";
78
+
79
+ function Page() {
80
+ const [md, setMd] = useState("# Title\n");
81
+ return <MDitorView value={md} onChange={setMd} locale="en" preview style={{ height: 600 }} />;
82
+ }
83
+ ```
84
+
85
+ `react` and `react-dom` are optional peer dependencies — install them yourself. A `ref` gives you the `MDitor` instance. Use `toolbarStart` / `toolbarEnd` to put your own buttons at either end of the toolbar. The editor is created once; later prop changes follow `value`, `editable`, `dialect` and `preview` (change the `key` to recreate it with other options).
86
+
87
+ ### No UI — parse, write, render HTML
88
+
89
+ ```ts
90
+ import { parseMarkdown, docToMarkdown, renderHtml } from "@watalabs/lasee-mditor/core"; // no TipTap, no DOM
91
+
92
+ const doc = parseMarkdown(md); // Markdown → document (JSON); throws MdError(line, code) on invalid input
93
+ docToMarkdown(doc); // document → canonical Markdown
94
+ renderHtml(md); // Markdown → HTML (only safe link URLs)
95
+ ```
96
+
97
+ Works on a server or in a worker.
98
+
99
+ ## Options
100
+
101
+ | Name | Default | Description |
102
+ |---|---|---|
103
+ | `element` | (required) | Element to mount the editor in |
104
+ | `markdown` / `doc` | `""` | Initial content (Markdown, or a document JSON) |
105
+ | `locale` | `"ko"` | UI language, `"en"` or `"ko"` |
106
+ | `messages` | | Override UI strings (`Partial<Messages>`) |
107
+ | `dialect` | auto | Formatting tag names — `{red}` or `{빨강}`. Defaults to the first tag found in the Markdown, otherwise `locale` |
108
+ | `toolbar` | `DEFAULT_TOOLBAR` | Toolbar items; `false` for no toolbar |
109
+ | `preview` | `false` | Open the preview pane |
110
+ | `pageMarks` | `false` | Show page-break marks from the start (you supply them with `setPageMarks`) |
111
+ | `mode` | `"wysiwyg"` | Initial mode; `"source"` for the Markdown source |
112
+ | `statusbar` | `true` | Character and word counts |
113
+ | `editable` | `true` | Allow editing |
114
+ | `placeholder` | | Hint shown in an empty document |
115
+ | `contentClass` | `"mde-doc"` | Class of the document area (to use your own document styles) |
116
+ | `image.upload` | data: URL | `(file) => Promise<url>` — upload a file and return the URL to write in the document |
117
+ | `image.resolve` | as written | Map an image name in the document to the URL to display |
118
+ | `image.onFiles` / `image.pick` | | Handle image files / the image button yourself |
119
+ | `onChange` | | `(markdown, mditor) => void` |
120
+ | `maxPaste` | none | Characters allowed in one paste; longer pastes are rejected |
121
+ | `maxLength` | none | Document (Markdown) length limit; pastes that would exceed it are rejected. Typing is never blocked |
122
+ | `onTooLong` | a notice above the editor | `({ kind: "paste" \| "document", length, max }) => void` — called when a paste is rejected |
123
+ | `extensions` | | Extra TipTap extensions |
124
+
125
+ ### Toolbar items
126
+
127
+ `undo` `redo` `blockKind` `bold` `italic` `underline` `strike` `color` `highlight` `link` `code` `superscript` `subscript` `removeFormat`
128
+ `bulletList` `orderedList` `taskList` `outdent` `indent` `align` `table` `image` `codeBlock` `horizontalRule` `pageBreak` `specialChars`
129
+ `find` `source` `preview` `fullscreen` `pageMarks` (not in the default toolbar), the separator `"|"`, and custom items `{ name, render: (mditor) => HTMLElement }`.
130
+
131
+ ```ts
132
+ createMDitor({
133
+ element,
134
+ toolbar: ["bold", "italic", "|", "link", "|", "preview", { name: "save", render: () => mySaveButton }],
135
+ });
136
+ ```
137
+
138
+ ## The `MDitor` instance
139
+
140
+ | Method | |
141
+ |---|---|
142
+ | `getMarkdown()` · `setMarkdown(md)` | Read or replace the Markdown (`setMarkdown` throws `MdError` on invalid Markdown) |
143
+ | `getDoc()` · `setDoc(doc)` · `getHTML()` | Document JSON · the preview HTML |
144
+ | `setMode("wysiwyg" \| "source")` · `getMode()` | Switch between the document and the Markdown source. Returns `false` and shows the error line if the source can't be parsed |
145
+ | `setPreview(on)` · `isPreview()` | Show or hide the preview |
146
+ | `setPageMarks(marks)` · `setPageMarksVisible(on)` · `isPageMarksVisible()` | Automatic page-break marks |
147
+ | `setFullscreen(on)` · `setEditable(on)` · `setDialect(d)` | |
148
+ | `insertImage(src, caption?)` · `replaceImage(from, to)` · `refreshImages()` | Images |
149
+ | `on("change" \| "mode" \| "preview" \| "fullscreen" \| "pagemarks", fn)` | Events; returns an unsubscribe function |
150
+ | `slot("start" \| "end")` | Empty slots at either end of the toolbar for your own buttons |
151
+ | `focus()` · `destroy()` | |
152
+ | `tiptap` | The underlying TipTap `Editor` |
153
+
154
+ **Shortcuts** (Ctrl instead of ⌘ on Windows/Linux): bold ⌘B · italic ⌘I · underline ⌘U · code ⌘E · link ⌘K · highlight ⌘⇧H · superscript/subscript ⌘. / ⌘, · numbered/bulleted/to-do list ⌘⇧7 / 8 / 9 · body/heading/subheading ⌘⌥0 / 2 / 3 · page break ⌘Enter · find ⌘F · indent Tab / ⇧Tab.
155
+
156
+ ### Automatic page-break marks
157
+
158
+ The editor never guesses where pages end — you compute that and pass it in. (The MDitor server's `POST /api/md/preview-pages` returns the layout of the actual PDF.) Positions use indexes into the document JSON; the editor groups blocks by the same rules, so the indexes match.
159
+
160
+ ```ts
161
+ mditor.setPageMarks({
162
+ total: 4,
163
+ sections: { 2: 3 }, // the third section (## …) starts on page 3
164
+ blocks: {
165
+ 0: { items: { 12: 2 } }, // in the first block (a list), page 2 starts at the 13th item
166
+ 5: { rows: { 30: 4 } }, // in the sixth block (a table), page 4 starts at the 31st body row
167
+ 7: { before: 4 }, // a new page starts before the eighth block
168
+ },
169
+ });
170
+ mditor.setPageMarksVisible(true); // or the "pageMarks" toolbar item
171
+ ```
172
+
173
+ Until new marks arrive, existing marks follow the text as it's edited. Marks are never written to the Markdown. While they're on, the status bar shows the page count.
174
+
175
+ ## Syntax
176
+
177
+ A subset of CommonMark/GFM plus MDitor's report syntax. Any Markdown viewer can still read it.
178
+
179
+ ```markdown
180
+ # Document title
181
+ ## Heading (section)
182
+ ### Subheading (block title)
183
+
184
+ **bold** ~~strike~~ ==highlight== `code` [link](https://example.com) H<sub>2</sub>O x<sup>2</sup>
185
+ {italic}italic{/italic} {underline}underline{/underline} {shade}shade{/shade} {red}red{/red} {#2e8b57}any color{/#2e8b57}
186
+ {center}A centered paragraph{/center} ← also {right} {justify}
187
+
188
+ - Bullet
189
+ - Nested (up to 3 levels)
190
+ 1. Numbered
191
+ - [ ] To-do
192
+ - [x] Done
193
+ > Note (small text under the block)
194
+
195
+ | Head | Merged head | < |
196
+ | ^ | Left | Right |
197
+ |:---|:---|---:|
198
+ | Cell | {shade}Shaded cell{/shade} | 1 |
199
+
200
+ ![Caption](image.png)
201
+
202
+ --- ← horizontal line
203
+ <!-- pagebreak --> ← page break (PDF)
204
+ ```
205
+
206
+ Code blocks use ```` ``` ```` fences with an optional language.
207
+
208
+ - Tags: `{red}` `{blue}` `{gray}` or any `{#rrggbb}`, `{italic}` `{underline}` `{shade}`, `{center}` `{right}` `{justify}`. Each also has a Korean name (`{빨강}` = `{red}`, `{가운데}` = `{center}`); a document uses one set.
209
+ - In tables, `<` merges a cell into the one on its left and `^` into the one above.
210
+ - Escape a symbol with `\` to write it literally: `\*\*`, `\[`, `` \` ``, `1\.`.
211
+ - Not supported: `*italic*` (use `{italic}`), headings below `###`, footnotes, math, video.
212
+
213
+ Full guide: [lasee.watalabs.com/en/syntax](https://lasee.watalabs.com/en/syntax).
214
+
215
+ ## Styling
216
+
217
+ Every class starts with `.mde`. Colors and fonts are CSS variables:
218
+
219
+ ```css
220
+ .my-app .mde {
221
+ --mde-accent: #6d28d9;
222
+ --mde-font: "Inter", sans-serif;
223
+ --mde-doc-width: 720px;
224
+ --mde-min-height: 480px;
225
+ }
226
+ ```
227
+
228
+ To style the document area yourself, pass `contentClass: "my-doc"` and style `h1 h2 h3 p .md-list li[data-num] .md-check table pre code hr .md-pagebreak .md-note mark.md-mark` under that class.
229
+
230
+ ## Development
231
+
232
+ The package lives in the [mditor-lasee](https://github.com/madorik/mditor-lasee) repository under `web/packages/lasee-mditor`.
233
+
234
+ ```bash
235
+ cd web/packages/lasee-mditor
236
+ npm run build # dist/: index.js · core.js · react.js (ESM), lasee-mditor.umd.js, style.css, types/
237
+ npm run dev # demo/ — try it without a server
238
+ cd ../.. && npx vitest run packages # tests, including the fixture shared with the server
239
+ ```
240
+
241
+ | Path | Contents |
242
+ |---|---|
243
+ | `src/core/` | Inline formatting, Markdown parse/write, HTML — the **same rules** as the server's `src/mditor/inline.py` and `md.py` (change both) |
244
+ | `src/pm/` | TipTap schema, document ↔ editor conversion, commands, plugins (list numbers, find, page marks) |
245
+ | `src/ui/` | Toolbar, popovers, find and replace, source mode, preview, UI strings |
246
+ | `src/react.tsx` | React wrapper |
247
+ | `src/fixture.json` | Shared fixture generated by the server tests (`tests/test_fixture.py`) |
248
+
249
+ Publishing: `npm publish` from this folder (it builds first via `prepublishOnly`; check the contents with `npm pack --dry-run`). The `watalabs` npm account uses two-factor auth, so add `--otp=<code>`.
250
+
251
+ ## License
252
+
253
+ [MIT](LICENSE) © WataLabs
package/dist/core.js ADDED
@@ -0,0 +1 @@
1
+ export { S as INLINE_COLORS, C as MARK, d as MAX_COLS, f as MAX_LEVEL, v as MdError, w as SHADE, T as SPACES, E as blockAlign, t as blockHtml, o as blockMd, D as canon, y as canonical, O as cellShade, s as codeFence, k as colorCss, A as dialectOf, c as docToMarkdown, n as escapeHtml, r as inlineHtml, j as isColor, l as itemLines, i as itemNumbers, M as linkHref, b as marker, N as normalize, P as oneSpace, h as parseBlocks, g as parseMarkdown, F as plainInline, I as pyStrip, a as renderHtml, L as safeHref, u as sectionMd, R as segments, x as spans, _ as splitCells, z as tag, B as title, V as write } from "./html-BGPHBFj_.js";