dsh-remote-vs 0.19.0 → 0.20.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.
@@ -0,0 +1,380 @@
1
+ /**
2
+ * Coloured file-type / folder icons for the remote DIRECTORY TREE
3
+ * (`RemoteExplorer`), so a remote folder looks like the local sidebar's folder.
4
+ *
5
+ * Scope: the tree only. Search hits, SCM rows, commit panes and download rows
6
+ * keep the neutral outline glyphs from `kit.tsx` — this set is deliberately not
7
+ * the fallback of `FileIcon` / `FolderIcon`.
8
+ *
9
+ * Provenance
10
+ * ----------
11
+ * These are a straight port of the local sidebar plugin's artwork (`FileTypeIcon`
12
+ * and its amber `FolderIcon` in dsh-sidebar's `src/client/icons.tsx`, package
13
+ * name `dsh-sidebar`): one paper sheet whose colour and bottom-right mark carry
14
+ * the type — TS blue + `<>`, JS yellow + `<>`, Python blue with a yellow mark,
15
+ * Markdown blue + lines, images purple + a mountain, archives yellow + a zip,
16
+ * `.gitignore` orange + a commit graph.
17
+ *
18
+ * The copy exists on purpose: the client bundle may not import another plugin's
19
+ * values (tsdown's purity gate rejects cross-plugin imports), and dsh-sidebar
20
+ * publishes no `fileIcon` / `folderIcon` service that `kit.tsx` could call.
21
+ * `kit.tsx` still prefers such a service if a host ever provides one (the
22
+ * better-sidebar lineage is where that contract would come from); this set is
23
+ * the fallback that paints a real, typed tree in a dsh-sidebar profile.
24
+ *
25
+ * One deliberate difference from the source: the image mark used
26
+ * `fill="currentColor"`, which in a tree inherits the row's dim text colour —
27
+ * `.rvs-node-icon` sets `color: var(--rvs-fg3)` — so the mountain would render
28
+ * grey on the purple sheet. Here the mark group pins `color` to the type colour
29
+ * and the artwork stays the colour the palette intends.
30
+ */
31
+ import type { ReactNode } from 'react'
32
+
33
+ /** File paper outline (shared by every file-type icon). */
34
+ const SHEET = 'M4 1.4h5.4l3.6 3.6v9.4c0 .5-.4.9-.9.9H3.1a.9.9 0 0 1-.9-.9V2.3c0-.5.4-.9.9-.9Z'
35
+ /** Top-right fold. */
36
+ const SHEET_FOLD = 'M9.4 1.4v3.6h3.6'
37
+
38
+ /** The bottom-right mark that carries the category (drawn in the type colour). */
39
+ type FileMark =
40
+ | 'code' | 'markup' | 'style' | 'data' | 'doc' | 'image'
41
+ | 'archive' | 'shell' | 'config' | 'git' | 'lock' | 'box' | 'table'
42
+
43
+ /** How one file type looks: sheet colour + category mark + optional mark colour. */
44
+ export interface FileLook {
45
+ color: string
46
+ mark: FileMark
47
+ /** Mark colour; defaults to the sheet colour (Python = blue sheet + yellow mark). */
48
+ markColor?: string
49
+ }
50
+
51
+ /** Extension → look. Brand colours are tuned for readability on dark and light. */
52
+ const BY_EXT: Readonly<Record<string, FileLook>> = { ts: { color: '#519aba', mark: 'code' },
53
+ mts: { color: '#519aba', mark: 'code' },
54
+ cts: { color: '#519aba', mark: 'code' },
55
+ tsx: { color: '#4fc3f7', mark: 'code' },
56
+ js: { color: '#d5c93f', mark: 'code' },
57
+ mjs: { color: '#d5c93f', mark: 'code' },
58
+ cjs: { color: '#d5c93f', mark: 'code' },
59
+ jsx: { color: '#4fc3f7', mark: 'code' },
60
+ json: { color: '#d2b13a', mark: 'data' },
61
+ jsonc: { color: '#d2b13a', mark: 'data' },
62
+ json5: { color: '#d2b13a', mark: 'data' },
63
+ md: { color: '#4b9fe3', mark: 'doc' },
64
+ markdown: { color: '#4b9fe3', mark: 'doc' },
65
+ mdx: { color: '#4b9fe3', mark: 'doc' },
66
+ py: { color: '#3572a5', mark: 'code', markColor: '#ffd75e' },
67
+ pyi: { color: '#3572a5', mark: 'code', markColor: '#ffd75e' },
68
+ java: { color: '#e05a4f', mark: 'code' },
69
+ kt: { color: '#a97bff', mark: 'code' },
70
+ c: { color: '#7f9bd6', mark: 'code' },
71
+ h: { color: '#a074c4', mark: 'code' },
72
+ cpp: { color: '#6295cb', mark: 'code' },
73
+ cc: { color: '#6295cb', mark: 'code' },
74
+ cxx: { color: '#6295cb', mark: 'code' },
75
+ hpp: { color: '#6295cb', mark: 'code' },
76
+ hh: { color: '#6295cb', mark: 'code' },
77
+ cs: { color: '#b878d8', mark: 'code' },
78
+ go: { color: '#00add8', mark: 'code' },
79
+ rs: { color: '#dea584', mark: 'code' },
80
+ php: { color: '#8b9be8', mark: 'code' },
81
+ rb: { color: '#e05a4f', mark: 'code' },
82
+ swift: { color: '#e8743b', mark: 'code' },
83
+ lua: { color: '#5a8fe0', mark: 'code' },
84
+ html: { color: '#e8743b', mark: 'markup' },
85
+ htm: { color: '#e8743b', mark: 'markup' },
86
+ vue: { color: '#41b883', mark: 'markup' },
87
+ svelte: { color: '#ff5c33', mark: 'markup' },
88
+ xml: { color: '#f19a38', mark: 'markup' },
89
+ xsl: { color: '#f19a38', mark: 'markup' },
90
+ css: { color: '#42a5f5', mark: 'style' },
91
+ scss: { color: '#e05a8f', mark: 'style' },
92
+ sass: { color: '#e05a8f', mark: 'style' },
93
+ less: { color: '#42a5f5', mark: 'style' },
94
+ yaml: { color: '#a074c4', mark: 'data' },
95
+ yml: { color: '#a074c4', mark: 'data' },
96
+ toml: { color: '#b08b6a', mark: 'config' },
97
+ ini: { color: '#b08b6a', mark: 'config' },
98
+ conf: { color: '#b08b6a', mark: 'config' },
99
+ cfg: { color: '#b08b6a', mark: 'config' },
100
+ env: { color: '#b08b6a', mark: 'config' },
101
+ sh: { color: '#4ec9b0', mark: 'shell' },
102
+ bash: { color: '#4ec9b0', mark: 'shell' },
103
+ zsh: { color: '#4ec9b0', mark: 'shell' },
104
+ fish: { color: '#4ec9b0', mark: 'shell' },
105
+ ps1: { color: '#4ec9b0', mark: 'shell' },
106
+ psm1: { color: '#4ec9b0', mark: 'shell' },
107
+ bat: { color: '#4ec9b0', mark: 'shell' },
108
+ cmd: { color: '#4ec9b0', mark: 'shell' },
109
+ txt: { color: '#9aa0a6', mark: 'doc' },
110
+ log: { color: '#9aa0a6', mark: 'doc' },
111
+ csv: { color: '#7fb36b', mark: 'table' },
112
+ tsv: { color: '#7fb36b', mark: 'table' },
113
+ xlsx: { color: '#7fb36b', mark: 'table' },
114
+ png: { color: '#b18adf', mark: 'image' },
115
+ jpg: { color: '#b18adf', mark: 'image' },
116
+ jpeg: { color: '#b18adf', mark: 'image' },
117
+ gif: { color: '#b18adf', mark: 'image' },
118
+ webp: { color: '#b18adf', mark: 'image' },
119
+ bmp: { color: '#b18adf', mark: 'image' },
120
+ ico: { color: '#b18adf', mark: 'image' },
121
+ avif: { color: '#b18adf', mark: 'image' },
122
+ svg: { color: '#b18adf', mark: 'image' },
123
+ pdf: { color: '#d94f4f', mark: 'doc' },
124
+ zip: { color: '#d9b64a', mark: 'archive' },
125
+ rar: { color: '#d9b64a', mark: 'archive' },
126
+ '7z': { color: '#d9b64a', mark: 'archive' },
127
+ tar: { color: '#d9b64a', mark: 'archive' },
128
+ gz: { color: '#d9b64a', mark: 'archive' },
129
+ tgz: { color: '#d9b64a', mark: 'archive' },
130
+ bz2: { color: '#d9b64a', mark: 'archive' },
131
+ xz: { color: '#d9b64a', mark: 'archive' },
132
+ lock: { color: '#8b949e', mark: 'lock' },
133
+ dockerfile: { color: '#2496ed', mark: 'box' },
134
+ docker: { color: '#2496ed', mark: 'box' },
135
+ // `demo.gitignore` / `x.gitattributes` derive from the dot-file convention and
136
+ // take the orange branch mark here; the plain names are in BY_NAME.
137
+ gitignore: { color: '#e8703a', mark: 'git' },
138
+ gitattributes: { color: '#e8703a', mark: 'git' },
139
+ gitmodules: { color: '#e8703a', mark: 'git' },
140
+ exe: { color: '#8b949e', mark: 'box' },
141
+ dll: { color: '#8b949e', mark: 'box' },
142
+ so: { color: '#8b949e', mark: 'box' },
143
+ dylib: { color: '#8b949e', mark: 'box' },
144
+ }
145
+
146
+ /** Exact file name → look (extension-less files and conventional names hit here first). */
147
+ const BY_NAME: Readonly<Record<string, FileLook>> = {
148
+ dockerfile: { color: '#2496ed', mark: 'box' },
149
+ 'docker-compose.yml': { color: '#2496ed', mark: 'box' },
150
+ 'docker-compose.yaml': { color: '#2496ed', mark: 'box' },
151
+ makefile: { color: '#b08b6a', mark: 'config' },
152
+ gnumakefile: { color: '#b08b6a', mark: 'config' },
153
+ 'cmakelists.txt': { color: '#b08b6a', mark: 'config' },
154
+ '.gitignore': { color: '#e8703a', mark: 'git' },
155
+ '.gitattributes': { color: '#e8703a', mark: 'git' },
156
+ '.gitmodules': { color: '#e8703a', mark: 'git' },
157
+ '.npmrc': { color: '#b08b6a', mark: 'config' },
158
+ '.editorconfig': { color: '#b08b6a', mark: 'config' },
159
+ '.prettierrc': { color: '#b08b6a', mark: 'config' },
160
+ 'package-lock.json': { color: '#8b949e', mark: 'lock' },
161
+ 'pnpm-lock.yaml': { color: '#8b949e', mark: 'lock' },
162
+ 'yarn.lock': { color: '#8b949e', mark: 'lock' },
163
+ license: { color: '#9aa0a6', mark: 'doc' },
164
+ readme: { color: '#4b9fe3', mark: 'doc' },
165
+ }
166
+
167
+ /** Unrecognised file: grey document. */
168
+ const FALLBACK: FileLook = { color: '#8b949e', mark: 'doc' }
169
+
170
+ /**
171
+ * The extension / exact-name tables, exposed read-only for the gate's full-table
172
+ * snapshot: one changed hex or mark must turn `scripts/check-file-icons.mjs`
173
+ * red, instead of shipping a silently different palette.
174
+ *
175
+ * `baseName` stays private on purpose — `kit.tsx` already exports a `baseName`
176
+ * with different semantics (POSIX only, strips a trailing slash), and exporting
177
+ * both invites the wrong import.
178
+ */
179
+ export const FILE_TYPE_LOOKS: Readonly<Record<string, FileLook>> = BY_EXT
180
+ export const FILE_NAME_LOOKS: Readonly<Record<string, FileLook>> = BY_NAME
181
+
182
+ /** Drawing commands for a category mark (coordinates sit on the sheet's lower half). */
183
+ const MARKS: Readonly<Record<FileMark, ReactNode>> = {
184
+ code: (
185
+ <>
186
+ <path d="M6.4 7.8 5 9.6l1.4 1.8" />
187
+ <path d="M9.6 7.8 11 9.6l-1.4 1.8" />
188
+ </>
189
+ ),
190
+ markup: (
191
+ <>
192
+ <path d="M5.8 7.9 4.4 9.8l1.4 1.9" />
193
+ <path d="M8.6 7.5l-1.6 4.6" />
194
+ <path d="M10.2 7.9l1.4 1.9-1.4 1.9" />
195
+ </>
196
+ ),
197
+ style: (
198
+ <>
199
+ <path d="M7.1 7.6 6.3 12M9.7 7.6l-.8 4.4" />
200
+ <path d="M5.5 9h4.9M5.3 10.6h4.9" />
201
+ </>
202
+ ),
203
+ data: (
204
+ <>
205
+ <path d="M7.1 7.4c-.9 0-.9.7-.9 1.3s0 1.2-.9 1.2c.9 0 .9.6.9 1.2s0 1.3.9 1.3" />
206
+ <path d="M8.9 7.4c.9 0 .9.7.9 1.3s0 1.2.9 1.2c-.9 0-.9.6-.9 1.2s0 1.3-.9 1.3" />
207
+ </>
208
+ ),
209
+ doc: <path d="M5.2 7.8h5.6M5.2 9.7h5.6M5.2 11.6h3.6" />,
210
+ image: (
211
+ <>
212
+ <circle cx="6.4" cy="8.1" r=".85" fill="currentColor" stroke="none" />
213
+ <path d="M4.8 12.2l2.1-2.6 1.5 1.7 1.2-1.3 1.8 2.2Z" fill="currentColor" stroke="none" />
214
+ </>
215
+ ),
216
+ archive: (
217
+ <>
218
+ <path d="M4.8 7.6h6.4v4.6H4.8z" />
219
+ <path d="M4.8 9h6.4" />
220
+ <path d="M7.2 7.6v1.4M7.2 10.4h1.6" />
221
+ </>
222
+ ),
223
+ shell: (
224
+ <>
225
+ <path d="M5.2 8.2 6.9 9.8l-1.7 1.6" />
226
+ <path d="M8.3 11.4h2.7" />
227
+ </>
228
+ ),
229
+ config: (
230
+ <>
231
+ <path d="M5 8.2h6M5 11h6" />
232
+ <circle cx="7" cy="8.2" r="1.05" />
233
+ <circle cx="9.4" cy="11" r="1.05" />
234
+ </>
235
+ ),
236
+ git: (
237
+ <>
238
+ <circle cx="6" cy="7.7" r="1" />
239
+ <circle cx="9.8" cy="10.9" r="1" />
240
+ <path d="M6 8.7v1.3M9.8 8.6c0 1.4-3.8 1.3-3.8 2.3" />
241
+ </>
242
+ ),
243
+ lock: (
244
+ <>
245
+ <rect x="5.4" y="8.6" width="5.2" height="3.8" rx="1" />
246
+ <path d="M6.6 8.6V7.4a1.4 1.4 0 0 1 2.8 0v1.2" />
247
+ </>
248
+ ),
249
+ box: (
250
+ <>
251
+ <path d="M4.6 8.4h2v1.8h-2zM6.9 8.4h2v1.8h-2zM6.9 10.5h2v1.8h-2zM4.6 12.6h6.8" />
252
+ </>
253
+ ),
254
+ table: (
255
+ <>
256
+ <path d="M4.8 7.6h6.4v4.6H4.8z" />
257
+ <path d="M4.8 9.1h6.4M4.8 10.7h6.4M7.5 7.6v4.6" />
258
+ </>
259
+ ),
260
+ }
261
+
262
+ /** Basename of a path that may use either separator. */
263
+ function baseName(path: string): string {
264
+ const normalized = path.replace(/\\/g, '/')
265
+ return normalized.slice(normalized.lastIndexOf('/') + 1)
266
+ }
267
+
268
+ /** Resolve a path's look from its name / extension. */
269
+ export function lookOf(path: string): FileLook {
270
+ const name = baseName(path).toLowerCase()
271
+ const named = BY_NAME[name]
272
+ if (named !== undefined) return named
273
+ if (name.startsWith('.env')) return { color: '#b08b6a', mark: 'config' }
274
+ const dot = name.lastIndexOf('.')
275
+ // dot === 0 is a dot-file such as `.bashrc` with no extension: fall through.
276
+ if (dot <= 0) return FALLBACK
277
+ return BY_EXT[name.slice(dot + 1)] ?? FALLBACK
278
+ }
279
+
280
+ /** Props for {@link FileTypeIcon} / {@link FolderGlyph}. */
281
+ export interface FileIconProps {
282
+ /** Workspace-relative path (any separator); only the basename is read. */
283
+ path: string
284
+ /** Edge length in px, default 16. */
285
+ size?: number
286
+ className?: string
287
+ }
288
+
289
+ /**
290
+ * Coloured file-type icon: sheet + top-right fold + bottom-right category mark.
291
+ *
292
+ * At 16 px this reads better than two-letter badges and does not depend on font
293
+ * rendering.
294
+ */
295
+ export function FileTypeIcon(props: FileIconProps): ReactNode {
296
+ const size = props.size ?? 16
297
+ const look = lookOf(props.path)
298
+ return (
299
+ <svg
300
+ width={size}
301
+ height={size}
302
+ viewBox="0 0 16 16"
303
+ fill="none"
304
+ className={props.className}
305
+ aria-hidden="true"
306
+ >
307
+ <path
308
+ d={SHEET}
309
+ fill={look.color}
310
+ fillOpacity={0.14}
311
+ stroke={look.color}
312
+ strokeWidth={1}
313
+ strokeLinejoin="round"
314
+ />
315
+ <path d={SHEET_FOLD} stroke={look.color} strokeWidth={1} strokeLinejoin="round" />
316
+ <g
317
+ stroke={look.markColor ?? look.color}
318
+ strokeWidth={1.15}
319
+ strokeLinecap="round"
320
+ strokeLinejoin="round"
321
+ // Pins currentColor for the image mark to the type colour: the tree row
322
+ // sets a dim text colour that would otherwise grey the mountain out.
323
+ style={{ color: look.markColor ?? look.color }}
324
+ >
325
+ {MARKS[look.mark]}
326
+ </g>
327
+ </svg>
328
+ )
329
+ }
330
+
331
+ /** Every extension the file-type icon recognises (reporting / gate). */
332
+ export const FILE_TYPE_EXTENSIONS: readonly string[] = Object.keys(BY_EXT).sort()
333
+
334
+ /** Props for the amber folder glyph. */
335
+ export interface FolderGlyphProps {
336
+ /** Expanded: the front flap drops down and reveals the inner sheet (VSCode-like). */
337
+ open?: boolean
338
+ /** Edge length in px, default 16. */
339
+ size?: number
340
+ className?: string
341
+ }
342
+
343
+ /**
344
+ * Amber folder icon. The folder colour is content colour, in the same scheme as
345
+ * the file types — it does not follow the skin.
346
+ */
347
+ export function FolderGlyph(props: FolderGlyphProps): ReactNode {
348
+ const size = props.size ?? 16
349
+ return props.open === true
350
+ ? (
351
+ <svg width={size} height={size} viewBox="0 0 16 16" fill="none" className={props.className} aria-hidden="true">
352
+ <path
353
+ d="M1.9 12V4.3c0-.6.4-1 1-1h3.2l1.5 1.7h5.6c.6 0 1 .4 1 1v5.4"
354
+ fill="#c69a3f"
355
+ stroke="#a8781c"
356
+ strokeWidth=".9"
357
+ strokeLinejoin="round"
358
+ />
359
+ <path
360
+ d="M2 12.6 3.5 8c.1-.4.5-.7.9-.7h9.5c.7 0 1.2.7 1 1.4l-1.3 3.8c-.1.4-.5.7-.9.7H2.9c-.6 0-1-.5-.9-1.1Z"
361
+ fill="#e7b95d"
362
+ stroke="#a8781c"
363
+ strokeWidth=".9"
364
+ strokeLinejoin="round"
365
+ />
366
+ </svg>
367
+ )
368
+ : (
369
+ <svg width={size} height={size} viewBox="0 0 16 16" fill="none" className={props.className} aria-hidden="true">
370
+ <path
371
+ d="M1.9 12.3V4.2c0-.6.4-1 1-1h3.2l1.5 1.7h5.6c.6 0 1 .4 1 1v6.4c0 .6-.4 1-1 1H2.9c-.6 0-1-.4-1-1Z"
372
+ fill="#d9ab4e"
373
+ stroke="#a8781c"
374
+ strokeWidth=".9"
375
+ strokeLinejoin="round"
376
+ />
377
+ <path d="M2.6 5.3h10.8" stroke="#a8781c" strokeWidth=".9" opacity=".45" />
378
+ </svg>
379
+ )
380
+ }
@@ -5,11 +5,17 @@
5
5
  * ships the same split, and the confirm dialogs are what guard destructive
