@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,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.RichTextBody = RichTextBody;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const editorNavigation_1 = require("./editorNavigation");
|
|
7
|
+
// Renders the editable rich-text body and reports input and selection changes.
|
|
8
|
+
function RichTextBody({ bodyRef, disabled, label, onBackspace, onDelete, onEnter, onFocus, onImageAlignChange, onImageCustomWidthChange, onImageSizeChange, onInput, onPasteText, onRedo, onSelectionChange, onShortcutCommand, onTab, onToggleCollapse, onUndo, }) {
|
|
9
|
+
return ((0, jsx_runtime_1.jsx)("div", { "aria-label": label, className: "bayon-rte-body", contentEditable: !disabled, "data-placeholder": "Tell your story...", dir: "auto", onBlur: onSelectionChange, onClick: (event) => {
|
|
10
|
+
const imageAlignButton = event.target instanceof Element
|
|
11
|
+
? event.target.closest("[data-image-align-action]")
|
|
12
|
+
: null;
|
|
13
|
+
if (imageAlignButton instanceof HTMLElement) {
|
|
14
|
+
const alignment = imageAlignButton.getAttribute("data-image-align-action");
|
|
15
|
+
const blockId = imageAlignButton
|
|
16
|
+
.closest("[data-block-id]")
|
|
17
|
+
?.getAttribute("data-block-id");
|
|
18
|
+
if (blockId &&
|
|
19
|
+
(alignment === "left" ||
|
|
20
|
+
alignment === "center" ||
|
|
21
|
+
alignment === "right")) {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
onImageAlignChange(blockId, alignment);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const imageSizeButton = event.target instanceof Element
|
|
28
|
+
? event.target.closest("[data-image-size-action]")
|
|
29
|
+
: null;
|
|
30
|
+
if (imageSizeButton instanceof HTMLElement) {
|
|
31
|
+
const displaySize = imageSizeButton.getAttribute("data-image-size-action");
|
|
32
|
+
const blockId = imageSizeButton
|
|
33
|
+
.closest("[data-block-id]")
|
|
34
|
+
?.getAttribute("data-block-id");
|
|
35
|
+
if (blockId &&
|
|
36
|
+
(displaySize === "small" ||
|
|
37
|
+
displaySize === "medium" ||
|
|
38
|
+
displaySize === "full" ||
|
|
39
|
+
displaySize === "custom")) {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
onImageSizeChange(blockId, displaySize);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const toggleButton = event.target instanceof Element
|
|
46
|
+
? event.target.closest("[data-toggle-collapse]")
|
|
47
|
+
: null;
|
|
48
|
+
if (toggleButton instanceof HTMLElement) {
|
|
49
|
+
const blockId = toggleButton
|
|
50
|
+
.closest("[data-block-id]")
|
|
51
|
+
?.getAttribute("data-block-id");
|
|
52
|
+
if (blockId) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
onToggleCollapse(blockId);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (event.target instanceof HTMLInputElement &&
|
|
59
|
+
event.target.type === "checkbox") {
|
|
60
|
+
onInput();
|
|
61
|
+
}
|
|
62
|
+
}, onFocus: onFocus, onInput: (event) => {
|
|
63
|
+
if (event.target instanceof HTMLInputElement &&
|
|
64
|
+
event.target.hasAttribute("data-image-custom-width-action")) {
|
|
65
|
+
const blockId = event.target
|
|
66
|
+
.closest("[data-block-id]")
|
|
67
|
+
?.getAttribute("data-block-id");
|
|
68
|
+
const width = Number(event.target.value);
|
|
69
|
+
if (blockId && Number.isFinite(width)) {
|
|
70
|
+
onImageCustomWidthChange(blockId, width);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
onInput();
|
|
75
|
+
}, onKeyDown: (event) => {
|
|
76
|
+
const historyShortcut = (0, editorNavigation_1.getEditorHistoryShortcut)(event);
|
|
77
|
+
if (historyShortcut === "undo") {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
onUndo();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (historyShortcut === "redo") {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
onRedo();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if ((0, editorNavigation_1.isSelectAllShortcut)(event)) {
|
|
88
|
+
const code = (0, editorNavigation_1.getCodeBlockSelectionTarget)(event.currentTarget, window.getSelection());
|
|
89
|
+
if (code) {
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
selectElementContents(code);
|
|
92
|
+
onSelectionChange();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (event.key === "Enter" && onEnter(event)) {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (event.key === "Backspace" && onBackspace()) {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (event.key === "Delete" && onDelete()) {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (event.key === "Tab" && onTab(event)) {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const shortcutCommand = (0, editorNavigation_1.getEditorKeyboardShortcut)(event);
|
|
113
|
+
if (shortcutCommand) {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
onShortcutCommand(shortcutCommand);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}, onKeyUp: onSelectionChange, onMouseUp: onSelectionChange, onPaste: (event) => {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
const text = event.clipboardData.getData("text/plain");
|
|
121
|
+
if (onPasteText(text)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
document.execCommand("insertText", false, text);
|
|
125
|
+
onInput();
|
|
126
|
+
}, ref: bodyRef, role: "textbox", suppressContentEditableWarning: true, tabIndex: disabled ? -1 : 0 }));
|
|
127
|
+
}
|
|
128
|
+
function selectElementContents(element) {
|
|
129
|
+
const range = document.createRange();
|
|
130
|
+
range.selectNodeContents(element);
|
|
131
|
+
const selection = window.getSelection();
|
|
132
|
+
selection?.removeAllRanges();
|
|
133
|
+
selection?.addRange(range);
|
|
134
|
+
}
|