@ruckc/truss-chat 1.37.0 → 1.37.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.
@@ -103,6 +103,34 @@
103
103
  pin(log);
104
104
  };
105
105
 
106
+ // The pill floats over the bottom of the log. A QuestionForm card there has interactive content (the options) under it, and
107
+ // on a phone a card taller than the log leaves nowhere else for the pill to go: so it steps aside while focus is inside a
108
+ // card or a card reaches the pill's strip. It comes back as soon as the cards are out of the strip, e.g. once scrolled past.
109
+ const FORM = '[data-tr-question-form]';
110
+ const STRIP = 64; // the pill's height plus its bottom offset, with some slack
111
+ let formFocus = $state(false);
112
+ let formNear = $state(false);
113
+ const stepAside = $derived(formFocus || formNear);
114
+ function measure() {
115
+ if (!log) return; // an observer callback queued before the thread went away
116
+ const r = log.getBoundingClientRect();
117
+ formNear = [...log.querySelectorAll(FORM)].some((f) => {
118
+ const b = f.getBoundingClientRect();
119
+ return b.height > 0 && b.bottom > r.bottom - STRIP && b.top < r.bottom;
120
+ });
121
+ }
122
+ const infocus = (e: FocusEvent) => (formFocus = !!(e.target as Element).closest(FORM));
123
+ const outfocus = (e: FocusEvent) => (formFocus = !!(e.relatedTarget as Element | null)?.closest(FORM));
124
+ $effect(() => {
125
+ measure();
126
+ const ro = new ResizeObserver(measure);
127
+ ro.observe(content);
128
+ ro.observe(log);
129
+ const mo = new MutationObserver(measure);
130
+ mo.observe(content, { childList: true, subtree: true });
131
+ return () => { ro.disconnect(); mo.disconnect(); };
132
+ });
133
+
106
134
  // following: scroll now (mount, jump, `follow` set from outside) and again whenever the content or the viewport resizes
107
135
  $effect(() => {
108
136
  if (follow) pin(log);
@@ -118,10 +146,10 @@
118
146
 
119
147
  <div {...rest} class={['thread', klass]}>
120
148
  <!-- aria-live="off": a log is implicitly polite, which would announce every streamed token; finished replies go through the live region below instead -->
121
- <div class="log" role="log" aria-live="off" aria-label={label} bind:this={log} {onscroll}>
149
+ <div class="log" role="log" aria-live="off" aria-label={label} bind:this={log} onscroll={(e) => { onscroll(e); measure(); }} onfocusin={infocus} onfocusout={outfocus}>
122
150
  <div class="content" bind:this={content}>{@render children()}</div>
123
151
  </div>
124
- {#if !follow}
152
+ {#if !follow && !stepAside}
125
153
  <div class="jump"><Button size="sm" variant="tonal" icon="arrow-down" onclick={jump}>{jumpLabel}</Button></div>
126
154
  {/if}
127
155
  <div class="tr-visually-hidden" role="status" aria-live="polite" aria-atomic="true">{live}</div>
@@ -222,7 +222,7 @@
222
222
  {/snippet}
223
223
 
224
224
  <!-- the keydown handler lives on the wrapper so Enter and Escape work from any control inside -->
225
- <div {...rest} class={['qf', klass]} role="group" aria-label="Questions" {onkeydown} onkeyup={() => (arrowed = false)}>
225
+ <div {...rest} data-tr-question-form class={['qf', klass]} role="group" aria-label="Questions" {onkeydown} onkeyup={() => (arrowed = false)}>
226
226
  {#if header}<div class="attn">{@render header()}</div>{/if}
227
227
  {#if tabs}
228
228
  <div class="tabs" role="tablist" aria-label="Questions" aria-orientation="horizontal">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-chat",
3
- "version": "1.37.0",
3
+ "version": "1.37.1",
4
4
  "description": "Chat building blocks for Truss UI: thread, messages, tool calls, composer, status line and a question form",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "@ruckc/truss-ui": "^1.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "@ruckc/truss-markdown": "^1.37.0"
30
+ "@ruckc/truss-markdown": "^1.37.1"
31
31
  },
32
32
  "author": "Curtis Ruck",
33
33
  "homepage": "https://truss.ruck.io",