@magicx-eng/ai-autocomplete-vanilla 0.76.3 → 0.78.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 +2 -0
- package/REFERENCE.md +22 -0
- package/dist/index.d.mts +81 -2
- package/dist/index.d.ts +81 -2
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -713,6 +713,8 @@ const ac = new AIAutocomplete(container, {
|
|
|
713
713
|
|
|
714
714
|
Pass `visitorId` to tie searches to what the same visitor does later: a UUID v4 you keep across page loads (for example a first-party cookie), or a function that returns one. A function is called only when the id is needed, so it is safe to create the id lazily inside it.
|
|
715
715
|
|
|
716
|
+
Or pass `analyticsConsent` and let the SDK keep one: see [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-vanilla/REFERENCE.md).
|
|
717
|
+
|
|
716
718
|
Submits from Enter and from the built-in submit button are recorded for you. If you render your own submit button (Tier 2 or 3), call `recordSubmit(result)` from it, once per submit, with the result you pass to your own submit handler.
|
|
717
719
|
|
|
718
720
|
## Option Overrides
|
package/REFERENCE.md
CHANGED
|
@@ -9,6 +9,7 @@ Longer guides that do not fit in the [README](https://unpkg.com/@magicx-eng/ai-a
|
|
|
9
9
|
- [Multiple selections](#multiple-selections)
|
|
10
10
|
- [Location search](#location-search)
|
|
11
11
|
- [CSS variables](#css-variables)
|
|
12
|
+
- [Visitor id kept by the SDK](#visitor-id-kept-by-the-sdk)
|
|
12
13
|
|
|
13
14
|
## Product strip
|
|
14
15
|
|
|
@@ -706,6 +707,7 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
|
|
|
706
707
|
| `--aia-multi-done-width` | `100%` (classic: as wide as the widest option) | same | Width of the multi-select Done button. |
|
|
707
708
|
| `--aia-panel-min-width` | `160px` | same | Narrowest the floating options box gets when it hugs its options (desktop). Set `100%` to turn the hug off: the box then stays as wide as the field, up to `--aia-dropdown-max-width`. |
|
|
708
709
|
| `--aia-dropdown-max-width` | `544px` | same | Widest the floating options box gets. `none` lets it span the whole field (with `--aia-panel-min-width: 100%`, it always does). The calendar and the time wheel keep `--aia-date-panel-width` and `--aia-time-panel-width`. |
|
|
710
|
+
| `--aia-option-peek` | `0` | same | How much of one more option row a scrolling options list shows past its visible rows: a unitless number, 0 or more. `0.5` shows half of the next row, a hint that the list scrolls. A list where every option fits is unchanged, and a list that scrolls only because its options wrap onto more lines gets no peek (rows are counted, not measured). A negative reads as 0; a value with a unit (`0.5rem`, `50%`) is invalid and removes the list's height cap. Set it on the widget's container or any ancestor. |
|
|
709
711
|
| `--aia-focus-ring` | `none` | same | Outline drawn around the whole field while it has focus, e.g. `2px solid #1668e3`. Off by default. The editor inside never draws a ring of its own, whatever your page's `:focus-visible` rule says, so this is where focus shows. |
|
|
710
712
|
| `--aia-focus-ring-offset` | `0px` | same | Gap between that ring and the field's border; negative draws it over the border. |
|
|
711
713
|
| `--aia-multi-done-min-width` | `120px` | `120px` | Narrowest the multi-select Done button gets. |
|
|
@@ -723,3 +725,23 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
|
|
|
723
725
|
| `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color of the option and chip image tiles while their picture loads (unless `--aia-option-image-bg` / `--aia-chip-image-bg` are set). |
|
|
724
726
|
| `--aia-chip-remove-opacity` | `0.32` | `0.32` | Opacity of a chip's remove × (`showChipRemove`). The × is for a mouse or a tap and is hidden from assistive technology; from the keyboard, Backspace at the end of a chip removes it. |
|
|
725
727
|
| `--aia-chip-remove-opacity-hover` | `0.7` | `0.7` | Opacity of that × under a hovering pointer (never on touch). |
|
|
728
|
+
|
|
729
|
+
## Visitor id kept by the SDK
|
|
730
|
+
|
|
731
|
+
Without `visitorId`, the SDK can keep the id for you. Pass `analyticsConsent` so it knows the visitor's choice: `true` (allowed), `false` (declined), or `undefined` (not answered yet). Once allowed, it keeps a UUID v4 in the first-party cookie `aia_vid` for a year, renewed on use; declined, it removes that cookie. This needs the feature to be enabled for your account, and nothing is stored without `analyticsConsent`.
|
|
732
|
+
|
|
733
|
+
```ts
|
|
734
|
+
const ac = new AIAutocomplete(el, {
|
|
735
|
+
// Cookiebot, as an example. Return undefined until the visitor answers.
|
|
736
|
+
analyticsConsent: () => {
|
|
737
|
+
const cookiebot = window.Cookiebot;
|
|
738
|
+
return cookiebot?.hasResponse ? cookiebot.consent.statistics : undefined;
|
|
739
|
+
},
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
// Apply a changed choice at once, rather than at the next event.
|
|
743
|
+
window.addEventListener("CookiebotOnAccept", () => ac.refreshAnalyticsConsent());
|
|
744
|
+
window.addEventListener("CookiebotOnDecline", () => ac.refreshAnalyticsConsent());
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
`getVisitorId()` returns the id the instance's events carry, so you can send it with your own events. It is `undefined` before the first response and whenever there is no id.
|
package/dist/index.d.mts
CHANGED
|
@@ -264,6 +264,11 @@ interface AutocompleteResponse {
|
|
|
264
264
|
* shows. Absent means one for every response that changes it.
|
|
265
265
|
*/
|
|
266
266
|
visible_impression?: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Set when the SDK may keep its own visitor id for a site that passes no
|
|
269
|
+
* `visitorId` and reports analytics consent. Absent means off.
|
|
270
|
+
*/
|
|
271
|
+
sdk_visitor_id?: boolean;
|
|
267
272
|
/** The request's `schema_version`, echoed back. */
|
|
268
273
|
schema_version?: string;
|
|
269
274
|
};
|
|
@@ -1408,6 +1413,15 @@ interface CoreOptions {
|
|
|
1408
1413
|
* while it is off.
|
|
1409
1414
|
*/
|
|
1410
1415
|
visitorId?: string | (() => string | undefined);
|
|
1416
|
+
/**
|
|
1417
|
+
* Whether the visitor allowed analytics: `true`, `false`, or a function
|
|
1418
|
+
* returning either, or `undefined` while they have not answered. Once
|
|
1419
|
+
* allowed, and while the server has it on, a site that passes no `visitorId`
|
|
1420
|
+
* gets one kept for it in the first-party cookie `aia_vid` (a UUID v4, one
|
|
1421
|
+
* year, renewed on use). Declined, that cookie is removed. Omit it and the
|
|
1422
|
+
* SDK never touches the cookie. Ignored when `visitorId` is passed.
|
|
1423
|
+
*/
|
|
1424
|
+
analyticsConsent?: boolean | (() => boolean | undefined);
|
|
1411
1425
|
columns?: number;
|
|
1412
1426
|
/** Where pills render in "full" mode. Default: "dropdown". Ignored in "dropdown" mode (always in dropdown). */
|
|
1413
1427
|
pillPlacement?: "inline" | "dropdown" | "hidden";
|
|
@@ -1736,6 +1750,8 @@ declare class AIAutocomplete {
|
|
|
1736
1750
|
private lastImpressionKey;
|
|
1737
1751
|
/** The server's `visible_impression`: send an impression only while the dropdown is visible. */
|
|
1738
1752
|
private visibleImpression;
|
|
1753
|
+
/** The server's `sdk_visitor_id`: keep a visitor id for a host that passes none. */
|
|
1754
|
+
private sdkVisitorId;
|
|
1739
1755
|
private destroyed;
|
|
1740
1756
|
/** The location search in flight, so a newer phrase or destroy() can cancel it. */
|
|
1741
1757
|
private locationAbort;
|
|
@@ -1911,6 +1927,18 @@ declare class AIAutocomplete {
|
|
|
1911
1927
|
* own — a button you render — so each submit is counted once.
|
|
1912
1928
|
*/
|
|
1913
1929
|
recordSubmit(result: AutocompleteResult): void;
|
|
1930
|
+
/**
|
|
1931
|
+
* The visitor id this instance's events carry right now, to send with your
|
|
1932
|
+
* own events. Undefined while there is none: before the first response, or
|
|
1933
|
+
* without `visitorId` and without consent.
|
|
1934
|
+
*/
|
|
1935
|
+
getVisitorId(): string | undefined;
|
|
1936
|
+
/**
|
|
1937
|
+
* Reads `analyticsConsent` again now. Call it when the shopper changes their
|
|
1938
|
+
* choice, so a declined one removes the stored visitor id at once rather
|
|
1939
|
+
* than at the next event.
|
|
1940
|
+
*/
|
|
1941
|
+
refreshAnalyticsConsent(): void;
|
|
1914
1942
|
/**
|
|
1915
1943
|
* Ends whatever is in progress, a submit or a product selection, at once:
|
|
1916
1944
|
* call it when the work your handler started is done and the shopper is
|
|
@@ -2115,6 +2143,7 @@ declare class AIAutocomplete {
|
|
|
2115
2143
|
private applyOption;
|
|
2116
2144
|
private startSelectionAnimationTimer;
|
|
2117
2145
|
private resolveVisitorId;
|
|
2146
|
+
private resolveOwnVisitorId;
|
|
2118
2147
|
private resolveSource;
|
|
2119
2148
|
/**
|
|
2120
2149
|
* With `visible_impression`, the dropdown opening is itself an impression of
|
|
@@ -2554,7 +2583,10 @@ interface OptionsGridLayout {
|
|
|
2554
2583
|
cols: number;
|
|
2555
2584
|
/** Rows visible before the list scrolls. */
|
|
2556
2585
|
rows: number;
|
|
2557
|
-
/**
|
|
2586
|
+
/**
|
|
2587
|
+
* Value for `--aia-grid-max-height` — caps the scroll box at `rows` rows,
|
|
2588
|
+
* plus the consumer's `--aia-option-peek` when the list scrolls.
|
|
2589
|
+
*/
|
|
2558
2590
|
maxHeight: string;
|
|
2559
2591
|
}
|
|
2560
2592
|
/**
|
|
@@ -2861,6 +2893,53 @@ declare function inPanelGhost(el: Element): boolean;
|
|
|
2861
2893
|
/** The first element under `root` matching `selector` outside the crossfade's copy. */
|
|
2862
2894
|
declare function queryLive<E extends Element = Element>(root: ParentNode, selector: string): E | null;
|
|
2863
2895
|
|
|
2896
|
+
/**
|
|
2897
|
+
* Keeps the option the keyboard highlights in view.
|
|
2898
|
+
*
|
|
2899
|
+
* The options grid scrolls past its row cap, and the arrow keys walk the
|
|
2900
|
+
* highlight through every option, so a highlight moved by a key has to bring
|
|
2901
|
+
* its row along. A highlight the pointer set must not: the row is under the
|
|
2902
|
+
* cursor already, and a list that moves under the cursor highlights whatever
|
|
2903
|
+
* row lands there next.
|
|
2904
|
+
*
|
|
2905
|
+
* All three packages render the same grid, so the behaviour lives here and
|
|
2906
|
+
* each one makes the same two calls:
|
|
2907
|
+
*
|
|
2908
|
+
* - `syncHighlightScroll(grid, activeIndex)` after every render;
|
|
2909
|
+
* - `pointerMayHighlight(grid, index, event)` before its hover handlers
|
|
2910
|
+
* change the highlight (`-1` when the pointer leaves a row).
|
|
2911
|
+
*
|
|
2912
|
+
* The second call is how the two sources are told apart. It also holds the
|
|
2913
|
+
* pointer off after a scripted scroll: a browser re-targets a resting cursor
|
|
2914
|
+
* when the content under it moves and fires mouseenter / mouseleave for the
|
|
2915
|
+
* rows that pass, which would take the highlight back from the keyboard on
|
|
2916
|
+
* every step. Those events carry the cursor's last screen position, so the
|
|
2917
|
+
* pointer is let back in by the first event that reports another one.
|
|
2918
|
+
*/
|
|
2919
|
+
/** Where a mouse event says the cursor is. */
|
|
2920
|
+
interface PointerPosition {
|
|
2921
|
+
screenX: number;
|
|
2922
|
+
screenY: number;
|
|
2923
|
+
}
|
|
2924
|
+
/**
|
|
2925
|
+
* Whether the pointer may change the highlight now. Call it from the hover
|
|
2926
|
+
* handlers with the option's index (-1 when the pointer leaves a row) and
|
|
2927
|
+
* their mouse event, and leave the highlight alone when it answers false: the
|
|
2928
|
+
* list has just been scrolled by a key and the cursor has not moved, so the
|
|
2929
|
+
* event is the list passing under it. The event is judged here as well as by
|
|
2930
|
+
* the grid's own listeners because a framework may deliver a row's enter
|
|
2931
|
+
* from an event the grid never sees (React reads it off the mouseout of the
|
|
2932
|
+
* element the cursor came from).
|
|
2933
|
+
*/
|
|
2934
|
+
declare function pointerMayHighlight(grid: HTMLElement | null | undefined, index: number, event: PointerPosition): boolean;
|
|
2935
|
+
/**
|
|
2936
|
+
* Scroll the highlighted option into view when the highlight moved and the
|
|
2937
|
+
* pointer did not move it. Call after every render with the index the grid
|
|
2938
|
+
* shows as highlighted (-1 for none, and while the rows are loading
|
|
2939
|
+
* skeletons). Only the rows' own scroll box moves, never the page.
|
|
2940
|
+
*/
|
|
2941
|
+
declare function syncHighlightScroll(grid: HTMLElement, activeIndex: number): void;
|
|
2942
|
+
|
|
2864
2943
|
declare const MULTI_DONE_FIT_VAR = "--aia-multi-done-fit";
|
|
2865
2944
|
/** The live multi-select Done button under `root`, skipping the crossfade ghost. */
|
|
2866
2945
|
declare function findMultiSelectDone(root: ParentNode): HTMLButtonElement | null;
|
|
@@ -3660,4 +3739,4 @@ declare const SMART_SUGGESTION_SPARKLE_SVG: string;
|
|
|
3660
3739
|
/** True when some pill is a question the shopper can decline. */
|
|
3661
3740
|
declare function hasSkippablePill(suggestions: Suggestion[]): boolean;
|
|
3662
3741
|
|
|
3663
|
-
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, EDITOR_GROW_MS, type ExpressedFilter, type FilterOp, type FormatType, HANDOFF_NOT_HANDLED, HINT_ATTR, HINT_EL_ATTR, HINT_HOLD_MS, type IdentifiedParam, type IdentifiedParamState, type InputItem, LOCATION_META_KEY, LOCATION_MIN_QUERY, type LocationPlace, type LocationStatus, type LocationView, type LooseDateOptions, MULTI_DONE_FIT_VAR, MULTI_SELECT_TOGGLE_MIN_PX, MULTI_SELECT_TOGGLE_SLOP_PX, 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, PANEL_ENTER_DELAY_MS, PANEL_ENTER_MS, PANEL_GHOST_CLASS, PANEL_GLIDE_MS, PANEL_LEAVE_MS, 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 SelectOptionOptions, type SkippedParamState, type StartingHintOption, 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, attachChipRemove, attachProductRowWheel, attachScrollArrow, attachViewportFit, buildAttributionUrl, buildDateOptions, buildLocationOption, buildQuery, buildSubmitResult, buildTimeOption, cancelStartingHint, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateFloorFor, dateSelectionFor, destroyPanelMorph, dropdownPillsFor, editingSuggestion, extractPlainText, findMultiSelectDone, fitMultiSelectDone, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, formatPlace, formatTime, getCursorOffset, getFooterHint, hasSkippablePill, highlightParts, identifiedParamLabel, inPanelGhost, isCalendarFormat, isDimmedDay, isMultiSelectToggleTap, isOptionsGridMobileViewport, isPickerFormat, isSmartSuggestion, isTraditionalAutocompleteSuggestion, isoDate, isoTime, keepCaretOnChip, labelTraditionalAutocomplete, locationEndpointFor, matchTypedPhrase, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, notePanelMorphHeight, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, optionsShowLeadingVisuals, panelMorphGlide, panelMorphKey, panelMorphTargetHeight, parseDate, parseLooseDate, parseLooseDateRange, parseTime, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productImageSources, productImageSrc, productInitial, productPhotoFill, productRowWheelTarget, productsFromCustomFields, queryLive, releasePanelHug, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, settlePanelMorph, shopifyImageSrc, startingHintOptions, syncPanelHug, timeWheelIndex, timeWheelIndexFromScroll, timeWheelRows, toWireIdentifiedParams, typedFragment, uiStringsFor, visibleDateRange, watchEditorHeight, withSkippedParams, withTimeWheelIndex, withoutTraditionalAutocomplete };
|
|
3742
|
+
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, EDITOR_GROW_MS, type ExpressedFilter, type FilterOp, type FormatType, HANDOFF_NOT_HANDLED, HINT_ATTR, HINT_EL_ATTR, HINT_HOLD_MS, type IdentifiedParam, type IdentifiedParamState, type InputItem, LOCATION_META_KEY, LOCATION_MIN_QUERY, type LocationPlace, type LocationStatus, type LocationView, type LooseDateOptions, MULTI_DONE_FIT_VAR, MULTI_SELECT_TOGGLE_MIN_PX, MULTI_SELECT_TOGGLE_SLOP_PX, 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, PANEL_ENTER_DELAY_MS, PANEL_ENTER_MS, PANEL_GHOST_CLASS, PANEL_GLIDE_MS, PANEL_LEAVE_MS, 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 SelectOptionOptions, type SkippedParamState, type StartingHintOption, 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, attachChipRemove, attachProductRowWheel, attachScrollArrow, attachViewportFit, buildAttributionUrl, buildDateOptions, buildLocationOption, buildQuery, buildSubmitResult, buildTimeOption, cancelStartingHint, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateFloorFor, dateSelectionFor, destroyPanelMorph, dropdownPillsFor, editingSuggestion, extractPlainText, findMultiSelectDone, fitMultiSelectDone, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, formatPlace, formatTime, getCursorOffset, getFooterHint, hasSkippablePill, highlightParts, identifiedParamLabel, inPanelGhost, isCalendarFormat, isDimmedDay, isMultiSelectToggleTap, isOptionsGridMobileViewport, isPickerFormat, isSmartSuggestion, isTraditionalAutocompleteSuggestion, isoDate, isoTime, keepCaretOnChip, labelTraditionalAutocomplete, locationEndpointFor, matchTypedPhrase, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, notePanelMorphHeight, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, optionsShowLeadingVisuals, panelMorphGlide, panelMorphKey, panelMorphTargetHeight, parseDate, parseLooseDate, parseLooseDateRange, parseTime, plainTextLength, planOptionsGrid, pointerMayHighlight, previousGraphemeBoundary, productFromMatchedItem, productImageSources, productImageSrc, productInitial, productPhotoFill, productRowWheelTarget, productsFromCustomFields, queryLive, releasePanelHug, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, settlePanelMorph, shopifyImageSrc, startingHintOptions, syncHighlightScroll, syncPanelHug, timeWheelIndex, timeWheelIndexFromScroll, timeWheelRows, toWireIdentifiedParams, typedFragment, uiStringsFor, visibleDateRange, watchEditorHeight, withSkippedParams, withTimeWheelIndex, withoutTraditionalAutocomplete };
|
package/dist/index.d.ts
CHANGED
|
@@ -264,6 +264,11 @@ interface AutocompleteResponse {
|
|
|
264
264
|
* shows. Absent means one for every response that changes it.
|
|
265
265
|
*/
|
|
266
266
|
visible_impression?: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Set when the SDK may keep its own visitor id for a site that passes no
|
|
269
|
+
* `visitorId` and reports analytics consent. Absent means off.
|
|
270
|
+
*/
|
|
271
|
+
sdk_visitor_id?: boolean;
|
|
267
272
|
/** The request's `schema_version`, echoed back. */
|
|
268
273
|
schema_version?: string;
|
|
269
274
|
};
|
|
@@ -1408,6 +1413,15 @@ interface CoreOptions {
|
|
|
1408
1413
|
* while it is off.
|
|
1409
1414
|
*/
|
|
1410
1415
|
visitorId?: string | (() => string | undefined);
|
|
1416
|
+
/**
|
|
1417
|
+
* Whether the visitor allowed analytics: `true`, `false`, or a function
|
|
1418
|
+
* returning either, or `undefined` while they have not answered. Once
|
|
1419
|
+
* allowed, and while the server has it on, a site that passes no `visitorId`
|
|
1420
|
+
* gets one kept for it in the first-party cookie `aia_vid` (a UUID v4, one
|
|
1421
|
+
* year, renewed on use). Declined, that cookie is removed. Omit it and the
|
|
1422
|
+
* SDK never touches the cookie. Ignored when `visitorId` is passed.
|
|
1423
|
+
*/
|
|
1424
|
+
analyticsConsent?: boolean | (() => boolean | undefined);
|
|
1411
1425
|
columns?: number;
|
|
1412
1426
|
/** Where pills render in "full" mode. Default: "dropdown". Ignored in "dropdown" mode (always in dropdown). */
|
|
1413
1427
|
pillPlacement?: "inline" | "dropdown" | "hidden";
|
|
@@ -1736,6 +1750,8 @@ declare class AIAutocomplete {
|
|
|
1736
1750
|
private lastImpressionKey;
|
|
1737
1751
|
/** The server's `visible_impression`: send an impression only while the dropdown is visible. */
|
|
1738
1752
|
private visibleImpression;
|
|
1753
|
+
/** The server's `sdk_visitor_id`: keep a visitor id for a host that passes none. */
|
|
1754
|
+
private sdkVisitorId;
|
|
1739
1755
|
private destroyed;
|
|
1740
1756
|
/** The location search in flight, so a newer phrase or destroy() can cancel it. */
|
|
1741
1757
|
private locationAbort;
|
|
@@ -1911,6 +1927,18 @@ declare class AIAutocomplete {
|
|
|
1911
1927
|
* own — a button you render — so each submit is counted once.
|
|
1912
1928
|
*/
|
|
1913
1929
|
recordSubmit(result: AutocompleteResult): void;
|
|
1930
|
+
/**
|
|
1931
|
+
* The visitor id this instance's events carry right now, to send with your
|
|
1932
|
+
* own events. Undefined while there is none: before the first response, or
|
|
1933
|
+
* without `visitorId` and without consent.
|
|
1934
|
+
*/
|
|
1935
|
+
getVisitorId(): string | undefined;
|
|
1936
|
+
/**
|
|
1937
|
+
* Reads `analyticsConsent` again now. Call it when the shopper changes their
|
|
1938
|
+
* choice, so a declined one removes the stored visitor id at once rather
|
|
1939
|
+
* than at the next event.
|
|
1940
|
+
*/
|
|
1941
|
+
refreshAnalyticsConsent(): void;
|
|
1914
1942
|
/**
|
|
1915
1943
|
* Ends whatever is in progress, a submit or a product selection, at once:
|
|
1916
1944
|
* call it when the work your handler started is done and the shopper is
|
|
@@ -2115,6 +2143,7 @@ declare class AIAutocomplete {
|
|
|
2115
2143
|
private applyOption;
|
|
2116
2144
|
private startSelectionAnimationTimer;
|
|
2117
2145
|
private resolveVisitorId;
|
|
2146
|
+
private resolveOwnVisitorId;
|
|
2118
2147
|
private resolveSource;
|
|
2119
2148
|
/**
|
|
2120
2149
|
* With `visible_impression`, the dropdown opening is itself an impression of
|
|
@@ -2554,7 +2583,10 @@ interface OptionsGridLayout {
|
|
|
2554
2583
|
cols: number;
|
|
2555
2584
|
/** Rows visible before the list scrolls. */
|
|
2556
2585
|
rows: number;
|
|
2557
|
-
/**
|
|
2586
|
+
/**
|
|
2587
|
+
* Value for `--aia-grid-max-height` — caps the scroll box at `rows` rows,
|
|
2588
|
+
* plus the consumer's `--aia-option-peek` when the list scrolls.
|
|
2589
|
+
*/
|
|
2558
2590
|
maxHeight: string;
|
|
2559
2591
|
}
|
|
2560
2592
|
/**
|
|
@@ -2861,6 +2893,53 @@ declare function inPanelGhost(el: Element): boolean;
|
|
|
2861
2893
|
/** The first element under `root` matching `selector` outside the crossfade's copy. */
|
|
2862
2894
|
declare function queryLive<E extends Element = Element>(root: ParentNode, selector: string): E | null;
|
|
2863
2895
|
|
|
2896
|
+
/**
|
|
2897
|
+
* Keeps the option the keyboard highlights in view.
|
|
2898
|
+
*
|
|
2899
|
+
* The options grid scrolls past its row cap, and the arrow keys walk the
|
|
2900
|
+
* highlight through every option, so a highlight moved by a key has to bring
|
|
2901
|
+
* its row along. A highlight the pointer set must not: the row is under the
|
|
2902
|
+
* cursor already, and a list that moves under the cursor highlights whatever
|
|
2903
|
+
* row lands there next.
|
|
2904
|
+
*
|
|
2905
|
+
* All three packages render the same grid, so the behaviour lives here and
|
|
2906
|
+
* each one makes the same two calls:
|
|
2907
|
+
*
|
|
2908
|
+
* - `syncHighlightScroll(grid, activeIndex)` after every render;
|
|
2909
|
+
* - `pointerMayHighlight(grid, index, event)` before its hover handlers
|
|
2910
|
+
* change the highlight (`-1` when the pointer leaves a row).
|
|
2911
|
+
*
|
|
2912
|
+
* The second call is how the two sources are told apart. It also holds the
|
|
2913
|
+
* pointer off after a scripted scroll: a browser re-targets a resting cursor
|
|
2914
|
+
* when the content under it moves and fires mouseenter / mouseleave for the
|
|
2915
|
+
* rows that pass, which would take the highlight back from the keyboard on
|
|
2916
|
+
* every step. Those events carry the cursor's last screen position, so the
|
|
2917
|
+
* pointer is let back in by the first event that reports another one.
|
|
2918
|
+
*/
|
|
2919
|
+
/** Where a mouse event says the cursor is. */
|
|
2920
|
+
interface PointerPosition {
|
|
2921
|
+
screenX: number;
|
|
2922
|
+
screenY: number;
|
|
2923
|
+
}
|
|
2924
|
+
/**
|
|
2925
|
+
* Whether the pointer may change the highlight now. Call it from the hover
|
|
2926
|
+
* handlers with the option's index (-1 when the pointer leaves a row) and
|
|
2927
|
+
* their mouse event, and leave the highlight alone when it answers false: the
|
|
2928
|
+
* list has just been scrolled by a key and the cursor has not moved, so the
|
|
2929
|
+
* event is the list passing under it. The event is judged here as well as by
|
|
2930
|
+
* the grid's own listeners because a framework may deliver a row's enter
|
|
2931
|
+
* from an event the grid never sees (React reads it off the mouseout of the
|
|
2932
|
+
* element the cursor came from).
|
|
2933
|
+
*/
|
|
2934
|
+
declare function pointerMayHighlight(grid: HTMLElement | null | undefined, index: number, event: PointerPosition): boolean;
|
|
2935
|
+
/**
|
|
2936
|
+
* Scroll the highlighted option into view when the highlight moved and the
|
|
2937
|
+
* pointer did not move it. Call after every render with the index the grid
|
|
2938
|
+
* shows as highlighted (-1 for none, and while the rows are loading
|
|
2939
|
+
* skeletons). Only the rows' own scroll box moves, never the page.
|
|
2940
|
+
*/
|
|
2941
|
+
declare function syncHighlightScroll(grid: HTMLElement, activeIndex: number): void;
|
|
2942
|
+
|
|
2864
2943
|
declare const MULTI_DONE_FIT_VAR = "--aia-multi-done-fit";
|
|
2865
2944
|
/** The live multi-select Done button under `root`, skipping the crossfade ghost. */
|
|
2866
2945
|
declare function findMultiSelectDone(root: ParentNode): HTMLButtonElement | null;
|
|
@@ -3660,4 +3739,4 @@ declare const SMART_SUGGESTION_SPARKLE_SVG: string;
|
|
|
3660
3739
|
/** True when some pill is a question the shopper can decline. */
|
|
3661
3740
|
declare function hasSkippablePill(suggestions: Suggestion[]): boolean;
|
|
3662
3741
|
|
|
3663
|
-
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, EDITOR_GROW_MS, type ExpressedFilter, type FilterOp, type FormatType, HANDOFF_NOT_HANDLED, HINT_ATTR, HINT_EL_ATTR, HINT_HOLD_MS, type IdentifiedParam, type IdentifiedParamState, type InputItem, LOCATION_META_KEY, LOCATION_MIN_QUERY, type LocationPlace, type LocationStatus, type LocationView, type LooseDateOptions, MULTI_DONE_FIT_VAR, MULTI_SELECT_TOGGLE_MIN_PX, MULTI_SELECT_TOGGLE_SLOP_PX, 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, PANEL_ENTER_DELAY_MS, PANEL_ENTER_MS, PANEL_GHOST_CLASS, PANEL_GLIDE_MS, PANEL_LEAVE_MS, 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 SelectOptionOptions, type SkippedParamState, type StartingHintOption, 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, attachChipRemove, attachProductRowWheel, attachScrollArrow, attachViewportFit, buildAttributionUrl, buildDateOptions, buildLocationOption, buildQuery, buildSubmitResult, buildTimeOption, cancelStartingHint, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateFloorFor, dateSelectionFor, destroyPanelMorph, dropdownPillsFor, editingSuggestion, extractPlainText, findMultiSelectDone, fitMultiSelectDone, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, formatPlace, formatTime, getCursorOffset, getFooterHint, hasSkippablePill, highlightParts, identifiedParamLabel, inPanelGhost, isCalendarFormat, isDimmedDay, isMultiSelectToggleTap, isOptionsGridMobileViewport, isPickerFormat, isSmartSuggestion, isTraditionalAutocompleteSuggestion, isoDate, isoTime, keepCaretOnChip, labelTraditionalAutocomplete, locationEndpointFor, matchTypedPhrase, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, notePanelMorphHeight, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, optionsShowLeadingVisuals, panelMorphGlide, panelMorphKey, panelMorphTargetHeight, parseDate, parseLooseDate, parseLooseDateRange, parseTime, plainTextLength, planOptionsGrid, previousGraphemeBoundary, productFromMatchedItem, productImageSources, productImageSrc, productInitial, productPhotoFill, productRowWheelTarget, productsFromCustomFields, queryLive, releasePanelHug, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, settlePanelMorph, shopifyImageSrc, startingHintOptions, syncPanelHug, timeWheelIndex, timeWheelIndexFromScroll, timeWheelRows, toWireIdentifiedParams, typedFragment, uiStringsFor, visibleDateRange, watchEditorHeight, withSkippedParams, withTimeWheelIndex, withoutTraditionalAutocomplete };
|
|
3742
|
+
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, EDITOR_GROW_MS, type ExpressedFilter, type FilterOp, type FormatType, HANDOFF_NOT_HANDLED, HINT_ATTR, HINT_EL_ATTR, HINT_HOLD_MS, type IdentifiedParam, type IdentifiedParamState, type InputItem, LOCATION_META_KEY, LOCATION_MIN_QUERY, type LocationPlace, type LocationStatus, type LocationView, type LooseDateOptions, MULTI_DONE_FIT_VAR, MULTI_SELECT_TOGGLE_MIN_PX, MULTI_SELECT_TOGGLE_SLOP_PX, 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, PANEL_ENTER_DELAY_MS, PANEL_ENTER_MS, PANEL_GHOST_CLASS, PANEL_GLIDE_MS, PANEL_LEAVE_MS, 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 SelectOptionOptions, type SkippedParamState, type StartingHintOption, 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, attachChipRemove, attachProductRowWheel, attachScrollArrow, attachViewportFit, buildAttributionUrl, buildDateOptions, buildLocationOption, buildQuery, buildSubmitResult, buildTimeOption, cancelStartingHint, cellDay, cellIso, chipIdFromTap, computeOptionsGridLayout, containScroll, createStore, cursorIsAtEnd, dateCellMarks, dateFloorFor, dateSelectionFor, destroyPanelMorph, dropdownPillsFor, editingSuggestion, extractPlainText, findMultiSelectDone, fitMultiSelectDone, formatAbsoluteDate, formatDate, formatDateRange, formatOptionCount, formatPlace, formatTime, getCursorOffset, getFooterHint, hasSkippablePill, highlightParts, identifiedParamLabel, inPanelGhost, isCalendarFormat, isDimmedDay, isMultiSelectToggleTap, isOptionsGridMobileViewport, isPickerFormat, isSmartSuggestion, isTraditionalAutocompleteSuggestion, isoDate, isoTime, keepCaretOnChip, labelTraditionalAutocomplete, locationEndpointFor, matchTypedPhrase, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, notePanelMorphHeight, optionCountLabel, optionEnterDelayMs, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsEntranceDurationMs, optionsGridTemplateColumns, optionsShowLeadingVisuals, panelMorphGlide, panelMorphKey, panelMorphTargetHeight, parseDate, parseLooseDate, parseLooseDateRange, parseTime, plainTextLength, planOptionsGrid, pointerMayHighlight, previousGraphemeBoundary, productFromMatchedItem, productImageSources, productImageSrc, productInitial, productPhotoFill, productRowWheelTarget, productsFromCustomFields, queryLive, releasePanelHug, renderEditableContent, resolveFormatType, resolveIdentifiedDate, sameOptionRows, sanitizeOptionIconSvg, scrollCaretIntoView, selectedIsoFromText, selectedRangeFor, setCursorOffset, settlePanelMorph, shopifyImageSrc, startingHintOptions, syncHighlightScroll, syncPanelHug, timeWheelIndex, timeWheelIndexFromScroll, timeWheelRows, toWireIdentifiedParams, typedFragment, uiStringsFor, visibleDateRange, watchEditorHeight, withSkippedParams, withTimeWheelIndex, withoutTraditionalAutocomplete };
|