@ternarytech-io/gears-ui 0.11.0 → 0.13.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,230 @@
1
+ <script setup lang="ts">
2
+ // A tree that opens and closes, such as folders: v-model:selected is the chosen node's id, and
3
+ // v-model:expanded the open ones'. A node's children are its `children`, or, the first time it
4
+ // opens, what `load` gives (a node with neither is openable until loaded; `leaf` says it has
5
+ // none). It follows the ARIA tree pattern: Up and Down move, Right opens or goes in, Left closes or
6
+ // goes up, Home and End, Enter or Space chooses, and typing a letter jumps to the next node it
7
+ // starts. Nodes can take drops (`droppable` says which, for a dragover) and be dragged
8
+ // (`draggable`), for moving things into folders. The `label` slot draws a row's text, `actions`
9
+ // its trailing buttons. `reload(id)` reads a node's children again; `reveal(ids)` opens a path
10
+ // and marks its last node chosen (without `select`, which is for a person's choice).
11
+ import { computed, nextTick, reactive, ref } from 'vue'
12
+ import TIcon from './TIcon.vue'
13
+ import TSpinner from './TSpinner.vue'
14
+ import type { TreeNode } from '../types'
15
+
16
+ const props = withDefaults(defineProps<{
17
+ nodes: TreeNode[]
18
+ load?: (node: TreeNode) => Promise<TreeNode[]>
19
+ /** Whether a drag over a node may drop there. */
20
+ droppable?: (node: TreeNode, event: DragEvent) => boolean
21
+ /** Whether a node can be dragged. */
22
+ draggable?: (node: TreeNode) => boolean
23
+ size?: 'sm' | 'md'
24
+ /** The tree's accessible name. */
25
+ label?: string
26
+ }>(), { size: 'md', label: 'Tree' })
27
+
28
+ const selected = defineModel<string | null>('selected', { default: null })
29
+ const expanded = defineModel<string[]>('expanded', { default: () => [] })
30
+ const emit = defineEmits<{
31
+ select: [node: TreeNode]
32
+ open: [node: TreeNode]
33
+ drop: [drop: { node: TreeNode; event: DragEvent }]
34
+ dragstart: [drag: { node: TreeNode; event: DragEvent }]
35
+ }>()
36
+ defineSlots<{ label?(scope: { node: TreeNode; depth: number }): unknown; actions?(scope: { node: TreeNode; depth: number }): unknown }>()
37
+
38
+ // Children loaded (by id), loading, or failed.
39
+ const loaded = reactive(new Map<string, TreeNode[]>())
40
+ const loading = reactive(new Set<string>())
41
+ const failed = reactive(new Map<string, string>())
42
+ const focused = ref<string | null>(null)
43
+ const over = ref<string | null>(null)
44
+ const root = ref<HTMLElement>()
45
+
46
+ const childrenOf = (node: TreeNode) => node.children ?? loaded.get(node.id)
47
+ // Openable unless it's a leaf or was given no children; one loaded empty stays openable, and shows Empty.
48
+ const openable = (node: TreeNode) => node.leaf !== true && !(node.children && node.children.length === 0)
49
+ const isOpen = (node: TreeNode) => expanded.value.includes(node.id)
50
+
51
+ interface Row { node: TreeNode; depth: number; parent: TreeNode | null }
52
+ // The nodes shown, in order: each open node's children under it.
53
+ const rows = computed(() => {
54
+ const list: Row[] = []
55
+ const walk = (nodes: TreeNode[], depth: number, parent: TreeNode | null) => {
56
+ for (const node of nodes) {
57
+ list.push({ node, depth, parent })
58
+ const children = childrenOf(node)
59
+ if (isOpen(node) && children) walk(children, depth + 1, node)
60
+ }
61
+ }
62
+ walk(props.nodes, 1, null)
63
+ return list
64
+ })
65
+ const tabStop = computed(() => focused.value ?? selected.value ?? rows.value[0]?.node.id ?? null)
66
+
67
+ async function fetch(node: TreeNode, again = false) {
68
+ if (!props.load || node.children || (!again && loaded.has(node.id)) || loading.has(node.id)) return
69
+ loading.add(node.id)
70
+ failed.delete(node.id)
71
+ try {
72
+ loaded.set(node.id, await props.load(node))
73
+ } catch (e) {
74
+ failed.set(node.id, e instanceof Error ? e.message : 'It couldn\'t be read.')
75
+ } finally {
76
+ loading.delete(node.id)
77
+ }
78
+ }
79
+ async function openNode(node: TreeNode) {
80
+ if (isOpen(node) || !openable(node)) return
81
+ expanded.value = [...expanded.value, node.id]
82
+ emit('open', node)
83
+ await fetch(node)
84
+ }
85
+ function closeNode(node: TreeNode) {
86
+ expanded.value = expanded.value.filter(id => id !== node.id)
87
+ }
88
+ function toggle(node: TreeNode) {
89
+ if (isOpen(node)) closeNode(node)
90
+ else void openNode(node)
91
+ }
92
+ function choose(node: TreeNode) {
93
+ if (node.disabled) return
94
+ selected.value = node.id
95
+ focus(node.id)
96
+ emit('select', node)
97
+ }
98
+ async function focus(id: string) {
99
+ focused.value = id
100
+ await nextTick()
101
+ root.value?.querySelector<HTMLElement>(`[data-node="${CSS.escape(id)}"]`)?.focus()
102
+ }
103
+
104
+ /** Reads a node's children again (after one is added, renamed or moved); its own id, or the top for none. */
105
+ async function reload(id?: string) {
106
+ if (!id) return
107
+ const row = rows.value.find(r => r.node.id === id)
108
+ if (row) await fetch(row.node, true)
109
+ else loaded.delete(id)
110
+ }
111
+ /**
112
+ * Opens each node of a path, top first, loading as it goes, and marks the last as chosen. It
113
+ * doesn't emit `select`: that's for a person's choice, and a reveal follows one made elsewhere.
114
+ */
115
+ async function reveal(ids: string[]) {
116
+ for (const [i, id] of ids.entries()) {
117
+ const row = rows.value.find(r => r.node.id === id)
118
+ if (!row) return
119
+ if (i < ids.length - 1) await openNode(row.node)
120
+ else selected.value = row.node.id
121
+ }
122
+ }
123
+ defineExpose({ reload, reveal })
124
+
125
+ function key(event: KeyboardEvent, row: Row) {
126
+ const index = rows.value.indexOf(row)
127
+ const at = (i: number) => rows.value[Math.max(0, Math.min(rows.value.length - 1, i))]!
128
+ switch (event.key) {
129
+ case 'ArrowDown': void focus(at(index + 1).node.id); break
130
+ case 'ArrowUp': void focus(at(index - 1).node.id); break
131
+ case 'Home': void focus(at(0).node.id); break
132
+ case 'End': void focus(at(rows.value.length - 1).node.id); break
133
+ case 'ArrowRight':
134
+ if (!isOpen(row.node) && openable(row.node)) void openNode(row.node)
135
+ else if (childrenOf(row.node)?.[0]) void focus(childrenOf(row.node)![0]!.id)
136
+ break
137
+ case 'ArrowLeft':
138
+ if (isOpen(row.node)) closeNode(row.node)
139
+ else if (row.parent) void focus(row.parent.id)
140
+ break
141
+ case 'Enter':
142
+ case ' ':
143
+ choose(row.node)
144
+ break
145
+ default:
146
+ // Typing a letter: the next node whose label starts with it.
147
+ if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
148
+ const letter = event.key.toLowerCase()
149
+ const after = [...rows.value.slice(index + 1), ...rows.value.slice(0, index + 1)]
150
+ const next = after.find(r => r.node.label.toLowerCase().startsWith(letter))
151
+ if (next) void focus(next.node.id)
152
+ break
153
+ }
154
+ return
155
+ }
156
+ event.preventDefault()
157
+ }
158
+
159
+ function dragOver(event: DragEvent, node: TreeNode) {
160
+ if (!props.droppable?.(node, event)) return
161
+ event.preventDefault()
162
+ over.value = node.id
163
+ }
164
+ function dropped(event: DragEvent, node: TreeNode) {
165
+ over.value = null
166
+ if (!props.droppable?.(node, event)) return
167
+ event.preventDefault()
168
+ emit('drop', { node, event })
169
+ }
170
+ function dragStart(event: DragEvent, node: TreeNode) {
171
+ emit('dragstart', { node, event })
172
+ }
173
+ </script>
174
+
175
+ <template>
176
+ <div ref="root" :class="['t-tree', `t-tree-${size}`]" role="tree" :aria-label="label">
177
+ <template v-for="row in rows" :key="row.node.id">
178
+ <div :data-node="row.node.id" role="treeitem" :aria-level="row.depth" :aria-expanded="openable(row.node) ? isOpen(row.node) : undefined"
179
+ :aria-selected="selected === row.node.id" :aria-disabled="row.node.disabled || undefined" :tabindex="tabStop === row.node.id ? 0 : -1"
180
+ :draggable="draggable?.(row.node) || undefined"
181
+ :class="['t-tree-row', { selected: selected === row.node.id, over: over === row.node.id, disabled: row.node.disabled }]"
182
+ :style="{ paddingInlineStart: `${(row.depth - 1) * 1.125 + 0.25}rem` }"
183
+ @click="choose(row.node)" @keydown="key($event, row)" @focus="focused = row.node.id"
184
+ @dragover="dragOver($event, row.node)" @dragleave="over = over === row.node.id ? null : over" @drop="dropped($event, row.node)"
185
+ @dragstart="dragStart($event, row.node)">
186
+ <button v-if="openable(row.node)" type="button" class="t-tree-toggle" tabindex="-1" :aria-label="isOpen(row.node) ? 'Close' : 'Open'" @click.stop="toggle(row.node)">
187
+ <TSpinner v-if="loading.has(row.node.id)" size="sm" />
188
+ <TIcon v-else :name="isOpen(row.node) ? 'chevron-down' : 'chevron-right'" />
189
+ </button>
190
+ <span v-else class="t-tree-toggle" aria-hidden="true" />
191
+ <TIcon v-if="row.node.icon" :name="isOpen(row.node) && row.node.openIcon ? row.node.openIcon : row.node.icon" class="t-tree-icon" />
192
+ <span class="t-tree-label">
193
+ <slot name="label" :node="row.node" :depth="row.depth">{{ row.node.label }}</slot>
194
+ </span>
195
+ <span v-if="$slots.actions" class="t-tree-actions" @click.stop><slot name="actions" :node="row.node" :depth="row.depth" /></span>
196
+ </div>
197
+ <div v-if="failed.has(row.node.id) && isOpen(row.node)" class="t-tree-problem" :style="{ paddingInlineStart: `${row.depth * 1.125 + 0.5}rem` }">
198
+ {{ failed.get(row.node.id) }}
199
+ <button type="button" class="btn btn-link btn-sm p-0 ms-1" @click="fetch(row.node, true)">Try again</button>
200
+ </div>
201
+ <div v-else-if="isOpen(row.node) && childrenOf(row.node)?.length === 0" class="t-tree-empty" :style="{ paddingInlineStart: `${row.depth * 1.125 + 1.25}rem` }">
202
+ Empty
203
+ </div>
204
+ </template>
205
+ </div>
206
+ </template>
207
+
208
+ <style scoped>
209
+ .t-tree { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
210
+ .t-tree-sm { font-size: .8125rem; }
211
+ .t-tree-row {
212
+ display: flex; align-items: center; gap: .25rem; min-height: 1.875rem; padding-inline-end: .25rem;
213
+ border-radius: var(--tblr-border-radius, 4px); cursor: pointer; user-select: none; min-width: 0;
214
+ }
215
+ .t-tree-sm .t-tree-row { min-height: 1.625rem; }
216
+ .t-tree-row:hover { background: var(--tblr-bg-surface-secondary); }
217
+ .t-tree-row:focus-visible { outline: 2px solid var(--tblr-primary); outline-offset: -2px; }
218
+ .t-tree-row.selected { background: var(--tblr-primary-lt); color: var(--tblr-primary); }
219
+ .t-tree-row.over { box-shadow: inset 0 0 0 2px var(--tblr-primary); background: var(--tblr-primary-lt); }
220
+ .t-tree-row.disabled { opacity: .55; cursor: default; }
221
+ .t-tree-toggle { display: inline-flex; align-items: center; justify-content: center; width: 1.25rem; height: 1.25rem; flex: none; padding: 0; border: 0; background: none; color: var(--tblr-secondary); border-radius: 3px; }
222
+ button.t-tree-toggle:hover { background: var(--tblr-bg-surface-tertiary, rgba(0, 0, 0, .06)); }
223
+ .t-tree-icon { flex: none; color: var(--tblr-secondary); }
224
+ .t-tree-row.selected .t-tree-icon { color: inherit; }
225
+ .t-tree-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
226
+ .t-tree-actions { display: inline-flex; gap: .125rem; opacity: 0; }
227
+ .t-tree-row:hover .t-tree-actions, .t-tree-row:focus-within .t-tree-actions, .t-tree-row.selected .t-tree-actions { opacity: 1; }
228
+ .t-tree-problem { font-size: .8125rem; color: var(--tblr-danger); padding-block: .125rem; }
229
+ .t-tree-empty { font-size: .8125rem; color: var(--tblr-secondary); padding-block: .125rem; }
230
+ </style>
@@ -0,0 +1,157 @@
1
+ <script setup lang="ts">
2
+ // One level of a TContextMenu: its items in groups split by dividers, at a point on the screen
3
+ // (kept inside the window), with the keyboard: arrows move, Enter and Space choose, Right opens a
4
+ // submenu, Left and Escape close this level. A submenu is another panel, beside its item.
5
+ import { computed, nextTick, onMounted, ref, watch } from 'vue'
6
+ import TIcon from '../TIcon.vue'
7
+ import { toTabler, type ContextMenuItem } from '../../types'
8
+
9
+ defineOptions({ name: 'ContextMenuPanel' })
10
+
11
+ // `backX`: for a submenu, where its item starts, to open to the left of it when there's no room on the right.
12
+ const props = defineProps<{ items: ContextMenuItem[] | ContextMenuItem[][]; x: number; y: number; level: number; label?: string; backX?: number }>()
13
+ const emit = defineEmits<{ choose: [item: ContextMenuItem, event: Event]; close: [all: boolean] }>()
14
+
15
+ const groups = computed(() => (Array.isArray(props.items[0]) ? props.items : [props.items]) as ContextMenuItem[][])
16
+ // Every row in order, for the keyboard: choosable items only.
17
+ const rows = computed(() => groups.value.flat().filter(i => i.type !== 'label'))
18
+ const panel = ref<HTMLElement>()
19
+ const place = ref({ left: props.x, top: props.y })
20
+ const active = ref(-1)
21
+ const sub = ref<{ item: ContextMenuItem; x: number; y: number; backX: number } | null>(null)
22
+
23
+ // Inside the window: a menu that would go off the right or the bottom opens the other way.
24
+ async function fit() {
25
+ await nextTick()
26
+ const el = panel.value
27
+ if (!el) return
28
+ const { width, height } = el.getBoundingClientRect()
29
+ const margin = 4
30
+ let left = props.x
31
+ let top = props.y
32
+ if (left + width > window.innerWidth - margin) left = props.backX !== undefined ? props.backX - width : window.innerWidth - width - margin
33
+ if (top + height > window.innerHeight - margin) top = Math.max(margin, window.innerHeight - height - margin)
34
+ place.value = { left: Math.max(margin, left), top: Math.max(margin, top) }
35
+ }
36
+ onMounted(async () => {
37
+ await fit()
38
+ panel.value?.focus()
39
+ move(1)
40
+ })
41
+ watch(() => [props.x, props.y], fit)
42
+
43
+ function rowEl(index: number) {
44
+ return panel.value?.querySelectorAll<HTMLElement>('[data-row]')[index]
45
+ }
46
+ function move(by: number) {
47
+ const count = rows.value.length
48
+ if (!count) return
49
+ let next = active.value
50
+ for (let step = 0; step < count; step++) {
51
+ next = (next + by + count) % count
52
+ if (!rows.value[next]!.disabled) break
53
+ }
54
+ active.value = next
55
+ rowEl(next)?.focus()
56
+ }
57
+ function openSub(item: ContextMenuItem, index: number) {
58
+ const el = rowEl(index)
59
+ if (!el || !item.children?.length) return
60
+ const rect = el.getBoundingClientRect()
61
+ sub.value = { item, x: rect.right - 2, y: rect.top - 4, backX: rect.left + 2 }
62
+ }
63
+ function choose(item: ContextMenuItem, event: Event) {
64
+ if (item.disabled) return
65
+ if (item.children?.length) {
66
+ openSub(item, rows.value.indexOf(item))
67
+ return
68
+ }
69
+ emit('choose', item, event)
70
+ }
71
+ function key(event: KeyboardEvent) {
72
+ const item = rows.value[active.value]
73
+ switch (event.key) {
74
+ case 'ArrowDown': move(1); break
75
+ case 'ArrowUp': move(-1); break
76
+ case 'Home': active.value = -1; move(1); break
77
+ case 'End': active.value = rows.value.length; move(-1); break
78
+ case 'ArrowRight':
79
+ if (item?.children?.length && !item.disabled) openSub(item, active.value)
80
+ break
81
+ case 'ArrowLeft':
82
+ if (props.level > 0) emit('close', false)
83
+ break
84
+ case 'Enter':
85
+ case ' ':
86
+ if (item) choose(item, event)
87
+ break
88
+ case 'Escape':
89
+ emit('close', props.level === 0)
90
+ break
91
+ case 'Tab':
92
+ emit('close', true)
93
+ break
94
+ default:
95
+ return
96
+ }
97
+ event.preventDefault()
98
+ event.stopPropagation()
99
+ }
100
+ function hover(item: ContextMenuItem, index: number) {
101
+ active.value = index
102
+ rowEl(index)?.focus()
103
+ if (item.children?.length && !item.disabled) openSub(item, index)
104
+ else sub.value = null
105
+ }
106
+ function subClosed(all: boolean) {
107
+ const back = sub.value ? rows.value.indexOf(sub.value.item) : -1
108
+ sub.value = null
109
+ if (all) emit('close', true)
110
+ else if (back >= 0) rowEl(back)?.focus()
111
+ }
112
+ </script>
113
+
114
+ <template>
115
+ <div ref="panel" class="t-context-menu" role="menu" tabindex="-1" :aria-label="label"
116
+ :style="{ position: 'fixed', left: `${place.left}px`, top: `${place.top}px` }" @keydown="key" @contextmenu.prevent>
117
+ <template v-for="(group, g) in groups" :key="g">
118
+ <div v-if="g > 0 && group.length" class="dropdown-divider" />
119
+ <template v-for="(item, i) in group" :key="`${g}-${i}`">
120
+ <div v-if="item.type === 'label'" class="dropdown-header d-block">
121
+ <div class="text-body fw-medium text-truncate">{{ item.label }}</div>
122
+ <div v-if="item.description" class="text-secondary text-truncate fw-normal">{{ item.description }}</div>
123
+ </div>
124
+ <button v-else type="button" data-row role="menuitem" :aria-disabled="item.disabled || undefined" :aria-haspopup="item.children?.length ? 'menu' : undefined"
125
+ :aria-expanded="item.children?.length ? sub?.item === item : undefined" tabindex="-1"
126
+ :class="['dropdown-item', { disabled: item.disabled, active: sub?.item === item }, item.color && !item.disabled && `text-${toTabler(item.color)}`]"
127
+ @click="choose(item, $event)" @mouseenter="hover(item, rows.indexOf(item))">
128
+ <TIcon v-if="item.icon" :name="item.icon" class="dropdown-item-icon" />
129
+ <span class="min-w-0 flex-fill">
130
+ <span class="d-block text-truncate">{{ item.label }}</span>
131
+ <span v-if="item.disabled && item.reason" class="d-block small text-secondary text-truncate">{{ item.reason }}</span>
132
+ <span v-else-if="item.description" class="d-block small text-secondary text-truncate">{{ item.description }}</span>
133
+ </span>
134
+ <kbd v-if="item.kbd" class="t-context-menu-kbd ms-3">{{ item.kbd }}</kbd>
135
+ <TIcon v-if="item.children?.length" name="chevron-right" class="ms-2" />
136
+ <TIcon v-else-if="item.trailingIcon" :name="item.trailingIcon" class="ms-auto ps-2" />
137
+ </button>
138
+ </template>
139
+ </template>
140
+ </div>
141
+ <ContextMenuPanel v-if="sub" :items="sub.item.children!" :x="sub.x" :y="sub.y" :back-x="sub.backX" :level="level + 1" :label="sub.item.label"
142
+ @choose="(item, event) => emit('choose', item, event)" @close="subClosed" />
143
+ </template>
144
+
145
+ <style scoped>
146
+ /* A dropdown menu's look, without Bootstrap's .dropdown-menu, whose keyboard handler expects a toggle. */
147
+ .t-context-menu {
148
+ min-width: 12rem; max-width: 22rem; z-index: 1090; margin: 0; padding: .25rem 0;
149
+ font-size: .875rem; color: var(--tblr-body-color); background: var(--tblr-bg-surface);
150
+ border: var(--tblr-border-width) solid var(--tblr-border-color-translucent, var(--tblr-border-color));
151
+ border-radius: var(--tblr-border-radius); box-shadow: var(--tblr-box-shadow-dropdown, 0 16px 24px 2px rgba(0, 0, 0, .07));
152
+ }
153
+ .t-context-menu:focus { outline: none; }
154
+ .t-context-menu .dropdown-item { display: flex; align-items: center; width: 100%; }
155
+ .t-context-menu .dropdown-item.disabled { pointer-events: auto; cursor: default; opacity: .55; }
156
+ .t-context-menu-kbd { font-size: .6875rem; padding: .0625rem .3rem; color: var(--tblr-secondary); background: transparent; border: 1px solid var(--tblr-border-color); box-shadow: none; }
157
+ </style>
package/src/index.ts CHANGED
@@ -25,6 +25,10 @@ import TDataGrid from './components/TDataGrid.vue'
25
25
  import TDataGridItem from './components/TDataGridItem.vue'
26
26
  import TDensityPicker from './components/TDensityPicker.vue'
27
27
  import TDropdown from './components/TDropdown.vue'
28
+ import TBreadcrumbs from './components/TBreadcrumbs.vue'
29
+ import TContextMenu from './components/TContextMenu.vue'
30
+ import TTree from './components/TTree.vue'
31
+ import TFileExplorer from './components/TFileExplorer.vue'
28
32
  import TEditableTable from './components/TEditableTable.vue'
29
33
  import TEmpty from './components/TEmpty.vue'
30
34
  import TFieldGroup from './components/TFieldGroup.vue'
@@ -99,6 +103,10 @@ export {
99
103
  TDataGridItem,
100
104
  TDensityPicker,
101
105
  TDropdown,
106
+ TBreadcrumbs,
107
+ TContextMenu,
108
+ TTree,
109
+ TFileExplorer,
102
110
  TEditableTable,
103
111
  TEmpty,
104
112
  TFieldGroup,
@@ -164,7 +172,7 @@ export { useToast, type Toast, type ToastPosition } from './composables/useToast
164
172
  const components = {
165
173
  TAccentPicker, TAdvancedTable, TAlert, TAppLayout, TAuthLayout, TAvatar, TBadge, TButton, TButtonGroup, TCard,
166
174
  TCheckbox, TCheckboxTree, TCodeBlock, TColorModeButton, TCommandPalette, TContainerPicker, TCopyButton, TDataGrid, TDataGridItem, TDensityPicker,
167
- TDropdown, TEditableTable, TEmpty, TFieldGroup, TFileUpload, TFontPicker, TFormField, TIcon, TIconPicker, TImageUpload,
175
+ TDropdown, TBreadcrumbs, TContextMenu, TTree, TFileExplorer, TEditableTable, TEmpty, TFieldGroup, TFileUpload, TFontPicker, TFormField, TIcon, TIconPicker, TImageUpload,
168
176
  TInput, TInputNumber, TInputTags, TLightbox, TListBox, TLogView, TMethodBadge, TModal, TNav, TNavPositionPicker, TPage, TPagination,
169
177
  TPanelList, TProgress, TRadioGroup, TRadiusPicker, TRating, TScaledFrame, TSearchButton, TSectionLayout,
170
178
  TSelect, TSelectMenu, TSeparator, TShell, TSkeleton, TSlideover, TSparkline, TSpinner, TSplitButton, TSplitter, TStatCard,
@@ -201,6 +209,10 @@ declare module 'vue' {
201
209
  TDataGridItem: typeof TDataGridItem
202
210
  TDensityPicker: typeof TDensityPicker
203
211
  TDropdown: typeof TDropdown
212
+ TBreadcrumbs: typeof TBreadcrumbs
213
+ TContextMenu: typeof TContextMenu
214
+ TTree: typeof TTree
215
+ TFileExplorer: typeof TFileExplorer
204
216
  TEditableTable: typeof TEditableTable
205
217
  TEmpty: typeof TEmpty
206
218
  TFieldGroup: typeof TFieldGroup
package/src/types.ts CHANGED
@@ -34,6 +34,103 @@ export interface DropdownItem {
34
34
  onSelect?: (event: Event) => void
35
35
  }
36
36
 
37
+ /** A step of a TBreadcrumbs trail: a link (`to`, `href`), an action (`onSelect`), or plain text (the last, where you are). */
38
+ export interface BreadcrumbItem {
39
+ label: string
40
+ icon?: string
41
+ to?: Target
42
+ href?: string
43
+ onSelect?: (event: Event) => void
44
+ }
45
+
46
+ /**
47
+ * An item of a TContextMenu: a dropdown item, with a keyboard shortcut to show beside it
48
+ * (`kbd`, shown only), a submenu (`children`), and, for a disabled one, why (`reason`, shown
49
+ * under its label).
50
+ */
51
+ export interface ContextMenuItem extends Omit<DropdownItem, 'to' | 'href'> {
52
+ kbd?: string
53
+ children?: ContextMenuItem[] | ContextMenuItem[][]
54
+ reason?: string
55
+ }
56
+
57
+ /**
58
+ * A node of a TTree: its id and label, an icon (and one for when it's open), and its children.
59
+ * Children may come later: `leaf: false` with no `children` makes it openable, and the tree's
60
+ * `load` fetches them the first time it opens.
61
+ */
62
+ export interface TreeNode {
63
+ id: string
64
+ label: string
65
+ icon?: string
66
+ openIcon?: string
67
+ /** A node with no children to open; false (or children) makes it openable. Without either, it's openable until loaded. */
68
+ leaf?: boolean
69
+ children?: TreeNode[]
70
+ disabled?: boolean
71
+ /** Anything of the caller's: the tree only passes it back. */
72
+ data?: unknown
73
+ }
74
+
75
+ /** A drive of a TFileExplorer: a top-level place files are kept (App files, a share, a bucket). */
76
+ export interface ExplorerDrive {
77
+ id: string
78
+ name: string
79
+ icon?: string
80
+ /** Nothing can be added, renamed, moved or deleted in it. */
81
+ readOnly?: boolean
82
+ /** Why it can't be opened here; shown instead of its contents. */
83
+ unavailable?: string | null
84
+ }
85
+
86
+ /** A file or folder in a TFileExplorer. `can` says what the person may do with it (all, when unset). */
87
+ export interface ExplorerItem {
88
+ id: string
89
+ name: string
90
+ folder: boolean
91
+ size?: number | null
92
+ /** When it was last changed or uploaded (ISO). */
93
+ modifiedAt?: string | null
94
+ mimeType?: string | null
95
+ /** What the explorer shows as its kind: a file type's name, say. */
96
+ kind?: string | null
97
+ icon?: string
98
+ can?: { rename?: boolean; move?: boolean; delete?: boolean }
99
+ /** Anything of the provider's: the explorer only passes it back. */
100
+ data?: unknown
101
+ }
102
+
103
+ /** Where a TFileExplorer is: a drive, a folder in it (null for its top), and the folders on the way. */
104
+ export interface ExplorerLocation {
105
+ drive: string
106
+ folder: string | null
107
+ path: { id: string; name: string }[]
108
+ }
109
+
110
+ /** A page of a folder's contents: folders first, then files; `cursor` reads the next page (null for none). */
111
+ export interface ExplorerPage {
112
+ items: ExplorerItem[]
113
+ cursor: string | null
114
+ }
115
+
116
+ /**
117
+ * What a TFileExplorer works over: the Studio's server, an app's API, or anything else. Only
118
+ * `drives` and `list` are needed; what's missing is left out of the menus and the toolbar.
119
+ */
120
+ export interface ExplorerProvider {
121
+ drives(): Promise<ExplorerDrive[]>
122
+ /** A folder's contents (null for the drive's top), a page at a time. */
123
+ list(drive: string, folder: string | null, cursor?: string | null): Promise<ExplorerPage>
124
+ createFolder?(drive: string, parent: string | null, name: string): Promise<ExplorerItem>
125
+ rename?(drive: string, item: ExplorerItem, name: string): Promise<ExplorerItem>
126
+ /** Moves items into a folder of the same drive (null for its top). */
127
+ move?(drive: string, items: ExplorerItem[], folder: string | null): Promise<void>
128
+ remove?(drive: string, items: ExplorerItem[]): Promise<void>
129
+ upload?(drive: string, folder: string | null, file: File, progress: (sent: number) => void, signal: AbortSignal): Promise<ExplorerItem>
130
+ /** Where a file downloads from. */
131
+ href?(drive: string, item: ExplorerItem): string
132
+ }
133
+
37
134
  /** A button of a TButtonGroup: a label and/or an icon (give an icon-only one a tooltip). */
38
135
  export interface ButtonGroupItem {
39
136
  label?: string