@sensiblestats/widget-react 0.2.1 → 0.3.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @sensiblestats/widget-react
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Entity cards are no longer clickable — they render as static info cards
8
+ (planned to return later with proper question composition). Fix iOS Safari
9
+ zooming on input focus (textarea font-size ≥ 16px on touch). Fix the message
10
+ list yanking the reader to the bottom when late content (suggested actions)
11
+ arrives after they scrolled up — auto-scroll now follows only while pinned to
12
+ the bottom. Also ships the i18n/localized labels and logo refactor from master.
13
+
3
14
  ## 0.2.0
4
15
 
5
16
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -151,8 +151,7 @@ function toCardVM(card) {
151
151
  name: card.canonicalName,
152
152
  image: str(card.imagePath) ?? str(card.imageUrl) ?? str(card.image_url) ?? str(card.logoUrl) ?? str(card.logo),
153
153
  sub: str(card.subtitle) ?? str(card.teamName) ?? str(card.leagueName) ?? str(card.position),
154
- stats: readStats(card),
155
- query: card.canonicalName
154
+ stats: readStats(card)
156
155
  };
157
156
  }
158
157
  function toActionVM(action) {
@@ -325,9 +324,6 @@ function SendIcon() {
325
324
  function CloseIcon() {
326
325
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { viewBox: "0 0 24 24", width: "1em", height: "1em", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { fill: "none", d: "M18 6L6 18M6 6l12 12", stroke: "currentColor", strokeWidth: "2" }) });
327
326
  }
328
- function ChevronIcon() {
329
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { viewBox: "0 0 24 24", width: "1em", height: "1em", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { fill: "none", stroke: "currentColor", strokeWidth: "2", d: "M9 6l6 6-6 6" }) });
330
- }
331
327
 
332
328
  // src/components/GreetingBubble.tsx
333
329
  var import_jsx_runtime2 = require("react/jsx-runtime");
@@ -386,13 +382,13 @@ var MAX_VISIBLE = 3;
386
382
  function initials(name) {
387
383
  return name.split(/\s+/).slice(0, 2).map((w) => w[0] ?? "").join("").toUpperCase();
388
384
  }
389
- function EntityCardList({ cards, disabled, onSelect, showLessLabel = "Show less", showMoreLabel = (n) => `Show ${n} more` }) {
385
+ function EntityCardList({ cards, disabled, showLessLabel = "Show less", showMoreLabel = (n) => `Show ${n} more` }) {
390
386
  const [expanded, setExpanded] = (0, import_react2.useState)(false);
391
387
  if (cards.length === 0) return null;
392
388
  const visible = expanded ? cards : cards.slice(0, MAX_VISIBLE);
393
389
  const overflow = cards.length - MAX_VISIBLE;
394
390
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "ss-w-cards", children: [
395
- visible.map((c) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { type: "button", className: "ss-w-ecard", "data-kind": c.kind, disabled, onClick: () => onSelect(c.query), children: [
391
+ visible.map((c) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "ss-w-ecard", "data-kind": c.kind, children: [
396
392
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
397
393
  "span",
398
394
  {
@@ -409,8 +405,7 @@ function EntityCardList({ cards, disabled, onSelect, showLessLabel = "Show less"
409
405
  c.stats.map((s) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "ss-w-stat", children: [
410
406
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { children: s.value }),
411
407
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: s.label })
412
- ] }, s.label)),
413
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "ss-w-chev", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChevronIcon, {}) })
408
+ ] }, s.label))
414
409
  ] }, c.id)),
415
410
  overflow > 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "ss-w-cards-more", disabled, onClick: () => setExpanded((v) => !v), children: expanded ? showLessLabel : showMoreLabel(overflow) }) : null
416
411
  ] });
