@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,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AddIcon = AddIcon;
4
+ exports.BoldIcon = BoldIcon;
5
+ exports.CloseIcon = CloseIcon;
6
+ exports.CopyIcon = CopyIcon;
7
+ exports.CodeIcon = CodeIcon;
8
+ exports.CutIcon = CutIcon;
9
+ exports.DataObjectIcon = DataObjectIcon;
10
+ exports.DeleteIcon = DeleteIcon;
11
+ exports.DividerIcon = DividerIcon;
12
+ exports.DragHandleIcon = DragHandleIcon;
13
+ exports.ImageIcon = ImageIcon;
14
+ exports.ItalicIcon = ItalicIcon;
15
+ exports.LinkIcon = LinkIcon;
16
+ exports.MicIcon = MicIcon;
17
+ exports.QuoteIcon = QuoteIcon;
18
+ exports.StopIcon = StopIcon;
19
+ exports.TitleIcon = TitleIcon;
20
+ const jsx_runtime_1 = require("react/jsx-runtime");
21
+ function IconSvg({ children, className, size = 18, viewBox = "0 0 24 24", }) {
22
+ return ((0, jsx_runtime_1.jsx)("svg", { "aria-hidden": "true", className: className, fill: "none", height: size, viewBox: viewBox, width: size, children: children }));
23
+ }
24
+ function AddIcon(props) {
25
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.jsx)("path", { d: "M12 5v14M5 12h14", stroke: "currentColor", strokeWidth: "2" }) }));
26
+ }
27
+ function BoldIcon(props) {
28
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.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" }) }));
29
+ }
30
+ function CloseIcon(props) {
31
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.jsx)("path", { d: "m6 6 12 12M18 6 6 18", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" }) }));
32
+ }
33
+ function CopyIcon(props) {
34
+ return ((0, jsx_runtime_1.jsxs)(IconSvg, { ...props, children: [(0, jsx_runtime_1.jsx)("rect", { height: "11", rx: "1.8", stroke: "currentColor", strokeWidth: "2", width: "9", x: "9", y: "7" }), (0, jsx_runtime_1.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" })] }));
35
+ }
36
+ function CodeIcon(props) {
37
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.jsx)("path", { d: "m9 8-4 4 4 4m6-8 4 4-4 4", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2" }) }));
38
+ }
39
+ function CutIcon(props) {
40
+ return ((0, jsx_runtime_1.jsxs)(IconSvg, { ...props, children: [(0, jsx_runtime_1.jsx)("circle", { cx: "6", cy: "6", r: "2.2", stroke: "currentColor", strokeWidth: "2" }), (0, jsx_runtime_1.jsx)("circle", { cx: "6", cy: "18", r: "2.2", stroke: "currentColor", strokeWidth: "2" }), (0, jsx_runtime_1.jsx)("path", { d: "M8 8 20 20M8 16 20 4", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" })] }));
41
+ }
42
+ function DataObjectIcon(props) {
43
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.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" }) }));
44
+ }
45
+ function DeleteIcon(props) {
46
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.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" }) }));
47
+ }
48
+ function DividerIcon(props) {
49
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.jsx)("path", { d: "M5 12h14", stroke: "currentColor", strokeWidth: "2" }) }));
50
+ }
51
+ function DragHandleIcon(props) {
52
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.jsx)("path", { d: "M9 6h.01M15 6h.01M9 12h.01M15 12h.01M9 18h.01M15 18h.01", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "3" }) }));
53
+ }
54
+ function ImageIcon(props) {
55
+ return ((0, jsx_runtime_1.jsxs)(IconSvg, { ...props, children: [(0, jsx_runtime_1.jsx)("rect", { height: "14", rx: "2", stroke: "currentColor", strokeWidth: "2", width: "16", x: "4", y: "5" }), (0, jsx_runtime_1.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" }), (0, jsx_runtime_1.jsx)("circle", { cx: "15.5", cy: "8.5", fill: "currentColor", r: "1.2" })] }));
56
+ }
57
+ function ItalicIcon(props) {
58
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.jsx)("path", { d: "M10 5h7M7 19h7m-1-14-4 14", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" }) }));
59
+ }
60
+ function LinkIcon(props) {
61
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.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" }) }));
62
+ }
63
+ function MicIcon(props) {
64
+ return ((0, jsx_runtime_1.jsxs)(IconSvg, { ...props, children: [(0, jsx_runtime_1.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" }), (0, jsx_runtime_1.jsx)("path", { d: "M5 11a7 7 0 0 0 14 0M12 18v3m-3 0h6", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" })] }));
65
+ }
66
+ function QuoteIcon(props) {
67
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.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" }) }));
68
+ }
69
+ function StopIcon(props) {
70
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.jsx)("rect", { fill: "currentColor", height: "12", rx: "2", width: "12", x: "6", y: "6" }) }));
71
+ }
72
+ function TitleIcon(props) {
73
+ return ((0, jsx_runtime_1.jsx)(IconSvg, { ...props, children: (0, jsx_runtime_1.jsx)("path", { d: "M5 6h14M12 6v12m-4 0h8", stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2" }) }));
74
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RichTextRenderedBlock = RichTextRenderedBlock;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const richText_1 = require("../richText");
6
+ // Renders one stored rich-text block as display-only journal content.
7
+ function RichTextRenderedBlock({ block }) {
8
+ if (block.type === "divider") {
9
+ return (0, jsx_runtime_1.jsx)("hr", { className: "bayon-rte-divider" });
10
+ }
11
+ if (block.type === "image") {
12
+ return ((0, jsx_runtime_1.jsx)("figure", { "data-placeholder": "image", children: block.assetId ? null : (0, jsx_runtime_1.jsx)("p", { children: "Image placeholder" }) }));
13
+ }
14
+ if (block.type === "code") {
15
+ return ((0, jsx_runtime_1.jsx)("pre", { children: (0, jsx_runtime_1.jsx)("code", { children: block.text }) }));
16
+ }
17
+ if (block.type === "checkbox") {
18
+ return ((0, jsx_runtime_1.jsxs)("div", { "data-rich-text-checkbox": "", children: [(0, jsx_runtime_1.jsx)("input", { checked: block.checked, readOnly: true, type: "checkbox" }), (0, jsx_runtime_1.jsx)("span", { dangerouslySetInnerHTML: {
19
+ __html: (0, richText_1.markdownToEditorHtml)(block.markdown) || " ",
20
+ } })] }));
21
+ }
22
+ const component = block.type === "heading"
23
+ ? "h2"
24
+ : block.type === "quote"
25
+ ? "blockquote"
26
+ : "p";
27
+ const props = {
28
+ dangerouslySetInnerHTML: {
29
+ __html: (0, richText_1.markdownToEditorHtml)(block.markdown) || " ",
30
+ },
31
+ };
32
+ if (component === "h2") {
33
+ return (0, jsx_runtime_1.jsx)("h2", { ...props });
34
+ }
35
+ if (component === "blockquote") {
36
+ return (0, jsx_runtime_1.jsx)("blockquote", { ...props });
37
+ }
38
+ return (0, jsx_runtime_1.jsx)("p", { ...props });
39
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RichTextRenderer = RichTextRenderer;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const RichTextRenderedBlock_1 = require("./RichTextRenderedBlock");
6
+ const richText_1 = require("../richText");
7
+ const RichTextStyles_1 = require("./RichTextStyles");
8
+ // Renders a sanitized collection of rich-text blocks for read-only views.
9
+ function RichTextRenderer({ contentBlocks, }) {
10
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(RichTextStyles_1.RichTextStyleScope, {}), (0, jsx_runtime_1.jsx)("div", { className: "bayon-rte-renderer", children: (0, richText_1.sanitizeRichTextBlocks)(contentBlocks).map((block) => ((0, jsx_runtime_1.jsx)(RichTextRenderedBlock_1.RichTextRenderedBlock, { block: block }, block.id))) })] }));
11
+ }