@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,20 @@
|
|
|
1
|
+
import type { RichTextBlock } from "../../core/types";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { RichTextAnnotationTarget } from "./RichTextRenderer";
|
|
4
|
+
type RenderedToggleCollapsedChangeHandler = (blockId: string, collapsed: boolean) => void;
|
|
5
|
+
export type RichTextToolBlockRenderer = (block: Extract<RichTextBlock, {
|
|
6
|
+
type: "tool";
|
|
7
|
+
}>) => ReactNode;
|
|
8
|
+
export declare function RichTextRenderedBlocks({ activeAnnotationTarget, blocks, onToggleCollapsedChange, renderToolBlock, }: {
|
|
9
|
+
activeAnnotationTarget?: RichTextAnnotationTarget | null;
|
|
10
|
+
blocks: RichTextBlock[];
|
|
11
|
+
onToggleCollapsedChange?: RenderedToggleCollapsedChangeHandler;
|
|
12
|
+
renderToolBlock?: RichTextToolBlockRenderer;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare function RichTextRenderedBlock({ activeAnnotationTarget, block, onToggleCollapsedChange, renderToolBlock, }: {
|
|
15
|
+
activeAnnotationTarget?: RichTextAnnotationTarget | null;
|
|
16
|
+
block: RichTextBlock;
|
|
17
|
+
onToggleCollapsedChange?: RenderedToggleCollapsedChangeHandler;
|
|
18
|
+
renderToolBlock?: RichTextToolBlockRenderer;
|
|
19
|
+
}): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { markdownToEditorHtml } from "../../core/richText.js";
|
|
3
|
+
export function RichTextRenderedBlocks({ activeAnnotationTarget, blocks, onToggleCollapsedChange, renderToolBlock, }) {
|
|
4
|
+
const renderedBlocks = [];
|
|
5
|
+
for (let index = 0; index < blocks.length; index += 1) {
|
|
6
|
+
const block = blocks[index];
|
|
7
|
+
if (!block) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
if (isTreeRenderedBlock(block)) {
|
|
11
|
+
const treeKind = getRenderedTreeKind(block);
|
|
12
|
+
const treeBlocks = [];
|
|
13
|
+
while (true) {
|
|
14
|
+
const treeBlock = blocks[index];
|
|
15
|
+
if (!isTreeRenderedBlock(treeBlock) ||
|
|
16
|
+
getRenderedTreeKind(treeBlock) !== treeKind) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
treeBlocks.push(treeBlock);
|
|
20
|
+
index += 1;
|
|
21
|
+
}
|
|
22
|
+
index -= 1;
|
|
23
|
+
const TreeTag = treeKind === "ordered" ? "ol" : "ul";
|
|
24
|
+
renderedBlocks.push(_jsx(TreeTag, { "data-rich-text-children": "", children: treeBlocks.map((child) => (_jsx(RichTextRenderedBlock, { activeAnnotationTarget: activeAnnotationTarget, block: child, onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock }, child.id))) }, `tree-${treeBlocks[0]?.id}`));
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
renderedBlocks.push(_jsx(RichTextRenderedBlock, { activeAnnotationTarget: activeAnnotationTarget, block: block, onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock }, block.id));
|
|
28
|
+
}
|
|
29
|
+
return _jsx(_Fragment, { children: renderedBlocks });
|
|
30
|
+
}
|
|
31
|
+
// Renders one stored rich-text block as display-only journal content.
|
|
32
|
+
export function RichTextRenderedBlock({ activeAnnotationTarget, block, onToggleCollapsedChange, renderToolBlock, }) {
|
|
33
|
+
const activeBlockAttributes = getActiveCommentTargetAttributes(block, activeAnnotationTarget);
|
|
34
|
+
const blockAnnotationTarget = activeBlockAttributes["data-rich-text-comment-target"] === "active"
|
|
35
|
+
? activeAnnotationTarget
|
|
36
|
+
: null;
|
|
37
|
+
if (block.type === "divider") {
|
|
38
|
+
return _jsx("hr", { className: "bayon-rte-divider", ...activeBlockAttributes });
|
|
39
|
+
}
|
|
40
|
+
if (block.type === "image") {
|
|
41
|
+
const imageDisplaySize = getRenderedImageDisplaySize(block.displaySize);
|
|
42
|
+
const imageStyle = getRenderedImageCustomWidthStyle(imageDisplaySize, block.customWidth);
|
|
43
|
+
return (_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 ? _jsx("img", { alt: block.alt ?? "", src: block.url }) : null }));
|
|
44
|
+
}
|
|
45
|
+
if (block.type === "code") {
|
|
46
|
+
return (_jsx("pre", { ...activeBlockAttributes, children: _jsx("code", { children: block.text }) }));
|
|
47
|
+
}
|
|
48
|
+
if (block.type === "message") {
|
|
49
|
+
return (_jsx("p", { ...activeBlockAttributes, "data-rich-text-message": "", children: _jsx(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) }));
|
|
50
|
+
}
|
|
51
|
+
if (block.type === "tool") {
|
|
52
|
+
if (renderToolBlock) {
|
|
53
|
+
try {
|
|
54
|
+
return renderToolBlock(block);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error("[RichTextRenderer] Tool block renderer failed.", {
|
|
58
|
+
block,
|
|
59
|
+
error,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return _jsx(DefaultToolBlock, { block: block });
|
|
64
|
+
}
|
|
65
|
+
if (block.type === "checkbox") {
|
|
66
|
+
return (_jsxs("li", { "data-rich-text-checkbox": "", ...activeBlockAttributes, children: [_jsxs("div", { "data-rich-text-row": "", children: [_jsx("input", { checked: block.checked, readOnly: true, type: "checkbox" }), _jsx("span", { children: _jsx(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) })] }), _jsx(NestedRichTextBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: block.children ?? [], onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock })] }));
|
|
67
|
+
}
|
|
68
|
+
if (block.type === "bullet") {
|
|
69
|
+
return (_jsxs("li", { "data-rich-text-bullet": "", ...activeBlockAttributes, children: [_jsxs("div", { "data-rich-text-row": "", children: [_jsx("span", { "aria-hidden": "true", "data-bullet-marker": "" }), _jsx("span", { children: _jsx(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) })] }), _jsx(NestedRichTextBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: block.children ?? [], onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock })] }));
|
|
70
|
+
}
|
|
71
|
+
if (block.type === "ordered") {
|
|
72
|
+
return (_jsxs("li", { "data-rich-text-ordered": "", ...activeBlockAttributes, children: [_jsxs("div", { "data-rich-text-row": "", children: [_jsx("span", { "aria-hidden": "true", "data-ordered-marker": "" }), _jsx("span", { children: _jsx(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) })] }), _jsx(NestedRichTextBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: block.children ?? [], onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock })] }));
|
|
73
|
+
}
|
|
74
|
+
if (block.type === "toggle") {
|
|
75
|
+
const actionLabel = block.collapsed ? "Expand toggle" : "Collapse toggle";
|
|
76
|
+
return (_jsxs("li", { ...activeBlockAttributes, "data-rich-text-toggle": "", "data-toggle-collapsed": block.collapsed ? "true" : "false", children: [_jsxs("div", { "data-rich-text-row": "", children: [onToggleCollapsedChange ? (_jsx("button", { "aria-label": actionLabel, className: "bayon-rte-toggle-button", "data-toggle-collapse": "", onClick: () => onToggleCollapsedChange(block.id, !block.collapsed), title: actionLabel, type: "button", children: _jsx("span", { "aria-hidden": "true", className: "bayon-rte-toggle-caret" }) })) : (_jsx("span", { "aria-hidden": "true", className: "bayon-rte-toggle-caret" })), _jsx("span", { "data-toggle-label": "", children: _jsx(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }) })] }), block.children.length > 0 ? (_jsx("div", { "data-toggle-content": "", children: _jsx(NestedRichTextBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: block.children, onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock }) })) : null] }));
|
|
77
|
+
}
|
|
78
|
+
const component = block.type === "heading"
|
|
79
|
+
? "h2"
|
|
80
|
+
: block.type === "quote"
|
|
81
|
+
? "blockquote"
|
|
82
|
+
: "p";
|
|
83
|
+
const props = activeBlockAttributes;
|
|
84
|
+
const children = (_jsx(RenderedMarkdown, { markdown: block.markdown, target: blockAnnotationTarget }));
|
|
85
|
+
if (component === "h2") {
|
|
86
|
+
return _jsx("h2", { ...props, children: children });
|
|
87
|
+
}
|
|
88
|
+
if (component === "blockquote") {
|
|
89
|
+
return _jsx("blockquote", { ...props, children: children });
|
|
90
|
+
}
|
|
91
|
+
return _jsx("p", { ...props, children: children });
|
|
92
|
+
}
|
|
93
|
+
function getRenderedImageAlignment(value) {
|
|
94
|
+
return value === "left" || value === "right" ? value : "center";
|
|
95
|
+
}
|
|
96
|
+
function getRenderedImageDisplaySize(value) {
|
|
97
|
+
return value === "small" ||
|
|
98
|
+
value === "medium" ||
|
|
99
|
+
value === "full" ||
|
|
100
|
+
value === "custom"
|
|
101
|
+
? value
|
|
102
|
+
: null;
|
|
103
|
+
}
|
|
104
|
+
function getRenderedImageCustomWidthStyle(displaySize, customWidth) {
|
|
105
|
+
if (displaySize !== "custom" ||
|
|
106
|
+
typeof customWidth !== "number" ||
|
|
107
|
+
!Number.isFinite(customWidth)) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const width = Math.min(Math.max(Math.round(customWidth), 120), 1600);
|
|
111
|
+
return {
|
|
112
|
+
"--bayon-rte-image-custom-width": `${width}px`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function NestedRichTextBlocks({ activeAnnotationTarget, blocks, onToggleCollapsedChange, renderToolBlock, }) {
|
|
116
|
+
if (blocks.length === 0) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
return (_jsx(RichTextRenderedBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: blocks, onToggleCollapsedChange: onToggleCollapsedChange, renderToolBlock: renderToolBlock }));
|
|
120
|
+
}
|
|
121
|
+
function getActiveCommentTargetAttributes(block, target) {
|
|
122
|
+
const isActive = Boolean(target?.blockId && target.blockId === block.id);
|
|
123
|
+
return {
|
|
124
|
+
"data-rich-text-block-id": block.id,
|
|
125
|
+
...(isActive ? { "data-rich-text-comment-target": "active" } : {}),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function RenderedMarkdown({ markdown, target, }) {
|
|
129
|
+
const quote = target?.quote?.trim();
|
|
130
|
+
if (!quote) {
|
|
131
|
+
return (_jsx("span", { dangerouslySetInnerHTML: {
|
|
132
|
+
__html: markdownToEditorHtml(markdown) || " ",
|
|
133
|
+
} }));
|
|
134
|
+
}
|
|
135
|
+
const quoteIndex = markdown.indexOf(quote);
|
|
136
|
+
if (quoteIndex < 0) {
|
|
137
|
+
return (_jsx("span", { dangerouslySetInnerHTML: {
|
|
138
|
+
__html: markdownToEditorHtml(markdown) || " ",
|
|
139
|
+
} }));
|
|
140
|
+
}
|
|
141
|
+
const before = markdown.slice(0, quoteIndex);
|
|
142
|
+
const highlighted = markdown.slice(quoteIndex, quoteIndex + quote.length);
|
|
143
|
+
const after = markdown.slice(quoteIndex + quote.length);
|
|
144
|
+
return (_jsxs(_Fragment, { children: [before ? (_jsx("span", { dangerouslySetInnerHTML: { __html: markdownToEditorHtml(before) } })) : null, _jsx("mark", { className: "bayon-rte-comment-highlight", dangerouslySetInnerHTML: {
|
|
145
|
+
__html: markdownToEditorHtml(highlighted) || " ",
|
|
146
|
+
} }), after ? (_jsx("span", { dangerouslySetInnerHTML: { __html: markdownToEditorHtml(after) } })) : null] }));
|
|
147
|
+
}
|
|
148
|
+
function DefaultToolBlock({ block, }) {
|
|
149
|
+
const label = block.title || block.toolType;
|
|
150
|
+
return (_jsxs("section", { "data-rich-text-tool": "", "data-tool-status": block.status, "data-tool-type": block.toolType, children: [_jsxs("div", { "data-tool-header": "", children: [_jsx("span", { "data-tool-title": "", children: label }), _jsx("span", { "data-tool-status-label": "", children: block.status })] }), block.markdown ? (_jsx("p", { "data-tool-markdown": "", dangerouslySetInnerHTML: {
|
|
151
|
+
__html: markdownToEditorHtml(block.markdown),
|
|
152
|
+
} })) : null] }));
|
|
153
|
+
}
|
|
154
|
+
function isTreeRenderedBlock(block) {
|
|
155
|
+
return (block?.type === "bullet" ||
|
|
156
|
+
block?.type === "ordered" ||
|
|
157
|
+
block?.type === "checkbox" ||
|
|
158
|
+
block?.type === "toggle");
|
|
159
|
+
}
|
|
160
|
+
function getRenderedTreeKind(block) {
|
|
161
|
+
return block?.type === "ordered" ? "ordered" : "unordered";
|
|
162
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type RichTextToolBlockRenderer } from "./RichTextRenderedBlock";
|
|
2
|
+
import type { RichTextBlock } from "../../core/types";
|
|
3
|
+
export type RichTextAnnotationTarget = {
|
|
4
|
+
blockId: string;
|
|
5
|
+
quote?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function RichTextRenderer({ activeAnnotationTarget, contentBlocks, onContentBlocksChange, renderToolBlock, }: {
|
|
8
|
+
activeAnnotationTarget?: RichTextAnnotationTarget | null;
|
|
9
|
+
contentBlocks: RichTextBlock[];
|
|
10
|
+
onContentBlocksChange?: (contentBlocks: RichTextBlock[]) => void;
|
|
11
|
+
renderToolBlock?: RichTextToolBlockRenderer;
|
|
12
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function getRichTextBlocksWithRenderedToggleCollapsed(blocks: RichTextBlock[], blockId: string, collapsed: boolean): RichTextBlock[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { RichTextRenderedBlocks, } from "./RichTextRenderedBlock.js";
|
|
3
|
+
import { setToggleCollapsed } from "../editor/blockActions.js";
|
|
4
|
+
import { sanitizeRichTextBlocks } from "../../core/richText.js";
|
|
5
|
+
import { RichTextStyleScope } from "../styles/RichTextStyles.js";
|
|
6
|
+
// Renders a sanitized collection of rich-text blocks for read-only views.
|
|
7
|
+
export function RichTextRenderer({ activeAnnotationTarget, contentBlocks, onContentBlocksChange, renderToolBlock, }) {
|
|
8
|
+
const sanitizedContentBlocks = sanitizeRichTextBlocks(contentBlocks);
|
|
9
|
+
function handleToggleCollapsedChange(blockId, collapsed) {
|
|
10
|
+
onContentBlocksChange?.(getRichTextBlocksWithRenderedToggleCollapsed(sanitizedContentBlocks, blockId, collapsed));
|
|
11
|
+
}
|
|
12
|
+
return (_jsxs(_Fragment, { children: [_jsx(RichTextStyleScope, {}), _jsx("div", { className: "bayon-rte-renderer", children: _jsx(RichTextRenderedBlocks, { activeAnnotationTarget: activeAnnotationTarget, blocks: sanitizedContentBlocks, onToggleCollapsedChange: onContentBlocksChange ? handleToggleCollapsedChange : undefined, renderToolBlock: renderToolBlock }) })] }));
|
|
13
|
+
}
|
|
14
|
+
export function getRichTextBlocksWithRenderedToggleCollapsed(blocks, blockId, collapsed) {
|
|
15
|
+
return setToggleCollapsed(sanitizeRichTextBlocks(blocks), blockId, collapsed);
|
|
16
|
+
}
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import { type RefObject } from "react";
|
|
2
|
+
import { type EditorHistoryShortcutCommand } from "./editorNavigation";
|
|
2
3
|
type RichTextTitleInputProps = {
|
|
3
4
|
disabled: boolean;
|
|
4
5
|
inputRef: RefObject<HTMLTextAreaElement | null>;
|
|
5
6
|
label: string;
|
|
6
7
|
onArrowDown: () => void;
|
|
7
8
|
onChange: (value: string) => void;
|
|
9
|
+
onRedo?: () => boolean;
|
|
8
10
|
required: boolean;
|
|
9
11
|
title: string;
|
|
12
|
+
onUndo?: () => boolean;
|
|
10
13
|
validationMessage?: string;
|
|
11
14
|
};
|
|
12
15
|
type TitleKeyCommand = "focus-body-start";
|
|
13
|
-
export declare function RichTextTitleInput({ disabled, inputRef, label, onArrowDown, onChange, required, title, validationMessage, }: RichTextTitleInputProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare function RichTextTitleInput({ disabled, inputRef, label, onArrowDown, onChange, onRedo, required, title, onUndo, validationMessage, }: RichTextTitleInputProps): import("react/jsx-runtime").JSX.Element;
|
|
14
17
|
export declare function getTitleKeyCommand(event: {
|
|
15
18
|
key: string;
|
|
16
19
|
}): TitleKeyCommand | null;
|
|
20
|
+
export declare function getTitleHistoryCommand(event: {
|
|
21
|
+
altKey?: boolean;
|
|
22
|
+
ctrlKey?: boolean;
|
|
23
|
+
key: string;
|
|
24
|
+
metaKey?: boolean;
|
|
25
|
+
shiftKey?: boolean;
|
|
26
|
+
}): EditorHistoryShortcutCommand | null;
|
|
17
27
|
export declare function RichTextReadTitle({ title }: {
|
|
18
28
|
title: string;
|
|
19
29
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useId, useRef } from "react";
|
|
4
|
-
import { RichTextStyleScope } from "
|
|
4
|
+
import { RichTextStyleScope } from "../styles/RichTextStyles.js";
|
|
5
|
+
import { getEditorHistoryShortcut, } from "./editorNavigation.js";
|
|
5
6
|
// Renders the title field and handles keyboard movement into the editor body.
|
|
6
|
-
export function RichTextTitleInput({ disabled, inputRef, label, onArrowDown, onChange, required, title, validationMessage = "", }) {
|
|
7
|
+
export function RichTextTitleInput({ disabled, inputRef, label, onArrowDown, onChange, onRedo, required, title, onUndo, validationMessage = "", }) {
|
|
7
8
|
const validationMessageId = useId();
|
|
8
9
|
useEffect(() => {
|
|
9
10
|
resizeTitleTextArea(inputRef.current);
|
|
@@ -12,6 +13,17 @@ export function RichTextTitleInput({ disabled, inputRef, label, onArrowDown, onC
|
|
|
12
13
|
resizeTitleTextArea(event.currentTarget);
|
|
13
14
|
onChange(event.target.value);
|
|
14
15
|
}, onInput: (event) => resizeTitleTextArea(event.currentTarget), onKeyDown: (event) => {
|
|
16
|
+
const historyCommand = getTitleHistoryCommand(event);
|
|
17
|
+
if (historyCommand === "undo") {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
onUndo?.();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (historyCommand === "redo") {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
onRedo?.();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
15
27
|
if (getTitleKeyCommand(event) === "focus-body-start") {
|
|
16
28
|
event.preventDefault();
|
|
17
29
|
onArrowDown();
|
|
@@ -23,6 +35,9 @@ export function getTitleKeyCommand(event) {
|
|
|
23
35
|
? "focus-body-start"
|
|
24
36
|
: null;
|
|
25
37
|
}
|
|
38
|
+
export function getTitleHistoryCommand(event) {
|
|
39
|
+
return getEditorHistoryShortcut(event);
|
|
40
|
+
}
|
|
26
41
|
export function RichTextReadTitle({ title }) {
|
|
27
42
|
const titleRef = useRef(null);
|
|
28
43
|
useEffect(() => {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type NestableRichTextBlock } from "../../core/blockTypes";
|
|
2
|
+
import type { RichTextBlock } from "../../core/types";
|
|
3
|
+
export type BlockDropPlacement = "before" | "after" | "inside";
|
|
4
|
+
export declare function isBlockActionTarget(_block: RichTextBlock): boolean;
|
|
5
|
+
export declare function reorderBlock(blocks: RichTextBlock[], draggedBlockId: string, targetBlockId: string, placement?: BlockDropPlacement): RichTextBlock[];
|
|
6
|
+
export declare function deleteBlockById(blocks: RichTextBlock[], blockId: string): RichTextBlock[];
|
|
7
|
+
export declare function indentBlock(blocks: RichTextBlock[], blockId: string): RichTextBlock[];
|
|
8
|
+
export declare function outdentBlock(blocks: RichTextBlock[], blockId: string): RichTextBlock[];
|
|
9
|
+
export declare function setToggleCollapsed(blocks: RichTextBlock[], blockId: string, collapsed: boolean): RichTextBlock[];
|
|
10
|
+
export declare function splitTreeRowBlock(blocks: RichTextBlock[], blockId: string, split: {
|
|
11
|
+
afterMarkdown: string;
|
|
12
|
+
beforeMarkdown: string;
|
|
13
|
+
nextBlockId: string;
|
|
14
|
+
}): RichTextBlock[];
|
|
15
|
+
export declare function splitTextBlock(blocks: RichTextBlock[], blockId: string, split: {
|
|
16
|
+
afterMarkdown: string;
|
|
17
|
+
beforeMarkdown: string;
|
|
18
|
+
nextBlockId: string;
|
|
19
|
+
}): RichTextBlock[];
|
|
20
|
+
export declare function insertBlocksAfterBlock(blocks: RichTextBlock[], blockId: string, insertedBlocks: RichTextBlock[]): RichTextBlock[];
|
|
21
|
+
export declare function replaceBlockWithBlocks(blocks: RichTextBlock[], blockId: string, replacementBlocks: RichTextBlock[]): RichTextBlock[];
|
|
22
|
+
export declare function insertBlocksInsideBlock(blocks: RichTextBlock[], blockId: string, insertedBlocks: RichTextBlock[]): RichTextBlock[];
|
|
23
|
+
export declare function getBlockActionBlocks(blocks: RichTextBlock[], blockId: string): RichTextBlock[];
|
|
24
|
+
export declare function convertCheckboxBlockToParagraph(blocks: RichTextBlock[], blockId: string): RichTextBlock[];
|
|
25
|
+
type TreeRowParagraphMarkdown = string | ((block: NestableRichTextBlock) => string);
|
|
26
|
+
export declare function convertTreeRowBlockToParagraph(blocks: RichTextBlock[], blockId: string, markdown: TreeRowParagraphMarkdown, options?: {
|
|
27
|
+
convertNonEmpty?: boolean;
|
|
28
|
+
}): RichTextBlock[];
|
|
29
|
+
export declare function blockToClipboardText(block: RichTextBlock): string;
|
|
30
|
+
export declare function blockActionToClipboardText(blocks: RichTextBlock[], blockId: string): string;
|
|
31
|
+
export declare function getBlockDeletionFocusTarget(blocks: RichTextBlock[], blockId: string): {
|
|
32
|
+
blockId: string;
|
|
33
|
+
position: "end";
|
|
34
|
+
} | {
|
|
35
|
+
blockId: string;
|
|
36
|
+
position: "start";
|
|
37
|
+
} | undefined;
|
|
38
|
+
export declare function getForwardDeleteFocusTarget(blocks: RichTextBlock[], blockId: string): {
|
|
39
|
+
blockId: string;
|
|
40
|
+
position: "start";
|
|
41
|
+
} | undefined;
|
|
42
|
+
export declare function getToggleContentBackspaceDeletionFocusTarget(blocks: RichTextBlock[], blockId: string): {
|
|
43
|
+
blockId: string;
|
|
44
|
+
position: "end";
|
|
45
|
+
} | undefined;
|
|
46
|
+
export declare function isFirstToggleContentBlock(blocks: RichTextBlock[], blockId: string): boolean;
|
|
47
|
+
export declare function isRootBlockAfterToggle(blocks: RichTextBlock[], blockId: string): boolean;
|
|
48
|
+
export {};
|