@monolith-forensics/monolith-ui 1.9.1-dev.0 → 1.9.1-dev.2
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.
|
@@ -2,7 +2,7 @@ import TiptapImage from "@tiptap/extension-image";
|
|
|
2
2
|
import StarterKit from "@tiptap/starter-kit";
|
|
3
3
|
import HorizontalRule from "@tiptap/extension-horizontal-rule";
|
|
4
4
|
import TextAlign from "@tiptap/extension-text-align";
|
|
5
|
-
import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table";
|
|
5
|
+
import { Table, TableCell, TableHeader, TableRow, } from "@tiptap/extension-table";
|
|
6
6
|
import { Focus, Placeholder } from "@tiptap/extensions";
|
|
7
7
|
import { Color } from "@tiptap/extension-color";
|
|
8
8
|
import { TextStyle } from "@tiptap/extension-text-style";
|
|
@@ -17,6 +17,8 @@ const CustomImage = TiptapImage.extend({
|
|
|
17
17
|
var _a;
|
|
18
18
|
return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { "data-uuid": {
|
|
19
19
|
default: null,
|
|
20
|
+
}, crossorigin: {
|
|
21
|
+
default: "anonymous",
|
|
20
22
|
} });
|
|
21
23
|
},
|
|
22
24
|
addProseMirrorPlugins() {
|
|
@@ -60,13 +60,42 @@ const getImageFilename = (image) => {
|
|
|
60
60
|
return "image.png";
|
|
61
61
|
};
|
|
62
62
|
const getImageBlob = (src) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
const response = yield fetch(src
|
|
63
|
+
const response = yield fetch(src, {
|
|
64
|
+
mode: "cors",
|
|
65
|
+
credentials: "omit",
|
|
66
|
+
cache: "no-store",
|
|
67
|
+
});
|
|
64
68
|
if (!response.ok) {
|
|
65
69
|
throw new Error("Unable to load image.");
|
|
66
70
|
}
|
|
67
|
-
return
|
|
71
|
+
return {
|
|
72
|
+
blob: yield response.blob(),
|
|
73
|
+
contentType: response.headers.get("content-type") || "",
|
|
74
|
+
};
|
|
68
75
|
});
|
|
69
76
|
const clipboardPngType = "image/png";
|
|
77
|
+
const imageMimeTypesByExtension = {
|
|
78
|
+
gif: "image/gif",
|
|
79
|
+
jpg: "image/jpeg",
|
|
80
|
+
jpeg: "image/jpeg",
|
|
81
|
+
png: clipboardPngType,
|
|
82
|
+
svg: "image/svg+xml",
|
|
83
|
+
webp: "image/webp",
|
|
84
|
+
};
|
|
85
|
+
const normalizeMimeType = (type) => type.toLowerCase().split(";")[0].trim();
|
|
86
|
+
const getImageMimeTypeFromSource = (src) => {
|
|
87
|
+
var _a;
|
|
88
|
+
try {
|
|
89
|
+
const url = new URL(src);
|
|
90
|
+
const filename = url.pathname.split("/").filter(Boolean).pop();
|
|
91
|
+
const extension = (_a = filename === null || filename === void 0 ? void 0 : filename.split(".").pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
92
|
+
return extension ? imageMimeTypesByExtension[extension] || "" : "";
|
|
93
|
+
}
|
|
94
|
+
catch (_b) {
|
|
95
|
+
const dataUrlMatch = src.match(/^data:([^;,]+)/);
|
|
96
|
+
return (dataUrlMatch === null || dataUrlMatch === void 0 ? void 0 : dataUrlMatch[1]) || "";
|
|
97
|
+
}
|
|
98
|
+
};
|
|
70
99
|
const canWriteClipboardType = (ClipboardItemCtor, type) => {
|
|
71
100
|
if (!type)
|
|
72
101
|
return false;
|
|
@@ -126,10 +155,15 @@ const convertBlobToClipboardPng = (blob, fallbackSrc) => __awaiter(void 0, void
|
|
|
126
155
|
});
|
|
127
156
|
const getClipboardImageBlob = (image, ClipboardItemCtor) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
157
|
const src = image.currentSrc || image.src;
|
|
129
|
-
const blob = yield getImageBlob(src);
|
|
130
|
-
const type = blob.type ||
|
|
158
|
+
const { blob, contentType } = yield getImageBlob(src);
|
|
159
|
+
const type = normalizeMimeType(blob.type) ||
|
|
160
|
+
normalizeMimeType(contentType) ||
|
|
161
|
+
getImageMimeTypeFromSource(src);
|
|
131
162
|
if (canWriteClipboardType(ClipboardItemCtor, type)) {
|
|
132
|
-
return {
|
|
163
|
+
return {
|
|
164
|
+
blob: blob.type === type ? blob : new Blob([blob], { type }),
|
|
165
|
+
type,
|
|
166
|
+
};
|
|
133
167
|
}
|
|
134
168
|
return {
|
|
135
169
|
blob: yield convertBlobToClipboardPng(blob, src),
|
|
@@ -155,7 +189,7 @@ const downloadImage = (image) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
155
189
|
let href = image.src;
|
|
156
190
|
let objectUrl = null;
|
|
157
191
|
try {
|
|
158
|
-
const blob = yield getImageBlob(image.src);
|
|
192
|
+
const { blob } = yield getImageBlob(image.src);
|
|
159
193
|
objectUrl = URL.createObjectURL(blob);
|
|
160
194
|
href = objectUrl;
|
|
161
195
|
}
|