@domternal/react 0.5.1 → 0.6.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 +5 -4
- package/dist/index.d.ts +467 -33
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@domternal/react)
|
|
4
4
|
[](https://github.com/domternal/domternal/blob/main/LICENSE)
|
|
5
5
|
|
|
6
|
-
A lightweight, extensible rich text editor toolkit built on <u>[ProseMirror](https://prosemirror.net/)</u>. Framework-agnostic headless core with first-class Angular and
|
|
6
|
+
A lightweight, extensible rich text editor toolkit built on <u>[ProseMirror](https://prosemirror.net/)</u>. Framework-agnostic headless core with first-class Angular, React, and Vue support.
|
|
7
7
|
Use it headless with vanilla JS/TS, add the built-in toolbar and theme, or drop in ready-made framework components. Fully tree-shakeable, import only what you use, unused extensions are stripped from your bundle.
|
|
8
8
|
|
|
9
9
|
## Links
|
|
10
10
|
|
|
11
11
|
<u>[Website](https://domternal.dev)</u> • <u>[Documentation](https://domternal.dev/v1/introduction)</u>
|
|
12
|
-
<u>[StackBlitz (Angular)](https://stackblitz.com/edit/domternal-angular-full-example)</u> • <u>[StackBlitz (React)](https://stackblitz.com/edit/domternal-react-full-example)</u> • <u>[StackBlitz (Vanilla TS)](https://stackblitz.com/edit/domternal-vanilla-full-example)</u>
|
|
12
|
+
<u>[StackBlitz (Angular)](https://stackblitz.com/edit/domternal-angular-full-example)</u> • <u>[StackBlitz (React)](https://stackblitz.com/edit/domternal-react-full-example)</u> • <u>[StackBlitz (Vue)](https://stackblitz.com/edit/domternal-vue-full-example)</u> • <u>[StackBlitz (Vanilla TS)](https://stackblitz.com/edit/domternal-vanilla-full-example)</u>
|
|
13
13
|
|
|
14
14
|
## Features
|
|
15
15
|
|
|
@@ -18,13 +18,14 @@ See <u>[Packages & Bundle Size](https://domternal.dev/v1/packages)</u> for a ful
|
|
|
18
18
|
- **Headless core** - use with any framework or vanilla JS/TS
|
|
19
19
|
- **Angular components** - editor, toolbar, bubble menu, floating menu, emoji picker (signals, OnPush, zoneless-ready)
|
|
20
20
|
- **React components** - composable `Domternal` component, toolbar, bubble menu, floating menu, emoji picker, custom node views (React 18+)
|
|
21
|
-
- **
|
|
21
|
+
- **Vue components** - composable `Domternal` component, `useEditor`/`useEditorState` composables, toolbar, bubble menu, floating menu, emoji picker, custom node views (Vue 3.3+)
|
|
22
|
+
- **57 extensions across 12 packages** - 23 nodes, 9 marks, and 25 behavior extensions
|
|
22
23
|
- **140+ chainable commands** - `editor.chain().focus().toggleBold().run()`
|
|
23
24
|
- **Full table support** - cell merging, column resize, row/column controls, cell toolbar, all free and MIT licensed
|
|
24
25
|
- **Tree-shakeable** - import only what you use, your bundler strips the rest
|
|
25
26
|
- **~38 KB gzipped** (own code), <u>[~108 KB total](https://domternal.dev/v1/packages)</u> with ProseMirror
|
|
26
27
|
- **TypeScript first** - 100% typed, zero `any`
|
|
27
|
-
- **
|
|
28
|
+
- **8,500+ tests** - 2,677 unit tests and 5,800+ E2E tests across 120+ Playwright specs
|
|
28
29
|
- **Light and dark theme** - 70+ CSS custom properties for full visual control
|
|
29
30
|
- **Inline styles export** - `getHTML({ styled: true })` produces inline CSS ready for email clients, CMS, and Google Docs
|
|
30
31
|
- **SSR helpers** - `generateHTML`, `generateJSON`, `generateText` for server-side rendering
|
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,467 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { DependencyList, ReactNode, HTMLAttributes, Ref, ElementType, RefCallback } from 'react';
|
|
3
|
+
import { AnyExtension, Content, FocusPosition, Editor, JSONContent, IconSet, ToolbarLayoutEntry, BubbleMenuOptions, FloatingMenuOptions } from '@domternal/core';
|
|
4
|
+
export { AnyExtension, Content, Editor, FocusPosition, GenerateHTMLOptions, GenerateJSONOptions, GenerateTextOptions, JSONContent, generateHTML, generateJSON, generateText } from '@domternal/core';
|
|
5
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
declare const DEFAULT_EXTENSIONS: AnyExtension[];
|
|
8
|
+
interface UseEditorOptions {
|
|
9
|
+
/** Custom extensions to add to the editor. */
|
|
10
|
+
extensions?: AnyExtension[];
|
|
11
|
+
/** Initial editor content (HTML string or JSON). */
|
|
12
|
+
content?: Content;
|
|
13
|
+
/** Whether the editor is editable. @default true */
|
|
14
|
+
editable?: boolean;
|
|
15
|
+
/** Where to autofocus on mount. @default false */
|
|
16
|
+
autofocus?: FocusPosition;
|
|
17
|
+
/** Output format for content comparison. @default 'html' */
|
|
18
|
+
outputFormat?: 'html' | 'json';
|
|
19
|
+
/**
|
|
20
|
+
* Set to false to delay editor creation to useEffect (SSR-safe).
|
|
21
|
+
* When false, the editor will be null during server-side rendering
|
|
22
|
+
* and created only after the component mounts in the browser.
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
immediatelyRender?: boolean;
|
|
26
|
+
/** Called when the editor instance is created. */
|
|
27
|
+
onCreate?: (editor: Editor) => void;
|
|
28
|
+
/** Called when the document content changes. */
|
|
29
|
+
onUpdate?: (props: {
|
|
30
|
+
editor: Editor;
|
|
31
|
+
}) => void;
|
|
32
|
+
/** Called when the selection changes without content change. */
|
|
33
|
+
onSelectionChange?: (props: {
|
|
34
|
+
editor: Editor;
|
|
35
|
+
}) => void;
|
|
36
|
+
/** Called when the editor gains focus. */
|
|
37
|
+
onFocus?: (props: {
|
|
38
|
+
editor: Editor;
|
|
39
|
+
event: FocusEvent;
|
|
40
|
+
}) => void;
|
|
41
|
+
/** Called when the editor loses focus. */
|
|
42
|
+
onBlur?: (props: {
|
|
43
|
+
editor: Editor;
|
|
44
|
+
event: FocusEvent;
|
|
45
|
+
}) => void;
|
|
46
|
+
/** Called before the editor is destroyed. */
|
|
47
|
+
onDestroy?: () => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Core hook for creating and managing a Domternal editor instance.
|
|
51
|
+
*
|
|
52
|
+
* @param options - Editor configuration
|
|
53
|
+
* @param deps - Optional dependency array. When any value changes, the editor
|
|
54
|
+
* is destroyed and recreated (content is preserved). Useful for dynamic
|
|
55
|
+
* configuration that requires a full editor rebuild.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```tsx
|
|
59
|
+
* const { editor, editorRef } = useEditor({ extensions, content });
|
|
60
|
+
* return <div className="dm-editor"><div ref={editorRef} /></div>;
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example SSR-safe usage (Next.js)
|
|
64
|
+
* ```tsx
|
|
65
|
+
* const { editor, editorRef } = useEditor({
|
|
66
|
+
* extensions,
|
|
67
|
+
* content,
|
|
68
|
+
* immediatelyRender: false,
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example With deps for forced recreation
|
|
73
|
+
* ```tsx
|
|
74
|
+
* const { editor, editorRef } = useEditor({ extensions, content }, [locale]);
|
|
75
|
+
* // Editor is recreated when locale changes
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare function useEditor(options?: UseEditorOptions, deps?: DependencyList): {
|
|
79
|
+
editor: Editor | null;
|
|
80
|
+
editorRef: react.RefObject<HTMLDivElement | null>;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Full editor state returned when no selector is provided.
|
|
85
|
+
*/
|
|
86
|
+
interface EditorState {
|
|
87
|
+
htmlContent: string;
|
|
88
|
+
jsonContent: JSONContent | null;
|
|
89
|
+
isEmpty: boolean;
|
|
90
|
+
isFocused: boolean;
|
|
91
|
+
isEditable: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Subscribe to editor state changes.
|
|
95
|
+
*
|
|
96
|
+
* **Overload 1 - Full state:**
|
|
97
|
+
* ```tsx
|
|
98
|
+
* const { htmlContent, isEmpty } = useEditorState(editor);
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* **Overload 2 - Selector (granular, avoids unnecessary re-renders):**
|
|
102
|
+
* ```tsx
|
|
103
|
+
* const isBold = useEditorState(editor, (ed) => ed.isActive('bold'));
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function useEditorState(editor: Editor | null): EditorState;
|
|
107
|
+
declare function useEditorState<T>(editor: Editor | null, selector: (editor: Editor) => T): T | undefined;
|
|
108
|
+
|
|
109
|
+
interface EditorContextValue {
|
|
110
|
+
editor: Editor | null;
|
|
111
|
+
}
|
|
112
|
+
interface EditorProviderProps {
|
|
113
|
+
/** The editor instance to provide to descendants. */
|
|
114
|
+
editor: Editor | null;
|
|
115
|
+
children: ReactNode;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Provides an editor instance to all descendant components via React Context.
|
|
119
|
+
*
|
|
120
|
+
* Components like DomternalToolbar, DomternalBubbleMenu, DomternalFloatingMenu,
|
|
121
|
+
* and DomternalEmojiPicker will automatically use this editor when no explicit
|
|
122
|
+
* `editor` prop is passed.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* const { editor } = useEditor({ extensions, content });
|
|
127
|
+
*
|
|
128
|
+
* <EditorProvider editor={editor}>
|
|
129
|
+
* <DomternalToolbar />
|
|
130
|
+
* <EditorContent editor={editor} />
|
|
131
|
+
* <DomternalBubbleMenu contexts={{ text: ['bold', 'italic'] }} />
|
|
132
|
+
* </EditorProvider>
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function EditorProvider({ editor, children }: EditorProviderProps): react_jsx_runtime.JSX.Element;
|
|
136
|
+
/**
|
|
137
|
+
* Access the editor instance from the nearest EditorProvider.
|
|
138
|
+
*
|
|
139
|
+
* @returns `{ editor }` where editor may be null if the provider has no editor yet.
|
|
140
|
+
* @throws If used outside of an EditorProvider (optional - returns null editor instead).
|
|
141
|
+
*/
|
|
142
|
+
declare function useCurrentEditor(): EditorContextValue;
|
|
143
|
+
|
|
144
|
+
interface DomternalToolbarProps {
|
|
145
|
+
/** The editor instance. If omitted, uses EditorProvider context. */
|
|
146
|
+
editor?: Editor;
|
|
147
|
+
/** Custom icon set. When provided, only these icons are used (no defaultIcons fallback). */
|
|
148
|
+
icons?: IconSet;
|
|
149
|
+
/** Custom toolbar layout. */
|
|
150
|
+
layout?: ToolbarLayoutEntry[];
|
|
151
|
+
}
|
|
152
|
+
declare function DomternalToolbar({ editor: editorProp, icons, layout }: DomternalToolbarProps): react_jsx_runtime.JSX.Element | null;
|
|
153
|
+
|
|
154
|
+
interface DomternalBubbleMenuProps {
|
|
155
|
+
/** The editor instance. If omitted, uses EditorProvider context. */
|
|
156
|
+
editor?: Editor;
|
|
157
|
+
/** Custom visibility function. */
|
|
158
|
+
shouldShow?: BubbleMenuOptions['shouldShow'];
|
|
159
|
+
/** Position relative to selection. @default 'top' */
|
|
160
|
+
placement?: 'top' | 'bottom';
|
|
161
|
+
/** Pixel offset from selection. @default 8 */
|
|
162
|
+
offset?: number;
|
|
163
|
+
/** Debounce delay in ms. @default 0 */
|
|
164
|
+
updateDelay?: number;
|
|
165
|
+
/** Fixed item names, e.g. ['bold', 'italic', 'code']. */
|
|
166
|
+
items?: string[];
|
|
167
|
+
/** Context-aware: map context names to item arrays, true for all, or null to disable. */
|
|
168
|
+
contexts?: Record<string, string[] | true | null>;
|
|
169
|
+
/** Additional content rendered after buttons. */
|
|
170
|
+
children?: React.ReactNode;
|
|
171
|
+
}
|
|
172
|
+
declare function DomternalBubbleMenu({ editor: editorProp, shouldShow, placement, offset, updateDelay, items, contexts, children, }: DomternalBubbleMenuProps): react_jsx_runtime.JSX.Element;
|
|
173
|
+
|
|
174
|
+
interface DomternalFloatingMenuProps {
|
|
175
|
+
/** The editor instance. If omitted, uses EditorProvider context. */
|
|
176
|
+
editor?: Editor;
|
|
177
|
+
/** Custom visibility function. */
|
|
178
|
+
shouldShow?: FloatingMenuOptions['shouldShow'];
|
|
179
|
+
/** Pixel offset from trigger. @default 0 */
|
|
180
|
+
offset?: number;
|
|
181
|
+
/** Content to render inside the floating menu. */
|
|
182
|
+
children?: React.ReactNode;
|
|
183
|
+
}
|
|
184
|
+
declare function DomternalFloatingMenu({ editor: editorProp, shouldShow, offset, children, }: DomternalFloatingMenuProps): react_jsx_runtime.JSX.Element;
|
|
185
|
+
|
|
186
|
+
interface EmojiPickerItem {
|
|
187
|
+
emoji: string;
|
|
188
|
+
name: string;
|
|
189
|
+
group: string;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
interface DomternalEmojiPickerProps {
|
|
193
|
+
/** The editor instance. If omitted, uses EditorProvider context. */
|
|
194
|
+
editor?: Editor;
|
|
195
|
+
/** Array of emoji items with emoji, name, and group. */
|
|
196
|
+
emojis: EmojiPickerItem[];
|
|
197
|
+
}
|
|
198
|
+
declare function DomternalEmojiPicker({ editor: editorProp, emojis }: DomternalEmojiPickerProps): react_jsx_runtime.JSX.Element;
|
|
199
|
+
|
|
200
|
+
interface DomternalProps extends UseEditorOptions {
|
|
201
|
+
/** Optional dependency array for forced editor recreation. */
|
|
202
|
+
deps?: DependencyList;
|
|
203
|
+
children: ReactNode;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Composable root component that creates an editor and provides it to all
|
|
207
|
+
* subcomponents via context. No need to pass `editor` prop to children.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```tsx
|
|
211
|
+
* <Domternal extensions={[Bold, Italic]} content="<p>Hello</p>">
|
|
212
|
+
* <Domternal.Toolbar />
|
|
213
|
+
* <Domternal.Content />
|
|
214
|
+
* <Domternal.BubbleMenu contexts={{ text: ['bold', 'italic'] }} />
|
|
215
|
+
* <Domternal.EmojiPicker emojis={emojis} />
|
|
216
|
+
* </Domternal>
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* @example SSR-safe with loading state
|
|
220
|
+
* ```tsx
|
|
221
|
+
* <Domternal extensions={extensions} immediatelyRender={false}>
|
|
222
|
+
* <Domternal.Loading>Loading editor...</Domternal.Loading>
|
|
223
|
+
* <Domternal.Toolbar />
|
|
224
|
+
* <Domternal.Content />
|
|
225
|
+
* </Domternal>
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
declare function Domternal({ children, deps, ...options }: DomternalProps): react_jsx_runtime.JSX.Element;
|
|
229
|
+
declare namespace Domternal {
|
|
230
|
+
var Content: typeof DomternalContent;
|
|
231
|
+
var Loading: typeof DomternalLoading;
|
|
232
|
+
var Toolbar: typeof DomternalToolbarSub;
|
|
233
|
+
var BubbleMenu: typeof DomternalBubbleMenuSub;
|
|
234
|
+
var FloatingMenu: typeof DomternalFloatingMenuSub;
|
|
235
|
+
var EmojiPicker: typeof DomternalEmojiPickerSub;
|
|
236
|
+
}
|
|
237
|
+
/** Renders the editor content area. Mounts the editor view DOM from context. */
|
|
238
|
+
declare function DomternalContent({ className }: {
|
|
239
|
+
className?: string;
|
|
240
|
+
}): react_jsx_runtime.JSX.Element;
|
|
241
|
+
declare namespace DomternalContent {
|
|
242
|
+
var displayName: string;
|
|
243
|
+
}
|
|
244
|
+
/** Renders children only while editor is not yet ready (SSR loading state). */
|
|
245
|
+
declare function DomternalLoading({ children }: {
|
|
246
|
+
children: ReactNode;
|
|
247
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
248
|
+
declare namespace DomternalLoading {
|
|
249
|
+
var displayName: string;
|
|
250
|
+
}
|
|
251
|
+
/** Toolbar subcomponent. Uses editor from context automatically. */
|
|
252
|
+
declare function DomternalToolbarSub(props: Omit<DomternalToolbarProps, 'editor'>): react_jsx_runtime.JSX.Element;
|
|
253
|
+
declare namespace DomternalToolbarSub {
|
|
254
|
+
var displayName: string;
|
|
255
|
+
}
|
|
256
|
+
/** BubbleMenu subcomponent. Uses editor from context automatically. */
|
|
257
|
+
declare function DomternalBubbleMenuSub(props: Omit<DomternalBubbleMenuProps, 'editor'>): react_jsx_runtime.JSX.Element;
|
|
258
|
+
declare namespace DomternalBubbleMenuSub {
|
|
259
|
+
var displayName: string;
|
|
260
|
+
}
|
|
261
|
+
/** FloatingMenu subcomponent. Uses editor from context automatically. */
|
|
262
|
+
declare function DomternalFloatingMenuSub(props: Omit<DomternalFloatingMenuProps, 'editor'>): react_jsx_runtime.JSX.Element;
|
|
263
|
+
declare namespace DomternalFloatingMenuSub {
|
|
264
|
+
var displayName: string;
|
|
265
|
+
}
|
|
266
|
+
/** EmojiPicker subcomponent. Uses editor from context automatically. */
|
|
267
|
+
declare function DomternalEmojiPickerSub(props: Omit<DomternalEmojiPickerProps, 'editor'>): react_jsx_runtime.JSX.Element;
|
|
268
|
+
declare namespace DomternalEmojiPickerSub {
|
|
269
|
+
var displayName: string;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
interface DomternalEditorProps extends Omit<UseEditorOptions, 'outputFormat'> {
|
|
273
|
+
/** Additional CSS class for the .dm-editor wrapper. */
|
|
274
|
+
className?: string;
|
|
275
|
+
/** Output format for onChange. @default 'html' */
|
|
276
|
+
outputFormat?: 'html' | 'json';
|
|
277
|
+
/** Controlled value. When provided, editor content syncs to this value. */
|
|
278
|
+
value?: Content;
|
|
279
|
+
/** Called when content changes (controlled mode). */
|
|
280
|
+
onChange?: (value: string | JSONContent) => void;
|
|
281
|
+
/** Additional content rendered inside the dm-editor wrapper. */
|
|
282
|
+
children?: React.ReactNode;
|
|
283
|
+
}
|
|
284
|
+
interface DomternalEditorRef {
|
|
285
|
+
editor: Editor | null;
|
|
286
|
+
htmlContent: string;
|
|
287
|
+
jsonContent: JSONContent | null;
|
|
288
|
+
isEmpty: boolean;
|
|
289
|
+
isFocused: boolean;
|
|
290
|
+
isEditable: boolean;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* All-in-one editor component with integrated state management and context.
|
|
294
|
+
*
|
|
295
|
+
* Wraps children with EditorProvider automatically, so toolbar, bubble menu,
|
|
296
|
+
* and emoji picker components can access the editor via context.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```tsx
|
|
300
|
+
* const editorRef = useRef<DomternalEditorRef>(null);
|
|
301
|
+
*
|
|
302
|
+
* <DomternalEditor
|
|
303
|
+
* ref={editorRef}
|
|
304
|
+
* extensions={[Bold, Italic, Heading]}
|
|
305
|
+
* content="<p>Hello</p>"
|
|
306
|
+
* onUpdate={({ editor }) => console.log(editor.getHTML())}
|
|
307
|
+
* />
|
|
308
|
+
* ```
|
|
309
|
+
*
|
|
310
|
+
* @example Controlled mode
|
|
311
|
+
* ```tsx
|
|
312
|
+
* const [html, setHtml] = useState('<p>Hello</p>');
|
|
313
|
+
* <DomternalEditor value={html} onChange={setHtml} outputFormat="html" />
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
declare const DomternalEditor: react.ForwardRefExoticComponent<DomternalEditorProps & react.RefAttributes<DomternalEditorRef>>;
|
|
317
|
+
|
|
318
|
+
interface EditorContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
319
|
+
/** The editor instance to render. */
|
|
320
|
+
editor: Editor | null;
|
|
321
|
+
/** Ref to the underlying div element. */
|
|
322
|
+
innerRef?: Ref<HTMLDivElement>;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Renders the ProseMirror editor view into a div element.
|
|
326
|
+
*
|
|
327
|
+
* Use this with `useEditor` for a flexible, decoupled pattern where the
|
|
328
|
+
* editor hook and rendering are separated:
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```tsx
|
|
332
|
+
* const { editor } = useEditor({ extensions, content });
|
|
333
|
+
* return <EditorContent editor={editor} className="my-editor" />;
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
declare function EditorContent({ editor, innerRef, ...htmlProps }: EditorContentProps): react_jsx_runtime.JSX.Element;
|
|
337
|
+
|
|
338
|
+
/** ProseMirror node shape passed to node views. */
|
|
339
|
+
interface PMNode {
|
|
340
|
+
type: {
|
|
341
|
+
name: string;
|
|
342
|
+
spec: {
|
|
343
|
+
group?: string;
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
attrs: Record<string, unknown>;
|
|
347
|
+
textContent: string;
|
|
348
|
+
nodeSize: number;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Props passed to custom React node view components.
|
|
352
|
+
*/
|
|
353
|
+
interface ReactNodeViewProps {
|
|
354
|
+
/** The editor instance. */
|
|
355
|
+
editor: Editor;
|
|
356
|
+
/** The ProseMirror node being rendered. */
|
|
357
|
+
node: PMNode;
|
|
358
|
+
/** Whether this node is selected via NodeSelection. */
|
|
359
|
+
selected: boolean;
|
|
360
|
+
/** Get the document position of this node. */
|
|
361
|
+
getPos: () => number;
|
|
362
|
+
/** Update the node's attributes. */
|
|
363
|
+
updateAttributes: (attrs: Record<string, unknown>) => void;
|
|
364
|
+
/** Delete this node from the document. */
|
|
365
|
+
deleteNode: () => void;
|
|
366
|
+
/** The extension that created this node view (name, options). Injected by core. */
|
|
367
|
+
extension: {
|
|
368
|
+
name: string;
|
|
369
|
+
options: Record<string, unknown>;
|
|
370
|
+
};
|
|
371
|
+
/** ProseMirror decorations applied to this node. */
|
|
372
|
+
decorations: unknown[];
|
|
373
|
+
}
|
|
374
|
+
interface ReactNodeViewRendererOptions {
|
|
375
|
+
/** Wrapper element tag. @default 'div' for block, 'span' for inline */
|
|
376
|
+
as?: string;
|
|
377
|
+
/** Additional CSS class on the wrapper element. */
|
|
378
|
+
className?: string;
|
|
379
|
+
/** Tag for the content DOM element. Set to null for no editable content. @default 'div' */
|
|
380
|
+
contentDOMElement?: string | null;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Converts a React component into a ProseMirror NodeView constructor.
|
|
384
|
+
*
|
|
385
|
+
* Returns a function matching ProseMirror's native `(node, view, getPos, decorations)` signature.
|
|
386
|
+
* The editor and extension context are automatically injected by core via `__domternalContext`.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* const ImageExtension = Image.extend({
|
|
391
|
+
* addNodeView() {
|
|
392
|
+
* return ReactNodeViewRenderer(ImageComponent);
|
|
393
|
+
* }
|
|
394
|
+
* });
|
|
395
|
+
* ```
|
|
396
|
+
*
|
|
397
|
+
* @example Accessing extension options in the component
|
|
398
|
+
* ```tsx
|
|
399
|
+
* function ImageComponent({ node, extension, decorations }: ReactNodeViewProps) {
|
|
400
|
+
* const maxWidth = extension.options.maxWidth as number;
|
|
401
|
+
* return <NodeViewWrapper><img src={node.attrs.src} style={{ maxWidth }} /></NodeViewWrapper>;
|
|
402
|
+
* }
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
declare function ReactNodeViewRenderer(component: React.ComponentType<ReactNodeViewProps>, options?: ReactNodeViewRendererOptions): (node: PMNode, _view: unknown, getPos: () => number, decorations: unknown[]) => ReactNodeView;
|
|
406
|
+
interface ReactNodeViewInit {
|
|
407
|
+
editor: Editor;
|
|
408
|
+
node: PMNode;
|
|
409
|
+
getPos: () => number;
|
|
410
|
+
decorations: unknown[];
|
|
411
|
+
extension: {
|
|
412
|
+
name: string;
|
|
413
|
+
options: Record<string, unknown>;
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
declare class ReactNodeView {
|
|
417
|
+
dom: HTMLElement;
|
|
418
|
+
contentDOM: HTMLElement | null;
|
|
419
|
+
private root;
|
|
420
|
+
private component;
|
|
421
|
+
private editor;
|
|
422
|
+
private node;
|
|
423
|
+
private getPos;
|
|
424
|
+
private decorations;
|
|
425
|
+
private extension;
|
|
426
|
+
private selected;
|
|
427
|
+
constructor(component: React.ComponentType<ReactNodeViewProps>, init: ReactNodeViewInit, options: ReactNodeViewRendererOptions);
|
|
428
|
+
private render;
|
|
429
|
+
update(node: PMNode, decorations: unknown[]): boolean;
|
|
430
|
+
selectNode(): void;
|
|
431
|
+
deselectNode(): void;
|
|
432
|
+
destroy(): void;
|
|
433
|
+
ignoreMutation(mutation: MutationRecord): boolean;
|
|
434
|
+
stopEvent(): boolean;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
interface NodeViewWrapperProps extends HTMLAttributes<HTMLElement> {
|
|
438
|
+
/** The HTML element type to render. @default 'div' */
|
|
439
|
+
as?: ElementType;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Container component for custom React node views.
|
|
443
|
+
* Handles drag events and marks the element as a node view wrapper.
|
|
444
|
+
*/
|
|
445
|
+
declare function NodeViewWrapper({ as: Tag, style, ...props }: NodeViewWrapperProps): react_jsx_runtime.JSX.Element;
|
|
446
|
+
|
|
447
|
+
interface NodeViewContentProps extends HTMLAttributes<HTMLElement> {
|
|
448
|
+
/** The HTML element type to render. @default 'div' */
|
|
449
|
+
as?: ElementType;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Placeholder for editable nested content within a custom React node view.
|
|
453
|
+
* ProseMirror manages the content DOM inside this element.
|
|
454
|
+
*/
|
|
455
|
+
declare function NodeViewContent({ as: Tag, style, ...props }: NodeViewContentProps): react_jsx_runtime.JSX.Element;
|
|
456
|
+
|
|
457
|
+
interface ReactNodeViewContextValue {
|
|
458
|
+
onDragStart: (event: DragEvent) => void;
|
|
459
|
+
nodeViewContentRef: RefCallback<HTMLElement>;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Access node view internals from within a custom React node view component.
|
|
463
|
+
* Used by NodeViewWrapper and NodeViewContent.
|
|
464
|
+
*/
|
|
465
|
+
declare function useReactNodeView(): ReactNodeViewContextValue;
|
|
466
|
+
|
|
467
|
+
export { DEFAULT_EXTENSIONS, Domternal, DomternalBubbleMenu, type DomternalBubbleMenuProps, DomternalEditor, type DomternalEditorProps, type DomternalEditorRef, DomternalEmojiPicker, type DomternalEmojiPickerProps, DomternalFloatingMenu, type DomternalFloatingMenuProps, type DomternalProps, DomternalToolbar, type DomternalToolbarProps, EditorContent, type EditorContentProps, EditorProvider, type EditorProviderProps, type EditorState, type EmojiPickerItem, NodeViewContent, type NodeViewContentProps, NodeViewWrapper, type NodeViewWrapperProps, type ReactNodeViewProps, ReactNodeViewRenderer, type ReactNodeViewRendererOptions, type UseEditorOptions, useCurrentEditor, useEditor, useEditorState, useReactNodeView };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domternal/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "React components for Domternal editor",
|
|
5
5
|
"author": "https://github.com/ThomasNowHere",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,16 +21,21 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"react": ">=18",
|
|
23
23
|
"react-dom": ">=18",
|
|
24
|
-
"@domternal/core": ">=0.
|
|
24
|
+
"@domternal/core": ">=0.6.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
+
"@domternal/core": "workspace:*",
|
|
27
28
|
"@types/react": "^19.0.0",
|
|
28
29
|
"@types/react-dom": "^19.0.0",
|
|
29
30
|
"react": "^19.1.0",
|
|
30
31
|
"react-dom": "^19.1.0",
|
|
31
32
|
"tsup": "^8.5.1",
|
|
32
|
-
"typescript": "~5.9.3"
|
|
33
|
-
|
|
33
|
+
"typescript": "~5.9.3"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"dev": "tsup --watch",
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
34
39
|
},
|
|
35
40
|
"keywords": [
|
|
36
41
|
"react",
|
|
@@ -47,10 +52,5 @@
|
|
|
47
52
|
"bugs": {
|
|
48
53
|
"url": "https://github.com/domternal/domternal/issues"
|
|
49
54
|
},
|
|
50
|
-
"homepage": "https://domternal.dev"
|
|
51
|
-
|
|
52
|
-
"build": "tsup",
|
|
53
|
-
"dev": "tsup --watch",
|
|
54
|
-
"typecheck": "tsc --noEmit"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
55
|
+
"homepage": "https://domternal.dev"
|
|
56
|
+
}
|