@@ -431,13 +426,13 @@ function ActionButtons({ actions, loading, disabled, onAct }) {
431
426
 
432
427
  // src/components/ChatMessage.tsx
433
428
  var import_jsx_runtime8 = require("react/jsx-runtime");
434
- function ChatMessage({ message, disabled, onAct, onSelect, ui }) {
429
+ function ChatMessage({ message, disabled, onAct, ui }) {
435
430
  if (message.role === "user") {
436
431
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "ss-w-msg ss-w-user", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "ss-w-bubble", children: message.text }) });
437
432
  }
438
433
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "ss-w-msg ss-w-bot", children: [
439
434
  message.text ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Markdown, { text: message.text }) : null,
440
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(EntityCardList, { cards: message.cards, disabled, onSelect, showLessLabel: ui?.showLess, showMoreLabel: ui?.showMore }),
435
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(EntityCardList, { cards: message.cards, disabled, showLessLabel: ui?.showLess, showMoreLabel: ui?.showMore }),
441
436
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ActionButtons, { actions: message.actions, loading: false, disabled, onAct })
442
437
  ] });
443
438
  }
@@ -449,37 +444,55 @@ function IntentChips({ chips, onPick }) {
449
444
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "ss-w-chips", children: chips.map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { type: "button", className: "ss-w-chip", onClick: () => onPick(c.text), children: c.text }, `${c.text}-${i}`)) });
450
445
  }
451
446
 
447
+ // src/scroll.ts
448
+ var PIN_THRESHOLD = 48;
449
+ function isPinnedToBottom(el, threshold = PIN_THRESHOLD) {
450
+ return el.scrollHeight - el.scrollTop - el.clientHeight <= threshold;
451
+ }
452
+
452
453
  // src/components/MessageList.tsx
453
454
  var import_jsx_runtime10 = require("react/jsx-runtime");
454
455
  function MessageList({ controller, ui }) {
455
456
  const { state, send } = controller;
457
+ const listRef = (0, import_react3.useRef)(null);
456
458
  const endRef = (0, import_react3.useRef)(null);
459
+ const pinnedRef = (0, import_react3.useRef)(true);
457
460
  (0, import_react3.useEffect)(() => {
458
- endRef.current?.scrollIntoView({ block: "end" });
461
+ if (pinnedRef.current) endRef.current?.scrollIntoView({ block: "end" });
459
462
  }, [state.messages, state.status]);
460
463
  const empty = state.messages.length === 0;
461
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "ss-w-list", "aria-live": "polite", children: [
462
- state.messages.map((m) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
463
- ChatMessage,
464
- {
465
- message: m,
466
- disabled: state.isStreaming,
467
- onAct: (a) => send(a.message, { actionId: a.actionId, displayText: a.label }),
468
- onSelect: (q) => send(q),
469
- ui
464
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
465
+ "div",
466
+ {
467
+ className: "ss-w-list",
468
+ "aria-live": "polite",
469
+ ref: listRef,
470
+ onScroll: () => {
471
+ if (listRef.current) pinnedRef.current = isPinnedToBottom(listRef.current);
470
472
  },
471
- m.id
472
- )),
473
- state.isStreaming && state.actionsLoading ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ActionButtons, { actions: [], loading: true, onAct: () => {
474
- } }) : null,
475
- state.status ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "ss-w-status", children: state.status }) : null,
476
- state.error ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "ss-w-error", role: "alert", children: [
477
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "message" in state.error ? state.error.message : ui.somethingWentWrong }),
478
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "ss-w-retry", onClick: () => controller.retry(), children: ui.retry })
479
- ] }) : null,
480
- empty ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(IntentChips, { chips: state.starters, onPick: (t) => send(t) }) : null,
481
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { ref: endRef })
482
- ] });
473
+ children: [
474
+ state.messages.map((m) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
475
+ ChatMessage,
476
+ {
477
+ message: m,
478
+ disabled: state.isStreaming,
479
+ onAct: (a) => send(a.message, { actionId: a.actionId, displayText: a.label }),
480
+ ui
481
+ },
482
+ m.id
483
+ )),
484
+ state.isStreaming && state.actionsLoading ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ActionButtons, { actions: [], loading: true, onAct: () => {
485
+ } }) : null,
486
+ state.status ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "ss-w-status", children: state.status }) : null,
487
+ state.error ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "ss-w-error", role: "alert", children: [
488
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "message" in state.error ? state.error.message : ui.somethingWentWrong }),
489
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "ss-w-retry", onClick: () => controller.retry(), children: ui.retry })
490
+ ] }) : null,
491
+ empty ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(IntentChips, { chips: state.starters, onPick: (t) => send(t) }) : null,
492
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { ref: endRef })
493
+ ]
494
+ }
495
+ );
483
496
  }
