@ternarytech-io/gears-ui 0.3.0 → 0.3.1
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 +113 -113
- package/src/components/TAccentPicker.vue +41 -41
- package/src/components/TContainerPicker.vue +22 -22
- package/src/components/TDensityPicker.vue +19 -19
- package/src/components/TEditableTable.vue +203 -203
- package/src/components/TFontPicker.vue +23 -23
- package/src/components/TNavPositionPicker.vue +22 -22
- package/src/components/TScaledFrame.vue +36 -36
- package/src/components/TShell.vue +82 -72
- package/src/components/TSortableTree.vue +73 -73
- package/src/components/TSortableTreeList.vue +60 -60
- package/src/components/TSparkline.vue +34 -34
- package/src/components/TStatCard.vue +56 -56
- package/src/components/TThemeBasePicker.vue +22 -22
- package/src/components/sortableTree.ts +19 -19
- package/src/index.ts +227 -227
- package/src/plugins/charts.ts +4 -4
- package/src/styles/gears.css +18 -12
|
@@ -1,72 +1,82 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
// An app's frame: the sidebar (dark in both themes) with the brand, the links and a footer, and
|
|
3
|
-
// the page beside it. The sidebar folds to icons (remembered per `storageKey`); on small screens
|
|
4
|
-
// it's a top bar whose menu opens below it.
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// An app's frame: the sidebar (dark in both themes) with the brand, the links and a footer, and
|
|
3
|
+
// the page beside it. The sidebar folds to icons (remembered per `storageKey`); on small screens
|
|
4
|
+
// it's a top bar whose menu opens below it. `fold` folds it for a while (a full-screen editor, say)
|
|
5
|
+
// without changing what's remembered; the toggle still opens it for the moment.
|
|
6
|
+
import { computed, ref, watch } from 'vue'
|
|
7
|
+
import { RouterLink, useRoute } from 'vue-router'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import TNav from './TNav.vue'
|
|
10
|
+
import type { NavItem, Target } from '../types'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
nav: NavItem[]
|
|
14
|
+
footerNav?: NavItem[]
|
|
15
|
+
brand?: string
|
|
16
|
+
// A line under the brand name, in small capitals.
|
|
17
|
+
tagline?: string
|
|
18
|
+
logo?: string
|
|
19
|
+
brandTo?: Target
|
|
20
|
+
foldable?: boolean
|
|
21
|
+
storageKey?: string
|
|
22
|
+
fold?: boolean
|
|
23
|
+
}>(), { brandTo: '/', foldable: true, storageKey: 'gears-sidebar', fold: false })
|
|
24
|
+
|
|
25
|
+
function storedFold() {
|
|
26
|
+
try { return localStorage.getItem(props.storageKey) === 'folded' } catch { return false }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const remembered = ref(props.foldable && storedFold())
|
|
30
|
+
// While `fold` is on: folded unless the toggle opened it; null when `fold` is off.
|
|
31
|
+
const temporary = ref<boolean | null>(props.foldable && props.fold ? true : null)
|
|
32
|
+
const folded = computed(() => temporary.value ?? remembered.value)
|
|
33
|
+
const menuOpen = ref(false)
|
|
34
|
+
const route = useRoute()
|
|
35
|
+
|
|
36
|
+
watch(remembered, value => {
|
|
37
|
+
try { localStorage.setItem(props.storageKey, value ? 'folded' : 'open') } catch { /* storage blocked */ }
|
|
38
|
+
})
|
|
39
|
+
watch(() => props.fold, fold => { temporary.value = props.foldable && fold ? true : null })
|
|
40
|
+
function toggle() {
|
|
41
|
+
if (temporary.value !== null) temporary.value = !temporary.value
|
|
42
|
+
else remembered.value = !remembered.value
|
|
43
|
+
}
|
|
44
|
+
watch(() => route.fullPath, () => { menuOpen.value = false })
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<div class="page t-shell">
|
|
49
|
+
<aside :class="['navbar navbar-vertical navbar-expand-lg', { 'navbar-folded': folded }]" data-bs-theme="dark">
|
|
50
|
+
<div class="container-fluid">
|
|
51
|
+
<button type="button" class="navbar-toggler" :aria-expanded="menuOpen" aria-label="Menu" @click="menuOpen = !menuOpen">
|
|
52
|
+
<span class="navbar-toggler-icon" />
|
|
53
|
+
</button>
|
|
54
|
+
<div class="navbar-brand">
|
|
55
|
+
<slot name="brand" :folded="folded">
|
|
56
|
+
<RouterLink :to="brandTo" class="d-flex align-items-center gap-2 text-reset text-decoration-none">
|
|
57
|
+
<img v-if="logo" :src="logo" alt="" class="navbar-brand-image" width="32" height="32">
|
|
58
|
+
<span v-if="!folded && brand" class="text-start lh-sm">
|
|
59
|
+
<span class="d-block fw-bold">{{ brand }}</span>
|
|
60
|
+
<span v-if="tagline" class="d-block text-secondary text-uppercase fw-medium" style="font-size: 0.625rem; letter-spacing: 0.18em">{{ tagline }}</span>
|
|
61
|
+
</span>
|
|
62
|
+
</RouterLink>
|
|
63
|
+
</slot>
|
|
64
|
+
</div>
|
|
65
|
+
<button v-if="foldable" type="button" class="t-fold-toggle d-none d-lg-grid"
|
|
66
|
+
:aria-label="folded ? 'Expand the menu' : 'Fold the menu'" @click="toggle">
|
|
67
|
+
<TIcon :name="folded ? 'chevron-right' : 'chevron-left'" />
|
|
68
|
+
</button>
|
|
69
|
+
<div :class="['collapse navbar-collapse', { show: menuOpen }]">
|
|
70
|
+
<TNav :items="nav" :folded="folded" class="pt-lg-3" />
|
|
71
|
+
<div v-if="footerNav || $slots['sidebar-footer']" class="navbar-footer">
|
|
72
|
+
<TNav v-if="footerNav" :items="footerNav" :folded="folded" />
|
|
73
|
+
<slot name="sidebar-footer" :folded="folded" />
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</aside>
|
|
78
|
+
<div class="page-wrapper">
|
|
79
|
+
<slot />
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</template>
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
<script setup lang="ts" generic="T extends object">
|
|
2
|
-
// A tree whose items can be dragged into a new order, and into or out of each other, with
|
|
3
|
-
// SortableJS: a menu of pages and sub-pages, say. v-model is the top level; each item keeps its
|
|
4
|
-
// children in `childrenKey` ("children"). The `item` slot draws an item's row (it gets the item,
|
|
5
|
-
// its depth from 1, and its parent). `maxDepth` limits how deep the tree goes (2: items and their
|
|
6
|
-
// children); a drop that would go deeper is refused. With `handle`, rows drag only by an element
|
|
7
|
-
// with the `sortable-handle` class. `move` reports each move. SortableJS loads on first use.
|
|
8
|
-
import { provide, ref, useId } from 'vue'
|
|
9
|
-
import TSortableTreeList from './TSortableTreeList.vue'
|
|
10
|
-
import { treeKey, type TreeContext } from './sortableTree'
|
|
11
|
-
|
|
12
|
-
const props = withDefaults(defineProps<{
|
|
13
|
-
itemKey: string | ((item: T) => string | number)
|
|
14
|
-
childrenKey?: string
|
|
15
|
-
maxDepth?: number
|
|
16
|
-
handle?: boolean
|
|
17
|
-
disabled?: boolean
|
|
18
|
-
}>(), { childrenKey: 'children', maxDepth: 2 })
|
|
19
|
-
|
|
20
|
-
const model = defineModel<T[]>({ default: () => [] })
|
|
21
|
-
const emit = defineEmits<{ move: [move: { item: T; from: { parent: T | null; index: number }; to: { parent: T | null; index: number } }] }>()
|
|
22
|
-
const slots = defineSlots<{ item?(scope: { item: T; depth: number; parent: T | null }): unknown }>()
|
|
23
|
-
const dragging = ref(false)
|
|
24
|
-
|
|
25
|
-
const keyOf = (item: T) => String(typeof props.itemKey === 'function' ? props.itemKey(item) : (item as Record<string, unknown>)[props.itemKey])
|
|
26
|
-
const childrenOf = (item: T): T[] => ((item as Record<string, unknown>)[props.childrenKey] as T[] | undefined) ?? []
|
|
27
|
-
|
|
28
|
-
function find(key: string, items: T[] = model.value): T | null {
|
|
29
|
-
for (const item of items) {
|
|
30
|
-
if (keyOf(item) === key) return item
|
|
31
|
-
const found = find(key, childrenOf(item))
|
|
32
|
-
if (found) return found
|
|
33
|
-
}
|
|
34
|
-
return null
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// The list a parent's children are in, made when it has none yet.
|
|
38
|
-
function listOf(parent: T | null): T[] {
|
|
39
|
-
if (!parent) return model.value
|
|
40
|
-
const record = parent as Record<string, unknown>
|
|
41
|
-
if (!Array.isArray(record[props.childrenKey])) record[props.childrenKey] = []
|
|
42
|
-
return record[props.childrenKey] as T[]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function move(fromKey: string, oldIndex: number, toKey: string, newIndex: number) {
|
|
46
|
-
const from = fromKey ? find(fromKey) : null
|
|
47
|
-
const to = toKey ? find(toKey) : null
|
|
48
|
-
const [item] = listOf(from).splice(oldIndex, 1)
|
|
49
|
-
if (!item) return
|
|
50
|
-
listOf(to).splice(newIndex, 0, item)
|
|
51
|
-
model.value = [...model.value]
|
|
52
|
-
emit('move', { item, from: { parent: from, index: oldIndex }, to: { parent: to, index: newIndex } })
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const context: TreeContext<T> = {
|
|
56
|
-
group: useId(),
|
|
57
|
-
get handle() { return props.handle },
|
|
58
|
-
get disabled() { return props.disabled },
|
|
59
|
-
get maxDepth() { return props.maxDepth },
|
|
60
|
-
dragging,
|
|
61
|
-
keyOf,
|
|
62
|
-
childrenOf,
|
|
63
|
-
move,
|
|
64
|
-
render: scope => slots.item?.(scope as { item: T; depth: number; parent: T | null }) as ReturnType<TreeContext<T>['render']>
|
|
65
|
-
}
|
|
66
|
-
provide(treeKey, context as unknown as TreeContext<object>)
|
|
67
|
-
</script>
|
|
68
|
-
|
|
69
|
-
<template>
|
|
70
|
-
<div :class="['t-tree', { 't-tree-dragging': dragging, 't-sortable-handles': handle }]">
|
|
71
|
-
<TSortableTreeList :items="model" :parent="null" :depth="1" />
|
|
72
|
-
</div>
|
|
73
|
-
</template>
|
|
1
|
+
<script setup lang="ts" generic="T extends object">
|
|
2
|
+
// A tree whose items can be dragged into a new order, and into or out of each other, with
|
|
3
|
+
// SortableJS: a menu of pages and sub-pages, say. v-model is the top level; each item keeps its
|
|
4
|
+
// children in `childrenKey` ("children"). The `item` slot draws an item's row (it gets the item,
|
|
5
|
+
// its depth from 1, and its parent). `maxDepth` limits how deep the tree goes (2: items and their
|
|
6
|
+
// children); a drop that would go deeper is refused. With `handle`, rows drag only by an element
|
|
7
|
+
// with the `sortable-handle` class. `move` reports each move. SortableJS loads on first use.
|
|
8
|
+
import { provide, ref, useId } from 'vue'
|
|
9
|
+
import TSortableTreeList from './TSortableTreeList.vue'
|
|
10
|
+
import { treeKey, type TreeContext } from './sortableTree'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
itemKey: string | ((item: T) => string | number)
|
|
14
|
+
childrenKey?: string
|
|
15
|
+
maxDepth?: number
|
|
16
|
+
handle?: boolean
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
}>(), { childrenKey: 'children', maxDepth: 2 })
|
|
19
|
+
|
|
20
|
+
const model = defineModel<T[]>({ default: () => [] })
|
|
21
|
+
const emit = defineEmits<{ move: [move: { item: T; from: { parent: T | null; index: number }; to: { parent: T | null; index: number } }] }>()
|
|
22
|
+
const slots = defineSlots<{ item?(scope: { item: T; depth: number; parent: T | null }): unknown }>()
|
|
23
|
+
const dragging = ref(false)
|
|
24
|
+
|
|
25
|
+
const keyOf = (item: T) => String(typeof props.itemKey === 'function' ? props.itemKey(item) : (item as Record<string, unknown>)[props.itemKey])
|
|
26
|
+
const childrenOf = (item: T): T[] => ((item as Record<string, unknown>)[props.childrenKey] as T[] | undefined) ?? []
|
|
27
|
+
|
|
28
|
+
function find(key: string, items: T[] = model.value): T | null {
|
|
29
|
+
for (const item of items) {
|
|
30
|
+
if (keyOf(item) === key) return item
|
|
31
|
+
const found = find(key, childrenOf(item))
|
|
32
|
+
if (found) return found
|
|
33
|
+
}
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The list a parent's children are in, made when it has none yet.
|
|
38
|
+
function listOf(parent: T | null): T[] {
|
|
39
|
+
if (!parent) return model.value
|
|
40
|
+
const record = parent as Record<string, unknown>
|
|
41
|
+
if (!Array.isArray(record[props.childrenKey])) record[props.childrenKey] = []
|
|
42
|
+
return record[props.childrenKey] as T[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function move(fromKey: string, oldIndex: number, toKey: string, newIndex: number) {
|
|
46
|
+
const from = fromKey ? find(fromKey) : null
|
|
47
|
+
const to = toKey ? find(toKey) : null
|
|
48
|
+
const [item] = listOf(from).splice(oldIndex, 1)
|
|
49
|
+
if (!item) return
|
|
50
|
+
listOf(to).splice(newIndex, 0, item)
|
|
51
|
+
model.value = [...model.value]
|
|
52
|
+
emit('move', { item, from: { parent: from, index: oldIndex }, to: { parent: to, index: newIndex } })
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const context: TreeContext<T> = {
|
|
56
|
+
group: useId(),
|
|
57
|
+
get handle() { return props.handle },
|
|
58
|
+
get disabled() { return props.disabled },
|
|
59
|
+
get maxDepth() { return props.maxDepth },
|
|
60
|
+
dragging,
|
|
61
|
+
keyOf,
|
|
62
|
+
childrenOf,
|
|
63
|
+
move,
|
|
64
|
+
render: scope => slots.item?.(scope as { item: T; depth: number; parent: T | null }) as ReturnType<TreeContext<T>['render']>
|
|
65
|
+
}
|
|
66
|
+
provide(treeKey, context as unknown as TreeContext<object>)
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<div :class="['t-tree', { 't-tree-dragging': dragging, 't-sortable-handles': handle }]">
|
|
71
|
+
<TSortableTreeList :items="model" :parent="null" :depth="1" />
|
|
72
|
+
</div>
|
|
73
|
+
</template>
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
// One level of a TSortableTree: its items, each with a list for its children under it (empty
|
|
3
|
-
// ones open up while something is dragged, to drop into). Not used on its own.
|
|
4
|
-
import { inject, onBeforeUnmount, onMounted, ref, watch, type FunctionalComponent } from 'vue'
|
|
5
|
-
import type Sortable from 'sortablejs'
|
|
6
|
-
import { treeKey, type TreeItemScope } from './sortableTree'
|
|
7
|
-
|
|
8
|
-
defineOptions({ name: 'TSortableTreeList' })
|
|
9
|
-
|
|
10
|
-
const props = defineProps<{ items: object[]; parent: object | null; depth: number }>()
|
|
11
|
-
const tree = inject(treeKey)!
|
|
12
|
-
|
|
13
|
-
const list = ref<HTMLElement>()
|
|
14
|
-
let sortable: Sortable | null = null
|
|
15
|
-
|
|
16
|
-
// An item's height: 1, plus its deepest child's.
|
|
17
|
-
const heightOf = (item: object): number => 1 + Math.max(0, ...tree.childrenOf(item).map(heightOf))
|
|
18
|
-
|
|
19
|
-
const Row: FunctionalComponent<TreeItemScope<object>> = scope => tree.render(scope)
|
|
20
|
-
|
|
21
|
-
onMounted(async () => {
|
|
22
|
-
const SortableClass = (await import('sortablejs')).default
|
|
23
|
-
if (!list.value) return
|
|
24
|
-
sortable = new SortableClass(list.value, {
|
|
25
|
-
group: tree.group,
|
|
26
|
-
animation: 150,
|
|
27
|
-
draggable: '.t-tree-node',
|
|
28
|
-
handle: tree.handle ? '.sortable-handle' : undefined,
|
|
29
|
-
disabled: tree.disabled,
|
|
30
|
-
// SortableJS's own dragging (not the browser's): the same in every browser and on touch screens.
|
|
31
|
-
forceFallback: true,
|
|
32
|
-
fallbackOnBody: true,
|
|
33
|
-
swapThreshold: 0.65,
|
|
34
|
-
onStart: () => { tree.dragging.value = true },
|
|
35
|
-
// A drop may not take the item's deepest child past the tree's depth.
|
|
36
|
-
onMove: event => Number(event.to.dataset.depth) - 1 + Number(event.dragged.dataset.height) <= tree.maxDepth,
|
|
37
|
-
onEnd: ({ oldIndex, newIndex, item, from, to }) => {
|
|
38
|
-
tree.dragging.value = false
|
|
39
|
-
if (oldIndex == null || newIndex == null || (from === to && oldIndex === newIndex)) return
|
|
40
|
-
// SortableJS moved the element; put it back and let Vue move it, so the lists stay right.
|
|
41
|
-
to.removeChild(item)
|
|
42
|
-
from.insertBefore(item, from.children[oldIndex] ?? null)
|
|
43
|
-
tree.move(from.dataset.parent ?? '', oldIndex, to.dataset.parent ?? '', newIndex)
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
watch(() => tree.disabled, disabled => sortable?.option('disabled', !!disabled))
|
|
49
|
-
onBeforeUnmount(() => sortable?.destroy())
|
|
50
|
-
</script>
|
|
51
|
-
|
|
52
|
-
<template>
|
|
53
|
-
<div ref="list" :class="['t-tree-list', { 't-tree-children': depth > 1, 't-tree-empty': !items.length }]"
|
|
54
|
-
:data-parent="parent ? tree.keyOf(parent) : ''" :data-depth="depth">
|
|
55
|
-
<div v-for="item in items" :key="tree.keyOf(item)" class="t-tree-node" :data-height="heightOf(item)">
|
|
56
|
-
<Row :item="item" :depth="depth" :parent="parent" />
|
|
57
|
-
<TSortableTreeList v-if="depth < tree.maxDepth" :items="tree.childrenOf(item)" :parent="item" :depth="depth + 1" />
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// One level of a TSortableTree: its items, each with a list for its children under it (empty
|
|
3
|
+
// ones open up while something is dragged, to drop into). Not used on its own.
|
|
4
|
+
import { inject, onBeforeUnmount, onMounted, ref, watch, type FunctionalComponent } from 'vue'
|
|
5
|
+
import type Sortable from 'sortablejs'
|
|
6
|
+
import { treeKey, type TreeItemScope } from './sortableTree'
|
|
7
|
+
|
|
8
|
+
defineOptions({ name: 'TSortableTreeList' })
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{ items: object[]; parent: object | null; depth: number }>()
|
|
11
|
+
const tree = inject(treeKey)!
|
|
12
|
+
|
|
13
|
+
const list = ref<HTMLElement>()
|
|
14
|
+
let sortable: Sortable | null = null
|
|
15
|
+
|
|
16
|
+
// An item's height: 1, plus its deepest child's.
|
|
17
|
+
const heightOf = (item: object): number => 1 + Math.max(0, ...tree.childrenOf(item).map(heightOf))
|
|
18
|
+
|
|
19
|
+
const Row: FunctionalComponent<TreeItemScope<object>> = scope => tree.render(scope)
|
|
20
|
+
|
|
21
|
+
onMounted(async () => {
|
|
22
|
+
const SortableClass = (await import('sortablejs')).default
|
|
23
|
+
if (!list.value) return
|
|
24
|
+
sortable = new SortableClass(list.value, {
|
|
25
|
+
group: tree.group,
|
|
26
|
+
animation: 150,
|
|
27
|
+
draggable: '.t-tree-node',
|
|
28
|
+
handle: tree.handle ? '.sortable-handle' : undefined,
|
|
29
|
+
disabled: tree.disabled,
|
|
30
|
+
// SortableJS's own dragging (not the browser's): the same in every browser and on touch screens.
|
|
31
|
+
forceFallback: true,
|
|
32
|
+
fallbackOnBody: true,
|
|
33
|
+
swapThreshold: 0.65,
|
|
34
|
+
onStart: () => { tree.dragging.value = true },
|
|
35
|
+
// A drop may not take the item's deepest child past the tree's depth.
|
|
36
|
+
onMove: event => Number(event.to.dataset.depth) - 1 + Number(event.dragged.dataset.height) <= tree.maxDepth,
|
|
37
|
+
onEnd: ({ oldIndex, newIndex, item, from, to }) => {
|
|
38
|
+
tree.dragging.value = false
|
|
39
|
+
if (oldIndex == null || newIndex == null || (from === to && oldIndex === newIndex)) return
|
|
40
|
+
// SortableJS moved the element; put it back and let Vue move it, so the lists stay right.
|
|
41
|
+
to.removeChild(item)
|
|
42
|
+
from.insertBefore(item, from.children[oldIndex] ?? null)
|
|
43
|
+
tree.move(from.dataset.parent ?? '', oldIndex, to.dataset.parent ?? '', newIndex)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
watch(() => tree.disabled, disabled => sortable?.option('disabled', !!disabled))
|
|
49
|
+
onBeforeUnmount(() => sortable?.destroy())
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<div ref="list" :class="['t-tree-list', { 't-tree-children': depth > 1, 't-tree-empty': !items.length }]"
|
|
54
|
+
:data-parent="parent ? tree.keyOf(parent) : ''" :data-depth="depth">
|
|
55
|
+
<div v-for="item in items" :key="tree.keyOf(item)" class="t-tree-node" :data-height="heightOf(item)">
|
|
56
|
+
<Row :item="item" :depth="depth" :parent="parent" />
|
|
57
|
+
<TSortableTreeList v-if="depth < tree.maxDepth" :items="tree.childrenOf(item)" :parent="item" :depth="depth + 1" />
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</template>
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
// A tiny chart in a line of text or a stat card: Tabler's sparkline (an inline SVG, no library), as
|
|
3
|
-
// a line, bars, or a circle for one percentage. It takes the text color, so a color names it.
|
|
4
|
-
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
5
|
-
import { Sparkline } from '@tabler/core'
|
|
6
|
-
import { toTabler, type Color } from '../types'
|
|
7
|
-
|
|
8
|
-
const props = withDefaults(defineProps<{
|
|
9
|
-
values: number[]
|
|
10
|
-
type?: 'line' | 'bar' | 'circle'
|
|
11
|
-
color?: Color
|
|
12
|
-
width?: number
|
|
13
|
-
height?: number
|
|
14
|
-
// Mark the last, highest or lowest value with a dot.
|
|
15
|
-
spot?: 'none' | 'last' | 'max' | 'min'
|
|
16
|
-
label?: string
|
|
17
|
-
}>(), { type: 'line', color: 'primary', width: 64, height: 24, spot: 'none' })
|
|
18
|
-
|
|
19
|
-
const el = ref<HTMLElement>()
|
|
20
|
-
let sparkline: InstanceType<typeof Sparkline> | null = null
|
|
21
|
-
|
|
22
|
-
onMounted(() => {
|
|
23
|
-
sparkline = new Sparkline(el.value!, {
|
|
24
|
-
type: props.type, values: props.values, width: props.width, height: props.height,
|
|
25
|
-
spot: props.spot, fill: props.type === 'line' ? 'auto' : 'none', animation: 0, label: false
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
watch(() => props.values, values => sparkline?.update(values), { deep: true })
|
|
29
|
-
onBeforeUnmount(() => sparkline?.dispose())
|
|
30
|
-
</script>
|
|
31
|
-
|
|
32
|
-
<template>
|
|
33
|
-
<span ref="el" :class="['sparkline', `text-${toTabler(color)}`]" role="img" :aria-label="label ?? `Trend: ${values.join(', ')}`" />
|
|
34
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A tiny chart in a line of text or a stat card: Tabler's sparkline (an inline SVG, no library), as
|
|
3
|
+
// a line, bars, or a circle for one percentage. It takes the text color, so a color names it.
|
|
4
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
5
|
+
import { Sparkline } from '@tabler/core'
|
|
6
|
+
import { toTabler, type Color } from '../types'
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(defineProps<{
|
|
9
|
+
values: number[]
|
|
10
|
+
type?: 'line' | 'bar' | 'circle'
|
|
11
|
+
color?: Color
|
|
12
|
+
width?: number
|
|
13
|
+
height?: number
|
|
14
|
+
// Mark the last, highest or lowest value with a dot.
|
|
15
|
+
spot?: 'none' | 'last' | 'max' | 'min'
|
|
16
|
+
label?: string
|
|
17
|
+
}>(), { type: 'line', color: 'primary', width: 64, height: 24, spot: 'none' })
|
|
18
|
+
|
|
19
|
+
const el = ref<HTMLElement>()
|
|
20
|
+
let sparkline: InstanceType<typeof Sparkline> | null = null
|
|
21
|
+
|
|
22
|
+
onMounted(() => {
|
|
23
|
+
sparkline = new Sparkline(el.value!, {
|
|
24
|
+
type: props.type, values: props.values, width: props.width, height: props.height,
|
|
25
|
+
spot: props.spot, fill: props.type === 'line' ? 'auto' : 'none', animation: 0, label: false
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
watch(() => props.values, values => sparkline?.update(values), { deep: true })
|
|
29
|
+
onBeforeUnmount(() => sparkline?.dispose())
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<template>
|
|
33
|
+
<span ref="el" :class="['sparkline', `text-${toTabler(color)}`]" role="img" :aria-label="label ?? `Trend: ${values.join(', ')}`" />
|
|
34
|
+
</template>
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
// A figure on an overview page: label, value, a line under it, and an icon in a tinted square. A
|
|
3
|
-
// `trend` (the change, in percent) shows beside the value, green when it's good: up, unless
|
|
4
|
-
// `trendGood` is 'down' (costs, errors). `sparkline` draws the recent values under it.
|
|
5
|
-
import { computed } from 'vue'
|
|
6
|
-
import TIcon from './TIcon.vue'
|
|
7
|
-
import TSparkline from './TSparkline.vue'
|
|
8
|
-
import { toTabler, type Color } from '../types'
|
|
9
|
-
|
|
10
|
-
const props = withDefaults(defineProps<{
|
|
11
|
-
label: string
|
|
12
|
-
value: string | number
|
|
13
|
-
detail?: string
|
|
14
|
-
icon?: string
|
|
15
|
-
color?: Color
|
|
16
|
-
trend?: number | null
|
|
17
|
-
trendLabel?: string
|
|
18
|
-
trendGood?: 'up' | 'down'
|
|
19
|
-
sparkline?: number[]
|
|
20
|
-
sparklineType?: 'line' | 'bar'
|
|
21
|
-
}>(), { color: 'primary', trendGood: 'up', sparklineType: 'line' })
|
|
22
|
-
|
|
23
|
-
const trendText = computed(() => props.trend == null ? '' : `${Math.abs(Math.round(props.trend * 10) / 10)}%`)
|
|
24
|
-
const trendClass = computed(() => {
|
|
25
|
-
if (props.trend == null || props.trend === 0) return 'text-secondary'
|
|
26
|
-
return (props.trend > 0) === (props.trendGood === 'up') ? 'text-success' : 'text-danger'
|
|
27
|
-
})
|
|
28
|
-
const trendIcon = computed(() => !props.trend ? 'minus' : props.trend > 0 ? 'trending-up' : 'trending-down')
|
|
29
|
-
</script>
|
|
30
|
-
|
|
31
|
-
<template>
|
|
32
|
-
<div class="card">
|
|
33
|
-
<div class="card-body">
|
|
34
|
-
<div class="d-flex align-items-start justify-content-between gap-3">
|
|
35
|
-
<div class="min-w-0">
|
|
36
|
-
<div class="subheader">{{ label }}</div>
|
|
37
|
-
<div class="d-flex align-items-baseline gap-2 mt-2">
|
|
38
|
-
<div class="h1 mb-0">{{ value }}</div>
|
|
39
|
-
<span v-if="trend != null" :class="['d-inline-flex align-items-center gap-1 lh-1 small fw-medium', trendClass]"
|
|
40
|
-
:title="trendLabel">
|
|
41
|
-
{{ trendText }}<TIcon :name="trendIcon" />
|
|
42
|
-
</span>
|
|
43
|
-
</div>
|
|
44
|
-
<div v-if="detail || trendLabel || $slots.detail" class="text-secondary small mt-1">
|
|
45
|
-
<slot name="detail">{{ detail ?? trendLabel }}</slot>
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
<div v-if="icon" :class="['t-stat-icon', `bg-${toTabler(color)}-lt`]">
|
|
49
|
-
<TIcon :name="icon" />
|
|
50
|
-
</div>
|
|
51
|
-
</div>
|
|
52
|
-
<TSparkline v-if="sparkline?.length" :values="sparkline" :type="sparklineType" :color="color" :width="240" :height="36"
|
|
53
|
-
class="t-stat-sparkline mt-3" :label="`${label}: recent values`" />
|
|
54
|
-
</div>
|
|
55
|
-
</div>
|
|
56
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A figure on an overview page: label, value, a line under it, and an icon in a tinted square. A
|
|
3
|
+
// `trend` (the change, in percent) shows beside the value, green when it's good: up, unless
|
|
4
|
+
// `trendGood` is 'down' (costs, errors). `sparkline` draws the recent values under it.
|
|
5
|
+
import { computed } from 'vue'
|
|
6
|
+
import TIcon from './TIcon.vue'
|
|
7
|
+
import TSparkline from './TSparkline.vue'
|
|
8
|
+
import { toTabler, type Color } from '../types'
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
|
+
label: string
|
|
12
|
+
value: string | number
|
|
13
|
+
detail?: string
|
|
14
|
+
icon?: string
|
|
15
|
+
color?: Color
|
|
16
|
+
trend?: number | null
|
|
17
|
+
trendLabel?: string
|
|
18
|
+
trendGood?: 'up' | 'down'
|
|
19
|
+
sparkline?: number[]
|
|
20
|
+
sparklineType?: 'line' | 'bar'
|
|
21
|
+
}>(), { color: 'primary', trendGood: 'up', sparklineType: 'line' })
|
|
22
|
+
|
|
23
|
+
const trendText = computed(() => props.trend == null ? '' : `${Math.abs(Math.round(props.trend * 10) / 10)}%`)
|
|
24
|
+
const trendClass = computed(() => {
|
|
25
|
+
if (props.trend == null || props.trend === 0) return 'text-secondary'
|
|
26
|
+
return (props.trend > 0) === (props.trendGood === 'up') ? 'text-success' : 'text-danger'
|
|
27
|
+
})
|
|
28
|
+
const trendIcon = computed(() => !props.trend ? 'minus' : props.trend > 0 ? 'trending-up' : 'trending-down')
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<template>
|
|
32
|
+
<div class="card">
|
|
33
|
+
<div class="card-body">
|
|
34
|
+
<div class="d-flex align-items-start justify-content-between gap-3">
|
|
35
|
+
<div class="min-w-0">
|
|
36
|
+
<div class="subheader">{{ label }}</div>
|
|
37
|
+
<div class="d-flex align-items-baseline gap-2 mt-2">
|
|
38
|
+
<div class="h1 mb-0">{{ value }}</div>
|
|
39
|
+
<span v-if="trend != null" :class="['d-inline-flex align-items-center gap-1 lh-1 small fw-medium', trendClass]"
|
|
40
|
+
:title="trendLabel">
|
|
41
|
+
{{ trendText }}<TIcon :name="trendIcon" />
|
|
42
|
+
</span>
|
|
43
|
+
</div>
|
|
44
|
+
<div v-if="detail || trendLabel || $slots.detail" class="text-secondary small mt-1">
|
|
45
|
+
<slot name="detail">{{ detail ?? trendLabel }}</slot>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
<div v-if="icon" :class="['t-stat-icon', `bg-${toTabler(color)}-lt`]">
|
|
49
|
+
<TIcon :name="icon" />
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
<TSparkline v-if="sparkline?.length" :values="sparkline" :type="sparklineType" :color="color" :width="240" :height="36"
|
|
53
|
+
class="t-stat-sparkline mt-3" :label="`${label}: recent values`" />
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</template>
|