@sensiblestats/widget-react 0.141.0 → 0.142.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.142.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 087796d: The sentence builder takes a typed total: a pencil chip beside the totals opens an input in the visitor's odds format. `combo_add_click.total` reads `custom` for it. The total row is a four-column grid. Input that can't be read says how to type it in the visitor's format; a number outside 1.01 to 1000 says the range. A trailing `.` or `,` after a whole number is ignored in every format, a bare fractional `7` reads as 7/1 and shows that way on the chip, and `evs` reads as evens.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [087796d]
12
+ - @sensiblestats/widget-sdk@0.104.0
13
+
3
14
  ## 0.141.0
4
15
 
5
16
  ### Minor Changes
package/README.md CHANGED
@@ -236,7 +236,7 @@ Rules:
236
236
  | `pin_click` | `action` (`add`, `remove`), `target` (`match`, `market`), `matchId?`, `market?`, `sport?` | A pin is tapped |
237
237
  | `add_to_slip_click` | `matchOddsId`, `matchId`, `odds`, `market?`, `sport?`, `factKey?` | "Add to slip" is tapped. `factKey` is set when the add came from a live fact's market, so you can attribute the add to that fact |
238
238
  | `add_to_slip_result` | as above, plus `outcome` | Your `onAddToSlip` has answered |
239
- | `combo_add_click` | `surface`, `sport`, `legs`, `total` | "Add all" has added every leg of a combo: `surface` is `builder` for the bet builder and `chat` for a combo card in an answer. `total` is the total the visitor asked for. A partial add or a refused leg fires none. Each leg also fires its own `add_to_slip_click` and `add_to_slip_result` |
239
+ | `combo_add_click` | `surface`, `sport`, `legs`, `total` | "Add all" has added every leg of a combo: `surface` is `builder` for the bet builder and `chat` for a combo card in an answer. `total` is the chip key the visitor chose in the builder (`custom` for a typed total), or the total the visitor asked for in chat (empty when they asked for none). A partial add or a refused leg fires none. Each leg also fires its own `add_to_slip_click` and `add_to_slip_result` |
240
240
  | `all_markets_click` | `matchId`, `market?`, `surface` | "All markets" is tapped |
241
241
  | `dashboard_tile_click` | `entityType`, `entityId` | A dashboard tile is tapped |
242
242
  | `sport_switch` | `sport` | The visitor switches sport on the dashboard |
