Malina commited on
Commit
acc9d08
·
1 Parent(s): 4eba183

aria(mobile/ui): fix keyboard layout jump (lock page + recompute through anim); swipe-right-to-reply; truncate quote >25 chars to 20+...

Browse files
cloudflare/pages-integration/aria.html CHANGED
@@ -6,7 +6,7 @@
6
  <title>ARIA · NNL</title>
7
  <link rel="icon" href="favicon.png" />
8
  <link rel="stylesheet" href="css/styles.css" />
9
- <link rel="stylesheet" href="css/aria.css?v=8" />
10
  </head>
11
  <body class="app-body aria-page" data-theme="default">
12
 
@@ -123,6 +123,6 @@
123
 
124
  <div class="aria-toast" id="ariaToast" hidden></div>
125
 
126
- <script type="module" src="js/aria-chat.js?v=9"></script>
127
  </body>
128
  </html>
 
6
  <title>ARIA · NNL</title>
7
  <link rel="icon" href="favicon.png" />
8
  <link rel="stylesheet" href="css/styles.css" />
9
+ <link rel="stylesheet" href="css/aria.css?v=9" />
10
  </head>
11
  <body class="app-body aria-page" data-theme="default">
12
 
 
123
 
124
  <div class="aria-toast" id="ariaToast" hidden></div>
125
 
126
+ <script type="module" src="js/aria-chat.js?v=10"></script>
127
  </body>
128
  </html>
cloudflare/pages-integration/css/aria.css CHANGED
@@ -11,8 +11,19 @@
11
  .aria-page [hidden] { display: none !important; }
12
 
