@domternal/react 0.4.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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -0
  3. package/dist/Domternal.d.ts +79 -0
  4. package/dist/Domternal.d.ts.map +1 -0
  5. package/dist/DomternalEditor.d.ts +48 -0
  6. package/dist/DomternalEditor.d.ts.map +1 -0
  7. package/dist/DomternalFloatingMenu.d.ts +13 -0
  8. package/dist/DomternalFloatingMenu.d.ts.map +1 -0
  9. package/dist/EditorContent.d.ts +22 -0
  10. package/dist/EditorContent.d.ts.map +1 -0
  11. package/dist/EditorContext.d.ts +38 -0
  12. package/dist/EditorContext.d.ts.map +1 -0
  13. package/dist/bubble-menu/DomternalBubbleMenu.d.ts +21 -0
  14. package/dist/bubble-menu/DomternalBubbleMenu.d.ts.map +1 -0
  15. package/dist/bubble-menu/useBubbleMenu.d.ts +26 -0
  16. package/dist/bubble-menu/useBubbleMenu.d.ts.map +1 -0
  17. package/dist/emoji-picker/DomternalEmojiPicker.d.ts +10 -0
  18. package/dist/emoji-picker/DomternalEmojiPicker.d.ts.map +1 -0
  19. package/dist/emoji-picker/useEmojiPicker.d.ts +22 -0
  20. package/dist/emoji-picker/useEmojiPicker.d.ts.map +1 -0
  21. package/dist/index.d.ts +467 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +1720 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/node-views/NodeViewContent.d.ts +11 -0
  26. package/dist/node-views/NodeViewContent.d.ts.map +1 -0
  27. package/dist/node-views/NodeViewWrapper.d.ts +11 -0
  28. package/dist/node-views/NodeViewWrapper.d.ts.map +1 -0
  29. package/dist/node-views/ReactNodeViewContext.d.ts +12 -0
  30. package/dist/node-views/ReactNodeViewContext.d.ts.map +1 -0
  31. package/dist/node-views/ReactNodeViewRenderer.d.ts +101 -0
  32. package/dist/node-views/ReactNodeViewRenderer.d.ts.map +1 -0
  33. package/dist/toolbar/DomternalToolbar.d.ts +11 -0
  34. package/dist/toolbar/DomternalToolbar.d.ts.map +1 -0
  35. package/dist/toolbar/ToolbarButton.d.ts +14 -0
  36. package/dist/toolbar/ToolbarButton.d.ts.map +1 -0
  37. package/dist/toolbar/ToolbarDropdown.d.ts +16 -0
  38. package/dist/toolbar/ToolbarDropdown.d.ts.map +1 -0
  39. package/dist/toolbar/ToolbarDropdownPanel.d.ts +9 -0
  40. package/dist/toolbar/ToolbarDropdownPanel.d.ts.map +1 -0
  41. package/dist/toolbar/useComputedStyle.d.ts +12 -0
  42. package/dist/toolbar/useComputedStyle.d.ts.map +1 -0
  43. package/dist/toolbar/useKeyboardNav.d.ts +6 -0
  44. package/dist/toolbar/useKeyboardNav.d.ts.map +1 -0
  45. package/dist/toolbar/useToolbarController.d.ts +19 -0
  46. package/dist/toolbar/useToolbarController.d.ts.map +1 -0
  47. package/dist/toolbar/useToolbarIcons.d.ts +11 -0
  48. package/dist/toolbar/useToolbarIcons.d.ts.map +1 -0
  49. package/dist/toolbar/useTooltip.d.ts +5 -0
  50. package/dist/toolbar/useTooltip.d.ts.map +1 -0
  51. package/dist/useEditor.d.ts +79 -0
  52. package/dist/useEditor.d.ts.map +1 -0
  53. package/dist/useEditorState.d.ts +27 -0
  54. package/dist/useEditorState.d.ts.map +1 -0
  55. package/package.json +56 -0
