@macrowing/filepilot 0.1.0 → 0.1.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.
- package/dist/builtin.js +70 -3
- package/dist/chunk-KCRUK7FG.js +41 -0
- package/dist/{chunk-MHWH3ZGP.js → chunk-MTBYBLJA.js} +3 -2
- package/dist/index.cjs +3 -74
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +4 -8
- package/dist/react.cjs +1 -68
- package/dist/react.js +2 -2
- package/package.json +28 -8
- package/dist/chunk-EQYOJW24.js +0 -111
package/dist/builtin.js
CHANGED
|
@@ -1,7 +1,74 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
createFilePilotRegistry
|
|
3
|
+
} from "./chunk-KCRUK7FG.js";
|
|
4
|
+
|
|
5
|
+
// src/builtin.ts
|
|
6
|
+
var builtinParsers = [
|
|
7
|
+
{
|
|
8
|
+
id: "filepilot-parser-drawio",
|
|
9
|
+
kind: "drawing",
|
|
10
|
+
extensions: ["drawio", "dio"],
|
|
11
|
+
mimeTypes: ["application/vnd.jgraph.mxfile", "application/x-drawio", "application/drawio"],
|
|
12
|
+
load: () => import("@macrowing/filepilot-parser-drawio")
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "filepilot-parser-viewer",
|
|
16
|
+
kind: "viewer",
|
|
17
|
+
extensions: ["md", "markdown", "mdx", "txt", "text", "log", "csv", "json", "xml", "yaml", "yml", "png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"],
|
|
18
|
+
mimeTypes: [
|
|
19
|
+
"text/markdown",
|
|
20
|
+
"text/x-markdown",
|
|
21
|
+
"text/plain",
|
|
22
|
+
"text/csv",
|
|
23
|
+
"application/json",
|
|
24
|
+
"application/xml",
|
|
25
|
+
"text/xml",
|
|
26
|
+
"image/png",
|
|
27
|
+
"image/jpeg",
|
|
28
|
+
"image/gif",
|
|
29
|
+
"image/webp",
|
|
30
|
+
"image/bmp",
|
|
31
|
+
"image/svg+xml"
|
|
32
|
+
],
|
|
33
|
+
load: () => import("@macrowing/filepilot-parser-viewer")
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "filepilot-parser-pdf",
|
|
37
|
+
kind: "pdf",
|
|
38
|
+
extensions: ["pdf"],
|
|
39
|
+
mimeTypes: ["application/pdf"],
|
|
40
|
+
load: () => import("@macrowing/filepilot-parser-pdf")
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "filepilot-parser-office",
|
|
44
|
+
kind: "office",
|
|
45
|
+
extensions: ["doc", "docx", "ppt", "pptx", "xls", "xlsx"],
|
|
46
|
+
mimeTypes: [
|
|
47
|
+
"application/msword",
|
|
48
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
49
|
+
"application/vnd.ms-powerpoint",
|
|
50
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
51
|
+
"application/vnd.ms-excel",
|
|
52
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
53
|
+
],
|
|
54
|
+
load: () => import("@macrowing/filepilot-parser-office")
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "filepilot-parser-mmind",
|
|
58
|
+
kind: "mindmap",
|
|
59
|
+
extensions: ["mmind"],
|
|
60
|
+
mimeTypes: ["application/json", "application/x-mmind"],
|
|
61
|
+
load: () => import("@macrowing/filepilot-parser-mmind")
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "filepilot-parser-mdoc",
|
|
65
|
+
kind: "docflow",
|
|
66
|
+
extensions: ["mdoc"],
|
|
67
|
+
mimeTypes: ["application/x-mdoc", "application/vnd.docflow.mdoc", "application/octet-stream"],
|
|
68
|
+
load: () => import("@macrowing/filepilot-parser-mdoc")
|
|
69
|
+
}
|
|
70
|
+
];
|
|
71
|
+
var defaultRegistry = createFilePilotRegistry(builtinParsers);
|
|
5
72
|
export {
|
|
6
73
|
builtinParsers,
|
|
7
74
|
defaultRegistry
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/registry.ts
|
|
2
|
+
var normalizeExtension = (extension) => extension?.replace(/^\./, "").toLowerCase();
|
|
3
|
+
var getFileExtension = (file) => {
|
|
4
|
+
if (file.extension) return normalizeExtension(file.extension);
|
|
5
|
+
const name = file.name?.split(/[?#]/)[0];
|
|
6
|
+
const index = name?.lastIndexOf(".") ?? -1;
|
|
7
|
+
return index >= 0 ? normalizeExtension(name?.slice(index + 1)) : void 0;
|
|
8
|
+
};
|
|
9
|
+
var hasExtensionMatch = (parser, extension) => Boolean(
|
|
10
|
+
extension && parser.extensions.some((item) => normalizeExtension(item) === extension)
|
|
11
|
+
);
|
|
12
|
+
var hasMimeTypeMatch = (parser, mimeType) => Boolean(
|
|
13
|
+
mimeType && parser.mimeTypes?.some((item) => item.toLowerCase() === mimeType)
|
|
14
|
+
);
|
|
15
|
+
var createFilePilotRegistry = (initialParsers = []) => {
|
|
16
|
+
const parsers = /* @__PURE__ */ new Map();
|
|
17
|
+
initialParsers.forEach((parser) => parsers.set(parser.id, parser));
|
|
18
|
+
return {
|
|
19
|
+
register(parser) {
|
|
20
|
+
parsers.set(parser.id, parser);
|
|
21
|
+
return () => parsers.delete(parser.id);
|
|
22
|
+
},
|
|
23
|
+
unregister(id) {
|
|
24
|
+
parsers.delete(id);
|
|
25
|
+
},
|
|
26
|
+
resolve(file, parserId) {
|
|
27
|
+
const extension = getFileExtension(file);
|
|
28
|
+
const mimeType = file.mimeType?.toLowerCase();
|
|
29
|
+
if (parserId) return parsers.get(parserId);
|
|
30
|
+
const list = Array.from(parsers.values());
|
|
31
|
+
return list.find((parser) => hasExtensionMatch(parser, extension)) ?? list.find((parser) => hasMimeTypeMatch(parser, mimeType));
|
|
32
|
+
},
|
|
33
|
+
list() {
|
|
34
|
+
return Array.from(parsers.values());
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
createFilePilotRegistry
|
|
41
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createFilePilotRegistry
|
|
3
|
+
} from "./chunk-KCRUK7FG.js";
|
|
4
4
|
|
|
5
5
|
// src/react.tsx
|
|
6
6
|
import React, { Suspense, useEffect, useMemo, useRef } from "react";
|
|
7
7
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
8
8
|
var normalizeLocale = (locale) => locale?.startsWith("en") ? "en-US" : "zh-CN";
|
|
9
|
+
var defaultRegistry = createFilePilotRegistry();
|
|
9
10
|
var viewerCache = /* @__PURE__ */ new WeakMap();
|
|
10
11
|
var getLazyViewerEntry = (parser) => {
|
|
11
12
|
const cached = viewerCache.get(parser);
|
package/dist/index.cjs
CHANGED
|
@@ -31,9 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
FilePilot: () => FilePilot,
|
|
34
|
-
|
|
35
|
-
createFilePilotRegistry: () => createFilePilotRegistry,
|
|
36
|
-
defaultRegistry: () => defaultRegistry
|
|
34
|
+
createFilePilotRegistry: () => createFilePilotRegistry
|
|
37
35
|
});
|
|
38
36
|
module.exports = __toCommonJS(index_exports);
|
|
39
37
|
|
|
@@ -75,78 +73,11 @@ var createFilePilotRegistry = (initialParsers = []) => {
|
|
|
75
73
|
};
|
|
76
74
|
};
|
|
77
75
|
|
|
78
|
-
// src/builtin.ts
|
|
79
|
-
var builtinParsers = [
|
|
80
|
-
{
|
|
81
|
-
id: "filepilot-parser-drawio",
|
|
82
|
-
kind: "drawing",
|
|
83
|
-
extensions: ["drawio", "dio"],
|
|
84
|
-
mimeTypes: ["application/vnd.jgraph.mxfile", "application/x-drawio", "application/drawio"],
|
|
85
|
-
load: () => import("@macrowing/filepilot-parser-drawio")
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
id: "filepilot-parser-viewer",
|
|
89
|
-
kind: "viewer",
|
|
90
|
-
extensions: ["md", "markdown", "mdx", "txt", "text", "log", "csv", "json", "xml", "yaml", "yml", "png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"],
|
|
91
|
-
mimeTypes: [
|
|
92
|
-
"text/markdown",
|
|
93
|
-
"text/x-markdown",
|
|
94
|
-
"text/plain",
|
|
95
|
-
"text/csv",
|
|
96
|
-
"application/json",
|
|
97
|
-
"application/xml",
|
|
98
|
-
"text/xml",
|
|
99
|
-
"image/png",
|
|
100
|
-
"image/jpeg",
|
|
101
|
-
"image/gif",
|
|
102
|
-
"image/webp",
|
|
103
|
-
"image/bmp",
|
|
104
|
-
"image/svg+xml"
|
|
105
|
-
],
|
|
106
|
-
load: () => import("@macrowing/filepilot-parser-viewer")
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
id: "filepilot-parser-pdf",
|
|
110
|
-
kind: "pdf",
|
|
111
|
-
extensions: ["pdf"],
|
|
112
|
-
mimeTypes: ["application/pdf"],
|
|
113
|
-
load: () => import("@macrowing/filepilot-parser-pdf")
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
id: "filepilot-parser-office",
|
|
117
|
-
kind: "office",
|
|
118
|
-
extensions: ["doc", "docx", "ppt", "pptx", "xls", "xlsx"],
|
|
119
|
-
mimeTypes: [
|
|
120
|
-
"application/msword",
|
|
121
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
122
|
-
"application/vnd.ms-powerpoint",
|
|
123
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
124
|
-
"application/vnd.ms-excel",
|
|
125
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
126
|
-
],
|
|
127
|
-
load: () => import("@macrowing/filepilot-parser-office")
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
id: "filepilot-parser-mmind",
|
|
131
|
-
kind: "mindmap",
|
|
132
|
-
extensions: ["mmind"],
|
|
133
|
-
mimeTypes: ["application/json", "application/x-mmind"],
|
|
134
|
-
load: () => import("@macrowing/filepilot-parser-mmind")
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
id: "filepilot-parser-mdoc",
|
|
138
|
-
kind: "docflow",
|
|
139
|
-
extensions: ["mdoc"],
|
|
140
|
-
mimeTypes: ["application/x-mdoc", "application/vnd.docflow.mdoc", "application/octet-stream"],
|
|
141
|
-
load: () => import("@macrowing/filepilot-parser-mdoc")
|
|
142
|
-
}
|
|
143
|
-
];
|
|
144
|
-
var defaultRegistry = createFilePilotRegistry(builtinParsers);
|
|
145
|
-
|
|
146
76
|
// src/react.tsx
|
|
147
77
|
var import_react = __toESM(require("react"), 1);
|
|
148
78
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
149
79
|
var normalizeLocale = (locale) => locale?.startsWith("en") ? "en-US" : "zh-CN";
|
|
80
|
+
var defaultRegistry = createFilePilotRegistry();
|
|
150
81
|
var viewerCache = /* @__PURE__ */ new WeakMap();
|
|
151
82
|
var getLazyViewerEntry = (parser) => {
|
|
152
83
|
const cached = viewerCache.get(parser);
|
|
@@ -197,7 +128,5 @@ var FilePilot = ({
|
|
|
197
128
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
129
|
0 && (module.exports = {
|
|
199
130
|
FilePilot,
|
|
200
|
-
|
|
201
|
-
createFilePilotRegistry,
|
|
202
|
-
defaultRegistry
|
|
131
|
+
createFilePilotRegistry
|
|
203
132
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FilePilotParser, FilePilotRegistry } from '@macrowing/filepilot-types';
|
|
2
2
|
export { FilePilotFile, FilePilotKind, FilePilotLocale, FilePilotParser, FilePilotProps, FilePilotRegistry, FilePilotRenderProps, FilePilotSource } from '@macrowing/filepilot-types';
|
|
3
|
-
export { builtinParsers, defaultRegistry } from './builtin.cjs';
|
|
4
3
|
export { FilePilot } from './react.cjs';
|
|
5
4
|
import 'react';
|
|
6
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FilePilotParser, FilePilotRegistry } from '@macrowing/filepilot-types';
|
|
2
2
|
export { FilePilotFile, FilePilotKind, FilePilotLocale, FilePilotParser, FilePilotProps, FilePilotRegistry, FilePilotRenderProps, FilePilotSource } from '@macrowing/filepilot-types';
|
|
3
|
-
export { builtinParsers, defaultRegistry } from './builtin.js';
|
|
4
3
|
export { FilePilot } from './react.js';
|
|
5
4
|
import 'react';
|
|
6
5
|
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FilePilot
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MTBYBLJA.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
defaultRegistry
|
|
8
|
-
} from "./chunk-EQYOJW24.js";
|
|
5
|
+
createFilePilotRegistry
|
|
6
|
+
} from "./chunk-KCRUK7FG.js";
|
|
9
7
|
export {
|
|
10
8
|
FilePilot,
|
|
11
|
-
|
|
12
|
-
createFilePilotRegistry,
|
|
13
|
-
defaultRegistry
|
|
9
|
+
createFilePilotRegistry
|
|
14
10
|
};
|
package/dist/react.cjs
CHANGED
|
@@ -73,77 +73,10 @@ var createFilePilotRegistry = (initialParsers = []) => {
|
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
// src/builtin.ts
|
|
77
|
-
var builtinParsers = [
|
|
78
|
-
{
|
|
79
|
-
id: "filepilot-parser-drawio",
|
|
80
|
-
kind: "drawing",
|
|
81
|
-
extensions: ["drawio", "dio"],
|
|
82
|
-
mimeTypes: ["application/vnd.jgraph.mxfile", "application/x-drawio", "application/drawio"],
|
|
83
|
-
load: () => import("@macrowing/filepilot-parser-drawio")
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
id: "filepilot-parser-viewer",
|
|
87
|
-
kind: "viewer",
|
|
88
|
-
extensions: ["md", "markdown", "mdx", "txt", "text", "log", "csv", "json", "xml", "yaml", "yml", "png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"],
|
|
89
|
-
mimeTypes: [
|
|
90
|
-
"text/markdown",
|
|
91
|
-
"text/x-markdown",
|
|
92
|
-
"text/plain",
|
|
93
|
-
"text/csv",
|
|
94
|
-
"application/json",
|
|
95
|
-
"application/xml",
|
|
96
|
-
"text/xml",
|
|
97
|
-
"image/png",
|
|
98
|
-
"image/jpeg",
|
|
99
|
-
"image/gif",
|
|
100
|
-
"image/webp",
|
|
101
|
-
"image/bmp",
|
|
102
|
-
"image/svg+xml"
|
|
103
|
-
],
|
|
104
|
-
load: () => import("@macrowing/filepilot-parser-viewer")
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
id: "filepilot-parser-pdf",
|
|
108
|
-
kind: "pdf",
|
|
109
|
-
extensions: ["pdf"],
|
|
110
|
-
mimeTypes: ["application/pdf"],
|
|
111
|
-
load: () => import("@macrowing/filepilot-parser-pdf")
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
id: "filepilot-parser-office",
|
|
115
|
-
kind: "office",
|
|
116
|
-
extensions: ["doc", "docx", "ppt", "pptx", "xls", "xlsx"],
|
|
117
|
-
mimeTypes: [
|
|
118
|
-
"application/msword",
|
|
119
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
120
|
-
"application/vnd.ms-powerpoint",
|
|
121
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
122
|
-
"application/vnd.ms-excel",
|
|
123
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
124
|
-
],
|
|
125
|
-
load: () => import("@macrowing/filepilot-parser-office")
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
id: "filepilot-parser-mmind",
|
|
129
|
-
kind: "mindmap",
|
|
130
|
-
extensions: ["mmind"],
|
|
131
|
-
mimeTypes: ["application/json", "application/x-mmind"],
|
|
132
|
-
load: () => import("@macrowing/filepilot-parser-mmind")
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
id: "filepilot-parser-mdoc",
|
|
136
|
-
kind: "docflow",
|
|
137
|
-
extensions: ["mdoc"],
|
|
138
|
-
mimeTypes: ["application/x-mdoc", "application/vnd.docflow.mdoc", "application/octet-stream"],
|
|
139
|
-
load: () => import("@macrowing/filepilot-parser-mdoc")
|
|
140
|
-
}
|
|
141
|
-
];
|
|
142
|
-
var defaultRegistry = createFilePilotRegistry(builtinParsers);
|
|
143
|
-
|
|
144
76
|
// src/react.tsx
|
|
145
77
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
146
78
|
var normalizeLocale = (locale) => locale?.startsWith("en") ? "en-US" : "zh-CN";
|
|
79
|
+
var defaultRegistry = createFilePilotRegistry();
|
|
147
80
|
var viewerCache = /* @__PURE__ */ new WeakMap();
|
|
148
81
|
var getLazyViewerEntry = (parser) => {
|
|
149
82
|
const cached = viewerCache.get(parser);
|
package/dist/react.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macrowing/filepilot",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Extensible, lazy-loaded React file preview toolkit.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -28,18 +28,38 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@macrowing/filepilot-
|
|
32
|
-
"@macrowing/filepilot-parser-mdoc": "0.1.0",
|
|
33
|
-
"@macrowing/filepilot-parser-mmind": "0.1.0",
|
|
34
|
-
"@macrowing/filepilot-parser-pdf": "0.1.0",
|
|
35
|
-
"@macrowing/filepilot-parser-office": "0.1.0",
|
|
36
|
-
"@macrowing/filepilot-types": "0.1.0",
|
|
37
|
-
"@macrowing/filepilot-parser-viewer": "0.1.0"
|
|
31
|
+
"@macrowing/filepilot-types": "0.1.0"
|
|
38
32
|
},
|
|
39
33
|
"peerDependencies": {
|
|
34
|
+
"@macrowing/filepilot-parser-drawio": "^0.1.0",
|
|
35
|
+
"@macrowing/filepilot-parser-mdoc": "^0.1.0",
|
|
36
|
+
"@macrowing/filepilot-parser-mmind": "^0.1.0",
|
|
37
|
+
"@macrowing/filepilot-parser-office": "^0.1.0",
|
|
38
|
+
"@macrowing/filepilot-parser-pdf": "^0.1.0",
|
|
39
|
+
"@macrowing/filepilot-parser-viewer": "^0.1.0",
|
|
40
40
|
"react": ">=18.2.0 || >=19.0.0",
|
|
41
41
|
"react-dom": ">=18.2.0 || >=19.0.0"
|
|
42
42
|
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@macrowing/filepilot-parser-drawio": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"@macrowing/filepilot-parser-mdoc": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"@macrowing/filepilot-parser-mmind": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@macrowing/filepilot-parser-office": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"@macrowing/filepilot-parser-pdf": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"@macrowing/filepilot-parser-viewer": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
43
63
|
"devDependencies": {
|
|
44
64
|
"rimraf": "^6.0.1",
|
|
45
65
|
"tsup": "^8.4.0"
|
package/dist/chunk-EQYOJW24.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// src/registry.ts
|
|
2
|
-
var normalizeExtension = (extension) => extension?.replace(/^\./, "").toLowerCase();
|
|
3
|
-
var getFileExtension = (file) => {
|
|
4
|
-
if (file.extension) return normalizeExtension(file.extension);
|
|
5
|
-
const name = file.name?.split(/[?#]/)[0];
|
|
6
|
-
const index = name?.lastIndexOf(".") ?? -1;
|
|
7
|
-
return index >= 0 ? normalizeExtension(name?.slice(index + 1)) : void 0;
|
|
8
|
-
};
|
|
9
|
-
var hasExtensionMatch = (parser, extension) => Boolean(
|
|
10
|
-
extension && parser.extensions.some((item) => normalizeExtension(item) === extension)
|
|
11
|
-
);
|
|
12
|
-
var hasMimeTypeMatch = (parser, mimeType) => Boolean(
|
|
13
|
-
mimeType && parser.mimeTypes?.some((item) => item.toLowerCase() === mimeType)
|
|
14
|
-
);
|
|
15
|
-
var createFilePilotRegistry = (initialParsers = []) => {
|
|
16
|
-
const parsers = /* @__PURE__ */ new Map();
|
|
17
|
-
initialParsers.forEach((parser) => parsers.set(parser.id, parser));
|
|
18
|
-
return {
|
|
19
|
-
register(parser) {
|
|
20
|
-
parsers.set(parser.id, parser);
|
|
21
|
-
return () => parsers.delete(parser.id);
|
|
22
|
-
},
|
|
23
|
-
unregister(id) {
|
|
24
|
-
parsers.delete(id);
|
|
25
|
-
},
|
|
26
|
-
resolve(file, parserId) {
|
|
27
|
-
const extension = getFileExtension(file);
|
|
28
|
-
const mimeType = file.mimeType?.toLowerCase();
|
|
29
|
-
if (parserId) return parsers.get(parserId);
|
|
30
|
-
const list = Array.from(parsers.values());
|
|
31
|
-
return list.find((parser) => hasExtensionMatch(parser, extension)) ?? list.find((parser) => hasMimeTypeMatch(parser, mimeType));
|
|
32
|
-
},
|
|
33
|
-
list() {
|
|
34
|
-
return Array.from(parsers.values());
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/builtin.ts
|
|
40
|
-
var builtinParsers = [
|
|
41
|
-
{
|
|
42
|
-
id: "filepilot-parser-drawio",
|
|
43
|
-
kind: "drawing",
|
|
44
|
-
extensions: ["drawio", "dio"],
|
|
45
|
-
mimeTypes: ["application/vnd.jgraph.mxfile", "application/x-drawio", "application/drawio"],
|
|
46
|
-
load: () => import("@macrowing/filepilot-parser-drawio")
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
id: "filepilot-parser-viewer",
|
|
50
|
-
kind: "viewer",
|
|
51
|
-
extensions: ["md", "markdown", "mdx", "txt", "text", "log", "csv", "json", "xml", "yaml", "yml", "png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"],
|
|
52
|
-
mimeTypes: [
|
|
53
|
-
"text/markdown",
|
|
54
|
-
"text/x-markdown",
|
|
55
|
-
"text/plain",
|
|
56
|
-
"text/csv",
|
|
57
|
-
"application/json",
|
|
58
|
-
"application/xml",
|
|
59
|
-
"text/xml",
|
|
60
|
-
"image/png",
|
|
61
|
-
"image/jpeg",
|
|
62
|
-
"image/gif",
|
|
63
|
-
"image/webp",
|
|
64
|
-
"image/bmp",
|
|
65
|
-
"image/svg+xml"
|
|
66
|
-
],
|
|
67
|
-
load: () => import("@macrowing/filepilot-parser-viewer")
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: "filepilot-parser-pdf",
|
|
71
|
-
kind: "pdf",
|
|
72
|
-
extensions: ["pdf"],
|
|
73
|
-
mimeTypes: ["application/pdf"],
|
|
74
|
-
load: () => import("@macrowing/filepilot-parser-pdf")
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: "filepilot-parser-office",
|
|
78
|
-
kind: "office",
|
|
79
|
-
extensions: ["doc", "docx", "ppt", "pptx", "xls", "xlsx"],
|
|
80
|
-
mimeTypes: [
|
|
81
|
-
"application/msword",
|
|
82
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
83
|
-
"application/vnd.ms-powerpoint",
|
|
84
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
85
|
-
"application/vnd.ms-excel",
|
|
86
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
87
|
-
],
|
|
88
|
-
load: () => import("@macrowing/filepilot-parser-office")
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
id: "filepilot-parser-mmind",
|
|
92
|
-
kind: "mindmap",
|
|
93
|
-
extensions: ["mmind"],
|
|
94
|
-
mimeTypes: ["application/json", "application/x-mmind"],
|
|
95
|
-
load: () => import("@macrowing/filepilot-parser-mmind")
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
id: "filepilot-parser-mdoc",
|
|
99
|
-
kind: "docflow",
|
|
100
|
-
extensions: ["mdoc"],
|
|
101
|
-
mimeTypes: ["application/x-mdoc", "application/vnd.docflow.mdoc", "application/octet-stream"],
|
|
102
|
-
load: () => import("@macrowing/filepilot-parser-mdoc")
|
|
103
|
-
}
|
|
104
|
-
];
|
|
105
|
-
var defaultRegistry = createFilePilotRegistry(builtinParsers);
|
|
106
|
-
|
|
107
|
-
export {
|
|
108
|
-
createFilePilotRegistry,
|
|
109
|
-
builtinParsers,
|
|
110
|
-
defaultRegistry
|
|
111
|
-
};
|