6
6
  * remote git verbs).
7
7
  *
8
- * Icon sourcing: when dsh-better-sidebar is installed its service answers
9
- * `fileIcon` / `folderIcon`, which run the host's own classifier and any
10
- * user-registered icon theme — the remote tree then matches the user's local
11
- * sidebar glyph for glyph. Without that service the built-in SVG set below
12
- * takes over, so the native fallback surface still renders a real tree.
8
+ * Icon sourcing has two tiers. `FileIcon` / `FolderIcon` paint the plain glyphs
9
+ * below (search hits, SCM rows, commit panes, download rows — list chrome where
10
+ * one neutral outline reads best). `ExplorerFileIcon` / `ExplorerFolderIcon`
11
+ * paint the COLOURED type set ported from dsh-sidebar in `./file-icons.tsx`, so
12
+ * the remote directory tree looks like the local sidebar's tree: one sheet
13
+ * whose colour and mark carry the file type, and an amber folder that opens.
14
+ *
15
+ * Every tier still prefers the host service when one is published (the
16
+ * better-sidebar lineage's `fileIcon` / `folderIcon`: host classifier plus any
17
+ * registered icon theme). dsh-sidebar itself publishes none today, so in a
18
+ * dsh-sidebar profile the SVG sets above are what actually render.
13
19
  */
