@bayonai/rich-text-editor 0.1.2 → 1.0.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/BEHAVIOR.md +396 -0
- package/CHANGELOG.md +22 -0
- package/README.md +25 -6
- package/dist/core/blockTree.d.ts +14 -0
- package/dist/core/blockTree.js +126 -0
- package/dist/core/blockTypes.d.ts +6 -0
- package/dist/core/blockTypes.js +5 -0
- package/dist/core/exportImport.d.ts +59 -0
- package/dist/core/exportImport.js +51 -0
- package/dist/core/features.d.ts +59 -0
- package/dist/core/features.js +57 -0
- package/dist/core/imageBlockDiagnostics.d.ts +4 -0
- package/dist/core/imageBlockDiagnostics.js +19 -0
- package/dist/core/proFeatures.d.ts +60 -0
- package/dist/core/proFeatures.js +64 -0
- package/dist/{richText.d.ts → core/richText.d.ts} +2 -0
- package/dist/core/richText.js +566 -0
- package/dist/core/types.d.ts +78 -0
- package/dist/index.d.ts +14 -8
- package/dist/index.js +8 -5
- package/dist/react/editor/RichTextBody.d.ts +28 -0
- package/dist/react/editor/RichTextBody.js +131 -0
- package/dist/react/editor/RichTextEditor.d.ts +138 -0
- package/dist/react/editor/RichTextEditor.js +2925 -0
- package/dist/react/editor/RichTextRenderedBlock.d.ts +20 -0
- package/dist/react/editor/RichTextRenderedBlock.js +162 -0
- package/dist/react/editor/RichTextRenderer.d.ts +13 -0
- package/dist/react/editor/RichTextRenderer.js +16 -0
- package/dist/react/{RichTextTitleInput.d.ts → editor/RichTextTitleInput.d.ts} +11 -1
- package/dist/react/{RichTextTitleInput.js → editor/RichTextTitleInput.js} +17 -2
- package/dist/react/editor/blockActions.d.ts +48 -0
- package/dist/react/editor/blockActions.js +495 -0
- package/dist/react/editor/editorHistory.d.ts +55 -0
- package/dist/react/editor/editorHistory.js +111 -0
- package/dist/react/{editorNavigation.d.ts → editor/editorNavigation.d.ts} +2 -0
- package/dist/react/{editorNavigation.js → editor/editorNavigation.js} +16 -0
- package/dist/react/editor/editorOperations.d.ts +10 -0
- package/dist/react/editor/editorOperations.js +3 -0
- package/dist/react/editor/editorSelection.d.ts +3 -0
- package/dist/react/editor/editorSelection.js +215 -0
- package/dist/react/{editorShortcuts.d.ts → editor/editorShortcuts.d.ts} +10 -0
- package/dist/react/{editorShortcuts.js → editor/editorShortcuts.js} +17 -1
- package/dist/react/{RichTextIcons.d.ts → icons/RichTextIcons.d.ts} +3 -0
- package/dist/react/{RichTextIcons.js → icons/RichTextIcons.js} +9 -0
- package/dist/react/index.d.ts +12 -9
- package/dist/react/index.js +7 -6
- package/dist/react/{EditorSessionProvider.d.ts → session/EditorSessionProvider.d.ts} +2 -2
- package/dist/react/{EditorSessionProvider.js → session/EditorSessionProvider.js} +3 -3
- package/dist/react/{UnsavedChangesDialog.js → session/UnsavedChangesDialog.js} +1 -1
- package/dist/react/styles/RichTextStyles.js +1362 -0
- package/dist/react/{BlockActionTool.d.ts → tools/BlockActionTool.d.ts} +1 -1
- package/dist/react/{BlockActionTool.js → tools/BlockActionTool.js} +6 -2
- package/dist/react/tools/LinkCreationInput.d.ts +9 -0
- package/dist/react/tools/LinkCreationInput.js +38 -0
- package/dist/react/{SelectionFormatToolbar.d.ts → tools/SelectionFormatToolbar.d.ts} +3 -2
- package/dist/react/{SelectionFormatToolbar.js → tools/SelectionFormatToolbar.js} +3 -3
- package/dist/react/tools/SpecialBlockOption.d.ts +9 -0
- package/dist/react/tools/SpecialBlockOption.js +8 -0
- package/dist/react/tools/SpecialBlockTool.d.ts +91 -0
- package/dist/react/tools/SpecialBlockTool.js +125 -0
- package/dist/react/{TranscriptionControl.d.ts → tools/TranscriptionControl.d.ts} +9 -0
- package/dist/react/{TranscriptionControl.js → tools/TranscriptionControl.js} +70 -9
- package/dist/react/tools/blockActionToolState.d.ts +41 -0
- package/dist/react/tools/blockActionToolState.js +177 -0
- package/dist/react/tools/imageBlockDiagnostics.d.ts +2 -0
- package/dist/react/tools/imageBlockDiagnostics.js +12 -0
- package/dist/{session.d.ts → session/session.d.ts} +1 -1
- package/dist-cjs/core/blockTree.js +137 -0
- package/dist-cjs/core/blockTypes.js +9 -0
- package/dist-cjs/core/exportImport.js +56 -0
- package/dist-cjs/core/features.js +62 -0
- package/dist-cjs/core/proFeatures.js +70 -0
- package/dist-cjs/core/richText.js +578 -0
- package/dist-cjs/index.js +22 -6
- package/dist-cjs/react/editor/RichTextBody.js +134 -0
- package/dist-cjs/react/editor/RichTextEditor.js +2956 -0
- package/dist-cjs/react/editor/RichTextRenderedBlock.js +166 -0
- package/dist-cjs/react/editor/RichTextRenderer.js +20 -0
- package/dist-cjs/react/{RichTextTitleInput.js → editor/RichTextTitleInput.js} +18 -2
- package/dist-cjs/react/editor/blockActions.js +518 -0
- package/dist-cjs/react/editor/editorHistory.js +120 -0
- package/dist-cjs/react/{editorNavigation.js → editor/editorNavigation.js} +17 -0
- package/dist-cjs/react/editor/editorOperations.js +6 -0
- package/dist-cjs/react/editor/editorSelection.js +219 -0
- package/dist-cjs/react/{editorShortcuts.js → editor/editorShortcuts.js} +17 -1
- package/dist-cjs/react/{RichTextIcons.js → icons/RichTextIcons.js} +12 -0
- package/dist-cjs/react/index.js +9 -7
- package/dist-cjs/react/{EditorSessionProvider.js → session/EditorSessionProvider.js} +3 -3
- package/dist-cjs/react/{UnsavedChangesDialog.js → session/UnsavedChangesDialog.js} +1 -1
- package/dist-cjs/react/styles/RichTextStyles.js +1365 -0
- package/dist-cjs/react/{BlockActionTool.js → tools/BlockActionTool.js} +6 -2
- package/dist-cjs/react/tools/LinkCreationInput.js +41 -0
- package/dist-cjs/react/{SelectionFormatToolbar.js → tools/SelectionFormatToolbar.js} +3 -3
- package/dist-cjs/react/tools/SpecialBlockOption.js +11 -0
- package/dist-cjs/react/tools/SpecialBlockTool.js +129 -0
- package/dist-cjs/react/{TranscriptionControl.js → tools/TranscriptionControl.js} +71 -9
- package/dist-cjs/react/tools/blockActionToolState.js +186 -0
- package/package.json +3 -2
- package/dist/react/RichTextBody.d.ts +0 -18
- package/dist/react/RichTextBody.js +0 -66
- package/dist/react/RichTextEditor.d.ts +0 -45
- package/dist/react/RichTextEditor.js +0 -1096
- package/dist/react/RichTextRenderedBlock.d.ts +0 -4
- package/dist/react/RichTextRenderedBlock.js +0 -36
- package/dist/react/RichTextRenderer.d.ts +0 -4
- package/dist/react/RichTextRenderer.js +0 -8
- package/dist/react/RichTextStyles.js +0 -719
- package/dist/react/SpecialBlockOption.d.ts +0 -7
- package/dist/react/SpecialBlockOption.js +0 -7
- package/dist/react/SpecialBlockTool.d.ts +0 -42
- package/dist/react/SpecialBlockTool.js +0 -50
- package/dist/react/blockActionToolState.d.ts +0 -18
- package/dist/react/blockActionToolState.js +0 -53
- package/dist/react/blockActions.d.ts +0 -8
- package/dist/react/blockActions.js +0 -111
- package/dist/richText.js +0 -297
- package/dist/types.d.ts +0 -34
- package/dist-cjs/react/RichTextBody.js +0 -69
- package/dist-cjs/react/RichTextEditor.js +0 -1108
- package/dist-cjs/react/RichTextRenderedBlock.js +0 -39
- package/dist-cjs/react/RichTextRenderer.js +0 -11
- package/dist-cjs/react/RichTextStyles.js +0 -722
- package/dist-cjs/react/SpecialBlockOption.js +0 -10
- package/dist-cjs/react/SpecialBlockTool.js +0 -54
- package/dist-cjs/react/blockActionToolState.js +0 -58
- package/dist-cjs/react/blockActions.js +0 -119
- package/dist-cjs/richText.js +0 -307
- /package/dist/{types.js → core/types.js} +0 -0
- /package/dist/{writingStats.d.ts → core/writingStats.d.ts} +0 -0
- /package/dist/{writingStats.js → core/writingStats.js} +0 -0
- /package/dist/react/{RichTextDocumentSurface.d.ts → editor/RichTextDocumentSurface.d.ts} +0 -0
- /package/dist/react/{RichTextDocumentSurface.js → editor/RichTextDocumentSurface.js} +0 -0
- /package/dist/react/{UnsavedChangesDialog.d.ts → session/UnsavedChangesDialog.d.ts} +0 -0
- /package/dist/react/{RichTextStyles.d.ts → styles/RichTextStyles.d.ts} +0 -0
- /package/dist/react/{richTextBlockStyles.d.ts → styles/richTextBlockStyles.d.ts} +0 -0
- /package/dist/react/{richTextBlockStyles.js → styles/richTextBlockStyles.js} +0 -0
- /package/dist/react/{specialBlockStyles.d.ts → styles/specialBlockStyles.d.ts} +0 -0
- /package/dist/react/{specialBlockStyles.js → styles/specialBlockStyles.js} +0 -0
- /package/dist/{saveControl.d.ts → session/saveControl.d.ts} +0 -0
- /package/dist/{saveControl.js → session/saveControl.js} +0 -0
- /package/dist/{session.js → session/session.js} +0 -0
- /package/dist/{sessionRegistry.d.ts → session/sessionRegistry.d.ts} +0 -0
- /package/dist/{sessionRegistry.js → session/sessionRegistry.js} +0 -0
- /package/dist-cjs/{types.js → core/types.js} +0 -0
- /package/dist-cjs/{writingStats.js → core/writingStats.js} +0 -0
- /package/dist-cjs/react/{RichTextDocumentSurface.js → editor/RichTextDocumentSurface.js} +0 -0
- /package/dist-cjs/react/{richTextBlockStyles.js → styles/richTextBlockStyles.js} +0 -0
- /package/dist-cjs/react/{specialBlockStyles.js → styles/specialBlockStyles.js} +0 -0
- /package/dist-cjs/{saveControl.js → session/saveControl.js} +0 -0
- /package/dist-cjs/{session.js → session/session.js} +0 -0
- /package/dist-cjs/{sessionRegistry.js → session/sessionRegistry.js} +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RichTextRenderedBlocks = RichTextRenderedBlocks;
|
|
4
|
+
exports.RichTextRenderedBlock = RichTextRenderedBlock;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const richText_1 = require("../../core/richText");
|
|
7
|
+
function RichTextRenderedBlocks({ activeAnnotationTarget, blocks, onToggleCollapsedChange, renderToolBlock, }) {
|
|
8
|
+
const renderedBlocks = [];
|
|
9
|
+
for (let index = 0; index < blocks.length; index += 1) {
|
|
10
|
+
const block = blocks[index];
|
|
11
|
+
if (!block) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (isTreeRenderedBlock(block)) {
|
|
15
|
+
const treeKind = getRenderedTreeKind(block);
|
|
16
|
+
const treeBlocks = [];
|
|
17
|
+
while (true) {
|
|
18
|
+
const treeBlock = blocks[index];
|
|
19
|
+
if (!isTreeRenderedBlock(treeBlock) ||
|
|
20
|
+
getRenderedTreeKind(treeBlock) !== treeKind) {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
treeBlocks.push(treeBlock);
|
|
24
|
+
index += 1;
|
|
25
|
+
}
|
|
26
|
+
index -= 1;
|
|
27
|
+
const TreeTag = treeKind === "ordered" ? "ol" : "ul";
|
|
28
|
+
renderedBlocks.push((0, jsx_runtime_1.jsx)(TreeTag, { "data-rich-text-children": "", children: treeBlocks.map((child) => ((0, jsx_runtime_1.jsx)(RichTextRenderedBlock, { activeAnnotationTarget: activeAnnotationTarget, block: child, onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock }, child.id))) }, `tree-${treeBlocks[0]?.id}`));
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
renderedBlocks.push((0, jsx_runtime_1.jsx)(RichTextRenderedBlock, { activeAnnotationTarget: activeAnnotationTarget, block: block, onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock }, block.id));
|
|
32
|
+
}
|
|
33
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: renderedBlocks });
|
|
34
|
+
}
|
|
35
|
+
// Renders one stored rich-text block as display-only journal content.
|
|
36
|
+
function RichTextRenderedBlock({ activeAnnotationTarget, block, onToggleCollapsedChange, renderToolBlock, }) {
|
|
37
|
+
const activeBlockAttributes = getActiveCommentTargetAttributes(block, activeAnnotationTarget);
|
|
38
|
+
const blockAnnotationTarget = activeBlockAttributes["data-rich-text-comment-target"] === "active"
|
|
39
|
+
? activeAnnotationTarget
|
|
40
|
+
: null;
|
|
41
|
+
if (block.type === "divider") {
|
|
42
|
+
return (0, jsx_runtime_1.jsx)("hr", { className: "bayon-rte-divider", ...activeBlockAttributes });
|
|
43
|
+
}
|
|
44
|
+
if (block.type === "image") {
|
|
45
|
+
const imageDisplaySize = getRenderedImageDisplaySize(block.displaySize);
|
|
46
|
+
const imageStyle = getRenderedImageCustomWidthStyle(imageDisplaySize, block.customWidth);
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)("figure", { ...activeBlockAttributes, "data-image-align": getRenderedImageAlignment(block.alignment), "data-image-size": imageDisplaySize ?? undefined, "data-placeholder": block.url ? undefined : "image", "data-rich-text-image": "", style: imageStyle, children: block.url ? (0, jsx_runtime_1.jsx)("img", { alt: block.alt ?? "", src: block.url }) : null }));
|
|
48
|
+
}
|
|
49
|
+
if (block.type === "code") {
|
|
50
|
+
return ((0, jsx_runtime_1.jsx)("pre", { ...activeBlockAttributes, children: (0, jsx_runtime_1.jsx)("code", { children: block.text }) }));
|
|
51
|
+
}
|
|
52
|
+
if (block.type === "message") {
|
|
53
|
+
return ((0, jsx_runtime_1.jsx)("p", { ...activeBlockAttributes, "data-rich-text-message": "", children: (0, jsx_runtime_1.jsx)(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) }));
|
|
54
|
+
}
|
|
55
|
+
if (block.type === "tool") {
|
|
56
|
+
if (renderToolBlock) {
|
|
57
|
+
try {
|
|
58
|
+
return renderToolBlock(block);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error("[RichTextRenderer] Tool block renderer failed.", {
|
|
62
|
+
block,
|
|
63
|
+
error,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return (0, jsx_runtime_1.jsx)(DefaultToolBlock, { block: block });
|
|
68
|
+
}
|
|
69
|
+
if (block.type === "checkbox") {
|
|
70
|
+
return ((0, jsx_runtime_1.jsxs)("li", { "data-rich-text-checkbox": "", ...activeBlockAttributes, children: [(0, jsx_runtime_1.jsxs)("div", { "data-rich-text-row": "", children: [(0, jsx_runtime_1.jsx)("input", { checked: block.checked, readOnly: true, type: "checkbox" }), (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) })] }), (0, jsx_runtime_1.jsx)(NestedRichTextBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: block.children ?? [], onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock })] }));
|
|
71
|
+
}
|
|
72
|
+
if (block.type === "bullet") {
|
|
73
|
+
return ((0, jsx_runtime_1.jsxs)("li", { "data-rich-text-bullet": "", ...activeBlockAttributes, children: [(0, jsx_runtime_1.jsxs)("div", { "data-rich-text-row": "", children: [(0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", "data-bullet-marker": "" }), (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) })] }), (0, jsx_runtime_1.jsx)(NestedRichTextBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: block.children ?? [], onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock })] }));
|
|
74
|
+
}
|
|
75
|
+
if (block.type === "ordered") {
|
|
76
|
+
return ((0, jsx_runtime_1.jsxs)("li", { "data-rich-text-ordered": "", ...activeBlockAttributes, children: [(0, jsx_runtime_1.jsxs)("div", { "data-rich-text-row": "", children: [(0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", "data-ordered-marker": "" }), (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) })] }), (0, jsx_runtime_1.jsx)(NestedRichTextBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: block.children ?? [], onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock })] }));
|
|
77
|
+
}
|
|
78
|
+
if (block.type === "toggle") {
|
|
79
|
+
const actionLabel = block.collapsed ? "Expand toggle" : "Collapse toggle";
|
|
80
|
+
return ((0, jsx_runtime_1.jsxs)("li", { ...activeBlockAttributes, "data-rich-text-toggle": "", "data-toggle-collapsed": block.collapsed ? "true" : "false", children: [(0, jsx_runtime_1.jsxs)("div", { "data-rich-text-row": "", children: [onToggleCollapsedChange ? ((0, jsx_runtime_1.jsx)("button", { "aria-label": actionLabel, className: "bayon-rte-toggle-button", "data-toggle-collapse": "", onClick: () => onToggleCollapsedChange(block.id, !block.collapsed), title: actionLabel, type: "button", children: (0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", className: "bayon-rte-toggle-caret" }) })) : ((0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", className: "bayon-rte-toggle-caret" })), (0, jsx_runtime_1.jsx)("span", { "data-toggle-label": "", children: (0, jsx_runtime_1.jsx)(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) })] }), block.children.length > 0 ? ((0, jsx_runtime_1.jsx)("div", { "data-toggle-content": "", children: (0, jsx_runtime_1.jsx)(NestedRichTextBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: block.children, onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock }) })) : null] }));
|
|
81
|
+
}
|
|
82
|
+
const component = block.type === "heading"
|
|
83
|
+
? "h2"
|
|
84
|
+
: block.type === "quote"
|
|
85
|
+
? "blockquote"
|
|
86
|
+
: "p";
|
|
87
|
+
const props = activeBlockAttributes;
|
|
88
|
+
const children = ((0, jsx_runtime_1.jsx)(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }));
|
|
89
|
+
if (component === "h2") {
|
|
90
|
+
return (0, jsx_runtime_1.jsx)("h2", { ...props, children: children });
|
|
91
|
+
}
|
|
92
|
+
if (component === "blockquote") {
|
|
93
|
+
return (0, jsx_runtime_1.jsx)("blockquote", { ...props, children: children });
|
|
94
|
+
}
|
|
95
|
+
return (0, jsx_runtime_1.jsx)("p", { ...props, children: children });
|
|
96
|
+
}
|
|
97
|
+
function getRenderedImageAlignment(value) {
|
|
98
|
+
return value === "left" || value === "right" ? value : "center";
|
|
99
|
+
}
|
|
100
|
+
function getRenderedImageDisplaySize(value) {
|
|
101
|
+
return value === "small" ||
|
|
102
|
+
value === "medium" ||
|
|
103
|
+
value === "full" ||
|
|
104
|
+
value === "custom"
|
|
105
|
+
? value
|
|
106
|
+
: null;
|
|
107
|
+
}
|
|
108
|
+
function getRenderedImageCustomWidthStyle(displaySize, customWidth) {
|
|
109
|
+
if (displaySize !== "custom" ||
|
|
110
|
+
typeof customWidth !== "number" ||
|
|
111
|
+
!Number.isFinite(customWidth)) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
const width = Math.min(Math.max(Math.round(customWidth), 120), 1600);
|
|
115
|
+
return {
|
|
116
|
+
"--bayon-rte-image-custom-width": `${width}px`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function NestedRichTextBlocks({ activeAnnotationTarget, blocks, onToggleCollapsedChange, renderToolBlock, }) {
|
|
120
|
+
if (blocks.length === 0) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return ((0, jsx_runtime_1.jsx)(RichTextRenderedBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: blocks, onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock }));
|
|
124
|
+
}
|
|
125
|
+
function getActiveCommentTargetAttributes(block, target) {
|
|
126
|
+
const isActive = Boolean(target?.blockId && target.blockId === block.id);
|
|
127
|
+
return {
|
|
128
|
+
"data-rich-text-block-id": block.id,
|
|
129
|
+
...(isActive ? { "data-rich-text-comment-target": "active" } : {}),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function RenderedMarkdown({ markdown, target, }) {
|
|
133
|
+
const quote = target?.quote?.trim();
|
|
134
|
+
if (!quote) {
|
|
135
|
+
return ((0, jsx_runtime_1.jsx)("span", { dangerouslySetInnerHTML: {
|
|
136
|
+
__html: (0, richText_1.markdownToEditorHtml)(markdown) || " ",
|
|
137
|
+
} }));
|
|
138
|
+
}
|
|
139
|
+
const quoteIndex = markdown.indexOf(quote);
|
|
140
|
+
if (quoteIndex < 0) {
|
|
141
|
+
return ((0, jsx_runtime_1.jsx)("span", { dangerouslySetInnerHTML: {
|
|
142
|
+
__html: (0, richText_1.markdownToEditorHtml)(markdown) || " ",
|
|
143
|
+
} }));
|
|
144
|
+
}
|
|
145
|
+
const before = markdown.slice(0, quoteIndex);
|
|
146
|
+
const highlighted = markdown.slice(quoteIndex, quoteIndex + quote.length);
|
|
147
|
+
const after = markdown.slice(quoteIndex + quote.length);
|
|
148
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [before ? ((0, jsx_runtime_1.jsx)("span", { dangerouslySetInnerHTML: { __html: (0, richText_1.markdownToEditorHtml)(before) } })) : null, (0, jsx_runtime_1.jsx)("mark", { className: "bayon-rte-comment-highlight", dangerouslySetInnerHTML: {
|
|
149
|
+
__html: (0, richText_1.markdownToEditorHtml)(highlighted) || " ",
|
|
150
|
+
} }), after ? ((0, jsx_runtime_1.jsx)("span", { dangerouslySetInnerHTML: { __html: (0, richText_1.markdownToEditorHtml)(after) } })) : null] }));
|
|
151
|
+
}
|
|
152
|
+
function DefaultToolBlock({ block, }) {
|
|
153
|
+
const label = block.title || block.toolType;
|
|
154
|
+
return ((0, jsx_runtime_1.jsxs)("section", { "data-rich-text-tool": "", "data-tool-status": block.status, "data-tool-type": block.toolType, children: [(0, jsx_runtime_1.jsxs)("div", { "data-tool-header": "", children: [(0, jsx_runtime_1.jsx)("span", { "data-tool-title": "", children: label }), (0, jsx_runtime_1.jsx)("span", { "data-tool-status-label": "", children: block.status })] }), block.markdown ? ((0, jsx_runtime_1.jsx)("p", { "data-tool-markdown": "", dangerouslySetInnerHTML: {
|
|
155
|
+
__html: (0, richText_1.markdownToEditorHtml)(block.markdown),
|
|
156
|
+
} })) : null] }));
|
|
157
|
+
}
|
|
158
|
+
function isTreeRenderedBlock(block) {
|
|
159
|
+
return (block?.type === "bullet" ||
|
|
160
|
+
block?.type === "ordered" ||
|
|
161
|
+
block?.type === "checkbox" ||
|
|
162
|
+
block?.type === "toggle");
|
|
163
|
+
}
|
|
164
|
+
function getRenderedTreeKind(block) {
|
|
165
|
+
return block?.type === "ordered" ? "ordered" : "unordered";
|
|
166
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RichTextRenderer = RichTextRenderer;
|
|
4
|
+
exports.getRichTextBlocksWithRenderedToggleCollapsed = getRichTextBlocksWithRenderedToggleCollapsed;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const RichTextRenderedBlock_1 = require("./RichTextRenderedBlock");
|
|
7
|
+
const blockActions_1 = require("../editor/blockActions");
|
|
8
|
+
const richText_1 = require("../../core/richText");
|
|
9
|
+
const RichTextStyles_1 = require("../styles/RichTextStyles");
|
|
10
|
+
// Renders a sanitized collection of rich-text blocks for read-only views.
|
|
11
|
+
function RichTextRenderer({ activeAnnotationTarget, contentBlocks, onContentBlocksChange, renderToolBlock, }) {
|
|
12
|
+
const sanitizedContentBlocks = (0, richText_1.sanitizeRichTextBlocks)(contentBlocks);
|
|
13
|
+
function handleToggleCollapsedChange(blockId, collapsed) {
|
|
14
|
+
onContentBlocksChange?.(getRichTextBlocksWithRenderedToggleCollapsed(sanitizedContentBlocks, blockId, collapsed));
|
|
15
|
+
}
|
|
16
|
+
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, jsx_runtime_1.jsx)(RichTextRenderedBlock_1.RichTextRenderedBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: sanitizedContentBlocks, onToggleCollapsedChange: onContentBlocksChange ? handleToggleCollapsedChange : undefined, renderToolBlock: renderToolBlock }) })] }));
|
|
17
|
+
}
|
|
18
|
+
function getRichTextBlocksWithRenderedToggleCollapsed(blocks, blockId, collapsed) {
|
|
19
|
+
return (0, blockActions_1.setToggleCollapsed)((0, richText_1.sanitizeRichTextBlocks)(blocks), blockId, collapsed);
|
|
20
|
+
}
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.RichTextTitleInput = RichTextTitleInput;
|
|
5
5
|
exports.getTitleKeyCommand = getTitleKeyCommand;
|
|
6
|
+
exports.getTitleHistoryCommand = getTitleHistoryCommand;
|
|
6
7
|
exports.RichTextReadTitle = RichTextReadTitle;
|
|
7
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
9
|
const react_1 = require("react");
|
|
9
|
-
const RichTextStyles_1 = require("
|
|
10
|
+
const RichTextStyles_1 = require("../styles/RichTextStyles");
|
|
11
|
+
const editorNavigation_1 = require("./editorNavigation");
|
|
10
12
|
// Renders the title field and handles keyboard movement into the editor body.
|
|
11
|
-
function RichTextTitleInput({ disabled, inputRef, label, onArrowDown, onChange, required, title, validationMessage = "", }) {
|
|
13
|
+
function RichTextTitleInput({ disabled, inputRef, label, onArrowDown, onChange, onRedo, required, title, onUndo, validationMessage = "", }) {
|
|
12
14
|
const validationMessageId = (0, react_1.useId)();
|
|
13
15
|
(0, react_1.useEffect)(() => {
|
|
14
16
|
resizeTitleTextArea(inputRef.current);
|
|
@@ -17,6 +19,17 @@ function RichTextTitleInput({ disabled, inputRef, label, onArrowDown, onChange,
|
|
|
17
19
|
resizeTitleTextArea(event.currentTarget);
|
|
18
20
|
onChange(event.target.value);
|
|
19
21
|
}, onInput: (event) => resizeTitleTextArea(event.currentTarget), onKeyDown: (event) => {
|
|
22
|
+
const historyCommand = getTitleHistoryCommand(event);
|
|
23
|
+
if (historyCommand === "undo") {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
onUndo?.();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (historyCommand === "redo") {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
onRedo?.();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
20
33
|
if (getTitleKeyCommand(event) === "focus-body-start") {
|
|
21
34
|
event.preventDefault();
|
|
22
35
|
onArrowDown();
|
|
@@ -28,6 +41,9 @@ function getTitleKeyCommand(event) {
|
|
|
28
41
|
? "focus-body-start"
|
|
29
42
|
: null;
|
|
30
43
|
}
|
|
44
|
+
function getTitleHistoryCommand(event) {
|
|
45
|
+
return (0, editorNavigation_1.getEditorHistoryShortcut)(event);
|
|
46
|
+
}
|
|
31
47
|
function RichTextReadTitle({ title }) {
|
|
32
48
|
const titleRef = (0, react_1.useRef)(null);
|
|
33
49
|
(0, react_1.useEffect)(() => {
|