@monolith-forensics/monolith-ui 1.8.1-dev.4 → 1.8.1
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/dist/Button/Button.js +58 -9
- package/dist/Calendar/Calendar.d.ts +2 -7
- package/dist/Calendar/Calendar.js +49 -226
- package/dist/Calendar/CalendarStyles.d.ts +2 -6
- package/dist/Calendar/CalendarStyles.js +33 -153
- package/dist/Calendar/calendarHelpers.d.ts +2 -6
- package/dist/Calendar/calendarHelpers.js +5 -13
- package/dist/Charts/BarChart/BarChart.js +28 -14
- package/dist/Charts/BarChart/BarChart.styled.d.ts +7 -2
- package/dist/Charts/BarChart/BarChart.styled.js +5 -1
- package/dist/Charts/BarChart/BarChart.types.d.ts +13 -5
- package/dist/Charts/ChartUtils/chartSizing.d.ts +20 -0
- package/dist/Charts/ChartUtils/chartSizing.js +83 -0
- package/dist/Charts/ChartUtils/index.d.ts +1 -0
- package/dist/Charts/ChartUtils/index.js +1 -0
- package/dist/Charts/HeatMap/HeatMap.js +28 -7
- package/dist/Charts/HeatMap/HeatMap.styled.d.ts +6 -2
- package/dist/Charts/HeatMap/HeatMap.styled.js +3 -0
- package/dist/Charts/HeatMap/HeatMap.types.d.ts +7 -1
- package/dist/Charts/LineChart/LineChart.js +34 -15
- package/dist/Charts/LineChart/LineChart.styled.d.ts +7 -2
- package/dist/Charts/LineChart/LineChart.styled.js +5 -1
- package/dist/Charts/LineChart/LineChart.types.d.ts +13 -5
- package/dist/Charts/PieChart/PieChart.js +48 -33
- package/dist/Charts/PieChart/PieChart.styled.d.ts +7 -2
- package/dist/Charts/PieChart/PieChart.styled.js +6 -1
- package/dist/Charts/PieChart/PieChart.types.d.ts +7 -3
- package/dist/CheckBox/CheckBox.js +19 -36
- package/dist/DateInput/DateInput.js +143 -198
- package/dist/DropDownMenu/DropDownMenu.js +15 -25
- package/dist/DropDownMenu/components/MenuComponent.js +2 -8
- package/dist/DropDownMenu/components/MenuItem.d.ts +0 -2
- package/dist/DropDownMenu/components/MenuItem.js +21 -25
- package/dist/DropDownMenu/components/MenuItemList.d.ts +0 -3
- package/dist/DropDownMenu/components/MenuItemList.js +86 -192
- package/dist/DropDownMenu/components/StyledContent.js +2 -1
- package/dist/DropDownMenu/components/StyledFloatContainer.js +1 -1
- package/dist/DropDownMenu/types.d.ts +0 -3
- package/dist/FieldLabel/FieldLabel.js +12 -4
- package/dist/FileInputField/FileInputField.js +23 -4
- package/dist/FileViewer/viewers/ImageViewer.js +18 -75
- package/dist/FormSection/FormSection.js +25 -5
- package/dist/IconButton/IconButton.js +16 -2
- package/dist/Input/Input.js +56 -7
- package/dist/MonolithUIProvider/MonolithUIProvider.d.ts +4 -1
- package/dist/Pill/Pill.js +79 -8
- package/dist/Popover/Popover.context.d.ts +1 -2
- package/dist/Popover/Popover.js +2 -5
- package/dist/Popover/Popover.styles.d.ts +6 -1
- package/dist/Popover/Popover.styles.js +28 -11
- package/dist/Popover/Popover.transitions.d.ts +2 -4
- package/dist/Popover/Popover.transitions.js +49 -23
- package/dist/Popover/PopoverDropdown.js +8 -6
- package/dist/Popover/PopoverTarget.js +3 -6
- package/dist/QueryFilter/DefaultOperators.d.ts +76 -0
- package/dist/QueryFilter/DefaultOperators.js +21 -0
- package/dist/QueryFilter/QueryFilter.d.ts +1 -1
- package/dist/QueryFilter/QueryFilter.js +303 -3
- package/dist/QueryFilter/index.d.ts +2 -3
- package/dist/QueryFilter/index.js +2 -3
- package/dist/QueryFilter/types.d.ts +52 -0
- package/dist/QueryFilter/types.js +1 -0
- package/dist/QueryFilter/useQueryFilter.d.ts +1 -1
- package/dist/QueryFilter/useQueryFilter.js +19 -23
- package/dist/RichTextEditor/Components/CodeBlockBaseButton.d.ts +18 -0
- package/dist/RichTextEditor/Components/CodeBlockBaseButton.js +6 -0
- package/dist/RichTextEditor/Components/CodeBlockCopyButton.d.ts +9 -0
- package/dist/RichTextEditor/Components/CodeBlockCopyButton.js +42 -0
- package/dist/RichTextEditor/Components/CodeBlockFormatButton.d.ts +10 -0
- package/dist/RichTextEditor/Components/CodeBlockFormatButton.js +60 -0
- package/dist/RichTextEditor/Components/CodeBlockLanguageSelect.d.ts +9 -0
- package/dist/RichTextEditor/Components/CodeBlockLanguageSelect.js +30 -0
- package/dist/RichTextEditor/Components/CodeBlockNodeView.d.ts +3 -0
- package/dist/RichTextEditor/Components/CodeBlockNodeView.js +28 -0
- package/dist/RichTextEditor/Components/CodeBlockWrapButton.d.ts +10 -0
- package/dist/RichTextEditor/Components/CodeBlockWrapButton.js +17 -0
- package/dist/RichTextEditor/Components/LinkEditor.d.ts +8 -0
- package/dist/RichTextEditor/Components/LinkEditor.js +94 -0
- package/dist/RichTextEditor/Components/TableTools/TableCornerMenu.d.ts +2 -0
- package/dist/RichTextEditor/Components/TableTools/TableCornerMenu.js +19 -0
- package/dist/RichTextEditor/Components/TableTools/TableInsertControls.d.ts +2 -0
- package/dist/RichTextEditor/Components/TableTools/TableInsertControls.js +24 -0
- package/dist/RichTextEditor/Components/TableTools/TableRails.d.ts +2 -0
- package/dist/RichTextEditor/Components/TableTools/TableRails.js +180 -0
- package/dist/RichTextEditor/Components/TableTools/TableToolMenu.d.ts +5 -0
- package/dist/RichTextEditor/Components/TableTools/TableToolMenu.js +6 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.actions.d.ts +5 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.actions.js +183 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.commands.d.ts +16 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.commands.js +217 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.constants.d.ts +8 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.constants.js +11 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.d.ts +3 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.geometry.d.ts +23 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.geometry.js +75 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.js +3 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.selectors.d.ts +16 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.selectors.js +53 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.styled.d.ts +40 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.styled.js +167 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.types.d.ts +76 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.types.js +1 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.utils.d.ts +4 -0
- package/dist/RichTextEditor/Components/TableTools/TableTools.utils.js +4 -0
- package/dist/RichTextEditor/Components/TableTools/TableToolsPopover.d.ts +2 -0
- package/dist/RichTextEditor/Components/TableTools/TableToolsPopover.js +12 -0
- package/dist/RichTextEditor/Components/TableTools/index.d.ts +3 -0
- package/dist/RichTextEditor/Components/TableTools/index.js +2 -0
- package/dist/RichTextEditor/Enums/HighlightColors.d.ts +9 -0
- package/dist/RichTextEditor/Enums/HighlightColors.js +10 -0
- package/dist/RichTextEditor/Extensions/getTiptapExtensions.js +15 -5
- package/dist/RichTextEditor/Plugins/ImageActionsPlugin.js +4 -7
- package/dist/RichTextEditor/Plugins/UploadImagesPlugin.d.ts +0 -15
- package/dist/RichTextEditor/Plugins/UploadImagesPlugin.js +51 -115
- package/dist/RichTextEditor/Plugins/index.d.ts +0 -1
- package/dist/RichTextEditor/Plugins/index.js +0 -1
- package/dist/RichTextEditor/RichTextEditor.d.ts +2 -3
- package/dist/RichTextEditor/RichTextEditor.js +35 -309
- package/dist/RichTextEditor/Toolbar/Toolbar.js +2 -14
- package/dist/RichTextEditor/Utils/codeBlockUtils.d.ts +20 -0
- package/dist/RichTextEditor/Utils/codeBlockUtils.js +137 -0
- package/dist/RichTextEditor/Utils/codeUtils.d.ts +3 -0
- package/dist/RichTextEditor/Utils/codeUtils.js +12 -0
- package/dist/RichTextEditor/Utils/linkUtils.d.ts +19 -0
- package/dist/RichTextEditor/Utils/linkUtils.js +57 -0
- package/dist/RichTextEditor/Utils/tableUtils.d.ts +1 -0
- package/dist/RichTextEditor/Utils/tableUtils.js +1 -0
- package/dist/SegmentedControl/SegmentedControl.utils.d.ts +2 -2
- package/dist/SegmentedControl/SegmentedControl.utils.js +30 -3
- package/dist/SelectBox/SelectBox.js +5 -5
- package/dist/SelectBox/select-box.styled-components.d.ts +1 -4
- package/dist/SelectBox/select-box.styled-components.js +48 -11
- package/dist/SelectBox/types.d.ts +0 -1
- package/dist/Switch/Switch.d.ts +2 -2
- package/dist/Switch/Switch.js +83 -18
- package/dist/Table/ColumnResizer.d.ts +9 -6
- package/dist/Table/ColumnResizer.js +10 -30
- package/dist/Table/StateStorage.d.ts +0 -4
- package/dist/Table/StateStorage.js +0 -13
- package/dist/Table/Table.js +12 -160
- package/dist/Table/TableComponents.d.ts +0 -10
- package/dist/Table/TableComponents.js +10 -71
- package/dist/Table/TableDefaults.d.ts +0 -7
- package/dist/Table/TableDefaults.js +0 -7
- package/dist/Table/TableHeader.js +16 -31
- package/dist/Table/TableMenu/TableMenu.js +1 -1
- package/dist/Table/TableProvider.js +75 -354
- package/dist/Table/TableRow.js +16 -28
- package/dist/Table/Utils/index.d.ts +1 -0
- package/dist/Table/Utils/index.js +1 -0
- package/dist/Table/Utils/resizeHandler.d.ts +3 -0
- package/dist/Table/Utils/resizeHandler.js +84 -0
- package/dist/Table/types.d.ts +19 -70
- package/dist/TagBox/TagBox.d.ts +1 -1
- package/dist/TagBox/TagBox.js +80 -22
- package/dist/TagBox/types.d.ts +0 -1
- package/dist/TextArea/TextArea.js +23 -9
- package/dist/TextInput/TextInput.js +6 -12
- package/dist/Utilities/parseTimestamp.js +6 -11
- package/dist/core/ArrowButton.d.ts +0 -2
- package/dist/core/ArrowButton.js +3 -7
- package/dist/core/ClearButton.d.ts +0 -2
- package/dist/core/ClearButton.js +3 -7
- package/dist/core/controlSizes.js +9 -9
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -2
- package/dist/theme/variants.js +8 -2
- package/package.json +18 -26
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
11
2
|
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
12
3
|
import { nanoid } from "nanoid";
|
|
@@ -14,51 +5,10 @@ import calculateFileHash from "../../Utilities/calculateFileHash";
|
|
|
14
5
|
const uploadKey = new PluginKey("upload-image");
|
|
15
6
|
function findPlaceholder(state, id) {
|
|
16
7
|
const decos = uploadKey.getState(state);
|
|
17
|
-
if (!decos)
|
|
18
|
-
return null;
|
|
19
8
|
const found = decos.find(null, null, (spec) => spec.id === id);
|
|
20
9
|
return found.length ? found[0].from : null;
|
|
21
10
|
}
|
|
22
|
-
const readFileAsDataUrl = (file) => {
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
const reader = new FileReader();
|
|
25
|
-
reader.addEventListener("load", () => {
|
|
26
|
-
resolve(reader.result);
|
|
27
|
-
});
|
|
28
|
-
reader.addEventListener("error", () => {
|
|
29
|
-
reject(reader.error || new Error("Unable to read image file."));
|
|
30
|
-
});
|
|
31
|
-
reader.addEventListener("abort", () => {
|
|
32
|
-
reject(new Error("Image file read was aborted."));
|
|
33
|
-
});
|
|
34
|
-
reader.readAsDataURL(file);
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
export const addImagePlaceholder = ({ view, id, pos, src, label = "Processing image...", }) => {
|
|
38
|
-
if (!uploadKey.getState(view.state))
|
|
39
|
-
return;
|
|
40
|
-
view.dispatch(view.state.tr.setMeta(uploadKey, {
|
|
41
|
-
add: {
|
|
42
|
-
id,
|
|
43
|
-
pos,
|
|
44
|
-
src,
|
|
45
|
-
label,
|
|
46
|
-
},
|
|
47
|
-
}));
|
|
48
|
-
};
|
|
49
|
-
export const removeImagePlaceholder = (view, id) => {
|
|
50
|
-
if (!uploadKey.getState(view.state))
|
|
51
|
-
return;
|
|
52
|
-
const position = findPlaceholder(view.state, id);
|
|
53
|
-
view.dispatch(view.state.tr.setMeta(uploadKey, { remove: { id } }));
|
|
54
|
-
return position;
|
|
55
|
-
};
|
|
56
11
|
export const startImageUpload = (file, view, pos, handleImageUpload) => {
|
|
57
|
-
if (!handleImageUpload ||
|
|
58
|
-
!view.state.schema.nodes.image ||
|
|
59
|
-
!uploadKey.getState(view.state)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
12
|
// check if the file is an image
|
|
63
13
|
if (!file.type.includes("image/")) {
|
|
64
14
|
alert("File type not supported.");
|
|
@@ -72,61 +22,59 @@ export const startImageUpload = (file, view, pos, handleImageUpload) => {
|
|
|
72
22
|
// A fresh object to act as the ID for this upload
|
|
73
23
|
const id = nanoid(25);
|
|
74
24
|
// Replace the selection with a placeholder
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
transaction.setMeta(uploadKey, {
|
|
84
|
-
add: {
|
|
85
|
-
id,
|
|
86
|
-
pos,
|
|
87
|
-
src: previewSrc,
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
view.dispatch(transaction);
|
|
91
|
-
placeholderAdded = true;
|
|
92
|
-
const hashes = yield calculateFileHash(file);
|
|
93
|
-
const src = yield handleImageUpload({
|
|
94
|
-
file,
|
|
95
|
-
name: `${id}.png`,
|
|
25
|
+
const tr = view.state.tr;
|
|
26
|
+
if (!tr.selection.empty)
|
|
27
|
+
tr.deleteSelection();
|
|
28
|
+
const reader = new FileReader();
|
|
29
|
+
reader.readAsDataURL(file);
|
|
30
|
+
reader.onload = () => {
|
|
31
|
+
tr.setMeta(uploadKey, {
|
|
32
|
+
add: {
|
|
96
33
|
id,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
34
|
+
pos,
|
|
35
|
+
src: reader.result,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
view.dispatch(tr);
|
|
39
|
+
};
|
|
40
|
+
calculateFileHash(file).then((hashes) => {
|
|
41
|
+
var _a;
|
|
42
|
+
const md5 = hashes.md5Hash;
|
|
43
|
+
const sha1 = hashes.sha1Hash;
|
|
44
|
+
const sha256 = hashes.sha256Hash;
|
|
45
|
+
(_a = handleImageUpload === null || handleImageUpload === void 0 ? void 0 : handleImageUpload({
|
|
46
|
+
file,
|
|
47
|
+
name: `${id}.png`,
|
|
48
|
+
id,
|
|
49
|
+
md5,
|
|
50
|
+
sha1,
|
|
51
|
+
sha256,
|
|
52
|
+
})) === null || _a === void 0 ? void 0 : _a.then((src) => {
|
|
53
|
+
if (!src)
|
|
108
54
|
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
55
|
+
const { schema } = view.state;
|
|
56
|
+
let pos = findPlaceholder(view.state, id);
|
|
57
|
+
// If the content around the placeholder has been deleted, drop
|
|
58
|
+
// the image
|
|
59
|
+
if (pos == null)
|
|
60
|
+
return;
|
|
61
|
+
// Otherwise, insert it at the placeholder's position, and remove
|
|
62
|
+
// the placeholder
|
|
63
|
+
// When BLOB_READ_WRITE_TOKEN is not valid or unavailable, read
|
|
64
|
+
// the image locally
|
|
65
|
+
const imageSrc = typeof src === "object" ? reader.result : src;
|
|
66
|
+
const node = schema.nodes.image.create({
|
|
113
67
|
src: imageSrc,
|
|
114
68
|
alt: `${id}.png`,
|
|
115
69
|
"data-uuid": id,
|
|
116
70
|
title: `Filename: ${id}.png`,
|
|
117
71
|
});
|
|
118
|
-
const
|
|
119
|
-
.replaceWith(
|
|
72
|
+
const transaction = view.state.tr
|
|
73
|
+
.replaceWith(pos, pos, node)
|
|
120
74
|
.setMeta(uploadKey, { remove: { id } });
|
|
121
|
-
view.dispatch(
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (placeholderAdded) {
|
|
125
|
-
removeImagePlaceholder(view, id);
|
|
126
|
-
}
|
|
127
|
-
console.error("Image upload failed.", error);
|
|
128
|
-
}
|
|
129
|
-
}))();
|
|
75
|
+
view.dispatch(transaction);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
130
78
|
};
|
|
131
79
|
export const UploadImagesPlugin = () => new Plugin({
|
|
132
80
|
key: uploadKey,
|
|
@@ -139,25 +87,13 @@ export const UploadImagesPlugin = () => new Plugin({
|
|
|
139
87
|
// See if the transaction adds or removes any placeholders
|
|
140
88
|
const action = tr.getMeta(this);
|
|
141
89
|
if (action && action.add) {
|
|
142
|
-
const { id, pos, src
|
|
90
|
+
const { id, pos, src } = action.add;
|
|
143
91
|
const placeholder = document.createElement("div");
|
|
144
|
-
placeholder.setAttribute("class",
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
placeholder.appendChild(image);
|
|
150
|
-
const text = document.createElement("span");
|
|
151
|
-
text.setAttribute("class", "img-placeholder-label");
|
|
152
|
-
text.textContent = label || "Uploading image...";
|
|
153
|
-
placeholder.appendChild(text);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
const text = document.createElement("span");
|
|
157
|
-
text.setAttribute("class", "img-placeholder-label");
|
|
158
|
-
text.textContent = label;
|
|
159
|
-
placeholder.appendChild(text);
|
|
160
|
-
}
|
|
92
|
+
placeholder.setAttribute("class", "img-placeholder");
|
|
93
|
+
const image = document.createElement("img");
|
|
94
|
+
image.setAttribute("class", "monolith-image uploading");
|
|
95
|
+
image.src = src;
|
|
96
|
+
placeholder.appendChild(image);
|
|
161
97
|
const deco = Decoration.widget(pos + 1, placeholder, {
|
|
162
98
|
id,
|
|
163
99
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Editor } from "@tiptap/react";
|
|
2
2
|
import { ExtensionType } from "./Extensions/getTiptapExtensions";
|
|
3
|
-
import {
|
|
3
|
+
import { HandleImageUpload } from "./Plugins/UploadImagesPlugin";
|
|
4
4
|
import { BubbleMenuOptions } from "./Extensions/BubbleMenuExtension";
|
|
5
5
|
import { ToolbarOptions } from "./Toolbar/Toolbar";
|
|
6
6
|
type RichTextEditorProps = {
|
|
7
7
|
className?: string;
|
|
8
|
-
editorInstanceRef?: React.RefObject<Editor
|
|
8
|
+
editorInstanceRef?: React.RefObject<Editor>;
|
|
9
9
|
extensions?: ExtensionType[];
|
|
10
10
|
slashCommands?: any[];
|
|
11
11
|
defaultValue?: string;
|
|
@@ -17,7 +17,6 @@ type RichTextEditorProps = {
|
|
|
17
17
|
saving?: boolean;
|
|
18
18
|
onChange?: (value: string) => void;
|
|
19
19
|
handleImageUpload?: HandleImageUpload;
|
|
20
|
-
handleImageUrlUpload?: HandleImageUrlUpload;
|
|
21
20
|
bubbleMenuOptions?: BubbleMenuOptions;
|
|
22
21
|
toolbarOptions?: ToolbarOptions;
|
|
23
22
|
autoFocus?: boolean;
|
|
@@ -1,226 +1,14 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { useEffect,
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
12
3
|
import styled from "styled-components";
|
|
13
4
|
import { EditorContent, useEditor } from "@tiptap/react";
|
|
14
|
-
import { DOMParser as ProseMirrorDOMParser } from "@tiptap/pm/model";
|
|
15
5
|
import { Toolbar } from "./Toolbar";
|
|
16
6
|
import getTipTapExtensions from "./Extensions/getTiptapExtensions";
|
|
17
|
-
import { Extensions
|
|
18
|
-
import {
|
|
7
|
+
import { Extensions } from "./Enums";
|
|
8
|
+
import { startImageUpload, } from "./Plugins/UploadImagesPlugin";
|
|
19
9
|
import SaveBadge from "./Components/SaveBadge";
|
|
20
10
|
import Fonts from "./Enums/Fonts";
|
|
21
11
|
import RichTextEditorContext from "./Contexts/RichTextEditorContext";
|
|
22
|
-
const getImageFilesFromClipboard = (clipboardData) => {
|
|
23
|
-
return Array.from(clipboardData.files).filter((file) => file.type.includes("image/"));
|
|
24
|
-
};
|
|
25
|
-
const getImageFilenameFromSource = (src, fallbackIndex, fallbackName) => {
|
|
26
|
-
if (fallbackName)
|
|
27
|
-
return fallbackName;
|
|
28
|
-
try {
|
|
29
|
-
const url = new URL(src);
|
|
30
|
-
const filename = url.pathname.split("/").filter(Boolean).pop();
|
|
31
|
-
if (filename)
|
|
32
|
-
return filename;
|
|
33
|
-
}
|
|
34
|
-
catch (_a) {
|
|
35
|
-
// Data URLs and blob URLs may not parse to useful filenames.
|
|
36
|
-
}
|
|
37
|
-
return `pasted-image-${fallbackIndex + 1}.png`;
|
|
38
|
-
};
|
|
39
|
-
const getMimeExtension = (mimeType) => {
|
|
40
|
-
var _a;
|
|
41
|
-
const subtype = (_a = mimeType.split("/")[1]) === null || _a === void 0 ? void 0 : _a.split(";")[0];
|
|
42
|
-
if (!subtype)
|
|
43
|
-
return "png";
|
|
44
|
-
if (subtype === "jpeg")
|
|
45
|
-
return "jpg";
|
|
46
|
-
if (subtype === "svg+xml")
|
|
47
|
-
return "svg";
|
|
48
|
-
return subtype;
|
|
49
|
-
};
|
|
50
|
-
const ensureImageFilenameExtension = (name, mimeType) => {
|
|
51
|
-
if (/\.[a-z0-9]+$/i.test(name))
|
|
52
|
-
return name;
|
|
53
|
-
return `${name}.${getMimeExtension(mimeType)}`;
|
|
54
|
-
};
|
|
55
|
-
const createHtmlImageMarker = (index) => {
|
|
56
|
-
return `monolith-image-marker-${Date.now()}-${index}-${Math.random()
|
|
57
|
-
.toString(36)
|
|
58
|
-
.slice(2)}`;
|
|
59
|
-
};
|
|
60
|
-
const getHtmlImageSources = (html) => {
|
|
61
|
-
const document = new DOMParser().parseFromString(html, "text/html");
|
|
62
|
-
const imageSources = [];
|
|
63
|
-
Array.from(document.body.querySelectorAll("img[src]")).forEach((image, index) => {
|
|
64
|
-
const src = image.getAttribute("src");
|
|
65
|
-
if (!src)
|
|
66
|
-
return;
|
|
67
|
-
const marker = createHtmlImageMarker(index);
|
|
68
|
-
imageSources.push({
|
|
69
|
-
src,
|
|
70
|
-
name: getImageFilenameFromSource(src, index, image.getAttribute("title") || image.getAttribute("alt")),
|
|
71
|
-
marker,
|
|
72
|
-
placeholderId: marker,
|
|
73
|
-
});
|
|
74
|
-
image.replaceWith(document.createTextNode(marker));
|
|
75
|
-
});
|
|
76
|
-
return {
|
|
77
|
-
imageSources,
|
|
78
|
-
htmlWithImageMarkers: document.body.innerHTML,
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
const htmlHasContent = (html) => {
|
|
82
|
-
var _a;
|
|
83
|
-
const document = new DOMParser().parseFromString(html, "text/html");
|
|
84
|
-
return Boolean(((_a = document.body.textContent) === null || _a === void 0 ? void 0 : _a.trim()) ||
|
|
85
|
-
document.body.querySelector("table, ul, ol, blockquote, pre, code, hr, iframe, video, audio"));
|
|
86
|
-
};
|
|
87
|
-
const insertHtmlAtSelection = (view, html) => {
|
|
88
|
-
const container = window.document.createElement("div");
|
|
89
|
-
container.innerHTML = html;
|
|
90
|
-
const slice = ProseMirrorDOMParser.fromSchema(view.state.schema).parseSlice(container);
|
|
91
|
-
view.dispatch(view.state.tr.replaceSelection(slice).scrollIntoView());
|
|
92
|
-
};
|
|
93
|
-
const createImageFileFromSource = (imageSource, index) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
-
var _a;
|
|
95
|
-
const response = yield fetch(imageSource.src);
|
|
96
|
-
if (!response.ok) {
|
|
97
|
-
throw new Error(`Unable to fetch pasted image: ${imageSource.src}`);
|
|
98
|
-
}
|
|
99
|
-
const blob = yield response.blob();
|
|
100
|
-
const type = blob.type ||
|
|
101
|
-
((_a = imageSource.src.match(/^data:(image\/[^;,]+)/)) === null || _a === void 0 ? void 0 : _a[1]) ||
|
|
102
|
-
"image/png";
|
|
103
|
-
return new File([blob], ensureImageFilenameExtension(imageSource.name || `pasted-image-${index + 1}`, type), { type });
|
|
104
|
-
});
|
|
105
|
-
const findTextRange = (view, text) => {
|
|
106
|
-
let range;
|
|
107
|
-
view.state.doc.descendants((node, position) => {
|
|
108
|
-
if (range)
|
|
109
|
-
return false;
|
|
110
|
-
if (!node.isText || !node.text)
|
|
111
|
-
return;
|
|
112
|
-
const index = node.text.indexOf(text);
|
|
113
|
-
if (index === -1)
|
|
114
|
-
return;
|
|
115
|
-
range = {
|
|
116
|
-
from: position + index,
|
|
117
|
-
to: position + index + text.length,
|
|
118
|
-
};
|
|
119
|
-
return false;
|
|
120
|
-
});
|
|
121
|
-
return range;
|
|
122
|
-
};
|
|
123
|
-
const removeImageMarker = (view, marker) => {
|
|
124
|
-
const range = findTextRange(view, marker);
|
|
125
|
-
if (!range)
|
|
126
|
-
return;
|
|
127
|
-
view.dispatch(view.state.tr.delete(range.from, range.to));
|
|
128
|
-
return range.from;
|
|
129
|
-
};
|
|
130
|
-
const getPlaceholderAddPosition = (position) => {
|
|
131
|
-
return Math.max(position - 1, 0);
|
|
132
|
-
};
|
|
133
|
-
const replaceImageMarkerWithPlaceholder = (view, imageSource) => {
|
|
134
|
-
const markerPosition = removeImageMarker(view, imageSource.marker);
|
|
135
|
-
if (markerPosition === undefined)
|
|
136
|
-
return;
|
|
137
|
-
addImagePlaceholder({
|
|
138
|
-
view,
|
|
139
|
-
id: imageSource.placeholderId,
|
|
140
|
-
pos: getPlaceholderAddPosition(markerPosition),
|
|
141
|
-
label: "Processing image...",
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
const replaceImagePlaceholder = (view, placeholderId, src, name) => {
|
|
145
|
-
var _a;
|
|
146
|
-
const position = removeImagePlaceholder(view, placeholderId);
|
|
147
|
-
const imageNode = (_a = view.state.schema.nodes.image) === null || _a === void 0 ? void 0 : _a.create({
|
|
148
|
-
src,
|
|
149
|
-
alt: name,
|
|
150
|
-
title: `Filename: ${name}`,
|
|
151
|
-
});
|
|
152
|
-
if (position == null || !imageNode)
|
|
153
|
-
return false;
|
|
154
|
-
view.dispatch(view.state.tr.replaceWith(position, position, imageNode).scrollIntoView());
|
|
155
|
-
return true;
|
|
156
|
-
};
|
|
157
|
-
const uploadImagesFromHtmlSources = (imageSources, view, handleImageUpload, handleImageUrlUpload) => {
|
|
158
|
-
imageSources.forEach((imageSource, index) => {
|
|
159
|
-
createImageFileFromSource(imageSource, index)
|
|
160
|
-
.then((file) => {
|
|
161
|
-
const uploadPosition = removeImagePlaceholder(view, imageSource.placeholderId);
|
|
162
|
-
if (uploadPosition == null)
|
|
163
|
-
return;
|
|
164
|
-
startImageUpload(file, view, getPlaceholderAddPosition(uploadPosition), handleImageUpload);
|
|
165
|
-
})
|
|
166
|
-
.catch((error) => __awaiter(void 0, void 0, void 0, function* () {
|
|
167
|
-
if (!handleImageUrlUpload) {
|
|
168
|
-
console.error("Unable to upload pasted HTML image.", error);
|
|
169
|
-
removeImagePlaceholder(view, imageSource.placeholderId);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
try {
|
|
173
|
-
const uploadedSrc = yield handleImageUrlUpload(imageSource);
|
|
174
|
-
if (uploadedSrc) {
|
|
175
|
-
replaceImagePlaceholder(view, imageSource.placeholderId, uploadedSrc, imageSource.name);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
removeImagePlaceholder(view, imageSource.placeholderId);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
catch (urlUploadError) {
|
|
182
|
-
console.error("Unable to upload pasted HTML image URL.", urlUploadError);
|
|
183
|
-
removeImagePlaceholder(view, imageSource.placeholderId);
|
|
184
|
-
}
|
|
185
|
-
}));
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
const handleImagePaste = (view, event, handleImageUpload, handleImageUrlUpload) => {
|
|
189
|
-
const { clipboardData } = event;
|
|
190
|
-
if (!clipboardData)
|
|
191
|
-
return false;
|
|
192
|
-
const imageFiles = getImageFilesFromClipboard(clipboardData);
|
|
193
|
-
const html = clipboardData.getData("text/html");
|
|
194
|
-
const { imageSources, htmlWithImageMarkers } = html
|
|
195
|
-
? getHtmlImageSources(html)
|
|
196
|
-
: { imageSources: [], htmlWithImageMarkers: "" };
|
|
197
|
-
if (!imageFiles.length && !imageSources.length)
|
|
198
|
-
return false;
|
|
199
|
-
event.preventDefault();
|
|
200
|
-
if (html && htmlHasContent(htmlWithImageMarkers)) {
|
|
201
|
-
insertHtmlAtSelection(view, htmlWithImageMarkers);
|
|
202
|
-
imageSources.forEach((imageSource) => {
|
|
203
|
-
replaceImageMarkerWithPlaceholder(view, imageSource);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
const uploadPosition = view.state.selection.from;
|
|
207
|
-
if (imageFiles.length) {
|
|
208
|
-
imageFiles.forEach((file, index) => {
|
|
209
|
-
var _a;
|
|
210
|
-
const placeholderId = (_a = imageSources[index]) === null || _a === void 0 ? void 0 : _a.placeholderId;
|
|
211
|
-
const markerPosition = placeholderId
|
|
212
|
-
? removeImagePlaceholder(view, placeholderId)
|
|
213
|
-
: undefined;
|
|
214
|
-
startImageUpload(file, view, markerPosition == null
|
|
215
|
-
? uploadPosition
|
|
216
|
-
: getPlaceholderAddPosition(markerPosition), handleImageUpload);
|
|
217
|
-
});
|
|
218
|
-
uploadImagesFromHtmlSources(imageSources.slice(imageFiles.length), view, handleImageUpload, handleImageUrlUpload);
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
uploadImagesFromHtmlSources(imageSources, view, handleImageUpload, handleImageUrlUpload);
|
|
222
|
-
return true;
|
|
223
|
-
};
|
|
224
12
|
const StyledContent = styled.div `
|
|
225
13
|
position: relative;
|
|
226
14
|
display: flex;
|
|
@@ -261,7 +49,6 @@ const StyledContent = styled.div `
|
|
|
261
49
|
}
|
|
262
50
|
|
|
263
51
|
.ProseMirror {
|
|
264
|
-
font-size: 14px;
|
|
265
52
|
font-weight: 400;
|
|
266
53
|
outline: none;
|
|
267
54
|
height: 100%;
|
|
@@ -294,34 +81,37 @@ const StyledContent = styled.div `
|
|
|
294
81
|
}
|
|
295
82
|
|
|
296
83
|
h1 {
|
|
297
|
-
font-size:
|
|
84
|
+
font-size: 1.5rem;
|
|
298
85
|
line-height: 2rem;
|
|
299
86
|
margin: 0;
|
|
300
87
|
}
|
|
301
88
|
h2 {
|
|
302
|
-
font-size:
|
|
89
|
+
font-size: 1.25rem;
|
|
303
90
|
line-height: 1.75rem;
|
|
304
91
|
margin: 0;
|
|
305
92
|
}
|
|
306
93
|
h3 {
|
|
307
|
-
font-size:
|
|
94
|
+
font-size: 1.125rem;
|
|
308
95
|
line-height: 1.75rem;
|
|
309
96
|
margin: 0;
|
|
310
97
|
}
|
|
311
98
|
h4 {
|
|
312
|
-
font-size:
|
|
99
|
+
font-size: 1rem;
|
|
313
100
|
line-height: 1.5rem;
|
|
314
101
|
margin: 0;
|
|
315
102
|
}
|
|
316
103
|
p {
|
|
317
104
|
margin: 0;
|
|
105
|
+
font-size: 0.8rem;
|
|
318
106
|
line-height: 1.5rem;
|
|
319
107
|
}
|
|
320
108
|
ul {
|
|
321
109
|
margin: 0;
|
|
110
|
+
font-size: 0.8rem;
|
|
322
111
|
}
|
|
323
112
|
ol {
|
|
324
113
|
margin: 0;
|
|
114
|
+
font-size: 0.8rem;
|
|
325
115
|
}
|
|
326
116
|
.editor-link {
|
|
327
117
|
color: ${({ theme }) => theme.palette.primary.main};
|
|
@@ -365,9 +155,6 @@ const StyledContent = styled.div `
|
|
|
365
155
|
.ProseMirror .img-placeholder {
|
|
366
156
|
position: relative;
|
|
367
157
|
width: fit-content;
|
|
368
|
-
display: inline-flex;
|
|
369
|
-
align-items: center;
|
|
370
|
-
justify-content: center;
|
|
371
158
|
|
|
372
159
|
&:before {
|
|
373
160
|
content: "";
|
|
@@ -390,58 +177,6 @@ const StyledContent = styled.div `
|
|
|
390
177
|
}
|
|
391
178
|
}
|
|
392
179
|
|
|
393
|
-
.ProseMirror .img-placeholder .img-placeholder-label {
|
|
394
|
-
position: absolute;
|
|
395
|
-
top: calc(50% + 1.75rem);
|
|
396
|
-
left: 50%;
|
|
397
|
-
transform: translateX(-50%);
|
|
398
|
-
width: max-content;
|
|
399
|
-
max-width: calc(100% - 1rem);
|
|
400
|
-
padding: 0.25rem 0.5rem;
|
|
401
|
-
border-radius: 6px;
|
|
402
|
-
background-color: ${({ theme }) => theme.palette.background.paper};
|
|
403
|
-
color: ${({ theme }) => theme.palette.text.secondary};
|
|
404
|
-
font-size: 0.75rem;
|
|
405
|
-
line-height: 1rem;
|
|
406
|
-
text-align: center;
|
|
407
|
-
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
.ProseMirror .img-placeholder.processing {
|
|
411
|
-
display: inline-flex;
|
|
412
|
-
align-items: center;
|
|
413
|
-
gap: 0.5rem;
|
|
414
|
-
width: auto;
|
|
415
|
-
min-height: 2rem;
|
|
416
|
-
padding: 0.35rem 0.65rem;
|
|
417
|
-
border: 1px dashed ${({ theme }) => theme.palette.divider};
|
|
418
|
-
border-radius: 6px;
|
|
419
|
-
background-color: ${({ theme }) => theme.palette.action.hover};
|
|
420
|
-
color: ${({ theme }) => theme.palette.text.secondary};
|
|
421
|
-
font-size: 0.75rem;
|
|
422
|
-
line-height: 1rem;
|
|
423
|
-
vertical-align: middle;
|
|
424
|
-
|
|
425
|
-
.img-placeholder-label {
|
|
426
|
-
position: static;
|
|
427
|
-
transform: none;
|
|
428
|
-
max-width: none;
|
|
429
|
-
padding: 0;
|
|
430
|
-
border-radius: 0;
|
|
431
|
-
background-color: transparent;
|
|
432
|
-
box-shadow: none;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
&:before {
|
|
436
|
-
position: static;
|
|
437
|
-
flex: 0 0 auto;
|
|
438
|
-
width: 0.875rem;
|
|
439
|
-
height: 0.875rem;
|
|
440
|
-
border-width: 2px;
|
|
441
|
-
transform: none;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
180
|
.floating-menu {
|
|
446
181
|
display: flex;
|
|
447
182
|
background-color: #0d0d0d10;
|
|
@@ -543,28 +278,18 @@ const StyledContent = styled.div `
|
|
|
543
278
|
margin: 0 0.125rem;
|
|
544
279
|
}
|
|
545
280
|
`;
|
|
546
|
-
export const RichTextEditor = ({ className, editorInstanceRef, defaultValue = "", value, readOnly = false, font, showToolbar = true, saving = false, extensions = [], slashCommands = [], bubbleMenuOptions, toolbarOptions, autoFocus, onChange, handleImageUpload,
|
|
547
|
-
const isControlled = value !== undefined;
|
|
548
|
-
const hasImageExtension = extensions.includes(Extensions.Image);
|
|
549
|
-
const hasSlashCommandExtension = extensions.includes(Extensions.SlashCommand);
|
|
550
|
-
const hasImageSlashCommand = hasSlashCommandExtension && slashCommands.includes(SlashCommands.Image);
|
|
551
|
-
const onChangeRef = useRef(onChange);
|
|
281
|
+
export const RichTextEditor = ({ className, editorInstanceRef, defaultValue = "", value = "", readOnly = false, font, showToolbar = true, saving = false, extensions = [], slashCommands = [], bubbleMenuOptions, toolbarOptions, autoFocus, onChange, handleImageUpload, style, }) => {
|
|
552
282
|
const [fontState, setFontState] = useState(font || Fonts.DEFAULT);
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
if (hasImageSlashCommand && !hasImageExtension) {
|
|
557
|
-
throw new Error("Extensions.Image is required when using the Image slash command.");
|
|
558
|
-
}
|
|
559
|
-
if (hasImageExtension || hasImageSlashCommand) {
|
|
283
|
+
// check if image extension is included
|
|
284
|
+
if (extensions === null || extensions === void 0 ? void 0 : extensions.includes(Extensions.Image)) {
|
|
285
|
+
// Ensure that handleImageUpload is provided
|
|
560
286
|
if (!handleImageUpload) {
|
|
561
|
-
throw new Error("handleImageUpload is required when using image
|
|
287
|
+
throw new Error("handleImageUpload is required when using the image extension.");
|
|
562
288
|
}
|
|
563
289
|
}
|
|
564
290
|
const editor = useEditor({
|
|
565
|
-
content:
|
|
291
|
+
content: defaultValue,
|
|
566
292
|
editable: !readOnly,
|
|
567
|
-
shouldRerenderOnTransaction: true,
|
|
568
293
|
extensions: getTipTapExtensions({
|
|
569
294
|
extensions,
|
|
570
295
|
slashCommands,
|
|
@@ -573,12 +298,27 @@ export const RichTextEditor = ({ className, editorInstanceRef, defaultValue = ""
|
|
|
573
298
|
}),
|
|
574
299
|
editorProps: {
|
|
575
300
|
handlePaste: (view, event) => {
|
|
576
|
-
if (!
|
|
301
|
+
if (!handleImageUpload)
|
|
577
302
|
return false;
|
|
578
|
-
|
|
303
|
+
if (!(event === null || event === void 0 ? void 0 : event.clipboardData))
|
|
304
|
+
return false;
|
|
305
|
+
if (event.clipboardData.types.includes("text/html") ||
|
|
306
|
+
event.clipboardData.types.includes("text/plain") ||
|
|
307
|
+
event.clipboardData.types.includes("text/rtf"))
|
|
308
|
+
return false;
|
|
309
|
+
if (event.clipboardData &&
|
|
310
|
+
event.clipboardData.files &&
|
|
311
|
+
event.clipboardData.files[0]) {
|
|
312
|
+
event.preventDefault();
|
|
313
|
+
const file = event.clipboardData.files[0];
|
|
314
|
+
const pos = view.state.selection.from;
|
|
315
|
+
startImageUpload(file, view, pos, handleImageUpload);
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
579
319
|
},
|
|
580
320
|
handleDrop: (view, event, _slice, moved) => {
|
|
581
|
-
if (!
|
|
321
|
+
if (!handleImageUpload)
|
|
582
322
|
return false;
|
|
583
323
|
if (!moved &&
|
|
584
324
|
event.dataTransfer &&
|
|
@@ -600,23 +340,9 @@ export const RichTextEditor = ({ className, editorInstanceRef, defaultValue = ""
|
|
|
600
340
|
},
|
|
601
341
|
},
|
|
602
342
|
onUpdate: ({ editor }) => {
|
|
603
|
-
|
|
604
|
-
(_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, editor.getHTML());
|
|
343
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(editor.getHTML());
|
|
605
344
|
},
|
|
606
345
|
});
|
|
607
|
-
useEffect(() => {
|
|
608
|
-
if (!editor || !isControlled)
|
|
609
|
-
return;
|
|
610
|
-
const currentValue = editor.getHTML();
|
|
611
|
-
if (currentValue !== value) {
|
|
612
|
-
editor.commands.setContent(value, { emitUpdate: false });
|
|
613
|
-
}
|
|
614
|
-
}, [editor, isControlled, value]);
|
|
615
|
-
useEffect(() => {
|
|
616
|
-
if (!editor)
|
|
617
|
-
return;
|
|
618
|
-
editor.setEditable(!readOnly, false);
|
|
619
|
-
}, [editor, readOnly]);
|
|
620
346
|
useEffect(() => {
|
|
621
347
|
const _ref = editorInstanceRef;
|
|
622
348
|
if (editorInstanceRef) {
|