@preptex/ui 0.0.0-stage → 0.1.0
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 +21 -0
- package/README.md +54 -2
- package/dist/components/CatalogDialog.css +401 -0
- package/dist/components/CatalogDialog.d.ts +16 -0
- package/dist/components/CatalogDialog.js +224 -0
- package/dist/components/CatalogDialog.js.map +1 -0
- package/dist/components/Codeview.css +127 -0
- package/dist/components/Codeview.d.ts +14 -0
- package/dist/components/Codeview.js +74 -0
- package/dist/components/Codeview.js.map +1 -0
- package/dist/components/ConfigurationSummary.d.ts +18 -0
- package/dist/components/ConfigurationSummary.js +44 -0
- package/dist/components/ConfigurationSummary.js.map +1 -0
- package/dist/components/ControlPanel.css +792 -0
- package/dist/components/ControlPanel.d.ts +48 -0
- package/dist/components/ControlPanel.js +218 -0
- package/dist/components/ControlPanel.js.map +1 -0
- package/dist/components/EditPreviewDialog.css +308 -0
- package/dist/components/EditPreviewDialog.d.ts +18 -0
- package/dist/components/EditPreviewDialog.js +46 -0
- package/dist/components/EditPreviewDialog.js.map +1 -0
- package/dist/components/Filetree.css +344 -0
- package/dist/components/Filetree.d.ts +22 -0
- package/dist/components/Filetree.js +250 -0
- package/dist/components/Filetree.js.map +1 -0
- package/dist/components/LogDialog.css +154 -0
- package/dist/components/LogDialog.d.ts +16 -0
- package/dist/components/LogDialog.js +42 -0
- package/dist/components/LogDialog.js.map +1 -0
- package/dist/components/LogPanel.css +106 -0
- package/dist/components/LogPanel.d.ts +10 -0
- package/dist/components/LogPanel.js +30 -0
- package/dist/components/LogPanel.js.map +1 -0
- package/dist/components/MetadataDialog.css +275 -0
- package/dist/components/MetadataDialog.d.ts +13 -0
- package/dist/components/MetadataDialog.js +67 -0
- package/dist/components/MetadataDialog.js.map +1 -0
- package/dist/components/NodeActionBar.css +163 -0
- package/dist/components/NodeActionBar.d.ts +19 -0
- package/dist/components/NodeActionBar.js +114 -0
- package/dist/components/NodeActionBar.js.map +1 -0
- package/dist/components/OperationsDialog.css +154 -0
- package/dist/components/OperationsDialog.d.ts +8 -0
- package/dist/components/OperationsDialog.js +27 -0
- package/dist/components/OperationsDialog.js.map +1 -0
- package/dist/components/PrepTeXWorkspace.css +224 -0
- package/dist/components/PrepTeXWorkspace.d.ts +125 -0
- package/dist/components/PrepTeXWorkspace.js +593 -0
- package/dist/components/PrepTeXWorkspace.js.map +1 -0
- package/dist/components/ProjectSetupDialog.css +292 -0
- package/dist/components/ProjectSetupDialog.d.ts +18 -0
- package/dist/components/ProjectSetupDialog.js +134 -0
- package/dist/components/ProjectSetupDialog.js.map +1 -0
- package/dist/components/WelcomeEmptyState.css +105 -0
- package/dist/components/WelcomeEmptyState.d.ts +9 -0
- package/dist/components/WelcomeEmptyState.js +28 -0
- package/dist/components/WelcomeEmptyState.js.map +1 -0
- package/dist/components/WorkspaceHeader.css +410 -0
- package/dist/components/WorkspaceHeader.d.ts +66 -0
- package/dist/components/WorkspaceHeader.js +297 -0
- package/dist/components/WorkspaceHeader.js.map +1 -0
- package/dist/components/astview/ASTview.css +690 -0
- package/dist/components/astview/ASTview.d.ts +27 -0
- package/dist/components/astview/ASTview.js +314 -0
- package/dist/components/astview/ASTview.js.map +1 -0
- package/dist/components/astview/TreeNode.d.ts +8 -0
- package/dist/components/astview/TreeNode.js +237 -0
- package/dist/components/astview/TreeNode.js.map +1 -0
- package/dist/components/astview/treebuilder.d.ts +13 -0
- package/dist/components/astview/treebuilder.js +292 -0
- package/dist/components/astview/treebuilder.js.map +1 -0
- package/dist/components/index.d.ts +18 -0
- package/dist/components/index.js +19 -0
- package/dist/components/index.js.map +1 -0
- package/dist/docs/architecture.md +46 -0
- package/dist/docs/integration.md +107 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/model/useArtifacts.d.ts +14 -0
- package/dist/model/useArtifacts.js +32 -0
- package/dist/model/useArtifacts.js.map +1 -0
- package/dist/model/useControl.d.ts +15 -0
- package/dist/model/useControl.js +19 -0
- package/dist/model/useControl.js.map +1 -0
- package/dist/model/useFiles.d.ts +53 -0
- package/dist/model/useFiles.js +283 -0
- package/dist/model/useFiles.js.map +1 -0
- package/dist/model/useProjectConfiguration.d.ts +32 -0
- package/dist/model/useProjectConfiguration.js +151 -0
- package/dist/model/useProjectConfiguration.js.map +1 -0
- package/dist/model/useWorkspaceLayout.d.ts +26 -0
- package/dist/model/useWorkspaceLayout.js +55 -0
- package/dist/model/useWorkspaceLayout.js.map +1 -0
- package/dist/services/zip.d.ts +24 -0
- package/dist/services/zip.js +279 -0
- package/dist/services/zip.js.map +1 -0
- package/dist/styles/bundle.css +4652 -0
- package/dist/styles/tokens.css +77 -0
- package/dist/types/LayoutNode.d.ts +30 -0
- package/dist/types/LayoutNode.js +18 -0
- package/dist/types/LayoutNode.js.map +1 -0
- package/dist/types/artifacts.d.ts +9 -0
- package/dist/types/artifacts.js +2 -0
- package/dist/types/artifacts.js.map +1 -0
- package/dist/types/errors.d.ts +14 -0
- package/dist/types/errors.js +2 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/files.d.ts +12 -0
- package/dist/types/files.js +2 -0
- package/dist/types/files.js.map +1 -0
- package/dist/utils/dropEntries.d.ts +6 -0
- package/dist/utils/dropEntries.js +58 -0
- package/dist/utils/dropEntries.js.map +1 -0
- package/dist/utils/fileFilter.d.ts +10 -0
- package/dist/utils/fileFilter.js +68 -0
- package/dist/utils/fileFilter.js.map +1 -0
- package/dist/utils/transformOutput.d.ts +24 -0
- package/dist/utils/transformOutput.js +83 -0
- package/dist/utils/transformOutput.js.map +1 -0
- package/package.json +103 -4
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
.FiletreePane {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
height: 100%;
|
|
5
|
+
min-height: 0;
|
|
6
|
+
background: var(--color-surface);
|
|
7
|
+
border-right: 1px solid var(--color-border);
|
|
8
|
+
transition: background 120ms ease, outline 120ms ease;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.FiletreePane.is-drag-over {
|
|
12
|
+
background: rgba(37, 99, 235, 0.05);
|
|
13
|
+
outline: 2px dashed var(--color-primary);
|
|
14
|
+
outline-offset: -3px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.FiletreeHeader {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: space-between;
|
|
21
|
+
gap: 8px;
|
|
22
|
+
padding: 10px 10px 6px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.FiletreeHeaderTitleRow {
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
gap: 6px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.FiletreeHeading {
|
|
32
|
+
margin: 0;
|
|
33
|
+
font-size: 11px;
|
|
34
|
+
font-weight: 700;
|
|
35
|
+
letter-spacing: 0.06em;
|
|
36
|
+
text-transform: uppercase;
|
|
37
|
+
color: var(--color-text-muted);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.FiletreeCount {
|
|
41
|
+
font-size: 10px;
|
|
42
|
+
font-weight: 600;
|
|
43
|
+
padding: 1px 6px;
|
|
44
|
+
border-radius: 999px;
|
|
45
|
+
background: var(--color-surface-subtle);
|
|
46
|
+
color: var(--color-text-muted);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.FiletreeHeaderActions {
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
gap: 4px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.FiletreeToolBtn {
|
|
56
|
+
height: 22px;
|
|
57
|
+
padding: 0 7px;
|
|
58
|
+
border-radius: 5px;
|
|
59
|
+
border: 1px solid var(--color-border);
|
|
60
|
+
background: var(--color-surface);
|
|
61
|
+
color: var(--color-text-muted);
|
|
62
|
+
font: inherit;
|
|
63
|
+
font-size: 11px;
|
|
64
|
+
font-weight: 500;
|
|
65
|
+
cursor: pointer;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.FiletreeToolBtn:hover {
|
|
69
|
+
background: var(--color-surface-subtle);
|
|
70
|
+
color: var(--color-text);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.FiletreeUpload {
|
|
74
|
+
display: grid;
|
|
75
|
+
grid-template-columns: 1fr 1fr;
|
|
76
|
+
gap: 6px;
|
|
77
|
+
padding: 4px 10px 6px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.FiletreeUploadBtn {
|
|
81
|
+
height: 28px;
|
|
82
|
+
padding: 0 8px;
|
|
83
|
+
border-radius: 6px;
|
|
84
|
+
border: 1px solid var(--color-border);
|
|
85
|
+
background: var(--color-surface-subtle);
|
|
86
|
+
color: var(--color-text);
|
|
87
|
+
font: inherit;
|
|
88
|
+
font-size: 11px;
|
|
89
|
+
font-weight: 500;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.FiletreeUploadBtn:hover {
|
|
94
|
+
border-color: var(--color-border-strong);
|
|
95
|
+
background: #edf1f6;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.FiletreeSearchRow {
|
|
99
|
+
padding: 2px 10px 6px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.FiletreeSearchInput {
|
|
103
|
+
width: 100%;
|
|
104
|
+
box-sizing: border-box;
|
|
105
|
+
height: 28px;
|
|
106
|
+
padding: 0 8px;
|
|
107
|
+
border-radius: 6px;
|
|
108
|
+
border: 1px solid var(--color-border);
|
|
109
|
+
background: var(--color-bg);
|
|
110
|
+
color: var(--color-text);
|
|
111
|
+
font: inherit;
|
|
112
|
+
font-size: 12px;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.FiletreeSearchInput:focus {
|
|
116
|
+
outline: none;
|
|
117
|
+
border-color: var(--color-primary);
|
|
118
|
+
background: var(--color-surface);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.FiletreeNewFileForm {
|
|
122
|
+
margin: 0 10px 8px;
|
|
123
|
+
padding: 8px;
|
|
124
|
+
border-radius: 8px;
|
|
125
|
+
border: 1px solid var(--color-border-strong);
|
|
126
|
+
background: var(--color-surface-subtle);
|
|
127
|
+
display: flex;
|
|
128
|
+
flex-direction: column;
|
|
129
|
+
gap: 6px;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.FiletreeNewFileInput {
|
|
133
|
+
width: 100%;
|
|
134
|
+
box-sizing: border-box;
|
|
135
|
+
height: 28px;
|
|
136
|
+
padding: 0 8px;
|
|
137
|
+
border-radius: 6px;
|
|
138
|
+
border: 1px solid var(--color-border);
|
|
139
|
+
background: var(--color-surface);
|
|
140
|
+
font: inherit;
|
|
141
|
+
font-size: 12px;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.FiletreeNewFileButtons {
|
|
145
|
+
display: flex;
|
|
146
|
+
justify-content: flex-end;
|
|
147
|
+
gap: 6px;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.FiletreeNewFileConfirm,
|
|
151
|
+
.FiletreeNewFileCancel {
|
|
152
|
+
height: 24px;
|
|
153
|
+
padding: 0 9px;
|
|
154
|
+
border-radius: 5px;
|
|
155
|
+
font: inherit;
|
|
156
|
+
font-size: 11px;
|
|
157
|
+
cursor: pointer;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.FiletreeNewFileConfirm {
|
|
161
|
+
border: 1px solid var(--color-primary);
|
|
162
|
+
background: var(--color-primary);
|
|
163
|
+
color: #ffffff;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.FiletreeNewFileCancel {
|
|
167
|
+
border: 1px solid var(--color-border);
|
|
168
|
+
background: var(--color-surface);
|
|
169
|
+
color: var(--color-text);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.FiletreeUploadError {
|
|
173
|
+
margin: 0 10px 6px;
|
|
174
|
+
padding: 6px 8px;
|
|
175
|
+
border-radius: 6px;
|
|
176
|
+
background: rgba(220, 38, 38, 0.08);
|
|
177
|
+
color: var(--color-danger);
|
|
178
|
+
font-size: 11px;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.FiletreeUploadNotice {
|
|
182
|
+
margin: 0 10px 6px;
|
|
183
|
+
padding: 6px 8px;
|
|
184
|
+
border-radius: 6px;
|
|
185
|
+
background: rgba(37, 99, 235, 0.08);
|
|
186
|
+
color: var(--color-text-muted);
|
|
187
|
+
font-size: 11px;
|
|
188
|
+
display: flex;
|
|
189
|
+
align-items: flex-start;
|
|
190
|
+
justify-content: space-between;
|
|
191
|
+
gap: 6px;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.FiletreeUploadNoticeDismiss {
|
|
195
|
+
border: none;
|
|
196
|
+
background: transparent;
|
|
197
|
+
color: inherit;
|
|
198
|
+
cursor: pointer;
|
|
199
|
+
padding: 0 2px;
|
|
200
|
+
font-size: 13px;
|
|
201
|
+
line-height: 1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.FiletreeList {
|
|
205
|
+
flex: 1;
|
|
206
|
+
min-height: 0;
|
|
207
|
+
overflow-y: auto;
|
|
208
|
+
padding: 2px 6px 12px;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.FiletreeEmpty {
|
|
212
|
+
padding: 16px 10px;
|
|
213
|
+
text-align: center;
|
|
214
|
+
font-size: 12px;
|
|
215
|
+
color: var(--color-text-muted);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.FiletreeRow {
|
|
219
|
+
display: flex;
|
|
220
|
+
align-items: center;
|
|
221
|
+
gap: 2px;
|
|
222
|
+
border-radius: 6px;
|
|
223
|
+
min-height: 28px;
|
|
224
|
+
padding-right: 4px;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.FiletreeRow:hover {
|
|
228
|
+
background: var(--color-surface-subtle);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.FiletreeRow.is-selected {
|
|
232
|
+
background: rgba(37, 99, 235, 0.1);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.FiletreeItem {
|
|
236
|
+
flex: 1;
|
|
237
|
+
min-width: 0;
|
|
238
|
+
display: flex;
|
|
239
|
+
align-items: center;
|
|
240
|
+
gap: 5px;
|
|
241
|
+
height: 28px;
|
|
242
|
+
padding: 0 4px;
|
|
243
|
+
border: none;
|
|
244
|
+
background: transparent;
|
|
245
|
+
color: var(--color-text);
|
|
246
|
+
font: inherit;
|
|
247
|
+
font-size: 12px;
|
|
248
|
+
text-align: left;
|
|
249
|
+
cursor: pointer;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.FiletreeChevron {
|
|
253
|
+
width: 12px;
|
|
254
|
+
flex-shrink: 0;
|
|
255
|
+
font-size: 10px;
|
|
256
|
+
color: var(--color-text-muted);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.FiletreeTypeIcon {
|
|
260
|
+
font-size: 11px;
|
|
261
|
+
flex-shrink: 0;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.FiletreeName {
|
|
265
|
+
flex: 1;
|
|
266
|
+
min-width: 0;
|
|
267
|
+
overflow: hidden;
|
|
268
|
+
text-overflow: ellipsis;
|
|
269
|
+
white-space: nowrap;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.FiletreeName--folder {
|
|
273
|
+
font-weight: 600;
|
|
274
|
+
color: var(--color-text);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.FiletreeRow.is-selected .FiletreeName {
|
|
278
|
+
color: var(--color-primary);
|
|
279
|
+
font-weight: 600;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.FiletreeEntryBadge {
|
|
283
|
+
flex-shrink: 0;
|
|
284
|
+
font-size: 10px;
|
|
285
|
+
font-weight: 700;
|
|
286
|
+
padding: 1px 5px;
|
|
287
|
+
border-radius: 4px;
|
|
288
|
+
background: rgba(22, 163, 74, 0.14);
|
|
289
|
+
color: #15803d;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.FiletreeExtBadge {
|
|
293
|
+
flex-shrink: 0;
|
|
294
|
+
font-size: 10px;
|
|
295
|
+
color: var(--color-text-muted);
|
|
296
|
+
opacity: 0.7;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.FiletreeRow:hover .FiletreeExtBadge {
|
|
300
|
+
display: none;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.FiletreeAction {
|
|
304
|
+
display: none;
|
|
305
|
+
width: 22px;
|
|
306
|
+
height: 22px;
|
|
307
|
+
padding: 0;
|
|
308
|
+
border: none;
|
|
309
|
+
border-radius: 4px;
|
|
310
|
+
background: transparent;
|
|
311
|
+
color: var(--color-text-muted);
|
|
312
|
+
font-size: 11px;
|
|
313
|
+
cursor: pointer;
|
|
314
|
+
align-items: center;
|
|
315
|
+
justify-content: center;
|
|
316
|
+
flex-shrink: 0;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.FiletreeRow:hover .FiletreeAction,
|
|
320
|
+
.FiletreeRow:focus-within .FiletreeAction {
|
|
321
|
+
display: inline-flex;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.FiletreeAction:hover {
|
|
325
|
+
background: rgba(15, 23, 42, 0.08);
|
|
326
|
+
color: var(--color-text);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.FiletreeAction--entry:hover {
|
|
330
|
+
color: #d97706;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.FiletreeAction--remove:hover {
|
|
334
|
+
background: rgba(220, 38, 38, 0.12);
|
|
335
|
+
color: var(--color-danger);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
section[aria-label='Files'] {
|
|
339
|
+
height: 100%;
|
|
340
|
+
min-height: 0;
|
|
341
|
+
display: flex;
|
|
342
|
+
flex-direction: column;
|
|
343
|
+
gap: 12px;
|
|
344
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type DroppedFileItem } from '../utils/dropEntries.js';export interface FiletreeProps {
|
|
3
|
+
readonly files: string[];
|
|
4
|
+
readonly selected?: string;
|
|
5
|
+
readonly entryPath?: string | null;
|
|
6
|
+
readonly onSelect?: (path: string) => void;
|
|
7
|
+
readonly onSetEntry?: (path: string) => void;
|
|
8
|
+
readonly onCreateFile?: (path: string) => void;
|
|
9
|
+
readonly onDownload?: (path: string) => void;
|
|
10
|
+
readonly onRemove?: (path: string) => void;
|
|
11
|
+
readonly onUploadFiles?: (files: FileList) => void;
|
|
12
|
+
readonly onUploadFolder?: (files: FileList) => void;
|
|
13
|
+
readonly onDropFiles?: (items: readonly DroppedFileItem[]) => void;
|
|
14
|
+
readonly uploadError?: string | null;
|
|
15
|
+
readonly uploadNotice?: string | null;
|
|
16
|
+
readonly onDismissUploadNotice?: () => void;
|
|
17
|
+
readonly uploadFilesTrigger?: number;
|
|
18
|
+
readonly uploadFolderTrigger?: number;
|
|
19
|
+
readonly newFileTrigger?: number;
|
|
20
|
+
readonly onCollapseSidebar?: () => void;
|
|
21
|
+
}
|
|
22
|
+
export default function Filetree({ files, selected, entryPath, onSelect, onSetEntry, onCreateFile, onDownload, onRemove, onUploadFiles, onUploadFolder, onDropFiles, uploadError, uploadNotice, onDismissUploadNotice, uploadFilesTrigger, uploadFolderTrigger, newFileTrigger, onCollapseSidebar, }: FiletreeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { extractDroppedFiles } from '../utils/dropEntries.js';
|
|
4
|
+
import './Filetree.css';
|
|
5
|
+
const NAME_TRUNCATE_THRESHOLD = 28;
|
|
6
|
+
const NAME_KEEP_HEAD = 14;
|
|
7
|
+
const NAME_KEEP_TAIL = 10;
|
|
8
|
+
function shortenFilenameMiddle(name) {
|
|
9
|
+
if (name.length <= NAME_TRUNCATE_THRESHOLD)
|
|
10
|
+
return name;
|
|
11
|
+
return `${name.slice(0, NAME_KEEP_HEAD)}...${name.slice(-NAME_KEEP_TAIL)}`;
|
|
12
|
+
}
|
|
13
|
+
function getFileExtensionBadge(filename) {
|
|
14
|
+
const dot = filename.lastIndexOf('.');
|
|
15
|
+
if (dot <= 0 || dot === filename.length - 1)
|
|
16
|
+
return 'file';
|
|
17
|
+
return filename.slice(dot + 1).toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
function buildFiletree(paths) {
|
|
20
|
+
const root = {
|
|
21
|
+
folders: new Map(),
|
|
22
|
+
files: [],
|
|
23
|
+
};
|
|
24
|
+
for (const rawPath of paths) {
|
|
25
|
+
const clean = rawPath.trim().replace(/^\/+|\/+$/g, '');
|
|
26
|
+
if (!clean)
|
|
27
|
+
continue;
|
|
28
|
+
const parts = clean.split('/').filter(Boolean);
|
|
29
|
+
let curr = root;
|
|
30
|
+
let prefix = '';
|
|
31
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
32
|
+
const part = parts[i];
|
|
33
|
+
if (!part)
|
|
34
|
+
continue;
|
|
35
|
+
const isLast = i === parts.length - 1;
|
|
36
|
+
prefix = prefix ? `${prefix}/${part}` : part;
|
|
37
|
+
if (isLast) {
|
|
38
|
+
curr.files.push({ name: part, path: prefix, type: 'file' });
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const existingFolder = curr.folders.get(part);
|
|
42
|
+
const folder = existingFolder ?? {
|
|
43
|
+
name: part,
|
|
44
|
+
path: prefix,
|
|
45
|
+
type: 'folder',
|
|
46
|
+
children: [],
|
|
47
|
+
};
|
|
48
|
+
if (!existingFolder) {
|
|
49
|
+
curr.folders.set(part, folder);
|
|
50
|
+
}
|
|
51
|
+
const subFolders = new Map();
|
|
52
|
+
const subFiles = [];
|
|
53
|
+
for (const c of folder.children ?? []) {
|
|
54
|
+
if (c.type === 'folder')
|
|
55
|
+
subFolders.set(c.name, c);
|
|
56
|
+
else
|
|
57
|
+
subFiles.push(c);
|
|
58
|
+
}
|
|
59
|
+
curr = {
|
|
60
|
+
folders: subFolders,
|
|
61
|
+
files: subFiles,
|
|
62
|
+
};
|
|
63
|
+
folder._sub = curr;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function finalize(nodeMap) {
|
|
68
|
+
const folders = Array.from(nodeMap.folders.values())
|
|
69
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
70
|
+
.map((f) => {
|
|
71
|
+
const sub = f._sub;
|
|
72
|
+
return {
|
|
73
|
+
name: f.name,
|
|
74
|
+
path: f.path,
|
|
75
|
+
type: 'folder',
|
|
76
|
+
children: sub ? finalize(sub) : [],
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
const files = nodeMap.files.sort((a, b) => a.name.localeCompare(b.name));
|
|
80
|
+
return [...folders, ...files];
|
|
81
|
+
}
|
|
82
|
+
return finalize(root);
|
|
83
|
+
}
|
|
84
|
+
function collectFolderPaths(nodes) {
|
|
85
|
+
const result = [];
|
|
86
|
+
for (const node of nodes) {
|
|
87
|
+
if (node.type === 'folder') {
|
|
88
|
+
result.push(node.path);
|
|
89
|
+
if (node.children) {
|
|
90
|
+
result.push(...collectFolderPaths(node.children));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function TreeNode({ node, depth, selected, entryPath, expandedFolders, forceExpandAll, onToggleFolder, onSelect, onSetEntry, onDownload, onRemove, }) {
|
|
97
|
+
const isFolder = node.type === 'folder';
|
|
98
|
+
const open = isFolder ? forceExpandAll || expandedFolders.has(node.path) : false;
|
|
99
|
+
const isSelected = !isFolder && selected === node.path;
|
|
100
|
+
const isEntry = !isFolder && entryPath === node.path;
|
|
101
|
+
const toggleOrSelect = () => {
|
|
102
|
+
if (isFolder) {
|
|
103
|
+
onToggleFolder(node.path);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
onSelect?.(node.path);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
return (_jsxs("div", { children: [_jsxs("div", { className: `FiletreeRow${isSelected ? ' is-selected' : ''}${isEntry ? ' is-entry' : ''}`, style: { paddingLeft: `${depth * 14 + 6}px` }, role: "treeitem", "aria-selected": isSelected, "aria-expanded": isFolder ? open : undefined, children: [_jsxs("button", { type: "button", className: "FiletreeItem", onClick: toggleOrSelect, title: node.path, "aria-expanded": isFolder ? open : undefined, children: [_jsx("span", { className: "FiletreeChevron", "aria-hidden": "true", children: isFolder ? (open ? '▾' : '▸') : '' }), _jsx("span", { className: "FiletreeTypeIcon", "aria-hidden": "true", children: isFolder ? '📁' : '' }), _jsx("span", { className: isFolder ? 'FiletreeName FiletreeName--folder' : 'FiletreeName', children: isFolder ? node.name : shortenFilenameMiddle(node.name) }), !isFolder && isEntry ? _jsx("span", { className: "FiletreeEntryBadge", children: "Entry" }) : null, !isFolder && !isEntry ? (_jsx("span", { className: "FiletreeExtBadge", children: getFileExtensionBadge(node.name) })) : null] }), !isFolder && !isEntry && onSetEntry ? (_jsx("button", { type: "button", className: "FiletreeAction FiletreeAction--entry", "aria-label": `Set ${node.path} as entry`, title: `Set ${node.path} as entry file`, onClick: (e) => {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
e.stopPropagation();
|
|
112
|
+
onSetEntry(node.path);
|
|
113
|
+
}, children: _jsx("span", { "aria-hidden": "true", children: "\u2605" }) })) : null, !isFolder && onDownload ? (_jsx("button", { type: "button", className: "FiletreeAction", "aria-label": `Download ${node.path}`, title: `Download ${node.path}`, onClick: (e) => {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
e.stopPropagation();
|
|
116
|
+
onDownload(node.path);
|
|
117
|
+
}, children: _jsx("span", { "aria-hidden": "true", children: "\u2193" }) })) : null, !isFolder && onRemove ? (_jsx("button", { type: "button", className: "FiletreeAction FiletreeAction--remove", "aria-label": `Remove ${node.path}`, title: `Remove ${node.path}`, onClick: (e) => {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
e.stopPropagation();
|
|
120
|
+
onRemove(node.path);
|
|
121
|
+
}, children: _jsx("span", { "aria-hidden": "true", children: "\u2715" }) })) : null] }), isFolder && open
|
|
122
|
+
? node.children?.map((child) => (_jsx(TreeNode, { node: child, depth: depth + 1, selected: selected, entryPath: entryPath, expandedFolders: expandedFolders, forceExpandAll: forceExpandAll, onToggleFolder: onToggleFolder, onSelect: onSelect, onSetEntry: onSetEntry, onDownload: onDownload, onRemove: onRemove }, `${child.type}:${child.path}`)))
|
|
123
|
+
: null] }));
|
|
124
|
+
}
|
|
125
|
+
export default function Filetree({ files, selected, entryPath, onSelect, onSetEntry, onCreateFile, onDownload, onRemove, onUploadFiles, onUploadFolder, onDropFiles, uploadError, uploadNotice, onDismissUploadNotice, uploadFilesTrigger, uploadFolderTrigger, newFileTrigger, onCollapseSidebar, }) {
|
|
126
|
+
const inputRef = useRef(null);
|
|
127
|
+
const folderInputRef = useRef(null);
|
|
128
|
+
const newFileInputRef = useRef(null);
|
|
129
|
+
const [filterText, setFilterText] = useState('');
|
|
130
|
+
const [creatingFile, setCreatingFile] = useState(false);
|
|
131
|
+
const [newFilePath, setNewFilePath] = useState('');
|
|
132
|
+
const [isDragOver, setIsDragOver] = useState(false);
|
|
133
|
+
const [collapsedFolders, setCollapsedFolders] = useState(() => new Set());
|
|
134
|
+
const filteredFiles = useMemo(() => {
|
|
135
|
+
const query = filterText.trim().toLowerCase();
|
|
136
|
+
if (!query)
|
|
137
|
+
return files;
|
|
138
|
+
return files.filter((path) => path.toLowerCase().includes(query));
|
|
139
|
+
}, [files, filterText]);
|
|
140
|
+
const tree = useMemo(() => buildFiletree(filteredFiles), [filteredFiles]);
|
|
141
|
+
const allFolders = useMemo(() => collectFolderPaths(tree), [tree]);
|
|
142
|
+
const expandedFolders = useMemo(() => {
|
|
143
|
+
const set = new Set();
|
|
144
|
+
for (const folder of allFolders) {
|
|
145
|
+
if (!collapsedFolders.has(folder)) {
|
|
146
|
+
set.add(folder);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return set;
|
|
150
|
+
}, [allFolders, collapsedFolders]);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const el = folderInputRef.current;
|
|
153
|
+
if (!el)
|
|
154
|
+
return;
|
|
155
|
+
el.setAttribute('webkitdirectory', '');
|
|
156
|
+
el.setAttribute('directory', '');
|
|
157
|
+
}, []);
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (uploadFilesTrigger && uploadFilesTrigger > 0) {
|
|
160
|
+
inputRef.current?.click();
|
|
161
|
+
}
|
|
162
|
+
}, [uploadFilesTrigger]);
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (uploadFolderTrigger && uploadFolderTrigger > 0) {
|
|
165
|
+
folderInputRef.current?.click();
|
|
166
|
+
}
|
|
167
|
+
}, [uploadFolderTrigger]);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (newFileTrigger && newFileTrigger > 0 && onCreateFile) {
|
|
170
|
+
setCreatingFile(true);
|
|
171
|
+
window.setTimeout(() => newFileInputRef.current?.focus(), 0);
|
|
172
|
+
}
|
|
173
|
+
}, [newFileTrigger, onCreateFile]);
|
|
174
|
+
const onFilesChange = (e) => {
|
|
175
|
+
const fileList = e.target.files;
|
|
176
|
+
if (fileList && fileList.length > 0 && onUploadFiles) {
|
|
177
|
+
onUploadFiles(fileList);
|
|
178
|
+
}
|
|
179
|
+
e.target.value = '';
|
|
180
|
+
};
|
|
181
|
+
const onFolderChange = (e) => {
|
|
182
|
+
const fileList = e.target.files;
|
|
183
|
+
if (fileList && fileList.length > 0) {
|
|
184
|
+
if (onUploadFolder) {
|
|
185
|
+
onUploadFolder(fileList);
|
|
186
|
+
}
|
|
187
|
+
else if (onUploadFiles) {
|
|
188
|
+
onUploadFiles(fileList);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
e.target.value = '';
|
|
192
|
+
};
|
|
193
|
+
const handleToggleFolder = (path) => {
|
|
194
|
+
setCollapsedFolders((prev) => {
|
|
195
|
+
const next = new Set(prev);
|
|
196
|
+
if (next.has(path)) {
|
|
197
|
+
next.delete(path);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
next.add(path);
|
|
201
|
+
}
|
|
202
|
+
return next;
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
const handleExpandAll = () => {
|
|
206
|
+
setCollapsedFolders(new Set());
|
|
207
|
+
};
|
|
208
|
+
const handleCollapseAll = () => {
|
|
209
|
+
setCollapsedFolders(new Set(allFolders));
|
|
210
|
+
};
|
|
211
|
+
const handleCreateSubmit = (event) => {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
const cleaned = newFilePath.trim().replace(/\\/g, '/').replace(/^\/+|\/+$/g, '');
|
|
214
|
+
if (!cleaned || !onCreateFile)
|
|
215
|
+
return;
|
|
216
|
+
onCreateFile(cleaned);
|
|
217
|
+
setNewFilePath('');
|
|
218
|
+
setCreatingFile(false);
|
|
219
|
+
};
|
|
220
|
+
const handleDragOver = (event) => {
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
223
|
+
if (!isDragOver)
|
|
224
|
+
setIsDragOver(true);
|
|
225
|
+
};
|
|
226
|
+
const handleDragLeave = () => {
|
|
227
|
+
setIsDragOver(false);
|
|
228
|
+
};
|
|
229
|
+
const handleDrop = async (event) => {
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
setIsDragOver(false);
|
|
232
|
+
const items = await extractDroppedFiles(event.dataTransfer);
|
|
233
|
+
if (items.length === 0)
|
|
234
|
+
return;
|
|
235
|
+
if (onDropFiles) {
|
|
236
|
+
onDropFiles(items);
|
|
237
|
+
}
|
|
238
|
+
else if (onUploadFiles && event.dataTransfer.files.length > 0) {
|
|
239
|
+
onUploadFiles(event.dataTransfer.files);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
return (_jsxs("section", { className: `FiletreePane${isDragOver ? ' is-drag-over' : ''}`, "aria-label": "Files", onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: (event) => void handleDrop(event), children: [_jsxs("div", { className: "FiletreeHeader", children: [_jsxs("div", { className: "FiletreeHeaderTitleRow", children: [_jsx("h2", { className: "FiletreeHeading", children: "Explorer" }), _jsx("span", { className: "FiletreeCount", children: files.length })] }), _jsxs("div", { className: "FiletreeHeaderActions", children: [onCreateFile ? (_jsx("button", { type: "button", className: "FiletreeToolBtn", "aria-label": "New file", title: "New file (supports subfolder paths like intro/history.tex)", onClick: () => {
|
|
243
|
+
setCreatingFile((prev) => !prev);
|
|
244
|
+
window.setTimeout(() => newFileInputRef.current?.focus(), 0);
|
|
245
|
+
}, children: "+ File" })) : null, allFolders.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "FiletreeToolBtn", onClick: handleExpandAll, title: "Expand all folders", "aria-label": "Expand all folders", children: "\u229E" }), _jsx("button", { type: "button", className: "FiletreeToolBtn", onClick: handleCollapseAll, title: "Collapse all folders", "aria-label": "Collapse all folders", children: "\u229F" })] })) : null, onCollapseSidebar ? (_jsx("button", { type: "button", className: "FiletreeToolBtn FiletreeToolBtn--collapse", onClick: onCollapseSidebar, title: "Hide file explorer", "aria-label": "Hide file explorer", children: "\u00AB" })) : null] })] }), onUploadFiles ? (_jsxs("div", { className: "FiletreeUpload", children: [_jsx("button", { type: "button", className: "FiletreeUploadBtn", onClick: () => inputRef.current?.click(), children: "Upload files" }), _jsx("button", { type: "button", className: "FiletreeUploadBtn", onClick: () => folderInputRef.current?.click(), children: "Upload folder" }), _jsx("input", { ref: inputRef, "aria-label": "Upload files", type: "file", multiple: true, onChange: onFilesChange, style: { display: 'none' } }), _jsx("input", { ref: folderInputRef, "aria-label": "Upload folder", type: "file", multiple: true, onChange: onFolderChange, style: { display: 'none' } })] })) : null, _jsx("div", { className: "FiletreeSearchRow", children: _jsx("input", { type: "search", className: "FiletreeSearchInput", "aria-label": "Filter files", placeholder: "Filter files or folders\u2026", value: filterText, onChange: (e) => setFilterText(e.target.value) }) }), creatingFile && onCreateFile ? (_jsxs("form", { className: "FiletreeNewFileForm", onSubmit: handleCreateSubmit, children: [_jsx("input", { ref: newFileInputRef, type: "text", className: "FiletreeNewFileInput", "aria-label": "New file path", placeholder: "e.g. intro/history.tex", value: newFilePath, onChange: (e) => setNewFilePath(e.target.value) }), _jsxs("div", { className: "FiletreeNewFileButtons", children: [_jsx("button", { type: "submit", className: "FiletreeNewFileConfirm", children: "Create" }), _jsx("button", { type: "button", className: "FiletreeNewFileCancel", onClick: () => {
|
|
246
|
+
setCreatingFile(false);
|
|
247
|
+
setNewFilePath('');
|
|
248
|
+
}, children: "Cancel" })] })] })) : null, uploadError ? (_jsx("div", { className: "FiletreeUploadError", role: "alert", children: uploadError })) : null, uploadNotice ? (_jsxs("div", { className: "FiletreeUploadNotice", role: "status", children: [_jsx("span", { children: uploadNotice }), onDismissUploadNotice ? (_jsx("button", { type: "button", className: "FiletreeUploadNoticeDismiss", "aria-label": "Dismiss upload notice", onClick: onDismissUploadNotice, children: "\u00D7" })) : null] })) : null, _jsx("div", { className: "FiletreeList", role: "tree", children: files.length === 0 ? (_jsx("div", { className: "FiletreeEmpty", children: "Drop .tex files or folders here" })) : filteredFiles.length === 0 ? (_jsxs("div", { className: "FiletreeEmpty", children: ["No files matching \u201C", filterText, "\u201D"] })) : (tree.map((node) => (_jsx(TreeNode, { node: node, depth: 0, selected: selected, entryPath: entryPath, expandedFolders: expandedFolders, forceExpandAll: filterText.trim().length > 0, onToggleFolder: handleToggleFolder, onSelect: onSelect, onSetEntry: onSetEntry, onDownload: onDownload, onRemove: onRemove }, `${node.type}:${node.path}`)))) })] }));
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=Filetree.js.map
|