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