@magicx-eng/ai-autocomplete-vanilla 0.29.0 → 0.31.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
@@ -124,6 +124,10 @@ const ac = new AIAutocomplete(container, {
124
124
  // - HTMLElement: replaces the default button. Click events bubble up and trigger submit.
125
125
  submitButton: undefined,
126
126
 
127
+ // Clear the input and start a new session after onSubmit (Tier 1 only).
128
+ // false keeps the query in place — e.g. when onSubmit navigates away.
129
+ resetOnSubmit: true,
130
+
127
131
  // Events
128
132
  onSubmit: (result) => { ... },
129
133
  onResult: (result) => { ... }, // after every successful round-trip — see "Reading the query as it's built"
@@ -162,7 +166,7 @@ ac.selectProduct(product); // Emit onProductSelect (Tier 3 / custom strips)
162
166
  ac.getResult(); // The AutocompleteResult as it stands right now
163
167
  ```
164
168
 
165
- > **Tier 1 auto-resets** after both Enter key and built-in submit-button clicks — your `onSubmit` runs, then the SDK clears the input and starts a new session. You don't need to call `ac.reset()` yourself in Tier 1.
169
+ > **Tier 1 auto-resets** after both Enter key and built-in submit-button clicks — your `onSubmit` runs, then the SDK clears the input and starts a new session. You don't need to call `ac.reset()` yourself in Tier 1. Pass `resetOnSubmit: false` to keep the query in place instead — useful when `onSubmit` navigates to a results page, where a cleared field would flash empty until the next page paints — and call `ac.reset()` yourself when you want a fresh session.
166
170
 
167
171
  > `autoFocus`, `focus()`, and `blur()` only operate on the contentEditable editor the library owns (Tier 1 / `renderMode: "full"`). In Tier 2/3, the consumer owns the input and calls `.focus()` / `.blur()` on their own element; the `onFocus` / `onBlur` callbacks still fire whenever `setFocused()` is called.
168
172
 
@@ -948,7 +952,7 @@ The vanilla core also exposes stable BEM class names (`magicx-aia-*`); both can
948
952
 
949
953
  Every `/api/suggest` request carries a `meta.session_id` UUID. A session runs from instance construction (or the last `reset()`) until the next `reset()`. All requests in one session share the same `session_id`; calling `reset()` starts a new one.
950
954
 
951
- - **Tier 1 (`renderMode: "full"`)** — the SDK auto-resets after both Enter key and built-in submit-button clicks. Your `onSubmit` runs first, then the SDK clears the input and starts a new session.
955
+ - **Tier 1 (`renderMode: "full"`)** — the SDK auto-resets after both Enter key and built-in submit-button clicks. Your `onSubmit` runs first, then the SDK clears the input and starts a new session. With `resetOnSubmit: false` it doesn't, and the session continues until you call `reset()`.
952
956
  - **Tier 2/3 (`renderMode: "dropdown" | "headless"`)** — you own the input and submit flow, so you must call `ac.reset()` yourself from your `onSubmit` handler (or from your custom submit button after firing `onSubmit`).
953
957
 
954
958
  > **Why it matters:** suggestions get sharper as a query develops. Each one
package/dist/index.d.mts CHANGED
@@ -941,6 +941,14 @@ interface CoreOptions {
941
941
  * arrow button. Clicks on the provided element bubble up and trigger submit.
942
942
  */
943
943
  submitButton?: HTMLElement | null;
944
+ /**
945
+ * Tier 1 ("full") only. When true (default), the input is cleared and a new
946
+ * session starts after `onSubmit` runs — on Enter and on the submit button.
947
+ * Set to false to leave the query in place: when `onSubmit` navigates away,
948
+ * a cleared field flashes empty until the next page paints. Call `reset()`
949
+ * yourself when you want a fresh session. Tiers 2/3 never auto-reset.
950
+ */
951
+ resetOnSubmit?: boolean;
944
952
  /**
945
953
  * When true (default), the dropdown renders a horizontal row of product
946
954
  * cards below the options grid whenever it has products to show: by default
@@ -1062,6 +1070,8 @@ declare class AIAutocomplete {
1062
1070
  focus(): void;
1063
1071
  blur(): void;
1064
1072
  reset(): void;
1073
+ /** Tier 1's post-submit reset. Read at call time so `update()` can flip it. */
1074
+ private resetAfterSubmit;
1065
1075
  destroy(): void;
1066
1076
  setMode(mode: AppearanceMode): void;
1067
1077
  setValue(text: string): void;
@@ -1157,6 +1167,13 @@ declare class AIAutocomplete {
1157
1167
  handleCaretAfterInput(offset: number | null): void;
1158
1168
  handleCaretMove(offset: number | null): void;
1159
1169
  setActiveDropdownIndex(index: number): void;
1170
+ /**
1171
+ * The pointer left option `index`: clear the highlight if it is still on
1172
+ * that option. A hover highlight that outlived the hover made Enter pick an
1173
+ * option the pointer was no longer on instead of submitting the search. A
1174
+ * highlight the keyboard has since moved elsewhere is left alone.
1175
+ */
1176
+ clearHighlight(index: number): void;
1160
1177
  /**
1161
1178
  * Announce a product selection. The rendered cards call this on activation;
1162
1179
  * headless consumers rendering their own strip call it themselves.
package/dist/index.d.ts CHANGED
@@ -941,6 +941,14 @@ interface CoreOptions {
941
941
  * arrow button. Clicks on the provided element bubble up and trigger submit.
942
942
  */
943
943
  submitButton?: HTMLElement | null;
944
+ /**
945
+ * Tier 1 ("full") only. When true (default), the input is cleared and a new
946
+ * session starts after `onSubmit` runs — on Enter and on the submit button.
947
+ * Set to false to leave the query in place: when `onSubmit` navigates away,
948
+ * a cleared field flashes empty until the next page paints. Call `reset()`
949
+ * yourself when you want a fresh session. Tiers 2/3 never auto-reset.
950
+ */
951
+ resetOnSubmit?: boolean;
944
952
  /**
945
953
  * When true (default), the dropdown renders a horizontal row of product
946
954
  * cards below the options grid whenever it has products to show: by default
@@ -1062,6 +1070,8 @@ declare class AIAutocomplete {
1062
1070
  focus(): void;
1063
1071
  blur(): void;
1064
1072
  reset(): void;
1073
+ /** Tier 1's post-submit reset. Read at call time so `update()` can flip it. */
1074
+ private resetAfterSubmit;
1065
1075
  destroy(): void;
1066
1076
  setMode(mode: AppearanceMode): void;
1067
1077
  setValue(text: string): void;
@@ -1157,6 +1167,13 @@ declare class AIAutocomplete {
1157
1167
  handleCaretAfterInput(offset: number | null): void;
1158
1168
  handleCaretMove(offset: number | null): void;
1159
1169
  setActiveDropdownIndex(index: number): void;
1170
+ /**
1171
+ * The pointer left option `index`: clear the highlight if it is still on
1172
+ * that option. A hover highlight that outlived the hover made Enter pick an
1173
+ * option the pointer was no longer on instead of submitting the search. A
1174
+ * highlight the keyboard has since moved elsewhere is left alone.
1175
+ */
1176
+ clearHighlight(index: number): void;
1160
1177
  /**
1161
1178
  * Announce a product selection. The rendered cards call this on activation;
1162
1179
  * headless consumers rendering their own strip call it themselves.