package/dist/index.cjs CHANGED
@@ -254,6 +254,12 @@ var BUNDLED_EN_GB = {
254
254
  "widget.v8BuilderSingles": "Singles",
255
255
  "widget.v8BuilderTotal": "total",
256
256
  "widget.v8BuilderAny": "Any",
257
+ "widget.v8BuilderCustomLabel": "Type your own total",
258
+ "widget.v8BuilderCustomPlaceholder": "e.g. {example}",
259
+ "widget.v8BuilderCustomSet": "Set",
260
+ "widget.v8BuilderCustomRange": "Enter a total above 1.01 and up to 1000.",
261
+ "widget.v8BuilderCustomUnreadable": "Type the total like {example}.",
262
+ "widget.v8BuilderCustomEdit": "Your total {total}, edit",
257
263
  "widget.v8BuilderLoading": "Loading\u2026",
258
264
  "widget.v8BuilderError": "Couldn't load this right now.",
259
265
  "widget.v8BuilderRetry": "Try again",
@@ -1147,6 +1153,9 @@ var ROW_LEAVES = {
1147
1153
  favRemove: (c) => (name) => c.t("widget.favRemove", { name }),
1148
1154
  favStar: (c) => (name) => c.t("widget.favStar", { name }),
1149
1155
  favUnstar: (c) => (name) => c.t("widget.favUnstar", { name }),
1156
+ v8BuilderCustomPlaceholder: (c) => (example) => c.t("widget.v8BuilderCustomPlaceholder", { example }),
1157
+ v8BuilderCustomUnreadable: (c) => (example) => c.t("widget.v8BuilderCustomUnreadable", { example }),
1158
+ v8BuilderCustomEdit: (c) => (total) => c.t("widget.v8BuilderCustomEdit", { total }),
1150
1159
  v8Follow: (c) => (name) => c.t("widget.v8Follow", { name }),
1151
1160
  v8PricesAsOf: (c) => (time) => c.t("widget.v8PricesAsOf", { time }),
1152
1161
  v8InjuryAsOf: (c) => (time) => c.t("widget.v8InjuryAsOf", { time }),
@@ -1340,9 +1349,29 @@ function parseOddsFormat(value) {
1340
1349
  const v = typeof value === "string" ? value.trim().toLowerCase() : "";
1341
1350
  return v === "decimal" || v === "american" || v === "fractional" ? v : void 0;
1342
1351
  }
1352
+ var CUSTOM_TOTAL_EXAMPLE = { decimal: "7.50", fractional: "13/2", american: "+650" };
1353
+ var roundCents = (x) => Math.round(x * 100 + 1e-9) / 100;
1354
+ function parseCustomTotal(text2, format2) {
1355
+ const t = text2.trim().replace(/\u2212/g, "-").replace(/^([+-]?\d+)[.,]$/, "$1");
1356
+ const point = /^(\d{0,9})[.,](\d{1,9})$/.exec(t);
1357
+ const whole = /^\d{1,12}$/.test(t);
1358
+ const fraction = format2 === "fractional" ? /^(\d{1,9})\s*\/\s*(\d{1,9})$/.exec(t) : null;
1359
+ const american = format2 === "american" ? /^([+-]?)(\d{1,12})$/.exec(t) : null;
1360
+ let value = null;
1361
+ if (point) value = Number(`${point[1] || "0"}.${point[2]}`);
1362
+ else if (format2 === "decimal" && whole) value = Number(t);
1363
+ else if (format2 === "fractional" && whole) value = 1 + Number(t);
1364
+ else if (format2 === "fractional" && /^ev(s|ens)$/i.test(t)) value = 2;
1365
+ else if (fraction && Number(fraction[2]) > 0) value = 1 + Number(fraction[1]) / Number(fraction[2]);
1366
+ else if (american && Number(american[2]) >= 100) value = american[1] === "-" ? 1 + 100 / Number(american[2]) : 1 + Number(american[2]) / 100;
1367
+ if (value === null) return { error: "unreadable" };
1368
+ const cents2 = roundCents(value);
1369
+ if (!(cents2 > 1.01 && cents2 <= 1e3)) return { error: "range" };
1370
+ return { decimal: cents2.toFixed(2), text: format2 === "fractional" && whole ? `${t}/1` : t };
1371
+ }
1343
1372
 
1344
1373
  // src/version.generated.ts
1345
- var WIDGET_REACT_VERSION = "0.141.0";
1374
+ var WIDGET_REACT_VERSION = "0.142.0";
1346
1375
 
1347
1376
  // src/config.ts
1348
1377
  function hostTag(cfg) {
@@ -1652,6 +1681,12 @@ function normalizeUi(cfg, loaded) {
1652
1681
  v8BuilderSingles: strings.v8BuilderSingles,
1653
1682
  v8BuilderTotal: strings.v8BuilderTotal,
1654
1683
  v8BuilderAny: strings.v8BuilderAny,
1684
+ v8BuilderCustomLabel: strings.v8BuilderCustomLabel,
1685
+ v8BuilderCustomPlaceholder: strings.v8BuilderCustomPlaceholder,
1686
+ v8BuilderCustomSet: strings.v8BuilderCustomSet,
1687
+ v8BuilderCustomRange: strings.v8BuilderCustomRange,
1688
+ v8BuilderCustomUnreadable: strings.v8BuilderCustomUnreadable,
1689
+ v8BuilderCustomEdit: strings.v8BuilderCustomEdit,
1655
1690
  v8BuilderLoading: strings.v8BuilderLoading,
1656
1691
  v8BuilderError: strings.v8BuilderError,
1657
1692
  v8BuilderRetry: strings.v8BuilderRetry,
@@ -17304,6 +17339,7 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17304
17339
  const openingView = {
17305
17340
  legs: preset.legs,
17306
17341
  total: asTotal(preset.totalTarget, totals),
17342
+ custom: null,
17307
17343
  // All markets opens unless the visitor has a usual market, which is never beaten.
17308
17344
  marketKey: marketOptions && !marketOptions.some((m) => m.usual) ? null : preset.marketKey,
17309
17345
  gamesId: opening.option?.id ?? null,
@@ -17320,11 +17356,38 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17320
17356
  matchIds: v.widen ? [] : v.matchIds,
17321
17357
  legs: v.legs,
17322
17358
  // The total row is hidden for Singles, so a total picked earlier must not narrow them; the pick stays in state for the way back.
17323
- total: v.legs === 1 ? "any" : v.total,
17359
+ total: v.legs === 1 ? "any" : v.custom?.decimal ?? v.total,
17324
17360
  widen: v.widen,
17325
17361
  ...operatorUserId ? { operatorUserId } : {},
17326
17362
  ...anonymousUserId ? { anonymousUserId } : {}
17327
17363
  });
17364
+ const [editing, setEditing] = (0, import_react108.useState)(false);
17365
+ const [draft, setDraft] = (0, import_react108.useState)("");
17366
+ const [invalid, setInvalid] = (0, import_react108.useState)(null);
17367
+ const inputRef = (0, import_react108.useRef)(null);
17368
+ const pencilRef = (0, import_react108.useRef)(null);
17369
+ const noteId = (0, import_react108.useId)();
17370
+ const customId = (0, import_react108.useId)();
17371
+ (0, import_react108.useEffect)(() => {
17372
+ if (editing) inputRef.current?.focus();
17373
+ }, [editing]);
17374
+ const customLabel = (c) => c.format === oddsFormat ? c.text : c.decimal;
17375
+ (0, import_react108.useEffect)(() => {
17376
+ if (view.legs === 1) {
17377
+ setEditing(false);
17378
+ setDraft("");
17379
+ setInvalid(null);
17380
+ }
17381
+ }, [view.legs]);
17382
+ const openCustom = () => {
17383
+ setDraft(view.custom ? customLabel(view.custom) : "");
17384
+ setInvalid(null);
17385
+ setEditing(true);
17386
+ };
17387
+ const closeCustom = () => {
17388
+ setEditing(false);
17389
+ pencilRef.current?.focus();
17390
+ };
17328
17391
  const [first] = (0, import_react108.useState)(() => requestFor(view));
17329
17392
  const { grid, status: status2, confirmed, request } = useBuilderGrid({ conversation, locale: ui.hostTag, memory: memory3, initial: first });
17330
17393
  const lastRequest = (0, import_react108.useRef)(first);
@@ -17346,6 +17409,18 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17346
17409
  commit(next, false);
17347
17410
  send(requestFor(next));
17348
17411
  };
17412
+ const setCustom = () => {
17413
+ const parsed = parseCustomTotal(draft, oddsFormat);
17414
+ if ("error" in parsed) {
17415
+ setInvalid(parsed.error);
17416
+ return;
17417
+ }
17418
+ closeCustom();
17419
+ setInvalid(null);
17420
+ const custom = { decimal: parsed.decimal, text: parsed.text, format: oddsFormat };
17421
+ if (view.custom?.decimal === parsed.decimal) commit({ ...view, custom }, widenedNote);
17422
+ else ask({ ...view, custom });
17423
+ };
17349
17424
  const allGames = gamesOptions?.find((o) => o.matchIds.length === 0) ?? null;
17350
17425
  const pickGames = (option) => {
17351
17426
  const next = { ...view, gamesId: option.id, matchIds: option.matchIds, widen: option.matchIds.length === 0 };
@@ -17379,7 +17454,7 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17379
17454
  const singles = view.legs === 1;
17380
17455
  const onOpeningChoice = view.marketKey === openingView.marketKey && view.widen === openingView.widen && view.gamesId === openingView.gamesId && sameIds(view.matchIds, openingView.matchIds);
17381
17456
  const quotedAt = rows ? oldestQuote(rows) : null;
17382
- const combo = ready && grid.total !== null ? { sport, totalChosen: view.total, totalActual: grid.total } : void 0;
17457
+ const combo = ready && grid.total !== null ? { sport, totalChosen: view.custom ? "custom" : view.total, totalActual: grid.total } : void 0;
17383
17458
  const canWiden = gamesOptions === null || allGames !== null;
17384
17459
  (0, import_react108.useEffect)(() => {
17385
17460
  if (!empty2 || !singles || widened || !canWiden || autoWidened.current) return;
@@ -17461,19 +17536,72 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17461
17536
  ] }),
17462
17537
  view.legs > 1 ? /* @__PURE__ */ (0, import_jsx_runtime141.jsxs)("div", { className: "ss-w-v8-builder-ln ss-w-v8-builder-ln--total", children: [
17463
17538
  /* @__PURE__ */ (0, import_jsx_runtime141.jsx)("span", { className: "ss-w-v8-builder-w", children: ui.v8BuilderTotal }),
17464
- /* @__PURE__ */ (0, import_jsx_runtime141.jsx)("div", { className: "ss-w-v8-builder-btns", role: "group", "aria-label": ui.v8BuilderTotal, children: totals.map((t) => /* @__PURE__ */ (0, import_jsx_runtime141.jsx)(
17465
- "button",
17466
- {
17467
- type: "button",
17468
- className: "ss-w-v8-builder-btn",
17469
- "aria-pressed": view.total === t,
17470
- onClick: () => {
17471
- if (view.total !== t) ask({ ...view, total: t });
17539
+ /* @__PURE__ */ (0, import_jsx_runtime141.jsxs)("div", { className: "ss-w-v8-builder-btns", role: "group", "aria-label": ui.v8BuilderTotal, children: [
17540
+ totals.map((t) => /* @__PURE__ */ (0, import_jsx_runtime141.jsx)(
17541
+ "button",
17542
+ {
17543
+ type: "button",
17544
+ className: "ss-w-v8-builder-btn",
17545
+ "aria-pressed": view.custom === null && view.total === t,
17546
+ onClick: () => {
17547
+ if (view.total !== t || view.custom) {
17548
+ setEditing(false);
17549
+ ask({ ...view, total: t, custom: null });
17550
+ }
17551
+ },
17552
+ children: totalLabel(t, preset.totalOptions, oddsFormat, ui)
17472
17553
  },
17473
- children: totalLabel(t, preset.totalOptions, oddsFormat, ui)
17474
- },
17475
- t
17476
- )) })
17554
+ t
17555
+ )),
17556
+ /* @__PURE__ */ (0, import_jsx_runtime141.jsx)(
17557
+ "button",
17558
+ {
17559
+ ref: pencilRef,
17560
+ type: "button",
17561
+ className: "ss-w-v8-builder-btn",
17562
+ "data-custom": true,
17563
+ "aria-pressed": view.custom !== null,
17564
+ "aria-expanded": editing,
17565
+ "aria-controls": editing ? customId : void 0,
17566
+ "aria-label": view.custom ? ui.v8BuilderCustomEdit(customLabel(view.custom)) : ui.v8BuilderCustomLabel,
17567
+ onClick: () => editing ? closeCustom() : openCustom(),
17568
+ children: view.custom ? customLabel(view.custom) : /* @__PURE__ */ (0, import_jsx_runtime141.jsx)(PencilIcon, {})
17569
+ }
17570
+ )
17571
+ ] }),
17572
+ editing ? /* @__PURE__ */ (0, import_jsx_runtime141.jsxs)("div", { id: customId, className: "ss-w-v8-builder-custom", children: [
17573
+ /* @__PURE__ */ (0, import_jsx_runtime141.jsx)(
17574
+ "input",
17575
+ {
17576
+ ref: inputRef,
17577
+ className: "ss-w-v8-builder-input",
17578
+ type: "text",
17579
+ inputMode: oddsFormat === "decimal" ? "decimal" : "text",
17580
+ maxLength: 12,
17581
+ value: draft,
17582
+ placeholder: ui.v8BuilderCustomPlaceholder(CUSTOM_TOTAL_EXAMPLE[oddsFormat]),
17583
+ "aria-label": ui.v8BuilderCustomLabel,
17584
+ "aria-invalid": invalid !== null,
17585
+ "aria-describedby": invalid ? noteId : void 0,
17586
+ onChange: (e) => {
17587
+ setDraft(e.target.value);
17588
+ setInvalid(null);
17589
+ },
17590
+ onKeyDown: (e) => {
17591
+ if (e.key === "Enter") {
17592
+ e.preventDefault();
17593
+ setCustom();
17594
+ } else if (e.key === "Escape") {
17595
+ e.preventDefault();
17596
+ e.stopPropagation();
17597
+ closeCustom();
17598
+ }
17599
+ }
17600
+ }
17601
+ ),
17602
+ /* @__PURE__ */ (0, import_jsx_runtime141.jsx)("button", { type: "button", className: "ss-w-v8-builder-btn", onClick: setCustom, children: ui.v8BuilderCustomSet }),
17603
+ invalid ? /* @__PURE__ */ (0, import_jsx_runtime141.jsx)("p", { id: noteId, className: "ss-w-v8-builder-note", "data-kind": `custom-${invalid}`, role: "alert", children: invalid === "range" ? ui.v8BuilderCustomRange : ui.v8BuilderCustomUnreadable(CUSTOM_TOTAL_EXAMPLE[oddsFormat]) }) : null
17604
+ ] }) : null
17477
17605
  ] }) : null,
17478
17606
  ready && singles && widenedNote && !empty2 ? /* @__PURE__ */ (0, import_jsx_runtime141.jsx)("p", { className: "ss-w-v8-builder-note", "data-kind": "widened", children: ui.v8SinglesWidened(marketName) }) : null,
17479
17607
  ready && !widenedNote && !empty2 && preset.widenedForMarket === true && onOpeningChoice && view.marketKey !== null ? /* @__PURE__ */ (0, import_jsx_runtime141.jsx)("p", { className: "ss-w-v8-builder-note", children: ui.v8Widened }) : null,
@@ -17505,6 +17633,12 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17505
17633
  ] }) : null
