@ternarytech-io/gears-ui 0.13.0 → 0.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ternarytech-io/gears-ui",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "description": "Gears UI: Vue 3 components on Tabler, used by the Gears Studio and the applications it builds.",
6
6
  "license": "MPL-2.0",
@@ -6,9 +6,10 @@
6
6
  // or the cards. Selection works with the mouse (Ctrl, Shift) and the keyboard (arrows, Shift,
7
7
  // Ctrl+A); Enter opens a folder (a file emits `open`), F2 renames in place, Delete deletes (after
8
8
  // asking), Ctrl+X and Ctrl+V move, Backspace goes up. Items drag onto folders (in the list or the
9
- // tree) to move; files dropped from the computer upload, a queue with progress. The context menu
10
- // has the standard actions and `menu`'s own. The `info` slot is a side pane for the selection.
11
- // What the provider can't do is left out.
9
+ // tree) to move; files dropped from the computer upload, a queue with progress. Copy to… and Move
10
+ // to… send files to a folder of any drive (chosen in a dialog of the drives' folders), through the
11
+ // same queue. The context menu has the standard actions and `menu`'s own. The `info` slot is a side
12
+ // pane for the selection. What the provider can't do is left out.
12
13
  import { computed, onMounted, reactive, ref, watch } from 'vue'
13
14
  import TBreadcrumbs from './TBreadcrumbs.vue'
14
15
  import TButton from './TButton.vue'
@@ -305,8 +306,17 @@ async function createFolder() {
305
306
  })
306
307
  }
307
308
 
308
- // ---- Uploads: one at a time, each with its progress, cancelable ----
309
- interface Upload { id: number; name: string; size: number; sent: number; state: 'waiting' | 'sending' | 'done' | 'failed' | 'canceled'; error?: string; abort: AbortController; drive: string; folder: string | null; file: File }
309
+ // ---- The queue: uploads, copies and moves to other drives, one at a time, each cancelable ----
310
+ interface Upload {
311
+ id: number; kind: 'upload' | 'copy' | 'move'; name: string; size: number; sent: number; state: 'waiting' | 'sending' | 'done' | 'failed' | 'canceled'; error?: string
312
+ abort: AbortController
313
+ /** Where it goes. */
314
+ drive: string; folder: string | null
315
+ /** An upload's file. */
316
+ file?: File
317
+ /** A copy's or move's item, from where it is, and where it goes as people read it. */
318
+ item?: ExplorerItem; from?: { drive: string; folder: string | null }; to?: string
319
+ }
310
320
  const uploads = reactive<Upload[]>([])
311
321
  let uploadIds = 0
312
322
  let uploading = false
@@ -315,7 +325,7 @@ function queue(files: File[]) {
315
325
  const at = location.value
316
326
  if (!at || !props.provider.upload || !writable.value) return
317
327
  for (const file of files)
318
- uploads.push({ id: ++uploadIds, name: file.name, size: file.size, sent: 0, state: 'waiting', abort: new AbortController(), drive: at.drive, folder: at.folder, file })
328
+ uploads.push({ id: ++uploadIds, kind: 'upload', name: file.name, size: file.size, sent: 0, state: 'waiting', abort: new AbortController(), drive: at.drive, folder: at.folder, file })
319
329
  void run()
320
330
  }
