@magicx-eng/ai-autocomplete-vanilla 0.54.0 → 0.56.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/README.md CHANGED
@@ -15,6 +15,7 @@ A framework-agnostic vanilla JS/TypeScript library that provides a guided AI-pow
15
15
  - **Keyboard navigation** — arrow keys, enter to submit, tab to autocomplete, backspace to un-bold the last completed param
16
16
  - **Client-side filtering** — instant substring filtering on every keystroke
17
17
  - **Datepicker** — date parameters are answered with a calendar instead of an option list. Click a day or navigate with the arrow keys; the date is committed the way it would be written — `Tuesday` for a date inside the next week, `March 23` for one later this year, `March 23 2027` for another year. Tapping a committed date re-opens the calendar on the month that text names now — for a weekday name, that is the next such day, not the one originally picked. A date-range parameter gets the same calendar answered in two clicks, committed as one range.
18
+ - **Time picker** — time parameters are answered with a time wheel instead of an option list: three wheels (hour, minutes in fives, AM/PM) and a Done button. Scroll or tap the wheels, or press ↑ / ↓ in the input to move the time five minutes; Enter or Done commits it, written as `7:30 PM`. Tapping a committed time re-opens the wheel on it.
18
19
  - **Option overrides** — supply the options for a parameter yourself: a fixed list, a computed one, or one fetched from your own search endpoint as the user types
19
20
  - **Product strip** — the dropdown renders a horizontal row of product cards below the options, filled by default with the items the `/suggest` response reports as matching the query; plug in your own product search instead with `products`, or turn the strip off with `showProducts: false`
20
21
  - **Catalog report** — every response says which of the query's constraints the catalog applied, which it had to drop, and how many items are left, on `customFields` / `custom_fields`
