@bayonai/rich-text-editor 0.1.2

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 (91) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +37 -0
  3. package/dist/index.d.ts +8 -0
  4. package/dist/index.js +5 -0
  5. package/dist/react/BlockActionTool.d.ts +15 -0
  6. package/dist/react/BlockActionTool.js +37 -0
  7. package/dist/react/EditorSessionProvider.d.ts +28 -0
  8. package/dist/react/EditorSessionProvider.js +74 -0
  9. package/dist/react/RichTextBody.d.ts +18 -0
  10. package/dist/react/RichTextBody.js +66 -0
  11. package/dist/react/RichTextDocumentSurface.d.ts +6 -0
  12. package/dist/react/RichTextDocumentSurface.js +5 -0
  13. package/dist/react/RichTextEditor.d.ts +45 -0
  14. package/dist/react/RichTextEditor.js +1096 -0
  15. package/dist/react/RichTextIcons.d.ts +21 -0
  16. package/dist/react/RichTextIcons.js +55 -0
  17. package/dist/react/RichTextRenderedBlock.d.ts +4 -0
  18. package/dist/react/RichTextRenderedBlock.js +36 -0
  19. package/dist/react/RichTextRenderer.d.ts +4 -0
  20. package/dist/react/RichTextRenderer.js +8 -0
  21. package/dist/react/RichTextStyles.d.ts +1 -0
  22. package/dist/react/RichTextStyles.js +719 -0
  23. package/dist/react/RichTextTitleInput.d.ts +20 -0
  24. package/dist/react/RichTextTitleInput.js +39 -0
  25. package/dist/react/SelectionFormatToolbar.d.ts +34 -0
  26. package/dist/react/SelectionFormatToolbar.js +18 -0
  27. package/dist/react/SpecialBlockOption.d.ts +7 -0
  28. package/dist/react/SpecialBlockOption.js +7 -0
  29. package/dist/react/SpecialBlockTool.d.ts +42 -0
  30. package/dist/react/SpecialBlockTool.js +50 -0
  31. package/dist/react/TranscriptionControl.d.ts +19 -0
  32. package/dist/react/TranscriptionControl.js +129 -0
  33. package/dist/react/UnsavedChangesDialog.d.ts +9 -0
  34. package/dist/react/UnsavedChangesDialog.js +13 -0
  35. package/dist/react/blockActionToolState.d.ts +18 -0
  36. package/dist/react/blockActionToolState.js +53 -0
  37. package/dist/react/blockActions.d.ts +8 -0
  38. package/dist/react/blockActions.js +111 -0
  39. package/dist/react/editorNavigation.d.ts +19 -0
  40. package/dist/react/editorNavigation.js +39 -0
  41. package/dist/react/editorShortcuts.d.ts +20 -0
  42. package/dist/react/editorShortcuts.js +25 -0
  43. package/dist/react/index.d.ts +9 -0
  44. package/dist/react/index.js +6 -0
  45. package/dist/react/richTextBlockStyles.d.ts +7 -0
  46. package/dist/react/richTextBlockStyles.js +7 -0
  47. package/dist/react/specialBlockStyles.d.ts +15 -0
  48. package/dist/react/specialBlockStyles.js +9 -0
  49. package/dist/richText.d.ts +15 -0
  50. package/dist/richText.js +297 -0
  51. package/dist/saveControl.d.ts +8 -0
  52. package/dist/saveControl.js +9 -0
  53. package/dist/session.d.ts +27 -0
  54. package/dist/session.js +78 -0
  55. package/dist/sessionRegistry.d.ts +24 -0
  56. package/dist/sessionRegistry.js +87 -0
  57. package/dist/types.d.ts +34 -0
  58. package/dist/types.js +1 -0
  59. package/dist/writingStats.d.ts +5 -0
  60. package/dist/writingStats.js +9 -0
  61. package/dist-cjs/index.js +22 -0
  62. package/dist-cjs/package.json +3 -0
  63. package/dist-cjs/react/BlockActionTool.js +40 -0
  64. package/dist-cjs/react/EditorSessionProvider.js +79 -0
  65. package/dist-cjs/react/RichTextBody.js +69 -0
  66. package/dist-cjs/react/RichTextDocumentSurface.js +8 -0
  67. package/dist-cjs/react/RichTextEditor.js +1108 -0
  68. package/dist-cjs/react/RichTextIcons.js +74 -0
  69. package/dist-cjs/react/RichTextRenderedBlock.js +39 -0
  70. package/dist-cjs/react/RichTextRenderer.js +11 -0
  71. package/dist-cjs/react/RichTextStyles.js +722 -0
  72. package/dist-cjs/react/RichTextTitleInput.js +44 -0
  73. package/dist-cjs/react/SelectionFormatToolbar.js +22 -0
  74. package/dist-cjs/react/SpecialBlockOption.js +10 -0
  75. package/dist-cjs/react/SpecialBlockTool.js +54 -0
  76. package/dist-cjs/react/TranscriptionControl.js +133 -0
  77. package/dist-cjs/react/UnsavedChangesDialog.js +16 -0
  78. package/dist-cjs/react/blockActionToolState.js +58 -0
  79. package/dist-cjs/react/blockActions.js +119 -0
  80. package/dist-cjs/react/editorNavigation.js +45 -0
  81. package/dist-cjs/react/editorShortcuts.js +28 -0
  82. package/dist-cjs/react/index.js +17 -0
  83. package/dist-cjs/react/richTextBlockStyles.js +10 -0
  84. package/dist-cjs/react/specialBlockStyles.js +12 -0
  85. package/dist-cjs/richText.js +307 -0
  86. package/dist-cjs/saveControl.js +12 -0
  87. package/dist-cjs/session.js +83 -0
  88. package/dist-cjs/sessionRegistry.js +90 -0
  89. package/dist-cjs/types.js +2 -0
  90. package/dist-cjs/writingStats.js +12 -0
  91. package/package.json +45 -0