@@ -0,0 +1,12 @@
1
+ import type { Editor } from '@domternal/core';
2
+ /**
3
+ * Read a CSS property value at the current cursor position.
4
+ * Prefers inline style (explicit mark) over computed style (inherited).
5
+ */
6
+ export declare function getComputedStyleAtCursor(editor: Editor, prop: string): string | null;
7
+ /**
8
+ * Read only inline style at the current cursor position (no computed fallback).
9
+ * Used for font-family to avoid reading browser default inheritance.
10
+ */
11
+ export declare function getInlineStyleAtCursor(editor: Editor, prop: string): string | null;
12
+ //# sourceMappingURL=useComputedStyle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComputedStyle.d.ts","sourceRoot":"","sources":["../../src/toolbar/useComputedStyle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAcpF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYlF"}
@@ -0,0 +1,6 @@
1
+ import type { ToolbarController } from '@domternal/core';
2
+ export declare function useKeyboardNav(controllerRef: React.RefObject<ToolbarController | null>, toolbarRef: React.RefObject<HTMLDivElement | null>, closeDropdown: () => void): {
3
+ onKeyDown: (event: React.KeyboardEvent) => void;
4
+ focusCurrentButton: () => void;
5
+ };
6
+ //# sourceMappingURL=useKeyboardNav.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useKeyboardNav.d.ts","sourceRoot":"","sources":["../../src/toolbar/useKeyboardNav.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,wBAAgB,cAAc,CAC5B,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,EACxD,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,EAClD,aAAa,EAAE,MAAM,IAAI;uBAQa,KAAK,CAAC,aAAa;;EAoC1D"}
@@ -0,0 +1,19 @@
1
+ import { ToolbarController } from '@domternal/core';
2
+ import type { Editor, ToolbarButton, ToolbarDropdown, ToolbarGroup, ToolbarLayoutEntry } from '@domternal/core';
3
+ export declare function useToolbarController(editor: Editor | null, layout?: ToolbarLayoutEntry[]): {
4
+ controller: import("react").RefObject<ToolbarController | null>;
5
+ groups: ToolbarGroup[];
6
+ focusedIndex: number;
7
+ openDropdown: string | null;
8
+ activeVersion: number;
9
+ toolbarRef: import("react").RefObject<HTMLDivElement | null>;
10
+ isActive: (name: string) => boolean;
11
+ isDisabled: (name: string) => boolean;
12
+ isDropdownActive: (dropdown: ToolbarDropdown) => boolean;
13
+ getAriaExpanded: (item: ToolbarButton) => string | null;
14
+ getFlatIndex: (name: string) => number;
15
+ handleDropdownToggle: (dropdown: ToolbarDropdown) => void;
16
+ closeDropdown: () => void;
17
+ syncState: () => void;
18
+ };
19
+ //# sourceMappingURL=useToolbarController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolbarController.d.ts","sourceRoot":"","sources":["../../src/toolbar/useToolbarController.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EAElB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,eAAe,EAEf,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAEzB,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,MAAM,CAAC,EAAE,kBAAkB,EAAE;;;;;;;qBA8FO,MAAM,KAAG,OAAO;uBAKd,MAAM,KAAG,OAAO;iCAIN,eAAe,KAAG,OAAO;4BAQ9B,aAAa,KAAG,MAAM,GAAG,IAAI;yBAKhC,MAAM,KAAG,MAAM;qCAIH,eAAe;;;EA+CpE"}
@@ -0,0 +1,11 @@
1
+ import type { IconSet, ToolbarButton, ToolbarDropdown } from '@domternal/core';
2
+ export declare const DROPDOWN_CARET = "<svg class=\"dm-dropdown-caret\" width=\"10\" height=\"10\" viewBox=\"0 0 10 10\"><path d=\"M2 4l3 3 3-3\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>";
3
+ export declare function useToolbarIcons(icons?: IconSet | null): {
4
+ resolveIconSvg: (name: string) => string;
5
+ getCachedIcon: (name: string) => string;
6
+ getCachedTriggerLabel: (label: string, isIcon?: boolean) => string;
7
+ getCachedTriggerIcon: (iconName: string) => string;
8
+ getCachedItemContent: (iconName: string, label: string, displayMode?: "icon-text" | "text" | "icon") => string;
9
+ getDropdownTriggerHtml: (dropdown: ToolbarDropdown, activeItem: ToolbarButton | undefined) => string;
10
+ };
11
+ //# sourceMappingURL=useToolbarIcons.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolbarIcons.d.ts","sourceRoot":"","sources":["../../src/toolbar/useToolbarIcons.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE/E,eAAO,MAAM,cAAc,qOAAiN,CAAC;AAE7O,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;2BAUV,MAAM,KAAG,MAAM;0BAOhB,MAAM,KAAG,MAAM;mCAWN,MAAM,WAAW,OAAO,KAAG,MAAM;qCAY/B,MAAM,KAAG,MAAM;qCAYvD,MAAM,SACT,MAAM,gBACC,WAAW,GAAG,MAAM,GAAG,MAAM,KAC1C,MAAM;uCAmBG,eAAe,cACb,aAAa,GAAG,SAAS,KACpC,MAAM;EAkCV"}
@@ -0,0 +1,5 @@
1
+ import type { ToolbarButton } from '@domternal/core';
2
+ export declare function useTooltip(): {
3
+ getTooltip: (item: ToolbarButton) => string;
4
+ };
5
+ //# sourceMappingURL=useTooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTooltip.d.ts","sourceRoot":"","sources":["../../src/toolbar/useTooltip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIrD,wBAAgB,UAAU;uBACc,aAAa,KAAG,MAAM;EAgB7D"}
@@ -0,0 +1,79 @@
1
+ import { type DependencyList } from 'react';
2
+ import { Editor } from '@domternal/core';
3
+ import type { Content, AnyExtension, FocusPosition } from '@domternal/core';
4
+ export declare const DEFAULT_EXTENSIONS: AnyExtension[];
5
+ export interface UseEditorOptions {
6
+ /** Custom extensions to add to the editor. */
7
+ extensions?: AnyExtension[];
8
+ /** Initial editor content (HTML string or JSON). */
9
+ content?: Content;
10
+ /** Whether the editor is editable. @default true */
11
+ editable?: boolean;
12
+ /** Where to autofocus on mount. @default false */
13
+ autofocus?: FocusPosition;
14
+ /** Output format for content comparison. @default 'html' */
15
+ outputFormat?: 'html' | 'json';
16
+ /**
17
+ * Set to false to delay editor creation to useEffect (SSR-safe).
18
+ * When false, the editor will be null during server-side rendering
19
+ * and created only after the component mounts in the browser.
20
+ * @default true
21
+ */
22
+ immediatelyRender?: boolean;
23
+ /** Called when the editor instance is created. */
24
+ onCreate?: (editor: Editor) => void;
25
+ /** Called when the document content changes. */
26
+ onUpdate?: (props: {
27
+ editor: Editor;
28
+ }) => void;
29
+ /** Called when the selection changes without content change. */
30
+ onSelectionChange?: (props: {
31
+ editor: Editor;
32
+ }) => void;
33
+ /** Called when the editor gains focus. */
34
+ onFocus?: (props: {
35
+ editor: Editor;
36
+ event: FocusEvent;
37
+ }) => void;
38
+ /** Called when the editor loses focus. */
39
+ onBlur?: (props: {
40
+ editor: Editor;
41
+ event: FocusEvent;
42
+ }) => void;
43
+ /** Called before the editor is destroyed. */
44
+ onDestroy?: () => void;
45
+ }
46
+ /**
47
+ * Core hook for creating and managing a Domternal editor instance.
48
+ *
49
+ * @param options - Editor configuration
50
+ * @param deps - Optional dependency array. When any value changes, the editor
51
+ * is destroyed and recreated (content is preserved). Useful for dynamic
52
+ * configuration that requires a full editor rebuild.
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * const { editor, editorRef } = useEditor({ extensions, content });
57
+ * return <div className="dm-editor"><div ref={editorRef} /></div>;
58
+ * ```
59
+ *
60
+ * @example SSR-safe usage (Next.js)
61
+ * ```tsx
62
+ * const { editor, editorRef } = useEditor({
63
+ * extensions,
64
+ * content,
65
+ * immediatelyRender: false,
66
+ * });
67
+ * ```
68
+ *
69
+ * @example With deps for forced recreation
70
+ * ```tsx
71
+ * const { editor, editorRef } = useEditor({ extensions, content }, [locale]);
72
+ * // Editor is recreated when locale changes
73
+ * ```
74
+ */
75
+ export declare function useEditor(options?: UseEditorOptions, deps?: DependencyList): {
76
+ editor: Editor | null;
77
+ editorRef: import("react").RefObject<HTMLDivElement | null>;
78
+ };
79
+ //# sourceMappingURL=useEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEditor.d.ts","sourceRoot":"","sources":["../src/useEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,OAAO,CAAC;AACzE,OAAO,EACL,MAAM,EAMP,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAA0C,MAAM,iBAAiB,CAAC;AAEpH,eAAO,MAAM,kBAAkB,EAAE,YAAY,EAAqD,CAAC;AAEnG,MAAM,WAAW,gBAAgB;IAC/B,8CAA8C;IAC9C,UAAU,CAAC,EAAE,YAAY,EAAE,CAAC;IAC5B,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kDAAkD;IAClD,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,gDAAgD;IAChD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC/C,gEAAgE;IAChE,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACxD,0CAA0C;IAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,KAAK,IAAI,CAAC;IACjE,0CAA0C;IAC1C,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,KAAK,IAAI,CAAC;IAChE,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,EAAE,IAAI,CAAC,EAAE,cAAc;;;EA0J9E"}
@@ -0,0 +1,27 @@
1
+ import type { Editor, JSONContent } from '@domternal/core';
2
+ /**
3
+ * Full editor state returned when no selector is provided.
4
+ */
5
+ export interface EditorState {
6
+ htmlContent: string;
7
+ jsonContent: JSONContent | null;
8
+ isEmpty: boolean;
9
+ isFocused: boolean;
10
+ isEditable: boolean;
11
+ }
12
+ /**
13
+ * Subscribe to editor state changes.
14
+ *
15
+ * **Overload 1 - Full state:**
16
+ * ```tsx
17
+ * const { htmlContent, isEmpty } = useEditorState(editor);
18
+ * ```
19
+ *
20
+ * **Overload 2 - Selector (granular, avoids unnecessary re-renders):**
21
+ * ```tsx
22
+ * const isBold = useEditorState(editor, (ed) => ed.isActive('bold'));
23
+ * ```
24
+ */
25
+ export declare function useEditorState(editor: Editor | null): EditorState;
26
+ export declare function useEditorState<T>(editor: Editor | null, selector: (editor: Editor) => T): T | undefined;
27
+ //# sourceMappingURL=useEditorState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEditorState.d.ts","sourceRoot":"","sources":["../src/useEditorState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,WAAW,CAAC;AACnE,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@domternal/react",
3
+ "version": "0.4.0",
4
+ "description": "React components for Domternal editor",
5
+ "author": "https://github.com/ThomasNowHere",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "@domternal/source": "./src/index.ts",
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "peerDependencies": {
22
+ "react": ">=18",
23
+ "react-dom": ">=18",
24
+ "@domternal/core": ">=0.4.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/react": "^19.0.0",
28
+ "@types/react-dom": "^19.0.0",
29
+ "react": "^19.1.0",
30
+ "react-dom": "^19.1.0",
31
+ "tsup": "^8.5.1",
32
+ "typescript": "~5.9.3",
33
+ "@domternal/core": "0.4.0"
34
+ },
35
+ "keywords": [
36
+ "react",
37
+ "prosemirror",
38
+ "editor",
39
+ "rich-text",
40
+ "domternal"
41
+ ],
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/domternal/domternal.git",
45
+ "directory": "packages/react"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/domternal/domternal/issues"
49
+ },
50
+ "homepage": "https://domternal.dev",
51
+ "scripts": {
52
+ "build": "tsup",
53
+ "dev": "tsup --watch",
54
+ "typecheck": "tsc --noEmit"
55
+ }
56
+ }