321
331
  async function run() {
@@ -326,15 +336,20 @@ async function run() {
326
336
  const upload = next
327
337
  upload.state = 'sending'
328
338
  try {
329
- await props.provider.upload!(upload.drive, upload.folder, upload.file, sent => { upload.sent = sent }, upload.abort.signal)
339
+ if (upload.kind === 'upload')
340
+ await props.provider.upload!(upload.drive, upload.folder, upload.file!, sent => { upload.sent = sent }, upload.abort.signal)
341
+ else
342
+ await (upload.kind === 'copy' ? props.provider.copy! : props.provider.transfer!)(upload.from!.drive, upload.item!, upload.drive, upload.folder, upload.abort.signal)
330
343
  upload.state = 'done'
331
344
  upload.sent = upload.size
332
- if (location.value?.drive === upload.drive && location.value.folder === upload.folder) await load()
345
+ const here = location.value
346
+ const at = (place?: { drive: string; folder: string | null }) => !!place && here?.drive === place.drive && here.folder === place.folder
347
+ if (at(upload) || at(upload.from)) await load()
333
348
  } catch (e) {
334
349
  if (upload.abort.signal.aborted) upload.state = 'canceled'
335
350
  else {
336
351
  upload.state = 'failed'
337
- upload.error = e instanceof Error ? e.message : 'It couldn\'t be uploaded.'
352
+ upload.error = e instanceof Error ? e.message : upload.kind === 'upload' ? 'It couldn\'t be uploaded.' : `It couldn't be ${upload.kind === 'copy' ? 'copied' : 'moved'}.`
338
353
  }
339
354
  }
340
355
  }
@@ -356,6 +371,64 @@ const picked = (event: Event) => {
356
371
  input.value = ''
357
372
  }
358
373
 
374
+ // ---- Copy to… and Move to…: a folder of any drive, chosen in a dialog ----
375
+ const sending = ref<{ mode: 'copy' | 'move'; items: ExplorerItem[]; from: ExplorerLocation } | null>(null)
376
+ const sendOpen = computed({ get: () => !!sending.value, set: open => { if (!open) sending.value = null } })
377
+ const sendSelected = ref<string | null>(null)
378
+ const sendExpanded = ref<string[]>([])
379
+ // The drives a copy or move can go to: read-only and unavailable ones can't take files.
380
+ const sendNodes = computed<TreeNode[]>(() => drives.value.map(d => ({
381
+ id: nodeId(d.id, null), label: d.name, icon: d.icon ?? 'server-2', leaf: !!d.unavailable, disabled: d.readOnly || !!d.unavailable
382
+ })))
383
+ const canCopy = (list: ExplorerItem[]) => !!props.provider.copy && list.length > 0 && list.every(i => !i.folder)
384
+ const canSend = (list: ExplorerItem[]) => (!!props.provider.transfer || !!props.provider.move) && list.length > 0 && list.every(i => i.can?.move !== false)
385
+ function sendTo(mode: 'copy' | 'move', list: ExplorerItem[]) {
386
+ const at = location.value
387
+ if (!at) return
388
+ sendSelected.value = nodeId(at.drive, at.folder)
389
+ sendExpanded.value = [nodeId(at.drive, null), ...at.path.map(p => nodeId(at.drive, p.id))]
390
+ sending.value = { mode, items: [...list], from: at }
391
+ }
392
+ const sendTarget = computed(() => {
393
+ const id = sendSelected.value
394
+ if (!id) return null
395
+ const driveId = id.split('|')[0]!
396
+ const target = drives.value.find(d => d.id === driveId)
397
+ const place = places.get(id)
398
+ return target ? { drive: driveId, folder: place?.folder ?? null, label: [target.name, ...(place ? pathTo(id).map(p => p.name) : [])].join(' / '), writable: !target.readOnly && !target.unavailable } : null
399
+ })
400
+ // Why the chosen folder won't do; null when it will.
401
+ const sendProblem = computed(() => {
402
+ const job = sending.value
403
+ const target = sendTarget.value
404
+ if (!job || !target) return 'Choose a folder.'
405
+ if (!target.writable) return 'That drive is read-only here.'
406
+ if (job.mode === 'move' && target.drive === job.from.drive && target.folder === job.from.folder) return 'They\'re in this folder already.'
407
+ if (job.mode === 'move' && target.drive !== job.from.drive) {
408
+ if (!props.provider.transfer) return 'Items move within their drive here.'
409
+ if (job.items.some(i => i.folder)) return 'Folders move within their drive; their files can go to another one.'
410
+ }
411
+ if (job.mode === 'move' && target.drive === job.from.drive && job.items.some(i => i.id === target.folder)) return 'A folder can\'t go inside itself.'
412
+ return null
413
+ })
414
+ async function confirmSend() {
415
+ const job = sending.value
416
+ const target = sendTarget.value
417
+ if (!job || !target || sendProblem.value) return
418
+ sending.value = null
419
+ // Within a drive, a move is the drive's own (folders too); otherwise each file is queued.
420
+ if (job.mode === 'move' && target.drive === job.from.drive) {
421
+ await moveTo(job.items, target.folder)
422
+ return
423
+ }
424
+ for (const item of job.items)
425
+ uploads.push({
426
+ id: ++uploadIds, kind: job.mode, name: item.name, size: item.size ?? 0, sent: 0, state: 'waiting', abort: new AbortController(),
427
+ drive: target.drive, folder: target.folder, item, from: { drive: job.from.drive, folder: job.from.folder }, to: target.label
428
+ })
429
+ void run()
430
+ }
431
+
359
432
  // ---- Dragging: items onto folders (list or tree) to move; files from the computer to upload ----
360
433
  const dragType = 'application/x-t-explorer'
361
434
  const over = ref<string | null>(null)
@@ -423,6 +496,11 @@ function menuFor(event: MouseEvent | KeyboardEvent): ContextMenuItem[][] {
423
496
  ...(props.provider.rename && one ? [{ label: 'Rename', icon: 'pencil', kbd: 'F2', disabled: !canRename(one), reason: reasonFor(one, 'rename'), onSelect: () => startRename(one) }] : []),
424
497
  ...(props.provider.move ? [{ label: 'Cut', icon: 'scissors', kbd: 'Ctrl+X', disabled: !canMove(list), reason: list.length === 1 ? reasonFor(list[0]!, 'move') : undefined, onSelect: () => cut(list) }] : []),
425
498
  ...(clipboard.value && one?.folder ? [{ label: 'Paste into', icon: 'clipboard', onSelect: () => void paste(one.id) }] : [])
499
+ ], [
500
+ ...(props.provider.copy ? [{ label: 'Copy to…', icon: 'copy', disabled: !canCopy(list), reason: list.some(i => i.folder) ? 'Folders can\'t be copied yet' : undefined,
501
+ onSelect: () => sendTo('copy', list) }] : []),
502
+ ...(props.provider.transfer || props.provider.move ? [{ label: 'Move to…', icon: 'folder-share', disabled: !canSend(list),
503
+ reason: list.length === 1 ? reasonFor(list[0]!, 'move') : undefined, onSelect: () => sendTo('move', list) }] : [])
426
504
  ], ...(props.menu?.(list, at) ?? []), [
427
505
  ...(props.provider.remove ? [{ label: 'Delete', icon: 'trash', color: 'error' as const, kbd: 'Del', disabled: !canDelete(list), reason: list.length === 1 ? reasonFor(list[0]!, 'delete') : undefined, onSelect: () => askDelete(list) }] : [])
428
506
  ]]
