@zuilib/text-editor 0.0.0 → 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/README.md +132 -28
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,57 +1,161 @@
|
|
|
1
1
|
# @zuilib/text-editor
|
|
2
2
|
|
|
3
|
-
Markdown editor for ZUI
|
|
3
|
+
Markdown editor for ZUI built on [Lexical](https://lexical.dev/): rich editing with shortcuts, raw markdown mode, read-only view, checklists, and fenced code highlighting.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
- Notes, comments, or docs fields stored as **markdown strings**
|
|
8
|
+
- Controlled `value` / `onChange` integration with forms or autosave
|
|
9
|
+
- WYSIWYG-style editing without leaving markdown as the source of truth
|
|
10
|
+
|
|
11
|
+
## Prerequisites
|
|
12
|
+
|
|
13
|
+
Peer dependencies (install in the consuming app):
|
|
14
|
+
|
|
15
|
+
| Package | Version |
|
|
16
|
+
|---------|---------|
|
|
17
|
+
| `react`, `react-dom` | `^18.0.0 \|\| ^19.0.0` |
|
|
18
|
+
| `lexical` | `^0.35.0` |
|
|
19
|
+
| `@lexical/react` | `^0.35.0` |
|
|
20
|
+
| `@lexical/markdown` | `^0.35.0` |
|
|
21
|
+
| `@lexical/rich-text` | `^0.35.0` |
|
|
22
|
+
| `@lexical/code` | `^0.35.0` |
|
|
23
|
+
| `@lexical/list` | `^0.35.0` |
|
|
24
|
+
| `@lexical/link` | `^0.35.0` |
|
|
25
|
+
| `@zuilib/core` | workspace / published — import core styles |
|
|
4
26
|
|
|
5
27
|
## Installation
|
|
6
28
|
|
|
7
29
|
```bash
|
|
8
|
-
pnpm add @zuilib/text-editor @zuilib/core
|
|
30
|
+
pnpm add @zuilib/text-editor @zuilib/core \
|
|
31
|
+
lexical @lexical/react @lexical/markdown @lexical/rich-text \
|
|
32
|
+
@lexical/code @lexical/list @lexical/link
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Monorepo:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@zuilib/text-editor": "workspace:*",
|
|
41
|
+
"@zuilib/core": "workspace:*",
|
|
42
|
+
"lexical": "^0.35.0",
|
|
43
|
+
"@lexical/react": "^0.35.0",
|
|
44
|
+
"@lexical/markdown": "^0.35.0",
|
|
45
|
+
"@lexical/rich-text": "^0.35.0",
|
|
46
|
+
"@lexical/code": "^0.35.0",
|
|
47
|
+
"@lexical/list": "^0.35.0",
|
|
48
|
+
"@lexical/link": "^0.35.0"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
9
51
|
```
|
|
10
52
|
|
|
11
|
-
##
|
|
53
|
+
## Import rules
|
|
54
|
+
|
|
55
|
+
| Rule | Detail |
|
|
56
|
+
|------|--------|
|
|
57
|
+
| **Named export** | `import { MarkdownEditor } from '@zuilib/text-editor'` |
|
|
58
|
+
| **Types** | `import type { MarkdownEditorProps } from '@zuilib/text-editor'` |
|
|
59
|
+
| **Styles** | `import '@zuilib/text-editor/styles.css'` and `@zuilib/core/styles.css` |
|
|
60
|
+
| **Controlled** | Always pass `value` + `onChange` for persisted content |
|
|
61
|
+
| **Mode switches** | Switching `edit-raw` → `edit-md` re-mounts Lexical with latest markdown (cursor-safe) |
|
|
62
|
+
|
|
63
|
+
## Exports
|
|
64
|
+
|
|
65
|
+
| Subpath | Exports |
|
|
66
|
+
|---------|---------|
|
|
67
|
+
| `@zuilib/text-editor` | `MarkdownEditor` (default re-exported as named), `MarkdownEditorProps` |
|
|
68
|
+
| `@zuilib/text-editor/styles.css` | Editor chrome + Lexical theme classes |
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
12
71
|
|
|
13
72
|
```tsx
|
|
14
73
|
import { useState } from 'react'
|
|
15
|
-
import
|
|
74
|
+
import '@zuilib/core/styles.css'
|
|
16
75
|
import '@zuilib/text-editor/styles.css'
|
|
76
|
+
import { MarkdownEditor } from '@zuilib/text-editor'
|
|
17
77
|
|
|
18
78
|
function Notes() {
|
|
19
|
-
const [value, setValue] = useState('# Hello\n\n- [ ] Try
|
|
20
|
-
|
|
21
|
-
return
|
|
79
|
+
const [value, setValue] = useState('# Hello\n\n- [ ] Try checklists')
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<MarkdownEditor
|
|
83
|
+
value={value}
|
|
84
|
+
onChange={setValue}
|
|
85
|
+
placeholder="Start writing…"
|
|
86
|
+
/>
|
|
87
|
+
)
|
|
22
88
|
}
|
|
23
89
|
```
|
|
24
90
|
|
|
25
91
|
## Modes
|
|
26
92
|
|
|
93
|
+
| `mode` | UI | `onChange` |
|
|
94
|
+
|--------|-----|------------|
|
|
95
|
+
| `'edit-md'` (default) | Lexical rich editor + markdown shortcuts | Emits markdown string |
|
|
96
|
+
| `'edit-raw'` | Plain `<textarea>` with markdown source | Emits markdown string |
|
|
97
|
+
| `'view'` | Read-only rendered content | No editing (`onChange` unused) |
|
|
98
|
+
|
|
27
99
|
```tsx
|
|
28
|
-
|
|
29
|
-
<MarkdownEditor mode="edit-
|
|
100
|
+
<MarkdownEditor mode="edit-md" value={md} onChange={setMd} />
|
|
101
|
+
<MarkdownEditor mode="edit-raw" value={md} onChange={setMd} />
|
|
102
|
+
<MarkdownEditor mode="view" value={md} />
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Toggle modes in parent state; the editor preserves content via an internal ref when remounting Lexical after raw editing.
|
|
106
|
+
|
|
107
|
+
## Props (`MarkdownEditorProps`)
|
|
108
|
+
|
|
109
|
+
| Prop | Type | Default | Description |
|
|
110
|
+
|------|------|---------|-------------|
|
|
111
|
+
| `value` | `string` | `''` | Markdown source (controlled) |
|
|
112
|
+
| `onChange` | `(value: string) => void` | — | Called on every edit |
|
|
113
|
+
| `mode` | `'edit-md' \| 'edit-raw' \| 'view'` | `'edit-md'` | Editing surface |
|
|
114
|
+
| `placeholder` | `string` | `'Start writing...'` | Empty state hint |
|
|
115
|
+
| `readOnly` | `boolean` | `false` | Disables editing in Lexical modes |
|
|
116
|
+
| `autoFocus` | `boolean` | `false` | Focus on mount |
|
|
117
|
+
| `className` | `string` | — | Root wrapper class |
|
|
118
|
+
|
|
119
|
+
## Markdown features
|
|
120
|
+
|
|
121
|
+
**Shortcuts (edit-md):** headings (`#`), lists, blockquote, links, fenced code (via `CodeBlockShortcutPlugin`), checklists (`- [ ]` via `ChecklistShortcutPlugin`).
|
|
30
122
|
|
|
31
|
-
|
|
32
|
-
<MarkdownEditor mode="edit-raw" value={value} onChange={setValue} />
|
|
123
|
+
**Built-in plugins:** history (undo/redo), lists, checklists, links, markdown sync (`MarkdownSyncPlugin`), code highlighting (`CodeHighlightPlugin`).
|
|
33
124
|
|
|
34
|
-
|
|
35
|
-
|
|
125
|
+
**Not included:** file uploads, collaborative editing, or custom Lexical node registration — extend by forking or wrapping `MarkdownEditor`.
|
|
126
|
+
|
|
127
|
+
## Form integration
|
|
128
|
+
|
|
129
|
+
With `@zuilib/form`:
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
<FormField control={form.control} name="body">
|
|
133
|
+
{({ field }) => (
|
|
134
|
+
<MarkdownEditor
|
|
135
|
+
value={field.value}
|
|
136
|
+
onChange={field.onChange}
|
|
137
|
+
mode="edit-md"
|
|
138
|
+
/>
|
|
139
|
+
)}
|
|
140
|
+
</FormField>
|
|
36
141
|
```
|
|
37
142
|
|
|
38
|
-
|
|
143
|
+
Ensure both CSS entry points are loaded in the app layout.
|
|
39
144
|
|
|
40
|
-
|
|
41
|
-
- `onChange`: `(value: string) => void`
|
|
42
|
-
- `mode`: `'edit-md' | 'edit-raw' | 'view'` (default `'edit-md'`)
|
|
43
|
-
- `placeholder`: `string` (default `'Start writing...'`)
|
|
44
|
-
- `readOnly`: `boolean`
|
|
45
|
-
- `autoFocus`: `boolean`
|
|
46
|
-
- `className`: `string`
|
|
145
|
+
## Architecture notes (for extenders)
|
|
47
146
|
|
|
48
|
-
|
|
147
|
+
- Source: `src/MarkdownEditor.tsx`, plugins under `src/plugins/`
|
|
148
|
+
- Lexical namespace: `ZuiTextEditor`
|
|
149
|
+
- Markdown import/export uses `@lexical/markdown` transformers (`CHECK_LIST` prioritized for import)
|
|
150
|
+
- `edit-raw` bypasses Lexical; switching back to `edit-md` captures `latestValueRef` and bumps `mountKey` to avoid cursor jumps
|
|
49
151
|
|
|
50
|
-
|
|
51
|
-
- Syntax-highlighted fenced code blocks
|
|
52
|
-
- Undo/redo history
|
|
53
|
-
- Cursor-stable mode switching between raw and rich editing
|
|
152
|
+
## Related packages
|
|
54
153
|
|
|
55
|
-
|
|
154
|
+
- `@zuilib/core` — design tokens and base styles
|
|
155
|
+
- `@zuilib/form` — react-hook-form wiring
|
|
56
156
|
|
|
57
|
-
|
|
157
|
+
## Build (maintainers)
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pnpm --filter @zuilib/text-editor build
|
|
161
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuilib/text-editor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"description": "ZUI — A markdown editor component wrapping Lexical",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,4 +54,4 @@
|
|
|
54
54
|
"react",
|
|
55
55
|
"typescript"
|
|
56
56
|
]
|
|
57
|
-
}
|
|
57
|
+
}
|