@abraca/dabra 2.17.0 → 2.17.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.
|
@@ -19201,6 +19201,41 @@ var TreeManager = class {
|
|
|
19201
19201
|
* - cover set + no image/video remains → clear the three cover keys;
|
|
19202
19202
|
* - no cover + at least one image/video → adopt the first as the cover.
|
|
19203
19203
|
*/
|
|
19204
|
+
const EXT_MIME = {
|
|
19205
|
+
png: "image/png",
|
|
19206
|
+
jpg: "image/jpeg",
|
|
19207
|
+
jpeg: "image/jpeg",
|
|
19208
|
+
gif: "image/gif",
|
|
19209
|
+
webp: "image/webp",
|
|
19210
|
+
avif: "image/avif",
|
|
19211
|
+
svg: "image/svg+xml",
|
|
19212
|
+
bmp: "image/bmp",
|
|
19213
|
+
heic: "image/heic",
|
|
19214
|
+
heif: "image/heif",
|
|
19215
|
+
mp4: "video/mp4",
|
|
19216
|
+
webm: "video/webm",
|
|
19217
|
+
mov: "video/quicktime",
|
|
19218
|
+
m4v: "video/x-m4v",
|
|
19219
|
+
ogv: "video/ogg",
|
|
19220
|
+
mkv: "video/x-matroska"
|
|
19221
|
+
};
|
|
19222
|
+
function attr(node, name) {
|
|
19223
|
+
const v = node.getAttribute(name);
|
|
19224
|
+
return typeof v === "string" && v ? v : void 0;
|
|
19225
|
+
}
|
|
19226
|
+
/**
|
|
19227
|
+
* Resolve a file node's mime type. A `fileBlock` may carry the mime under
|
|
19228
|
+
* `mimeType` (cou-sh's TipTap/y-prosemirror node attr) or `mime` (the
|
|
19229
|
+
* `@abraca/convert` markdown path), and may carry neither — in which case we
|
|
19230
|
+
* infer it from the filename/src extension (the convert sidecar `src` is
|
|
19231
|
+
* `.abracadabra/files/<id>-<filename>`). Returns "" when it can't be
|
|
19232
|
+
* classified as image/video.
|
|
19233
|
+
*/
|
|
19234
|
+
function resolveMime(node) {
|
|
19235
|
+
const explicit = attr(node, "mimeType") ?? attr(node, "mime");
|
|
19236
|
+
if (explicit) return explicit;
|
|
19237
|
+
return EXT_MIME[(attr(node, "filename") ?? attr(node, "src") ?? "").split(".").pop()?.toLowerCase() ?? ""] ?? "";
|
|
19238
|
+
}
|
|
19204
19239
|
/**
|
|
19205
19240
|
* Recursively collect image/video `fileBlock` nodes from a Y.XmlFragment (or
|
|
19206
19241
|
* element subtree), in document order. Mirrors the TipTap
|
|
@@ -19211,17 +19246,14 @@ function collectMediaFileBlocks(root) {
|
|
|
19211
19246
|
const out = [];
|
|
19212
19247
|
const visit = (node) => {
|
|
19213
19248
|
if (node instanceof Y.XmlElement && node.nodeName === "fileBlock") {
|
|
19214
|
-
const
|
|
19215
|
-
if (
|
|
19216
|
-
const
|
|
19217
|
-
if (
|
|
19218
|
-
|
|
19219
|
-
|
|
19220
|
-
|
|
19221
|
-
|
|
19222
|
-
mimeType
|
|
19223
|
-
});
|
|
19224
|
-
}
|
|
19249
|
+
const uploadId = attr(node, "uploadId") ?? attr(node, "upload-id");
|
|
19250
|
+
if (uploadId) {
|
|
19251
|
+
const mimeType = resolveMime(node);
|
|
19252
|
+
if (mimeType.startsWith("image/") || mimeType.startsWith("video/")) out.push({
|
|
19253
|
+
uploadId,
|
|
19254
|
+
docId: attr(node, "docId") ?? "",
|
|
19255
|
+
mimeType
|
|
19256
|
+
});
|
|
19225
19257
|
}
|
|
19226
19258
|
}
|
|
19227
19259
|
if (node instanceof Y.XmlElement || node instanceof Y.XmlFragment) for (let i = 0; i < node.length; i++) visit(node.get(i));
|