@magicx-eng/ai-autocomplete-vanilla 0.43.0 → 0.45.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 +25 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -311,6 +311,31 @@ ac.subscribe((state) => {
|
|
|
311
311
|
catalog. The strip clears on such a response rather than keeping an older
|
|
312
312
|
query's items.
|
|
313
313
|
|
|
314
|
+
#### Change product cards before display
|
|
315
|
+
|
|
316
|
+
- `mapProducts(products, items)` synchronously returns the cards to show.
|
|
317
|
+
- The SDK calls it once per response with its default cards and their matched items in the same order.
|
|
318
|
+
- The returned array becomes the product state and the displayed strip.
|
|
319
|
+
- A thrown error or a non-array result keeps the default cards. A thrown error warns once per instance.
|
|
320
|
+
- `refreshProducts()` maps the current items again without a request. Call it when your own data arrives.
|
|
321
|
+
- Both APIs leave a custom `products` integration unchanged.
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
const autocomplete = new AIAutocomplete(container, {
|
|
325
|
+
mapProducts: (products, items) =>
|
|
326
|
+
products.map((product, index) => ({
|
|
327
|
+
...product,
|
|
328
|
+
price: shopperPrices[items[index].source_id] ?? "",
|
|
329
|
+
})),
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// After updating shopperPrices:
|
|
333
|
+
autocomplete.refreshProducts();
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
- `update({ mapProducts })` immediately maps the current items with the new mapper.
|
|
337
|
+
- Price changes add, update, or remove price text on the same cards. Selection reports the updated product.
|
|
338
|
+
|
|
314
339
|
#### Your own product search (`products`)
|
|
315
340
|
|
|
316
341
|
To source the cards from your own search instead — a platform with its own
|
package/dist/index.d.mts
CHANGED
|
@@ -1070,6 +1070,13 @@ interface CoreOptions {
|
|
|
1070
1070
|
* not rendered.
|
|
1071
1071
|
*/
|
|
1072
1072
|
products?: ProductsConfig;
|
|
1073
|
+
/**
|
|
1074
|
+
* Runs synchronously with the SDK's cards and their response items in the same order.
|
|
1075
|
+
* The product strip shows the returned array.
|
|
1076
|
+
* Does not apply to a custom products integration.
|
|
1077
|
+
* A throw or a result that is not an array keeps the SDK's cards.
|
|
1078
|
+
*/
|
|
1079
|
+
mapProducts?: (products: Product[], items: MatchedItem[]) => Product[];
|
|
1073
1080
|
/** Called when the user submits (Enter, or the submit button in Tier 1). */
|
|
1074
1081
|
onSubmit?: (result: AutocompleteResult) => void;
|
|
1075
1082
|
/**
|
|
@@ -1373,6 +1380,12 @@ declare class AIAutocomplete {
|
|
|
1373
1380
|
* `on()` once each; their unsubscribe handles are not exposed.
|
|
1374
1381
|
*/
|
|
1375
1382
|
on<E extends keyof AIAutocompleteEvents>(event: E, callback: (...args: AIAutocompleteEvents[E]) => void): () => void;
|
|
1383
|
+
/**
|
|
1384
|
+
* Runs mapProducts synchronously on the shown items again without a request.
|
|
1385
|
+
* Keeps the same cards while updating their content.
|
|
1386
|
+
* Does nothing without mapProducts or with a custom products integration.
|
|
1387
|
+
*/
|
|
1388
|
+
refreshProducts(): void;
|
|
1376
1389
|
update(opts: CoreUpdateOptions): void;
|
|
1377
1390
|
selectOption(option: SuggestionOption): void;
|
|
1378
1391
|
private applyOption;
|
package/dist/index.d.ts
CHANGED
|
@@ -1070,6 +1070,13 @@ interface CoreOptions {
|
|
|
1070
1070
|
* not rendered.
|
|
1071
1071
|
*/
|
|
1072
1072
|
products?: ProductsConfig;
|
|
1073
|
+
/**
|
|
1074
|
+
* Runs synchronously with the SDK's cards and their response items in the same order.
|
|
1075
|
+
* The product strip shows the returned array.
|
|
1076
|
+
* Does not apply to a custom products integration.
|
|
1077
|
+
* A throw or a result that is not an array keeps the SDK's cards.
|
|
1078
|
+
*/
|
|
1079
|
+
mapProducts?: (products: Product[], items: MatchedItem[]) => Product[];
|
|
1073
1080
|
/** Called when the user submits (Enter, or the submit button in Tier 1). */
|
|
1074
1081
|
onSubmit?: (result: AutocompleteResult) => void;
|
|
1075
1082
|
/**
|
|
@@ -1373,6 +1380,12 @@ declare class AIAutocomplete {
|
|
|
1373
1380
|
* `on()` once each; their unsubscribe handles are not exposed.
|
|
1374
1381
|
*/
|
|
1375
1382
|
on<E extends keyof AIAutocompleteEvents>(event: E, callback: (...args: AIAutocompleteEvents[E]) => void): () => void;
|
|
1383
|
+
/**
|
|
1384
|
+
* Runs mapProducts synchronously on the shown items again without a request.
|
|
1385
|
+
* Keeps the same cards while updating their content.
|
|
1386
|
+
* Does nothing without mapProducts or with a custom products integration.
|
|
1387
|
+
*/
|
|
1388
|
+
refreshProducts(): void;
|
|
1376
1389
|
update(opts: CoreUpdateOptions): void;
|
|
1377
1390
|
selectOption(option: SuggestionOption): void;
|
|
1378
1391
|
private applyOption;
|