@stacksjs/components 0.2.958 → 0.2.960

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.
@@ -19,6 +19,8 @@ export declare const minDate: unknown;
19
19
  export declare const maxDate: unknown;
20
20
  export declare const disabledDates: unknown;
21
21
  export declare const locale: unknown;
22
+ export declare const previousMonthLabel: unknown;
23
+ export declare const nextMonthLabel: unknown;
22
24
  export declare const firstDayOfWeek: unknown;
23
25
  export declare const showToday: unknown;
24
26
  export declare const className: unknown;
@@ -63,5 +65,5 @@ declare const currentMonth: unknown;
63
65
  declare const selectedDate: ReturnType<typeof state>;
64
66
  declare const rangeStart: ReturnType<typeof state>;
65
67
  declare const rangeEnd: ReturnType<typeof state>;
66
- declare type __DtsxStxComponentType = DefineComponent<{ value?: unknown, mode?: unknown, start?: unknown, end?: unknown, minDate?: unknown, maxDate?: unknown, disabledDates?: unknown[], locale?: string, firstDayOfWeek?: unknown, showToday?: unknown, className?: string, highlightToday?: unknown }> & { readonly __stxExposed?: { selectedDate: typeof selectedDate, currentMonth: typeof currentMonth, selectDate: typeof selectDate, rangeStart: typeof rangeStart, rangeEnd: typeof rangeEnd } }
68
+ declare type __DtsxStxComponentType = DefineComponent<{ value?: unknown, mode?: unknown, start?: unknown, end?: unknown, minDate?: unknown, maxDate?: unknown, disabledDates?: unknown[], locale?: string, previousMonthLabel?: string, nextMonthLabel?: string, firstDayOfWeek?: unknown, showToday?: unknown, className?: string, highlightToday?: unknown }> & { readonly __stxExposed?: { selectedDate: typeof selectedDate, currentMonth: typeof currentMonth, selectDate: typeof selectDate, rangeStart: typeof rangeStart, rangeEnd: typeof rangeEnd } }
67
69
  export default __dtsx_component__;
