@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.
Files changed (170) 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 -0
  56. package/dist/QueryFilter/DefaultOperators.js +21 -0
  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 -0
  62. package/dist/QueryFilter/types.js +1 -0
  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 -309
  119. package/dist/RichTextEditor/Toolbar/Toolbar.js +2 -14
  120. package/dist/RichTextEditor/Utils/codeBlockUtils.d.ts +20 -0
  121. package/dist/RichTextEditor/Utils/codeBlockUtils.js +137 -0
  122. package/dist/RichTextEditor/Utils/codeUtils.d.ts +3 -0
  123. package/dist/RichTextEditor/Utils/codeUtils.js +12 -0
  124. package/dist/RichTextEditor/Utils/linkUtils.d.ts +19 -0
  125. package/dist/RichTextEditor/Utils/linkUtils.js +57 -0
  126. package/dist/RichTextEditor/Utils/tableUtils.d.ts +1 -0
  127. package/dist/RichTextEditor/Utils/tableUtils.js +1 -0
  128. package/dist/SegmentedControl/SegmentedControl.utils.d.ts +2 -2
  129. package/dist/SegmentedControl/SegmentedControl.utils.js +30 -3
  130. package/dist/SelectBox/SelectBox.js +5 -5
  131. package/dist/SelectBox/select-box.styled-components.d.ts +1 -4
  132. package/dist/SelectBox/select-box.styled-components.js +48 -11
  133. package/dist/SelectBox/types.d.ts +0 -1
  134. package/dist/Switch/Switch.d.ts +2 -2
  135. package/dist/Switch/Switch.js +83 -18
  136. package/dist/Table/ColumnResizer.d.ts +9 -6
  137. package/dist/Table/ColumnResizer.js +10 -30
  138. package/dist/Table/StateStorage.d.ts +0 -4
  139. package/dist/Table/StateStorage.js +0 -13
  140. package/dist/Table/Table.js +12 -160
  141. package/dist/Table/TableComponents.d.ts +0 -10
  142. package/dist/Table/TableComponents.js +10 -71
  143. package/dist/Table/TableDefaults.d.ts +0 -7
  144. package/dist/Table/TableDefaults.js +0 -7
  145. package/dist/Table/TableHeader.js +16 -31
  146. package/dist/Table/TableMenu/TableMenu.js +1 -1
  147. package/dist/Table/TableProvider.js +75 -354
  148. package/dist/Table/TableRow.js +16 -28
  149. package/dist/Table/Utils/index.d.ts +1 -0
  150. package/dist/Table/Utils/index.js +1 -0
  151. package/dist/Table/Utils/resizeHandler.d.ts +3 -0
  152. package/dist/Table/Utils/resizeHandler.js +84 -0
  153. package/dist/Table/types.d.ts +19 -70
  154. package/dist/TagBox/TagBox.d.ts +1 -1
  155. package/dist/TagBox/TagBox.js +80 -22
  156. package/dist/TagBox/types.d.ts +0 -1
  157. package/dist/TextArea/TextArea.js +23 -9
  158. package/dist/TextInput/TextInput.js +6 -12
  159. package/dist/Utilities/parseTimestamp.js +6 -11
  160. package/dist/core/ArrowButton.d.ts +0 -2
  161. package/dist/core/ArrowButton.js +3 -7
  162. package/dist/core/ClearButton.d.ts +0 -2
  163. package/dist/core/ClearButton.js +3 -7
  164. package/dist/core/controlSizes.js +9 -9
  165. package/dist/core/index.d.ts +0 -1
  166. package/dist/core/index.js +0 -1
  167. package/dist/index.d.ts +0 -3
  168. package/dist/index.js +0 -2
  169. package/dist/theme/variants.js +8 -2
  170. 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
- (() => __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,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, 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
- import { DOMParser as ProseMirrorDOMParser } from "@tiptap/pm/model";
15
5
  import { Toolbar } from "./Toolbar";
16
6
  import getTipTapExtensions from "./Extensions/getTiptapExtensions";
17
- import { Extensions, SlashCommands } from "./Enums";
18
- import { addImagePlaceholder, removeImagePlaceholder, startImageUpload, } from "./Plugins/UploadImagesPlugin";
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: 32px;
84
+ font-size: 1.5rem;
298
85
  line-height: 2rem;
299
86
  margin: 0;
300
87
  }
301
88
  h2 {
302
- font-size: 28px;
89
+ font-size: 1.25rem;
303
90
  line-height: 1.75rem;
304
91
  margin: 0;
305
92
  }
306
93
  h3 {
307
- font-size: 24px;
94
+ font-size: 1.125rem;
308
95
  line-height: 1.75rem;
309
96
  margin: 0;
310
97
  }
311
98
  h4 {
312
- font-size: 20px;
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, 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);
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
- 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) {
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 uploads.");
287
+ throw new Error("handleImageUpload is required when using the image extension.");
562
288
  }
563
289
  }
564
290
  const editor = useEditor({
565
- content: value !== null && value !== void 0 ? value : defaultValue,
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 (!hasImageExtension || !handleImageUpload)
301
+ if (!handleImageUpload)
577
302
  return false;
578
- 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;
579
319
  },
580
320
  handleDrop: (view, event, _slice, moved) => {
581
- if (!hasImageExtension || !handleImageUpload)
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
- var _a;
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) {