@@ -0,0 +1,21 @@
1
+ export type RichTextIconProps = {
2
+ className?: string;
3
+ size?: number;
4
+ };
5
+ export declare function AddIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare function BoldIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function CloseIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare function CopyIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function CodeIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function CutIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function DataObjectIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function DeleteIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare function DividerIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
14
+ export declare function DragHandleIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
15
+ export declare function ImageIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
16
+ export declare function ItalicIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
17
+ export declare function LinkIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
18
+ export declare function MicIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
19
+ export declare function QuoteIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
20
+ export declare function StopIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
21
+ export declare function TitleIcon(props: RichTextIconProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ function IconSvg({ children, className, size = 18, viewBox = "0 0 24 24", }) {
3
+ return (_jsx("svg", { "aria-hidden": "true", className: className, fill: "none", height: size, viewBox: viewBox, width: size, children: children }));
4
+ }
5
+ export function AddIcon(props) {
6
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "M12 5v14M5 12h14", stroke: "currentColor", strokeWidth: "2" }) }));
7
+ }
8
+ export function BoldIcon(props) {
9
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "M8 5h5.2a3.1 3.1 0 0 1 0 6.2H8zm0 6.2h6a3.4 3.4 0 0 1 0 6.8H8z", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2" }) }));
10
+ }
11
+ export function CloseIcon(props) {
12
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "m6 6 12 12M18 6 6 18", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" }) }));
13
+ }
14
+ export function CopyIcon(props) {
15
+ return (_jsxs(IconSvg, { ...props, children: [_jsx("rect", { height: "11", rx: "1.8", stroke: "currentColor", strokeWidth: "2", width: "9", x: "9", y: "7" }), _jsx("path", { d: "M6 15H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v1", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" })] }));
16
+ }
17
+ export function CodeIcon(props) {
18
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "m9 8-4 4 4 4m6-8 4 4-4 4", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2" }) }));
19
+ }
20
+ export function CutIcon(props) {
21
+ return (_jsxs(IconSvg, { ...props, children: [_jsx("circle", { cx: "6", cy: "6", r: "2.2", stroke: "currentColor", strokeWidth: "2" }), _jsx("circle", { cx: "6", cy: "18", r: "2.2", stroke: "currentColor", strokeWidth: "2" }), _jsx("path", { d: "M8 8 20 20M8 16 20 4", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" })] }));
22
+ }
23
+ export function DataObjectIcon(props) {
24
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "M8 4H7a3 3 0 0 0-3 3v2a2 2 0 0 1-2 2 2 2 0 0 1 2 2v2a3 3 0 0 0 3 3h1m8-14h1a3 3 0 0 1 3 3v2a2 2 0 0 0 2 2 2 2 0 0 0-2 2v2a3 3 0 0 1-3 3h-1", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2" }) }));
25
+ }
26
+ export function DeleteIcon(props) {
27
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "M5 7h14m-11 0V5a1.5 1.5 0 0 1 1.5-1.5h5A1.5 1.5 0 0 1 16 5v2m-8 0 .6 12h6.8L16 7", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2" }) }));
28
+ }
29
+ export function DividerIcon(props) {
30
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "M5 12h14", stroke: "currentColor", strokeWidth: "2" }) }));
31
+ }
32
+ export function DragHandleIcon(props) {
33
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "M9 6h.01M15 6h.01M9 12h.01M15 12h.01M9 18h.01M15 18h.01", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "3" }) }));
34
+ }
35
+ export function ImageIcon(props) {
36
+ return (_jsxs(IconSvg, { ...props, children: [_jsx("rect", { height: "14", rx: "2", stroke: "currentColor", strokeWidth: "2", width: "16", x: "4", y: "5" }), _jsx("path", { d: "m7 16 3.5-3.5 2.5 2.5 2-2 2 3", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2" }), _jsx("circle", { cx: "15.5", cy: "8.5", fill: "currentColor", r: "1.2" })] }));
37
+ }
38
+ export function ItalicIcon(props) {
39
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "M10 5h7M7 19h7m-1-14-4 14", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" }) }));
40
+ }
41
+ export function LinkIcon(props) {
42
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "m10 13 4-4m-3.5-3.5 1.2-1.2a4 4 0 0 1 5.7 5.7L16 11.4m-2.5 7.1-1.2 1.2a4 4 0 0 1-5.7-5.7L8 12.6", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2" }) }));
43
+ }
44
+ export function MicIcon(props) {
45
+ return (_jsxs(IconSvg, { ...props, children: [_jsx("path", { d: "M12 4a3 3 0 0 0-3 3v5a3 3 0 0 0 6 0V7a3 3 0 0 0-3-3Z", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2" }), _jsx("path", { d: "M5 11a7 7 0 0 0 14 0M12 18v3m-3 0h6", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" })] }));
46
+ }
47
+ export function QuoteIcon(props) {
48
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "M9 7H6.5A2.5 2.5 0 0 0 4 9.5V17h5v-5H6.5v-1.5H9zm11 0h-2.5A2.5 2.5 0 0 0 15 9.5V17h5v-5h-2.5v-1.5H20z", fill: "currentColor" }) }));
49
+ }
50
+ export function StopIcon(props) {
51
+ return (_jsx(IconSvg, { ...props, children: _jsx("rect", { fill: "currentColor", height: "12", rx: "2", width: "12", x: "6", y: "6" }) }));
52
+ }
53
+ export function TitleIcon(props) {
54
+ return (_jsx(IconSvg, { ...props, children: _jsx("path", { d: "M5 6h14M12 6v12m-4 0h8", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" }) }));
55
+ }
@@ -0,0 +1,4 @@
1
+ import type { RichTextBlock } from "../types";
2
+ export declare function RichTextRenderedBlock({ block }: {
3
+ block: RichTextBlock;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { markdownToEditorHtml } from "../richText.js";
3
+ // Renders one stored rich-text block as display-only journal content.
4
+ export function RichTextRenderedBlock({ block }) {
5
+ if (block.type === "divider") {
6
+ return _jsx("hr", { className: "bayon-rte-divider" });
7
+ }
8
+ if (block.type === "image") {
9
+ return (_jsx("figure", { "data-placeholder": "image", children: block.assetId ? null : _jsx("p", { children: "Image placeholder" }) }));
10
+ }
11
+ if (block.type === "code") {
12
+ return (_jsx("pre", { children: _jsx("code", { children: block.text }) }));
13
+ }
14
+ if (block.type === "checkbox") {
15
+ return (_jsxs("div", { "data-rich-text-checkbox": "", children: [_jsx("input", { checked: block.checked, readOnly: true, type: "checkbox" }), _jsx("span", { dangerouslySetInnerHTML: {
16
+ __html: markdownToEditorHtml(block.markdown) || " ",
17
+ } })] }));
18
+ }
19
+ const component = block.type === "heading"
20
+ ? "h2"
21
+ : block.type === "quote"
22
+ ? "blockquote"
23
+ : "p";
24
+ const props = {
25
+ dangerouslySetInnerHTML: {
26
+ __html: markdownToEditorHtml(block.markdown) || " ",
27
+ },
28
+ };
29
+ if (component === "h2") {
30
+ return _jsx("h2", { ...props });
31
+ }
32
+ if (component === "blockquote") {
33
+ return _jsx("blockquote", { ...props });
34
+ }
35
+ return _jsx("p", { ...props });
36
+ }
@@ -0,0 +1,4 @@
1
+ import type { RichTextBlock } from "../types";
2
+ export declare function RichTextRenderer({ contentBlocks, }: {
3
+ contentBlocks: RichTextBlock[];
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { RichTextRenderedBlock } from "./RichTextRenderedBlock.js";
3
+ import { sanitizeRichTextBlocks } from "../richText.js";
4
+ import { RichTextStyleScope } from "./RichTextStyles.js";
5
+ // Renders a sanitized collection of rich-text blocks for read-only views.
6
+ export function RichTextRenderer({ contentBlocks, }) {
7
+ return (_jsxs(_Fragment, { children: [_jsx(RichTextStyleScope, {}), _jsx("div", { className: "bayon-rte-renderer", children: sanitizeRichTextBlocks(contentBlocks).map((block) => (_jsx(RichTextRenderedBlock, { block: block }, block.id))) })] }));
8
+ }
@@ -0,0 +1 @@
1
+ export declare function RichTextStyleScope(): import("react/jsx-runtime").JSX.Element;