@stacksjs/components 0.2.919 → 0.2.922

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,145 @@
1
+ // src/ui/render-surface/render-surface.ts
2
+ var RENDER_SURFACE_MAX_SIDE = 8192;
3
+ var root = globalThis;
4
+ function canvases() {
5
+ root.__stxRenderSurfaces ??= new Map;
6
+ return root.__stxRenderSurfaces;
7
+ }
8
+ function surfaceError(code, message) {
9
+ return Object.assign(new Error(message), { code });
10
+ }
11
+ function onNativeScreen() {
12
+ return Boolean(root.stx?._host?.isNative);
13
+ }
14
+ function renderSurfaceHost() {
15
+ if (onNativeScreen()) {
16
+ const present = root.craft?.renderSurface?.present;
17
+ return typeof present === "function" && root.craft?.capabilities?.renderSurface === true ? "native" : "none";
18
+ }
19
+ if (typeof document === "undefined")
20
+ return "none";
21
+ return "canvas";
22
+ }
23
+ function checkFrame(surface, pixels, width, height) {
24
+ if (typeof surface !== "string" || !surface)
25
+ throw new TypeError("presentFrame needs the surface's name");
26
+ if (!(pixels instanceof Uint32Array))
27
+ throw new TypeError("presentFrame takes a Uint32Array of 0xAARRGGBB words");
28
+ for (const [side, value] of [["width", width], ["height", height]]) {
29
+ if (!Number.isInteger(value) || value < 1 || value > RENDER_SURFACE_MAX_SIDE)
30
+ throw new TypeError(`presentFrame's ${side} must be a whole number from 1 to ${RENDER_SURFACE_MAX_SIDE}, not ${value}`);
31
+ }
32
+ if (pixels.length !== width * height)
33
+ throw new TypeError(`presentFrame was given ${pixels.length} words for a ${width} x ${height} frame (${width * height})`);
34
+ }
35
+ function presentFrame(surface, pixels, width, height) {
36
+ if (onNativeScreen()) {
37
+ const host = root.craft?.renderSurface;
38
+ if (!host || typeof host.present !== "function")
39
+ throw surfaceError("UNAVAILABLE", "This device cannot draw a RenderSurface");
40
+ return host.present(surface, pixels, width, height);
41
+ }
42
+ checkFrame(surface, pixels, width, height);
43
+ const target = canvases().get(surface);
44
+ if (!target)
45
+ throw surfaceError("NOT_FOUND", `No RenderSurface named "${surface}" is on the page`);
46
+ drawToCanvas(target, pixels, width, height);
47
+ return true;
48
+ }
49
+ function drawToCanvas(target, pixels, width, height) {
50
+ const { canvas, context, opaque } = target;
51
+ if (canvas.width !== width)
52
+ canvas.width = width;
53
+ if (canvas.height !== height)
54
+ canvas.height = height;
55
+ if (!target.image || target.image.width !== width || target.image.height !== height)
56
+ target.image = context.createImageData(width, height);
57
+ const bytes = target.image.data;
58
+ for (let i = 0, j = 0;i < pixels.length; i++, j += 4) {
59
+ const word = pixels[i];
60
+ let a = word >>> 24;
61
+ let r = word >>> 16 & 255;
62
+ let g = word >>> 8 & 255;
63
+ let b = word & 255;
64
+ if (opaque) {
65
+ a = 255;
66
+ } else if (a > 0 && a < 255) {
67
+ r = Math.min(255, Math.round(r * 255 / a));
68
+ g = Math.min(255, Math.round(g * 255 / a));
69
+ b = Math.min(255, Math.round(b * 255 / a));
70
+ }
71
+ bytes[j] = r;
72
+ bytes[j + 1] = g;
73
+ bytes[j + 2] = b;
74
+ bytes[j + 3] = a;
75
+ }
76
+ context.putImageData(target.image, 0, 0);
77
+ }
78
+ function claimCanvasSurface(surface, canvas, options = {}) {
79
+ if (canvases().has(surface))
80
+ return { error: { surface, code: "DUPLICATE", message: `Another RenderSurface named "${surface}" is already on the page` } };
81
+ let context = null;
82
+ try {
83
+ context = canvas.getContext("2d", { alpha: options.opaque === false });
84
+ } catch {
85
+ context = null;
86
+ }
87
+ if (!context)
88
+ return { error: { surface, code: "UNAVAILABLE", message: "This browser cannot draw a RenderSurface: it has no 2D canvas" } };
89
+ const entry = { canvas, context, opaque: options.opaque !== false, image: null };
90
+ canvases().set(surface, entry);
91
+ return {
92
+ release: () => {
93
+ if (canvases().get(surface) === entry)
94
+ canvases().delete(surface);
95
+ }
96
+ };
97
+ }
98
+ function startRenderLoop(surface, draw, options = {}) {
99
+ const frame = typeof requestAnimationFrame === "function" ? requestAnimationFrame : (callback) => setTimeout(() => callback(Date.now()), 16);
100
+ let ended = false;
101
+ let waiting = false;
102
+ const tick = (time) => {
103
+ if (ended)
104
+ return;
105
+ if (!waiting) {
106
+ try {
107
+ const next = draw(time);
108
+ if (next && !presentFrame(surface, next.pixels, next.width, next.height))
109
+ waiting = true;
110
+ } catch (error) {
111
+ ended = true;
112
+ if (error?.code === "NOT_FOUND")
113
+ return;
114
+ if (options.onError)
115
+ options.onError(error);
116
+ else
117
+ throw error;
118
+ return;
119
+ }
120
+ }
121
+ frame(tick);
122
+ };
123
+ frame(tick);
124
+ return {
125
+ stop: () => {
126
+ ended = true;
127
+ },
128
+ wake: () => {
129
+ waiting = false;
130
+ },
131
+ get waiting() {
132
+ return waiting;
133
+ },
134
+ get ended() {
135
+ return ended;
136
+ }
137
+ };
138
+ }
139
+ export {
140
+ RENDER_SURFACE_MAX_SIDE,
141
+ claimCanvasSurface,
142
+ presentFrame,
143
+ renderSurfaceHost,
144
+ startRenderLoop
145
+ };
@@ -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
+ }
@@ -0,0 +1,45 @@
1
+ import type { DefineComponent } from '@stacksjs/stx';
2
+ declare const __dtsx_component__: __DtsxStxComponentType;
3
+ /*
4
+ * <RenderSurface>: a box shared TypeScript draws into, frame by frame, with
5
+ * no WebView (stacksjs/stx#2108, craft-native/craft#578).
6
+ *
7
+ * <RenderSurface class="flex-1" filter="nearest"
8
+ * @ready="loop = startRenderLoop($event.surface, paint)"
9
+ * @restored="loop.wake()" @error="report($event)" />
10
+ *
11
+ * On a native screen it is the host's RenderSurface, drawn with Metal; in a
12
+ * browser it is a <canvas>. Frames go in through `presentFrame` or
13
+ * `startRenderLoop` from `@stacksjs/components/render-surface`, by the name
14
+ * `ready` carries.
15
+ *
16
+ * Props:
17
+ * - `surface`: the name frames are given to. Unique on the screen; when it is
18
+ * left out each instance gets its own. A second live surface of a name
19
+ * already taken stays blank and reports `DUPLICATE`.
20
+ * - `filter`: `nearest` (the default, for pixel art) or `linear`, used when a
21
+ * frame's size differs from the box's pixels.
22
+ * - `opaque`: true by default. A surface that is not opaque takes
23
+ * premultiplied alpha.
24
+ * - `label`: what a screen reader says for it.
25
+ * - `unavailableText`: what shows in its place where nothing can draw one.
26
+ *
27
+ * Events:
28
+ * - `ready` the first time it has a size, then `resize` on each change, both
29
+ * `{ surface, width, height, scale, pixelWidth, pixelHeight }`;
30
+ * - `lost` (`{ surface, reason }`) when the app goes to the background on a
31
+ * phone, and `restored` (the metrics again) when it returns: nothing is
32
+ * kept across a loss, so draw a whole frame again;
33
+ * - `error` with `{ surface, code, message }`: `UNAVAILABLE` where this device
34
+ * cannot draw one (the box then says so rather than staying blank), or
35
+ * `DUPLICATE`.
36
+ */
37
+ export declare const surface: unknown;
38
+ export declare const filter: boolean;
39
+ export declare const opaque: unknown;
40
+ export declare const className: unknown;
41
+ export declare const label: unknown;
42
+ export declare const unavailableText: unknown;
43
+ declare const unavailable: ReturnType<typeof state>;
44
+ declare type __DtsxStxComponentType = DefineComponent<{ surface?: string, filter?: unknown, opaque?: unknown, className?: unknown, class?: string, label?: string, unavailableText?: string }> & { readonly __stxEmits?: ["ready", "resize", "lost", "restored", "error"], readonly __stxExposed?: { surface: unknown, unavailable: typeof unavailable } }
45
+ export default __dtsx_component__;
@@ -0,0 +1,17 @@
1
+ export type { RenderFrame, RenderLoop, RenderSurfaceError, RenderSurfaceFilter, RenderSurfaceHost, RenderSurfaceMetrics } from './render-surface';
2
+ /** A box shared TypeScript draws into, frame by frame (stacksjs/stx#2108). */
3
+ export declare interface RenderSurfaceProps {
4
+ surface?: string
5
+ filter?: 'nearest' | 'linear'
6
+ opaque?: boolean
7
+ label?: string
8
+ unavailableText?: string
9
+ className?: string
10
+ onReady?: (detail: import('./render-surface').RenderSurfaceMetrics) => void
11
+ onResize?: (detail: import('./render-surface').RenderSurfaceMetrics) => void
12
+ onLost?: (detail: { surface: string, reason: string }) => void
13
+ onRestored?: (detail: import('./render-surface').RenderSurfaceMetrics) => void
14
+ onError?: (detail: import('./render-surface').RenderSurfaceError) => void
15
+ }
16
+ export { default as RenderSurface } from './RenderSurface';
17
+ export { presentFrame, RENDER_SURFACE_MAX_SIDE, renderSurfaceHost, startRenderLoop } from './render-surface';
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Where a frame would go on this page: `native` on a screen whose host has a
3
+ * Metal GPU, `canvas` in a browser, `none` on a native host without the
4
+ * capability. Read before mounting to decide whether to offer a surface.
5
+ */
6
+ export declare function renderSurfaceHost(): RenderSurfaceHost;
7
+ /**
8
+ * Draw one frame. True when the surface took it; false while it is not ready
9
+ * or is lost (wait for `ready` or `restored`, then draw a whole frame again:
10
+ * nothing is kept across a loss). Throws a TypeError for a wrong array or
11
+ * size, and an Error whose `code` is NOT_FOUND for a name no mounted surface
12
+ * holds (from its removal on) or UNAVAILABLE where nothing can draw one.
13
+ */
14
+ export declare function presentFrame(surface: string, pixels: Uint32Array, width: number, height: number): boolean;
15
+ /**
16
+ * The component's half in a browser: put a canvas under a name, or say why
17
+ * not. One live surface per name, as on a native screen: a second answers
18
+ * DUPLICATE and the first keeps drawing.
19
+ */
20
+ export declare function claimCanvasSurface(surface: string, canvas: HTMLCanvasElement, options?: { opaque?: boolean }): { release: () => void } | { error: RenderSurfaceError };
21
+ /**
22
+ * Draw on every display frame. `draw` returns the frame to show, or nothing
23
+ * to skip one. While the surface answers false (not ready yet, or lost) the
24
+ * loop draws nothing until `wake()`. Its surface being removed ends it
25
+ * quietly: that is how a loop learns its screen went. Any other error ends
26
+ * it and goes to `onError`, or is thrown when there is none.
27
+ */
28
+ export declare function startRenderLoop(surface: string, draw: (time: number) => RenderFrame | null | undefined | void, options?: { onError?: (error: unknown) => void }): RenderLoop;
29
+ /** The largest frame, in pixels a side, that a host takes. */
30
+ export declare const RENDER_SURFACE_MAX_SIDE: 8192;
31
+ /** What `ready`, `resize` and `restored` carry: the box in points, and in pixels. */
32
+ export declare interface RenderSurfaceMetrics {
33
+ surface: string
34
+ width: number
35
+ height: number
36
+ scale: number
37
+ pixelWidth: number
38
+ pixelHeight: number
39
+ }
40
+ /** What `error` carries. `UNAVAILABLE`: this device cannot draw one. `DUPLICATE`: the name is taken. */
41
+ export declare interface RenderSurfaceError {
42
+ surface: string
43
+ code: 'UNAVAILABLE' | 'DUPLICATE' | string
44
+ message: string
45
+ }
46
+ declare interface CanvasSurface {
47
+ canvas: HTMLCanvasElement
48
+ context: CanvasRenderingContext2D
49
+ opaque: boolean
50
+ image: ImageData | null
51
+ }
52
+ declare interface NativeRenderSurface {
53
+ present: (surface: string, pixels: Uint32Array, width: number, height: number) => boolean
54
+ }
55
+ export declare interface RenderFrame {
56
+ pixels: Uint32Array
57
+ width: number
58
+ height: number
59
+ }
60
+ export declare interface RenderLoop {
61
+ stop: () => void
62
+ wake: () => void
63
+ readonly waiting: boolean
64
+ readonly ended: boolean
65
+ }
66
+ /**
67
+ * Frames for a `<RenderSurface>`: a box shared TypeScript draws into, frame
68
+ * by frame, the same on a phone and in a browser (stacksjs/stx#2108).
69
+ *
70
+ * A frame is `width * height` 0xAARRGGBB words, row by row: what a CPU
71
+ * graphics core produces. On a native screen `presentFrame` hands them to the
72
+ * host's own `craft.renderSurface.present`, which copies them where the script
73
+ * runs and draws them with Metal (craft-native/craft#578). In a browser the
74
+ * component's `<canvas>` takes them. Either way the frame is scaled to the
75
+ * box, `nearest` or `linear`, so a game can draw below the display's
76
+ * resolution.
77
+ *
78
+ * import { startRenderLoop } from '@stacksjs/components/render-surface'
79
+ *
80
+ * <RenderSurface class="flex-1" @ready="loop = startRenderLoop($event.surface, paint)"
81
+ * @restored="loop.wake()" @error="report($event)" />
82
+ *
83
+ * This module never defines `craft.renderSurface`. The host installs it
84
+ * before the screen's script runs, and it is a function rather than a
85
+ * message: a frame sent as a message would be serialized on every frame.
86
+ */
87
+ export type RenderSurfaceFilter = 'nearest' | 'linear';
88
+ /** Where a frame goes: the host's surface, a canvas, or nowhere. */
89
+ export type RenderSurfaceHost = 'native' | 'canvas' | 'none';
90
+ declare type AnyGlobal = typeof globalThis & {
91
+ craft?: { renderSurface?: NativeRenderSurface, capabilities?: Record<string, boolean> }
92
+ stx?: { _host?: { isNative?: boolean } }
93
+ __stxRenderSurfaces?: Map<string, CanvasSurface>
94
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/components",
3
3
  "type": "module",
4
- "version": "0.2.919",
4
+ "version": "0.2.922",
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",
@@ -47,6 +47,11 @@
47
47
  "bun": "./stx-plugin.ts",
48
48
  "import": "./stx-plugin.ts"
49
49
  },
