picocrank 1.31.1 → 1.33.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.
@@ -10,9 +10,27 @@
10
10
  @click.stop
11
11
  >
12
12
  <div class="popover-body">
13
- <h4 :id="titleId" ref="titleRef" class="popover-title">
14
- {{ popoverTitle }}
15
- </h4>
13
+ <div class="popover-title-row">
14
+ <h4 :id="titleId" ref="titleRef" class="popover-title">
15
+ {{ popoverTitle }}
16
+ </h4>
17
+ <button
18
+ v-if="canHide"
19
+ type="button"
20
+ class="neutral inline-icon popover-hide-column"
21
+ :aria-label="`Hide ${columnLabel || 'column'} column`"
22
+ title="Hide column"
23
+ @click="hideColumn"
24
+ >
25
+ <HugeiconsIcon
26
+ :icon="ViewOffIcon"
27
+ width="1em"
28
+ height="1em"
29
+ :strokeWidth="2.5"
30
+ aria-hidden="true"
31
+ />
32
+ </button>
33
+ </div>
16
34
 
17
35
  <div v-if="filterType === 'text'" class="filter-fields">
18
36
  <label>
@@ -148,7 +166,7 @@
148
166
  <script setup>
149
167
  import { computed, nextTick, onBeforeUnmount, ref, useId, watch } from 'vue'
150
168
  import { HugeiconsIcon } from '@hugeicons/vue'
151
- import { Delete02Icon } from '@hugeicons/core-free-icons'
169
+ import { Delete02Icon, ViewOffIcon } from '@hugeicons/core-free-icons'
152
170
  import CheckGroup from './CheckGroup.vue'
153
171
  import RadioGroup from './RadioGroup.vue'
154
172
  import {
@@ -186,9 +204,13 @@ const props = defineProps({
186
204
  type: Array,
187
205
  default: () => [],
188
206
  },
207
+ canHide: {
208
+ type: Boolean,
209
+ default: false,
210
+ },
189
211
  })
190
212
 
191
- const emit = defineEmits(['update:open', 'apply', 'clear', 'cancel'])
213
+ const emit = defineEmits(['update:open', 'apply', 'clear', 'cancel', 'hide'])
192
214
 
193
215
  const MIN_VISIBLE_OPTIONS = 3
194
216
  const MAX_VISIBLE_OPTIONS = 20
@@ -441,6 +463,14 @@ function cancel() {
441
463
  emit('cancel')
442
464
  }
443
465
 