14
20
  import {
15
21
  createElement,
@@ -25,6 +31,7 @@ import {
25
31
  } from 'react'
26
32
  import { createPortal } from 'react-dom'
27
33
  import { detectLang, makeT } from '../i18n.ts'
34
+ import { FileTypeIcon, FolderGlyph } from './file-icons.tsx'
28
35
 
29
36
  // ------------------------------------------------------------------ icons
30
37
 
@@ -330,6 +337,28 @@ export function FolderIcon(props: { path: string; open: boolean; size?: number;
330
337
  return <IconFolder size={size} open={props.open} className={props.className} />
331
338
  }
332
339
 
340
+ // --------------------------------------------------- directory-tree icons
341
+ //
342
+ // The tree is the one surface that has to match the local sidebar, so it uses
343
+ // the coloured type set (see `./file-icons.tsx`) instead of the plain glyphs
344
+ // above. Host service still wins, so a user-registered icon theme keeps working.
345
+
346
+ /** Explorer file row: host glyph when available, else the coloured type icon. */
347
+ export function ExplorerFileIcon(props: { path: string; size?: number; className?: string }): ReactNode {
348
+ const size = props.size ?? 16
349
+ const fromHost = tryService(() => iconService?.fileIcon(props.path, size))
350
+ if (fromHost !== undefined) return fromHost
351
+ return <FileTypeIcon path={props.path} size={size} className={props.className} />
352
+ }
353
+
354
+ /** Explorer directory row: host glyph when available, else the amber folder. */
355
+ export function ExplorerFolderIcon(props: { path: string; open: boolean; size?: number; className?: string }): ReactNode {
356
+ const size = props.size ?? 16
357
+ const fromHost = tryService(() => iconService?.folderIcon(props.path, props.open, size))
358
+ if (fromHost !== undefined) return fromHost
359
+ return <FolderGlyph open={props.open} size={size} className={props.className} />
360
+ }
361
+
333
362
  // ------------------------------------------------------------- file kinds
334
363
 
335
364
  const IMAGE_EXTS = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'bmp', 'ico', 'avif'])