@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/dist/index.js CHANGED
@@ -215,6 +215,12 @@ var BUNDLED_EN_GB = {
215
215
  "widget.v8BuilderSingles": "Singles",
216
216
  "widget.v8BuilderTotal": "total",
217
217
  "widget.v8BuilderAny": "Any",
218
+ "widget.v8BuilderCustomLabel": "Type your own total",
219
+ "widget.v8BuilderCustomPlaceholder": "e.g. {example}",
220
+ "widget.v8BuilderCustomSet": "Set",
221
+ "widget.v8BuilderCustomRange": "Enter a total above 1.01 and up to 1000.",
222
+ "widget.v8BuilderCustomUnreadable": "Type the total like {example}.",
223
+ "widget.v8BuilderCustomEdit": "Your total {total}, edit",
218
224
  "widget.v8BuilderLoading": "Loading\u2026",
219
225
  "widget.v8BuilderError": "Couldn't load this right now.",
220
226
  "widget.v8BuilderRetry": "Try again",
@@ -1108,6 +1114,9 @@ var ROW_LEAVES = {
1108
1114
  favRemove: (c) => (name) => c.t("widget.favRemove", { name }),
1109
1115
  favStar: (c) => (name) => c.t("widget.favStar", { name }),
1110
1116
  favUnstar: (c) => (name) => c.t("widget.favUnstar", { name }),
1117
+ v8BuilderCustomPlaceholder: (c) => (example) => c.t("widget.v8BuilderCustomPlaceholder", { example }),
1118
+ v8BuilderCustomUnreadable: (c) => (example) => c.t("widget.v8BuilderCustomUnreadable", { example }),
1119
+ v8BuilderCustomEdit: (c) => (total) => c.t("widget.v8BuilderCustomEdit", { total }),
1111
1120
  v8Follow: (c) => (name) => c.t("widget.v8Follow", { name }),
1112
1121
  v8PricesAsOf: (c) => (time) => c.t("widget.v8PricesAsOf", { time }),
1113
1122
  v8InjuryAsOf: (c) => (time) => c.t("widget.v8InjuryAsOf", { time }),
@@ -1301,9 +1310,29 @@ function parseOddsFormat(value) {
1301
1310
  const v = typeof value === "string" ? value.trim().toLowerCase() : "";
1302
1311
  return v === "decimal" || v === "american" || v === "fractional" ? v : void 0;
1303
1312
  }
1313
+ var CUSTOM_TOTAL_EXAMPLE = { decimal: "7.50", fractional: "13/2", american: "+650" };
1314
+ var roundCents = (x) => Math.round(x * 100 + 1e-9) / 100;
1315
+ function parseCustomTotal(text2, format2) {
1316
+ const t = text2.trim().replace(/\u2212/g, "-").replace(/^([+-]?\d+)[.,]$/, "$1");
1317
+ const point = /^(\d{0,9})[.,](\d{1,9})$/.exec(t);
1318
+ const whole = /^\d{1,12}$/.test(t);
1319
+ const fraction = format2 === "fractional" ? /^(\d{1,9})\s*\/\s*(\d{1,9})$/.exec(t) : null;
1320
+ const american = format2 === "american" ? /^([+-]?)(\d{1,12})$/.exec(t) : null;
1321
+ let value = null;
1322
+ if (point) value = Number(`${point[1] || "0"}.${point[2]}`);
1323
+ else if (format2 === "decimal" && whole) value = Number(t);
1324
+ else if (format2 === "fractional" && whole) value = 1 + Number(t);
1325
+ else if (format2 === "fractional" && /^ev(s|ens)$/i.test(t)) value = 2;
1326
+ else if (fraction && Number(fraction[2]) > 0) value = 1 + Number(fraction[1]) / Number(fraction[2]);
1327
+ else if (american && Number(american[2]) >= 100) value = american[1] === "-" ? 1 + 100 / Number(american[2]) : 1 + Number(american[2]) / 100;
1328
+ if (value === null) return { error: "unreadable" };
1329
+ const cents2 = roundCents(value);
1330
+ if (!(cents2 > 1.01 && cents2 <= 1e3)) return { error: "range" };
1331
+ return { decimal: cents2.toFixed(2), text: format2 === "fractional" && whole ? `${t}/1` : t };
1332
+ }
1304
1333
 
1305
1334
  // src/version.generated.ts
1306
- var WIDGET_REACT_VERSION = "0.141.0";
1335
+ var WIDGET_REACT_VERSION = "0.142.0";
1307
1336
 
1308
1337
  // src/config.ts
1309
1338
  function hostTag(cfg) {
@@ -1613,6 +1642,12 @@ function normalizeUi(cfg, loaded) {
1613
1642
  v8BuilderSingles: strings.v8BuilderSingles,
1614
1643
  v8BuilderTotal: strings.v8BuilderTotal,
1615
1644
  v8BuilderAny: strings.v8BuilderAny,
1645
+ v8BuilderCustomLabel: strings.v8BuilderCustomLabel,
1646
+ v8BuilderCustomPlaceholder: strings.v8BuilderCustomPlaceholder,
1647
+ v8BuilderCustomSet: strings.v8BuilderCustomSet,
1648
+ v8BuilderCustomRange: strings.v8BuilderCustomRange,
1649
+ v8BuilderCustomUnreadable: strings.v8BuilderCustomUnreadable,
1650
+ v8BuilderCustomEdit: strings.v8BuilderCustomEdit,
1616
1651
  v8BuilderLoading: strings.v8BuilderLoading,
1617
1652
  v8BuilderError: strings.v8BuilderError,
1618
1653
  v8BuilderRetry: strings.v8BuilderRetry,
@@ -17231,7 +17266,7 @@ function FavouritesSheet({ ui, controller, sport, sports, onSportChange, onClose
17231
17266
  }
17232
17267
 
17233
17268
  // src/components/dashboard/v8/SentenceBuilder.tsx
17234
- import { useEffect as useEffect54, useRef as useRef44, useState as useState80 } from "react";
17269
+ import { useEffect as useEffect54, useId as useId12, useRef as useRef44, useState as useState80 } from "react";
17235
17270
  import { Fragment as Fragment43, jsx as jsx141, jsxs as jsxs124 } from "react/jsx-runtime";
17236
17271
  var TOTALS = ["any", "3", "5", "10", "20", "50"];
17237
17272
  var BASE_LEGS = [1, 2, 3, 4];
@@ -17265,6 +17300,7 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17265
17300
  const openingView = {
17266
17301
  legs: preset.legs,
17267
17302
  total: asTotal(preset.totalTarget, totals),
17303
+ custom: null,
17268
17304
  // All markets opens unless the visitor has a usual market, which is never beaten.
17269
17305
  marketKey: marketOptions && !marketOptions.some((m) => m.usual) ? null : preset.marketKey,
17270
17306
  gamesId: opening.option?.id ?? null,
@@ -17281,11 +17317,38 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17281
17317
  matchIds: v.widen ? [] : v.matchIds,
17282
17318
  legs: v.legs,
17283
17319
  // 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.
17284
- total: v.legs === 1 ? "any" : v.total,
17320
+ total: v.legs === 1 ? "any" : v.custom?.decimal ?? v.total,
17285
17321
  widen: v.widen,
17286
17322
  ...operatorUserId ? { operatorUserId } : {},
17287
17323
  ...anonymousUserId ? { anonymousUserId } : {}
17288
17324
  });
17325
+ const [editing, setEditing] = useState80(false);
17326
+ const [draft, setDraft] = useState80("");
17327
+ const [invalid, setInvalid] = useState80(null);
17328
+ const inputRef = useRef44(null);
17329
+ const pencilRef = useRef44(null);
17330
+ const noteId = useId12();
17331
+ const customId = useId12();
17332
+ useEffect54(() => {
17333
+ if (editing) inputRef.current?.focus();
17334
+ }, [editing]);
17335
+ const customLabel = (c) => c.format === oddsFormat ? c.text : c.decimal;
17336
+ useEffect54(() => {
17337
+ if (view.legs === 1) {
17338
+ setEditing(false);
17339
+ setDraft("");
17340
+ setInvalid(null);
17341
+ }
17342
+ }, [view.legs]);
17343
+ const openCustom = () => {
17344
+ setDraft(view.custom ? customLabel(view.custom) : "");
17345
+ setInvalid(null);
17346
+ setEditing(true);
17347
+ };
17348
+ const closeCustom = () => {
17349
+ setEditing(false);
17350
+ pencilRef.current?.focus();
17351
+ };
17289
17352
  const [first] = useState80(() => requestFor(view));
17290
17353
  const { grid, status: status2, confirmed, request } = useBuilderGrid({ conversation, locale: ui.hostTag, memory: memory3, initial: first });
17291
17354
  const lastRequest = useRef44(first);
@@ -17307,6 +17370,18 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17307
17370
  commit(next, false);
17308
17371
  send(requestFor(next));
17309
17372
  };
17373
+ const setCustom = () => {
17374
+ const parsed = parseCustomTotal(draft, oddsFormat);
17375
+ if ("error" in parsed) {
17376
+ setInvalid(parsed.error);
17377
+ return;
17378
+ }
17379
+ closeCustom();
17380
+ setInvalid(null);
17381
+ const custom = { decimal: parsed.decimal, text: parsed.text, format: oddsFormat };
17382
+ if (view.custom?.decimal === parsed.decimal) commit({ ...view, custom }, widenedNote);
17383
+ else ask({ ...view, custom });
17384
+ };
17310
17385
  const allGames = gamesOptions?.find((o) => o.matchIds.length === 0) ?? null;
17311
17386
  const pickGames = (option) => {
17312
17387
  const next = { ...view, gamesId: option.id, matchIds: option.matchIds, widen: option.matchIds.length === 0 };
@@ -17340,7 +17415,7 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17340
17415
  const singles = view.legs === 1;
17341
17416
  const onOpeningChoice = view.marketKey === openingView.marketKey && view.widen === openingView.widen && view.gamesId === openingView.gamesId && sameIds(view.matchIds, openingView.matchIds);
17342
17417
  const quotedAt = rows ? oldestQuote(rows) : null;
17343
- const combo = ready && grid.total !== null ? { sport, totalChosen: view.total, totalActual: grid.total } : void 0;
17418
+ const combo = ready && grid.total !== null ? { sport, totalChosen: view.custom ? "custom" : view.total, totalActual: grid.total } : void 0;
17344
17419
  const canWiden = gamesOptions === null || allGames !== null;
17345
17420
  useEffect54(() => {
17346
17421
  if (!empty2 || !singles || widened || !canWiden || autoWidened.current) return;
@@ -17422,19 +17497,72 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17422
17497
  ] }),
17423
17498
  view.legs > 1 ? /* @__PURE__ */ jsxs124("div", { className: "ss-w-v8-builder-ln ss-w-v8-builder-ln--total", children: [
17424
17499
  /* @__PURE__ */ jsx141("span", { className: "ss-w-v8-builder-w", children: ui.v8BuilderTotal }),
17425
- /* @__PURE__ */ jsx141("div", { className: "ss-w-v8-builder-btns", role: "group", "aria-label": ui.v8BuilderTotal, children: totals.map((t) => /* @__PURE__ */ jsx141(
17426
- "button",
17427
- {
17428
- type: "button",
17429
- className: "ss-w-v8-builder-btn",
17430
- "aria-pressed": view.total === t,
17431
- onClick: () => {
17432
- if (view.total !== t) ask({ ...view, total: t });
17500
+ /* @__PURE__ */ jsxs124("div", { className: "ss-w-v8-builder-btns", role: "group", "aria-label": ui.v8BuilderTotal, children: [
17501
+ totals.map((t) => /* @__PURE__ */ jsx141(
17502
+ "button",
17503
+ {
17504
+ type: "button",
17505
+ className: "ss-w-v8-builder-btn",
17506
+ "aria-pressed": view.custom === null && view.total === t,
17507
+ onClick: () => {
17508
+ if (view.total !== t || view.custom) {
17509
+ setEditing(false);
17510
+ ask({ ...view, total: t, custom: null });
17511
+ }
17512
+ },
17513
+ children: totalLabel(t, preset.totalOptions, oddsFormat, ui)
17433
17514
  },
17434
- children: totalLabel(t, preset.totalOptions, oddsFormat, ui)
17435
- },
17436
- t
17437
- )) })
17515
+ t
17516
+ )),
17517
+ /* @__PURE__ */ jsx141(
17518
+ "button",
17519
+ {
17520
+ ref: pencilRef,
17521
+ type: "button",
17522
+ className: "ss-w-v8-builder-btn",
17523
+ "data-custom": true,
17524
+ "aria-pressed": view.custom !== null,
17525
+ "aria-expanded": editing,
17526
+ "aria-controls": editing ? customId : void 0,
17527
+ "aria-label": view.custom ? ui.v8BuilderCustomEdit(customLabel(view.custom)) : ui.v8BuilderCustomLabel,
17528
+ onClick: () => editing ? closeCustom() : openCustom(),
17529
+ children: view.custom ? customLabel(view.custom) : /* @__PURE__ */ jsx141(PencilIcon, {})
17530
+ }
17531
+ )
17532
+ ] }),
17533
+ editing ? /* @__PURE__ */ jsxs124("div", { id: customId, className: "ss-w-v8-builder-custom", children: [
17534
+ /* @__PURE__ */ jsx141(
17535
+ "input",
17536
+ {
17537
+ ref: inputRef,
17538
+ className: "ss-w-v8-builder-input",
17539
+ type: "text",
17540
+ inputMode: oddsFormat === "decimal" ? "decimal" : "text",
17541
+ maxLength: 12,
17542
+ value: draft,
17543
+ placeholder: ui.v8BuilderCustomPlaceholder(CUSTOM_TOTAL_EXAMPLE[oddsFormat]),
17544
+ "aria-label": ui.v8BuilderCustomLabel,
17545
+ "aria-invalid": invalid !== null,
17546
+ "aria-describedby": invalid ? noteId : void 0,
17547
+ onChange: (e) => {
17548
+ setDraft(e.target.value);
17549
+ setInvalid(null);
17550
+ },
17551
+ onKeyDown: (e) => {
17552
+ if (e.key === "Enter") {
17553
+ e.preventDefault();
17554
+ setCustom();
17555
+ } else if (e.key === "Escape") {
17556
+ e.preventDefault();
17557
+ e.stopPropagation();
17558
+ closeCustom();
17559
+ }
17560
+ }
17561
+ }
17562
+ ),
17563
+ /* @__PURE__ */ jsx141("button", { type: "button", className: "ss-w-v8-builder-btn", onClick: setCustom, children: ui.v8BuilderCustomSet }),
17564
+ invalid ? /* @__PURE__ */ jsx141("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
17565
+ ] }) : null
17438
17566
  ] }) : null,
17439
17567
  ready && singles && widenedNote && !empty2 ? /* @__PURE__ */ jsx141("p", { className: "ss-w-v8-builder-note", "data-kind": "widened", children: ui.v8SinglesWidened(marketName) }) : null,
17440
17568
  ready && !widenedNote && !empty2 && preset.widenedForMarket === true && onOpeningChoice && view.marketKey !== null ? /* @__PURE__ */ jsx141("p", { className: "ss-w-v8-builder-note", children: ui.v8Widened }) : null,
@@ -17466,6 +17594,12 @@ function SentenceBuilder({ preset, ui, conversation, memory: memory3, slip, spor
17466
17594
  ] }) : null
17467
17595
  ] }) : null });
