@ternarytech-io/gears-ui 0.0.0-stage → 0.2.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.
Files changed (98) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +161 -3
  3. package/package.json +111 -6
  4. package/src/code-editor.ts +25 -0
  5. package/src/components/TAccentPicker.vue +41 -0
  6. package/src/components/TAdvancedSelect.vue +128 -0
  7. package/src/components/TAdvancedTable.vue +130 -0
  8. package/src/components/TAlert.vue +41 -0
  9. package/src/components/TAppLayout.vue +76 -0
  10. package/src/components/TAuthLayout.vue +32 -0
  11. package/src/components/TAvatar.vue +28 -0
  12. package/src/components/TBadge.vue +29 -0
  13. package/src/components/TButton.vue +60 -0
  14. package/src/components/TCard.vue +40 -0
  15. package/src/components/TCheckbox.vue +29 -0
  16. package/src/components/TCodeEditor.vue +128 -0
  17. package/src/components/TColorModeButton.vue +14 -0
  18. package/src/components/TColorPicker.vue +61 -0
  19. package/src/components/TCommandPalette.vue +109 -0
  20. package/src/components/TContainerPicker.vue +22 -0
  21. package/src/components/TCopyButton.vue +72 -0
  22. package/src/components/TDatePicker.vue +83 -0
  23. package/src/components/TDensityPicker.vue +19 -0
  24. package/src/components/TDropdown.vue +76 -0
  25. package/src/components/TDropzone.vue +76 -0
  26. package/src/components/TEmpty.vue +21 -0
  27. package/src/components/TFieldGroup.vue +11 -0
  28. package/src/components/TFileUpload.vue +92 -0
  29. package/src/components/TFontPicker.vue +23 -0
  30. package/src/components/TFormField.vue +40 -0
  31. package/src/components/TIcon.vue +12 -0
  32. package/src/components/TImageUpload.vue +131 -0
  33. package/src/components/TInput.vue +52 -0
  34. package/src/components/TInputMask.vue +70 -0
  35. package/src/components/TInputNumber.vue +62 -0
  36. package/src/components/TInputTags.vue +53 -0
  37. package/src/components/TLogView.vue +39 -0
  38. package/src/components/TModal.vue +54 -0
  39. package/src/components/TNav.vue +75 -0
  40. package/src/components/TNavPositionPicker.vue +22 -0
  41. package/src/components/TPage.vue +48 -0
  42. package/src/components/TPagination.vue +44 -0
  43. package/src/components/TPanelList.vue +29 -0
  44. package/src/components/TProgress.vue +18 -0
  45. package/src/components/TRadioGroup.vue +68 -0
  46. package/src/components/TRadiusPicker.vue +21 -0
  47. package/src/components/TRangeSlider.vue +63 -0
  48. package/src/components/TRichEditor.vue +82 -0
  49. package/src/components/TScaledFrame.vue +36 -0
  50. package/src/components/TSearchButton.vue +20 -0
  51. package/src/components/TSectionLayout.vue +37 -0
  52. package/src/components/TSelect.vue +60 -0
  53. package/src/components/TSelectMenu.vue +126 -0
  54. package/src/components/TSeparator.vue +10 -0
  55. package/src/components/TShell.vue +72 -0
  56. package/src/components/TSkeleton.vue +17 -0
  57. package/src/components/TSlideover.vue +47 -0
  58. package/src/components/TSortable.vue +61 -0
  59. package/src/components/TSortableTree.vue +73 -0
  60. package/src/components/TSortableTreeList.vue +60 -0
  61. package/src/components/TSpinner.vue +14 -0
  62. package/src/components/TSplitter.vue +85 -0
  63. package/src/components/TStatCard.vue +26 -0
  64. package/src/components/TSteps.vue +19 -0
  65. package/src/components/TSwitch.vue +18 -0
  66. package/src/components/TTable.vue +134 -0
  67. package/src/components/TTabs.vue +38 -0
  68. package/src/components/TTextarea.vue +42 -0
  69. package/src/components/TThemeBasePicker.vue +22 -0
  70. package/src/components/TThemeScope.vue +23 -0
  71. package/src/components/TToaster.vue +27 -0
  72. package/src/components/TTooltip.vue +33 -0
  73. package/src/components/TTopbar.vue +17 -0
  74. package/src/components/TVectorMap.vue +74 -0
  75. package/src/components/sortableTree.ts +19 -0
  76. package/src/composables/useColorMode.ts +41 -0
  77. package/src/composables/useCommandPalette.ts +11 -0
  78. package/src/composables/useField.ts +26 -0
  79. package/src/composables/useOverlay.ts +55 -0
  80. package/src/composables/useToast.ts +33 -0
  81. package/src/index.ts +215 -0
  82. package/src/monaco.ts +27 -0
  83. package/src/plugins/coloris.ts +8 -0
  84. package/src/plugins/datepicker.ts +7 -0
  85. package/src/plugins/dropzone.ts +5 -0
  86. package/src/plugins/index.ts +52 -0
  87. package/src/plugins/inputMask.ts +7 -0
  88. package/src/plugins/once.ts +8 -0
  89. package/src/plugins/richEditor.ts +37 -0
  90. package/src/plugins/slider.ts +4 -0
  91. package/src/plugins/sortable.ts +7 -0
  92. package/src/plugins/tomSelect.ts +4 -0
  93. package/src/shims.d.ts +17 -0
  94. package/src/styles/gears.css +625 -0
  95. package/src/styles/plugins.css +10 -0
  96. package/src/theme.ts +45 -0
  97. package/src/types.ts +177 -0
  98. package/src/vectorMap.ts +14 -0
