@monolith-forensics/monolith-ui 1.8.1-dev.2 → 1.8.1-dev.4
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/Calendar/Calendar.d.ts +4 -1
- package/dist/Calendar/Calendar.js +126 -50
- package/dist/Calendar/CalendarStyles.d.ts +3 -2
- package/dist/Calendar/CalendarStyles.js +62 -23
- package/dist/Calendar/calendarHelpers.d.ts +1 -1
- package/dist/CheckBox/CheckBox.js +35 -4
- package/dist/DropDownMenu/DropDownMenu.js +25 -15
- package/dist/DropDownMenu/components/MenuComponent.js +6 -1
- package/dist/DropDownMenu/components/MenuItem.js +6 -0
- package/dist/DropDownMenu/components/MenuItemList.d.ts +2 -0
- package/dist/DropDownMenu/components/MenuItemList.js +94 -13
- package/dist/DropDownMenu/components/StyledContent.js +1 -2
- package/dist/DropDownMenu/types.d.ts +1 -0
- package/dist/FileViewer/viewers/ImageViewer.js +75 -18
- package/dist/MonolithUIProvider/MonolithUIProvider.d.ts +1 -0
- package/dist/QueryFilter/QueryFilter.constants.d.ts +134 -0
- package/dist/QueryFilter/QueryFilter.constants.js +39 -0
- package/dist/QueryFilter/QueryFilter.d.ts +1 -1
- package/dist/QueryFilter/QueryFilter.js +3 -303
- package/dist/QueryFilter/QueryFilter.lib.d.ts +14 -0
- package/dist/QueryFilter/QueryFilter.lib.js +84 -0
- package/dist/QueryFilter/QueryFilter.styled.d.ts +89 -0
- package/dist/QueryFilter/QueryFilter.styled.js +184 -0
- package/dist/QueryFilter/{types.d.ts → QueryFilter.types.d.ts} +11 -2
- package/dist/QueryFilter/components/MultiSelectEditor.d.ts +7 -0
- package/dist/QueryFilter/components/MultiSelectEditor.js +44 -0
- package/dist/QueryFilter/components/RuleChip.d.ts +8 -0
- package/dist/QueryFilter/components/RuleChip.js +37 -0
- package/dist/QueryFilter/components/Rules.d.ts +11 -0
- package/dist/QueryFilter/components/Rules.js +41 -0
- package/dist/QueryFilter/components/UnavailableRuleChip.d.ts +5 -0
- package/dist/QueryFilter/components/UnavailableRuleChip.js +7 -0
- package/dist/QueryFilter/components/ValueEditor.d.ts +7 -0
- package/dist/QueryFilter/components/ValueEditor.js +45 -0
- package/dist/QueryFilter/components/ValueSelector.d.ts +7 -0
- package/dist/QueryFilter/components/ValueSelector.js +34 -0
- package/dist/QueryFilter/components/index.d.ts +6 -0
- package/dist/QueryFilter/components/index.js +6 -0
- package/dist/QueryFilter/index.d.ts +3 -2
- package/dist/QueryFilter/index.js +3 -2
- package/dist/QueryFilter/useQueryFilter.d.ts +1 -1
- package/dist/QueryFilter/useQueryFilter.js +23 -19
- package/dist/RichTextEditor/Extensions/getTiptapExtensions.js +5 -15
- package/dist/RichTextEditor/Plugins/ImageActionsPlugin.d.ts +3 -0
- package/dist/RichTextEditor/Plugins/ImageActionsPlugin.js +241 -0
- package/dist/RichTextEditor/Plugins/UploadImagesPlugin.d.ts +15 -0
- package/dist/RichTextEditor/Plugins/UploadImagesPlugin.js +115 -51
- package/dist/RichTextEditor/Plugins/index.d.ts +1 -0
- package/dist/RichTextEditor/Plugins/index.js +1 -0
- package/dist/RichTextEditor/RichTextEditor.d.ts +3 -2
- package/dist/RichTextEditor/RichTextEditor.js +309 -35
- package/dist/RichTextEditor/Toolbar/Toolbar.js +14 -2
- package/dist/SuperDatePicker/SuperDatePicker.constants.d.ts +24 -0
- package/dist/SuperDatePicker/SuperDatePicker.constants.js +30 -0
- package/dist/SuperDatePicker/SuperDatePicker.d.ts +3 -0
- package/dist/SuperDatePicker/SuperDatePicker.js +31 -0
- package/dist/SuperDatePicker/SuperDatePicker.lib.d.ts +17 -0
- package/dist/SuperDatePicker/SuperDatePicker.lib.js +206 -0
- package/dist/SuperDatePicker/SuperDatePicker.styled.d.ts +60 -0
- package/dist/SuperDatePicker/SuperDatePicker.styled.js +256 -0
- package/dist/SuperDatePicker/SuperDatePicker.types.d.ts +48 -0
- package/dist/SuperDatePicker/SuperDatePicker.types.js +1 -0
- package/dist/SuperDatePicker/components/CommonPresetGroups.d.ts +7 -0
- package/dist/SuperDatePicker/components/CommonPresetGroups.js +6 -0
- package/dist/SuperDatePicker/components/EndpointCalendarDropdown.d.ts +10 -0
- package/dist/SuperDatePicker/components/EndpointCalendarDropdown.js +9 -0
- package/dist/SuperDatePicker/components/EndpointDateInput.d.ts +16 -0
- package/dist/SuperDatePicker/components/EndpointDateInput.js +26 -0
- package/dist/SuperDatePicker/components/EndpointPopover.d.ts +18 -0
- package/dist/SuperDatePicker/components/EndpointPopover.js +11 -0
- package/dist/SuperDatePicker/components/QuickRangeDropdown.d.ts +14 -0
- package/dist/SuperDatePicker/components/QuickRangeDropdown.js +19 -0
- package/dist/SuperDatePicker/components/QuickRangePopover.d.ts +18 -0
- package/dist/SuperDatePicker/components/QuickRangePopover.js +12 -0
- package/dist/SuperDatePicker/components/index.d.ts +6 -0
- package/dist/SuperDatePicker/components/index.js +6 -0
- package/dist/SuperDatePicker/index.d.ts +3 -0
- package/dist/SuperDatePicker/index.js +3 -0
- package/dist/SuperDatePicker/useSuperDatePicker.d.ts +32 -0
- package/dist/SuperDatePicker/useSuperDatePicker.js +125 -0
- package/dist/Table/ColumnResizer.d.ts +6 -9
- package/dist/Table/ColumnResizer.js +30 -10
- package/dist/Table/TableComponents.js +14 -10
- package/dist/Table/TableHeader.js +31 -16
- package/dist/Table/TableMenu/TableMenu.js +1 -1
- package/dist/Table/TableProvider.js +91 -4
- package/dist/Table/TableRow.js +19 -12
- package/dist/Table/Utils/index.d.ts +0 -1
- package/dist/Table/Utils/index.js +0 -1
- package/dist/Table/types.d.ts +6 -19
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/theme/variants.js +2 -0
- package/package.json +22 -18
- package/dist/QueryFilter/DefaultOperators.d.ts +0 -76
- package/dist/QueryFilter/DefaultOperators.js +0 -21
- package/dist/Table/Utils/resizeHandler.d.ts +0 -3
- package/dist/Table/Utils/resizeHandler.js +0 -84
- /package/dist/QueryFilter/{types.js → QueryFilter.types.js} +0 -0
|
@@ -1,14 +1,226 @@
|
|
|
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
|
+
};
|
|
1
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
11
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
12
|
import styled from "styled-components";
|
|
4
13
|
import { EditorContent, useEditor } from "@tiptap/react";
|
|
14
|
+
import { DOMParser as ProseMirrorDOMParser } from "@tiptap/pm/model";
|
|
5
15
|
import { Toolbar } from "./Toolbar";
|
|
6
16
|
import getTipTapExtensions from "./Extensions/getTiptapExtensions";
|
|
7
|
-
import { Extensions } from "./Enums";
|
|
8
|
-
import { startImageUpload, } from "./Plugins/UploadImagesPlugin";
|
|
17
|
+
import { Extensions, SlashCommands } from "./Enums";
|
|
18
|
+
import { addImagePlaceholder, removeImagePlaceholder, startImageUpload, } from "./Plugins/UploadImagesPlugin";
|
|
9
19
|
import SaveBadge from "./Components/SaveBadge";
|
|
10
20
|
import Fonts from "./Enums/Fonts";
|
|
11
21
|
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
|
+
};
|
|
12
224
|
const StyledContent = styled.div `
|
|
13
225
|
position: relative;
|
|
14
226
|
display: flex;
|
|
@@ -49,6 +261,7 @@ const StyledContent = styled.div `
|
|
|
49
261
|
}
|
|
50
262
|
|
|
51
263
|
.ProseMirror {
|
|
264
|
+
font-size: 14px;
|
|
52
265
|
font-weight: 400;
|
|
53
266
|
outline: none;
|
|
54
267
|
height: 100%;
|
|
@@ -81,37 +294,34 @@ const StyledContent = styled.div `
|
|
|
81
294
|
}
|
|
82
295
|
|
|
83
296
|
h1 {
|
|
84
|
-
font-size:
|
|
297
|
+
font-size: 32px;
|
|
85
298
|
line-height: 2rem;
|
|
86
299
|
margin: 0;
|
|
87
300
|
}
|
|
88
301
|
h2 {
|
|
89
|
-
font-size:
|
|
302
|
+
font-size: 28px;
|
|
90
303
|
line-height: 1.75rem;
|
|
91
304
|
margin: 0;
|
|
92
305
|
}
|
|
93
306
|
h3 {
|
|
94
|
-
font-size:
|
|
307
|
+
font-size: 24px;
|
|
95
308
|
line-height: 1.75rem;
|
|
96
309
|
margin: 0;
|
|
97
310
|
}
|
|
98
311
|
h4 {
|
|
99
|
-
font-size:
|
|
312
|
+
font-size: 20px;
|
|
100
313
|
line-height: 1.5rem;
|
|
101
314
|
margin: 0;
|
|
102
315
|
}
|
|
103
316
|
p {
|
|
104
317
|
margin: 0;
|
|
105
|
-
font-size: 0.8rem;
|
|
106
318
|
line-height: 1.5rem;
|
|
107
319
|
}
|
|
108
320
|
ul {
|
|
109
321
|
margin: 0;
|
|
110
|
-
font-size: 0.8rem;
|
|
111
322
|
}
|
|
112
323
|
ol {
|
|
113
324
|
margin: 0;
|
|
114
|
-
font-size: 0.8rem;
|
|
115
325
|
}
|
|
116
326
|
.editor-link {
|
|
117
327
|
color: ${({ theme }) => theme.palette.primary.main};
|
|
@@ -155,6 +365,9 @@ const StyledContent = styled.div `
|
|
|
155
365
|
.ProseMirror .img-placeholder {
|
|
156
366
|
position: relative;
|
|
157
367
|
width: fit-content;
|
|
368
|
+
display: inline-flex;
|
|
369
|
+
align-items: center;
|
|
370
|
+
justify-content: center;
|
|
158
371
|
|
|
159
372
|
&:before {
|
|
160
373
|
content: "";
|
|
@@ -177,6 +390,58 @@ const StyledContent = styled.div `
|
|
|
177
390
|
}
|
|
178
391
|
}
|
|
179
392
|
|
|
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
|
+
|
|
180
445
|
.floating-menu {
|
|
181
446
|
display: flex;
|
|
182
447
|
background-color: #0d0d0d10;
|
|
@@ -278,18 +543,28 @@ const StyledContent = styled.div `
|
|
|
278
543
|
margin: 0 0.125rem;
|
|
279
544
|
}
|
|
280
545
|
`;
|
|
281
|
-
export const RichTextEditor = ({ className, editorInstanceRef, defaultValue = "", value
|
|
546
|
+
export const RichTextEditor = ({ className, editorInstanceRef, defaultValue = "", value, readOnly = false, font, showToolbar = true, saving = false, extensions = [], slashCommands = [], bubbleMenuOptions, toolbarOptions, autoFocus, onChange, handleImageUpload, handleImageUrlUpload, style, }) => {
|
|
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);
|
|
282
552
|
const [fontState, setFontState] = useState(font || Fonts.DEFAULT);
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
553
|
+
useEffect(() => {
|
|
554
|
+
onChangeRef.current = onChange;
|
|
555
|
+
}, [onChange]);
|
|
556
|
+
if (hasImageSlashCommand && !hasImageExtension) {
|
|
557
|
+
throw new Error("Extensions.Image is required when using the Image slash command.");
|
|
558
|
+
}
|
|
559
|
+
if (hasImageExtension || hasImageSlashCommand) {
|
|
286
560
|
if (!handleImageUpload) {
|
|
287
|
-
throw new Error("handleImageUpload is required when using
|
|
561
|
+
throw new Error("handleImageUpload is required when using image uploads.");
|
|
288
562
|
}
|
|
289
563
|
}
|
|
290
564
|
const editor = useEditor({
|
|
291
|
-
content: defaultValue,
|
|
565
|
+
content: value !== null && value !== void 0 ? value : defaultValue,
|
|
292
566
|
editable: !readOnly,
|
|
567
|
+
shouldRerenderOnTransaction: true,
|
|
293
568
|
extensions: getTipTapExtensions({
|
|
294
569
|
extensions,
|
|
295
570
|
slashCommands,
|
|
@@ -298,27 +573,12 @@ export const RichTextEditor = ({ className, editorInstanceRef, defaultValue = ""
|
|
|
298
573
|
}),
|
|
299
574
|
editorProps: {
|
|
300
575
|
handlePaste: (view, event) => {
|
|
301
|
-
if (!handleImageUpload)
|
|
576
|
+
if (!hasImageExtension || !handleImageUpload)
|
|
302
577
|
return false;
|
|
303
|
-
|
|
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;
|
|
578
|
+
return handleImagePaste(view, event, handleImageUpload, handleImageUrlUpload);
|
|
319
579
|
},
|
|
320
580
|
handleDrop: (view, event, _slice, moved) => {
|
|
321
|
-
if (!handleImageUpload)
|
|
581
|
+
if (!hasImageExtension || !handleImageUpload)
|
|
322
582
|
return false;
|
|
323
583
|
if (!moved &&
|
|
324
584
|
event.dataTransfer &&
|
|
@@ -340,9 +600,23 @@ export const RichTextEditor = ({ className, editorInstanceRef, defaultValue = ""
|
|
|
340
600
|
},
|
|
341
601
|
},
|
|
342
602
|
onUpdate: ({ editor }) => {
|
|
343
|
-
|
|
603
|
+
var _a;
|
|
604
|
+
(_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, editor.getHTML());
|
|
344
605
|
},
|
|
345
606
|
});
|
|
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]);
|
|
346
620
|
useEffect(() => {
|
|
347
621
|
const _ref = editorInstanceRef;
|
|
348
622
|
if (editorInstanceRef) {
|
|
@@ -23,7 +23,11 @@ export const Toolbar = styled(({ className, editor, toolbarOptions }) => {
|
|
|
23
23
|
return (_jsx(Button, Object.assign({}, item.options, { children: (_a = item === null || item === void 0 ? void 0 : item.options) === null || _a === void 0 ? void 0 : _a.label }), index));
|
|
24
24
|
}
|
|
25
25
|
else if (item.type === "menu") {
|
|
26
|
-
return (_jsx(DropDownMenu, Object.assign({
|
|
26
|
+
return (_jsx(DropDownMenu, Object.assign({ dropDownProps: {
|
|
27
|
+
style: {
|
|
28
|
+
width: 135,
|
|
29
|
+
},
|
|
30
|
+
} }, item.options, { children: (_b = item === null || item === void 0 ? void 0 : item.options) === null || _b === void 0 ? void 0 : _b.label }), index));
|
|
27
31
|
}
|
|
28
32
|
}), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.FONT)) && (_jsx(DropDownMenu, { data: Object.values(Fonts).map((font) => ({
|
|
29
33
|
label: font,
|
|
@@ -31,7 +35,11 @@ export const Toolbar = styled(({ className, editor, toolbarOptions }) => {
|
|
|
31
35
|
onClick: () => {
|
|
32
36
|
setFont(font);
|
|
33
37
|
},
|
|
34
|
-
})), size: "xxs", variant: "outlined", arrow: true,
|
|
38
|
+
})), size: "xxs", variant: "outlined", arrow: true, dropDownProps: {
|
|
39
|
+
style: {
|
|
40
|
+
width: 135,
|
|
41
|
+
},
|
|
42
|
+
}, buttonProps: {
|
|
35
43
|
title: "Select Font",
|
|
36
44
|
}, children: (font || Fonts.DEFAULT) })), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.UNDO)) && _jsx(UndoControl, { editor: editor }), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.REDO)) && _jsx(RedoControl, { editor: editor })] }), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.COLOR)) && (_jsx(DropDownMenu, { data: [
|
|
37
45
|
{
|
|
@@ -60,6 +68,10 @@ export const Toolbar = styled(({ className, editor, toolbarOptions }) => {
|
|
|
60
68
|
borderRadius: "3px",
|
|
61
69
|
} }), item.label] })), size: "xxs", variant: "outlined", arrow: true, buttonProps: {
|
|
62
70
|
title: "Select Color",
|
|
71
|
+
}, dropDownProps: {
|
|
72
|
+
style: {
|
|
73
|
+
width: 100,
|
|
74
|
+
},
|
|
63
75
|
}, children: "Color" })), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.BOLD)) && _jsx(BoldControl, { editor: editor }), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.ITALIC)) && (_jsx(ItalicControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.UNDERLINE)) && (_jsx(UnderlineControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.STRIKE)) && (_jsx(StrikeThroughControl, { editor: editor }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_1)) && (_jsx(Heading1Control, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_2)) && (_jsx(Heading2Control, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_3)) && (_jsx(Heading3Control, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_4)) && (_jsx(Heading4Control, { editor: editor }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.BULLET_LIST)) && (_jsx(BulletListControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.ORDERED_LIST)) && (_jsx(OrderedListControl, { editor: editor }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_LEFT)) && (_jsx(AlignLeftControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_CENTER)) && (_jsx(AlignCenterControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_RIGHT)) && (_jsx(AlignRightControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_JUSTIFIED)) && (_jsx(AlignJustifiedControl, { editor: editor }))] })] }));
|
|
64
76
|
}) `
|
|
65
77
|
display: flex;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { QuickDirection, QuickUnit, SuperDatePickerProps, SuperDatePickerValue } from "./SuperDatePicker.types";
|
|
2
|
+
export declare const DEFAULT_VALUE: SuperDatePickerValue;
|
|
3
|
+
export declare const DEFAULT_ON_CHANGE: NonNullable<SuperDatePickerProps["onChange"]>;
|
|
4
|
+
export declare const DEFAULT_PLACEHOLDER = "Select date/time range";
|
|
5
|
+
export declare const DEFAULT_START_LABEL = "Start";
|
|
6
|
+
export declare const DEFAULT_END_LABEL = "End";
|
|
7
|
+
export declare const DEFAULT_FORMAT: NonNullable<SuperDatePickerProps["format"]>;
|
|
8
|
+
export declare const DEFAULT_SIZE: NonNullable<SuperDatePickerProps["size"]>;
|
|
9
|
+
export declare const DEFAULT_VARIANT: NonNullable<SuperDatePickerProps["variant"]>;
|
|
10
|
+
export declare const DEFAULT_REQUIRED = false;
|
|
11
|
+
export declare const DEFAULT_CLEARABLE = true;
|
|
12
|
+
export declare const DEFAULT_DISABLED = false;
|
|
13
|
+
export declare const DEFAULT_UTC = false;
|
|
14
|
+
export declare const DEFAULT_QUICK_DIRECTION: QuickDirection;
|
|
15
|
+
export declare const DEFAULT_QUICK_AMOUNT = "15";
|
|
16
|
+
export declare const DEFAULT_QUICK_UNIT: QuickUnit;
|
|
17
|
+
export declare const QUICK_UNITS: Array<{
|
|
18
|
+
label: string;
|
|
19
|
+
value: QuickUnit;
|
|
20
|
+
}>;
|
|
21
|
+
export declare const QUICK_DIRECTION_OPTIONS: Array<{
|
|
22
|
+
label: string;
|
|
23
|
+
value: QuickDirection;
|
|
24
|
+
}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const DEFAULT_VALUE = {
|
|
2
|
+
start: null,
|
|
3
|
+
end: null,
|
|
4
|
+
};
|
|
5
|
+
export const DEFAULT_ON_CHANGE = () => { };
|
|
6
|
+
export const DEFAULT_PLACEHOLDER = "Select date/time range";
|
|
7
|
+
export const DEFAULT_START_LABEL = "Start";
|
|
8
|
+
export const DEFAULT_END_LABEL = "End";
|
|
9
|
+
export const DEFAULT_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
10
|
+
export const DEFAULT_SIZE = "sm";
|
|
11
|
+
export const DEFAULT_VARIANT = "outlined";
|
|
12
|
+
export const DEFAULT_REQUIRED = false;
|
|
13
|
+
export const DEFAULT_CLEARABLE = true;
|
|
14
|
+
export const DEFAULT_DISABLED = false;
|
|
15
|
+
export const DEFAULT_UTC = false;
|
|
16
|
+
export const DEFAULT_QUICK_DIRECTION = "last";
|
|
17
|
+
export const DEFAULT_QUICK_AMOUNT = "15";
|
|
18
|
+
export const DEFAULT_QUICK_UNIT = "minutes";
|
|
19
|
+
export const QUICK_UNITS = [
|
|
20
|
+
{ label: "Minutes", value: "minutes" },
|
|
21
|
+
{ label: "Hours", value: "hours" },
|
|
22
|
+
{ label: "Days", value: "days" },
|
|
23
|
+
{ label: "Weeks", value: "weeks" },
|
|
24
|
+
{ label: "Months", value: "months" },
|
|
25
|
+
{ label: "Years", value: "years" },
|
|
26
|
+
];
|
|
27
|
+
export const QUICK_DIRECTION_OPTIONS = [
|
|
28
|
+
{ label: "Last", value: "last" },
|
|
29
|
+
{ label: "Next", value: "next" },
|
|
30
|
+
];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { FieldLabel } from "..";
|
|
4
|
+
import { ClearButton } from "../core";
|
|
5
|
+
import { DEFAULT_DISABLED, DEFAULT_END_LABEL, DEFAULT_FORMAT, DEFAULT_ON_CHANGE, DEFAULT_PLACEHOLDER, DEFAULT_REQUIRED, DEFAULT_SIZE, DEFAULT_START_LABEL, DEFAULT_UTC, DEFAULT_VALUE, DEFAULT_VARIANT, } from "./SuperDatePicker.constants";
|
|
6
|
+
import useSuperDatePicker from "./useSuperDatePicker";
|
|
7
|
+
import { EndpointPopover, QuickRangePopover, } from "./components";
|
|
8
|
+
import { RangeSeparator, StyledContainer, StyledInput, TriggerActions, } from "./SuperDatePicker.styled";
|
|
9
|
+
const SuperDatePicker = forwardRef(({ className, style, defaultValue = DEFAULT_VALUE, value, onChange = DEFAULT_ON_CHANGE, label, description, placeholder = DEFAULT_PLACEHOLDER, startLabel = DEFAULT_START_LABEL, endLabel = DEFAULT_END_LABEL, format = DEFAULT_FORMAT, size = DEFAULT_SIZE, variant = DEFAULT_VARIANT, required = DEFAULT_REQUIRED, clearable, disabled = DEFAULT_DISABLED, error, width, min, max, timeIntervalMinutes, utc = DEFAULT_UTC, presets, }, ref) => {
|
|
10
|
+
const isClearable = clearable === true;
|
|
11
|
+
const picker = useSuperDatePicker({
|
|
12
|
+
defaultValue,
|
|
13
|
+
value,
|
|
14
|
+
onChange,
|
|
15
|
+
disabled,
|
|
16
|
+
min,
|
|
17
|
+
max,
|
|
18
|
+
utc,
|
|
19
|
+
presets,
|
|
20
|
+
});
|
|
21
|
+
return (_jsxs(StyledContainer, { ref: (node) => {
|
|
22
|
+
if (typeof ref === "function") {
|
|
23
|
+
ref(node);
|
|
24
|
+
}
|
|
25
|
+
else if (ref) {
|
|
26
|
+
ref.current = node;
|
|
27
|
+
}
|
|
28
|
+
}, className: className, "$width": width, children: [label && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label })), _jsxs(StyledInput, { size: size, variant: variant, "$disabled": disabled, "$active": picker.openSegment !== null, "$clearable": isClearable, style: style, children: [_jsx(QuickRangePopover, { opened: picker.openSegment === "quick", disabled: disabled, size: size, commonRangeGroups: picker.commonRangeGroups, quickDirection: picker.quickDirection, quickAmount: picker.quickAmount, quickUnit: picker.quickUnit, onOpenChange: (opened) => picker.handleOpenSegmentChange("quick", opened), onQuickDirectionChange: picker.handleQuickDirectionChange, onQuickAmountChange: picker.handleQuickAmountChange, onQuickAmountSubmit: picker.handleQuickAmountSubmit, onQuickUnitChange: picker.handleQuickUnitChange, onPresetClick: picker.handlePreset }), _jsx(EndpointPopover, { opened: picker.openSegment === "start", disabled: disabled, label: startLabel, value: picker.value.start, onOpenChange: (opened) => picker.handleOpenSegmentChange("start", opened), onInputChange: (next) => picker.handleEndpointChange("start", next), onCalendarChange: (date) => picker.handleCalendarChange("start", date), format: format, size: size, utc: utc, min: min, max: picker.getEndpointMax("start"), timeIntervalMinutes: timeIntervalMinutes }), _jsx(RangeSeparator, { size: size, children: "\u2192" }), _jsx(EndpointPopover, { opened: picker.openSegment === "end", disabled: disabled, label: endLabel, value: picker.value.end, onOpenChange: (opened) => picker.handleOpenSegmentChange("end", opened), onInputChange: (next) => picker.handleEndpointChange("end", next), onCalendarChange: (date) => picker.handleCalendarChange("end", date), format: format, size: size, utc: utc, min: picker.getEndpointMin("end"), max: max, timeIntervalMinutes: timeIntervalMinutes }), _jsx(TriggerActions, { children: isClearable && (picker.value.start || picker.value.end) ? (_jsx(ClearButton, { size: size, onClick: picker.handleClear })) : null })] })] }));
|
|
29
|
+
});
|
|
30
|
+
SuperDatePicker.displayName = "SuperDatePicker";
|
|
31
|
+
export default SuperDatePicker;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
import type { CommonRangeGroupConfig, SuperDatePickerPreset } from "./SuperDatePicker.types";
|
|
3
|
+
export declare const resolveNow: (utc: boolean) => moment.Moment;
|
|
4
|
+
export declare const serializeMoment: (value: moment.Moment, utc: boolean) => string;
|
|
5
|
+
export declare const createRange: (start: moment.Moment, end: moment.Moment, utc: boolean) => {
|
|
6
|
+
start: string;
|
|
7
|
+
end: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const makeCommonRange: (utc: boolean, label: string, getRange: (now: moment.Moment) => {
|
|
10
|
+
start: moment.Moment;
|
|
11
|
+
end: moment.Moment;
|
|
12
|
+
}) => SuperDatePickerPreset;
|
|
13
|
+
export declare const getDefaultCommonRangeGroups: (utc: boolean) => CommonRangeGroupConfig[];
|
|
14
|
+
export declare const getAdditionalCommonRangeGroups: (utc: boolean) => CommonRangeGroupConfig[];
|
|
15
|
+
export declare const parseRangeMoment: (value: string | null | undefined, utc: boolean) => moment.Moment | null;
|
|
16
|
+
export declare const momentToCalendarDate: (value: string | null | undefined, utc: boolean) => Date | undefined;
|
|
17
|
+
export declare const calendarDateToMoment: (value: Date, utc: boolean) => moment.Moment;
|