@@ -565,21 +643,41 @@ const infoShown = ref(true)
565
643
  </div>
566
644
  <div v-if="uploads.length" class="t-explorer-uploads" aria-label="Uploads">
567
645
  <div class="d-flex align-items-center gap-2 mb-1">
568
- <span class="small fw-medium flex-fill">Uploads</span>
646
+ <span class="small fw-medium flex-fill">{{ uploads.every(u => u.kind === 'upload') ? 'Uploads' : 'Uploads, copies and moves' }}</span>
569
647
  <TButton size="sm" variant="ghost" color="neutral" label="Clear finished" @click="clearUploads" />
570
648
  </div>
571
649
  <div v-for="u in uploads" :key="u.id" class="t-explorer-upload">
572
- <TIcon :name="u.state === 'done' ? 'circle-check' : u.state === 'failed' ? 'alert-circle' : u.state === 'canceled' ? 'circle-x' : 'upload'"
650
+ <TIcon :name="u.state === 'done' ? 'circle-check' : u.state === 'failed' ? 'alert-circle' : u.state === 'canceled' ? 'circle-x' : u.kind === 'copy' ? 'copy' : u.kind === 'move' ? 'folder-share' : 'upload'"
573
651
  :class="u.state === 'done' ? 'text-success' : u.state === 'failed' ? 'text-danger' : 'text-secondary'" />
574
652
  <span class="text-truncate small" style="min-width: 6rem; max-width: 16rem">{{ u.name }}</span>
575
- <TProgress v-if="u.state === 'sending' || u.state === 'waiting'" :value="u.state === 'waiting' ? 0 : u.sent" :max="u.size || 1" size="sm" class="flex-fill" :label="`${u.name} sent`" />
576
- <span v-else class="small text-secondary flex-fill text-truncate">{{ u.state === 'failed' ? u.error : u.state === 'canceled' ? 'Canceled' : sizeOf(u.size) }}</span>
653
+ <template v-if="u.kind === 'upload'">
654
+ <TProgress v-if="u.state === 'sending' || u.state === 'waiting'" :value="u.state === 'waiting' ? 0 : u.sent" :max="u.size || 1" size="sm" class="flex-fill" :label="`${u.name} sent`" />
655
+ <span v-else class="small text-secondary flex-fill text-truncate">{{ u.state === 'failed' ? u.error : u.state === 'canceled' ? 'Canceled' : sizeOf(u.size) }}</span>
656
+ </template>
657
+ <span v-else class="small text-secondary flex-fill text-truncate">
658
+ <TSpinner v-if="u.state === 'sending'" size="sm" class="me-1" />{{ u.state === 'failed' ? u.error : u.state === 'canceled' ? 'Canceled'
659
+ : `${u.state === 'done' ? (u.kind === 'copy' ? 'Copied' : 'Moved') : u.state === 'waiting' ? 'Waiting' : (u.kind === 'copy' ? 'Copying' : 'Moving')} to ${u.to}` }}
660
+ </span>
577
661
  <TButton v-if="u.state === 'waiting' || u.state === 'sending'" size="sm" variant="ghost" color="neutral" icon="x" :aria-label="`Cancel ${u.name}`" @click="cancel(u)" />
