@stacksjs/components 0.2.921 → 0.2.923

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ import type { DefineComponent } from '@stacksjs/stx';
2
+ declare const __dtsx_component__: __DtsxStxComponentType;
3
+ export declare const nativeHost: unknown;
4
+ export declare const defaultLabel: unknown;
5
+ export declare const className: unknown;
6
+ export declare const testID: unknown;
7
+ export declare const initialActions: unknown;
8
+ export declare const initialDisabled: ReturnType<typeof $bool>;
9
+ declare const actions: unknown;
10
+ declare const actionsLabel: unknown;
11
+ declare const disabled: unknown;
12
+ declare type __DtsxStxComponentType = DefineComponent<{ actionsLabel?: string, className?: unknown, class?: string, testID?: string, actions?: unknown[], disabled?: unknown }> & { readonly __stxEmits?: ["action"] }
13
+ export default __dtsx_component__;
@@ -1,3 +1,4 @@
1
+ export type { SwipeRowAction, SwipeRowProps } from './swipe-row';
1
2
  /** A bounded scrolling collection. Keep keyed data rows as direct children. */
2
3
  export declare interface ListProps {
3
4
  className?: string
@@ -11,3 +12,4 @@ export declare interface ListProps {
11
12
  contentContainerStyle?: Record<string, number>
12
13
  }
13
14
  export { default as List } from './List';
15
+ export { default as SwipeRow } from './SwipeRow';
@@ -0,0 +1,16 @@
1
+ export declare function openSwipeRow(dismiss: () => void): void;
2
+ export declare function closeSwipeRow(dismiss: () => void): void;
3
+ export declare interface SwipeRowAction {
4
+ id: string
5
+ label: string
6
+ destructive?: boolean
7
+ accessibilityLabel?: string
8
+ testID?: string
9
+ }
10
+ export declare interface SwipeRowProps {
11
+ actions: SwipeRowAction[]
12
+ actionsLabel?: string
13
+ className?: string
14
+ disabled?: boolean
15
+ testID?: string
16
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/components",
3
3
  "type": "module",
4
- "version": "0.2.921",
4
+ "version": "0.2.923",
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",
@@ -139,8 +139,8 @@
139
139
  "dependencies": {
140
140
  "@iconify-json/f7": "^1.2.2",
141
141
  "@stacksjs/ts-css": "^0.3.11",
142
- "@stacksjs/stx": "0.2.921",
143
- "bun-plugin-stx": "0.2.921",
142
+ "@stacksjs/stx": "0.2.923",
143
+ "bun-plugin-stx": "0.2.923",
144
144
  "ts-syntax-highlighter": "^0.2.20",
145
145
  "ts-video-player": "^0.1.11"
146
146
  },
@@ -50,7 +50,7 @@ effect(() => {
50
50
  if (element && (changedThread || newMessage && (nearBottom || last.sender_id === selfId()))) {
51
51
  nextTick(() => { element.scrollTop = element.scrollHeight })
52
52
  }
53
- if (changedThread && id) nextTick(() => composer()?.focus())
53
+ if (changedThread && id) nextTick(() => composer()?.focus({ preventScroll: true }))
54
54
  lastThread = id
55
55
  lastMessage = last?.id || 0
56
56
  })
@@ -58,6 +58,12 @@ const hasSelection = derived(() => !!selected())
58
58
  const noSelection = derived(() => !selected() && !compact)
59
59
  const emptyRows = derived(() => !loading() && rows().length === 0)
60
60
  const emptyThread = derived(() => hasSelection() && !threadLoading() && messages().length === 0)
61
+ const messageRows = derived(() => messages().map((message, index, thread) => {
62
+ const next = thread[index + 1]
63
+ const gap = next && Number(new Date(next.created_at)) - Number(new Date(message.created_at))
64
+ const end = !next || message.sender_id !== next.sender_id || !(gap >= 0 && gap < 300_000)
65
+ return { message, end, mine: message.sender_id === selfId() }
66
+ }))
61
67
  const selectedName = derived(() => selected()?.name || '')
62
68
  const selectedRole = derived(() => selected()?.role || '')
63
69
  const selectedAvatar = derived(() => selected()?.avatar || '')
@@ -71,7 +77,7 @@ watch(() => active() && visibility() === 'visible' ? chat.scopeKey() : null, (sc
71
77
  if (scope !== null) void chat.refresh(true)
72
78
  }, { immediate: true })
73
79
  </script>
74
- <section aria-label="Messages" data-compact="{{ compact }}" class="stx-chat-inbox flex flex-col {{ sizeClasses }} max-h-[900px] overflow-hidden bg-panel border border-line rounded-2xl {{ className }}">
80
+ <section aria-label="Messages" data-compact="{{ compact }}" class="stx-chat-inbox flex flex-col {{ sizeClasses }} max-h-[900px] overflow-hidden bg-panel rounded-2xl {{ className }}">
75
81
  <div :if="error" role="alert" class="flex gap-3 items-center justify-between px-4 py-3 text-sm text-rose-800 dark:text-rose-200 bg-danger-soft">
76
82
  <span :text="error"></span><button type="button" @click="chat.refresh(true)" class="font-semibold underline">Try again</button>
77
83
  </div>
@@ -84,7 +90,7 @@ watch(() => active() && visibility() === 'visible' ? chat.scopeKey() : null, (sc
84
90
  </div>
85
91
  <p :if="loading" role="status" class="px-5 pb-2 text-xs text-fg-muted">Updating messages...</p>
86
92
  <div class="flex-1 overflow-y-auto px-2 pb-2">
87
- <button :for="person in rows" type="button" @click="chat.open(person)" :aria-pressed="selected && selected.id === person.id" :class="selected && selected.id === person.id ? 'bg-accent-soft' : 'hover:bg-panel-hover'" class="flex gap-3 items-start w-full p-3 text-left rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent">
93
+ <button :for="person in rows" :key="person.id" type="button" @click="chat.open(person)" :data-chat-contact="person.id" :aria-pressed="selected && selected.id === person.id" :class="selected && selected.id === person.id ? 'bg-accent-soft' : 'hover:bg-panel-hover'" class="flex gap-3 items-start w-full p-3 text-left rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent">
88
94
  <Avatar :src="person.avatar || ''" :alt="person.name" size="md" className="shrink-0" />
89
95
  <span class="flex-1 min-w-0"><span class="flex items-center justify-between gap-2"><span class="font-semibold text-sm text-fg-strong truncate" :text="person.name"></span><span :if="person.conversation && person.conversation.unread" class="px-1.5 min-w-5 text-center text-xs font-semibold text-accent-ink bg-accent-solid rounded-full" :text="person.conversation.unread"></span></span><span class="block mt-0.5 text-xs text-fg-muted" :text="person.role"></span><span class="block mt-1 text-sm text-fg truncate" :text="person.conversation && person.conversation.last_message ? person.conversation.last_message.body : 'Start a conversation'"></span></span>
90
96
  </button>
@@ -94,20 +100,22 @@ watch(() => active() && visibility() === 'visible' ? chat.scopeKey() : null, (sc
94
100
  <div :if="noSelection" class="stx-chat-empty hidden flex-1 flex-col items-center justify-center px-8 text-center bg-surface/50">
95
101
  <span class="i-lucide-messages-square text-3xl text-accent" aria-hidden="true"></span><h2 class="mt-4 text-lg font-semibold text-fg-strong">A place for the conversation</h2><p class="mt-2 max-w-xs text-sm leading-6 text-fg-muted">Training questions, session feedback, or a quick check-in. Choose someone from your inbox to get started.</p>
96
102
  </div>
97
- <div :if="hasSelection" class="flex flex-1 flex-col min-w-0">
103
+ <div :if="hasSelection" data-chat-thread class="flex flex-1 flex-col min-w-0">
98
104
  <header class="flex items-center gap-3 px-4 py-4 border-b border-line">
99
105
  <button type="button" @click="chat.back()" aria-label="Back to inbox" class="stx-chat-back {{ backButtonClass }} p-2 rounded-lg hover:bg-surface-hover"><span class="i-lucide-arrow-left" aria-hidden="true"></span></button><StxLink :if="selectedHref" :to="selectedHref" className="stx-chat-person flex flex-1 gap-3 items-center min-w-0 rounded-lg hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"><Avatar :src="selectedAvatar" :alt="selectedName" size="md" className="shrink-0" /><div class="min-w-0"><h2 class="font-semibold text-fg-strong truncate" :text="selectedName"></h2><p class="mt-0.5 text-xs text-fg-muted" :text="selectedRole"></p></div></StxLink><div :if="!selectedHref" class="stx-chat-person flex flex-1 gap-3 items-center min-w-0"><Avatar :src="selectedAvatar" :alt="selectedName" size="md" className="shrink-0" /><div class="min-w-0"><h2 class="font-semibold text-fg-strong truncate" :text="selectedName"></h2><p class="mt-0.5 text-xs text-fg-muted" :text="selectedRole"></p></div></div><button type="button" @click="chat.refresh(true)" aria-label="Refresh conversation" class="p-2 text-fg-muted rounded-lg hover:bg-surface-hover"><span class="i-lucide-refresh-cw" aria-hidden="true"></span></button>
100
106
  </header>
101
- <div ref="chat-history" role="log" aria-label="Conversation history" aria-live="polite" aria-relevant="additions" :aria-busy="threadLoading" class="flex flex-col flex-1 min-h-0 overflow-y-auto px-4 py-5 gap-4">
107
+ <div ref="chat-history" role="log" aria-label="Conversation history" aria-live="polite" aria-relevant="additions" :aria-busy="threadLoading" class="flex flex-col flex-1 min-h-0 overflow-y-auto px-4 py-5">
102
108
  <button :if="hasMore" type="button" @click="chat.older()" :disabled="threadLoading" class="self-center text-sm text-accent-soft-ink font-medium underline">Load earlier messages</button>
103
109
  <p :if="threadLoading" role="status" class="text-center text-sm text-fg-muted">Loading conversation...</p>
104
110
  <div :if="emptyThread" class="my-auto text-center"><p class="font-semibold text-fg-strong">Start with a question or a check-in</p><p class="mt-2 text-sm text-fg-muted">Messages stay here so you can pick up where you left off.</p></div>
105
- <article :for="message in messages" :class="message.sender_id === selfId ? 'items-end' : 'items-start'" class="flex flex-col gap-1.5">
106
- <p :class="message.sender_id === selfId ? 'bg-accent-solid text-accent-ink' : 'bg-surface-sunken text-fg-strong'" class="stx-chat-message max-w-[88%] whitespace-pre-wrap break-words px-4 py-3 rounded-2xl text-sm leading-6" :text="message.body"></p><span class="text-[11px] text-fg-muted"><time :datetime="message.created_at" :text="timestamp(message.created_at)"></time><span :if="message.sender_id === selfId" :text="message.read_at ? ' · Read' : ' · Sent'"></span></span>
111
+ <article :for="row in messageRows" :key="row.message.id" :data-chat-message="row.message.id" :class="(row.mine ? 'items-end' : 'items-start') + (row.end ? ' mb-3' : ' mb-0.5')" class="flex flex-col gap-1">
112
+ <p :class="(row.mine ? 'bg-accent-solid text-accent-ink' : 'bg-surface-sunken text-fg-strong') + (row.end ? (row.mine ? ' rounded-br-md' : ' rounded-bl-md') : '')" class="stx-chat-message max-w-[88%] whitespace-pre-wrap break-words px-3.5 py-2 rounded-[18px] text-sm leading-5" :text="row.message.body"></p>
113
+ <span :class="row.end ? '' : 'sr-only'" class="px-1 text-[11px] text-fg-muted"><time :datetime="row.message.created_at" :text="timestamp(row.message.created_at)"></time><span :if="row.mine" :text="row.message.read_at ? ' · Read' : ' · Sent'"></span></span>
107
114
  </article>
108
115
  </div>
109
- <form @submit.prevent="submit()" class="px-4 pt-3 pb-4 border-t border-line">
110
- <label class="block"><span class="sr-only">Write a message</span><textarea ref="chat-composer" x-model="draft" @keydown="keyboard($event)" :maxlength="maxLength" :disabled="sending" rows="3" placeholder="Write a message..." class="w-full resize-none px-3 py-2 text-sm leading-6 text-fg-strong placeholder:text-fg-soft bg-field border border-line rounded-xl focus:outline-none focus:ring-2 focus:ring-accent"></textarea></label><div class="flex items-center justify-between gap-3 mt-2"><span class="stx-chat-shortcut hidden text-xs text-fg-muted">Ctrl or ⌘ + Enter to send</span><button type="submit" :disabled="!canSend" class="shrink-0 ml-auto inline-flex gap-2 items-center px-4 py-2.5 text-sm font-semibold text-accent-ink bg-accent-solid hover:bg-accent-solid-hover disabled:opacity-50 disabled:cursor-not-allowed rounded-lg focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-panel"><span :text="sendLabel">Send message</span><span class="i-lucide-send" aria-hidden="true"></span></button></div>
116
+ <form @submit.prevent="submit()" class="m-3 flex items-end gap-2 p-1.5 rounded-3xl bg-field focus-within:ring-2 focus-within:ring-accent">
117
+ <label class="flex-1 min-w-0"><span class="sr-only">Write a message</span><textarea ref="chat-composer" x-model="draft" @keydown="keyboard($event)" :maxlength="maxLength" :disabled="sending" rows="1" placeholder="Write a message…" class="stx-chat-composer block w-full resize-none px-2.5 py-2 text-sm leading-6 text-fg-strong placeholder:text-fg-soft bg-transparent focus:outline-none"></textarea></label>
118
+ <button type="submit" :aria-label="sendLabel" :disabled="!canSend" class="flex shrink-0 items-center justify-center h-10 w-10 text-accent-ink bg-accent-solid hover:bg-accent-solid-hover disabled:opacity-50 disabled:cursor-not-allowed rounded-full focus-visible:ring-2 focus-visible:ring-accent"><span class="h-5 w-5 i-lucide-arrow-up" aria-hidden="true"></span></button>
111
119
  </form>
112
120
  </div>
113
121
  </div>
@@ -115,11 +123,17 @@ watch(() => active() && visibility() === 'visible' ? chat.scopeKey() : null, (sc
115
123
 
116
124
  <style>
117
125
  .stx-chat-inbox { container: stx-chat / inline-size; }
126
+ .stx-chat-composer { field-sizing: content; max-height: 7rem; }
127
+ @media (width < 768px) {
128
+ .stx-chat-inbox[data-compact="false"]:has([data-chat-thread]) {
129
+ height: max(340px, calc(100dvh - 210px));
130
+ min-height: 0;
131
+ }
132
+ }
118
133
  @container stx-chat (min-width: 48rem) {
119
134
  .stx-chat-inbox[data-compact="false"] .stx-chat-sidebar { display: flex; width: 20rem; }
120
135
  .stx-chat-inbox[data-compact="false"] .stx-chat-back { display: none; }
121
136
  .stx-chat-inbox[data-compact="false"] .stx-chat-empty { display: flex; }
122
137
  .stx-chat-inbox[data-compact="false"] .stx-chat-message { max-width: 75%; }
123
- .stx-chat-inbox[data-compact="false"] .stx-chat-shortcut { display: inline; }
124
138
  }
125
139
  </style>
@@ -0,0 +1,78 @@
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>
@@ -15,3 +15,6 @@ export interface ListProps {
15
15
  /** Content padding shared by browsers and native hosts. */
16
16
  contentContainerStyle?: Record<string, number>
17
17
  }
18
+
19
+ export { default as SwipeRow } from './SwipeRow.stx'
20
+ export type { SwipeRowAction, SwipeRowProps } from './swipe-row'
@@ -0,0 +1,29 @@
1
+ export interface SwipeRowAction {
2
+ id: string
3
+ label: string
4
+ destructive?: boolean
5
+ accessibilityLabel?: string
6
+ testID?: string
7
+ }
8
+
9
+ export interface SwipeRowProps {
10
+ actions: SwipeRowAction[]
11
+ actionsLabel?: string
12
+ className?: string
13
+ disabled?: boolean
14
+ testID?: string
15
+ }
16
+
17
+ // Native screens have separate script contexts. One open row per context also
18
+ // keeps browser lists from leaving several action trays open at the same time.
19
+ let dismissOpenRow: (() => void) | undefined
20
+
21
+ export function openSwipeRow(dismiss: () => void): void {
22
+ if (dismissOpenRow === dismiss) return
23
+ dismissOpenRow?.()
24
+ dismissOpenRow = dismiss
25
+ }
26
+
27
+ export function closeSwipeRow(dismiss: () => void): void {
28
+ if (dismissOpenRow === dismiss) dismissOpenRow = undefined
29
+ }