@@ -0,0 +1,19 @@
1
+ <script setup lang="ts">
2
+ // A wizard's progress: the steps, with the current one bound by v-model (from 0). Steps already
3
+ // done can be clicked to go back to them.
4
+ import { toTabler, type Color, type StepItem } from '../types'
5
+
6
+ withDefaults(defineProps<{ items: StepItem[]; color?: Color; counter?: boolean }>(), { color: 'primary', counter: true })
7
+
8
+ const step = defineModel<number>({ default: 0 })
9
+ </script>
10
+
11
+ <template>
12
+ <div :class="['steps', `steps-${toTabler(color)}`, { 'steps-counter': counter }]">
13
+ <component :is="i < step ? 'a' : 'span'" v-for="(item, i) in items" :key="i" :href="i < step ? '#' : undefined"
14
+ :class="['step-item', { active: i === step }]" :aria-current="i === step ? 'step' : undefined" @click.prevent="i < step && (step = i)">
15
+ <span class="d-block">{{ item.title }}</span>
16
+ <span v-if="item.description" class="d-block small text-secondary fw-normal">{{ item.description }}</span>
17
+ </component>
18
+ </div>
19
+ </template>
@@ -0,0 +1,18 @@
1
+ <script setup lang="ts">
2
+ // An on/off switch, for settings that apply right away.
3
+ import { useField } from '../composables/useField'
4
+
5
+ const props = defineProps<{ label?: string; description?: string; disabled?: boolean; id?: string }>()
6
+
7
+ const model = defineModel<boolean>({ default: false })
8
+ const field = useField(props)
9
+ </script>
10
+
11
+ <template>
12
+ <label class="form-check form-switch" :for="field.id.value">
13
+ <input :id="field.id.value" v-model="model" type="checkbox" role="switch" class="form-check-input" :disabled="disabled"
14
+ :aria-describedby="field.describedBy.value">
15
+ <span class="form-check-label"><slot>{{ label }}</slot></span>
16
+ <span v-if="description" class="form-check-description">{{ description }}</span>
17
+ </label>
18
+ </template>
@@ -0,0 +1,134 @@
1
+ <script setup lang="ts" generic="Row extends Record<string, any>">
2
+ // A table of rows. Columns name a key, a label and how to align; a `{key}-cell` slot draws a cell
3
+ // (it gets the row and value), `{key}-header` a heading, and the `cell` slot any cell without its
4
+ // own slot. Sortable columns sort the rows here, unless `manualSort` leaves it to the caller (who
5
+ // watches v-model:sort); a `{key}-header` slot gets the column's sort and `toggleSort` to draw its
6
+ // own sort button. `selectable` adds a checkbox to each row (Tabler's table-selectable) and one in
7
+ // the header for every row; v-model:selected holds the chosen rows' keys. `card` fits it into a
8
+ // flush TCard; `sticky` keeps the header in view while the table scrolls in its container.
9
+ import { computed, ref, watchEffect } from 'vue'
10
+ import TSpinner from './TSpinner.vue'
11
+ import type { TableColumn, TableSort } from '../types'
12
+
13
+ const props = withDefaults(defineProps<{
14
+ columns: TableColumn<Row>[]
15
+ rows: Row[]
16
+ rowKey?: string | ((row: Row) => string | number)
17
+ loading?: boolean
18
+ empty?: string
19
+ card?: boolean
20
+ striped?: boolean
21
+ hover?: boolean
22
+ // Rows can be clicked; each click emits `select`.
23
+ clickable?: boolean
24
+ // A checkbox on each row; clicking a row (unless it's `clickable`) checks it too.
25
+ selectable?: boolean
26
+ manualSort?: boolean
27
+ sticky?: boolean
28
+ }>(), { rowKey: 'id', empty: 'Nothing to show.' })
29
+
30
+ const emit = defineEmits<{ select: [row: Row] }>()
31
+ const sort = defineModel<TableSort | null>('sort', { default: null })
32
+ const selected = defineModel<(string | number)[]>('selected', { default: () => [] })
33
+
34
+ const cell = (row: Row, column: TableColumn<Row>) => column.value ? column.value(row) : row[column.key]
35
+ const key = (row: Row, index: number) => typeof props.rowKey === 'function' ? props.rowKey(row) : row[props.rowKey] ?? index
36
+ const align = (column: TableColumn<Row>) => column.align === 'end' ? 'text-end' : column.align === 'center' ? 'text-center' : undefined
37
+
38
+ const sorted = computed(() => {
39
+ const by = sort.value
40
+ const column = by && props.columns.find(c => c.key === by.key)
41
+ if (!by || !column || props.manualSort) return props.rows
42
+ const factor = by.direction === 'asc' ? 1 : -1
43
+ return [...props.rows].sort((a, b) => {
44
+ const x = cell(a, column) as any
45
+ const y = cell(b, column) as any
46
+ if (x == null) return y == null ? 0 : 1
47
+ if (y == null) return -1
48
+ return (typeof x === 'number' && typeof y === 'number' ? x - y : String(x).localeCompare(String(y), undefined, { numeric: true })) * factor
49
+ })
50
+ })
51
+
52
+ function sortOf(column: TableColumn<Row>) {
53
+ return sort.value?.key === column.key ? sort.value.direction : null
54
+ }
55
+
56
+ function toggleSort(column: TableColumn<Row>) {
57
+ const current = sort.value?.key === column.key ? sort.value.direction : null
58
+ sort.value = current === 'asc' ? { key: column.key, direction: 'desc' } : current === 'desc' ? null : { key: column.key, direction: 'asc' }
59
+ }
60
+
61
+ // ---- Selection ----
62
+ const keys = computed(() => sorted.value.map((row, index) => key(row, index)))
63
+ const isChecked = (row: Row, index: number) => selected.value.includes(key(row, index))
64
+ const allChecked = computed(() => keys.value.length > 0 && keys.value.every(k => selected.value.includes(k)))
65
+ const someChecked = computed(() => !allChecked.value && keys.value.some(k => selected.value.includes(k)))
66
+ const allBox = ref<HTMLInputElement>()
67
+ watchEffect(() => { if (allBox.value) allBox.value.indeterminate = someChecked.value })
68
+
69
+ function check(row: Row, index: number) {
70
+ const k = key(row, index)
71
+ selected.value = selected.value.includes(k) ? selected.value.filter(x => x !== k) : [...selected.value, k]
72
+ }
73
+ // The header's box checks every row shown, or unchecks them (keeping rows not shown).
74
+ function checkAll() {
75
+ selected.value = allChecked.value
76
+ ? selected.value.filter(k => !keys.value.includes(k))
77
+ : [...new Set([...selected.value, ...keys.value])]
78
+ }
79
+ function clickRow(row: Row, index: number) {
80
+ if (props.clickable) emit('select', row)
81
+ else if (props.selectable) check(row, index)
82
+ }
83
+
84
+ const span = computed(() => props.columns.length + (props.selectable ? 1 : 0))
85
+
86
+ function format(value: unknown) {
87
+ if (value == null || value === '') return '—'
88
+ if (typeof value === 'boolean') return value ? 'Yes' : 'No'
89
+ return String(value)
90
+ }
91
+ </script>
92
+
93
+ <template>
94
+ <div :class="sticky ? 't-table-sticky' : 'table-responsive'">
95
+ <table :class="['table table-vcenter mb-0', { 'card-table': card, 'table-striped': striped, 'table-hover': hover || clickable, 'table-selectable': selectable }]">
96
+ <thead>
97
+ <tr>
98
+ <th v-if="selectable" class="w-1">
99
+ <input ref="allBox" type="checkbox" class="form-check-input m-0 align-middle" :checked="allChecked" :disabled="!keys.length"
100
+ aria-label="Select every row" @change="checkAll">
101
+ </th>
102
+ <th v-for="column in columns" :key="column.key" :class="align(column)" :style="column.width ? { width: column.width } : undefined"
103
+ :aria-sort="sort?.key === column.key ? (sort.direction === 'asc' ? 'ascending' : 'descending') : undefined">
104
+ <slot :name="`${column.key}-header`" :column="column" :sort="sortOf(column)" :toggle-sort="() => toggleSort(column)">
105
+ <button v-if="column.sortable" type="button" :class="['table-sort', { asc: sort?.key === column.key && sort.direction === 'asc', desc: sort?.key === column.key && sort.direction === 'desc' }]"
106
+ @click="toggleSort(column)">{{ column.label ?? column.key }}</button>
107
+ <template v-else>{{ column.label ?? column.key }}</template>
108
+ </slot>
109
+ </th>
110
+ </tr>
111
+ </thead>
112
+ <tbody>
113
+ <tr v-if="loading && !rows.length">
114
+ <td :colspan="span" class="text-center py-4"><TSpinner size="sm" show-label /></td>
115
+ </tr>
116
+ <tr v-else-if="!rows.length">
117
+ <td :colspan="span" class="text-center text-secondary py-4"><slot name="empty">{{ empty }}</slot></td>
118
+ </tr>
119
+ <tr v-for="(row, index) in sorted" v-else :key="key(row, index)"
120
+ :class="{ 'cursor-pointer': clickable || selectable, 'table-active': selectable && isChecked(row, index) }" @click="clickRow(row, index)">
121
+ <td v-if="selectable" @click.stop>
122
+ <input type="checkbox" class="form-check-input m-0 align-middle table-selectable-check" :checked="isChecked(row, index)"
123
+ aria-label="Select the row" @change="check(row, index)">
124
+ </td>
125
+ <td v-for="column in columns" :key="column.key" :class="align(column)">
126
+ <slot :name="`${column.key}-cell`" :row="row" :value="cell(row, column)">
127
+ <slot name="cell" :row="row" :column="column" :value="cell(row, column)">{{ format(cell(row, column)) }}</slot>
128
+ </slot>
129
+ </td>
130
+ </tr>
131
+ </tbody>
132
+ </table>
133
+ </div>
134
+ </template>
@@ -0,0 +1,38 @@
1
+ <script setup lang="ts">
2
+ // Tabs, bound with v-model to the chosen item's value (the first item's when unset). Each tab's
3
+ // content goes in a slot named after its value; the default slot gets the chosen item. `segmented`
4
+ // is a compact switch between modes (it usually has no content slots); `card` fits the tabs into a
5
+ // TCard's header slot.
6
+ import { computed } from 'vue'
7
+ import TIcon from './TIcon.vue'
8
+ import type { TabItem } from '../types'
9
+
10
+ const props = withDefaults(defineProps<{
11
+ items: TabItem[]
12
+ variant?: 'tabs' | 'pills' | 'segmented'
13
+ size?: 'sm' | 'md'
14
+ card?: boolean
15
+ }>(), { variant: 'tabs', size: 'md' })
16
+
17
+ const model = defineModel<string>()
18
+ const current = computed(() => model.value ?? props.items[0]?.value)
19
+ const item = computed(() => props.items.find(i => i.value === current.value))
20
+ </script>
21
+
22
+ <template>
23
+ <div>
24
+ <nav :class="['nav', `nav-${variant}`, { 'card-header-tabs': card, 'nav-segmented-sm': variant === 'segmented' && size === 'sm' }]" role="tablist">
25
+ <button v-for="tab in items" :key="tab.value" type="button" role="tab" :class="['nav-link', { active: tab.value === current }]"
26
+ :aria-selected="tab.value === current" :disabled="tab.disabled" @click="model = tab.value">
27
+ <TIcon v-if="tab.icon" :name="tab.icon" :class="variant === 'segmented' ? 'me-1' : 'me-2'" />
28
+ {{ tab.label }}
29
+ <span v-if="tab.badge != null" class="badge bg-secondary-lt ms-2">{{ tab.badge }}</span>
30
+ </button>
31
+ </nav>
32
+ <div v-if="item && ($slots[item.value] || $slots.default)" class="pt-3" role="tabpanel">
33
+ <slot :name="item.value" :item="item">
34
+ <slot :item="item" />
35
+ </slot>
36
+ </div>
37
+ </div>
38
+ </template>
@@ -0,0 +1,42 @@
1
+ <script setup lang="ts">
2
+ // A multi-line text input. `autoresize` grows it with its text instead of scrolling; `autofocus`
3
+ // focuses it when it appears.
4
+ import { nextTick, onMounted, ref, watch } from 'vue'
5
+ import { useField } from '../composables/useField'
6
+
7
+ defineOptions({ inheritAttrs: false })
8
+
9
+ const props = withDefaults(defineProps<{
10
+ placeholder?: string
11
+ rows?: number
12
+ autoresize?: boolean
13
+ disabled?: boolean
14
+ readonly?: boolean
15
+ invalid?: boolean
16
+ autofocus?: boolean
17
+ id?: string
18
+ }>(), { rows: 3 })
19
+
20
+ const model = defineModel<string | null | undefined>()
21
+ const field = useField(props)
22
+ const el = ref<HTMLTextAreaElement>()
23
+
24
+ function resize() {
25
+ if (!props.autoresize || !el.value) return
26
+ el.value.style.height = 'auto'
27
+ el.value.style.height = `${el.value.scrollHeight + 2}px`
28
+ }
29
+
30
+ onMounted(() => {
31
+ resize()
32
+ if (props.autofocus) el.value?.focus()
33
+ })
34
+ watch(model, () => nextTick(resize))
35
+ </script>
36
+
37
+ <template>
38
+ <textarea v-bind="$attrs" :id="field.id.value" ref="el" :value="model ?? ''" :rows="rows" :placeholder="placeholder" :disabled="disabled" :readonly="readonly"
39
+ :aria-describedby="field.describedBy.value" :aria-invalid="field.invalid.value || undefined"
40
+ :class="['form-control', { 'is-invalid': field.invalid.value }]" :style="autoresize ? { resize: 'none', overflow: 'hidden' } : undefined"
41
+ @input="model = ($event.target as HTMLTextAreaElement).value" />
42
+ </template>
@@ -0,0 +1,22 @@
1
+ <script setup lang="ts">
2
+ // A theme's base: the grays behind every surface, border and muted text. Each tile shows five of
3
+ // the base's shades, lightest to darkest.
4
+ import TRadioGroup from './TRadioGroup.vue'
5
+ import { themeBases } from '../theme'
6
+ import type { ThemeBase } from '../types'
7
+
8
+ defineProps<{ disabled?: boolean; legend?: string }>()
9
+
10
+ const model = defineModel<ThemeBase | null | undefined>()
11
+ const shades = [100, 300, 500, 700, 900]
12
+ </script>
13
+
14
+ <template>
15
+ <TRadioGroup v-model="model" :items="themeBases" variant="tiles" :disabled="disabled" :legend="legend">
16
+ <template #preview="{ item }">
17
+ <span class="t-theme-swatches" :data-bs-theme-base="item.value">
18
+ <span v-for="shade in shades" :key="shade" :style="{ background: `var(--tblr-gray-${shade})` }" />
19
+ </span>
20
+ </template>
21
+ </TRadioGroup>
22
+ </template>
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ // Tabler's theme settings for part of a page: what's inside takes the theme's accent color, font,
3
+ // base grays, corner radius, density and light or dark mode, whatever the page around it uses. For
4
+ // previews of an application's theme. A custom accent (#rrggbb) is set as the primary color
5
+ // directly. Layout (navigation, container) is TAppLayout's.
6
+ import { computed } from 'vue'
7
+ import { useColorMode } from '../composables/useColorMode'
8
+ import { isCustomAccent } from '../theme'
9
+ import type { ThemeSettings } from '../types'
10
+
11
+ const props = defineProps<{ theme: ThemeSettings }>()
12
+ const { resolved } = useColorMode()
13
+
14
+ const custom = computed(() => isCustomAccent(props.theme.accent))
15
+ </script>
16
+
17
+ <template>
18
+ <div class="t-theme-scope" :data-bs-theme="theme.mode ?? resolved" :data-bs-theme-base="theme.base"
19
+ :data-bs-theme-font="theme.font" :data-bs-theme-radius="theme.radius" :data-t-density="theme.density"
20
+ :data-bs-theme-primary="custom ? undefined : theme.accent" :style="custom ? { '--tblr-primary': theme.accent } : undefined">
21
+ <slot />
22
+ </div>
23
+ </template>
@@ -0,0 +1,27 @@
1
+ <script setup lang="ts">
2
+ // Shows the toasts added with useToast(), stacked in the bottom corner. Put one in the app's frame.
3
+ import TIcon from './TIcon.vue'
4
+ import { useToast } from '../composables/useToast'
5
+ import { toTabler } from '../types'
6
+
7
+ const { toasts, remove } = useToast()
8
+ </script>
9
+
10
+ <template>
11
+ <Teleport to="body">
12
+ <div class="toast-container position-fixed bottom-0 end-0 p-3" aria-live="polite">
13
+ <TransitionGroup name="t-toast">
14
+ <div v-for="toast in toasts" :key="toast.id" class="toast show t-toast" role="status">
15
+ <div class="toast-body d-flex align-items-start gap-2">
16
+ <TIcon v-if="toast.icon" :name="toast.icon" :class="['mt-1', toast.color && toast.color !== 'neutral' ? `text-${toTabler(toast.color)}` : 'text-secondary']" />
17
+ <div class="flex-fill min-w-0">
18
+ <div class="fw-medium">{{ toast.title }}</div>
19
+ <div v-if="toast.description" class="text-secondary small mt-1">{{ toast.description }}</div>
20
+ </div>
21
+ <button type="button" class="btn-close ms-2" aria-label="Close" @click="remove(toast.id)" />
22
+ </div>
23
+ </div>
24
+ </TransitionGroup>
25
+ </div>
26
+ </Teleport>
27
+ </template>
@@ -0,0 +1,33 @@
1
+ <script setup lang="ts">
2
+ // A short hint on hover or focus, around whatever is in the slot. The text is read when the
3
+ // tooltip shows, so it can change; with no text it doesn't show.
4
+ import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
5
+ import { Tooltip } from '@tabler/core'
6
+
7
+ const props = withDefaults(defineProps<{ text?: string; placement?: 'top' | 'bottom' | 'start' | 'end'; disabled?: boolean }>(),
8
+ { placement: 'top' })
9
+
10
+ const el = ref<HTMLElement>()
11
+ let tooltip: Tooltip | null = null
12
+
13
+ const placements = { top: 'top', bottom: 'bottom', start: 'left', end: 'right' } as const
14
+
15
+ onMounted(() => {
16
+ tooltip = new Tooltip(el.value!, {
17
+ title: () => props.text ?? '',
18
+ placement: placements[props.placement],
19
+ trigger: 'hover focus',
20
+ delay: { show: 150, hide: 0 }
21
+ })
22
+ el.value!.addEventListener('show.bs.tooltip', event => { if (!props.text || props.disabled) event.preventDefault() })
23
+ })
24
+
25
+ watch(() => props.disabled, disabled => { if (disabled) tooltip?.hide() })
26
+ onBeforeUnmount(() => tooltip?.dispose())
27
+ </script>
28
+
29
+ <template>
30
+ <span ref="el" class="d-inline-flex">
31
+ <slot />
32
+ </span>
33
+ </template>
@@ -0,0 +1,17 @@
1
+ <script setup lang="ts">
2
+ // The bar along the top of a page: things on the left (a switcher, breadcrumbs) and on the right
3
+ // (search, actions, the theme and user menus).
4
+ </script>
5
+
6
+ <template>
7
+ <header class="navbar navbar-expand d-print-none border-bottom t-topbar">
8
+ <div class="container-fluid gap-2 flex-nowrap">
9
+ <div class="d-flex align-items-center gap-2 min-w-0">
10
+ <slot name="left" />
11
+ </div>
12
+ <div class="d-flex align-items-center gap-2 ms-auto">
13
+ <slot name="right" />
14
+ </div>
15
+ </div>
16
+ </header>
17
+ </template>
@@ -0,0 +1,74 @@
1
+ <script setup lang="ts">
2
+ // A world map with Tabler's vector map: countries shaded by `values` (a number per ISO code, such
3
+ // as { US: 120, DE: 80 }), places as `markers`, `lines` between markers, a `legend` for the scale,
4
+ // and selecting countries (`select`, with v-model:selected). `zoom` adds zoom buttons and dragging.
5
+ // The map and its data load on first use.
6
+ import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
7
+ import type VectorMap from '@tabler/core/dist/types/src/vector-map'
8
+ import type { VectorMapLine, VectorMapMarker, VectorMapTooltipItem } from '@tabler/core/dist/types/src/vector-map'
9
+ import { loadVectorMap } from '../vectorMap'
10
+
11
+ const props = withDefaults(defineProps<{
12
+ values?: Record<string, number>
13
+ min?: number
14
+ max?: number
15
+ // Two to five colors for the scale, low to high.
16
+ colors?: string[]
17
+ markers?: VectorMapMarker[]
18
+ lines?: VectorMapLine[]
19
+ tooltip?: boolean | ((item: VectorMapTooltipItem) => string)
20
+ legend?: boolean | ((value: number) => string)
21
+ select?: 'none' | 'single' | 'multiple'
22
+ zoom?: boolean
23
+ label?: string
24
+ height?: string
25
+ }>(), { values: () => ({}), colors: () => [], markers: () => [], lines: () => [], tooltip: true, legend: false, select: 'none', label: 'World map', height: '20rem' })
26
+
27
+ const selected = defineModel<string[]>('selected', { default: () => [] })
28
+ const emit = defineEmits<{ 'region-click': [code: string] }>()
29
+
30
+ const el = ref<HTMLElement>()
31
+ let map: VectorMap | null = null
32
+
33
+ async function create() {
34
+ const VectorMapClass = await loadVectorMap()
35
+ if (!el.value) return
36
+ map?.dispose()
37
+ el.value.replaceChildren()
38
+ map = new VectorMapClass(el.value, {
39
+ values: props.values,
40
+ min: props.min ?? null,
41
+ max: props.max ?? null,
42
+ colors: props.colors,
43
+ markers: props.markers,
44
+ lines: props.lines,
45
+ tooltip: props.tooltip,
46
+ legend: props.legend,
47
+ select: props.select,
48
+ selected: selected.value,
49
+ zoom: props.zoom,
50
+ label: props.label
51
+ })
52
+ }
53
+
54
+ onMounted(() => {
55
+ create()
56
+ el.value!.addEventListener('selected.bs.vector-map', event => {
57
+ selected.value = [...((event as Event & { selected: string[] }).selected ?? [])]
58
+ })
59
+ el.value!.addEventListener('regionclick.bs.vector-map', event => {
60
+ emit('region-click', (event as Event & { code: string }).code)
61
+ })
62
+ })
63
+
64
+ watch(() => props.values, values => map?.update(values), { deep: true })
65
+ watch(() => [props.min, props.max, props.colors, props.markers, props.lines, props.tooltip, props.legend, props.select, props.zoom, props.label], create, { deep: true })
66
+ watch(selected, codes => {
67
+ if (map && JSON.stringify(map.getSelected()) !== JSON.stringify(codes)) map.setSelected(codes)
68
+ })
69
+ onBeforeUnmount(() => map?.dispose())
70
+ </script>
71
+
72
+ <template>
73
+ <div ref="el" class="vector-map" :style="{ height }" />
74
+ </template>
@@ -0,0 +1,19 @@
1
+ // What TSortableTree shares with its lists (TSortableTreeList), one per level.
2
+ import type { InjectionKey, Ref, VNode } from 'vue'
3
+
4
+ export interface TreeItemScope<T> { item: T; depth: number; parent: T | null }
5
+
6
+ export interface TreeContext<T> {
7
+ // The SortableJS group: items move between this tree's lists, and no other's.
8
+ group: string
9
+ handle?: boolean
10
+ disabled?: boolean
11
+ maxDepth: number
12
+ dragging: Ref<boolean>
13
+ keyOf(item: T): string
14
+ childrenOf(item: T): T[]
15
+ move(fromKey: string, oldIndex: number, toKey: string, newIndex: number): void
16
+ render(scope: TreeItemScope<T>): VNode[] | undefined
17
+ }
18
+
19
+ export const treeKey: InjectionKey<TreeContext<object>> = Symbol('t-sortable-tree')
@@ -0,0 +1,41 @@
1
+ // The color theme: light, dark or the system's. Tabler reads `data-bs-theme` on <html>; the choice
2
+ // is remembered in localStorage (the browser may refuse, so that's best effort).
3
+ import { computed, ref, watchEffect } from 'vue'
4
+
5
+ export type ColorMode = 'light' | 'dark' | 'system'
6
+
7
+ const storageKey = 'gears-color-mode'
8
+ const media = typeof window !== 'undefined' ? window.matchMedia('(prefers-color-scheme: dark)') : null
9
+
10
+ function stored(): ColorMode {
11
+ try {
12
+ const value = localStorage.getItem(storageKey)
13
+ if (value === 'light' || value === 'dark' || value === 'system') return value
14
+ } catch { /* storage blocked */ }
15
+ return 'system'
16
+ }
17
+
18
+ const preference = ref<ColorMode>(stored())
19
+ const systemDark = ref(media?.matches ?? false)
20
+ media?.addEventListener('change', e => { systemDark.value = e.matches })
21
+
22
+ const resolved = computed<'light' | 'dark'>(() =>
23
+ preference.value === 'system' ? (systemDark.value ? 'dark' : 'light') : preference.value)
24
+
25
+ let applied = false
26
+
27
+ export function useColorMode() {
28
+ if (!applied && typeof document !== 'undefined') {
29
+ applied = true
30
+ watchEffect(() => {
31
+ document.documentElement.setAttribute('data-bs-theme', resolved.value)
32
+ try { localStorage.setItem(storageKey, preference.value) } catch { /* storage blocked */ }
33
+ })
34
+ }
35
+ return {
36
+ preference,
37
+ resolved,
38
+ isDark: computed(() => resolved.value === 'dark'),
39
+ toggle: () => { preference.value = resolved.value === 'dark' ? 'light' : 'dark' }
40
+ }
41
+ }
@@ -0,0 +1,11 @@
1
+ // The command palette's open state, shared: TSearchButton opens it, TCommandPalette shows it, and
2
+ // Ctrl+K (⌘K on a Mac) toggles it from anywhere.
3
+ import { ref } from 'vue'
4
+
5
+ const open = ref(false)
6
+
7
+ export const isMac = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform)
8
+
9
+ export function useCommandPalette() {
10
+ return { open, toggle: () => { open.value = !open.value } }
11
+ }
@@ -0,0 +1,26 @@
1
+ // A form field shares its id and state with the control inside it, so the label points at the
2
+ // control and an error marks it invalid without wiring each one by hand.
3
+ import { computed, inject, provide, useId, type ComputedRef, type InjectionKey } from 'vue'
4
+
5
+ export interface FieldContext {
6
+ id: string
7
+ invalid: ComputedRef<boolean>
8
+ describedBy: ComputedRef<string | undefined>
9
+ }
10
+
11
+ const fieldKey: InjectionKey<FieldContext> = Symbol('t-field')
12
+
13
+ export function provideField(context: FieldContext) {
14
+ provide(fieldKey, context)
15
+ }
16
+
17
+ // The control's id (its own, its field's or a new one), whether it's invalid, and what describes it.
18
+ export function useField(props: { id?: string; invalid?: boolean }) {
19
+ const field = inject(fieldKey, null)
20
+ const fallback = useId()
21
+ return {
22
+ id: computed(() => props.id ?? field?.id ?? fallback),
23
+ invalid: computed(() => props.invalid || (field?.invalid.value ?? false)),
24
+ describedBy: computed(() => field?.describedBy.value)
25
+ }
26
+ }
@@ -0,0 +1,55 @@
1
+ // Drives a Bootstrap modal or offcanvas from a v-model: opening the model shows it, and closing it
2
+ // any way (the close button, Esc, the backdrop) sets the model back. Content renders while it's
3
+ // open and until it has faded out. `afterEnter` runs once it has opened (and taken focus).
4
+ import { onBeforeUnmount, onMounted, ref, watch, type Ref } from 'vue'
5
+
6
+ interface Overlay {
7
+ show(): void
8
+ hide(): void
9
+ dispose(): void
10
+ }
11
+
12
+ export function useOverlay(el: Ref<HTMLElement | undefined>, kind: 'modal' | 'offcanvas', open: Ref<boolean>,
13
+ create: (el: HTMLElement) => Overlay, afterLeave: () => void, afterEnter?: () => void) {
14
+ const rendered = ref(open.value)
15
+ let overlay: Overlay | null = null
16
+ let shown = false
17
+
18
+ onMounted(() => {
19
+ const element = el.value!
20
+ overlay = create(element)
21
+ element.addEventListener(`show.bs.${kind}`, () => { shown = true })
22
+ element.addEventListener(`shown.bs.${kind}`, () => afterEnter?.())
23
+ element.addEventListener(`hide.bs.${kind}`, () => {
24
+ shown = false
25
+ if (open.value) open.value = false
26
+ })
27
+ element.addEventListener(`hidden.bs.${kind}`, () => {
28
+ if (!open.value) rendered.value = false
29
+ afterLeave()
30
+ })
31
+ if (open.value) overlay.show()
32
+ })
33
+
34
+ watch(open, value => {
35
+ if (value) {
36
+ rendered.value = true
37
+ overlay?.show()
38
+ } else {
39
+ overlay?.hide()
40
+ }
41
+ })
42
+
43
+ onBeforeUnmount(() => {
44
+ overlay?.dispose()
45
+ // Bootstrap leaves its backdrop and scroll lock behind when an open overlay is disposed.
46
+ if (shown) {
47
+ document.querySelectorAll(`.${kind}-backdrop`).forEach(backdrop => backdrop.remove())
48
+ document.body.classList.remove('modal-open')
49
+ document.body.style.removeProperty('overflow')
50
+ document.body.style.removeProperty('padding-right')
51
+ }
52
+ })
53
+
54
+ return rendered
55
+ }
@@ -0,0 +1,33 @@
1
+ // Short notices in the corner ("Saved.", "Deleted."), shown by a TToaster in the app's frame:
2
+ // `useToast().add({ title, description, color, icon })`. They close by themselves after
3
+ // `duration` milliseconds (5 seconds; 0 keeps one until it's closed).
4
+ import { ref } from 'vue'
5
+ import type { Color } from '../types'
6
+
7
+ export interface Toast {
8
+ id: number
9
+ title: string
10
+ description?: string
11
+ color?: Color
12
+ icon?: string
13
+ duration?: number
14
+ }
15
+
16
+ const toasts = ref<Toast[]>([])
17
+ let nextId = 1
18
+
19
+ function remove(id: number) {
20
+ toasts.value = toasts.value.filter(t => t.id !== id)
21
+ }
22
+
23
+ function add(toast: Omit<Toast, 'id'>) {
24
+ const id = nextId++
25
+ toasts.value = [...toasts.value, { ...toast, id }]
26
+ const duration = toast.duration ?? 5000
27
+ if (duration > 0) setTimeout(() => remove(id), duration)
28
+ return id
29
+ }
30
+
31
+ export function useToast() {
32
+ return { toasts, add, remove }
33
+ }