@mdzip/editor-react 2.4.2 → 2.5.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/README.md CHANGED
@@ -1,214 +1,211 @@
1
- [![MDZip logo][mdzip-logo]][mdzip-url]
2
-
3
- [mdzip-logo]: https://raw.githubusercontent.com/mdzip-project/mdzip-editor/main/resources/mdzip-mark.svg
4
- [mdzip-url]: https://mdzip.org
5
-
6
- # @mdzip/editor-react
7
-
8
- [![npm](https://img.shields.io/npm/v/@mdzip/editor-react?logo=npm)](https://www.npmjs.com/package/@mdzip/editor-react)
9
- [![license](https://img.shields.io/npm/l/@mdzip/editor-react)](https://github.com/mdzip-project/mdzip-editor/blob/main/LICENSE)
10
-
11
- React component wrapper for the MDZip workspace editor.
12
-
13
- `@mdzip/editor-react` provides a `MdzipWorkspace` component that embeds the full MDZip workspace UI — document preview, editor, package navigator, and asset manager — as a native React component.
14
-
15
- ## Install
16
-
17
- ```sh
18
- npm install @mdzip/editor-react
19
- ```
20
-
21
- Peer dependencies: `react` and `react-dom` >=18.
22
-
23
- ## Basic Usage
24
-
25
- ```tsx
26
- import { MdzipWorkspace } from '@mdzip/editor-react';
27
-
28
- export function Viewer({ bytes }: { bytes: Uint8Array }) {
29
- return (
30
- <div style={{ height: 600 }}>
31
- <MdzipWorkspace
32
- bytes={bytes}
33
- fileName="document.mdz"
34
- mode="read-only"
35
- controls="viewer"
36
- onFailed={console.error}
37
- />
38
- </div>
39
- );
40
- }
41
- ```
42
-
43
- The parent element must have an explicit height. The component expands to fill it.
44
-
45
- ## Archive Diff
46
-
47
- ```tsx
48
- import { MdzipDiff } from '@mdzip/editor-react/diff-view';
49
-
50
- <div style={{ height: 600 }}>
51
- <MdzipDiff
52
- before={{ bytes: baseBytes, label: 'Git base' }}
53
- after={{ bytes: workingBytes, label: 'Working tree' }}
54
- initialPath="index.md"
55
- toolbarActions={[{ id: 'refresh', label: 'Refresh', icon: 'refresh', run: refresh }]}
56
- />
57
- </div>
58
- ```
59
-
60
- `MdzipDiff` is read-only and updates the existing comparison view when its
61
- props change. A ref exposes `openPath`, `openPreviousChange`, `openNextChange`,
62
- `setShowUnchanged`, `setNavigationVisible`, and `setToolbarActions`. The
63
- built-in toolbar adds Previous/Next change buttons and a Show-unchanged
64
- toggle; pass a `controls` prop (`{ navigation?, changeTraversal?,
65
- showUnchanged? }`) to opt any of them out.
66
-
67
- ## Editor Mode
68
-
69
- ```tsx
70
- <MdzipWorkspace
71
- bytes={bytes}
72
- fileName="document.mdz"
73
- mode="editable"
74
- controls="standalone-editor"
75
- onSaved={({ bytes }) => persist(bytes)}
76
- onChanged={({ bytes }) => setDirty(true)}
77
- />
78
- ```
79
-
80
- ## Props
81
-
82
- | Prop | Type | Default | Description |
83
- |------|------|---------|-------------|
84
- | `bytes` | `Uint8Array \| null` | — | Raw archive bytes to open |
85
- | `workspace` | `MdzWorkspace \| null` | — | Pre-built workspace object |
86
- | `fileName` | `string` | `'document.mdz'` | Filename used for format detection and Save dialogs |
87
- | `mode` | `MdzipWorkspaceMode` | `'read-only'` | `'read-only'` or `'editable'` |
88
- | `sourceFormat` | `MdzipSourceFormat` | — | Override format detection: `'mdz'` or `'markdown'` |
89
- | `controls` | `MdzipControlPreset \| MdzipControlPolicy` | `'viewer'` | `'preview'`, `'viewer'`, `'standalone-editor'`, `'hosted-editor'`, or a policy object |
90
- | `toolbarDensity` | `'comfortable' \| 'compact' \| 'dense'` | `'comfortable'` | Semantic sizing preset for built-in toolbar controls |
91
- | `contentDensity` | `'comfortable' \| 'compact'` | `'comfortable'` | Semantic padding preset for editor and preview content |
92
- | `imageHydrationAnimation` | `'auto' \| 'initial' \| 'off'` | `'auto'` | Control preview image reveal animation: every render, first render per document path, or never |
93
- | `initialLayout` | `MdzipWorkspaceLayout` | — | Starting layout: `'preview'`, `'editor'`, `'split'` |
94
- | `initialColorScheme` | `MdzipColorSchemePreference` | `'system'` | `'light'`, `'dark'` or `'system'` (follows the OS setting live) |
95
- | `systemColorScheme` | `MdzipSystemColorScheme` | — | Makes the color scheme menu's System choice follow the host's theme instead of the OS setting, with its own `label` and `icon`, e.g. `{ colorScheme: 'dark', label: 'VS Code theme', icon: '<svg…>' }`; changes apply live |
96
- | `previewMaxWidth` | `MdzipPreviewMaxWidth` | `'default'` | Preview reading-column width: `'narrow'`, `'default'`, `'wide'`, `'full'` or a pixel number; the user can change it from the toolbar's page-width menu |
97
- | `navigationMode` | `MdzipNavigationMode` | — | Package navigation mode |
98
- | `navigationButtonActive` | `boolean` | — | Whether the navigation button is shown |
99
- | `inlineSvgLinks` | `boolean` | `true` | Shows archive SVGs that contain links inline, so the links can be clicked (draw.io `.drawio.svg` diagrams, for example); other SVGs stay images. Read when the view is created |
100
- | `hostFileActions` | `readonly MdzipFileAction[]` | — | The host's own items in the file tree's right-click menu on files (`{ id, label, appliesTo?, run }`), e.g. "Open in Another Editor". Also shown as buttons on the card that stands in for a `.drawio` image. Read when the view is created |
101
- | `markdownRenderer` | `MdzipMarkdownRenderer` | — | Custom markdown renderer (keep the reference stable, e.g. `useMemo`) |
102
- | `markdownExtensions` | `readonly MdzipMarkdownRenderExtension[]` | `[]` | Markdown pipeline extensions, diffed by `name` — inline arrays are safe |
103
- | `entryRenderers` | `readonly MdzipEntryRenderer[]` | `[]` | Entry renderers claiming the content area for matching entries, diffed by `id` — inline arrays are safe |
104
- | `renderEntry` | `(context) => ReactNode \| undefined` | — | Catch-all entry renderer: return a node to claim the selected entry, `undefined` to delegate |
105
- | `renderEntryPriority` | `number` | `0` | Matching priority of `renderEntry` relative to `entryRenderers` |
106
- | `frontMatter` | `MdzipFrontMatterOptions` | `{}` | Front matter panel config (`enabled`, `display`, `collapsible`, `label`) — always registered, diffed by deep equality; inline objects are safe |
107
- | `externalLinks` | `MdzipExternalLinkPolicy` | — | External-link policy, e.g. `{ target: '_blank' }` (adds `rel="noopener noreferrer"`); optional `rel` and `predicate(href)`. Re-applies without a re-render only when `target`, `rel` or `predicate` change; inline objects are safe |
108
-
109
- `controls`, density, `imageHydrationAnimation`, and rendering prop changes apply in
110
- place — they never recreate the workspace view. Line-number visibility changes
111
- preserve the current CodeMirror document and selection. See the `@mdzip/editor`
112
- Rendering Extensibility docs for the contracts and lifecycle rules.
113
-
114
- ### Native entry rendering
115
-
116
- ```tsx
117
- <MdzipWorkspace
118
- bytes={bytes}
119
- renderEntry={(context) =>
120
- context.path.toLowerCase() === 'manifest.json'
121
- ? <ManifestEditor
122
- manifest={context.manifest}
123
- editable={context.mode === 'editable'}
124
- onManifestChange={context.updateManifest}
125
- />
126
- : undefined}
127
- />
128
- ```
129
-
130
- The wrapper owns the React root: it mounts when the entry is claimed,
131
- re-renders on context updates and on every parent commit (entry content
132
- stays live with parent state — inline closures are safe and never
133
- re-mount), and unmounts on selection change.
134
-
135
- ## Callbacks
136
-
137
- | Prop | Signature | Description |
138
- |------|-----------|-------------|
139
- | `onChanged` | `(event: MdzipWorkspaceChange) => void` | Called when archive bytes change |
140
- | `onSaved` | `(event: MdzipWorkspaceSave) => void` | Called on Save |
141
- | `onSnapshotChanged` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called on any state change |
142
- | `onSelectionChanged` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called when the editor selection changes |
143
- | `onDirtyChanged` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called when the dirty flag changes |
144
- | `onValidationChanged` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called when validation state changes |
145
- | `onColorSchemeChanged` | `(colorScheme: MdzipColorScheme) => void` | Called when the color scheme changes |
146
- | `onColorSchemePreferenceChanged` | `(preference: MdzipColorSchemePreference) => void` | Called when the user picks Light, Dark or System in the toolbar menu |
147
- | `onPreviewWidthChanged` | `(width: MdzipPreviewWidthChoice) => void` | Called when the user picks a width in the toolbar's page-width menu |
148
- | `onPreviewRendered` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called when the preview HTML is mounted |
149
- | `onAssetsHydrated` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called once the mounted preview's images have loaded |
150
- | `onLinkActivated` | `(event: MdzipLinkActivatedEvent) => void` | Called for every preview link click before built-in handling; call `event.preventDefault()` to take over |
151
- | `onFailed` | `(error: unknown) => void` | Called on unrecoverable errors |
152
- | `onConversionRequested` | `(action: MdzipConversionAction) => boolean \| Promise<boolean>` | Host hook for the markdown→MDZ conversion flow (nav button, Insert Image, or image paste on a plain `.md`). Return/resolve `true` to take over and suppress the built-in conversion dialog |
153
- | `onPackRequested` | `(request: MdzipPackFilesRequest, context: MdzipPackFilesContext) => boolean \| Promise<boolean>` | Host hook for the folder→.mdz packing decision surfaced by the `packFilesAsWorkspace(files, options)` ref method — fires only when the file list contains more than one Markdown file. Same return contract as `onConversionRequested` |
154
-
155
- ## Image insertion
156
-
157
- Use `imageInsertMode="markdown"`, `"ask"`, or `"html"` for the built-in image
158
- markup flow. Pass `imageInsertHandler` for host-owned image UI; the handler can
159
- return Markdown or HTML sizing/alignment settings, return `null` to cancel, or
160
- return `undefined` to fall back to `imageInsertMode`.
161
-
162
- Pass `imageEditHandler` to let users edit an *existing* image by clicking it.
163
- Fully opt-in — with no handler, clicking an image does nothing and no edit
164
- affordance appears; there is no built-in fallback dialog.
165
-
166
- ## File management (nav pane)
167
-
168
- With `controls="standalone-editor"` or `"hosted-editor"` (or `fileActions: true` in a custom
169
- policy), the navigation pane offers a right-click context menu: new `.md` file, new folder,
170
- rename/move, duplicate, replace, download, copy markdown link, set entry point, set cover
171
- image, and delete. Files can also be dragged between folders, and OS files can be dropped
172
- onto the pane to add them as assets. Copy and Download remain available in read-only mode.
173
- The same operations are exposed imperatively: `removeFile`, `renameFile`, `setEntryPoint`,
174
- and `setCoverImage` on the handle. The handle also exposes `whenRendered()`, which resolves
175
- once the current preview (including its images) is mounted — useful for revealing or
176
- animating read-only preview content.
177
-
178
- ## Links and anchors
179
-
180
- `onLinkActivated` fires for every preview link click, before the view's own handling, with the
181
- parsed link (`kind`: `'anchor' | 'document' | 'relative' | 'external'`, plus `path`,
182
- `anchor`, `targetPath`, `sourcePath`, modifier keys). Call `event.preventDefault()` in the
183
- handler to route the link yourself; unprevented clicks keep the built-in behavior.
184
- The handle also exposes `scrollToAnchor(anchor)` (waits for the preview to mount, resolves whether it
185
- scrolled; safe straight after load), `getAvailableAnchors()`, `openPath(path, { anchor })` (opens another
186
- file, optionally at an anchor) and `getCurrentPath()`. Changing only `fileName` (e.g. after Save As)
187
- renames in place without reopening; set `preserveSelectionOnReopen` to stay on the current file when
188
- the archive content changes. See the
189
- [`@mdzip/editor` README](https://www.npmjs.com/package/@mdzip/editor#links-and-anchors).
190
-
191
- ## Imperative API
192
-
193
- Use a `ref` to access the imperative handle:
194
-
195
- ```tsx
196
- import { useRef } from 'react';
197
- import { MdzipWorkspace, type MdzipWorkspaceHandle } from '@mdzip/editor-react';
198
-
199
- const ref = useRef<MdzipWorkspaceHandle>(null);
200
-
201
- // Flush pending edits and persist
202
- const snapshot = await ref.current?.flush();
203
- if (snapshot) {
204
- await save(snapshot.bytes);
205
- ref.current?.markPersisted();
206
- }
207
-
208
- // Execute editor commands
209
- await ref.current?.executeCommand('bold');
210
-
211
- return <MdzipWorkspace ref={ref} ... />;
212
- ```
213
-
214
- See the [`@mdzip/editor`](https://www.npmjs.com/package/@mdzip/editor) package for the full API reference, theming guide, and framework-agnostic usage.
1
+ <a href="https://mdzip.org"><img src="https://mdzip.org/assets/images/mdzip-mark-square.svg" alt="MDZip logo" width="64" height="64"></a>
2
+
3
+ # @mdzip/editor-react
4
+
5
+ [![npm](https://img.shields.io/npm/v/@mdzip/editor-react?logo=npm)](https://www.npmjs.com/package/@mdzip/editor-react)
6
+ [![license](https://img.shields.io/npm/l/@mdzip/editor-react)](https://github.com/mdzip-project/mdzip-editor/blob/main/LICENSE)
7
+
8
+ React component wrapper for the MDZip workspace editor.
9
+
10
+ `@mdzip/editor-react` provides a `MdzipWorkspace` component that embeds the full MDZip workspace UI — document preview, editor, package navigator, and asset manager — as a native React component.
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ npm install @mdzip/editor-react
16
+ ```
17
+
18
+ Peer dependencies: `react` and `react-dom` >=18.
19
+
20
+ ## Basic Usage
21
+
22
+ ```tsx
23
+ import { MdzipWorkspace } from '@mdzip/editor-react';
24
+
25
+ export function Viewer({ bytes }: { bytes: Uint8Array }) {
26
+ return (
27
+ <div style={{ height: 600 }}>
28
+ <MdzipWorkspace
29
+ bytes={bytes}
30
+ fileName="document.mdz"
31
+ mode="read-only"
32
+ controls="viewer"
33
+ onFailed={console.error}
34
+ />
35
+ </div>
36
+ );
37
+ }
38
+ ```
39
+
40
+ The parent element must have an explicit height. The component expands to fill it.
41
+
42
+ ## Archive Diff
43
+
44
+ ```tsx
45
+ import { MdzipDiff } from '@mdzip/editor-react/diff-view';
46
+
47
+ <div style={{ height: 600 }}>
48
+ <MdzipDiff
49
+ before={{ bytes: baseBytes, label: 'Git base' }}
50
+ after={{ bytes: workingBytes, label: 'Working tree' }}
51
+ initialPath="index.md"
52
+ toolbarActions={[{ id: 'refresh', label: 'Refresh', icon: 'refresh', run: refresh }]}
53
+ />
54
+ </div>
55
+ ```
56
+
57
+ `MdzipDiff` is read-only and updates the existing comparison view when its
58
+ props change. A ref exposes `openPath`, `openPreviousChange`, `openNextChange`,
59
+ `setShowUnchanged`, `setNavigationVisible`, and `setToolbarActions`. The
60
+ built-in toolbar adds Previous/Next change buttons and a Show-unchanged
61
+ toggle; pass a `controls` prop (`{ navigation?, changeTraversal?,
62
+ showUnchanged? }`) to opt any of them out.
63
+
64
+ ## Editor Mode
65
+
66
+ ```tsx
67
+ <MdzipWorkspace
68
+ bytes={bytes}
69
+ fileName="document.mdz"
70
+ mode="editable"
71
+ controls="standalone-editor"
72
+ onSaved={({ bytes }) => persist(bytes)}
73
+ onChanged={({ bytes }) => setDirty(true)}
74
+ />
75
+ ```
76
+
77
+ ## Props
78
+
79
+ | Prop | Type | Default | Description |
80
+ |------|------|---------|-------------|
81
+ | `bytes` | `Uint8Array \| null` | — | Raw archive bytes to open |
82
+ | `workspace` | `MdzWorkspace \| null` | — | Pre-built workspace object |
83
+ | `fileName` | `string` | `'document.mdz'` | Filename used for format detection and Save dialogs |
84
+ | `mode` | `MdzipWorkspaceMode` | `'read-only'` | `'read-only'` or `'editable'` |
85
+ | `sourceFormat` | `MdzipSourceFormat` | — | Override format detection: `'mdz'` or `'markdown'` |
86
+ | `controls` | `MdzipControlPreset \| MdzipControlPolicy` | `'viewer'` | `'preview'`, `'viewer'`, `'standalone-editor'`, `'hosted-editor'`, or a policy object |
87
+ | `toolbarDensity` | `'comfortable' \| 'compact' \| 'dense'` | `'comfortable'` | Semantic sizing preset for built-in toolbar controls |
88
+ | `contentDensity` | `'comfortable' \| 'compact'` | `'comfortable'` | Semantic padding preset for editor and preview content |
89
+ | `imageHydrationAnimation` | `'auto' \| 'initial' \| 'off'` | `'auto'` | Control preview image reveal animation: every render, first render per document path, or never |
90
+ | `initialLayout` | `MdzipWorkspaceLayout` | — | Starting layout: `'preview'`, `'editor'`, `'split'` |
91
+ | `initialColorScheme` | `MdzipColorSchemePreference` | `'system'` | `'light'`, `'dark'` or `'system'` (follows the OS setting live) |
92
+ | `systemColorScheme` | `MdzipSystemColorScheme` | — | Makes the color scheme menu's System choice follow the host's theme instead of the OS setting, with its own `label` and `icon`, e.g. `{ colorScheme: 'dark', label: 'VS Code theme', icon: '<svg…>' }`; changes apply live |
93
+ | `previewMaxWidth` | `MdzipPreviewMaxWidth` | `'default'` | Preview reading-column width: `'narrow'`, `'default'`, `'wide'`, `'full'` or a pixel number; the user can change it from the toolbar's page-width menu |
94
+ | `navigationMode` | `MdzipNavigationMode` | — | Package navigation mode |
95
+ | `navigationButtonActive` | `boolean` | — | Whether the navigation button is shown |
96
+ | `inlineSvgLinks` | `boolean` | `true` | Shows archive SVGs that contain links inline, so the links can be clicked (draw.io `.drawio.svg` diagrams, for example); other SVGs stay images. Read when the view is created |
97
+ | `hostFileActions` | `readonly MdzipFileAction[]` | — | The host's own items in the file tree's right-click menu on files (`{ id, label, appliesTo?, run }`), e.g. "Open in Another Editor". Also shown as buttons on the card that stands in for a `.drawio` image. Read when the view is created |
98
+ | `markdownRenderer` | `MdzipMarkdownRenderer` | — | Custom markdown renderer (keep the reference stable, e.g. `useMemo`) |
99
+ | `markdownExtensions` | `readonly MdzipMarkdownRenderExtension[]` | `[]` | Markdown pipeline extensions, diffed by `name` — inline arrays are safe |
100
+ | `entryRenderers` | `readonly MdzipEntryRenderer[]` | `[]` | Entry renderers claiming the content area for matching entries, diffed by `id` — inline arrays are safe |
101
+ | `renderEntry` | `(context) => ReactNode \| undefined` | — | Catch-all entry renderer: return a node to claim the selected entry, `undefined` to delegate |
102
+ | `renderEntryPriority` | `number` | `0` | Matching priority of `renderEntry` relative to `entryRenderers` |
103
+ | `frontMatter` | `MdzipFrontMatterOptions` | `{}` | Front matter panel config (`enabled`, `display`, `collapsible`, `label`) — always registered, diffed by deep equality; inline objects are safe |
104
+ | `externalLinks` | `MdzipExternalLinkPolicy` | — | External-link policy, e.g. `{ target: '_blank' }` (adds `rel="noopener noreferrer"`); optional `rel` and `predicate(href)`. Re-applies without a re-render only when `target`, `rel` or `predicate` change; inline objects are safe |
105
+
106
+ `controls`, density, `imageHydrationAnimation`, and rendering prop changes apply in
107
+ place — they never recreate the workspace view. Line-number visibility changes
108
+ preserve the current CodeMirror document and selection. See the `@mdzip/editor`
109
+ Rendering Extensibility docs for the contracts and lifecycle rules.
110
+
111
+ ### Native entry rendering
112
+
113
+ ```tsx
114
+ <MdzipWorkspace
115
+ bytes={bytes}
116
+ renderEntry={(context) =>
117
+ context.path.toLowerCase() === 'manifest.json'
118
+ ? <ManifestEditor
119
+ manifest={context.manifest}
120
+ editable={context.mode === 'editable'}
121
+ onManifestChange={context.updateManifest}
122
+ />
123
+ : undefined}
124
+ />
125
+ ```
126
+
127
+ The wrapper owns the React root: it mounts when the entry is claimed,
128
+ re-renders on context updates and on every parent commit (entry content
129
+ stays live with parent state — inline closures are safe and never
130
+ re-mount), and unmounts on selection change.
131
+
132
+ ## Callbacks
133
+
134
+ | Prop | Signature | Description |
135
+ |------|-----------|-------------|
136
+ | `onChanged` | `(event: MdzipWorkspaceChange) => void` | Called when archive bytes change |
137
+ | `onSaved` | `(event: MdzipWorkspaceSave) => void` | Called on Save |
138
+ | `onSnapshotChanged` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called on any state change |
139
+ | `onSelectionChanged` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called when the editor selection changes |
140
+ | `onDirtyChanged` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called when the dirty flag changes |
141
+ | `onValidationChanged` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called when validation state changes |
142
+ | `onColorSchemeChanged` | `(colorScheme: MdzipColorScheme) => void` | Called when the color scheme changes |
143
+ | `onColorSchemePreferenceChanged` | `(preference: MdzipColorSchemePreference) => void` | Called when the user picks Light, Dark or System in the toolbar menu |
144
+ | `onPreviewWidthChanged` | `(width: MdzipPreviewWidthChoice) => void` | Called when the user picks a width in the toolbar's page-width menu |
145
+ | `onPreviewRendered` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called when the preview HTML is mounted |
146
+ | `onAssetsHydrated` | `(snapshot: MdzipWorkspaceSnapshot) => void` | Called once the mounted preview's images have loaded |
147
+ | `onLinkActivated` | `(event: MdzipLinkActivatedEvent) => void` | Called for every preview link click before built-in handling; call `event.preventDefault()` to take over |
148
+ | `onFailed` | `(error: unknown) => void` | Called on unrecoverable errors |
149
+ | `onConversionRequested` | `(action: MdzipConversionAction) => boolean \| Promise<boolean>` | Host hook for the markdown→MDZ conversion flow (nav button, Insert Image, or image paste on a plain `.md`). Return/resolve `true` to take over and suppress the built-in conversion dialog |
150
+ | `onPackRequested` | `(request: MdzipPackFilesRequest, context: MdzipPackFilesContext) => boolean \| Promise<boolean>` | Host hook for the folder→.mdz packing decision surfaced by the `packFilesAsWorkspace(files, options)` ref method — fires only when the file list contains more than one Markdown file. Same return contract as `onConversionRequested` |
151
+
152
+ ## Image insertion
153
+
154
+ Use `imageInsertMode="markdown"`, `"ask"`, or `"html"` for the built-in image
155
+ markup flow. Pass `imageInsertHandler` for host-owned image UI; the handler can
156
+ return Markdown or HTML sizing/alignment settings, return `null` to cancel, or
157
+ return `undefined` to fall back to `imageInsertMode`.
158
+
159
+ Pass `imageEditHandler` to let users edit an *existing* image by clicking it.
160
+ Fully opt-in — with no handler, clicking an image does nothing and no edit
161
+ affordance appears; there is no built-in fallback dialog.
162
+
163
+ ## File management (nav pane)
164
+
165
+ With `controls="standalone-editor"` or `"hosted-editor"` (or `fileActions: true` in a custom
166
+ policy), the navigation pane offers a right-click context menu: new `.md` file, new folder,
167
+ rename/move, duplicate, replace, download, copy markdown link, set entry point, set cover
168
+ image, and delete. Files can also be dragged between folders, and OS files can be dropped
169
+ onto the pane to add them as assets. Copy and Download remain available in read-only mode.
170
+ The same operations are exposed imperatively: `removeFile`, `renameFile`, `setEntryPoint`,
171
+ and `setCoverImage` on the handle. The handle also exposes `whenRendered()`, which resolves
172
+ once the current preview (including its images) is mounted — useful for revealing or
173
+ animating read-only preview content.
174
+
175
+ ## Links and anchors
176
+
177
+ `onLinkActivated` fires for every preview link click, before the view's own handling, with the
178
+ parsed link (`kind`: `'anchor' | 'document' | 'relative' | 'external'`, plus `path`,
179
+ `anchor`, `targetPath`, `sourcePath`, modifier keys). Call `event.preventDefault()` in the
180
+ handler to route the link yourself; unprevented clicks keep the built-in behavior.
181
+ The handle also exposes `scrollToAnchor(anchor)` (waits for the preview to mount, resolves whether it
182
+ scrolled; safe straight after load), `getAvailableAnchors()`, `openPath(path, { anchor })` (opens another
183
+ file, optionally at an anchor) and `getCurrentPath()`. Changing only `fileName` (e.g. after Save As)
184
+ renames in place without reopening; set `preserveSelectionOnReopen` to stay on the current file when
185
+ the archive content changes. See the
186
+ [`@mdzip/editor` README](https://www.npmjs.com/package/@mdzip/editor#links-and-anchors).
187
+
188
+ ## Imperative API
189
+
190
+ Use a `ref` to access the imperative handle:
191
+
192
+ ```tsx
193
+ import { useRef } from 'react';
194
+ import { MdzipWorkspace, type MdzipWorkspaceHandle } from '@mdzip/editor-react';
195
+
196
+ const ref = useRef<MdzipWorkspaceHandle>(null);
197
+
198
+ // Flush pending edits and persist
199
+ const snapshot = await ref.current?.flush();
200
+ if (snapshot) {
201
+ await save(snapshot.bytes);
202
+ ref.current?.markPersisted();
203
+ }
204
+
205
+ // Execute editor commands
206
+ await ref.current?.executeCommand('bold');
207
+
208
+ return <MdzipWorkspace ref={ref} ... />;
209
+ ```
210
+
211
+ See the [`@mdzip/editor`](https://www.npmjs.com/package/@mdzip/editor) package for the full API reference, theming guide, and framework-agnostic usage.
@@ -1,6 +1,6 @@
1
1
  export declare const PACKAGE_INFO: {
2
2
  readonly name: "@mdzip/editor-react";
3
- readonly version: "2.4.2";
3
+ readonly version: "2.5.0";
4
4
  readonly repositoryUrl: "https://github.com/mdzip-project/mdzip-editor/tree/main/packages/editor-react";
5
5
  readonly description: "React wrapper for the MDZip workspace editor.";
6
6
  };
@@ -1,7 +1,7 @@
1
1
  // Generated from package.json. Do not edit by hand.
2
2
  export const PACKAGE_INFO = {
3
3
  "name": "@mdzip/editor-react",
4
- "version": "2.4.2",
4
+ "version": "2.5.0",
5
5
  "repositoryUrl": "https://github.com/mdzip-project/mdzip-editor/tree/main/packages/editor-react",
6
6
  "description": "React wrapper for the MDZip workspace editor."
7
7
  };
package/package.json CHANGED
@@ -1,51 +1,51 @@
1
- {
2
- "name": "@mdzip/editor-react",
3
- "version": "2.4.2",
4
- "description": "React wrapper for the MDZip workspace editor.",
5
- "license": "Apache-2.0",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/mdzip-project/mdzip-editor.git",
9
- "directory": "packages/editor-react"
10
- },
11
- "homepage": "https://mdzip.org",
12
- "bugs": {
13
- "url": "https://github.com/mdzip-project/mdzip-editor/issues"
14
- },
15
- "type": "module",
16
- "main": "dist/index.js",
17
- "types": "dist/index.d.ts",
18
- "exports": {
19
- ".": {
20
- "types": "./dist/index.d.ts",
21
- "import": "./dist/index.js"
22
- },
23
- "./diff-view": {
24
- "types": "./dist/diff-view.d.ts",
25
- "import": "./dist/diff-view.js"
26
- }
27
- },
28
- "files": [
29
- "dist"
30
- ],
31
- "scripts": {
32
- "generate:package-info": "node ../../scripts/generate-package-info.mjs",
33
- "prebuild": "npm run generate:package-info",
34
- "build": "tsc -p tsconfig.json",
35
- "test": "vitest run"
36
- },
37
- "dependencies": {
38
- "@mdzip/editor": "^2.4.2"
39
- },
40
- "peerDependencies": {
41
- "react": ">=18.0.0",
42
- "react-dom": ">=18.0.0"
43
- },
44
- "devDependencies": {
45
- "@types/react": "^19.1.6",
46
- "@types/react-dom": "^19.1.5"
47
- },
48
- "publishConfig": {
49
- "access": "public"
50
- }
51
- }
1
+ {
2
+ "name": "@mdzip/editor-react",
3
+ "version": "2.5.0",
4
+ "description": "React wrapper for the MDZip workspace editor.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/mdzip-project/mdzip-editor.git",
9
+ "directory": "packages/editor-react"
10
+ },
11
+ "homepage": "https://mdzip.org",
12
+ "bugs": {
13
+ "url": "https://github.com/mdzip-project/mdzip-editor/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./diff-view": {
24
+ "types": "./dist/diff-view.d.ts",
25
+ "import": "./dist/diff-view.js"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "scripts": {
32
+ "generate:package-info": "node ../../scripts/generate-package-info.mjs",
33
+ "prebuild": "npm run generate:package-info",
34
+ "build": "tsc -p tsconfig.json",
35
+ "test": "vitest run"
36
+ },
37
+ "dependencies": {
38
+ "@mdzip/editor": "^2.5.0"
39
+ },
40
+ "peerDependencies": {
41
+ "react": ">=18.0.0",
42
+ "react-dom": ">=18.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/react": "^19.1.6",
46
+ "@types/react-dom": "^19.1.5"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }