@tutti-os/workspace-file-preview 0.0.190 → 0.0.192
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/README.md +25 -15
- package/dist/{chunk-SUQYO7VX.js → chunk-SDSS6OA5.js} +256 -178
- package/dist/chunk-SDSS6OA5.js.map +1 -0
- package/dist/core/index.d.ts +112 -26
- package/dist/core/index.js +17 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -11
- package/dist/react/index.d.ts +65 -2
- package/dist/react/index.js +121 -1
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-SUQYO7VX.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/core/
|
|
1
|
+
// src/core/workspaceFilePreviewKinds.ts
|
|
2
2
|
var imageExtensions = /* @__PURE__ */ new Set([
|
|
3
3
|
"avif",
|
|
4
4
|
"gif",
|
|
@@ -8,13 +8,6 @@ var imageExtensions = /* @__PURE__ */ new Set([
|
|
|
8
8
|
"svg",
|
|
9
9
|
"webp"
|
|
10
10
|
]);
|
|
11
|
-
var browserOpenableHtmlExtensions = /* @__PURE__ */ new Set([
|
|
12
|
-
"htm",
|
|
13
|
-
"html",
|
|
14
|
-
"shtml",
|
|
15
|
-
"xhtml"
|
|
16
|
-
]);
|
|
17
|
-
var browserOpenableVideoExtensions = /* @__PURE__ */ new Set(["mp4", "webm"]);
|
|
18
11
|
var videoExtensions = /* @__PURE__ */ new Set([
|
|
19
12
|
"avi",
|
|
20
13
|
"m2ts",
|
|
@@ -27,8 +20,25 @@ var videoExtensions = /* @__PURE__ */ new Set([
|
|
|
27
20
|
"webm",
|
|
28
21
|
"wmv"
|
|
29
22
|
]);
|
|
30
|
-
var
|
|
23
|
+
var workspaceFileBrowserVideoExtensions = /* @__PURE__ */ new Set(["mp4", "webm"]);
|
|
24
|
+
var audioExtensions = /* @__PURE__ */ new Set([
|
|
25
|
+
"aac",
|
|
26
|
+
"flac",
|
|
27
|
+
"m4a",
|
|
28
|
+
"mp3",
|
|
29
|
+
"oga",
|
|
30
|
+
"ogg",
|
|
31
|
+
"opus",
|
|
32
|
+
"wav"
|
|
33
|
+
]);
|
|
31
34
|
var markdownExtensions = /* @__PURE__ */ new Set(["md", "mdx"]);
|
|
35
|
+
var jsonExtensions = /* @__PURE__ */ new Set(["json", "jsonc"]);
|
|
36
|
+
var csvExtensions = /* @__PURE__ */ new Set(["csv", "tsv"]);
|
|
37
|
+
var htmlExtensions = /* @__PURE__ */ new Set(["htm", "html", "shtml", "xhtml"]);
|
|
38
|
+
var pdfExtensions = /* @__PURE__ */ new Set(["pdf"]);
|
|
39
|
+
var docxExtensions = /* @__PURE__ */ new Set(["docx"]);
|
|
40
|
+
var xlsxExtensions = /* @__PURE__ */ new Set(["xlsx"]);
|
|
41
|
+
var pptxExtensions = /* @__PURE__ */ new Set(["pptx"]);
|
|
32
42
|
var codeExtensions = /* @__PURE__ */ new Set([
|
|
33
43
|
"bash",
|
|
34
44
|
"c",
|
|
@@ -40,11 +50,10 @@ var codeExtensions = /* @__PURE__ */ new Set([
|
|
|
40
50
|
"go",
|
|
41
51
|
"h",
|
|
42
52
|
"hpp",
|
|
43
|
-
"
|
|
53
|
+
"ini",
|
|
44
54
|
"java",
|
|
45
55
|
"js",
|
|
46
56
|
"jsx",
|
|
47
|
-
"json",
|
|
48
57
|
"lua",
|
|
49
58
|
"m",
|
|
50
59
|
"mm",
|
|
@@ -65,7 +74,16 @@ var codeExtensions = /* @__PURE__ */ new Set([
|
|
|
65
74
|
"yml",
|
|
66
75
|
"zsh"
|
|
67
76
|
]);
|
|
68
|
-
var
|
|
77
|
+
var plainTextExtensions = /* @__PURE__ */ new Set(["env", "log", "txt"]);
|
|
78
|
+
var textFileNames = /* @__PURE__ */ new Set([
|
|
79
|
+
".gitignore",
|
|
80
|
+
".npmrc",
|
|
81
|
+
".nvmrc",
|
|
82
|
+
"dockerfile",
|
|
83
|
+
"makefile",
|
|
84
|
+
"readme"
|
|
85
|
+
]);
|
|
86
|
+
var documentVisualExtensions = /* @__PURE__ */ new Set([
|
|
69
87
|
"csv",
|
|
70
88
|
"doc",
|
|
71
89
|
"docx",
|
|
@@ -76,61 +94,39 @@ var documentExtensions = /* @__PURE__ */ new Set([
|
|
|
76
94
|
"xls",
|
|
77
95
|
"xlsx"
|
|
78
96
|
]);
|
|
79
|
-
var
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"conf",
|
|
84
|
-
"cpp",
|
|
85
|
-
"cs",
|
|
86
|
-
"css",
|
|
87
|
-
"csv",
|
|
88
|
-
"env",
|
|
89
|
-
"go",
|
|
90
|
-
"h",
|
|
91
|
-
"hpp",
|
|
92
|
-
"html",
|
|
93
|
-
"ini",
|
|
94
|
-
"java",
|
|
95
|
-
"js",
|
|
97
|
+
var textDegradablePreviewKinds = /* @__PURE__ */ new Set([
|
|
98
|
+
"text",
|
|
99
|
+
"code",
|
|
100
|
+
"markdown",
|
|
96
101
|
"json",
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"lua",
|
|
100
|
-
"m",
|
|
101
|
-
"md",
|
|
102
|
-
"mdx",
|
|
103
|
-
"mm",
|
|
104
|
-
"php",
|
|
105
|
-
"plist",
|
|
106
|
-
"proto",
|
|
107
|
-
"py",
|
|
108
|
-
"rb",
|
|
109
|
-
"rs",
|
|
110
|
-
"sh",
|
|
111
|
-
"sql",
|
|
112
|
-
"swift",
|
|
113
|
-
"toml",
|
|
114
|
-
"ts",
|
|
115
|
-
"tsx",
|
|
116
|
-
"txt",
|
|
117
|
-
"xml",
|
|
118
|
-
"yaml",
|
|
119
|
-
"yml",
|
|
120
|
-
"zsh"
|
|
121
|
-
]);
|
|
122
|
-
var textFileNames = /* @__PURE__ */ new Set([
|
|
123
|
-
".gitignore",
|
|
124
|
-
".npmrc",
|
|
125
|
-
".nvmrc",
|
|
126
|
-
"dockerfile",
|
|
127
|
-
"makefile",
|
|
128
|
-
"readme"
|
|
102
|
+
"csv",
|
|
103
|
+
"html"
|
|
129
104
|
]);
|
|
130
|
-
|
|
131
|
-
|
|
105
|
+
function resolveWorkspaceFileExtension(pathOrName) {
|
|
106
|
+
const name = pathOrName.split("/").pop()?.trim().toLowerCase() ?? "";
|
|
107
|
+
const dotIndex = name.lastIndexOf(".");
|
|
108
|
+
return dotIndex > 0 ? name.slice(dotIndex + 1) : "";
|
|
109
|
+
}
|
|
110
|
+
function resolveWorkspaceFilePreviewName(entry) {
|
|
111
|
+
return entry.name?.trim() || entry.path.split("/").pop()?.trim() || entry.path;
|
|
112
|
+
}
|
|
113
|
+
function isWorkspaceFileDirectoryKind(kind) {
|
|
114
|
+
return kind === "directory" || kind === "folder";
|
|
115
|
+
}
|
|
116
|
+
function isTextDegradablePreviewKind(kind) {
|
|
117
|
+
return textDegradablePreviewKinds.has(kind);
|
|
118
|
+
}
|
|
119
|
+
function resolveWorkspaceFileBuiltinRenderKind(kind) {
|
|
120
|
+
if (kind === "image" || kind === "video") {
|
|
121
|
+
return kind;
|
|
122
|
+
}
|
|
123
|
+
if (isTextDegradablePreviewKind(kind)) {
|
|
124
|
+
return "text";
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
132
128
|
function resolveWorkspaceFileVisualKind(entry) {
|
|
133
|
-
if (entry.kind
|
|
129
|
+
if (isWorkspaceFileDirectoryKind(entry.kind)) {
|
|
134
130
|
return "directory";
|
|
135
131
|
}
|
|
136
132
|
const extension = resolveWorkspaceFileExtension(
|
|
@@ -145,49 +141,82 @@ function resolveWorkspaceFileVisualKind(entry) {
|
|
|
145
141
|
if (markdownExtensions.has(extension)) {
|
|
146
142
|
return "markdown";
|
|
147
143
|
}
|
|
148
|
-
if (codeExtensions.has(extension)) {
|
|
144
|
+
if (codeExtensions.has(extension) || jsonExtensions.has(extension)) {
|
|
149
145
|
return "code";
|
|
150
146
|
}
|
|
151
|
-
if (
|
|
147
|
+
if (documentVisualExtensions.has(extension) || htmlExtensions.has(extension) || pptxExtensions.has(extension)) {
|
|
152
148
|
return "document";
|
|
153
149
|
}
|
|
154
150
|
return "binary";
|
|
155
151
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
function isWorkspaceFileBrowserOpenable(entry) {
|
|
152
|
+
function classifyWorkspaceFilePreviewKind(entry) {
|
|
153
|
+
if (isWorkspaceFileDirectoryKind(entry.kind)) {
|
|
154
|
+
return "directory";
|
|
155
|
+
}
|
|
162
156
|
if (entry.kind !== "file") {
|
|
163
|
-
return
|
|
157
|
+
return "unsupported";
|
|
164
158
|
}
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
);
|
|
168
|
-
if (
|
|
169
|
-
return
|
|
159
|
+
const name = resolveWorkspaceFilePreviewName(entry);
|
|
160
|
+
const extension = resolveWorkspaceFileExtension(name);
|
|
161
|
+
const normalizedName = name.trim().toLowerCase();
|
|
162
|
+
if (imageExtensions.has(extension)) {
|
|
163
|
+
return "image";
|
|
170
164
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
function shouldFilterVideoPlayersForOpenWith(entry) {
|
|
174
|
-
if (entry.kind !== "file") {
|
|
175
|
-
return false;
|
|
165
|
+
if (videoExtensions.has(extension)) {
|
|
166
|
+
return "video";
|
|
176
167
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return false;
|
|
168
|
+
if (audioExtensions.has(extension)) {
|
|
169
|
+
return "audio";
|
|
180
170
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
);
|
|
184
|
-
if (workspaceFileVideoHandlerCollisionExtensions.has(extension)) {
|
|
185
|
-
return true;
|
|
171
|
+
if (markdownExtensions.has(extension)) {
|
|
172
|
+
return "markdown";
|
|
186
173
|
}
|
|
187
|
-
if (
|
|
188
|
-
return
|
|
174
|
+
if (jsonExtensions.has(extension)) {
|
|
175
|
+
return "json";
|
|
176
|
+
}
|
|
177
|
+
if (csvExtensions.has(extension)) {
|
|
178
|
+
return "csv";
|
|
179
|
+
}
|
|
180
|
+
if (htmlExtensions.has(extension)) {
|
|
181
|
+
return "html";
|
|
182
|
+
}
|
|
183
|
+
if (pdfExtensions.has(extension)) {
|
|
184
|
+
return "pdf";
|
|
185
|
+
}
|
|
186
|
+
if (docxExtensions.has(extension)) {
|
|
187
|
+
return "docx";
|
|
188
|
+
}
|
|
189
|
+
if (xlsxExtensions.has(extension)) {
|
|
190
|
+
return "xlsx";
|
|
189
191
|
}
|
|
190
|
-
|
|
192
|
+
if (pptxExtensions.has(extension)) {
|
|
193
|
+
return "pptx";
|
|
194
|
+
}
|
|
195
|
+
if (codeExtensions.has(extension)) {
|
|
196
|
+
return "code";
|
|
197
|
+
}
|
|
198
|
+
if (plainTextExtensions.has(extension) || textFileNames.has(normalizedName)) {
|
|
199
|
+
return "text";
|
|
200
|
+
}
|
|
201
|
+
return "unsupported";
|
|
202
|
+
}
|
|
203
|
+
function resolveWorkspaceFilePreviewTarget(entry) {
|
|
204
|
+
const previewKind = classifyWorkspaceFilePreviewKind(entry);
|
|
205
|
+
if (resolveWorkspaceFileBuiltinRenderKind(previewKind) === null) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
const target = {
|
|
209
|
+
previewKind,
|
|
210
|
+
name: resolveWorkspaceFilePreviewName(entry),
|
|
211
|
+
path: entry.path
|
|
212
|
+
};
|
|
213
|
+
if (entry.mtimeMs !== void 0) {
|
|
214
|
+
target.mtimeMs = entry.mtimeMs;
|
|
215
|
+
}
|
|
216
|
+
if (entry.sizeBytes !== void 0) {
|
|
217
|
+
target.sizeBytes = entry.sizeBytes;
|
|
218
|
+
}
|
|
219
|
+
return target;
|
|
191
220
|
}
|
|
192
221
|
function resolveWorkspaceImageMimeType(pathOrName) {
|
|
193
222
|
switch (resolveWorkspaceFileExtension(pathOrName)) {
|
|
@@ -218,57 +247,35 @@ function resolveWorkspaceVideoMimeType(pathOrName) {
|
|
|
218
247
|
return null;
|
|
219
248
|
}
|
|
220
249
|
}
|
|
221
|
-
function
|
|
222
|
-
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
const name = resolveWorkspaceFilePreviewName(entry);
|
|
226
|
-
if (resolveWorkspaceImageMimeType(name) !== null) {
|
|
227
|
-
return "image";
|
|
228
|
-
}
|
|
229
|
-
if (resolveWorkspaceVideoMimeType(name) !== null) {
|
|
230
|
-
return "video";
|
|
231
|
-
}
|
|
232
|
-
const normalizedName = name.trim().toLowerCase();
|
|
233
|
-
const extension = resolveWorkspaceFileExtension(name);
|
|
234
|
-
if (textExtensions.has(extension) || textFileNames.has(normalizedName)) {
|
|
235
|
-
return "text";
|
|
236
|
-
}
|
|
237
|
-
return null;
|
|
250
|
+
function isWorkspaceFileBrowserHtmlExtension(extension) {
|
|
251
|
+
return htmlExtensions.has(extension);
|
|
238
252
|
}
|
|
239
|
-
function
|
|
240
|
-
|
|
241
|
-
if (!fileKind) {
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
const target = {
|
|
245
|
-
fileKind,
|
|
246
|
-
name: resolveWorkspaceFilePreviewName(entry),
|
|
247
|
-
path: entry.path
|
|
248
|
-
};
|
|
249
|
-
if (entry.mtimeMs !== void 0) {
|
|
250
|
-
target.mtimeMs = entry.mtimeMs;
|
|
251
|
-
}
|
|
252
|
-
if (entry.sizeBytes !== void 0) {
|
|
253
|
-
target.sizeBytes = entry.sizeBytes;
|
|
254
|
-
}
|
|
255
|
-
return target;
|
|
253
|
+
function isWorkspaceFileImageExtension(extension) {
|
|
254
|
+
return imageExtensions.has(extension);
|
|
256
255
|
}
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
|
|
257
|
+
// src/core/workspaceFilePreview.ts
|
|
258
|
+
var workspaceFileTextMaxBytes = 1024 * 1024;
|
|
259
|
+
var workspaceFilePreviewMaxBytes = 20 * 1024 * 1024;
|
|
260
|
+
function resolveWorkspaceFilePreviewReadiness(entry, options) {
|
|
261
|
+
const previewKind = classifyWorkspaceFilePreviewKind(entry);
|
|
262
|
+
if (previewKind === "directory") {
|
|
259
263
|
return {
|
|
260
264
|
entry,
|
|
261
265
|
status: "directory"
|
|
262
266
|
};
|
|
263
267
|
}
|
|
264
|
-
const
|
|
265
|
-
|
|
268
|
+
const builtin = resolveWorkspaceFileBuiltinRenderKind(previewKind);
|
|
269
|
+
const hostRenderable = options?.hasHostRenderer?.(previewKind) === true && previewKind !== "unsupported";
|
|
270
|
+
if (!builtin && !hostRenderable) {
|
|
266
271
|
return {
|
|
267
272
|
entry,
|
|
273
|
+
previewKind,
|
|
268
274
|
status: "unsupported"
|
|
269
275
|
};
|
|
270
276
|
}
|
|
271
|
-
|
|
277
|
+
const target = resolveWorkspaceFilePreviewTarget(entry) ?? createWorkspaceFilePreviewTarget(entry, previewKind);
|
|
278
|
+
if ((builtin === "text" || isTextDegradablePreviewKind(previewKind)) && isWorkspaceTextFileTooLarge(entry.sizeBytes)) {
|
|
272
279
|
return {
|
|
273
280
|
entry,
|
|
274
281
|
maxSizeBytes: workspaceFileTextMaxBytes,
|
|
@@ -291,22 +298,35 @@ function resolveWorkspaceFilePreviewReadiness(entry) {
|
|
|
291
298
|
};
|
|
292
299
|
}
|
|
293
300
|
function createWorkspaceFilePreviewLoadedState(input) {
|
|
294
|
-
|
|
301
|
+
const previewKind = input.target.previewKind;
|
|
302
|
+
const builtin = resolveWorkspaceFileBuiltinRenderKind(previewKind);
|
|
303
|
+
if (builtin === "image") {
|
|
295
304
|
return {
|
|
296
305
|
bytes: copyWorkspaceFilePreviewBytes(input.bytes),
|
|
297
306
|
contentType: input.contentType ?? resolveWorkspaceImageMimeType(input.target.name) ?? "application/octet-stream",
|
|
298
307
|
entry: input.target,
|
|
308
|
+
previewKind: "image",
|
|
299
309
|
status: "image"
|
|
300
310
|
};
|
|
301
311
|
}
|
|
302
|
-
if (
|
|
312
|
+
if (builtin === "video") {
|
|
303
313
|
return {
|
|
304
314
|
bytes: copyWorkspaceFilePreviewBytes(input.bytes),
|
|
305
315
|
contentType: input.contentType ?? resolveWorkspaceVideoMimeType(input.target.name) ?? "application/octet-stream",
|
|
306
316
|
entry: input.target,
|
|
317
|
+
previewKind: "video",
|
|
307
318
|
status: "video"
|
|
308
319
|
};
|
|
309
320
|
}
|
|
321
|
+
if (input.preferHostBytes || builtin === null) {
|
|
322
|
+
return {
|
|
323
|
+
bytes: copyWorkspaceFilePreviewBytes(input.bytes),
|
|
324
|
+
contentType: input.contentType ?? null,
|
|
325
|
+
entry: input.target,
|
|
326
|
+
previewKind,
|
|
327
|
+
status: "bytes"
|
|
328
|
+
};
|
|
329
|
+
}
|
|
310
330
|
try {
|
|
311
331
|
const content = decodeWorkspaceTextFile(input.bytes);
|
|
312
332
|
if (looksLikeBinaryText(content)) {
|
|
@@ -319,6 +339,7 @@ function createWorkspaceFilePreviewLoadedState(input) {
|
|
|
319
339
|
return {
|
|
320
340
|
content,
|
|
321
341
|
entry: input.target,
|
|
342
|
+
previewKind,
|
|
322
343
|
status: "text"
|
|
323
344
|
};
|
|
324
345
|
} catch {
|
|
@@ -329,9 +350,6 @@ function createWorkspaceFilePreviewLoadedState(input) {
|
|
|
329
350
|
};
|
|
330
351
|
}
|
|
331
352
|
}
|
|
332
|
-
function resolveWorkspaceFilePreviewName(entry) {
|
|
333
|
-
return entry.name?.trim() || entry.displayName?.trim() || entry.path.split("/").pop()?.trim() || entry.path;
|
|
334
|
-
}
|
|
335
353
|
function isWorkspaceTextFileTooLarge(sizeBytes) {
|
|
336
354
|
return typeof sizeBytes === "number" && Number.isFinite(sizeBytes) && sizeBytes > workspaceFileTextMaxBytes;
|
|
337
355
|
}
|
|
@@ -385,6 +403,20 @@ function formatWorkspacePreviewByteLimit(sizeBytes) {
|
|
|
385
403
|
}
|
|
386
404
|
return `${mebibytes.toFixed(1)} MiB`;
|
|
387
405
|
}
|
|
406
|
+
function createWorkspaceFilePreviewTarget(entry, previewKind) {
|
|
407
|
+
const target = {
|
|
408
|
+
previewKind,
|
|
409
|
+
name: resolveWorkspaceFilePreviewName(entry),
|
|
410
|
+
path: entry.path
|
|
411
|
+
};
|
|
412
|
+
if (entry.mtimeMs !== void 0) {
|
|
413
|
+
target.mtimeMs = entry.mtimeMs;
|
|
414
|
+
}
|
|
415
|
+
if (entry.sizeBytes !== void 0) {
|
|
416
|
+
target.sizeBytes = entry.sizeBytes;
|
|
417
|
+
}
|
|
418
|
+
return target;
|
|
419
|
+
}
|
|
388
420
|
|
|
389
421
|
// src/core/workspaceFilePreviewController.ts
|
|
390
422
|
function createWorkspaceFilePreviewController(input) {
|
|
@@ -476,21 +508,29 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
476
508
|
if (!result) {
|
|
477
509
|
this.updateState({
|
|
478
510
|
entry,
|
|
511
|
+
previewKind: target.previewKind,
|
|
479
512
|
reason: "file_type",
|
|
480
513
|
status: "unsupported"
|
|
481
514
|
});
|
|
482
515
|
return;
|
|
483
516
|
}
|
|
517
|
+
const resolvedKind = result.kind ?? target.previewKind;
|
|
518
|
+
const resolvedTarget = {
|
|
519
|
+
...target,
|
|
520
|
+
previewKind: resolvedKind
|
|
521
|
+
};
|
|
522
|
+
const preferHostBytes = resolveWorkspaceFileBuiltinRenderKind(resolvedKind) === null;
|
|
484
523
|
const loaded = createWorkspaceFilePreviewLoadedState({
|
|
485
|
-
bytes: result
|
|
486
|
-
contentType: result
|
|
524
|
+
bytes: result.bytes,
|
|
525
|
+
contentType: result.contentType,
|
|
487
526
|
entry: previewEntry,
|
|
488
|
-
|
|
527
|
+
preferHostBytes,
|
|
528
|
+
target: resolvedTarget
|
|
489
529
|
});
|
|
490
530
|
if (this.isStale(generation)) {
|
|
491
531
|
return;
|
|
492
532
|
}
|
|
493
|
-
if (loaded.status === "image"
|
|
533
|
+
if (loaded.status === "image") {
|
|
494
534
|
const previewSizeBytes = loaded.bytes.byteLength;
|
|
495
535
|
const objectUrl = this.objectUrls.create(
|
|
496
536
|
loaded.bytes,
|
|
@@ -504,8 +544,29 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
504
544
|
this.updateState({
|
|
505
545
|
entry,
|
|
506
546
|
objectUrl,
|
|
547
|
+
previewKind: "image",
|
|
507
548
|
previewSizeBytes,
|
|
508
|
-
status:
|
|
549
|
+
status: "image"
|
|
550
|
+
});
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
if (loaded.status === "video") {
|
|
554
|
+
const previewSizeBytes = loaded.bytes.byteLength;
|
|
555
|
+
const objectUrl = this.objectUrls.create(
|
|
556
|
+
loaded.bytes,
|
|
557
|
+
loaded.contentType
|
|
558
|
+
);
|
|
559
|
+
if (this.isStale(generation)) {
|
|
560
|
+
this.objectUrls.revoke(objectUrl);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
this.objectUrl = objectUrl;
|
|
564
|
+
this.updateState({
|
|
565
|
+
entry,
|
|
566
|
+
objectUrl,
|
|
567
|
+
previewKind: "video",
|
|
568
|
+
previewSizeBytes,
|
|
569
|
+
status: "video"
|
|
509
570
|
});
|
|
510
571
|
return;
|
|
511
572
|
}
|
|
@@ -513,14 +574,27 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
513
574
|
this.updateState({
|
|
514
575
|
content: loaded.content,
|
|
515
576
|
entry,
|
|
516
|
-
|
|
577
|
+
previewKind: loaded.previewKind,
|
|
578
|
+
previewSizeBytes: result.bytes.byteLength,
|
|
517
579
|
status: "text"
|
|
518
580
|
});
|
|
519
581
|
return;
|
|
520
582
|
}
|
|
583
|
+
if (loaded.status === "bytes") {
|
|
584
|
+
this.updateState({
|
|
585
|
+
bytes: loaded.bytes,
|
|
586
|
+
contentType: loaded.contentType,
|
|
587
|
+
entry,
|
|
588
|
+
previewKind: loaded.previewKind,
|
|
589
|
+
previewSizeBytes: loaded.bytes.byteLength,
|
|
590
|
+
status: "bytes"
|
|
591
|
+
});
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
521
594
|
this.updateState({
|
|
522
595
|
entry,
|
|
523
|
-
|
|
596
|
+
previewKind: target.previewKind,
|
|
597
|
+
previewSizeBytes: result.bytes.byteLength,
|
|
524
598
|
reason: loaded.reason,
|
|
525
599
|
...loaded.maxSizeBytes === void 0 ? {} : { maxSizeBytes: loaded.maxSizeBytes },
|
|
526
600
|
status: "readonly"
|
|
@@ -529,7 +603,12 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
529
603
|
if (this.isStale(generation)) {
|
|
530
604
|
return;
|
|
531
605
|
}
|
|
532
|
-
this.updateState({
|
|
606
|
+
this.updateState({
|
|
607
|
+
entry,
|
|
608
|
+
error,
|
|
609
|
+
previewKind: target.previewKind,
|
|
610
|
+
status: "error"
|
|
611
|
+
});
|
|
533
612
|
} finally {
|
|
534
613
|
if (!this.isStale(generation)) {
|
|
535
614
|
this.abortController = null;
|
|
@@ -545,7 +624,6 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
545
624
|
previewEntry.kind,
|
|
546
625
|
previewEntry.path,
|
|
547
626
|
previewEntry.name ?? "",
|
|
548
|
-
previewEntry.displayName ?? "",
|
|
549
627
|
previewEntry.sizeBytes ?? "",
|
|
550
628
|
previewEntry.mtimeMs ?? ""
|
|
551
629
|
].join("\0");
|
|
@@ -561,7 +639,9 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
561
639
|
this.cancelLoad();
|
|
562
640
|
this.revokeObjectUrl();
|
|
563
641
|
const previewEntry = this.input.toPreviewEntry(entry);
|
|
564
|
-
const readiness = resolveWorkspaceFilePreviewReadiness(previewEntry
|
|
642
|
+
const readiness = resolveWorkspaceFilePreviewReadiness(previewEntry, {
|
|
643
|
+
hasHostRenderer: this.input.hasHostRenderer
|
|
644
|
+
});
|
|
565
645
|
if (readiness.status === "directory") {
|
|
566
646
|
this.updateState({ entry, status: "directory" });
|
|
567
647
|
this.loadPromise = Promise.resolve();
|
|
@@ -581,6 +661,7 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
581
661
|
if (canRead !== true) {
|
|
582
662
|
this.updateState({
|
|
583
663
|
entry,
|
|
664
|
+
previewKind: readiness.previewKind,
|
|
584
665
|
reason: "file_type",
|
|
585
666
|
status: "unsupported"
|
|
586
667
|
});
|
|
@@ -590,6 +671,7 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
590
671
|
if (!this.input.read) {
|
|
591
672
|
this.updateState({
|
|
592
673
|
entry,
|
|
674
|
+
previewKind: readiness.previewKind,
|
|
593
675
|
reason: "reader_unavailable",
|
|
594
676
|
status: "unsupported"
|
|
595
677
|
});
|
|
@@ -597,24 +679,13 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
597
679
|
return this.loadPromise;
|
|
598
680
|
}
|
|
599
681
|
const target = {
|
|
600
|
-
|
|
601
|
-
name: previewEntry.name ?? previewEntry.
|
|
682
|
+
previewKind: "text",
|
|
683
|
+
name: previewEntry.name ?? previewEntry.path.split("/").pop() ?? previewEntry.path,
|
|
602
684
|
path: previewEntry.path,
|
|
603
685
|
...previewEntry.mtimeMs === void 0 ? {} : { mtimeMs: previewEntry.mtimeMs },
|
|
604
686
|
...previewEntry.sizeBytes === void 0 ? {} : { sizeBytes: previewEntry.sizeBytes }
|
|
605
687
|
};
|
|
606
|
-
|
|
607
|
-
this.abortController = abortController2;
|
|
608
|
-
const generation2 = this.generation;
|
|
609
|
-
this.updateState({ entry, status: "loading" });
|
|
610
|
-
this.loadPromise = this.load(
|
|
611
|
-
entry,
|
|
612
|
-
previewEntry,
|
|
613
|
-
target,
|
|
614
|
-
generation2,
|
|
615
|
-
abortController2
|
|
616
|
-
);
|
|
617
|
-
return this.loadPromise;
|
|
688
|
+
return this.beginLoad(entry, previewEntry, target);
|
|
618
689
|
}
|
|
619
690
|
if (readiness.status === "readonly") {
|
|
620
691
|
this.updateState({
|
|
@@ -629,20 +700,28 @@ var WorkspaceFilePreviewControllerImpl = class {
|
|
|
629
700
|
if (!this.input.read) {
|
|
630
701
|
this.updateState({
|
|
631
702
|
entry,
|
|
703
|
+
previewKind: readiness.target.previewKind,
|
|
632
704
|
reason: "reader_unavailable",
|
|
633
705
|
status: "unsupported"
|
|
634
706
|
});
|
|
635
707
|
this.loadPromise = Promise.resolve();
|
|
636
708
|
return this.loadPromise;
|
|
637
709
|
}
|
|
710
|
+
return this.beginLoad(entry, previewEntry, readiness.target);
|
|
711
|
+
}
|
|
712
|
+
beginLoad(entry, previewEntry, target) {
|
|
638
713
|
const abortController = new AbortController();
|
|
639
714
|
this.abortController = abortController;
|
|
640
715
|
const generation = this.generation;
|
|
641
|
-
this.updateState({
|
|
716
|
+
this.updateState({
|
|
717
|
+
entry,
|
|
718
|
+
previewKind: target.previewKind,
|
|
719
|
+
status: "loading"
|
|
720
|
+
});
|
|
642
721
|
this.loadPromise = this.load(
|
|
643
722
|
entry,
|
|
644
723
|
previewEntry,
|
|
645
|
-
|
|
724
|
+
target,
|
|
646
725
|
generation,
|
|
647
726
|
abortController
|
|
648
727
|
);
|
|
@@ -666,26 +745,25 @@ var browserWorkspaceFilePreviewObjectUrls = {
|
|
|
666
745
|
URL.revokeObjectURL(objectUrl);
|
|
667
746
|
}
|
|
668
747
|
};
|
|
669
|
-
function byteLengthOfPreviewReadResult(result) {
|
|
670
|
-
const bytes = result instanceof Uint8Array || result instanceof ArrayBuffer ? result : result.bytes;
|
|
671
|
-
return bytes.byteLength;
|
|
672
|
-
}
|
|
673
748
|
|
|
674
749
|
export {
|
|
675
|
-
|
|
676
|
-
workspaceFileTextMaxBytes,
|
|
677
|
-
workspaceFilePreviewMaxBytes,
|
|
678
|
-
resolveWorkspaceFileVisualKind,
|
|
750
|
+
workspaceFileBrowserVideoExtensions,
|
|
679
751
|
resolveWorkspaceFileExtension,
|
|
680
|
-
|
|
681
|
-
|
|
752
|
+
resolveWorkspaceFilePreviewName,
|
|
753
|
+
isWorkspaceFileDirectoryKind,
|
|
754
|
+
isTextDegradablePreviewKind,
|
|
755
|
+
resolveWorkspaceFileBuiltinRenderKind,
|
|
756
|
+
resolveWorkspaceFileVisualKind,
|
|
757
|
+
classifyWorkspaceFilePreviewKind,
|
|
758
|
+
resolveWorkspaceFilePreviewTarget,
|
|
682
759
|
resolveWorkspaceImageMimeType,
|
|
683
760
|
resolveWorkspaceVideoMimeType,
|
|
684
|
-
|
|
685
|
-
|
|
761
|
+
isWorkspaceFileBrowserHtmlExtension,
|
|
762
|
+
isWorkspaceFileImageExtension,
|
|
763
|
+
workspaceFileTextMaxBytes,
|
|
764
|
+
workspaceFilePreviewMaxBytes,
|
|
686
765
|
resolveWorkspaceFilePreviewReadiness,
|
|
687
766
|
createWorkspaceFilePreviewLoadedState,
|
|
688
|
-
resolveWorkspaceFilePreviewName,
|
|
689
767
|
isWorkspaceTextFileTooLarge,
|
|
690
768
|
isWorkspacePreviewFileTooLarge,
|
|
691
769
|
decodeWorkspaceTextFile,
|
|
@@ -695,4 +773,4 @@ export {
|
|
|
695
773
|
formatWorkspacePreviewByteLimit,
|
|
696
774
|
createWorkspaceFilePreviewController
|
|
697
775
|
};
|
|
698
|
-
//# sourceMappingURL=chunk-
|
|
776
|
+
//# sourceMappingURL=chunk-SDSS6OA5.js.map
|