50
+ "./render-surface": {
51
+ "types": "./dist/ui/render-surface/render-surface.d.ts",
52
+ "bun": "./dist/render-surface/render-surface.js",
53
+ "import": "./dist/render-surface/render-surface.js"
54
+ },
50
55
  "./biometric": {
51
56
  "types": "./dist/ui/auth/biometric.d.ts",
52
57
  "bun": "./dist/biometric/biometric.js",
@@ -134,8 +139,8 @@
134
139
  "dependencies": {
135
140
  "@iconify-json/f7": "^1.2.2",
136
141
  "@stacksjs/ts-css": "^0.3.11",
137
- "@stacksjs/stx": "0.2.919",
138
- "bun-plugin-stx": "0.2.919",
142
+ "@stacksjs/stx": "0.2.922",
143
+ "bun-plugin-stx": "0.2.922",
139
144
  "ts-syntax-highlighter": "^0.2.20",
140
145
  "ts-video-player": "^0.1.11"
141
146
  },
package/src/index.ts CHANGED
@@ -60,6 +60,7 @@ export * from './ui/preview-frame'
60
60
  export * from './ui/progress'
61
61
  export * from './ui/radio'
62
62
  export * from './ui/radio-group'
63
+ export * from './ui/render-surface'
63
64
  export * from './ui/segmented-control'
64
65
  export * from './ui/select'
65
66
  export * from './ui/settings'
@@ -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,74 @@
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)" @keydown.escape="opened() && close()">
55
+ <div class="flex flex-row items-center"
56
+ :style="nativeHost ? { transform: [{ translateX: -offset() }] } : { transform: 'translateX(' + -offset() + 'px)' }">
57
+ <div class="flex flex-1 flex-col min-w-0"><slot /></div>
58
+ <button :if="actions().length" type="button" class="flex shrink-0 items-center justify-center h-11 w-11"
59
+ :disabled="disabled()" :aria-label="actionsLabel()" :aria-expanded="opened() ? 'true' : 'false'"
60
+ :testID="testId() && testId() + '-actions'" @click="opened() ? close() : open()">
61
+ <i class="h-5 w-5 text-[#636366] dark:text-[#aeaeb2] i-lucide-more-horizontal" aria-hidden="true"></i>
62
+ </button>
63
+ </div>
64
+ <div :if="opened()" class="flex absolute inset-y-0 right-0 flex-row">
65
+ <button :for="item in actions()" :key="item.id" type="button"
66
+ class="flex shrink-0 items-center justify-center px-1 min-h-11"
67
+ :class="item.destructive ? 'bg-[#b4232b] dark:bg-[#b4232b]' : 'bg-[#245fa9] dark:bg-[#245fa9]'"
68
+ :style="{ width: actionWidth + 'px' }" :disabled="disabled()"
69
+ :accessibilityLabel="item.accessibilityLabel || item.label" :aria-label="item.accessibilityLabel || item.label"
70
+ :testID="item.testID || (testId() && testId() + '-' + item.id)" @click="activate(item.id)">
71
+ <span class="text-xs font-semibold text-center text-white" :text="item.label"></span>
72
+ </button>
73
+ </div>
74
+ </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
+ }