484
497
 
485
498
  // src/components/ChatInput.tsx
@@ -617,7 +630,7 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
617
630
 
618
631
  /* entity cards */
619
632
  .ss-w-cards { display: flex; flex-direction: column; gap: 7px; }
620
- .ss-w-ecard { display: flex; align-items: center; gap: 11px; width: 100%; background: var(--ss-w-panel); border: 1px solid var(--ss-w-line); border-radius: 12px; padding: 8px 11px; text-align: left; cursor: pointer; }
633
+ .ss-w-ecard { display: flex; align-items: center; gap: 11px; width: 100%; background: var(--ss-w-panel); border: 1px solid var(--ss-w-line); border-radius: 12px; padding: 8px 11px; text-align: left; }
621
634
  .ss-w-thumb { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; background-color: var(--ss-w-nav); background-size: cover; background-position: center; }
622
635
  .ss-w-thumb.ss-w-team { border-radius: 10px; }
623
636
  .ss-w-ecard[data-kind="player"] .ss-w-thumb { background-color: var(--ss-w-accent); }
@@ -628,10 +641,9 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
628
641
  .ss-w-stat { margin-left: auto; text-align: center; }
629
642
  .ss-w-stat b { display: block; font-variant-numeric: tabular-nums; }
630
643
  .ss-w-stat span { font-size: 9px; text-transform: uppercase; color: var(--ss-w-faint); }
631
- .ss-w-chev { color: var(--ss-w-faint); font-size: 16px; display: grid; place-items: center; }
632
644
  .ss-w-cards-more { align-self: flex-start; font-size: 11.5px; font-weight: 560; color: var(--ss-w-accent); background: none; border: none; cursor: pointer; padding: 3px 2px; }
633
645
  .ss-w-cards-more:hover:not(:disabled) { text-decoration: underline; }
634
- .ss-w-ecard:disabled, .ss-w-cards-more:disabled { opacity: .5; cursor: default; }
646
+ .ss-w-cards-more:disabled { opacity: .5; cursor: default; }
635
647
 
636
648
  /* action buttons */
637
649
  .ss-w-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
@@ -648,6 +660,11 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
648
660
  .ss-w-input { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--ss-w-line); }
649
661
  .ss-w-textarea { flex: 1; resize: none; border: 1px solid var(--ss-w-line); border-radius: 12px; padding: 8px 10px; font: inherit; color: inherit; background: var(--ss-w-panel); max-height: 96px; }
650
662
  .ss-w-textarea:disabled { opacity: .55; cursor: not-allowed; }
663
+ /* iOS Safari zooms the page when a focused field's font-size is < 16px. Bump it
664
+ on touch devices only, so the desktop 13px design is unchanged. */
665
+ @media (pointer: coarse) {
666
+ .ss-w-textarea { font-size: 16px; }
667
+ }
651
668
  .ss-w-send { width: 36px; height: 36px; flex: none; border: none; border-radius: 50%; background: var(--ss-w-accent); color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 16px; }
652
669
  .ss-w-stop-glyph { width: 11px; height: 11px; background: currentColor; border-radius: 2px; }
653
670