17506
17634
  ] }) : null });
17507
17635
  }
17636
+ function PencilIcon() {
17637
+ return /* @__PURE__ */ (0, import_jsx_runtime141.jsxs)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: [
17638
+ /* @__PURE__ */ (0, import_jsx_runtime141.jsx)("path", { d: "M12 20h9" }),
17639
+ /* @__PURE__ */ (0, import_jsx_runtime141.jsx)("path", { d: "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" })
17640
+ ] });
17641
+ }
17508
17642
  function GamesOptions({ options, ui }) {
17509
17643
  const top = options.filter((o) => o.group !== "league" && o.group !== "game");
17510
17644
  const leagues = options.filter((o) => o.group === "league");
@@ -20140,9 +20274,18 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
20140
20274
  .ss-w-v8-builder-btn:disabled:not([aria-pressed="true"]) { opacity: .55; }
20141
20275
  .ss-w-v8-builder-btn[data-suggested]:not([aria-pressed="true"]) { border-style: dashed; border-color: var(--ss-v8-mint); }
20142
20276
  .ss-w-v8-builder button:focus-visible { outline: 2px solid var(--ss-v8-mint); outline-offset: 1px; }
20143
- .ss-w-v8-builder-ln--total > .ss-w-v8-builder-btns { display: grid; grid-template-columns: auto repeat(5, minmax(0, 1fr)); }
20144
- .ss-w-v8-builder-ln--total .ss-w-v8-builder-btn { min-width: 0; padding: 4px 2px; font-size: 13.5px; }
20145
- .ss-w-v8-builder-ln--total .ss-w-v8-builder-btn:first-child { padding: 4px 9px; }
20277
+ .ss-w-v8-builder-ln--total > .ss-w-v8-builder-btns { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
20278
+ .ss-w-v8-builder-ln--total .ss-w-v8-builder-btn { min-width: 0; padding: 4px 2px; font-size: 13.5px; overflow-wrap: normal; }
20279
+ .ss-w-v8-builder-ln--total .ss-w-v8-builder-btn:first-child { padding: 4px 9px; grid-column: span 2; }
20280
+ .ss-w-v8-builder-btn[data-custom] { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
20281
+ .ss-w-v8-builder-btn[data-custom] svg { width: 16px; height: 16px; vertical-align: middle; }
20282
+ .ss-w-v8-builder-custom { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 100%; box-sizing: border-box; padding-left: 84px; }
20283
+ .ss-w-v8-builder-input { flex: 1 1 0; min-width: 0; box-sizing: border-box; height: 40px; margin: 0; padding: 8px 10px; border: 1px solid var(--ss-v8-chip-line); border-radius: 10px; background: var(--ss-v8-chip); color: #fff; font: inherit; font-size: 16px; font-weight: 600; line-height: 1.2; }
20284
+ .ss-w-v8-builder-input::placeholder { color: color-mix(in srgb, #fff 78%, var(--ss-w-nav)); opacity: 1; }
20285
+ .ss-w-v8-builder-custom > .ss-w-v8-builder-btn { flex: 0 0 auto; min-height: 40px; padding: 6px 14px; }
20286
+ .ss-w-v8-builder-input:focus-visible { outline: 2px solid var(--ss-v8-mint); outline-offset: 1px; }
20287
+ .ss-w-v8-builder-input[aria-invalid="true"] { border-color: #f2b8b5; }
20288
+ .ss-w-v8-builder-custom > .ss-w-v8-builder-note { flex: 1 1 100%; }
20146
20289
  .ss-w-v8-builder > .ss-w-v8-builder-btn { align-self: flex-start; min-height: 40px; padding: 6px 14px; }
20147
20290
  .ss-w-v8-builder .ss-w-slip-btn { min-height: 36px; }
20148
20291
  .ss-w-v8-builder .ss-w-combo-addall .ss-w-slip-btn { min-height: 44px; }
@@ -20157,10 +20300,7 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
20157
20300
  }
20158
20301
  @container (max-width: 400px) {
20159
20302
  .ss-w-v8-builder-ln--total .ss-w-v8-builder-w { flex-basis: 100%; }
20160
- }
20161
- /* Stacked, six targets still split "10.00" below this: three to a row, two rows. */
20162
- @container (max-width: 360px) {
20163
- .ss-w-v8-builder-ln--total > .ss-w-v8-builder-btns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
20303
+ .ss-w-v8-builder-custom { padding-left: 0; }
20164
20304
  }
20165
20305
 
20166
20306
  @media (prefers-reduced-motion: reduce) {