578
662
  </div>
579
663
  </div>
580
664
  </div>
581
665
  </template>
582
666
  </TSplitter>
667
+ <TModal v-model:open="sendOpen" :title="sending?.mode === 'copy' ? 'Copy to…' : 'Move to…'" size="md">
668
+ <p class="small text-secondary">
669
+ {{ sending?.items.length === 1 ? sending.items[0]!.name : `${sending?.items.length} items` }}: choose the folder {{ sending?.mode === 'copy' ? 'for the copy' : 'to move to' }}.
670
+ </p>
671
+ <div class="t-explorer-send">
672
+ <TTree v-model:selected="sendSelected" v-model:expanded="sendExpanded" :nodes="sendNodes" :load="loadFolders" size="sm" :label="`${label}: where to`" />
673
+ </div>
674
+ <p v-if="sendTarget" class="small mt-2 mb-0"><TIcon name="folder" class="text-secondary" /> {{ sendTarget.label }}</p>
675
+ <p v-if="sendProblem && sendTarget" class="small text-danger mb-0">{{ sendProblem }}</p>
676
+ <template #footer>
677
+ <TButton color="neutral" variant="ghost" label="Cancel" @click="sending = null" />
678
+ <TButton :icon="sending?.mode === 'copy' ? 'copy' : 'folder-share'" :label="sending?.mode === 'copy' ? 'Copy here' : 'Move here'" :disabled="!!sendProblem" @click="confirmSend" />
679
+ </template>
680
+ </TModal>
583
681
  <TModal v-model:open="deleteOpen" title="Delete?" size="sm">
584
682
  <p class="mb-0">
585
683
  {{ deleting?.length === 1 ? `Delete ${deleting[0]!.name}?` : `Delete these ${deleting?.length} items?` }}
@@ -619,4 +717,5 @@ const infoShown = ref(true)
619
717
  .t-explorer-info { width: 18rem; flex: none; overflow: auto; border-inline-start: var(--tblr-border-width) solid var(--tblr-border-color); }
620
718
  .t-explorer-uploads { border-top: var(--tblr-border-width) solid var(--tblr-border-color); padding: .5rem .75rem; max-height: 11rem; overflow: auto; }
621
719
  .t-explorer-upload { display: flex; align-items: center; gap: .5rem; padding-block: .125rem; }
720
+ .t-explorer-send { height: 18rem; overflow: auto; border: var(--tblr-border-width) solid var(--tblr-border-color); border-radius: var(--tblr-border-radius); padding: .375rem; }
622
721
  </style>
package/src/types.ts CHANGED
@@ -127,6 +127,10 @@ export interface ExplorerProvider {
127
127
  move?(drive: string, items: ExplorerItem[], folder: string | null): Promise<void>
128
128
  remove?(drive: string, items: ExplorerItem[]): Promise<void>
129
129
  upload?(drive: string, folder: string | null, file: File, progress: (sent: number) => void, signal: AbortSignal): Promise<ExplorerItem>
130
+ /** Copies a file into a folder of any drive (its own too; null for the top): Copy to…. One file a call, queued like uploads. */
131
+ copy?(drive: string, item: ExplorerItem, toDrive: string, toFolder: string | null, signal: AbortSignal): Promise<ExplorerItem>
132
+ /** Moves a file into a folder of another drive (null for its top): Move to…. Within a drive, Move to… uses `move`. */
133
+ transfer?(drive: string, item: ExplorerItem, toDrive: string, toFolder: string | null, signal: AbortSignal): Promise<ExplorerItem>
130
134
  /** Where a file downloads from. */
131
135
  href?(drive: string, item: ExplorerItem): string
132
136
  }