466
+ function hideColumn() {
467
+ if (!props.canHide) {
468
+ return
469
+ }
470
+ emit('hide')
471
+ emit('update:open', false)
472
+ }
473
+
444
474
  function detachDocumentListeners() {
445
475
  document.removeEventListener('pointerdown', onDocumentPointerDown)
446
476
  document.removeEventListener('keydown', onDocumentKeyDown)
@@ -459,7 +489,9 @@ async function initializePopover() {
459
489
  updateCheckGroupScrollLimit()
460
490
  await nextTick()
461
491
  positionPopover()
462
- popoverRef.value?.querySelector('input, select, button')?.focus()
492
+ popoverRef.value?.querySelector(
493
+ '.filter-fields input, .filter-fields select, .filter-fields button, .popover-actions button',
494
+ )?.focus()
463
495
  attachDocumentListeners()
464
496
  }
465
497
 
@@ -511,10 +543,26 @@ onBeforeUnmount(() => {
511
543
  flex-direction: column;
512
544
  }
513
545
 
546
+ .popover-title-row {
547
+ display: flex;
548
+ align-items: flex-start;
549
+ justify-content: space-between;
550
+ gap: 0.5rem;
551
+ margin-bottom: 0.75rem;
552
+ flex-shrink: 0;
553
+ }
554
+
514
555
  .popover-title {
515
- margin: 0 0 0.75rem;
556
+ margin: 0;
516
557
  font-size: 0.95rem;
517
- flex-shrink: 0;
558
+ min-width: 0;
559
+ flex: 1 1 auto;
560
+ }
561
+
562
+ .popover-hide-column {
563
+ flex: 0 0 auto;
564
+ padding: 0.2em 0.45em;
565
+ line-height: 1;
518
566
  }
519
567
 
520
568
  .filter-fields {
@@ -0,0 +1,267 @@
1
+ <template>
2
+ <Teleport to="body">
3
+ <nav
4
+ v-if="open"
5
+ ref="menuRef"
6
+ class="menu context-menu table-row-context-menu"
7
+ role="menu"
8
+ tabindex="-1"
9
+ :style="style"
10
+ aria-label="Row actions"
11
+ @click.stop
12
+ @contextmenu.prevent
13
+ @keydown="onMenuKeyDown"
14
+ >
15
+ <ul class="noListStyle">
16
+ <li>
17
+ <div>
18
+ <ul>
19
+ <template v-for="(item, index) in items" :key="itemKey(item, index)">
20
+ <li
21
+ v-if="item.divider"
22
+ role="separator"
23
+ />
24
+ <li v-else>
25
+ <button
26
+ type="button"
27
+ role="menuitem"
28
+ :class="{
29
+ 'inline-icon': Boolean(item.icon),
30
+ bad: item.danger,
31
+ }"
32
+ :disabled="item.disabled"
33
+ @click="onSelect(item)"
34
+ >
35
+ <HugeiconsIcon
36
+ v-if="item.icon"
37
+ :icon="item.icon"
38
+ width="1em"
39
+ height="1em"
40
+ :strokeWidth="2.5"
41
+ aria-hidden="true"
42
+ />
43
+ <span>{{ itemLabel(item) }}</span>
44
+ </button>
45
+ </li>
46
+ </template>
47
+ </ul>
48
+ </div>
49
+ </li>
50
+ </ul>
51
+ </nav>
52
+ </Teleport>
53
+ </template>
54
+
55
+ <script setup>
56
+ import { nextTick, onBeforeUnmount, ref, watch } from 'vue'
57
+ import { HugeiconsIcon } from '@hugeicons/vue'
58
+
59
+ const props = defineProps({
60
+ open: {
61
+ type: Boolean,
62
+ default: false,
63
+ },
64
+ items: {
65
+ type: Array,
66
+ default: () => [],
67
+ },
68
+ clientX: {
69
+ type: Number,
70
+ default: 0,
71
+ },
72
+ clientY: {
73
+ type: Number,
74
+ default: 0,
75
+ },
76
+ targetCount: {
77
+ type: Number,
78
+ default: 1,
79
+ },
80
+ })
81
+
82
+ const emit = defineEmits(['update:open', 'select', 'cancel'])
83
+
84
+ const MENU_MARGIN_PX = 8
85
+ const menuRef = ref(null)
86
+ const style = ref({ top: '0px', left: '0px' })
87
+
88
+ function itemKey(item, index) {
89
+ if (item.divider) {
90
+ return `divider-${index}`
91
+ }
92
+ return item.id ?? item.label ?? index
93
+ }
94
+
95
+ function itemLabel(item) {
96
+ if (typeof item.label === 'function') {
97
+ return item.label({ count: props.targetCount })
98
+ }
99
+ const label = item.label ?? ''
100
+ if (props.targetCount > 1 && item.showCount !== false) {
101
+ return `${label} (${props.targetCount})`
102
+ }
103
+ return label
104
+ }
105
+
106
+ function positionMenu() {
107
+ const menu = menuRef.value
108
+ if (!menu) {
109
+ return
110
+ }
111
+
112
+ const rect = menu.getBoundingClientRect()
113
+ const margin = MENU_MARGIN_PX
114
+ let top = props.clientY
115
+ let left = props.clientX
116
+
117
+ if (left + rect.width > window.innerWidth - margin) {
118
+ left = window.innerWidth - rect.width - margin
119
+ }
120
+ if (top + rect.height > window.innerHeight - margin) {
121
+ top = window.innerHeight - rect.height - margin
122
+ }
123
+ if (left < margin) {
124
+ left = margin
125
+ }
126
+ if (top < margin) {
127
+ top = margin
128
+ }
129
+
130
+ style.value = {
131
+ top: `${top}px`,
132
+ left: `${left}px`,
133
+ }
134
+ }
135
+
136
+ function close() {
137
+ emit('update:open', false)
138
+ emit('cancel')
139
+ }
140
+
141
+ function onSelect(item) {
142
+ if (item.disabled) {
143
+ return
144
+ }
145
+ emit('select', item)
146
+ emit('update:open', false)
147
+ }
148
+
149
+ function enabledMenuItems() {
150
+ if (!menuRef.value) {
151
+ return []
152
+ }
153
+ return [...menuRef.value.querySelectorAll('[role="menuitem"]:not([disabled])')]
154
+ }
155
+
156
+ function onMenuKeyDown(event) {
157
+ const items = enabledMenuItems()
158
+ const active = document.activeElement
159
+ const currentIndex = items.indexOf(active)
160
+ const focusIsOnMenuShell = active === menuRef.value
161
+
162
+ if (event.key === 'Escape') {
163
+ event.preventDefault()
164
+ close()
165
+ return
166
+ }
167
+
168
+ if (event.key === 'ArrowDown') {
169
+ event.preventDefault()
170
+ const nextIndex = currentIndex < 0 ? 0 : (currentIndex + 1) % items.length
171
+ items[nextIndex]?.focus()
172
+ return
173
+ }
174
+
175
+ if (event.key === 'ArrowUp') {
176
+ event.preventDefault()
177
+ const nextIndex = currentIndex < 0
178
+ ? items.length - 1
179
+ : (currentIndex - 1 + items.length) % items.length
180
+ items[nextIndex]?.focus()
181
+ return
182
+ }
183
+
184
+ if (event.key === 'Home') {
185
+ event.preventDefault()
186
+ items[0]?.focus()
187
+ return
188
+ }
189
+
190
+ if (event.key === 'End') {
191
+ event.preventDefault()
192
+ items[items.length - 1]?.focus()
193
+ return
194
+ }
195
+
196
+ if (event.key !== 'Tab' || items.length === 0) {
197
+ return
198
+ }
199
+
200
+ // Tab through items; leave (and close) rather than jumping to the rest of the page.
201
+ if (event.shiftKey) {
202
+ if (focusIsOnMenuShell || currentIndex <= 0) {
203
+ event.preventDefault()
204
+ close()
205
+ }
206
+ return
207
+ }
208
+
209
+ if (currentIndex === items.length - 1) {
210
+ event.preventDefault()
211
+ close()
212
+ }
213
+ }
214
+
215
+ function onDocumentPointerDown(event) {
216
+ if (!props.open) {
217
+ return
218
+ }
219
+ if (menuRef.value?.contains(event.target)) {
220
+ return
221
+ }
222
+ close()
223
+ }
224
+
225
+ function onDocumentKeyDown(event) {
226
+ if (!props.open) {
227
+ return
228
+ }
229
+ if (event.key === 'Escape') {
230
+ close()
231
+ }
232
+ }
233
+
234
+ function attachListeners() {
235
+ window.addEventListener('pointerdown', onDocumentPointerDown, true)
236
+ window.addEventListener('keydown', onDocumentKeyDown)
237
+ }
238
+
239
+ function detachListeners() {
240
+ window.removeEventListener('pointerdown', onDocumentPointerDown, true)
241
+ window.removeEventListener('keydown', onDocumentKeyDown)
242
+ }
243
+
244
+ watch(
245
+ () => props.open,
246
+ async (isOpen) => {
247
+ detachListeners()
248
+ if (!isOpen) {
249
+ return
250
+ }
251
+ style.value = {
252
+ top: `${props.clientY}px`,
253
+ left: `${props.clientX}px`,
254
+ }
255
+ await nextTick()
256
+ positionMenu()
257
+ // Focus the menu shell so keyboard users can Tab/arrow into items,
258
+ // without visually selecting the first action on open.
259
+ menuRef.value?.focus({ preventScroll: true })
260
+ attachListeners()
261
+ },
262
+ )
263
+
264
+ onBeforeUnmount(() => {
265
+ detachListeners()
266
+ })
267
+ </script>
@@ -387,7 +387,7 @@ export function cloneColumnFilterEntries(value, header = null, rows = []) {
387
387
  return normalizeColumnFilterEntries(value, header, rows).map((entry) => ({ ...entry }))
388
388
  }
389
389
 
390
- export function sortRows(rows, sortBy, sortDir) {
390
+ export function sortRows(rows, sortBy, sortDir, comparator = null) {
391
391
  if (!sortBy) {
392
392
  return [...rows]
393
393
  }
@@ -399,6 +399,11 @@ export function sortRows(rows, sortBy, sortDir) {
399
399
  if (av === bv) return 0
400
400
  if (av === null || av === undefined) return 1
401
401
  if (bv === null || bv === undefined) return -1
402
+ if (typeof comparator === 'function') {
403
+ const result = Number(comparator(av, bv, a, b))
404
+ if (!Number.isFinite(result) || result === 0) return 0
405
+ return sortDir === 'asc' ? result : -result
406
+ }
402
407
  if (typeof av === 'string' && typeof bv === 'string') {
403
408
  return sortDir === 'asc' ? av.localeCompare(bv) : bv.localeCompare(av)
404
409
  }
@@ -112,6 +112,11 @@ export const navSectionHubs = {
112
112
  title: 'Dialog',
113
113
  options: { description: 'Modal dialogs and confirmations' },
114
114
  },
115
+ {
116
+ name: 'LoadingAreaExample',
117
+ title: 'Loading area',
118
+ options: { description: 'Async placeholder with spinner' },
119
+ },
115
120
  ],
116
121
  },
117
122
  NavPatternsHub: {
@@ -0,0 +1,175 @@
1
+ <template>
2
+ <Section
3
+ title="Loading area"
4
+ :icon="Loading03Icon"
5
+ subtitle="Placeholder for async regions — wrap content or use as a standalone status block."
6
+ >
7
+ <p>
8
+ Bind <code>:loading</code> around a default slot for the usual Vue pattern, or
9
+ render <code>&lt;LoadingArea /&gt;</code> on its own while data is pending.
10
+ The spinner uses Hugeicons <code>Loading03Icon</code> with a CSS rotation
11
+ (respects <code>prefers-reduced-motion</code>).
12
+ </p>
13
+ </Section>
14
+
15
+ <Section title="Wrap content" subtitle="Toggle loading to swap between placeholder and content">
16
+ <template #toolbar>
17
+ <button type="button" class="neutral" @click="contentLoading = !contentLoading">
18
+ {{ contentLoading ? 'Show content' : 'Show loading' }}
19
+ </button>
20
+ </template>
21
+
22
+ <LoadingArea :loading="contentLoading" message="Fetching table rows…" min-height="10rem">
23
+ <div class="demo-panel">
24
+ <p>Content is ready. This block is the default slot.</p>
25
+ <ul>
26
+ <li>Ada — London</li>
27
+ <li>Grace — New York</li>
28
+ <li>Katherine — Newport News</li>
29
+ </ul>
30
+ </div>
31
+ </LoadingArea>
32
+ </Section>
33
+
34
+ <Section title="Overlay mode" subtitle="Keep layout size while covering content">
35
+ <template #toolbar>
36
+ <button type="button" class="neutral" @click="runOverlayFetch">
37
+ {{ overlayLoading ? 'Loading…' : 'Simulate refresh' }}
38
+ </button>
39
+ </template>
40
+
41
+ <LoadingArea
42
+ :loading="overlayLoading"
43
+ overlay
44
+ message="Refreshing…"
45
+ min-height="8rem"
46
+ >
47
+ <div class="demo-panel">
48
+ <p>
49
+ With <code>overlay</code>, the default slot stays mounted so the area does
50
+ not collapse. Useful for refresh-in-place.
51
+ </p>
52
+ <p class="subtle">Last refreshed: {{ lastRefreshedLabel }}</p>
53
+ </div>
54
+ </LoadingArea>
55
+ </Section>
56
+
57
+ <Section title="Standalone placeholder" subtitle="No default slot — just the loading state">
58
+ <LoadingArea message="Connecting to server…" min-height="8rem" />
59
+ </Section>
60
+
61
+ <Section title="Custom placeholder slot" subtitle="Replace the spinner with your own markup">
62
+ <LoadingArea :loading="true" min-height="8rem">
63
+ <template #placeholder>
64
+ <p class="custom-placeholder">Preparing preview…</p>
65
+ </template>
66
+ </LoadingArea>
67
+ </Section>
68
+
69
+ <Section title="Idiomatic async example" subtitle="ref + async function with try/finally">
70
+ <template #toolbar>
71
+ <button type="button" class="good" :disabled="peopleLoading" @click="loadPeople">
72
+ {{ peopleLoading ? 'Loading…' : 'Load people' }}
73
+ </button>
74
+ <button type="button" class="neutral" :disabled="!people.length" @click="people = []">
75
+ Clear
76
+ </button>
77
+ </template>
78
+
79
+ <LoadingArea :loading="peopleLoading" message="Loading people…" min-height="10rem">
80
+ <div v-if="peopleError" class="demo-panel">
81
+ <p class="annotation bad">{{ peopleError }}</p>
82
+ </div>
83
+ <div v-else-if="people.length" class="demo-panel">
84
+ <ul>
85
+ <li v-for="person in people" :key="person.name">
86
+ {{ person.name }} — {{ person.city }}
87
+ </li>
88
+ </ul>
89
+ </div>
90
+ <p v-else class="subtle">No people loaded yet. Click “Load people”.</p>
91
+ </LoadingArea>
92
+ </Section>
93
+ </template>
94
+
95
+ <script setup>
96
+ import { computed, onBeforeUnmount, ref } from 'vue'
97
+ import { Loading03Icon } from '@hugeicons/core-free-icons'
98
+ import { getExampleTableRows } from '../data/examplePeople.js'
99
+
100
+ const contentLoading = ref(true)
101
+ const overlayLoading = ref(false)
102
+ const lastRefreshedAt = ref(Date.now())
103
+ const people = ref([])
104
+ const peopleLoading = ref(false)
105
+ const peopleError = ref('')
106
+
107
+ let overlayTimer = null
108
+ let peopleTimer = null
109
+
110
+ const lastRefreshedLabel = computed(() =>
111
+ new Date(lastRefreshedAt.value).toLocaleTimeString(),
112
+ )
113
+
114
+ function runOverlayFetch() {
115
+ if (overlayLoading.value) {
116
+ return
117
+ }
118
+ overlayLoading.value = true
119
+ clearTimeout(overlayTimer)
120
+ overlayTimer = setTimeout(() => {
121
+ lastRefreshedAt.value = Date.now()
122
+ overlayLoading.value = false
123
+ overlayTimer = null
124
+ }, 1500)
125
+ }
126
+
127
+ async function loadPeople() {
128
+ peopleLoading.value = true
129
+ peopleError.value = ''
130
+ try {
131
+ people.value = await fetchPeople()
132
+ } catch (error) {
133
+ peopleError.value = error?.message || 'Failed to load people.'
134
+ people.value = []
135
+ } finally {
136
+ peopleLoading.value = false
137
+ }
138
+ }
139
+
140
+ function fetchPeople() {
141
+ return new Promise((resolve, reject) => {
142
+ clearTimeout(peopleTimer)
143
+ peopleTimer = setTimeout(() => {
144
+ peopleTimer = null
145
+ if (Math.random() < 0.15) {
146
+ reject(new Error('Simulated network failure. Try again.'))
147
+ return
148
+ }
149
+ resolve(getExampleTableRows().slice(0, 5))
150
+ }, 1200)
151
+ })
152
+ }
153
+
154
+ onBeforeUnmount(() => {
155
+ clearTimeout(overlayTimer)
156
+ clearTimeout(peopleTimer)
157
+ })
158
+ </script>
159
+
160
+ <style scoped>
161
+ .demo-panel {
162
+ padding: 1rem;
163
+ }
164
+
165
+ .demo-panel ul {
166
+ margin: 0.5rem 0 0;
167
+ padding-left: 1.25rem;
168
+ }
169
+
170
+ .custom-placeholder {
171
+ margin: 0;
172
+ font-style: italic;
173
+ color: var(--muted-text-color);
174
+ }
175
+ </style>