13
  /* override the shared .app-body (used by login screens): it centers + pads, which
14
- created background bars on the sides of the chat. ARIA fills the whole viewport. */
15
- body.aria-page { display: block; padding: 0; margin: 0; min-height: 0; }
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  .aria-page {
18
  --aria-me: var(--accent, #6ea0ff); /* user bubble */
 
11
  .aria-page [hidden] { display: none !important; }
12
 
13
  /* override the shared .app-body (used by login screens): it centers + pads, which
14
+ created background bars on the sides of the chat. ARIA fills the whole viewport.
15
+ position:fixed + overflow:hidden also stops the mobile keyboard from scrolling the
16
+ whole layout up (it stays pinned; the visible height is driven by --app-h). */
17
+ body.aria-page { position: fixed; inset: 0; width: 100%; height: 100%; display: block; padding: 0; margin: 0; min-height: 0; overflow: hidden; }
18
+
19
+ /* swipe-right-to-reply (Messenger-style) */
20
+ .aria-row { position: relative; }
21
+ .aria-row::before {
22
+ content: "↩"; position: absolute; left: 6px; top: 50%; transform: translateY(-50%);
23
+ font-size: 18px; color: var(--text-soft, #b9bcc6); opacity: 0; transition: opacity .15s; pointer-events: none;
24
+ }
25
+ .aria-row.swipe-armed::before { opacity: .9; }
26
+ .aria-bubble { transition: transform .18s var(--ease, ease); }
27
 
28
  .aria-page {
29
  --aria-me: var(--accent, #6ea0ff); /* user bubble */
cloudflare/pages-integration/js/aria-chat.js CHANGED
@@ -23,9 +23,15 @@ let _overlay = null, _picker = null, _menu = null, _holdRow = null, _holdClone =
23
  function fitViewport() {
24
  const vv = window.visualViewport;
25
  document.documentElement.style.setProperty("--app-h", (vv ? vv.height : window.innerHeight) + "px");
 
26
  const m = $("ariaMessages"); if (m) m.scrollTop = m.scrollHeight;
27
  closeHold();
28
  }
 
 
 
 
 
29
  fitViewport();
30
  if (window.visualViewport) {
31
  window.visualViewport.addEventListener("resize", fitViewport);
@@ -68,6 +74,10 @@ function wireUi() {
68
  else toast("Brak połączenia — spróbuj za chwilę");
69
  });
70
  $("ariaReplyCancel")?.addEventListener("click", clearReply);
 
 
 
 
71
  wireHold();
72
  }
73
 
@@ -192,10 +202,11 @@ function row(side, id) {
192
  if (side === "them") { const av = document.createElement("span"); av.className = "aria-avatar sm"; av.textContent = "A"; r.appendChild(av); }
193
  return r;
194
  }
 
195
  function quoteSnippet(refId) {
196
  const ref = refId && $("ariaMessages").querySelector(`.aria-row[data-id="${cssId(refId)}"] .aria-bubble`);
197
  if (!ref) return null;
198
- return (ref.querySelector(".aria-bubble-text")?.textContent || ref.textContent || "").trim().slice(0, 80);
199
  }
200
  function bubbleEl(text, kind) {
201
  const b = document.createElement("div");
@@ -302,7 +313,7 @@ function startReply(rowEl) {
302
  const text = (rowEl.querySelector(".aria-bubble-text")?.textContent || "").trim();
303
  const role = rowEl.classList.contains("them") ? "assistant" : "user";
304
  state.replyTo = { id, text, role };
305
- $("ariaReplyText").textContent = (role === "assistant" ? "ARIA: " : "Ty: ") + text.slice(0, 80);
306
  $("ariaReplyBar").hidden = false;
307
  $("ariaInput").focus();
308
  }
@@ -333,20 +344,48 @@ function addTrayChip(meta) {
333
  /* ---------------- hold-to-react (iMessage-style: blur + clone + picker + reply) ---------------- */
334
  function wireHold() {
335
  const msgs = $("ariaMessages");
 
 
 
 
 
 
 
336
  msgs.addEventListener("pointerdown", (e) => {
337
- const rowEl = e.target.closest(".aria-row");
338
- if (!rowEl || !rowEl.dataset.id) return;
339
- _psx = e.clientX; _psy = e.clientY;
340
  clearTimeout(_pressTimer);
341
- _pressTimer = setTimeout(() => openHold(rowEl), 380);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  });
343
- const cancel = (e) => {
344
- if (e && e.type === "pointermove" && Math.abs(e.clientX - _psx) < 10 && Math.abs(e.clientY - _psy) < 10) return;
345
  clearTimeout(_pressTimer);
 
 
 
 
 
 
346
  };
347
- msgs.addEventListener("pointerup", cancel);
348
- msgs.addEventListener("pointermove", cancel);
349
- msgs.addEventListener("pointercancel", cancel);
350
  msgs.addEventListener("scroll", () => { clearTimeout(_pressTimer); closeHold(); }, { passive: true });
351
  msgs.addEventListener("contextmenu", (e) => { if (e.target.closest(".aria-row")) e.preventDefault(); });
352
  }
 
23
  function fitViewport() {
24
  const vv = window.visualViewport;
25
  document.documentElement.style.setProperty("--app-h", (vv ? vv.height : window.innerHeight) + "px");
26
+ if (window.scrollY || window.scrollX) window.scrollTo(0, 0); // undo iOS keyboard auto-scroll
27
  const m = $("ariaMessages"); if (m) m.scrollTop = m.scrollHeight;
28
  closeHold();
29
  }
30
+ let _vvPings = null;
31
+ function pingViewport() { // recompute repeatedly while the keyboard animates
32
+ clearInterval(_vvPings); let n = 0;
33
+ _vvPings = setInterval(() => { fitViewport(); if (++n > 14) clearInterval(_vvPings); }, 45);
34
+ }
35
  fitViewport();
36
  if (window.visualViewport) {
37
  window.visualViewport.addEventListener("resize", fitViewport);
 
74
  else toast("Brak połączenia — spróbuj za chwilę");
75
  });
76
  $("ariaReplyCancel")?.addEventListener("click", clearReply);
77
+ // keyboard open/close → recompute layout through the animation (fixes the
78
+ // "layout jumps up and doesn't settle until I tap" bug on mobile)
79
+ $("ariaInput").addEventListener("focus", pingViewport);
80
+ $("ariaInput").addEventListener("blur", () => { setTimeout(pingViewport, 50); });
81
  wireHold();
82
  }
83
 
 
202
  if (side === "them") { const av = document.createElement("span"); av.className = "aria-avatar sm"; av.textContent = "A"; r.appendChild(av); }
203
  return r;
204
  }
205
+ function trunc(t) { t = (t || "").trim(); return t.length > 25 ? t.slice(0, 20) + "..." : t; }
206
  function quoteSnippet(refId) {
207
  const ref = refId && $("ariaMessages").querySelector(`.aria-row[data-id="${cssId(refId)}"] .aria-bubble`);
208
  if (!ref) return null;
209
+ return trunc(ref.querySelector(".aria-bubble-text")?.textContent || ref.textContent || "");
210
  }
211
  function bubbleEl(text, kind) {
212
  const b = document.createElement("div");
 
313
  const text = (rowEl.querySelector(".aria-bubble-text")?.textContent || "").trim();
314
  const role = rowEl.classList.contains("them") ? "assistant" : "user";
315
  state.replyTo = { id, text, role };
316
+ $("ariaReplyText").textContent = (role === "assistant" ? "ARIA: " : "Ty: ") + trunc(text);
317
  $("ariaReplyBar").hidden = false;
318
  $("ariaInput").focus();
319
  }
 
344
  /* ---------------- hold-to-react (iMessage-style: blur + clone + picker + reply) ---------------- */
345
  function wireHold() {
346
  const msgs = $("ariaMessages");
347
+ let row = null, sx = 0, sy = 0, dx = 0, mode = null; // mode: null | "swipe" | "scroll"
348
+ const snapBack = (animate) => {
349
+ if (!row) return;
350
+ const b = row.querySelector(".aria-bubble");
351
+ if (b) { b.style.transition = animate ? "transform .18s var(--ease, ease)" : "none"; b.style.transform = ""; }
352
+ row.classList.remove("swipe-armed");
353
+ };
354
  msgs.addEventListener("pointerdown", (e) => {
355
+ const r = e.target.closest(".aria-row");
356
+ if (!r || !r.dataset.id) { row = null; return; }
357
+ row = r; sx = _psx = e.clientX; sy = _psy = e.clientY; dx = 0; mode = null;
358
  clearTimeout(_pressTimer);
359
+ _pressTimer = setTimeout(() => { if (mode !== "swipe") openHold(r); }, 380);
360
+ });
361
+ msgs.addEventListener("pointermove", (e) => {
362
+ if (!row) return;
363
+ const ddx = e.clientX - sx, ddy = e.clientY - sy;
364
+ if (mode === null) {
365
+ if (Math.abs(ddx) < 8 && Math.abs(ddy) < 8) return;
366
+ clearTimeout(_pressTimer);
367
+ mode = (Math.abs(ddx) > Math.abs(ddy) && ddx > 0) ? "swipe" : "scroll";
368
+ if (mode === "scroll") { row = null; return; } // vertical → let the list scroll
369
+ }
370
+ if (mode === "swipe") {
371
+ if (e.cancelable) e.preventDefault();
372
+ dx = Math.max(0, Math.min(ddx, 80));
373
+ const b = row.querySelector(".aria-bubble");
374
+ if (b) { b.style.transition = "none"; b.style.transform = `translateX(${dx}px)`; }
375
+ row.classList.toggle("swipe-armed", dx > 50);
376
+ }
377
  });
378
+ const end = () => {
 
379
  clearTimeout(_pressTimer);
380
+ if (row && mode === "swipe") {
381
+ const armed = dx > 50, r = row;
382
+ snapBack(true);
383
+ if (armed) { if (navigator.vibrate) navigator.vibrate(12); startReply(r); }
384
+ }
385
+ row = null; mode = null; dx = 0;
386
  };
387
+ msgs.addEventListener("pointerup", end);
388
+ msgs.addEventListener("pointercancel", () => { snapBack(true); row = null; mode = null; });
 
389
  msgs.addEventListener("scroll", () => { clearTimeout(_pressTimer); closeHold(); }, { passive: true });
390
  msgs.addEventListener("contextmenu", (e) => { if (e.target.closest(".aria-row")) e.preventDefault(); });
391
  }