@@ -300,8 +301,10 @@ new AIAutocomplete(container, {
300
301
 
301
302
  Return a promise to have the button show progress. It carries
302
303
  `data-aia-cart-state="adding"` while the promise is pending, then `"added"`
303
- (the cart glyph turns into a check) for a moment once it resolves. A rejection
304
- returns it to rest. Style it with
304
+ (the cart glyph turns into a check) once it resolves. The check stays until the
305
+ card's product changes (a price-only change keeps it); pressing it again adds
306
+ another unit, going back through `"adding"` to `"added"`. A rejection returns
307
+ it to rest. Style it with
305
308
  `--aia-product-cart-size` (28px), `--aia-product-cart-bg` and
306
309
  `--aia-product-cart-color`, or `[data-aia-product-cart]`. In the list layout
307
310
  the button sits at the row's right end. Headless consumers rendering
@@ -582,6 +585,60 @@ the prose. Re-editing one re-opens the calendar with both ends marked.
582
585
  a new query, so suggestions refresh as the user types — useful when someone
583
586
  would rather describe what they want than pick a day.
584
587
 
588
+ ### Time picker
589
+
590
+ When the next parameter is a time, the dropdown shows a time wheel instead of a
591
+ list of options. As with dates, which parameters are times is the server's call:
592
+ one whose `type` is `time` gets the wheel, and one without it keeps its option
593
+ list, however time-like its options look.
594
+
595
+ Nothing is required to switch it on. The options the server still sends for a
596
+ time parameter are never shown, but they choose where the wheel opens: on the
597
+ middle of the times suggested (`6 PM`, `7 PM`, `8 PM` opens on 7:00 PM), or on
598
+ the next whole hour when there are none.
599
+
600
+ **What the user can do**
601
+
602
+ | Input | Result |
603
+ |---|---|
604
+ | Scroll or tap a wheel | Turns that wheel; the time on the top rows is the time. Commits nothing |
605
+ | <kbd>↓</kbd> / <kbd>↑</kbd> in the input | Moves the time 5 minutes later / earlier |
606
+ | <kbd>Enter</kbd> | Commits the time — once the wheel has been moved. Until then it is only a suggestion, and Enter submits as usual |
607
+ | Done | Commits the time |
608
+ | <kbd>Esc</kbd> | Puts a moved wheel back on its suggested time |
609
+ | <kbd>→</kbd> at the end of the input | Skips the parameter, same as any other pill |
610
+
611
+ **The committed value** is written the way a person would write it, always in
612
+ English: `7:30 PM`, `12:05 AM`. It arrives as an ordinary completed parameter
613
+ (bold in the input, in `completed_params` on submit) with the server's lead-in
614
+ before it when there is one (`at 7:30 PM`). The exact time is also recorded on
615
+ the parameter's `metadata` as 24-hour `HH:MM` under the `TIME_META_KEY` key
616
+ (`aiaTime`), so you never have to parse the prose:
617
+
618
+ ```ts
619
+ import { parseTime, TIME_META_KEY } from "@magicx-eng/ai-autocomplete-vanilla";
620
+
621
+ const time = param.metadata?.[TIME_META_KEY]; // "19:30"
622
+ const minutes = parseTime(param.text); // 1170 — minutes since midnight, or null
623
+ ```
624
+
625
+ **Re-editing** a committed time re-opens the wheel on it.
626
+
627
+ **Typing** while the wheel is open does not filter anything. As with the
628
+ calendar, the text is treated as a new query.
629
+
630
+ ### Multiple selections
631
+
632
+ - A suggestion with `type: { kind: "multi_select" }` shows checkbox options and a Done button.
633
+ - Select rows to toggle values. Typing filters the options and keeps the current picks.
634
+ - Done joins the picks in selection order with the UI language's word for "and".
635
+ - Each value has its own `completed_params` entry. The input shows one chip for the group.
636
+ - Remove the group chip to change the answer. Group chips do not open for editing.
637
+ - Done without picks skips the question. Typing a phrase with no matching options closes the question and keeps that phrase.
638
+ - Space toggles the highlighted row when nothing is typed for the question. Enter commits the picks, or selects the highlighted row when no values are picked.
639
+ - Headless integrations can call `toggleMultiSelectOption(option)` and `commitMultiSelect()`.
640
+ - `multiSelectView.picked` contains the selected option texts. The view is null outside a multi_select question.
641
+
585
642
  ---
586
643
 
587
644
  ## Tier 2: Dropdown Only
@@ -973,6 +1030,12 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
973
1030
  | `--aia-date-today-ring` | `--aia-option-color` | `--aia-option-color` | Outline drawn around today's date. |
974
1031
  | `--aia-date-selected-bg` | white at 12% | white at 12% | Fill behind the date a re-edited parameter already holds. |
975
1032
  | `--aia-date-range-bg` | white at 6% | white at 6% | Band across the days between the two ends of a picked date range. The ends themselves use `--aia-date-selected-bg`. |
1033
+ | `--aia-time-panel-width` | `240px` | `240px` | Max width of the whole dropdown panel while the time wheel is up. |
1034
+ | `--aia-time-font-size` | `15px` | `15px` | The time wheel's numbers and its `:` separator. |
1035
+ | `--aia-time-band-bg` | white at 8% | white at 8% | The band behind the wheels' top rows — the chosen time. |
1036
+ | `--aia-time-done-bg` | white at 10% | white at 10% | The time wheel's Done button. |
1037
+ | `--aia-time-done-bg-hover` | white at 16% | white at 16% | The Done button on hover. |
1038
+ | `--aia-time-done-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | The Done button's text. |
976
1039
  | `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color for the loading skeleton bars and the masked text in cached pills/options, and of the option and chip image tiles while their picture loads (unless `--aia-option-image-bg` / `--aia-chip-image-bg` are set). |
977
1040
 
978
1041
  ### Per-mode Overrides
@@ -1022,6 +1085,7 @@ For styling beyond the CSS variables, target these stable `data-aia-*` attribute
1022
1085
  | `[data-aia-scroll-arrow]` | The "more below" arrow on the dropdown — carries `data-aia-visible` while shown |
1023
1086
  | `[data-aia-dropdown]` | The dropdown root (listbox). Carries `data-aia-has-products` while the product strip has cards, and `data-aia-fit` while it is fitted to a short screen (see [Short screens](#short-screens)). |
1024
1087
  | `[data-aia-datepicker]` | The calendar, rendered in place of the option list for a date parameter |
1088
+ | `[data-aia-time-wheel]` | The time wheel, rendered in place of the option list for a time parameter |
1025
1089
  | `[data-aia-date-month]` | The "March 2026" header label |
1026
1090
  | `[data-aia-date-prev]` / `[data-aia-date-next]` | The month arrows |
1027
1091
  | `[data-aia-date-grid]` | The 7-column grid of day cells |
package/dist/index.d.mts CHANGED
@@ -70,12 +70,12 @@ interface SuggestionOption {
70
70
  }
71
71
  /**
72
72
  * The value type of a parameter — which picker it needs. The server sends it
73
- * for every date or date-range parameter; a parameter without one is answered
74
- * from its options.
73
+ * for every date, date-range or time parameter; a parameter without one is
74
+ * answered from its options.
75
75
  */
76
76
  interface SuggestionType {
77
77
  /** `traditional_autocomplete` marks a suggestion whose options complete the word being typed; it is never a pill. */
78
- kind: "string" | "numeric" | "date" | "date_range" | "boolean" | "traditional_autocomplete";
78
+ kind: "string" | "numeric" | "date" | "date_range" | "time" | "multi_select" | "boolean" | "traditional_autocomplete";
79
79
  /** How a date is written, e.g. "DD/MM/YYYY". */
80
80
  date_format?: string;
81
81
  /** What joins the two dates of a range, e.g. " to ". */
@@ -308,6 +308,8 @@ interface CustomFieldsReport {
308
308
  items: MatchedItems;
309
309
  }
310
310
  interface CompletedParamState extends CompletedParam {
311
+ /** Client-only identity for values committed together. */
312
+ group?: string;
311
313
  id: string;
312
314
  text: string;
313
315
  /** The originating option's `value` (see {@link SuggestionOption.value}), carried over so `toWireParam` can send it instead of the shortened `text`. */
@@ -381,6 +383,7 @@ type Segment = {
381
383
  type: "completed";
382
384
  value: string;
383
385
  param: CompletedParamState;
386
+ params?: CompletedParamState[];
384
387
  } | {
385
388
  type: "identified";
386
389
  value: string;
@@ -668,10 +671,18 @@ declare function cellDay(option: SuggestionOption | undefined): number | null;
668
671
  * options, or type to filter them. `"date"` ignores the options entirely and
669
672
  * renders a calendar instead. `"date-range"` renders the same calendar,
670
673
  * answered in two taps — a start and an end — and committed as one span.
674
+ * `"time"` ignores the options the same way and renders the time wheel.
671
675
  */
672
- type FormatType = "options" | "date" | "date-range";
676
+ type FormatType = "options" | "date" | "date-range" | "time";
673
677
  /** Whether this format is answered by a calendar rather than by a list. */
674
678
  declare function isCalendarFormat(format: FormatType): boolean;
679
+ /**
680
+ * Whether this format is answered by a picker the SDK draws (a calendar or the
681
+ * time wheel) rather than by the suggestion's options. The server still sends
682
+ * options for such a pill, so anything that reasons about options — filtering,
683
+ * exact-match promotion, the request gates, telemetry — has to ask this first.
684
+ */
685
+ declare function isPickerFormat(format: FormatType): boolean;
675
686
  /**
676
687
  * Decide how a parameter should be answered — from the value type the server
677
688
  * names on it, and nothing else.
@@ -690,6 +701,70 @@ declare function resolveFormatType(source: {
690
701
  type?: SuggestionType;
691
702
  } | undefined | null): FormatType;
692
703
 
704
+ /**
705
+ * Time-of-day helpers for the time wheel.
706
+ *
707
+ * A time is carried as minutes since midnight (0–1439) everywhere inside the
708
+ * SDK. It is turned into text only at the edges: the wheel's labels, and the
709
+ * committed answer, which is written the way a person would write it ("7:30
710
+ * PM") — always in English, like the datepicker's committed dates, so the value
711
+ * a consumer receives has one vocabulary everywhere. The exact value rides
712
+ * along on the completed param's `metadata` as `HH:MM` under
713
+ * {@link TIME_META_KEY}, so nobody has to parse the prose back.
714
+ */
715
+ /** `metadata` key holding a committed time as 24-hour `HH:MM`. */
716
+ declare const TIME_META_KEY = "aiaTime";
717
+ /** The minute wheel's step. A time between steps snaps to the nearest one. */
718
+ declare const TIME_STEP_MINUTES = 5;
719
+ type TimePeriod = "AM" | "PM";
720
+ /** A time split the way the wheels show it. */
721
+ interface TimeParts {
722
+ /** 1–12. */
723
+ hour: number;
724
+ /** 0–59. */
725
+ minute: number;
726
+ period: TimePeriod;
727
+ }
728
+ /**
729
+ * What the time wheel shows: the time on its top row, and whether the user has
730
+ * moved it. An untouched wheel is only a suggestion, so Enter in the input
731
+ * still submits; a touched one is an answer in progress, so Enter commits it.
732
+ */
733
+ interface TimeView {
734
+ minutes: number;
735
+ touched: boolean;
736
+ }
737
+ /** "7:30 PM", "12:05 AM". */
738
+ declare function formatTime(minutes: number): string;
739
+ /** 24-hour `HH:MM` — the exact value stored under {@link TIME_META_KEY}. */
740
+ declare function isoTime(minutes: number): string;
741
+ /**
742
+ * Read a time a person or a server wrote: "7 PM", "7:30pm", "7:30 p.m.",
743
+ * "19:30", "noon", "midnight". Null for anything else — never a guess, so
744
+ * "7" alone (morning or evening?) is null.
745
+ */
746
+ declare function parseTime(text: string | null | undefined): number | null;
747
+ /**
748
+ * The option a committed time is answered with. It goes through the same
749
+ * `selectOption` path as a tapped option, so lead-ins, re-edit and the
750
+ * follow-up request all behave exactly as they do for any other answer.
751
+ */
752
+ declare function buildTimeOption(minutes: number): SuggestionOption;
753
+ /** One wheel row's height in px. Must match `--aia-time-row-height` in every stylesheet copy. */
754
+ declare const TIME_WHEEL_ROW_HEIGHT = 30;
755
+ type TimeWheelColumn = "hour" | "minute" | "period";
756
+ declare const TIME_WHEEL_COLUMNS: readonly TimeWheelColumn[];
757
+ interface TimeWheelRow {
758
+ label: string;
759
+ }
760
+ declare function timeWheelRows(column: TimeWheelColumn): readonly TimeWheelRow[];
761
+ /** The row `minutes` puts on top of `column`. */
762
+ declare function timeWheelIndex(column: TimeWheelColumn, minutes: number): number;
763
+ /** The time after `column` is turned to row `index`, the other two wheels unchanged. */
764
+ declare function withTimeWheelIndex(column: TimeWheelColumn, minutes: number, index: number): number;
765
+ /** The row a column scrolled to `scrollTop` has settled on. */
766
+ declare function timeWheelIndexFromScroll(column: TimeWheelColumn, scrollTop: number): number;
767
+
693
768
  /**
694
769
  * Raw, user/network/internal-driven fields. The store holds *only* these —
695
770
  * derived state is recomputed lazily on read. See {@link CoreDerivedState}.
@@ -856,6 +931,24 @@ interface CoreInputState {
856
931
  iso: string;
857
932
  key: string;
858
933
  } | null;
934
+ /**
935
+ * The time the user has moved the time wheel to, as minutes since midnight,
936
+ * or null while it still shows its suggested starting time. Surfaces to
937
+ * readers as the derived `timeView`.
938
+ *
939
+ * `key` scopes it to the pill it was set for, exactly like `dateViewMonth`
940
+ * (see `dateViewKey`): a stale key is ignored, so the next time pill opens on
941
+ * its own starting time without any flow having to reset this.
942
+ */
943
+ timeDraft: {
944
+ minutes: number;
945
+ key: string;
946
+ } | null;
947
+ /** Picks for the active question, scoped by dateViewKey. */
948
+ multiSelectDraft: {
949
+ picked: string[];
950
+ key: string;
951
+ } | null;
859
952
  /**
860
953
  * Set while the user is picking a date for a span the server identified as
861
954
  * one — "september 5th" in "fly to vegas on september 5th".
@@ -934,6 +1027,15 @@ interface CoreDerivedState {
934
1027
  * first. The calendars paint the span between it and the highlighted cell.
935
1028
  */
936
1029
  dateRangeStart: string | null;
1030
+ /**
1031
+ * What the time wheel shows. Null unless `activeFormatType` is `"time"`.
1032
+ * `touched` is false while it still shows its suggested starting time.
1033
+ */
1034
+ timeView: TimeView | null;
1035
+ /** Selected option texts in pick order. Null outside a multi_select question. */
1036
+ multiSelectView: {
1037
+ picked: string[];
1038
+ } | null;
937
1039
  placeholderText: string;
938
1040
  /**
939
1041
  * The phrase the active pill's options are filtered by — what the user has
@@ -1196,8 +1298,10 @@ interface CoreOptions {
1196
1298
  * touches a cart itself; the integration does the adding.
1197
1299
  *
1198
1300
  * Return a promise to have the button show progress. It carries
1199
- * `data-aia-cart-state="adding"` until the promise settles, then `"added"` for
1200
- * a moment if it resolved. A rejection puts the button back at rest.
1301
+ * `data-aia-cart-state="adding"` until the promise settles, then `"added"` if
1302
+ * it resolved. `"added"` stays until the card's product changes; pressing
1303
+ * again adds another unit (adding → added again). A rejection puts the button
1304
+ * back at rest.
1201
1305
  */
1202
1306
  onProductAddToCart?: (product: Product) => void | PromiseLike<unknown>;
1203
1307
  value?: string;
@@ -1437,6 +1541,22 @@ declare class AIAutocomplete {
1437
1541
  * its own default month with nothing having to clear this.
1438
1542
  */
1439
1543
  private pageDateView;
1544
+ /**
1545
+ * Move the time wheel to `minutes` past midnight, snapped to its 5-minute
1546
+ * step. No-op unless a time pill is active. Moving the wheel commits nothing:
1547
+ * `commitTime` (the wheel's Done button, or Enter in the input once the wheel
1548
+ * has been moved) answers the pill.
1549
+ */
1550
+ setTime(minutes: number): void;
1551
+ /** Move the time wheel by `delta` minutes (ArrowDown / ArrowUp step by 5). No-op unless a time pill is active. */
1552
+ stepTime(delta: number): void;
1553
+ /** Toggle an option without completing the question or sending a request. */
1554
+ toggleMultiSelectOption(option: SuggestionOption): void;
1555
+ /** Complete the selected values, or skip the question when no values are selected. */
1556
+ commitMultiSelect(): void;
1557
+ private finishMultiSelect;
1558
+ /** Answer the active time pill with the time on the wheel. */
1559
+ commitTime(): void;
1440
1560
  /**
1441
1561
  * Skip the currently active pill (always index 0 of the actionable
1442
1562
  * suggestions) and promote the next pill to active. Invoked by ArrowRight at
@@ -2261,6 +2381,7 @@ declare function renderEditableContent(args: RenderEditableArgs): void;
2261
2381
 
2262
2382
  declare const en: {
2263
2383
  language: string;
2384
+ and: string;
2264
2385
  proceed: string;
2265
2386
  select: string;
2266
2387
  skipHint: string;
@@ -2272,6 +2393,8 @@ declare const en: {
2272
2393
  submit: string;
2273
2394
  scrollArrow: string;
2274
2395
  keepTyping: string;
2396
+ done: string;
2397
+ timeLabel: string;
2275
2398
  };
2276
2399
  type UIStrings = typeof en;
2277
2400
  declare function uiStringsFor(language?: string): UIStrings;
@@ -2734,4 +2857,4 @@ declare const SMART_SUGGESTION_SPARKLE_SVG: string;
2734
2857
  /** True when some pill is a question the shopper can decline. */
2735
2858
  declare function hasSkippablePill(suggestions: Suggestion[]): boolean;
2736
2859
 
2737
- export { AIAutocomplete, type APIConfig, type APIKeyConfig, ATTRIBUTION_URL, type AccessTokenConfig, type AccessTokenResult, type AppearanceMode, type AutocompleteRequest, type AutocompleteResponse, type AutocompleteResult, type CompletedParam, type CompletedParamState, type CoreOptions, type CoreState, type CurrencyOptions, type CustomFieldsReport, DATE_RANGE_META_END, DATE_RANGE_META_START, DEFAULT_OPTION_COUNT_UNIT, type DateMonthView, type DateRange, type DateSelection, type ExpressedFilter, type FilterOp, type FormatType, type IdentifiedParam, type IdentifiedParamState, type InputItem, type LooseDateOptions, type MatchedItem, type MatchedItems, ModeController, OPTIONS_GRID_MOBILE_QUERY, OPTION_ENTER_DELAY_VAR, OPTION_ENTER_FADE_MS, OPTION_ENTER_RISE_MS, OPTION_ENTER_RISE_PX, OPTION_ENTER_STAGGER_MS, OPTION_IMAGE_WIDTH, type OptionOverride, type OptionOverrides, type OptionsGridLayout, type OptionsGridPlan, PLACEHOLDER_FADE_OUT_MS, PLACEHOLDER_LEAVING_ATTR, PLACEHOLDER_SWAP_GAP_MS, PLACEHOLDER_TYPE_MS, PLACEHOLDER_WORD_PAUSE_MS, PRODUCT_IMAGE_WIDTH, PRODUCT_PATH_PREFIX, PRODUCT_ROW_PX_PER_LINE, type PhraseMatch, type Product, type ProductImageFallback, type ProductRowMetrics, type ProductRowWheel, type ProductsConfig, type ProductsLayout, RANGE_SEPARATOR, type RecentlySuggested, type RenderMode, SCHEMA_VERSION, SCROLL_ARROW_ATTR, SCROLL_ARROW_BOTTOM_VAR, SCROLL_ARROW_CLASS, SCROLL_ARROW_FADE_MS, SCROLL_ARROW_LABEL, SCROLL_ARROW_SCROLL_IDLE_MS, SCROLL_ARROW_VISIBLE_ATTR, SKIPPED_PARAM_TEXT, SMART_SUGGESTION_SPARKLE_SVG, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type SuggestionType, type TaskKind, type TextPart, type UIStrings, VIEWPORT_FIT_ATTR, VIEWPORT_FIT_HEIGHT_VAR, type ViewportFitArgs, type ViewportFitController, WEEKDAY_LABELS, addMonths, attachProductRowWheel, attachScrollArrow, attachViewportFit, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateSelectionFor, extractPlainText, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, getCursorOffset, getFooterHint, hasSkippablePill, highlightParts, identifiedParamLabel, isCalendarFormat, isOptionsGridMobileViewport, isSmartSuggestion, isTraditionalAutocompleteSuggestion, isoDate, keepCaretOnChip, labelTraditionalAutocomplete, matchTypedPhrase, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, optionsShowLeadingVisuals, parseDate, parseLooseDate, parseLooseDateRange, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productImageSources, productImageSrc, productInitial, productPhotoFill, productRowWheelTarget, productsFromCustomFields, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, shopifyImageSrc, toWireIdentifiedParams, typedFragment, uiStringsFor, visibleDateRange, withSkippedParams, withoutTraditionalAutocomplete };
2860
+ export { AIAutocomplete, type APIConfig, type APIKeyConfig, ATTRIBUTION_URL, type AccessTokenConfig, type AccessTokenResult, type AppearanceMode, type AutocompleteRequest, type AutocompleteResponse, type AutocompleteResult, type CompletedParam, type CompletedParamState, type CoreOptions, type CoreState, type CurrencyOptions, type CustomFieldsReport, DATE_RANGE_META_END, DATE_RANGE_META_START, DEFAULT_OPTION_COUNT_UNIT, type DateMonthView, type DateRange, type DateSelection, type ExpressedFilter, type FilterOp, type FormatType, type IdentifiedParam, type IdentifiedParamState, type InputItem, type LooseDateOptions, type MatchedItem, type MatchedItems, ModeController, OPTIONS_GRID_MOBILE_QUERY, OPTION_ENTER_DELAY_VAR, OPTION_ENTER_FADE_MS, OPTION_ENTER_RISE_MS, OPTION_ENTER_RISE_PX, OPTION_ENTER_STAGGER_MS, OPTION_IMAGE_WIDTH, type OptionOverride, type OptionOverrides, type OptionsGridLayout, type OptionsGridPlan, PLACEHOLDER_FADE_OUT_MS, PLACEHOLDER_LEAVING_ATTR, PLACEHOLDER_SWAP_GAP_MS, PLACEHOLDER_TYPE_MS, PLACEHOLDER_WORD_PAUSE_MS, PRODUCT_IMAGE_WIDTH, PRODUCT_PATH_PREFIX, PRODUCT_ROW_PX_PER_LINE, type PhraseMatch, type Product, type ProductImageFallback, type ProductRowMetrics, type ProductRowWheel, type ProductsConfig, type ProductsLayout, RANGE_SEPARATOR, type RecentlySuggested, type RenderMode, SCHEMA_VERSION, SCROLL_ARROW_ATTR, SCROLL_ARROW_BOTTOM_VAR, SCROLL_ARROW_CLASS, SCROLL_ARROW_FADE_MS, SCROLL_ARROW_LABEL, SCROLL_ARROW_SCROLL_IDLE_MS, SCROLL_ARROW_VISIBLE_ATTR, SKIPPED_PARAM_TEXT, SMART_SUGGESTION_SPARKLE_SVG, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type SuggestionType, TIME_META_KEY, TIME_STEP_MINUTES, TIME_WHEEL_COLUMNS, TIME_WHEEL_ROW_HEIGHT, type TaskKind, type TextPart, type TimeParts, type TimePeriod, type TimeView, type TimeWheelColumn, type TimeWheelRow, type UIStrings, VIEWPORT_FIT_ATTR, VIEWPORT_FIT_HEIGHT_VAR, type ViewportFitArgs, type ViewportFitController, WEEKDAY_LABELS, addMonths, attachProductRowWheel, attachScrollArrow, attachViewportFit, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, buildTimeOption, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateSelectionFor, extractPlainText, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, formatTime, getCursorOffset, getFooterHint, hasSkippablePill, highlightParts, identifiedParamLabel, isCalendarFormat, isOptionsGridMobileViewport, isPickerFormat, isSmartSuggestion, isTraditionalAutocompleteSuggestion, isoDate, isoTime, keepCaretOnChip, labelTraditionalAutocomplete, matchTypedPhrase, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, optionsShowLeadingVisuals, parseDate, parseLooseDate, parseLooseDateRange, parseTime, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productImageSources, productImageSrc, productInitial, productPhotoFill, productRowWheelTarget, productsFromCustomFields, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, shopifyImageSrc, timeWheelIndex, timeWheelIndexFromScroll, timeWheelRows, toWireIdentifiedParams, typedFragment, uiStringsFor, visibleDateRange, withSkippedParams, withTimeWheelIndex, withoutTraditionalAutocomplete };
package/dist/index.d.ts CHANGED
@@ -70,12 +70,12 @@ interface SuggestionOption {
70
70
  }
71
71
  /**
72
72
  * The value type of a parameter — which picker it needs. The server sends it
73
- * for every date or date-range parameter; a parameter without one is answered
74
- * from its options.
73
+ * for every date, date-range or time parameter; a parameter without one is
74
+ * answered from its options.
75
75
  */
76
76
  interface SuggestionType {
77
77
  /** `traditional_autocomplete` marks a suggestion whose options complete the word being typed; it is never a pill. */
78
- kind: "string" | "numeric" | "date" | "date_range" | "boolean" | "traditional_autocomplete";
78
+ kind: "string" | "numeric" | "date" | "date_range" | "time" | "multi_select" | "boolean" | "traditional_autocomplete";
79
79
  /** How a date is written, e.g. "DD/MM/YYYY". */
80
80
  date_format?: string;
81
81
  /** What joins the two dates of a range, e.g. " to ". */
@@ -308,6 +308,8 @@ interface CustomFieldsReport {
308
308
  items: MatchedItems;
309
309
  }
310
310
  interface CompletedParamState extends CompletedParam {
311
+ /** Client-only identity for values committed together. */
312
+ group?: string;
311
313
  id: string;
312
314
  text: string;
313
315
  /** The originating option's `value` (see {@link SuggestionOption.value}), carried over so `toWireParam` can send it instead of the shortened `text`. */
@@ -381,6 +383,7 @@ type Segment = {
381
383
  type: "completed";
382
384
  value: string;
383
385
  param: CompletedParamState;
386
+ params?: CompletedParamState[];
384
387
  } | {
385
388
  type: "identified";
386
389
  value: string;
@@ -668,10 +671,18 @@ declare function cellDay(option: SuggestionOption | undefined): number | null;
668
671
  * options, or type to filter them. `"date"` ignores the options entirely and
669
672
  * renders a calendar instead. `"date-range"` renders the same calendar,
670
673
  * answered in two taps — a start and an end — and committed as one span.
674
+ * `"time"` ignores the options the same way and renders the time wheel.
671
675
  */
672
- type FormatType = "options" | "date" | "date-range";
676
+ type FormatType = "options" | "date" | "date-range" | "time";
673
677
  /** Whether this format is answered by a calendar rather than by a list. */
674
678
  declare function isCalendarFormat(format: FormatType): boolean;
679
+ /**
680
+ * Whether this format is answered by a picker the SDK draws (a calendar or the
681
+ * time wheel) rather than by the suggestion's options. The server still sends
682
+ * options for such a pill, so anything that reasons about options — filtering,
683
+ * exact-match promotion, the request gates, telemetry — has to ask this first.
684
+ */
685
+ declare function isPickerFormat(format: FormatType): boolean;
675
686
  /**
676
687
  * Decide how a parameter should be answered — from the value type the server
677
688
  * names on it, and nothing else.
@@ -690,6 +701,70 @@ declare function resolveFormatType(source: {
690
701
  type?: SuggestionType;
691
702
  } | undefined | null): FormatType;
692
703
 
704
+ /**
705
+ * Time-of-day helpers for the time wheel.
706
+ *
707
+ * A time is carried as minutes since midnight (0–1439) everywhere inside the
708
+ * SDK. It is turned into text only at the edges: the wheel's labels, and the
709
+ * committed answer, which is written the way a person would write it ("7:30
710
+ * PM") — always in English, like the datepicker's committed dates, so the value
711
+ * a consumer receives has one vocabulary everywhere. The exact value rides
712
+ * along on the completed param's `metadata` as `HH:MM` under
713
+ * {@link TIME_META_KEY}, so nobody has to parse the prose back.
714
+ */
715
+ /** `metadata` key holding a committed time as 24-hour `HH:MM`. */
716
+ declare const TIME_META_KEY = "aiaTime";
717
+ /** The minute wheel's step. A time between steps snaps to the nearest one. */
718
+ declare const TIME_STEP_MINUTES = 5;
719
+ type TimePeriod = "AM" | "PM";
720
+ /** A time split the way the wheels show it. */
721
+ interface TimeParts {
722
+ /** 1–12. */
723
+ hour: number;
724
+ /** 0–59. */
725
+ minute: number;
726
+ period: TimePeriod;
727
+ }
728
+ /**
729
+ * What the time wheel shows: the time on its top row, and whether the user has
730
+ * moved it. An untouched wheel is only a suggestion, so Enter in the input
731
+ * still submits; a touched one is an answer in progress, so Enter commits it.
732
+ */
733
+ interface TimeView {
734
+ minutes: number;
735
+ touched: boolean;
736
+ }
737
+ /** "7:30 PM", "12:05 AM". */
738
+ declare function formatTime(minutes: number): string;
739
+ /** 24-hour `HH:MM` — the exact value stored under {@link TIME_META_KEY}. */
740
+ declare function isoTime(minutes: number): string;
741
+ /**
742
+ * Read a time a person or a server wrote: "7 PM", "7:30pm", "7:30 p.m.",
743
+ * "19:30", "noon", "midnight". Null for anything else — never a guess, so
744
+ * "7" alone (morning or evening?) is null.
745
+ */
746
+ declare function parseTime(text: string | null | undefined): number | null;
747
+ /**
748
+ * The option a committed time is answered with. It goes through the same
749
+ * `selectOption` path as a tapped option, so lead-ins, re-edit and the
750
+ * follow-up request all behave exactly as they do for any other answer.
751
+ */
752
+ declare function buildTimeOption(minutes: number): SuggestionOption;
753
+ /** One wheel row's height in px. Must match `--aia-time-row-height` in every stylesheet copy. */
754
+ declare const TIME_WHEEL_ROW_HEIGHT = 30;
755
+ type TimeWheelColumn = "hour" | "minute" | "period";
756
+ declare const TIME_WHEEL_COLUMNS: readonly TimeWheelColumn[];
757
+ interface TimeWheelRow {
758
+ label: string;
759
+ }
760
+ declare function timeWheelRows(column: TimeWheelColumn): readonly TimeWheelRow[];
761
+ /** The row `minutes` puts on top of `column`. */
762
+ declare function timeWheelIndex(column: TimeWheelColumn, minutes: number): number;
763
+ /** The time after `column` is turned to row `index`, the other two wheels unchanged. */
764
+ declare function withTimeWheelIndex(column: TimeWheelColumn, minutes: number, index: number): number;
765
+ /** The row a column scrolled to `scrollTop` has settled on. */
766
+ declare function timeWheelIndexFromScroll(column: TimeWheelColumn, scrollTop: number): number;
767
+
693
768
  /**
694
769
  * Raw, user/network/internal-driven fields. The store holds *only* these —
695
770
  * derived state is recomputed lazily on read. See {@link CoreDerivedState}.
@@ -856,6 +931,24 @@ interface CoreInputState {
856
931
  iso: string;
857
932
  key: string;
858
933
  } | null;
934
+ /**
935
+ * The time the user has moved the time wheel to, as minutes since midnight,
936
+ * or null while it still shows its suggested starting time. Surfaces to
937
+ * readers as the derived `timeView`.
938
+ *
939
+ * `key` scopes it to the pill it was set for, exactly like `dateViewMonth`
940
+ * (see `dateViewKey`): a stale key is ignored, so the next time pill opens on
941
+ * its own starting time without any flow having to reset this.
942
+ */
943
+ timeDraft: {
944
+ minutes: number;
945
+ key: string;
946
+ } | null;
947
+ /** Picks for the active question, scoped by dateViewKey. */
948
+ multiSelectDraft: {
949
+ picked: string[];
950
+ key: string;
951
+ } | null;
859
952
  /**
860
953
  * Set while the user is picking a date for a span the server identified as
861
954
  * one — "september 5th" in "fly to vegas on september 5th".
@@ -934,6 +1027,15 @@ interface CoreDerivedState {
934
1027
  * first. The calendars paint the span between it and the highlighted cell.
935
1028
  */
936
1029
  dateRangeStart: string | null;
1030
+ /**
1031
+ * What the time wheel shows. Null unless `activeFormatType` is `"time"`.
1032
+ * `touched` is false while it still shows its suggested starting time.
1033
+ */
1034
+ timeView: TimeView | null;
1035
+ /** Selected option texts in pick order. Null outside a multi_select question. */
1036
+ multiSelectView: {
1037
+ picked: string[];
1038
+ } | null;
937
1039
  placeholderText: string;
938
1040
  /**
939
1041
  * The phrase the active pill's options are filtered by — what the user has
@@ -1196,8 +1298,10 @@ interface CoreOptions {
1196
1298
  * touches a cart itself; the integration does the adding.
1197
1299
  *
1198
1300
  * Return a promise to have the button show progress. It carries
1199
- * `data-aia-cart-state="adding"` until the promise settles, then `"added"` for
1200
- * a moment if it resolved. A rejection puts the button back at rest.
1301
+ * `data-aia-cart-state="adding"` until the promise settles, then `"added"` if
1302
+ * it resolved. `"added"` stays until the card's product changes; pressing
1303
+ * again adds another unit (adding → added again). A rejection puts the button
1304
+ * back at rest.
1201
1305
  */
1202
1306
  onProductAddToCart?: (product: Product) => void | PromiseLike<unknown>;
1203
1307
  value?: string;
@@ -1437,6 +1541,22 @@ declare class AIAutocomplete {
1437
1541
  * its own default month with nothing having to clear this.
1438
1542
  */
1439
1543
  private pageDateView;
1544
+ /**
1545
+ * Move the time wheel to `minutes` past midnight, snapped to its 5-minute
1546
+ * step. No-op unless a time pill is active. Moving the wheel commits nothing:
1547
+ * `commitTime` (the wheel's Done button, or Enter in the input once the wheel
1548
+ * has been moved) answers the pill.
1549
+ */
1550
+ setTime(minutes: number): void;
1551
+ /** Move the time wheel by `delta` minutes (ArrowDown / ArrowUp step by 5). No-op unless a time pill is active. */
1552
+ stepTime(delta: number): void;
1553
+ /** Toggle an option without completing the question or sending a request. */
1554
+ toggleMultiSelectOption(option: SuggestionOption): void;
1555
+ /** Complete the selected values, or skip the question when no values are selected. */
1556
+ commitMultiSelect(): void;
1557
+ private finishMultiSelect;
1558
+ /** Answer the active time pill with the time on the wheel. */
1559
+ commitTime(): void;
1440
1560
  /**
1441
1561
  * Skip the currently active pill (always index 0 of the actionable
1442
1562
  * suggestions) and promote the next pill to active. Invoked by ArrowRight at
@@ -2261,6 +2381,7 @@ declare function renderEditableContent(args: RenderEditableArgs): void;
2261
2381
 
2262
2382
  declare const en: {
2263
2383
  language: string;
2384
+ and: string;
2264
2385
  proceed: string;
2265
2386
  select: string;
2266
2387
  skipHint: string;
@@ -2272,6 +2393,8 @@ declare const en: {
2272
2393
  submit: string;
2273
2394
  scrollArrow: string;
2274
2395
  keepTyping: string;
2396
+ done: string;
2397
+ timeLabel: string;
2275
2398
  };
2276
2399
  type UIStrings = typeof en;
2277
2400
  declare function uiStringsFor(language?: string): UIStrings;
@@ -2734,4 +2857,4 @@ declare const SMART_SUGGESTION_SPARKLE_SVG: string;
2734
2857
  /** True when some pill is a question the shopper can decline. */
2735
2858
  declare function hasSkippablePill(suggestions: Suggestion[]): boolean;
2736
2859
 
2737
- export { AIAutocomplete, type APIConfig, type APIKeyConfig, ATTRIBUTION_URL, type AccessTokenConfig, type AccessTokenResult, type AppearanceMode, type AutocompleteRequest, type AutocompleteResponse, type AutocompleteResult, type CompletedParam, type CompletedParamState, type CoreOptions, type CoreState, type CurrencyOptions, type CustomFieldsReport, DATE_RANGE_META_END, DATE_RANGE_META_START, DEFAULT_OPTION_COUNT_UNIT, type DateMonthView, type DateRange, type DateSelection, type ExpressedFilter, type FilterOp, type FormatType, type IdentifiedParam, type IdentifiedParamState, type InputItem, type LooseDateOptions, type MatchedItem, type MatchedItems, ModeController, OPTIONS_GRID_MOBILE_QUERY, OPTION_ENTER_DELAY_VAR, OPTION_ENTER_FADE_MS, OPTION_ENTER_RISE_MS, OPTION_ENTER_RISE_PX, OPTION_ENTER_STAGGER_MS, OPTION_IMAGE_WIDTH, type OptionOverride, type OptionOverrides, type OptionsGridLayout, type OptionsGridPlan, PLACEHOLDER_FADE_OUT_MS, PLACEHOLDER_LEAVING_ATTR, PLACEHOLDER_SWAP_GAP_MS, PLACEHOLDER_TYPE_MS, PLACEHOLDER_WORD_PAUSE_MS, PRODUCT_IMAGE_WIDTH, PRODUCT_PATH_PREFIX, PRODUCT_ROW_PX_PER_LINE, type PhraseMatch, type Product, type ProductImageFallback, type ProductRowMetrics, type ProductRowWheel, type ProductsConfig, type ProductsLayout, RANGE_SEPARATOR, type RecentlySuggested, type RenderMode, SCHEMA_VERSION, SCROLL_ARROW_ATTR, SCROLL_ARROW_BOTTOM_VAR, SCROLL_ARROW_CLASS, SCROLL_ARROW_FADE_MS, SCROLL_ARROW_LABEL, SCROLL_ARROW_SCROLL_IDLE_MS, SCROLL_ARROW_VISIBLE_ATTR, SKIPPED_PARAM_TEXT, SMART_SUGGESTION_SPARKLE_SVG, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type SuggestionType, type TaskKind, type TextPart, type UIStrings, VIEWPORT_FIT_ATTR, VIEWPORT_FIT_HEIGHT_VAR, type ViewportFitArgs, type ViewportFitController, WEEKDAY_LABELS, addMonths, attachProductRowWheel, attachScrollArrow, attachViewportFit, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateSelectionFor, extractPlainText, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, getCursorOffset, getFooterHint, hasSkippablePill, highlightParts, identifiedParamLabel, isCalendarFormat, isOptionsGridMobileViewport, isSmartSuggestion, isTraditionalAutocompleteSuggestion, isoDate, keepCaretOnChip, labelTraditionalAutocomplete, matchTypedPhrase, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, optionsShowLeadingVisuals, parseDate, parseLooseDate, parseLooseDateRange, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productImageSources, productImageSrc, productInitial, productPhotoFill, productRowWheelTarget, productsFromCustomFields, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, shopifyImageSrc, toWireIdentifiedParams, typedFragment, uiStringsFor, visibleDateRange, withSkippedParams, withoutTraditionalAutocomplete };
2860
+ export { AIAutocomplete, type APIConfig, type APIKeyConfig, ATTRIBUTION_URL, type AccessTokenConfig, type AccessTokenResult, type AppearanceMode, type AutocompleteRequest, type AutocompleteResponse, type AutocompleteResult, type CompletedParam, type CompletedParamState, type CoreOptions, type CoreState, type CurrencyOptions, type CustomFieldsReport, DATE_RANGE_META_END, DATE_RANGE_META_START, DEFAULT_OPTION_COUNT_UNIT, type DateMonthView, type DateRange, type DateSelection, type ExpressedFilter, type FilterOp, type FormatType, type IdentifiedParam, type IdentifiedParamState, type InputItem, type LooseDateOptions, type MatchedItem, type MatchedItems, ModeController, OPTIONS_GRID_MOBILE_QUERY, OPTION_ENTER_DELAY_VAR, OPTION_ENTER_FADE_MS, OPTION_ENTER_RISE_MS, OPTION_ENTER_RISE_PX, OPTION_ENTER_STAGGER_MS, OPTION_IMAGE_WIDTH, type OptionOverride, type OptionOverrides, type OptionsGridLayout, type OptionsGridPlan, PLACEHOLDER_FADE_OUT_MS, PLACEHOLDER_LEAVING_ATTR, PLACEHOLDER_SWAP_GAP_MS, PLACEHOLDER_TYPE_MS, PLACEHOLDER_WORD_PAUSE_MS, PRODUCT_IMAGE_WIDTH, PRODUCT_PATH_PREFIX, PRODUCT_ROW_PX_PER_LINE, type PhraseMatch, type Product, type ProductImageFallback, type ProductRowMetrics, type ProductRowWheel, type ProductsConfig, type ProductsLayout, RANGE_SEPARATOR, type RecentlySuggested, type RenderMode, SCHEMA_VERSION, SCROLL_ARROW_ATTR, SCROLL_ARROW_BOTTOM_VAR, SCROLL_ARROW_CLASS, SCROLL_ARROW_FADE_MS, SCROLL_ARROW_LABEL, SCROLL_ARROW_SCROLL_IDLE_MS, SCROLL_ARROW_VISIBLE_ATTR, SKIPPED_PARAM_TEXT, SMART_SUGGESTION_SPARKLE_SVG, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type SuggestionType, TIME_META_KEY, TIME_STEP_MINUTES, TIME_WHEEL_COLUMNS, TIME_WHEEL_ROW_HEIGHT, type TaskKind, type TextPart, type TimeParts, type TimePeriod, type TimeView, type TimeWheelColumn, type TimeWheelRow, type UIStrings, VIEWPORT_FIT_ATTR, VIEWPORT_FIT_HEIGHT_VAR, type ViewportFitArgs, type ViewportFitController, WEEKDAY_LABELS, addMonths, attachProductRowWheel, attachScrollArrow, attachViewportFit, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, buildTimeOption, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateSelectionFor, extractPlainText, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, formatTime, getCursorOffset, getFooterHint, hasSkippablePill, highlightParts, identifiedParamLabel, isCalendarFormat, isOptionsGridMobileViewport, isPickerFormat, isSmartSuggestion, isTraditionalAutocompleteSuggestion, isoDate, isoTime, keepCaretOnChip, labelTraditionalAutocomplete, matchTypedPhrase, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, optionsShowLeadingVisuals, parseDate, parseLooseDate, parseLooseDateRange, parseTime, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productImageSources, productImageSrc, productInitial, productPhotoFill, productRowWheelTarget, productsFromCustomFields, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, shopifyImageSrc, timeWheelIndex, timeWheelIndexFromScroll, timeWheelRows, toWireIdentifiedParams, typedFragment, uiStringsFor, visibleDateRange, withSkippedParams, withTimeWheelIndex, withoutTraditionalAutocomplete };