17468
17596
  }
17597
+ function PencilIcon() {
17598
+ return /* @__PURE__ */ jsxs124("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: [
17599
+ /* @__PURE__ */ jsx141("path", { d: "M12 20h9" }),
17600
+ /* @__PURE__ */ jsx141("path", { d: "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" })
17601
+ ] });
17602
+ }
17469
17603
  function GamesOptions({ options, ui }) {
17470
17604
  const top = options.filter((o) => o.group !== "league" && o.group !== "game");
17471
17605
  const leagues = options.filter((o) => o.group === "league");
@@ -20101,9 +20235,18 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
20101
20235
  .ss-w-v8-builder-btn:disabled:not([aria-pressed="true"]) { opacity: .55; }
20102
20236
  .ss-w-v8-builder-btn[data-suggested]:not([aria-pressed="true"]) { border-style: dashed; border-color: var(--ss-v8-mint); }
20103
20237
  .ss-w-v8-builder button:focus-visible { outline: 2px solid var(--ss-v8-mint); outline-offset: 1px; }
20104
- .ss-w-v8-builder-ln--total > .ss-w-v8-builder-btns { display: grid; grid-template-columns: auto repeat(5, minmax(0, 1fr)); }
20105
- .ss-w-v8-builder-ln--total .ss-w-v8-builder-btn { min-width: 0; padding: 4px 2px; font-size: 13.5px; }
20106
- .ss-w-v8-builder-ln--total .ss-w-v8-builder-btn:first-child { padding: 4px 9px; }
20238
+ .ss-w-v8-builder-ln--total > .ss-w-v8-builder-btns { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
20239
+ .ss-w-v8-builder-ln--total .ss-w-v8-builder-btn { min-width: 0; padding: 4px 2px; font-size: 13.5px; overflow-wrap: normal; }
20240
+ .ss-w-v8-builder-ln--total .ss-w-v8-builder-btn:first-child { padding: 4px 9px; grid-column: span 2; }
20241
+ .ss-w-v8-builder-btn[data-custom] { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
20242
+ .ss-w-v8-builder-btn[data-custom] svg { width: 16px; height: 16px; vertical-align: middle; }
20243
+ .ss-w-v8-builder-custom { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 100%; box-sizing: border-box; padding-left: 84px; }
20244
+ .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; }
20245
+ .ss-w-v8-builder-input::placeholder { color: color-mix(in srgb, #fff 78%, var(--ss-w-nav)); opacity: 1; }
20246
+ .ss-w-v8-builder-custom > .ss-w-v8-builder-btn { flex: 0 0 auto; min-height: 40px; padding: 6px 14px; }
20247
+ .ss-w-v8-builder-input:focus-visible { outline: 2px solid var(--ss-v8-mint); outline-offset: 1px; }
20248
+ .ss-w-v8-builder-input[aria-invalid="true"] { border-color: #f2b8b5; }
20249
+ .ss-w-v8-builder-custom > .ss-w-v8-builder-note { flex: 1 1 100%; }
20107
20250
  .ss-w-v8-builder > .ss-w-v8-builder-btn { align-self: flex-start; min-height: 40px; padding: 6px 14px; }
20108
20251
  .ss-w-v8-builder .ss-w-slip-btn { min-height: 36px; }
20109
20252
  .ss-w-v8-builder .ss-w-combo-addall .ss-w-slip-btn { min-height: 44px; }
@@ -20118,10 +20261,7 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
20118
20261
  }
20119
20262
  @container (max-width: 400px) {
20120
20263
  .ss-w-v8-builder-ln--total .ss-w-v8-builder-w { flex-basis: 100%; }
20121
- }
20122
- /* Stacked, six targets still split "10.00" below this: three to a row, two rows. */
20123
- @container (max-width: 360px) {
20124
- .ss-w-v8-builder-ln--total > .ss-w-v8-builder-btns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
20264
+ .ss-w-v8-builder-custom { padding-left: 0; }
20125
20265
  }
20126
20266
 
20127
20267
  @media (prefers-reduced-motion: reduce) {