@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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/dabra",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.2",
|
|
4
4
|
"description": "abracadabra provider",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"abracadabra",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"yjs": "^13.6.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@abraca/schema": "2.17.
|
|
44
|
+
"@abraca/schema": "2.17.2"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
|
package/src/CoverReconcile.ts
CHANGED
|
@@ -28,6 +28,46 @@ export interface MediaFileBlock {
|
|
|
28
28
|
mimeType: string;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
const EXT_MIME: Record<string, string> = {
|
|
32
|
+
png: "image/png",
|
|
33
|
+
jpg: "image/jpeg",
|
|
34
|
+
jpeg: "image/jpeg",
|
|
35
|
+
gif: "image/gif",
|
|
36
|
+
webp: "image/webp",
|
|
37
|
+
avif: "image/avif",
|
|
38
|
+
svg: "image/svg+xml",
|
|
39
|
+
bmp: "image/bmp",
|
|
40
|
+
heic: "image/heic",
|
|
41
|
+
heif: "image/heif",
|
|
42
|
+
mp4: "video/mp4",
|
|
43
|
+
webm: "video/webm",
|
|
44
|
+
mov: "video/quicktime",
|
|
45
|
+
m4v: "video/x-m4v",
|
|
46
|
+
ogv: "video/ogg",
|
|
47
|
+
mkv: "video/x-matroska",
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function attr(node: Y.XmlElement, name: string): string | undefined {
|
|
51
|
+
const v = node.getAttribute(name);
|
|
52
|
+
return typeof v === "string" && v ? v : undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Resolve a file node's mime type. A `fileBlock` may carry the mime under
|
|
57
|
+
* `mimeType` (cou-sh's TipTap/y-prosemirror node attr) or `mime` (the
|
|
58
|
+
* `@abraca/convert` markdown path), and may carry neither — in which case we
|
|
59
|
+
* infer it from the filename/src extension (the convert sidecar `src` is
|
|
60
|
+
* `.abracadabra/files/<id>-<filename>`). Returns "" when it can't be
|
|
61
|
+
* classified as image/video.
|
|
62
|
+
*/
|
|
63
|
+
function resolveMime(node: Y.XmlElement): string {
|
|
64
|
+
const explicit = attr(node, "mimeType") ?? attr(node, "mime");
|
|
65
|
+
if (explicit) return explicit;
|
|
66
|
+
const name = attr(node, "filename") ?? attr(node, "src") ?? "";
|
|
67
|
+
const ext = name.split(".").pop()?.toLowerCase() ?? "";
|
|
68
|
+
return EXT_MIME[ext] ?? "";
|
|
69
|
+
}
|
|
70
|
+
|
|
31
71
|
/**
|
|
32
72
|
* Recursively collect image/video `fileBlock` nodes from a Y.XmlFragment (or
|
|
33
73
|
* element subtree), in document order. Mirrors the TipTap
|
|
@@ -40,17 +80,16 @@ export function collectMediaFileBlocks(
|
|
|
40
80
|
const out: MediaFileBlock[] = [];
|
|
41
81
|
const visit = (node: Y.AbstractType<unknown>): void => {
|
|
42
82
|
if (node instanceof Y.XmlElement && node.nodeName === "fileBlock") {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const docId = node.getAttribute("docId");
|
|
83
|
+
const uploadId = attr(node, "uploadId") ?? attr(node, "upload-id");
|
|
84
|
+
if (uploadId) {
|
|
85
|
+
const mimeType = resolveMime(node);
|
|
86
|
+
if (
|
|
87
|
+
mimeType.startsWith("image/") ||
|
|
88
|
+
mimeType.startsWith("video/")
|
|
89
|
+
) {
|
|
51
90
|
out.push({
|
|
52
91
|
uploadId,
|
|
53
|
-
docId:
|
|
92
|
+
docId: attr(node, "docId") ?? "",
|
|
54
93
|
mimeType,
|
|
55
94
|
});
|
|
56
95
|
}
|