@magicx-eng/ai-autocomplete-react 0.67.3 → 0.67.5
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 +16 -44
- package/REFERENCE.md +115 -2
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -159,7 +159,7 @@ A suggestion with `type: { kind: "multi_select" }` shows checkbox options and a
|
|
|
159
159
|
|
|
160
160
|
### Location search
|
|
161
161
|
|
|
162
|
-
A location parameter the server sends without options gets a search field that looks up any city or address through the
|
|
162
|
+
A location parameter the server sends without options gets a search field that looks up any city or address through the location search endpoint (the hosted service's by default). If `apiConfig.endpoint` points at a proxy with its own path, set `apiConfig.locationEndpoint` too. `locationSearch: false` takes typed text only, and an `optionOverrides` entry for the parameter replaces the search. Details: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-react/REFERENCE.md), under "Location search"; to replace every endpoint, see "Using your own server" there.
|
|
163
163
|
|
|
164
164
|
## Tier 2: Hook + Dropdown
|
|
165
165
|
|
|
@@ -367,6 +367,9 @@ A discriminated union: `APIKeyConfig | AccessTokenConfig`.
|
|
|
367
367
|
| `apiKey?` | `string` | API key for Authorization header. |
|
|
368
368
|
| `authScheme?` | `"Bearer" \| "Basic"` | Auth header scheme. Default: `"Bearer"`. |
|
|
369
369
|
| `endpoint?` | `string` | Full URL for the suggest endpoint. Default: `"https://api.ai-autocomplete.com/api/suggest"`. |
|
|
370
|
+
| `locationEndpoint?` | `string` | Location search URL. Default: beside `endpoint` (`…/suggest` → `…/locations/autocomplete`). |
|
|
371
|
+
| `telemetryEndpoint?` | `string` | Telemetry events URL. Default: beside `endpoint` (`…/suggest` → `…/telemetry/events`). |
|
|
372
|
+
| `startingStateEndpoint?` | `string` | Base URL the starting state is read from (`{base}/{productId}/{language}`). Default: beside `endpoint` (`…/suggest` → `…/starting-state`). |
|
|
370
373
|
| `appIdentifier?` | `string` | Value for the `X-App-Identifier` header. |
|
|
371
374
|
| `headers?` | `Record<string, string>` | Additional headers merged into every request. |
|
|
372
375
|
|
|
@@ -393,6 +396,9 @@ A discriminated union: `APIKeyConfig | AccessTokenConfig`.
|
|
|
393
396
|
| `getAccessToken` | `() => Promise<AccessTokenResult>` | **Required.** Called when the SDK needs a token. |
|
|
394
397
|
| `accessToken?` | `string` | Initial token. Avoids one round-trip on mount. |
|
|
395
398
|
| `endpoint?` | `string` | Suggest endpoint URL. Default: `"https://api.ai-autocomplete.com/api/suggest"`. |
|
|
399
|
+
| `locationEndpoint?` | `string` | Location search URL. Default: beside `endpoint` (`…/suggest` → `…/locations/autocomplete`). |
|
|
400
|
+
| `telemetryEndpoint?` | `string` | Telemetry events URL. Default: beside `endpoint` (`…/suggest` → `…/telemetry/events`). |
|
|
401
|
+
| `startingStateEndpoint?` | `string` | Base URL the starting state is read from (`{base}/{productId}/{language}`). Default: beside `endpoint` (`…/suggest` → `…/starting-state`). |
|
|
396
402
|
| `appIdentifier?` | `string` | Value for the `X-App-Identifier` header. |
|
|
397
403
|
| `headers?` | `Record<string, string>` | Additional headers merged into every request. |
|
|
398
404
|
|
|
@@ -575,48 +581,7 @@ On a phone or tablet, the shopper can put the keyboard away to see the whole dro
|
|
|
575
581
|
|
|
576
582
|
### Selector Hooks
|
|
577
583
|
|
|
578
|
-
For styling beyond the CSS variables,
|
|
579
|
-
|
|
580
|
-
| Attribute | Element |
|
|
581
|
-
|---|---|
|
|
582
|
-
| `[data-aia-input-wrapper]` | Wrapper around the editor area and the submit button — one of the two roots the SDK isolates from page CSS (the dropdown is the other) |
|
|
583
|
-
| `[data-aia-editor]` | Editor area wrapping the contentEditable + inline pill list |
|
|
584
|
-
| `[data-aia-input]` | The Tier 1 contentEditable `<div>` that owns typed text and bold completed params. (Replaces the previous `[data-aia-textarea]` selector.) |
|
|
585
|
-
| `[data-aia-pill-list-container]` | Inline sibling of the editor that holds unfilled-suggestion pills |
|
|
586
|
-
| `[data-aia-submit]` | Submit button |
|
|
587
|
-
| `[data-aia-pill]` | Each unfilled-suggestion pill |
|
|
588
|
-
| `[data-aia-pillbar]` | Pill bar container inside the dropdown |
|
|
589
|
-
| `[data-aia-pill-scroll]` | Scrollable pill region inside the bar — carries the horizontal scroll and right-edge fade mask |
|
|
590
|
-
| `[data-aia-skip]` | The pill bar's "skip" button: at the header's trailing edge, or alone at the end of a skip-only row. Tune via `--aia-skip-font-size` / `--aia-skip-color` / `--aia-skip-color-hover` / `--aia-skip-hover-bg` |
|
|
591
|
-
| `[data-aia-hint-el]` | The empty box's hint: the lead-in and the first starting options, one at a time. Tune via `--aia-hint-color` / `--aia-hint-font-weight` / `--aia-hint-icon-opacity` |
|
|
592
|
-
| `[data-aia-option]` | Each suggestion option |
|
|
593
|
-
| `[data-aia-scroll-arrow]` | The "more below" arrow on the dropdown — carries `data-aia-visible` while shown |
|
|
594
|
-
| `[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)). |
|
|
595
|
-
| `[data-aia-datepicker]` | The calendar, rendered in place of the option list for a date parameter |
|
|
596
|
-
| `[data-aia-time-wheel]` | The time wheel, rendered in place of the option list for a time parameter |
|
|
597
|
-
| `[data-aia-location]` | The location search, rendered in place of the option list for a location parameter without options (`[data-aia-location-input]` is its field, `[data-aia-location-row]` each place) |
|
|
598
|
-
| `[data-aia-date-month]` | The "March 2026" header label |
|
|
599
|
-
| `[data-aia-date-prev]` / `[data-aia-date-next]` | The month arrows |
|
|
600
|
-
| `[data-aia-date-grid]` | The 7-column grid of day cells |
|
|
601
|
-
| `[data-aia-date-cell]` | Each day cell. Also carries `[data-aia-option]`, so option-level styling applies to both bodies |
|
|
602
|
-
| `[data-aia-products]` | Product strip section (label + row) |
|
|
603
|
-
| `[data-aia-products-row]` | The horizontally scrolling row of cards |
|
|
604
|
-
| `[data-aia-product]` | Each product card |
|
|
605
|
-
| `[data-aia-product-placeholder]` | Media tile showing the placeholder pictogram (`productImageFallback: "image"`) after a missing/blank URL or load error. The existing hook is unchanged. |
|
|
606
|
-
| `[data-aia-product-initial]` | The media tile itself when it shows the title initial (`productImageFallback: "initial"`). Decorative (`aria-hidden="true"`); target it to style the background, color, font size and border radius. |
|
|
607
|
-
|
|
608
|
-
Completed params render as inline `<strong>` elements inside the editor. Override their weight with `[data-aia-input] strong { font-weight: 700; }` — a selector that names the editor wins without `!important`, while a bare `strong { … }` page rule is kept out by the isolation reset.
|
|
609
|
-
|
|
610
|
-
```css
|
|
611
|
-
/* Solid (non-glass) dropdown */
|
|
612
|
-
.my-autocomplete [data-aia-dropdown] {
|
|
613
|
-
background: #fff;
|
|
614
|
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
|
615
|
-
backdrop-filter: none;
|
|
616
|
-
}
|
|
617
|
-
```
|
|
618
|
-
|
|
619
|
-
---
|
|
584
|
+
For styling beyond the CSS variables, the stable `data-aia-*` attributes to target are listed in [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-react/REFERENCE.md), under "Selector hooks".
|
|
620
585
|
|
|
621
586
|
## Sessions
|
|
622
587
|
|
|
@@ -685,4 +650,11 @@ The hook's `isLoading` is true while an answer is pending, the same flag it rais
|
|
|
685
650
|
|
|
686
651
|
## License
|
|
687
652
|
|
|
688
|
-
MIT.
|
|
653
|
+
The SDK in this repository is licensed under the [MIT License](./LICENSE).
|
|
654
|
+
|
|
655
|
+
By default the SDK sends requests to the hosted Intent-1 service operated by
|
|
656
|
+
MagicX. That server call is modular: every endpoint is configurable, and the
|
|
657
|
+
default can be replaced with a self-hosted or third-party server (see
|
|
658
|
+
["Using your own server"](./REFERENCE.md#using-your-own-server)).
|
|
659
|
+
|
|
660
|
+
The hosted Intent-1 service is a separate service, governed by MagicX's own [Terms & Conditions](https://ai-autocomplete.com/legal/terms), not by the SDK's license. The MIT license covers the SDK code only. No rights in the hosted service or in any server-side method are granted through it.
|
package/REFERENCE.md
CHANGED
|
@@ -653,8 +653,8 @@ locations is the server's call: it marks them `type: { kind: "location" }`.
|
|
|
653
653
|
- **With options** (a catalog with a `city` field, say), it is an ordinary
|
|
654
654
|
option list. Nothing changes.
|
|
655
655
|
- **Without options**, the dropdown shows a search field instead. Typing in it
|
|
656
|
-
searches places through the
|
|
657
|
-
|
|
656
|
+
searches places through the location search endpoint and
|
|
657
|
+
lists what it finds; any city, address or landmark can be picked.
|
|
658
658
|
What the user types in the main input is searched there too, cut to its
|
|
659
659
|
place-name end ("going to paris" searches "paris"; "to san fran" searches
|
|
660
660
|
"san fran"). Typing in the field itself takes over until it loses focus, and
|
|
@@ -847,6 +847,51 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
|
|
|
847
847
|
|
|
848
848
|
Legacy `--aia-color-*` variables are still supported as fallbacks.
|
|
849
849
|
|
|
850
|
+
## Selector hooks
|
|
851
|
+
|
|
852
|
+
For styling beyond the CSS variables, target these stable `data-aia-*` attributes (CSS-module class hashes are not part of the public API):
|
|
853
|
+
|
|
854
|
+
| Attribute | Element |
|
|
855
|
+
|---|---|
|
|
856
|
+
| `[data-aia-input-wrapper]` | Wrapper around the editor area and the submit button — one of the two roots the SDK isolates from page CSS (the dropdown is the other) |
|
|
857
|
+
| `[data-aia-editor]` | Editor area wrapping the contentEditable + inline pill list |
|
|
858
|
+
| `[data-aia-input]` | The Tier 1 contentEditable `<div>` that owns typed text and bold completed params. (Replaces the previous `[data-aia-textarea]` selector.) |
|
|
859
|
+
| `[data-aia-pill-list-container]` | Inline sibling of the editor that holds unfilled-suggestion pills |
|
|
860
|
+
| `[data-aia-submit]` | Submit button |
|
|
861
|
+
| `[data-aia-pill]` | Each unfilled-suggestion pill |
|
|
862
|
+
| `[data-aia-pillbar]` | Pill bar container inside the dropdown |
|
|
863
|
+
| `[data-aia-pill-scroll]` | Scrollable pill region inside the bar — carries the horizontal scroll and right-edge fade mask |
|
|
864
|
+
| `[data-aia-skip]` | The pill bar's "skip" button: at the header's trailing edge, or alone at the end of a skip-only row. Tune via `--aia-skip-font-size` / `--aia-skip-color` / `--aia-skip-color-hover` / `--aia-skip-hover-bg` |
|
|
865
|
+
| `[data-aia-hint-el]` | The empty box's hint: the lead-in and the first starting options, one at a time. Tune via `--aia-hint-color` / `--aia-hint-font-weight` / `--aia-hint-icon-opacity` |
|
|
866
|
+
| `[data-aia-option]` | Each suggestion option |
|
|
867
|
+
| `[data-aia-scroll-arrow]` | The "more below" arrow on the dropdown — carries `data-aia-visible` while shown |
|
|
868
|
+
| `[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](./README.md#short-screens)). |
|
|
869
|
+
| `[data-aia-datepicker]` | The calendar, rendered in place of the option list for a date parameter |
|
|
870
|
+
| `[data-aia-time-wheel]` | The time wheel, rendered in place of the option list for a time parameter |
|
|
871
|
+
| `[data-aia-location]` | The location search, rendered in place of the option list for a location parameter without options (`[data-aia-location-input]` is its field, `[data-aia-location-row]` each place) |
|
|
872
|
+
| `[data-aia-date-month]` | The "March 2026" header label |
|
|
873
|
+
| `[data-aia-date-prev]` / `[data-aia-date-next]` | The month arrows |
|
|
874
|
+
| `[data-aia-date-grid]` | The 7-column grid of day cells |
|
|
875
|
+
| `[data-aia-date-cell]` | Each day cell. Also carries `[data-aia-option]`, so option-level styling applies to both bodies |
|
|
876
|
+
| `[data-aia-products]` | Product strip section (label + row) |
|
|
877
|
+
| `[data-aia-products-row]` | The horizontally scrolling row of cards |
|
|
878
|
+
| `[data-aia-product]` | Each product card |
|
|
879
|
+
| `[data-aia-product-placeholder]` | Media tile showing the placeholder pictogram (`productImageFallback: "image"`) after a missing/blank URL or load error. The existing hook is unchanged. |
|
|
880
|
+
| `[data-aia-product-initial]` | The media tile itself when it shows the title initial (`productImageFallback: "initial"`). Decorative (`aria-hidden="true"`); target it to style the background, color, font size and border radius. |
|
|
881
|
+
|
|
882
|
+
Completed params render as inline `<strong>` elements inside the editor. Override their weight with `[data-aia-input] strong { font-weight: 700; }` — a selector that names the editor wins without `!important`, while a bare `strong { … }` page rule is kept out by the isolation reset.
|
|
883
|
+
|
|
884
|
+
```css
|
|
885
|
+
/* Solid (non-glass) dropdown */
|
|
886
|
+
.my-autocomplete [data-aia-dropdown] {
|
|
887
|
+
background: #fff;
|
|
888
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
|
889
|
+
backdrop-filter: none;
|
|
890
|
+
}
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
---
|
|
894
|
+
|
|
850
895
|
## Visitor id kept by the SDK
|
|
851
896
|
|
|
852
897
|
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`.
|
|
@@ -877,3 +922,71 @@ onSubmit: (result) => {
|
|
|
877
922
|
```
|
|
878
923
|
|
|
879
924
|
The id of the last search the current tab handed off (a submit or a product pick) is also kept in `sessionStorage` under `aia:last-search`, as `{ id, at }`, where `at` is when it was handed off, in milliseconds since the epoch.
|
|
925
|
+
|
|
926
|
+
## Using your own server
|
|
927
|
+
|
|
928
|
+
By default the SDK sends its requests to the hosted Intent-1 service. Every
|
|
929
|
+
endpoint is replaceable through `apiConfig`, so the widget can talk to your own
|
|
930
|
+
server, a proxy, or a third-party service instead.
|
|
931
|
+
|
|
932
|
+
| Request | Method and URL | Option | Default |
|
|
933
|
+
|---|---|---|---|
|
|
934
|
+
| Suggestions | `POST {endpoint}` | `endpoint` | the hosted service's `…/api/suggest` |
|
|
935
|
+
| Starting state (only with `productId`) | `GET {base}/{productId}/{language}` | `startingStateEndpoint` (the base) | beside `endpoint`: `…/starting-state` |
|
|
936
|
+
| Location search | `POST {locationEndpoint}` | `locationEndpoint` | beside `endpoint`: `…/locations/autocomplete` |
|
|
937
|
+
| Telemetry events | `POST {telemetryEndpoint}` | `telemetryEndpoint` | beside `endpoint`: `…/telemetry/events` |
|
|
938
|
+
|
|
939
|
+
On the hosted service, the starting state is served from its CDN host
|
|
940
|
+
(`cdn.ai-autocomplete.com`) rather than the API host, so an allowlist for the
|
|
941
|
+
default setup (a Content Security Policy's `connect-src`, say) needs both.
|
|
942
|
+
|
|
943
|
+
"Beside `endpoint`" means the `/suggest` at the end of the endpoint's path is
|
|
944
|
+
replaced, keeping its origin, any path prefix and query
|
|
945
|
+
(`https://search.example.com/v1/suggest` → `https://search.example.com/v1/telemetry/events`).
|
|
946
|
+
When `endpoint` does not end in `/suggest` and one of the other options is not
|
|
947
|
+
set, that request is not sent:
|
|
948
|
+
|
|
949
|
+
- **Telemetry:** no events are sent.
|
|
950
|
+
- **Starting state:** it is asked for with an ordinary suggestion request (empty query) instead.
|
|
951
|
+
- **Location search:** the field takes typed text only.
|
|
952
|
+
|
|
953
|
+
```tsx
|
|
954
|
+
<AIAutocomplete
|
|
955
|
+
apiConfig={{
|
|
956
|
+
endpoint: "https://search.example.com/v1/complete",
|
|
957
|
+
// Needed because the endpoint above does not end in /suggest:
|
|
958
|
+
telemetryEndpoint: "https://search.example.com/v1/events",
|
|
959
|
+
startingStateEndpoint: "https://search.example.com/v1/start",
|
|
960
|
+
locationEndpoint: "https://search.example.com/v1/places",
|
|
961
|
+
}}
|
|
962
|
+
/>
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
The suggestion, location search and telemetry requests carry the same
|
|
966
|
+
headers: `Content-Type: application/json`, your `apiConfig.headers`,
|
|
967
|
+
`X-App-Identifier` when `appIdentifier` is set, and an `Authorization` header
|
|
968
|
+
from your API key or access token. The starting-state GET carries none of
|
|
969
|
+
them (no custom headers and no `Authorization`), so it can be served from a
|
|
970
|
+
cache; as a plain GET it still sends the page's cookies to a same-origin
|
|
971
|
+
endpoint. With your own
|
|
972
|
+
endpoint, the SDK opens no connection to the hosted service's hosts, including
|
|
973
|
+
the image CDN it otherwise warms up; images load from whatever URLs your
|
|
974
|
+
responses carry.
|
|
975
|
+
|
|
976
|
+
What each request sends and expects:
|
|
977
|
+
|
|
978
|
+
- **Suggestions:** the request body is `AutocompleteRequest` and the response
|
|
979
|
+
`AutocompleteResponse`, both exported as types by
|
|
980
|
+
`@magicx-eng/ai-autocomplete-vanilla`. The response's optional `custom_fields`
|
|
981
|
+
block is described in [The catalog report](#the-catalog-report-customfields).
|
|
982
|
+
- **Starting state:** the response is the same `AutocompleteResponse`; see
|
|
983
|
+
[Starting state](#starting-state). `{language}` is the lowercase primary
|
|
984
|
+
language subtag (`es` for `es-MX`), or `zh-TW` for Traditional Chinese; the
|
|
985
|
+
segment is left off when the language tag has no usable subtag.
|
|
986
|
+
- **Location search:** the body is `{ query, session_token, language }` and the
|
|
987
|
+
response `{ places: [{ id, name, secondary? }] }` (the `LocationPlace` type).
|
|
988
|
+
A 404 turns the search off for the rest of the session; see
|
|
989
|
+
[Location search](#location-search).
|
|
990
|
+
- **Telemetry:** a fire-and-forget body of `source`, `session_id`, `type`, `at`
|
|
991
|
+
and `query_data`, plus `visitor_id`, `search_id`, `request_id` and
|
|
992
|
+
`language` when known. The response is ignored.
|
package/dist/index.js
CHANGED
|
@@ -3232,15 +3232,25 @@
|
|
|
3232
3232
|
on the inner content instead (next rule). */
|
|
3233
3233
|
}
|
|
3234
3234
|
|
|
3235
|
+
/* Each entrance keyframe also moves \`outline-offset\`, which draws nothing here
|
|
3236
|
+
(the content has no outline). It is there because Chrome runs an animation
|
|
3237
|
+
of only opacity or transform apart from normal painting, and a row whose
|
|
3238
|
+
entrance was still running that way when the panel's dissolve around it
|
|
3239
|
+
ended could stay on its first frame (transparent and 7px low) until
|
|
3240
|
+
something repainted it: with the pointer off the panel after a pick, an
|
|
3241
|
+
option stayed invisible until it was hovered. An animation that also moves
|
|
3242
|
+
a property Chrome paints normally runs with normal painting. */
|
|
3235
3243
|
@keyframes aia-fadeIn-I8u35 {
|
|
3236
3244
|
from {
|
|
3237
3245
|
opacity: 0;
|
|
3246
|
+
outline-offset: 0.5px;
|
|
3238
3247
|
}
|
|
3239
3248
|
}
|
|
3240
3249
|
|
|
3241
3250
|
@keyframes aia-riseIn-etXZT {
|
|
3242
3251
|
from {
|
|
3243
3252
|
transform: translateY(7px);
|
|
3253
|
+
outline-offset: 0.5px;
|
|
3244
3254
|
}
|
|
3245
3255
|
}
|
|
3246
3256
|
|