@tutti-os/workspace-file-preview 0.0.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/LICENSE +202 -0
- package/README.md +11 -0
- package/dist/chunk-MAJHX2MV.js +390 -0
- package/dist/chunk-MAJHX2MV.js.map +1 -0
- package/dist/core/index.d.ts +81 -0
- package/dist/core/index.js +45 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +49 -0
- package/dist/react/index.js +75 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @tutti-os/workspace-file-preview
|
|
2
|
+
|
|
3
|
+
Shared, host-neutral file preview helpers for workspace features.
|
|
4
|
+
|
|
5
|
+
This package owns file preview classification, safe byte handling, text
|
|
6
|
+
decoding, image mime resolution, and byte-limit helpers. Host adapters remain
|
|
7
|
+
responsible for reading bytes from the local workspace.
|
|
8
|
+
|
|
9
|
+
It also exposes a small React preview surface for consumers that want the shared
|
|
10
|
+
image, text, loading, and readonly rendering shell while keeping host-specific
|
|
11
|
+
icons and localized copy outside this package.
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
// src/core/workspaceFilePreview.ts
|
|
2
|
+
var imageExtensions = /* @__PURE__ */ new Set([
|
|
3
|
+
"avif",
|
|
4
|
+
"gif",
|
|
5
|
+
"jpeg",
|
|
6
|
+
"jpg",
|
|
7
|
+
"png",
|
|
8
|
+
"svg",
|
|
9
|
+
"webp"
|
|
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
|
+
var videoExtensions = /* @__PURE__ */ new Set([
|
|
19
|
+
"avi",
|
|
20
|
+
"m2ts",
|
|
21
|
+
"mkv",
|
|
22
|
+
"mov",
|
|
23
|
+
"mp4",
|
|
24
|
+
"mpeg",
|
|
25
|
+
"mpg",
|
|
26
|
+
"mts",
|
|
27
|
+
"webm",
|
|
28
|
+
"wmv"
|
|
29
|
+
]);
|
|
30
|
+
var workspaceFileVideoHandlerCollisionExtensions = /* @__PURE__ */ new Set(["ts"]);
|
|
31
|
+
var markdownExtensions = /* @__PURE__ */ new Set(["md", "mdx"]);
|
|
32
|
+
var codeExtensions = /* @__PURE__ */ new Set([
|
|
33
|
+
"bash",
|
|
34
|
+
"c",
|
|
35
|
+
"cc",
|
|
36
|
+
"conf",
|
|
37
|
+
"cpp",
|
|
38
|
+
"cs",
|
|
39
|
+
"css",
|
|
40
|
+
"go",
|
|
41
|
+
"h",
|
|
42
|
+
"hpp",
|
|
43
|
+
"html",
|
|
44
|
+
"java",
|
|
45
|
+
"js",
|
|
46
|
+
"jsx",
|
|
47
|
+
"json",
|
|
48
|
+
"lua",
|
|
49
|
+
"m",
|
|
50
|
+
"mm",
|
|
51
|
+
"php",
|
|
52
|
+
"plist",
|
|
53
|
+
"proto",
|
|
54
|
+
"py",
|
|
55
|
+
"rb",
|
|
56
|
+
"rs",
|
|
57
|
+
"sh",
|
|
58
|
+
"sql",
|
|
59
|
+
"swift",
|
|
60
|
+
"toml",
|
|
61
|
+
"ts",
|
|
62
|
+
"tsx",
|
|
63
|
+
"xml",
|
|
64
|
+
"yaml",
|
|
65
|
+
"yml",
|
|
66
|
+
"zsh"
|
|
67
|
+
]);
|
|
68
|
+
var documentExtensions = /* @__PURE__ */ new Set([
|
|
69
|
+
"csv",
|
|
70
|
+
"doc",
|
|
71
|
+
"docx",
|
|
72
|
+
"log",
|
|
73
|
+
"pdf",
|
|
74
|
+
"rtf",
|
|
75
|
+
"txt",
|
|
76
|
+
"xls",
|
|
77
|
+
"xlsx"
|
|
78
|
+
]);
|
|
79
|
+
var textExtensions = /* @__PURE__ */ new Set([
|
|
80
|
+
"bash",
|
|
81
|
+
"c",
|
|
82
|
+
"cc",
|
|
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",
|
|
96
|
+
"json",
|
|
97
|
+
"jsx",
|
|
98
|
+
"log",
|
|
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"
|
|
129
|
+
]);
|
|
130
|
+
var workspaceFileTextMaxBytes = 1024 * 1024;
|
|
131
|
+
var workspaceFilePreviewMaxBytes = 20 * 1024 * 1024;
|
|
132
|
+
function resolveWorkspaceFileVisualKind(entry) {
|
|
133
|
+
if (entry.kind === "directory" || entry.kind === "folder") {
|
|
134
|
+
return "directory";
|
|
135
|
+
}
|
|
136
|
+
const extension = resolveWorkspaceFileExtension(
|
|
137
|
+
entry.path || entry.name || ""
|
|
138
|
+
);
|
|
139
|
+
if (imageExtensions.has(extension)) {
|
|
140
|
+
return "image";
|
|
141
|
+
}
|
|
142
|
+
if (videoExtensions.has(extension)) {
|
|
143
|
+
return "video";
|
|
144
|
+
}
|
|
145
|
+
if (markdownExtensions.has(extension)) {
|
|
146
|
+
return "markdown";
|
|
147
|
+
}
|
|
148
|
+
if (codeExtensions.has(extension)) {
|
|
149
|
+
return "code";
|
|
150
|
+
}
|
|
151
|
+
if (documentExtensions.has(extension)) {
|
|
152
|
+
return "document";
|
|
153
|
+
}
|
|
154
|
+
return "binary";
|
|
155
|
+
}
|
|
156
|
+
function resolveWorkspaceFileExtension(pathOrName) {
|
|
157
|
+
const name = pathOrName.split("/").pop()?.trim().toLowerCase() ?? "";
|
|
158
|
+
const dotIndex = name.lastIndexOf(".");
|
|
159
|
+
return dotIndex > 0 ? name.slice(dotIndex + 1) : "";
|
|
160
|
+
}
|
|
161
|
+
function isWorkspaceFileBrowserOpenable(entry) {
|
|
162
|
+
if (entry.kind !== "file") {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
const extension = resolveWorkspaceFileExtension(
|
|
166
|
+
entry.path || entry.name || ""
|
|
167
|
+
);
|
|
168
|
+
if (extension === "pdf" || browserOpenableHtmlExtensions.has(extension) || imageExtensions.has(extension) || browserOpenableVideoExtensions.has(extension)) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return classifyWorkspaceFilePreviewKind(entry) === "text";
|
|
172
|
+
}
|
|
173
|
+
function shouldFilterVideoPlayersForOpenWith(entry) {
|
|
174
|
+
if (entry.kind !== "file") {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
const visualKind = resolveWorkspaceFileVisualKind(entry);
|
|
178
|
+
if (visualKind === "video") {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
const extension = resolveWorkspaceFileExtension(
|
|
182
|
+
entry.path || entry.name || ""
|
|
183
|
+
);
|
|
184
|
+
if (workspaceFileVideoHandlerCollisionExtensions.has(extension)) {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
if (visualKind === "code" || visualKind === "markdown") {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
return classifyWorkspaceFilePreviewKind(entry) === "text";
|
|
191
|
+
}
|
|
192
|
+
function resolveWorkspaceImageMimeType(pathOrName) {
|
|
193
|
+
switch (resolveWorkspaceFileExtension(pathOrName)) {
|
|
194
|
+
case "avif":
|
|
195
|
+
return "image/avif";
|
|
196
|
+
case "gif":
|
|
197
|
+
return "image/gif";
|
|
198
|
+
case "jpeg":
|
|
199
|
+
case "jpg":
|
|
200
|
+
return "image/jpeg";
|
|
201
|
+
case "png":
|
|
202
|
+
return "image/png";
|
|
203
|
+
case "svg":
|
|
204
|
+
return "image/svg+xml";
|
|
205
|
+
case "webp":
|
|
206
|
+
return "image/webp";
|
|
207
|
+
default:
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function classifyWorkspaceFilePreviewKind(entry) {
|
|
212
|
+
if (entry.kind !== "file") {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const name = resolveWorkspaceFilePreviewName(entry);
|
|
216
|
+
if (resolveWorkspaceImageMimeType(name) !== null) {
|
|
217
|
+
return "image";
|
|
218
|
+
}
|
|
219
|
+
const normalizedName = name.trim().toLowerCase();
|
|
220
|
+
const extension = resolveWorkspaceFileExtension(name);
|
|
221
|
+
if (textExtensions.has(extension) || textFileNames.has(normalizedName)) {
|
|
222
|
+
return "text";
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
function resolveWorkspaceFileActivationTarget(entry) {
|
|
227
|
+
const fileKind = classifyWorkspaceFilePreviewKind(entry);
|
|
228
|
+
if (!fileKind) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
const target = {
|
|
232
|
+
fileKind,
|
|
233
|
+
name: resolveWorkspaceFilePreviewName(entry),
|
|
234
|
+
path: entry.path
|
|
235
|
+
};
|
|
236
|
+
if (entry.mtimeMs !== void 0) {
|
|
237
|
+
target.mtimeMs = entry.mtimeMs;
|
|
238
|
+
}
|
|
239
|
+
if (entry.sizeBytes !== void 0) {
|
|
240
|
+
target.sizeBytes = entry.sizeBytes;
|
|
241
|
+
}
|
|
242
|
+
return target;
|
|
243
|
+
}
|
|
244
|
+
function resolveWorkspaceFilePreviewReadiness(entry) {
|
|
245
|
+
if (entry.kind === "directory" || entry.kind === "folder") {
|
|
246
|
+
return {
|
|
247
|
+
entry,
|
|
248
|
+
status: "directory"
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
const target = resolveWorkspaceFileActivationTarget(entry);
|
|
252
|
+
if (!target) {
|
|
253
|
+
return {
|
|
254
|
+
entry,
|
|
255
|
+
status: "unsupported"
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (target.fileKind === "text" && isWorkspaceTextFileTooLarge(entry.sizeBytes)) {
|
|
259
|
+
return {
|
|
260
|
+
entry,
|
|
261
|
+
maxSizeBytes: workspaceFileTextMaxBytes,
|
|
262
|
+
reason: "text_too_large",
|
|
263
|
+
status: "readonly"
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (isWorkspacePreviewFileTooLarge(entry.sizeBytes)) {
|
|
267
|
+
return {
|
|
268
|
+
entry,
|
|
269
|
+
maxSizeBytes: workspaceFilePreviewMaxBytes,
|
|
270
|
+
reason: "file_too_large",
|
|
271
|
+
status: "readonly"
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
entry,
|
|
276
|
+
status: "ready",
|
|
277
|
+
target
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function createWorkspaceFilePreviewLoadedState(input) {
|
|
281
|
+
if (input.target.fileKind === "image") {
|
|
282
|
+
return {
|
|
283
|
+
bytes: copyWorkspaceFilePreviewBytes(input.bytes),
|
|
284
|
+
contentType: input.contentType ?? resolveWorkspaceImageMimeType(input.target.name) ?? "application/octet-stream",
|
|
285
|
+
entry: input.target,
|
|
286
|
+
status: "image"
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
const content = decodeWorkspaceTextFile(input.bytes);
|
|
291
|
+
if (looksLikeBinaryText(content)) {
|
|
292
|
+
return {
|
|
293
|
+
entry: input.entry,
|
|
294
|
+
reason: "binary",
|
|
295
|
+
status: "readonly"
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
content,
|
|
300
|
+
entry: input.target,
|
|
301
|
+
status: "text"
|
|
302
|
+
};
|
|
303
|
+
} catch {
|
|
304
|
+
return {
|
|
305
|
+
entry: input.entry,
|
|
306
|
+
reason: "decode_failed",
|
|
307
|
+
status: "readonly"
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function resolveWorkspaceFilePreviewName(entry) {
|
|
312
|
+
return entry.name?.trim() || entry.displayName?.trim() || entry.path.split("/").pop()?.trim() || entry.path;
|
|
313
|
+
}
|
|
314
|
+
function isWorkspaceTextFileTooLarge(sizeBytes) {
|
|
315
|
+
return typeof sizeBytes === "number" && Number.isFinite(sizeBytes) && sizeBytes > workspaceFileTextMaxBytes;
|
|
316
|
+
}
|
|
317
|
+
function isWorkspacePreviewFileTooLarge(sizeBytes) {
|
|
318
|
+
return typeof sizeBytes === "number" && Number.isFinite(sizeBytes) && sizeBytes > workspaceFilePreviewMaxBytes;
|
|
319
|
+
}
|
|
320
|
+
function decodeWorkspaceTextFile(bytes) {
|
|
321
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(
|
|
322
|
+
normalizeWorkspaceFilePreviewBytes(bytes)
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
function normalizeWorkspaceFilePreviewBytes(value) {
|
|
326
|
+
if (value instanceof Uint8Array) {
|
|
327
|
+
return value;
|
|
328
|
+
}
|
|
329
|
+
return new Uint8Array(value);
|
|
330
|
+
}
|
|
331
|
+
function copyWorkspaceFilePreviewBytes(bytes) {
|
|
332
|
+
const normalized = normalizeWorkspaceFilePreviewBytes(bytes);
|
|
333
|
+
const buffer = new ArrayBuffer(normalized.byteLength);
|
|
334
|
+
const copy = new Uint8Array(buffer);
|
|
335
|
+
copy.set(normalized);
|
|
336
|
+
return copy;
|
|
337
|
+
}
|
|
338
|
+
function looksLikeBinaryText(content) {
|
|
339
|
+
if (content.length === 0) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
const sample = content.slice(0, 4096);
|
|
343
|
+
if (sample.includes("\0")) {
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
let suspiciousControlChars = 0;
|
|
347
|
+
for (let index = 0; index < sample.length; index += 1) {
|
|
348
|
+
const code = sample.charCodeAt(index);
|
|
349
|
+
const isAllowedWhitespace = code === 9 || code === 10 || code === 13;
|
|
350
|
+
const isControlChar = code < 32 || code >= 127 && code <= 159;
|
|
351
|
+
if (isControlChar && !isAllowedWhitespace) {
|
|
352
|
+
suspiciousControlChars += 1;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return suspiciousControlChars / sample.length > 0.12;
|
|
356
|
+
}
|
|
357
|
+
function formatWorkspacePreviewByteLimit(sizeBytes) {
|
|
358
|
+
if (sizeBytes < 1024) {
|
|
359
|
+
return `${sizeBytes} B`;
|
|
360
|
+
}
|
|
361
|
+
const mebibytes = sizeBytes / (1024 * 1024);
|
|
362
|
+
if (Number.isInteger(mebibytes)) {
|
|
363
|
+
return `${mebibytes} MiB`;
|
|
364
|
+
}
|
|
365
|
+
return `${mebibytes.toFixed(1)} MiB`;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export {
|
|
369
|
+
workspaceFileVideoHandlerCollisionExtensions,
|
|
370
|
+
workspaceFileTextMaxBytes,
|
|
371
|
+
workspaceFilePreviewMaxBytes,
|
|
372
|
+
resolveWorkspaceFileVisualKind,
|
|
373
|
+
resolveWorkspaceFileExtension,
|
|
374
|
+
isWorkspaceFileBrowserOpenable,
|
|
375
|
+
shouldFilterVideoPlayersForOpenWith,
|
|
376
|
+
resolveWorkspaceImageMimeType,
|
|
377
|
+
classifyWorkspaceFilePreviewKind,
|
|
378
|
+
resolveWorkspaceFileActivationTarget,
|
|
379
|
+
resolveWorkspaceFilePreviewReadiness,
|
|
380
|
+
createWorkspaceFilePreviewLoadedState,
|
|
381
|
+
resolveWorkspaceFilePreviewName,
|
|
382
|
+
isWorkspaceTextFileTooLarge,
|
|
383
|
+
isWorkspacePreviewFileTooLarge,
|
|
384
|
+
decodeWorkspaceTextFile,
|
|
385
|
+
normalizeWorkspaceFilePreviewBytes,
|
|
386
|
+
copyWorkspaceFilePreviewBytes,
|
|
387
|
+
looksLikeBinaryText,
|
|
388
|
+
formatWorkspacePreviewByteLimit
|
|
389
|
+
};
|
|
390
|
+
//# sourceMappingURL=chunk-MAJHX2MV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/workspaceFilePreview.ts"],"sourcesContent":["export type WorkspaceFilePreviewEntryKind =\n | \"file\"\n | \"directory\"\n | \"folder\"\n | \"unknown\"\n | (string & {});\n\nexport type WorkspaceFilePreviewKind = \"image\" | \"text\";\n\nexport type WorkspaceFileVisualKind =\n | \"binary\"\n | \"code\"\n | \"directory\"\n | \"document\"\n | \"image\"\n | \"markdown\"\n | \"video\";\n\nexport interface WorkspaceFilePreviewEntry {\n displayName?: string;\n kind: WorkspaceFilePreviewEntryKind;\n mtimeMs?: number | null;\n name?: string;\n path: string;\n sizeBytes?: number | null;\n}\n\nexport interface WorkspaceFilePreviewActivationTarget {\n fileKind: WorkspaceFilePreviewKind;\n mtimeMs?: number | null;\n name: string;\n path: string;\n sizeBytes?: number | null;\n}\n\nexport type WorkspaceFilePreviewReadonlyReason =\n | \"binary\"\n | \"decode_failed\"\n | \"file_too_large\"\n | \"text_too_large\";\n\nexport type WorkspaceFilePreviewReadiness<\n TEntry extends WorkspaceFilePreviewEntry,\n TTarget extends WorkspaceFilePreviewActivationTarget =\n WorkspaceFilePreviewActivationTarget\n> =\n | { entry: TEntry; status: \"directory\" }\n | {\n entry: TEntry;\n maxSizeBytes: number;\n reason: Extract<\n WorkspaceFilePreviewReadonlyReason,\n \"file_too_large\" | \"text_too_large\"\n >;\n status: \"readonly\";\n }\n | { entry: TEntry; status: \"unsupported\" }\n | { entry: TEntry; status: \"ready\"; target: TTarget };\n\nexport type WorkspaceFilePreviewLoadedState<\n TEntry extends WorkspaceFilePreviewEntry,\n TTarget extends WorkspaceFilePreviewActivationTarget\n> =\n | { content: string; entry: TTarget; status: \"text\" }\n | {\n bytes: Uint8Array<ArrayBuffer>;\n contentType: string;\n entry: TTarget;\n status: \"image\";\n }\n | {\n entry: TEntry;\n maxSizeBytes?: number;\n reason: WorkspaceFilePreviewReadonlyReason;\n status: \"readonly\";\n };\n\nconst imageExtensions = new Set([\n \"avif\",\n \"gif\",\n \"jpeg\",\n \"jpg\",\n \"png\",\n \"svg\",\n \"webp\"\n]);\nconst browserOpenableHtmlExtensions = new Set([\n \"htm\",\n \"html\",\n \"shtml\",\n \"xhtml\"\n]);\nconst browserOpenableVideoExtensions = new Set([\"mp4\", \"webm\"]);\n\nconst videoExtensions = new Set([\n \"avi\",\n \"m2ts\",\n \"mkv\",\n \"mov\",\n \"mp4\",\n \"mpeg\",\n \"mpg\",\n \"mts\",\n \"webm\",\n \"wmv\"\n]);\n/**\n * Extensions where macOS Launch Services may register video handlers even when\n * the workspace file is source code (UTI / uniform type collisions).\n */\nexport const workspaceFileVideoHandlerCollisionExtensions = new Set([\"ts\"]);\nconst markdownExtensions = new Set([\"md\", \"mdx\"]);\nconst codeExtensions = new Set([\n \"bash\",\n \"c\",\n \"cc\",\n \"conf\",\n \"cpp\",\n \"cs\",\n \"css\",\n \"go\",\n \"h\",\n \"hpp\",\n \"html\",\n \"java\",\n \"js\",\n \"jsx\",\n \"json\",\n \"lua\",\n \"m\",\n \"mm\",\n \"php\",\n \"plist\",\n \"proto\",\n \"py\",\n \"rb\",\n \"rs\",\n \"sh\",\n \"sql\",\n \"swift\",\n \"toml\",\n \"ts\",\n \"tsx\",\n \"xml\",\n \"yaml\",\n \"yml\",\n \"zsh\"\n]);\nconst documentExtensions = new Set([\n \"csv\",\n \"doc\",\n \"docx\",\n \"log\",\n \"pdf\",\n \"rtf\",\n \"txt\",\n \"xls\",\n \"xlsx\"\n]);\nconst textExtensions = new Set([\n \"bash\",\n \"c\",\n \"cc\",\n \"conf\",\n \"cpp\",\n \"cs\",\n \"css\",\n \"csv\",\n \"env\",\n \"go\",\n \"h\",\n \"hpp\",\n \"html\",\n \"ini\",\n \"java\",\n \"js\",\n \"json\",\n \"jsx\",\n \"log\",\n \"lua\",\n \"m\",\n \"md\",\n \"mdx\",\n \"mm\",\n \"php\",\n \"plist\",\n \"proto\",\n \"py\",\n \"rb\",\n \"rs\",\n \"sh\",\n \"sql\",\n \"swift\",\n \"toml\",\n \"ts\",\n \"tsx\",\n \"txt\",\n \"xml\",\n \"yaml\",\n \"yml\",\n \"zsh\"\n]);\nconst textFileNames = new Set([\n \".gitignore\",\n \".npmrc\",\n \".nvmrc\",\n \"dockerfile\",\n \"makefile\",\n \"readme\"\n]);\n\nexport const workspaceFileTextMaxBytes = 1024 * 1024;\nexport const workspaceFilePreviewMaxBytes = 20 * 1024 * 1024;\n\nexport function resolveWorkspaceFileVisualKind(\n entry: Pick<WorkspaceFilePreviewEntry, \"kind\" | \"name\" | \"path\">\n): WorkspaceFileVisualKind {\n if (entry.kind === \"directory\" || entry.kind === \"folder\") {\n return \"directory\";\n }\n\n const extension = resolveWorkspaceFileExtension(\n entry.path || entry.name || \"\"\n );\n if (imageExtensions.has(extension)) {\n return \"image\";\n }\n if (videoExtensions.has(extension)) {\n return \"video\";\n }\n if (markdownExtensions.has(extension)) {\n return \"markdown\";\n }\n if (codeExtensions.has(extension)) {\n return \"code\";\n }\n if (documentExtensions.has(extension)) {\n return \"document\";\n }\n return \"binary\";\n}\n\nexport function resolveWorkspaceFileExtension(pathOrName: string): string {\n const name = pathOrName.split(\"/\").pop()?.trim().toLowerCase() ?? \"\";\n const dotIndex = name.lastIndexOf(\".\");\n return dotIndex > 0 ? name.slice(dotIndex + 1) : \"\";\n}\n\nexport function isWorkspaceFileBrowserOpenable(\n entry: Pick<WorkspaceFilePreviewEntry, \"kind\" | \"name\" | \"path\">\n): boolean {\n if (entry.kind !== \"file\") {\n return false;\n }\n\n const extension = resolveWorkspaceFileExtension(\n entry.path || entry.name || \"\"\n );\n if (\n extension === \"pdf\" ||\n browserOpenableHtmlExtensions.has(extension) ||\n imageExtensions.has(extension) ||\n browserOpenableVideoExtensions.has(extension)\n ) {\n return true;\n }\n\n return classifyWorkspaceFilePreviewKind(entry) === \"text\";\n}\n\nexport function shouldFilterVideoPlayersForOpenWith(\n entry: Pick<WorkspaceFilePreviewEntry, \"kind\" | \"name\" | \"path\">\n): boolean {\n if (entry.kind !== \"file\") {\n return false;\n }\n\n const visualKind = resolveWorkspaceFileVisualKind(entry);\n if (visualKind === \"video\") {\n return false;\n }\n\n const extension = resolveWorkspaceFileExtension(\n entry.path || entry.name || \"\"\n );\n if (workspaceFileVideoHandlerCollisionExtensions.has(extension)) {\n return true;\n }\n\n if (visualKind === \"code\" || visualKind === \"markdown\") {\n return true;\n }\n\n return classifyWorkspaceFilePreviewKind(entry) === \"text\";\n}\n\nexport function resolveWorkspaceImageMimeType(\n pathOrName: string\n): string | null {\n switch (resolveWorkspaceFileExtension(pathOrName)) {\n case \"avif\":\n return \"image/avif\";\n case \"gif\":\n return \"image/gif\";\n case \"jpeg\":\n case \"jpg\":\n return \"image/jpeg\";\n case \"png\":\n return \"image/png\";\n case \"svg\":\n return \"image/svg+xml\";\n case \"webp\":\n return \"image/webp\";\n default:\n return null;\n }\n}\n\nexport function classifyWorkspaceFilePreviewKind(\n entry: Pick<\n WorkspaceFilePreviewEntry,\n \"displayName\" | \"kind\" | \"name\" | \"path\"\n >\n): WorkspaceFilePreviewKind | null {\n if (entry.kind !== \"file\") {\n return null;\n }\n\n const name = resolveWorkspaceFilePreviewName(entry);\n if (resolveWorkspaceImageMimeType(name) !== null) {\n return \"image\";\n }\n\n const normalizedName = name.trim().toLowerCase();\n const extension = resolveWorkspaceFileExtension(name);\n if (textExtensions.has(extension) || textFileNames.has(normalizedName)) {\n return \"text\";\n }\n\n return null;\n}\n\nexport function resolveWorkspaceFileActivationTarget(\n entry: WorkspaceFilePreviewEntry\n): WorkspaceFilePreviewActivationTarget | null {\n const fileKind = classifyWorkspaceFilePreviewKind(entry);\n if (!fileKind) {\n return null;\n }\n\n const target: WorkspaceFilePreviewActivationTarget = {\n fileKind,\n name: resolveWorkspaceFilePreviewName(entry),\n path: entry.path\n };\n if (entry.mtimeMs !== undefined) {\n target.mtimeMs = entry.mtimeMs;\n }\n if (entry.sizeBytes !== undefined) {\n target.sizeBytes = entry.sizeBytes;\n }\n return target;\n}\n\nexport function resolveWorkspaceFilePreviewReadiness<\n TEntry extends WorkspaceFilePreviewEntry\n>(entry: TEntry): WorkspaceFilePreviewReadiness<TEntry> {\n if (entry.kind === \"directory\" || entry.kind === \"folder\") {\n return {\n entry,\n status: \"directory\"\n };\n }\n\n const target = resolveWorkspaceFileActivationTarget(entry);\n if (!target) {\n return {\n entry,\n status: \"unsupported\"\n };\n }\n\n if (\n target.fileKind === \"text\" &&\n isWorkspaceTextFileTooLarge(entry.sizeBytes)\n ) {\n return {\n entry,\n maxSizeBytes: workspaceFileTextMaxBytes,\n reason: \"text_too_large\",\n status: \"readonly\"\n };\n }\n\n if (isWorkspacePreviewFileTooLarge(entry.sizeBytes)) {\n return {\n entry,\n maxSizeBytes: workspaceFilePreviewMaxBytes,\n reason: \"file_too_large\",\n status: \"readonly\"\n };\n }\n\n return {\n entry,\n status: \"ready\",\n target\n };\n}\n\nexport function createWorkspaceFilePreviewLoadedState<\n TEntry extends WorkspaceFilePreviewEntry,\n TTarget extends WorkspaceFilePreviewActivationTarget\n>(input: {\n bytes: Uint8Array | ArrayBuffer;\n contentType?: string | null;\n entry: TEntry;\n target: TTarget;\n}): WorkspaceFilePreviewLoadedState<TEntry, TTarget> {\n if (input.target.fileKind === \"image\") {\n return {\n bytes: copyWorkspaceFilePreviewBytes(input.bytes),\n contentType:\n input.contentType ??\n resolveWorkspaceImageMimeType(input.target.name) ??\n \"application/octet-stream\",\n entry: input.target,\n status: \"image\"\n };\n }\n\n try {\n const content = decodeWorkspaceTextFile(input.bytes);\n if (looksLikeBinaryText(content)) {\n return {\n entry: input.entry,\n reason: \"binary\",\n status: \"readonly\"\n };\n }\n return {\n content,\n entry: input.target,\n status: \"text\"\n };\n } catch {\n return {\n entry: input.entry,\n reason: \"decode_failed\",\n status: \"readonly\"\n };\n }\n}\n\nexport function resolveWorkspaceFilePreviewName(\n entry: Pick<WorkspaceFilePreviewEntry, \"displayName\" | \"name\" | \"path\">\n): string {\n return (\n entry.name?.trim() ||\n entry.displayName?.trim() ||\n entry.path.split(\"/\").pop()?.trim() ||\n entry.path\n );\n}\n\nexport function isWorkspaceTextFileTooLarge(\n sizeBytes?: number | null\n): boolean {\n return (\n typeof sizeBytes === \"number\" &&\n Number.isFinite(sizeBytes) &&\n sizeBytes > workspaceFileTextMaxBytes\n );\n}\n\nexport function isWorkspacePreviewFileTooLarge(\n sizeBytes?: number | null\n): boolean {\n return (\n typeof sizeBytes === \"number\" &&\n Number.isFinite(sizeBytes) &&\n sizeBytes > workspaceFilePreviewMaxBytes\n );\n}\n\nexport function decodeWorkspaceTextFile(\n bytes: Uint8Array | ArrayBuffer\n): string {\n return new TextDecoder(\"utf-8\", { fatal: true }).decode(\n normalizeWorkspaceFilePreviewBytes(bytes)\n );\n}\n\nexport function normalizeWorkspaceFilePreviewBytes(\n value: Uint8Array | ArrayBuffer\n): Uint8Array {\n if (value instanceof Uint8Array) {\n return value;\n }\n return new Uint8Array(value);\n}\n\nexport function copyWorkspaceFilePreviewBytes(\n bytes: Uint8Array | ArrayBuffer\n): Uint8Array<ArrayBuffer> {\n const normalized = normalizeWorkspaceFilePreviewBytes(bytes);\n const buffer = new ArrayBuffer(normalized.byteLength);\n const copy = new Uint8Array(buffer);\n copy.set(normalized);\n return copy;\n}\n\nexport function looksLikeBinaryText(content: string): boolean {\n if (content.length === 0) {\n return false;\n }\n\n const sample = content.slice(0, 4096);\n if (sample.includes(\"\\u0000\")) {\n return true;\n }\n\n let suspiciousControlChars = 0;\n for (let index = 0; index < sample.length; index += 1) {\n const code = sample.charCodeAt(index);\n const isAllowedWhitespace = code === 9 || code === 10 || code === 13;\n const isControlChar = code < 32 || (code >= 127 && code <= 159);\n if (isControlChar && !isAllowedWhitespace) {\n suspiciousControlChars += 1;\n }\n }\n\n return suspiciousControlChars / sample.length > 0.12;\n}\n\nexport function formatWorkspacePreviewByteLimit(sizeBytes: number): string {\n if (sizeBytes < 1024) {\n return `${sizeBytes} B`;\n }\n\n const mebibytes = sizeBytes / (1024 * 1024);\n if (Number.isInteger(mebibytes)) {\n return `${mebibytes} MiB`;\n }\n return `${mebibytes.toFixed(1)} MiB`;\n}\n"],"mappings":";AA6EA,IAAM,kBAAkB,oBAAI,IAAI;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AACD,IAAM,gCAAgC,oBAAI,IAAI;AAAA,EAC5C;AAAA,EACA;AAAA,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O,WAAW,KAAK;AACpC,UAAM,sBAAsB,SAAS,KAAK,SAAS,MAAM,SAAS;AAClE,UAAM,gBAAgB,OAAO,MAAO,QAAQ,OAAO,QAAQ;AAC3D,QAAI,iBAAiB,CAAC,qBAAqB;AACzC,gCAA0B;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO,yBAAyB,OAAO,SAAS;AAClD;AAEO,SAAS,gCAAgC,WAA2B;AACzE,MAAI,YAAY,MAAM;AACpB,WAAO,GAAG,SAAS;AAAA,EACrB;AAEA,QAAM,YAAY,aAAa,OAAO;AACtC,MAAI,OAAO,UAAU,SAAS,GAAG;AAC/B,WAAO,GAAG,SAAS;AAAA,EACrB;AACA,SAAO,GAAG,UAAU,QAAQ,CAAC,CAAC;AAChC;","names":[]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
type WorkspaceFilePreviewEntryKind = "file" | "directory" | "folder" | "unknown" | (string & {});
|
|
2
|
+
type WorkspaceFilePreviewKind = "image" | "text";
|
|
3
|
+
type WorkspaceFileVisualKind = "binary" | "code" | "directory" | "document" | "image" | "markdown" | "video";
|
|
4
|
+
interface WorkspaceFilePreviewEntry {
|
|
5
|
+
displayName?: string;
|
|
6
|
+
kind: WorkspaceFilePreviewEntryKind;
|
|
7
|
+
mtimeMs?: number | null;
|
|
8
|
+
name?: string;
|
|
9
|
+
path: string;
|
|
10
|
+
sizeBytes?: number | null;
|
|
11
|
+
}
|
|
12
|
+
interface WorkspaceFilePreviewActivationTarget {
|
|
13
|
+
fileKind: WorkspaceFilePreviewKind;
|
|
14
|
+
mtimeMs?: number | null;
|
|
15
|
+
name: string;
|
|
16
|
+
path: string;
|
|
17
|
+
sizeBytes?: number | null;
|
|
18
|
+
}
|
|
19
|
+
type WorkspaceFilePreviewReadonlyReason = "binary" | "decode_failed" | "file_too_large" | "text_too_large";
|
|
20
|
+
type WorkspaceFilePreviewReadiness<TEntry extends WorkspaceFilePreviewEntry, TTarget extends WorkspaceFilePreviewActivationTarget = WorkspaceFilePreviewActivationTarget> = {
|
|
21
|
+
entry: TEntry;
|
|
22
|
+
status: "directory";
|
|
23
|
+
} | {
|
|
24
|
+
entry: TEntry;
|
|
25
|
+
maxSizeBytes: number;
|
|
26
|
+
reason: Extract<WorkspaceFilePreviewReadonlyReason, "file_too_large" | "text_too_large">;
|
|
27
|
+
status: "readonly";
|
|
28
|
+
} | {
|
|
29
|
+
entry: TEntry;
|
|
30
|
+
status: "unsupported";
|
|
31
|
+
} | {
|
|
32
|
+
entry: TEntry;
|
|
33
|
+
status: "ready";
|
|
34
|
+
target: TTarget;
|
|
35
|
+
};
|
|
36
|
+
type WorkspaceFilePreviewLoadedState<TEntry extends WorkspaceFilePreviewEntry, TTarget extends WorkspaceFilePreviewActivationTarget> = {
|
|
37
|
+
content: string;
|
|
38
|
+
entry: TTarget;
|
|
39
|
+
status: "text";
|
|
40
|
+
} | {
|
|
41
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
42
|
+
contentType: string;
|
|
43
|
+
entry: TTarget;
|
|
44
|
+
status: "image";
|
|
45
|
+
} | {
|
|
46
|
+
entry: TEntry;
|
|
47
|
+
maxSizeBytes?: number;
|
|
48
|
+
reason: WorkspaceFilePreviewReadonlyReason;
|
|
49
|
+
status: "readonly";
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Extensions where macOS Launch Services may register video handlers even when
|
|
53
|
+
* the workspace file is source code (UTI / uniform type collisions).
|
|
54
|
+
*/
|
|
55
|
+
declare const workspaceFileVideoHandlerCollisionExtensions: Set<string>;
|
|
56
|
+
declare const workspaceFileTextMaxBytes: number;
|
|
57
|
+
declare const workspaceFilePreviewMaxBytes: number;
|
|
58
|
+
declare function resolveWorkspaceFileVisualKind(entry: Pick<WorkspaceFilePreviewEntry, "kind" | "name" | "path">): WorkspaceFileVisualKind;
|
|
59
|
+
declare function resolveWorkspaceFileExtension(pathOrName: string): string;
|
|
60
|
+
declare function isWorkspaceFileBrowserOpenable(entry: Pick<WorkspaceFilePreviewEntry, "kind" | "name" | "path">): boolean;
|
|
61
|
+
declare function shouldFilterVideoPlayersForOpenWith(entry: Pick<WorkspaceFilePreviewEntry, "kind" | "name" | "path">): boolean;
|
|
62
|
+
declare function resolveWorkspaceImageMimeType(pathOrName: string): string | null;
|
|
63
|
+
declare function classifyWorkspaceFilePreviewKind(entry: Pick<WorkspaceFilePreviewEntry, "displayName" | "kind" | "name" | "path">): WorkspaceFilePreviewKind | null;
|
|
64
|
+
declare function resolveWorkspaceFileActivationTarget(entry: WorkspaceFilePreviewEntry): WorkspaceFilePreviewActivationTarget | null;
|
|
65
|
+
declare function resolveWorkspaceFilePreviewReadiness<TEntry extends WorkspaceFilePreviewEntry>(entry: TEntry): WorkspaceFilePreviewReadiness<TEntry>;
|
|
66
|
+
declare function createWorkspaceFilePreviewLoadedState<TEntry extends WorkspaceFilePreviewEntry, TTarget extends WorkspaceFilePreviewActivationTarget>(input: {
|
|
67
|
+
bytes: Uint8Array | ArrayBuffer;
|
|
68
|
+
contentType?: string | null;
|
|
69
|
+
entry: TEntry;
|
|
70
|
+
target: TTarget;
|
|
71
|
+
}): WorkspaceFilePreviewLoadedState<TEntry, TTarget>;
|
|
72
|
+
declare function resolveWorkspaceFilePreviewName(entry: Pick<WorkspaceFilePreviewEntry, "displayName" | "name" | "path">): string;
|
|
73
|
+
declare function isWorkspaceTextFileTooLarge(sizeBytes?: number | null): boolean;
|
|
74
|
+
declare function isWorkspacePreviewFileTooLarge(sizeBytes?: number | null): boolean;
|
|
75
|
+
declare function decodeWorkspaceTextFile(bytes: Uint8Array | ArrayBuffer): string;
|
|
76
|
+
declare function normalizeWorkspaceFilePreviewBytes(value: Uint8Array | ArrayBuffer): Uint8Array;
|
|
77
|
+
declare function copyWorkspaceFilePreviewBytes(bytes: Uint8Array | ArrayBuffer): Uint8Array<ArrayBuffer>;
|
|
78
|
+
declare function looksLikeBinaryText(content: string): boolean;
|
|
79
|
+
declare function formatWorkspacePreviewByteLimit(sizeBytes: number): string;
|
|
80
|
+
|
|
81
|
+
export { type WorkspaceFilePreviewActivationTarget, type WorkspaceFilePreviewEntry, type WorkspaceFilePreviewEntryKind, type WorkspaceFilePreviewKind, type WorkspaceFilePreviewLoadedState, type WorkspaceFilePreviewReadiness, type WorkspaceFilePreviewReadonlyReason, type WorkspaceFileVisualKind, classifyWorkspaceFilePreviewKind, copyWorkspaceFilePreviewBytes, createWorkspaceFilePreviewLoadedState, decodeWorkspaceTextFile, formatWorkspacePreviewByteLimit, isWorkspaceFileBrowserOpenable, isWorkspacePreviewFileTooLarge, isWorkspaceTextFileTooLarge, looksLikeBinaryText, normalizeWorkspaceFilePreviewBytes, resolveWorkspaceFileActivationTarget, resolveWorkspaceFileExtension, resolveWorkspaceFilePreviewName, resolveWorkspaceFilePreviewReadiness, resolveWorkspaceFileVisualKind, resolveWorkspaceImageMimeType, shouldFilterVideoPlayersForOpenWith, workspaceFilePreviewMaxBytes, workspaceFileTextMaxBytes, workspaceFileVideoHandlerCollisionExtensions };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
classifyWorkspaceFilePreviewKind,
|
|
3
|
+
copyWorkspaceFilePreviewBytes,
|
|
4
|
+
createWorkspaceFilePreviewLoadedState,
|
|
5
|
+
decodeWorkspaceTextFile,
|
|
6
|
+
formatWorkspacePreviewByteLimit,
|
|
7
|
+
isWorkspaceFileBrowserOpenable,
|
|
8
|
+
isWorkspacePreviewFileTooLarge,
|
|
9
|
+
isWorkspaceTextFileTooLarge,
|
|
10
|
+
looksLikeBinaryText,
|
|
11
|
+
normalizeWorkspaceFilePreviewBytes,
|
|
12
|
+
resolveWorkspaceFileActivationTarget,
|
|
13
|
+
resolveWorkspaceFileExtension,
|
|
14
|
+
resolveWorkspaceFilePreviewName,
|
|
15
|
+
resolveWorkspaceFilePreviewReadiness,
|
|
16
|
+
resolveWorkspaceFileVisualKind,
|
|
17
|
+
resolveWorkspaceImageMimeType,
|
|
18
|
+
shouldFilterVideoPlayersForOpenWith,
|
|
19
|
+
workspaceFilePreviewMaxBytes,
|
|
20
|
+
workspaceFileTextMaxBytes,
|
|
21
|
+
workspaceFileVideoHandlerCollisionExtensions
|
|
22
|
+
} from "../chunk-MAJHX2MV.js";
|
|
23
|
+
export {
|
|
24
|
+
classifyWorkspaceFilePreviewKind,
|
|
25
|
+
copyWorkspaceFilePreviewBytes,
|
|
26
|
+
createWorkspaceFilePreviewLoadedState,
|
|
27
|
+
decodeWorkspaceTextFile,
|
|
28
|
+
formatWorkspacePreviewByteLimit,
|
|
29
|
+
isWorkspaceFileBrowserOpenable,
|
|
30
|
+
isWorkspacePreviewFileTooLarge,
|
|
31
|
+
isWorkspaceTextFileTooLarge,
|
|
32
|
+
looksLikeBinaryText,
|
|
33
|
+
normalizeWorkspaceFilePreviewBytes,
|
|
34
|
+
resolveWorkspaceFileActivationTarget,
|
|
35
|
+
resolveWorkspaceFileExtension,
|
|
36
|
+
resolveWorkspaceFilePreviewName,
|
|
37
|
+
resolveWorkspaceFilePreviewReadiness,
|
|
38
|
+
resolveWorkspaceFileVisualKind,
|
|
39
|
+
resolveWorkspaceImageMimeType,
|
|
40
|
+
shouldFilterVideoPlayersForOpenWith,
|
|
41
|
+
workspaceFilePreviewMaxBytes,
|
|
42
|
+
workspaceFileTextMaxBytes,
|
|
43
|
+
workspaceFileVideoHandlerCollisionExtensions
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WorkspaceFilePreviewActivationTarget, WorkspaceFilePreviewEntry, WorkspaceFilePreviewEntryKind, WorkspaceFilePreviewKind, WorkspaceFilePreviewLoadedState, WorkspaceFilePreviewReadiness, WorkspaceFilePreviewReadonlyReason, WorkspaceFileVisualKind, classifyWorkspaceFilePreviewKind, copyWorkspaceFilePreviewBytes, createWorkspaceFilePreviewLoadedState, decodeWorkspaceTextFile, formatWorkspacePreviewByteLimit, isWorkspaceFileBrowserOpenable, isWorkspacePreviewFileTooLarge, isWorkspaceTextFileTooLarge, looksLikeBinaryText, normalizeWorkspaceFilePreviewBytes, resolveWorkspaceFileActivationTarget, resolveWorkspaceFileExtension, resolveWorkspaceFilePreviewName, resolveWorkspaceFilePreviewReadiness, resolveWorkspaceFileVisualKind, resolveWorkspaceImageMimeType, shouldFilterVideoPlayersForOpenWith, workspaceFilePreviewMaxBytes, workspaceFileTextMaxBytes, workspaceFileVideoHandlerCollisionExtensions } from './core/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
classifyWorkspaceFilePreviewKind,
|
|
3
|
+
copyWorkspaceFilePreviewBytes,
|
|
4
|
+
createWorkspaceFilePreviewLoadedState,
|
|
5
|
+
decodeWorkspaceTextFile,
|
|
6
|
+
formatWorkspacePreviewByteLimit,
|
|
7
|
+
isWorkspaceFileBrowserOpenable,
|
|
8
|
+
isWorkspacePreviewFileTooLarge,
|
|
9
|
+
isWorkspaceTextFileTooLarge,
|
|
10
|
+
looksLikeBinaryText,
|
|
11
|
+
normalizeWorkspaceFilePreviewBytes,
|
|
12
|
+
resolveWorkspaceFileActivationTarget,
|
|
13
|
+
resolveWorkspaceFileExtension,
|
|
14
|
+
resolveWorkspaceFilePreviewName,
|
|
15
|
+
resolveWorkspaceFilePreviewReadiness,
|
|
16
|
+
resolveWorkspaceFileVisualKind,
|
|
17
|
+
resolveWorkspaceImageMimeType,
|
|
18
|
+
shouldFilterVideoPlayersForOpenWith,
|
|
19
|
+
workspaceFilePreviewMaxBytes,
|
|
20
|
+
workspaceFileTextMaxBytes,
|
|
21
|
+
workspaceFileVideoHandlerCollisionExtensions
|
|
22
|
+
} from "./chunk-MAJHX2MV.js";
|
|
23
|
+
export {
|
|
24
|
+
classifyWorkspaceFilePreviewKind,
|
|
25
|
+
copyWorkspaceFilePreviewBytes,
|
|
26
|
+
createWorkspaceFilePreviewLoadedState,
|
|
27
|
+
decodeWorkspaceTextFile,
|
|
28
|
+
formatWorkspacePreviewByteLimit,
|
|
29
|
+
isWorkspaceFileBrowserOpenable,
|
|
30
|
+
isWorkspacePreviewFileTooLarge,
|
|
31
|
+
isWorkspaceTextFileTooLarge,
|
|
32
|
+
looksLikeBinaryText,
|
|
33
|
+
normalizeWorkspaceFilePreviewBytes,
|
|
34
|
+
resolveWorkspaceFileActivationTarget,
|
|
35
|
+
resolveWorkspaceFileExtension,
|
|
36
|
+
resolveWorkspaceFilePreviewName,
|
|
37
|
+
resolveWorkspaceFilePreviewReadiness,
|
|
38
|
+
resolveWorkspaceFileVisualKind,
|
|
39
|
+
resolveWorkspaceImageMimeType,
|
|
40
|
+
shouldFilterVideoPlayersForOpenWith,
|
|
41
|
+
workspaceFilePreviewMaxBytes,
|
|
42
|
+
workspaceFileTextMaxBytes,
|
|
43
|
+
workspaceFileVideoHandlerCollisionExtensions
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ReactNode, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
type WorkspaceFilePreviewSurfaceState<TEntry> = {
|
|
4
|
+
status: "empty";
|
|
5
|
+
} | {
|
|
6
|
+
entry: TEntry;
|
|
7
|
+
status: "directory";
|
|
8
|
+
} | {
|
|
9
|
+
entry: TEntry;
|
|
10
|
+
status: "loading";
|
|
11
|
+
} | {
|
|
12
|
+
content: string;
|
|
13
|
+
entry: TEntry;
|
|
14
|
+
status: "text";
|
|
15
|
+
} | {
|
|
16
|
+
entry: TEntry;
|
|
17
|
+
objectUrl: string;
|
|
18
|
+
status: "image";
|
|
19
|
+
} | {
|
|
20
|
+
entry: TEntry;
|
|
21
|
+
message: string;
|
|
22
|
+
status: "readonly";
|
|
23
|
+
} | {
|
|
24
|
+
entry: TEntry;
|
|
25
|
+
message: string;
|
|
26
|
+
status: "unsupported";
|
|
27
|
+
} | {
|
|
28
|
+
entry: TEntry;
|
|
29
|
+
message: string;
|
|
30
|
+
status: "error";
|
|
31
|
+
};
|
|
32
|
+
interface WorkspaceFilePreviewSurfaceProps<TEntry> {
|
|
33
|
+
directoryMessage: string;
|
|
34
|
+
emptyMessage: string;
|
|
35
|
+
frameClassName: string;
|
|
36
|
+
imageAlt: (entry: TEntry) => string;
|
|
37
|
+
imageFrameClassName?: string;
|
|
38
|
+
imageClassName?: string;
|
|
39
|
+
loadingIndicator: ReactNode;
|
|
40
|
+
loadingMessage: string;
|
|
41
|
+
messageClassName?: string;
|
|
42
|
+
renderIcon: (entry: TEntry) => ReactNode;
|
|
43
|
+
state: WorkspaceFilePreviewSurfaceState<TEntry>;
|
|
44
|
+
textClassName?: string;
|
|
45
|
+
textFrameClassName?: string;
|
|
46
|
+
}
|
|
47
|
+
declare function WorkspaceFilePreviewSurface<TEntry>({ directoryMessage, emptyMessage, frameClassName, imageAlt, imageClassName, imageFrameClassName, loadingIndicator, loadingMessage, messageClassName, renderIcon, state, textClassName, textFrameClassName }: WorkspaceFilePreviewSurfaceProps<TEntry>): ReactElement;
|
|
48
|
+
|
|
49
|
+
export { WorkspaceFilePreviewSurface, type WorkspaceFilePreviewSurfaceProps, type WorkspaceFilePreviewSurfaceState };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/react/workspaceFilePreviewSurface.tsx
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
function WorkspaceFilePreviewSurface({
|
|
4
|
+
directoryMessage,
|
|
5
|
+
emptyMessage,
|
|
6
|
+
frameClassName,
|
|
7
|
+
imageAlt,
|
|
8
|
+
imageClassName = "max-h-full max-w-full rounded-[6px] object-contain",
|
|
9
|
+
imageFrameClassName,
|
|
10
|
+
loadingIndicator,
|
|
11
|
+
loadingMessage,
|
|
12
|
+
messageClassName = "max-w-[24ch] text-center text-sm leading-5 text-[var(--text-tertiary)] [overflow-wrap:anywhere]",
|
|
13
|
+
renderIcon,
|
|
14
|
+
state,
|
|
15
|
+
textClassName = "h-full overflow-auto p-4 text-xs leading-5 whitespace-pre-wrap break-words text-[var(--text-primary)]",
|
|
16
|
+
textFrameClassName
|
|
17
|
+
}) {
|
|
18
|
+
switch (state.status) {
|
|
19
|
+
case "directory":
|
|
20
|
+
return /* @__PURE__ */ jsx(WorkspaceFilePreviewFrame, { className: frameClassName, children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center gap-2.5 text-center text-sm leading-5 text-[var(--text-tertiary)]", children: [
|
|
21
|
+
renderIcon(state.entry),
|
|
22
|
+
/* @__PURE__ */ jsx("span", { children: directoryMessage })
|
|
23
|
+
] }) });
|
|
24
|
+
case "loading":
|
|
25
|
+
return /* @__PURE__ */ jsx(WorkspaceFilePreviewFrame, { className: frameClassName, children: /* @__PURE__ */ jsxs("div", { className: "space-y-3 px-4 text-center text-sm text-[var(--text-tertiary)]", children: [
|
|
26
|
+
loadingIndicator,
|
|
27
|
+
/* @__PURE__ */ jsx("span", { children: loadingMessage })
|
|
28
|
+
] }) });
|
|
29
|
+
case "image":
|
|
30
|
+
return /* @__PURE__ */ jsx(
|
|
31
|
+
WorkspaceFilePreviewFrame,
|
|
32
|
+
{
|
|
33
|
+
className: joinClassNames(frameClassName, imageFrameClassName),
|
|
34
|
+
children: /* @__PURE__ */ jsx(
|
|
35
|
+
"img",
|
|
36
|
+
{
|
|
37
|
+
alt: imageAlt(state.entry),
|
|
38
|
+
className: imageClassName,
|
|
39
|
+
src: state.objectUrl
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
case "text":
|
|
45
|
+
return /* @__PURE__ */ jsx(
|
|
46
|
+
WorkspaceFilePreviewFrame,
|
|
47
|
+
{
|
|
48
|
+
className: joinClassNames(frameClassName, textFrameClassName),
|
|
49
|
+
children: /* @__PURE__ */ jsx("pre", { className: textClassName, children: state.content })
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
case "readonly":
|
|
53
|
+
case "unsupported":
|
|
54
|
+
case "error":
|
|
55
|
+
return /* @__PURE__ */ jsx(WorkspaceFilePreviewFrame, { className: frameClassName, children: /* @__PURE__ */ jsxs("div", { className: "space-y-3 px-4 text-center text-sm text-[var(--text-tertiary)]", children: [
|
|
56
|
+
renderIcon(state.entry),
|
|
57
|
+
/* @__PURE__ */ jsx("span", { className: messageClassName, children: state.message })
|
|
58
|
+
] }) });
|
|
59
|
+
case "empty":
|
|
60
|
+
return /* @__PURE__ */ jsx(WorkspaceFilePreviewFrame, { className: frameClassName, children: /* @__PURE__ */ jsx("span", { className: messageClassName, children: emptyMessage }) });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function WorkspaceFilePreviewFrame({
|
|
64
|
+
children,
|
|
65
|
+
className
|
|
66
|
+
}) {
|
|
67
|
+
return /* @__PURE__ */ jsx("div", { className, children });
|
|
68
|
+
}
|
|
69
|
+
function joinClassNames(...classNames) {
|
|
70
|
+
return classNames.filter(Boolean).join(" ");
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
WorkspaceFilePreviewSurface
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/workspaceFilePreviewSurface.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from \"react\";\n\nexport type WorkspaceFilePreviewSurfaceState<TEntry> =\n | { status: \"empty\" }\n | { entry: TEntry; status: \"directory\" }\n | { entry: TEntry; status: \"loading\" }\n | { content: string; entry: TEntry; status: \"text\" }\n | { entry: TEntry; objectUrl: string; status: \"image\" }\n | { entry: TEntry; message: string; status: \"readonly\" }\n | { entry: TEntry; message: string; status: \"unsupported\" }\n | { entry: TEntry; message: string; status: \"error\" };\n\nexport interface WorkspaceFilePreviewSurfaceProps<TEntry> {\n directoryMessage: string;\n emptyMessage: string;\n frameClassName: string;\n imageAlt: (entry: TEntry) => string;\n imageFrameClassName?: string;\n imageClassName?: string;\n loadingIndicator: ReactNode;\n loadingMessage: string;\n messageClassName?: string;\n renderIcon: (entry: TEntry) => ReactNode;\n state: WorkspaceFilePreviewSurfaceState<TEntry>;\n textClassName?: string;\n textFrameClassName?: string;\n}\n\nexport function WorkspaceFilePreviewSurface<TEntry>({\n directoryMessage,\n emptyMessage,\n frameClassName,\n imageAlt,\n imageClassName = \"max-h-full max-w-full rounded-[6px] object-contain\",\n imageFrameClassName,\n loadingIndicator,\n loadingMessage,\n messageClassName = \"max-w-[24ch] text-center text-sm leading-5 text-[var(--text-tertiary)] [overflow-wrap:anywhere]\",\n renderIcon,\n state,\n textClassName = \"h-full overflow-auto p-4 text-xs leading-5 whitespace-pre-wrap break-words text-[var(--text-primary)]\",\n textFrameClassName\n}: WorkspaceFilePreviewSurfaceProps<TEntry>): ReactElement {\n switch (state.status) {\n case \"directory\":\n return (\n <WorkspaceFilePreviewFrame className={frameClassName}>\n <div className=\"flex flex-col items-center justify-center gap-2.5 text-center text-sm leading-5 text-[var(--text-tertiary)]\">\n {renderIcon(state.entry)}\n <span>{directoryMessage}</span>\n </div>\n </WorkspaceFilePreviewFrame>\n );\n case \"loading\":\n return (\n <WorkspaceFilePreviewFrame className={frameClassName}>\n <div className=\"space-y-3 px-4 text-center text-sm text-[var(--text-tertiary)]\">\n {loadingIndicator}\n <span>{loadingMessage}</span>\n </div>\n </WorkspaceFilePreviewFrame>\n );\n case \"image\":\n return (\n <WorkspaceFilePreviewFrame\n className={joinClassNames(frameClassName, imageFrameClassName)}\n >\n <img\n alt={imageAlt(state.entry)}\n className={imageClassName}\n src={state.objectUrl}\n />\n </WorkspaceFilePreviewFrame>\n );\n case \"text\":\n return (\n <WorkspaceFilePreviewFrame\n className={joinClassNames(frameClassName, textFrameClassName)}\n >\n <pre className={textClassName}>{state.content}</pre>\n </WorkspaceFilePreviewFrame>\n );\n case \"readonly\":\n case \"unsupported\":\n case \"error\":\n return (\n <WorkspaceFilePreviewFrame className={frameClassName}>\n <div className=\"space-y-3 px-4 text-center text-sm text-[var(--text-tertiary)]\">\n {renderIcon(state.entry)}\n <span className={messageClassName}>{state.message}</span>\n </div>\n </WorkspaceFilePreviewFrame>\n );\n case \"empty\":\n return (\n <WorkspaceFilePreviewFrame className={frameClassName}>\n <span className={messageClassName}>{emptyMessage}</span>\n </WorkspaceFilePreviewFrame>\n );\n }\n}\n\nfunction WorkspaceFilePreviewFrame({\n children,\n className\n}: {\n children: ReactNode;\n className: string;\n}): ReactElement {\n return <div className={className}>{children}</div>;\n}\n\nfunction joinClassNames(\n ...classNames: Array<string | false | null | undefined>\n): string {\n return classNames.filter(Boolean).join(\" \");\n}\n"],"mappings":";AA+CU,SAEE,KAFF;AAnBH,SAAS,4BAAoC;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA,mBAAmB;AAAA,EACnB;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB;AACF,GAA2D;AACzD,UAAQ,MAAM,QAAQ;AAAA,IACpB,KAAK;AACH,aACE,oBAAC,6BAA0B,WAAW,gBACpC,+BAAC,SAAI,WAAU,+GACZ;AAAA,mBAAW,MAAM,KAAK;AAAA,QACvB,oBAAC,UAAM,4BAAiB;AAAA,SAC1B,GACF;AAAA,IAEJ,KAAK;AACH,aACE,oBAAC,6BAA0B,WAAW,gBACpC,+BAAC,SAAI,WAAU,kEACZ;AAAA;AAAA,QACD,oBAAC,UAAM,0BAAe;AAAA,SACxB,GACF;AAAA,IAEJ,KAAK;AACH,aACE;AAAA,QAAC;AAAA;AAAA,UACC,WAAW,eAAe,gBAAgB,mBAAmB;AAAA,UAE7D;AAAA,YAAC;AAAA;AAAA,cACC,KAAK,SAAS,MAAM,KAAK;AAAA,cACzB,WAAW;AAAA,cACX,KAAK,MAAM;AAAA;AAAA,UACb;AAAA;AAAA,MACF;AAAA,IAEJ,KAAK;AACH,aACE;AAAA,QAAC;AAAA;AAAA,UACC,WAAW,eAAe,gBAAgB,kBAAkB;AAAA,UAE5D,8BAAC,SAAI,WAAW,eAAgB,gBAAM,SAAQ;AAAA;AAAA,MAChD;AAAA,IAEJ,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aACE,oBAAC,6BAA0B,WAAW,gBACpC,+BAAC,SAAI,WAAU,kEACZ;AAAA,mBAAW,MAAM,KAAK;AAAA,QACvB,oBAAC,UAAK,WAAW,kBAAmB,gBAAM,SAAQ;AAAA,SACpD,GACF;AAAA,IAEJ,KAAK;AACH,aACE,oBAAC,6BAA0B,WAAW,gBACpC,8BAAC,UAAK,WAAW,kBAAmB,wBAAa,GACnD;AAAA,EAEN;AACF;AAEA,SAAS,0BAA0B;AAAA,EACjC;AAAA,EACA;AACF,GAGiB;AACf,SAAO,oBAAC,SAAI,WAAuB,UAAS;AAC9C;AAEA,SAAS,kBACJ,YACK;AACR,SAAO,WAAW,OAAO,OAAO,EAAE,KAAK,GAAG;AAC5C;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tutti-os/workspace-file-preview",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./core": {
|
|
13
|
+
"types": "./dist/core/index.d.ts",
|
|
14
|
+
"import": "./dist/core/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"types": "./dist/react/index.d.ts",
|
|
18
|
+
"import": "./dist/react/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/tutti-os/tutti.git",
|
|
28
|
+
"directory": "packages/workspace/file-preview"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^24.0.1",
|
|
32
|
+
"@types/react": "^19.1.6",
|
|
33
|
+
"react": "^19.1.0",
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"@tutti-os/config-tsconfig": "0.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "^19.1.0"
|
|
39
|
+
},
|
|
40
|
+
"nextop": {
|
|
41
|
+
"tailwindSourceRoot": "src"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup --config tsup.config.ts",
|
|
48
|
+
"test": "node --test --experimental-strip-types \"./src/**/*.test.ts\"",
|
|
49
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
50
|
+
}
|
|
51
|
+
}
|