@@ -5,6 +5,8 @@ export declare interface CalendarProps {
5
5
  maxDate?: Date | string | null
6
6
  disabledDates?: Date[]
7
7
  locale?: string
8
+ previousMonthLabel?: string
9
+ nextMonthLabel?: string
8
10
  firstDayOfWeek?: number
9
11
  showToday?: boolean
10
12
  highlightToday?: boolean
@@ -1,5 +1,15 @@
1
1
  export declare function openSwipeRow(dismiss: () => void): void;
2
2
  export declare function closeSwipeRow(dismiss: () => void): void;
3
+ /** A drag past the ends gives a third of the extra distance, as UIKit's rubber band does. */
4
+ export declare function swipeOffset(position: number, reveal: number): number;
5
+ /**
6
+ * Whether a drag that ends at `position` (0 closed, -reveal open) with
7
+ * `velocity` (points per millisecond, negative leftward) settles open: past
8
+ * half of the reveal, or flung either way.
9
+ */
10
+ export declare function swipeSettlesOpen(position: number, reveal: number, velocity?: number): boolean;
11
+ /** Movement before a drag decides whether it is a swipe (horizontal) or a scroll. */
12
+ export declare const SWIPE_SLOP: 8;
3
13
  export declare interface SwipeRowAction {
4
14
  id: string
5
15
  label: string
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/components",
3
3
  "type": "module",
4
- "version": "0.2.958",
4
+ "version": "0.2.960",
5
5
  "description": "A modern component library built with STX, featuring headwind utility classes and TypeScript syntax highlighting.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -144,8 +144,8 @@
144
144
  "dependencies": {
145
145
  "@iconify-json/f7": "^1.2.2",
146
146
  "@stacksjs/ts-css": "^0.3.11",
147
- "@stacksjs/stx": "0.2.958",
148
- "bun-plugin-stx": "0.2.958",
147
+ "@stacksjs/stx": "0.2.960",
148
+ "bun-plugin-stx": "0.2.960",
149
149
  "ts-syntax-highlighter": "^0.2.20",
150
150
  "ts-video-player": "^0.1.11"
151
151
  },
@@ -17,6 +17,8 @@ export const minDate = $props.minDate || null
17
17
  export const maxDate = $props.maxDate || null
18
18
  export const disabledDates = $props.disabledDates || []
19
19
  export const locale = $props.locale || 'en-US'
20
+ export const previousMonthLabel = $props.previousMonthLabel || 'Previous month'
21
+ export const nextMonthLabel = $props.nextMonthLabel || 'Next month'
20
22
  export const firstDayOfWeek = $num($props.firstDayOfWeek) || 0
21
23
  export const showToday = $bool($props.showToday, true)
22
24
  export const className = $props.className || ''
@@ -45,6 +47,8 @@ export const disabledIsoList = disabledDates.map(d => new Date(d).toISOString())
45
47
  <script client>
46
48
  const emit = defineEmits()
47
49
  const locale = useReactiveProp('locale', {{ locale }})
50
+ const previousLabel = useReactiveProp('previousMonthLabel', {{ previousMonthLabel }})
51
+ const nextLabel = useReactiveProp('nextMonthLabel', {{ nextMonthLabel }})
48
52
  const firstDayOfWeek = {{ firstDayOfWeek }}
49
53
  const highlightToday = {{ highlightToday }}
50
54
  /*
@@ -284,7 +288,8 @@ defineExpose({ selectedDate, currentMonth, selectDate, rangeStart, rangeEnd })
284
288
  type="button"
285
289
  class="{{ buttonClasses }}"
286
290
  @click="previousMonth()"
287
- aria-label="Previous month"
291
+ :aria-label="previousLabel()"
292
+ aria-label="{{ previousMonthLabel }}"
288
293
  >
289
294
  <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
290
295
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
@@ -297,7 +302,8 @@ defineExpose({ selectedDate, currentMonth, selectDate, rangeStart, rangeEnd })
297
302
  type="button"
298
303
  class="{{ buttonClasses }}"
299
304
  @click="nextMonthFn()"
300
- aria-label="Next month"
305
+ :aria-label="nextLabel()"
306
+ aria-label="{{ nextMonthLabel }}"
301
307
  >
302
308
  <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
303
309
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
@@ -90,6 +90,8 @@ let selectedDate = new Date()
90
90
  <Calendar
91
91
  value={selectedDate}
92
92
  locale="es-ES"
93
+ previousMonthLabel="Mes anterior"
94
+ nextMonthLabel="Mes siguiente"
93
95
  firstDayOfWeek={1}
94
96
  onChange={(date) => selectedDate = date}
95
97
  />
@@ -7,6 +7,8 @@ export interface CalendarProps {
7
7
  maxDate?: Date | string | null
8
8
  disabledDates?: Date[]
9
9
  locale?: string
10
+ previousMonthLabel?: string
11
+ nextMonthLabel?: string
10
12
  firstDayOfWeek?: number // 0 = Sunday, 1 = Monday, etc.
11
13
  showToday?: boolean
12
14
  highlightToday?: boolean
@@ -8,17 +8,31 @@ export const initialDisabled = $bool($props.disabled)
8
8
  </script>
9
9
 
10
10
  <script client>
11
- import { closeSwipeRow, openSwipeRow } from './swipe-row'
11
+ import { closeSwipeRow, openSwipeRow, SWIPE_SLOP, swipeOffset, swipeSettlesOpen } from './swipe-row'
12
12
 
13
13
  const emit = defineEmits(['action'])
14
14
  const nativeHost = {{ nativeHost }}
15
+ // A host that pans the row with the finger and animates it (Craft's
16
+ // capabilities.interactiveSwipe): it owns the content's translation, and says
17
+ // where a swipe came to rest. Without it the row jumps open on a finished swipe.
18
+ const interactive = nativeHost && typeof craft !== 'undefined' && !!craft && !!craft.capabilities && craft.capabilities.interactiveSwipe === true
15
19
  const actions = useReactiveProp('actions', {{ initialActions }})
16
20
  const actionsLabel = useReactiveProp('actionsLabel', {{ defaultLabel }})
17
21
  const disabled = useReactiveProp('disabled', {{ initialDisabled }})
18
22
  const testId = useReactiveProp('testID', {{ testID }})
19
23
  const opened = state(false)
20
24
  const actionWidth = 88
21
- const offset = derived(() => opened() ? actionWidth * actions().length : 0)
25
+ const reveal = derived(() => actionWidth * actions().length)
26
+ const offset = derived(() => opened() ? reveal() : 0)
27
+ // Where a finger is holding the row on a web page, or null when nothing is.
28
+ const dragged = state(null)
29
+ const reduceMotion = !nativeHost && typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
30
+ const webStyle = derived(() => {
31
+ const position = dragged() === null ? -offset() : dragged()
32
+ // pan-y: the browser keeps vertical scrolling and leaves the horizontal drag to us.
33
+ return { transform: 'translateX(' + position + 'px)', transition: dragged() !== null || reduceMotion ? 'none' : 'transform 250ms ease-out', touchAction: 'pan-y' }
34
+ })
35
+ const trayStyle = derived(() => nativeHost ? { right: -reveal(), width: reveal() } : { right: -reveal() + 'px', width: reveal() + 'px' })
22
36
 
23
37
  function close() {
24
38
  closeSwipeRow(close)
@@ -36,12 +50,53 @@ function swipe(direction) {
36
50
  else if (direction === 'right') close()
37
51
  }
38
52
 
53
+ // An interactive swipe the user made came to rest.
54
+ function settle(isOpen) {
55
+ if (isOpen) open()
56
+ else close()
57
+ }
58
+
39
59
  function activate(id) {
40
60
  if (disabled() || !actions().some(action => action.id === id)) return
41
61
  close()
42
62
  emit('action', id)
43
63
  }
44
64
 
65
+ // A finger dragging the row on a web page: it follows 1:1 once the drag is
66
+ // horizontal, and lets a vertical one scroll the page.
67
+ let drag = null
68
+ function dragStart(event) {
69
+ if (event.pointerType !== 'touch' || disabled() || !actions().length) return
70
+ drag = { x: event.clientX, y: event.clientY, from: -offset(), horizontal: null, at: event.timeStamp, last: event.clientX }
71
+ }
72
+ function dragMove(event) {
73
+ if (!drag) return
74
+ const dx = event.clientX - drag.x
75
+ if (drag.horizontal === null) {
76
+ const dy = event.clientY - drag.y
77
+ if (Math.abs(dx) < SWIPE_SLOP && Math.abs(dy) < SWIPE_SLOP) return
78
+ drag.horizontal = Math.abs(dx) > Math.abs(dy)
79
+ if (!drag.horizontal) {
80
+ drag = null
81
+ return
82
+ }
83
+ event.currentTarget.setPointerCapture?.(event.pointerId)
84
+ }
85
+ drag.velocity = (event.clientX - drag.last) / Math.max(1, event.timeStamp - drag.at)
86
+ drag.last = event.clientX
87
+ drag.at = event.timeStamp
88
+ dragged.set(swipeOffset(drag.from + dx, reveal()))
89
+ }
90
+ function dragEnd() {
91
+ const ended = drag
92
+ drag = null
93
+ if (!ended || dragged() === null) return
94
+ const position = dragged()
95
+ dragged.set(null)
96
+ if (swipeSettlesOpen(position, reveal(), ended.velocity || 0)) open()
97
+ else close()
98
+ }
99
+
45
100
  effect(() => {
46
101
  if (!actions().length || disabled()) close()
47
102
  })
@@ -49,30 +104,53 @@ onMount(() => close)
49
104
  </script>
50
105
 
51
106
  <div class="relative overflow-hidden {{ className }}" :testID="testId()"
52
- :swipeEnabled="nativeHost && !disabled() && actions().length > 0"
107
+ @if(nativeHost)
108
+ :swipeEnabled="!interactive && !disabled() && actions().length > 0"
53
109
  :swipeDirection="opened() ? 'right' : 'left'"
54
110
  @swipe="swipe($event.direction)"
55
- @if(!nativeHost)
111
+ @else
56
112
  @keydown.escape="opened() && close()"
57
113
  @endif
58
114
  >
59
- <div class="flex flex-row items-center"
60
- :style="nativeHost ? { transform: [{ translateX: -offset() }] } : { transform: 'translateX(' + -offset() + 'px)' }">
115
+ <div class="relative flex flex-row items-center"
116
+ @if(nativeHost)
117
+ :swipeReveal="interactive && !disabled() ? reveal() : 0"
118
+ :swipeOpen="opened()"
119
+ @swipe-settle="settle($event.open)"
120
+ :style="interactive ? {} : { transform: [{ translateX: -offset() }] }"
121
+ @else
122
+ :style="webStyle()"
123
+ @pointerdown="dragStart($event)"
124
+ @pointermove="dragMove($event)"
125
+ @pointerup="dragEnd()"
126
+ @pointercancel="dragEnd()"
127
+ @endif
128
+ >
61
129
  <div class="flex flex-1 flex-col min-w-0"><slot /></div>
62
130
  <button :if="actions().length" type="button" class="flex shrink-0 items-center justify-center h-11 w-11"
63
131
  :disabled="disabled()" :aria-label="actionsLabel()" :aria-expanded="opened() ? 'true' : 'false'"
64
132
  :testID="testId() && testId() + '-actions'" @click="opened() ? close() : open()">
65
133
  <i class="h-5 w-5 text-[#636366] dark:text-[#aeaeb2] i-lucide-more-horizontal" aria-hidden="true"></i>
66
134
  </button>
67
- </div>
68
- <div :if="opened()" class="flex absolute inset-y-0 right-0 flex-row">
69
- <button :for="item in actions()" :key="item.id" type="button"
70
- class="flex shrink-0 items-center justify-center px-1 min-h-11"
71
- :class="item.destructive ? 'bg-[#b4232b] dark:bg-[#b4232b]' : 'bg-[#245fa9] dark:bg-[#245fa9]'"
72
- :style="{ width: actionWidth + 'px' }" :disabled="disabled()"
73
- :accessibilityLabel="item.accessibilityLabel || item.label" :aria-label="item.accessibilityLabel || item.label"
74
- :testID="item.testID || (testId() && testId() + '-' + item.id)" @click="activate(item.id)">
75
- <span class="text-xs font-semibold text-center text-white" :text="item.label"></span>
76
- </button>
135
+ <!-- Just past the trailing edge, riding on the sliding content: the row
136
+ clips them while closed and the slide reveals them, so nothing pops
137
+ in. Hidden from assistive tech and from touch until open. -->
138
+ <div class="flex absolute inset-y-0 flex-row" :style="trayStyle()"
139
+ :aria-hidden="opened() ? 'false' : 'true'"
140
+ @if(nativeHost)
141
+ :pointerEvents="opened() ? 'auto' : 'none'"
142
+ @else
143
+ :class="opened() ? '' : 'pointer-events-none'"
144
+ @endif
145
+ >
146
+ <button :for="item in actions()" :key="item.id" type="button"
147
+ class="flex shrink-0 items-center justify-center px-1 min-h-11"
148
+ :class="item.destructive ? 'bg-[#b4232b] dark:bg-[#b4232b]' : 'bg-[#245fa9] dark:bg-[#245fa9]'"
149
+ :style="{ width: actionWidth + 'px' }" :disabled="disabled()" :tabindex="opened() ? 0 : -1"
150
+ :accessibilityLabel="item.accessibilityLabel || item.label" :aria-label="item.accessibilityLabel || item.label"
151
+ :testID="item.testID || (testId() && testId() + '-' + item.id)" @click="activate(item.id)">
152
+ <span class="text-xs font-semibold text-center text-white" :text="item.label"></span>
153
+ </button>
154
+ </div>
77
155
  </div>
78
156
  </div>
@@ -27,3 +27,24 @@ export function openSwipeRow(dismiss: () => void): void {
27
27
  export function closeSwipeRow(dismiss: () => void): void {
28
28
  if (dismissOpenRow === dismiss) dismissOpenRow = undefined
29
29
  }
30
+
31
+ /** Movement before a drag decides whether it is a swipe (horizontal) or a scroll. */
32
+ export const SWIPE_SLOP = 8
33
+
34
+ /** A drag past the ends gives a third of the extra distance, as UIKit's rubber band does. */
35
+ export function swipeOffset(position: number, reveal: number): number {
36
+ if (position > 0) return position / 3
37
+ if (position < -reveal) return -reveal + (position + reveal) / 3
38
+ return position
39
+ }
40
+
41
+ /**
42
+ * Whether a drag that ends at `position` (0 closed, -reveal open) with
43
+ * `velocity` (points per millisecond, negative leftward) settles open: past
44
+ * half of the reveal, or flung either way.
45
+ */
46
+ export function swipeSettlesOpen(position: number, reveal: number, velocity = 0): boolean {
47
+ if (velocity < -0.5) return true
48
+ if (velocity > 0.5) return false
49
+ return position < -reveal / 2
50
+ }
@@ -80,10 +80,12 @@ const isDisabled = useReactiveProp('disabled', {{ disabled }})
80
80
  const pressToToggle = useReactiveProp('pressToToggle', {{ pressToToggle }})
81
81
  // Reactive prop binding — parent can drive `show` via signals. See #1704.
82
82
  const isVisible = useReactiveProp('show', {{ show }})
83
- let timeoutId = null
84
- let pointerExitTimeout = null
85
83
  let positionGeneration = 0
86
84
  let destroyed = false
85
+ const showAfterDelay = useDebounce(() => {
86
+ if (!destroyed && !isDisabled() && !pressToToggle()) isVisible.set(true)
87
+ }, delay)
88
+ const hideAfterExit = useDebounce(hideTooltip, 160)
87
89
 
88
90
  // Use the actual offset parent, so a tooltip inside a modal or a transformed
89
91
  // container still gets viewport bounds rather than assuming document origin.
@@ -117,31 +119,20 @@ function showTooltip() {
117
119
  if (isDisabled() || pressToToggle()) return
118
120
  cancelPointerExit()
119
121
  if (isVisible()) return
120
- if (timeoutId) clearTimeout(timeoutId)
121
- if (delay > 0) {
122
- timeoutId = setTimeout(() => {
123
- timeoutId = null
124
- if (!destroyed && !isDisabled() && !pressToToggle()) isVisible.set(true)
125
- }, delay)
126
- }
127
- else {
128
- isVisible.set(true)
129
- }
122
+ if (delay > 0) showAfterDelay()
123
+ else isVisible.set(true)
130
124
  }
131
125
 
132
126
  function cancelPointerExit() {
133
- if (pointerExitTimeout === null) return
134
- clearTimeout(pointerExitTimeout)
135
- pointerExitTimeout = null
127
+ hideAfterExit.cancel()
136
128
  }
137
129
 
138
130
  function leaveTooltip() {
139
131
  if (pressToToggle()) return
140
132
  if (!isVisible()) { hideTooltip(); return }
141
- cancelPointerExit()
142
133
  // A portaled panel has an eight-pixel gap from its trigger. Let a pointer
143
134
  // cross that gap without losing the text it was approaching to read.
144
- pointerExitTimeout = setTimeout(hideTooltip, 160)
135
+ hideAfterExit()
145
136
  }
146
137
 
147
138
  function toggleTouch(event) {
@@ -159,10 +150,7 @@ function toggleTouch(event) {
159
150
  function hideTooltip() {
160
151
  ++positionGeneration
161
152
  cancelPointerExit()
162
- if (timeoutId) {
163
- clearTimeout(timeoutId)
164
- timeoutId = null
165
- }
153
+ showAfterDelay.cancel()
166
154
  isVisible.set(false)
167
155
  }
168
156
 
@@ -198,8 +186,6 @@ effect(() => {
198
186
  onDestroy(() => {
199
187
  destroyed = true
200
188
  ++positionGeneration
201
- cancelPointerExit()
202
- if (timeoutId) clearTimeout(timeoutId)
203
189
  if (stopPositioning) stopPositioning()
204
190
  window.stx.overlays.close(activeTooltipId)
205
191
  })
@@ -1,78 +0,0 @@
1
- <script server>
2
- export const nativeHost = $native
3
- export const defaultLabel = $props.actionsLabel || 'More actions'
4
- export const className = $props.className || $props.class || ''
5
- export const testID = $props.testID || ''
6
- export const initialActions = $props.actions || []
7
- export const initialDisabled = $bool($props.disabled)
8
- </script>
9
-
10
- <script client>
11
- import { closeSwipeRow, openSwipeRow } from './swipe-row'
12
-
13
- const emit = defineEmits(['action'])
14
- const nativeHost = {{ nativeHost }}
15
- const actions = useReactiveProp('actions', {{ initialActions }})
16
- const actionsLabel = useReactiveProp('actionsLabel', {{ defaultLabel }})
17
- const disabled = useReactiveProp('disabled', {{ initialDisabled }})
18
- const testId = useReactiveProp('testID', {{ testID }})
19
- const opened = state(false)
20
- const actionWidth = 88
21
- const offset = derived(() => opened() ? actionWidth * actions().length : 0)
22
-
23
- function close() {
24
- closeSwipeRow(close)
25
- opened.set(false)
26
- }
27
-
28
- function open() {
29
- if (disabled() || !actions().length) return
30
- openSwipeRow(close)
31
- opened.set(true)
32
- }
33
-
34
- function swipe(direction) {
35
- if (direction === 'left') open()
36
- else if (direction === 'right') close()
37
- }
38
-
39
- function activate(id) {
40
- if (disabled() || !actions().some(action => action.id === id)) return
41
- close()
42
- emit('action', id)
43
- }
44
-
45
- effect(() => {
46
- if (!actions().length || disabled()) close()
47
- })
48
- onMount(() => close)
49
- </script>
50
-
51
- <div class="relative overflow-hidden {{ className }}" :testID="testId()"
52
- :swipeEnabled="nativeHost && !disabled() && actions().length > 0"
53
- :swipeDirection="opened() ? 'right' : 'left'"
54
- @swipe="swipe($event.direction)"
55
- @if(!nativeHost)
56
- @keydown.escape="opened() && close()"
57
- @endif
58
- >
59
- <div class="flex flex-row items-center"
60
- :style="nativeHost ? { transform: [{ translateX: -offset() }] } : { transform: 'translateX(' + -offset() + 'px)' }">
61
- <div class="flex flex-1 flex-col min-w-0"><slot /></div>
62
- <button :if="actions().length" type="button" class="flex shrink-0 items-center justify-center h-11 w-11"
63
- :disabled="disabled()" :aria-label="actionsLabel()" :aria-expanded="opened() ? 'true' : 'false'"
64
- :testID="testId() && testId() + '-actions'" @click="opened() ? close() : open()">
65
- <i class="h-5 w-5 text-[#636366] dark:text-[#aeaeb2] i-lucide-more-horizontal" aria-hidden="true"></i>
66
- </button>
67
- </div>
68
- <div :if="opened()" class="flex absolute inset-y-0 right-0 flex-row">
69
- <button :for="item in actions()" :key="item.id" type="button"
70
- class="flex shrink-0 items-center justify-center px-1 min-h-11"
71
- :class="item.destructive ? 'bg-[#b4232b] dark:bg-[#b4232b]' : 'bg-[#245fa9] dark:bg-[#245fa9]'"
72
- :style="{ width: actionWidth + 'px' }" :disabled="disabled()"
73
- :accessibilityLabel="item.accessibilityLabel || item.label" :aria-label="item.accessibilityLabel || item.label"
74
- :testID="item.testID || (testId() && testId() + '-' + item.id)" @click="activate(item.id)">
75
- <span class="text-xs font-semibold text-center text-white" :text="item.label"></span>
76
- </button>
77
- </div>
78
- </div>