@magicx-eng/ai-autocomplete-vanilla 0.33.0 → 0.34.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
@@ -648,7 +648,8 @@ unsub();
648
648
  | `clearNewParamId()` | Clear shimmer animation state. |
649
649
  | `reset()` | Clear all state, re-fetch initial suggestions, and start a new session (rotates `session_id`). Call this after handling submit. |
650
650
  | `recordSubmit(result)` | Record a submit from a button you render. Enter and the built-in button are recorded for you; call this once per submit from your own button. |
651
- | `setValue(text)` | Set text (controlled mode). |
651
+ | `setValue(text)` | Set text (controlled mode). Text set this way is not reported as the user starting a search. |
652
+ | `prefillText(text)` | Fill the field with text the user did not type — e.g. a query carried over from the previous page — and handle it like typing: suggestions are fetched and the text is recognized. Not reported as the user starting a search. |
652
653
  | `setCompletedParams(params)` | Set completed params (controlled mode). |
653
654
  | `setMode(mode)` | Switch color mode at runtime. |
654
655
  | `update(opts)` | Update multiple options at once (e.g. `animations`, `pillPlacement`, `dropdownTrigger`, `optionsPosition`). |
package/dist/index.d.mts CHANGED
@@ -1099,6 +1099,21 @@ declare class AIAutocomplete {
1099
1099
  private resetAfterSubmit;
1100
1100
  destroy(): void;
1101
1101
  setMode(mode: AppearanceMode): void;
1102
+ /**
1103
+ * Fill the field with text the shopper did not type — a query carried over
1104
+ * from the previous page, say — and handle it as if typed: suggestions are
1105
+ * fetched and the text is re-identified. Unlike typing, it does not count as
1106
+ * the shopper starting a search.
1107
+ */
1108
+ prefillText(text: string): void;
1109
+ /**
1110
+ * Reports `search_started` once per session, when the shopper (not the
1111
+ * consumer) first puts something in an empty field: typing, or picking an
1112
+ * option. Decided at the call, not in a store subscriber: a consumer write
1113
+ * made from inside a listener is delivered after its call returns, so a
1114
+ * subscriber cannot tell whose write it is.
1115
+ */
1116
+ private noteSearchStarted;
1102
1117
  setValue(text: string): void;
1103
1118
  setCompletedParams(params: CompletedParamState[]): void;
1104
1119
  setActivePill(index: number): void;
@@ -1215,6 +1230,7 @@ declare class AIAutocomplete {
1215
1230
  */
1216
1231
  selectProduct(product: Product): void;
1217
1232
  handleTextChange(value: string): void;
1233
+ private applyTextChange;
1218
1234
  /** Page the datepicker back one month. No-op unless a date pill is active. */
1219
1235
  showPreviousMonth(): void;
1220
1236
  /** Page the datepicker forward one month. No-op unless a date pill is active. */
@@ -1282,6 +1298,7 @@ declare class AIAutocomplete {
1282
1298
  on<E extends keyof AIAutocompleteEvents>(event: E, callback: (...args: AIAutocompleteEvents[E]) => void): () => void;
1283
1299
  update(opts: CoreUpdateOptions): void;
1284
1300
  selectOption(option: SuggestionOption): void;
1301
+ private applyOption;
1285
1302
  private startSelectionAnimationTimer;
1286
1303
  private resolveVisitorId;
1287
1304
  private resolveSource;
@@ -1737,6 +1754,36 @@ declare function getCursorOffset(root: HTMLElement): number | null;
1737
1754
  * get the browser's own scroll-to-caret behaviour.
1738
1755
  */
1739
1756
  declare function setCursorOffset(root: HTMLElement, offset: number): void;
1757
+ /**
1758
+ * The chip a tap or click landed on, or null.
1759
+ *
1760
+ * Re-edit otherwise starts only from `selectionchange`, i.e. from wherever
1761
+ * the browser put the caret — which on touch devices is frequently not the
1762
+ * chip the finger was on. iOS Safari snaps a tap's caret to a word boundary
1763
+ * and, on the tap that focuses the field, commonly parks it at the end of the
1764
+ * text: inside the last chip when the input ends with one. The event target
1765
+ * is the element actually hit, so a tap anywhere on the chip, edges and
1766
+ * padding included, selects it.
1767
+ *
1768
+ * Both chip kinds report, matching the selectionchange path: the core decides
1769
+ * what a tap means (a completed param re-opens its options, an identified date
1770
+ * opens the calendar, anything else is inert).
1771
+ *
1772
+ * Returns null when the gesture left a range selection (a drag-select that
1773
+ * ends on a chip is a selection, not a tap).
1774
+ */
1775
+ declare function chipIdFromTap(root: HTMLElement, target: EventTarget | null): string | null;
1776
+ /**
1777
+ * After a tap on a chip, make sure the caret is on that chip.
1778
+ *
1779
+ * The browser may have put the tap's caret somewhere else entirely (see
1780
+ * `chipIdFromTap`). Left there, the next `selectionchange` reads it as the
1781
+ * caret leaving the chip — or entering a different one — and closes or
1782
+ * redirects what the tap just opened. A caret already within the chip's
1783
+ * bounds (edges included) is left alone; otherwise it moves to the chip's
1784
+ * start, which every edit range includes.
1785
+ */
1786
+ declare function keepCaretOnChip(root: HTMLElement, paramId: string): void;
1740
1787
  /**
1741
1788
  * True when the caret offset equals the editable's plain-text length —
1742
1789
  * meaning the only content to the right is non-editable (e.g. trailing pills).
@@ -2252,4 +2299,4 @@ interface SubmitResultExtras {
2252
2299
  */
2253
2300
  declare function buildSubmitResult(text: string, completedParams: CompletedParamState[], skippedParams?: SkippedParamState[], extras?: SubmitResultExtras): AutocompleteResult;
2254
2301
 
2255
- 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 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, 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_PATH_PREFIX, PRODUCT_ROW_PX_PER_LINE, type Product, type ProductImageFallback, type ProductRowMetrics, type ProductRowWheel, type ProductsConfig, type ProductsLayout, RANGE_SEPARATOR, type RecentlySuggested, type RenderMode, 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, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type TaskKind, WEEKDAY_LABELS, addMonths, attachProductRowWheel, attachScrollArrow, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateSelectionFor, extractPlainText, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, getCursorOffset, getFooterHint, identifiedParamLabel, isCalendarFormat, isOptionsGridMobileViewport, isoDate, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, parseDate, parseLooseDate, parseLooseDateRange, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productInitial, productRowWheelTarget, productsFromCustomFields, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, toWireIdentifiedParams, visibleDateRange, withSkippedParams };
2302
+ 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 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, 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_PATH_PREFIX, PRODUCT_ROW_PX_PER_LINE, type Product, type ProductImageFallback, type ProductRowMetrics, type ProductRowWheel, type ProductsConfig, type ProductsLayout, RANGE_SEPARATOR, type RecentlySuggested, type RenderMode, 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, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type TaskKind, WEEKDAY_LABELS, addMonths, attachProductRowWheel, attachScrollArrow, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateSelectionFor, extractPlainText, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, getCursorOffset, getFooterHint, identifiedParamLabel, isCalendarFormat, isOptionsGridMobileViewport, isoDate, keepCaretOnChip, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, parseDate, parseLooseDate, parseLooseDateRange, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productInitial, productRowWheelTarget, productsFromCustomFields, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, toWireIdentifiedParams, visibleDateRange, withSkippedParams };
package/dist/index.d.ts CHANGED
@@ -1099,6 +1099,21 @@ declare class AIAutocomplete {
1099
1099
  private resetAfterSubmit;
1100
1100
  destroy(): void;
1101
1101
  setMode(mode: AppearanceMode): void;
1102
+ /**
1103
+ * Fill the field with text the shopper did not type — a query carried over
1104
+ * from the previous page, say — and handle it as if typed: suggestions are
1105
+ * fetched and the text is re-identified. Unlike typing, it does not count as
1106
+ * the shopper starting a search.
1107
+ */
1108
+ prefillText(text: string): void;
1109
+ /**
1110
+ * Reports `search_started` once per session, when the shopper (not the
1111
+ * consumer) first puts something in an empty field: typing, or picking an
1112
+ * option. Decided at the call, not in a store subscriber: a consumer write
1113
+ * made from inside a listener is delivered after its call returns, so a
1114
+ * subscriber cannot tell whose write it is.
1115
+ */
1116
+ private noteSearchStarted;
1102
1117
  setValue(text: string): void;
1103
1118
  setCompletedParams(params: CompletedParamState[]): void;
1104
1119
  setActivePill(index: number): void;
@@ -1215,6 +1230,7 @@ declare class AIAutocomplete {
1215
1230
  */
1216
1231
  selectProduct(product: Product): void;
1217
1232
  handleTextChange(value: string): void;
1233
+ private applyTextChange;
1218
1234
  /** Page the datepicker back one month. No-op unless a date pill is active. */
1219
1235
  showPreviousMonth(): void;
1220
1236
  /** Page the datepicker forward one month. No-op unless a date pill is active. */
@@ -1282,6 +1298,7 @@ declare class AIAutocomplete {
1282
1298
  on<E extends keyof AIAutocompleteEvents>(event: E, callback: (...args: AIAutocompleteEvents[E]) => void): () => void;
1283
1299
  update(opts: CoreUpdateOptions): void;
1284
1300
  selectOption(option: SuggestionOption): void;
1301
+ private applyOption;
1285
1302
  private startSelectionAnimationTimer;
1286
1303
  private resolveVisitorId;
1287
1304
  private resolveSource;
@@ -1737,6 +1754,36 @@ declare function getCursorOffset(root: HTMLElement): number | null;
1737
1754
  * get the browser's own scroll-to-caret behaviour.
1738
1755
  */
1739
1756
  declare function setCursorOffset(root: HTMLElement, offset: number): void;
1757
+ /**
1758
+ * The chip a tap or click landed on, or null.
1759
+ *
1760
+ * Re-edit otherwise starts only from `selectionchange`, i.e. from wherever
1761
+ * the browser put the caret — which on touch devices is frequently not the
1762
+ * chip the finger was on. iOS Safari snaps a tap's caret to a word boundary
1763
+ * and, on the tap that focuses the field, commonly parks it at the end of the
1764
+ * text: inside the last chip when the input ends with one. The event target
1765
+ * is the element actually hit, so a tap anywhere on the chip, edges and
1766
+ * padding included, selects it.
1767
+ *
1768
+ * Both chip kinds report, matching the selectionchange path: the core decides
1769
+ * what a tap means (a completed param re-opens its options, an identified date
1770
+ * opens the calendar, anything else is inert).
1771
+ *
1772
+ * Returns null when the gesture left a range selection (a drag-select that
1773
+ * ends on a chip is a selection, not a tap).
1774
+ */
1775
+ declare function chipIdFromTap(root: HTMLElement, target: EventTarget | null): string | null;
1776
+ /**
1777
+ * After a tap on a chip, make sure the caret is on that chip.
1778
+ *
1779
+ * The browser may have put the tap's caret somewhere else entirely (see
1780
+ * `chipIdFromTap`). Left there, the next `selectionchange` reads it as the
1781
+ * caret leaving the chip — or entering a different one — and closes or
1782
+ * redirects what the tap just opened. A caret already within the chip's
1783
+ * bounds (edges included) is left alone; otherwise it moves to the chip's
1784
+ * start, which every edit range includes.
1785
+ */
1786
+ declare function keepCaretOnChip(root: HTMLElement, paramId: string): void;
1740
1787
  /**
1741
1788
  * True when the caret offset equals the editable's plain-text length —
1742
1789
  * meaning the only content to the right is non-editable (e.g. trailing pills).
@@ -2252,4 +2299,4 @@ interface SubmitResultExtras {
2252
2299
  */
2253
2300
  declare function buildSubmitResult(text: string, completedParams: CompletedParamState[], skippedParams?: SkippedParamState[], extras?: SubmitResultExtras): AutocompleteResult;
2254
2301
 
2255
- 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 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, 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_PATH_PREFIX, PRODUCT_ROW_PX_PER_LINE, type Product, type ProductImageFallback, type ProductRowMetrics, type ProductRowWheel, type ProductsConfig, type ProductsLayout, RANGE_SEPARATOR, type RecentlySuggested, type RenderMode, 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, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type TaskKind, WEEKDAY_LABELS, addMonths, attachProductRowWheel, attachScrollArrow, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateSelectionFor, extractPlainText, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, getCursorOffset, getFooterHint, identifiedParamLabel, isCalendarFormat, isOptionsGridMobileViewport, isoDate, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, parseDate, parseLooseDate, parseLooseDateRange, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productInitial, productRowWheelTarget, productsFromCustomFields, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, toWireIdentifiedParams, visibleDateRange, withSkippedParams };
2302
+ 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 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, 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_PATH_PREFIX, PRODUCT_ROW_PX_PER_LINE, type Product, type ProductImageFallback, type ProductRowMetrics, type ProductRowWheel, type ProductsConfig, type ProductsLayout, RANGE_SEPARATOR, type RecentlySuggested, type RenderMode, 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, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type TaskKind, WEEKDAY_LABELS, addMonths, attachProductRowWheel, attachScrollArrow, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateSelectionFor, extractPlainText, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, getCursorOffset, getFooterHint, identifiedParamLabel, isCalendarFormat, isOptionsGridMobileViewport, isoDate, keepCaretOnChip, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, parseDate, parseLooseDate, parseLooseDateRange, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productInitial, productRowWheelTarget, productsFromCustomFields, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, toWireIdentifiedParams, visibleDateRange, withSkippedParams };