@magicx-eng/ai-autocomplete-vanilla 0.61.0 → 0.63.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
@@ -107,6 +107,7 @@ const ac = new AIAutocomplete(container, {
107
107
  pillPlacement: "dropdown", // "inline" | "dropdown" | "hidden"
108
108
  dropdownTrigger: "auto", // "auto" | "manual" | "hidden"
109
109
  closeDropdownOnBlur: true, // false = keep dropdown open even when input loses focus
110
+ prependPlaceholder: true, // false = show the starting state's lead-in text as a hint only; a picked option is not written after it
110
111
  showNonTappableOptions: true, // false = hide non-tappable options from the dropdown
111
112
  locationSearch: true, // false = a location field takes typed text only, no lookups
112
113
  showSkipButton: true, // false = hide the pill bar's trailing "skip" button
@@ -727,6 +728,8 @@ new AIAutocomplete(el, {
727
728
 
728
729
  **What's shown.** Your answer, as-is: it is not filtered again by the phrase it was produced for, so a fuzzy or synonym match survives. Between two calls the previous answer is filtered locally by what the user types, so the list reacts to every keystroke. Typing the full text of an option in the answer completes the parameter, exactly as it does for a server option.
729
730
 
731
+ **Icons.** When the server has an icon saved for the parameter it sends it on the suggestion (`icon` / `icon_svg`), and each option you return that has no `icon_svg` or `image_url` of its own is drawn with it. Give an option its own `icon_svg` or `image_url` to show that instead.
732
+
730
733
  **The server's role.** The server's own options for an overridden parameter are never shown. While an override owns the active parameter the server is not asked for suggestions; it is asked again when the parameter is answered or skipped. Return an empty list for a typed phrase and the SDK falls back to the server for that phrase — the typed text goes out the way it does for a parameter with no matching options — and won't ask you the same phrase twice. An empty list for `""` leaves the parameter on screen with no options.
731
734
 
732
735
  **Cancellation and errors.** Honour `signal`: it is aborted when a newer phrase supersedes the call, when the parameter stops being active, and on `destroy()`. A throw or a rejection is logged once per instance and treated as an empty answer, never as a fetch error.
package/dist/index.d.mts CHANGED
@@ -113,6 +113,19 @@ interface Suggestion {
113
113
  * none, which then answer exactly as before.
114
114
  */
115
115
  lead_in?: string;
116
+ /**
117
+ * The name of an icon for the whole question, such as `"map-pinned"` for a
118
+ * destination. The server sends it with `icon_svg` on a question it lists
119
+ * no tappable options for, when it has an icon saved for the parameter.
120
+ */
121
+ icon?: string;
122
+ /**
123
+ * Inline SVG markup for the question's icon. The SDK copies it, with `icon`,
124
+ * onto each `optionOverrides` option that brings no `icon_svg` or
125
+ * `image_url` of its own, so the rows the app supplies draw it like any
126
+ * option icon. It is not drawn anywhere else.
127
+ */
128
+ icon_svg?: string;
116
129
  }
117
130
  interface InputItem {
118
131
  parameter: string;
@@ -351,6 +364,13 @@ interface CompletedParamState extends CompletedParam {
351
364
  suggestionValueType?: SuggestionType;
352
365
  /** Source suggestion's `text` — used by re-edit mode to render the dropdown pill. */
353
366
  suggestionPlaceholder: string;
367
+ /**
368
+ * Source suggestion's `icon` / `icon_svg` (see {@link Suggestion.icon_svg}),
369
+ * carried so the `optionOverrides` options asked again in re-edit draw the
370
+ * same icon the first list did.
371
+ */
372
+ suggestionIcon?: string;
373
+ suggestionIconSvg?: string;
354
374
  /** Cached options from the suggestion that produced this param — re-edit shows these. */
355
375
  options: SuggestionOption[];
356
376
  metadata?: Record<string, unknown>;
@@ -1188,6 +1208,12 @@ interface CoreDerivedState {
1188
1208
  */
1189
1209
  locationView: LocationView | null;
1190
1210
  placeholderText: string;
1211
+ /**
1212
+ * The part of `placeholderText` that leads the query: put before the first
1213
+ * answer and skipped over when the user retypes it. Equal to
1214
+ * `placeholderText`, or `""` when `prependPlaceholder` is `false`.
1215
+ */
1216
+ leadInText: string;
1191
1217
  /**
1192
1218
  * The phrase the active pill's options are filtered by — what the user has
1193
1219
  * typed for it, trimmed — or, during a re-edit, the replacement typed so
@@ -1308,6 +1334,15 @@ interface CoreOptions {
1308
1334
  dropdownTrigger?: "auto" | "manual" | "hidden";
1309
1335
  /** When true (default), the dropdown closes when the input loses focus. Set to false to keep it open whenever options are available, regardless of focus. */
1310
1336
  closeDropdownOnBlur?: boolean;
1337
+ /**
1338
+ * Whether the starting state's lead-in text is put in front of the first
1339
+ * answer. Default `true`: the text shows in the empty input and picking an
1340
+ * option writes it before the option ("Create a" + "email"). Set to `false`
1341
+ * to show it as a hint only: a pick writes just the option, and typing the
1342
+ * text's first letters is ordinary typing. Use it where the lead-in does not
1343
+ * read naturally before an answer, as in verb-final languages.
1344
+ */
1345
+ prependPlaceholder?: boolean;
1311
1346
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
1312
1347
  showNonTappableOptions?: boolean;
1313
1348
  /**
package/dist/index.d.ts CHANGED
@@ -113,6 +113,19 @@ interface Suggestion {
113
113
  * none, which then answer exactly as before.
114
114
  */
115
115
  lead_in?: string;
116
+ /**
117
+ * The name of an icon for the whole question, such as `"map-pinned"` for a
118
+ * destination. The server sends it with `icon_svg` on a question it lists
119
+ * no tappable options for, when it has an icon saved for the parameter.
120
+ */
121
+ icon?: string;
122
+ /**
123
+ * Inline SVG markup for the question's icon. The SDK copies it, with `icon`,
124
+ * onto each `optionOverrides` option that brings no `icon_svg` or
125
+ * `image_url` of its own, so the rows the app supplies draw it like any
126
+ * option icon. It is not drawn anywhere else.
127
+ */
128
+ icon_svg?: string;
116
129
  }
117
130
  interface InputItem {
118
131
  parameter: string;
@@ -351,6 +364,13 @@ interface CompletedParamState extends CompletedParam {
351
364
  suggestionValueType?: SuggestionType;
352
365
  /** Source suggestion's `text` — used by re-edit mode to render the dropdown pill. */
353
366
  suggestionPlaceholder: string;
367
+ /**
368
+ * Source suggestion's `icon` / `icon_svg` (see {@link Suggestion.icon_svg}),
369
+ * carried so the `optionOverrides` options asked again in re-edit draw the
370
+ * same icon the first list did.
371
+ */
372
+ suggestionIcon?: string;
373
+ suggestionIconSvg?: string;
354
374
  /** Cached options from the suggestion that produced this param — re-edit shows these. */
355
375
  options: SuggestionOption[];
356
376
  metadata?: Record<string, unknown>;
@@ -1188,6 +1208,12 @@ interface CoreDerivedState {
1188
1208
  */
1189
1209
  locationView: LocationView | null;
1190
1210
  placeholderText: string;
1211
+ /**
1212
+ * The part of `placeholderText` that leads the query: put before the first
1213
+ * answer and skipped over when the user retypes it. Equal to
1214
+ * `placeholderText`, or `""` when `prependPlaceholder` is `false`.
1215
+ */
1216
+ leadInText: string;
1191
1217
  /**
1192
1218
  * The phrase the active pill's options are filtered by — what the user has
1193
1219
  * typed for it, trimmed — or, during a re-edit, the replacement typed so
@@ -1308,6 +1334,15 @@ interface CoreOptions {
1308
1334
  dropdownTrigger?: "auto" | "manual" | "hidden";
1309
1335
  /** When true (default), the dropdown closes when the input loses focus. Set to false to keep it open whenever options are available, regardless of focus. */
1310
1336
  closeDropdownOnBlur?: boolean;
1337
+ /**
1338
+ * Whether the starting state's lead-in text is put in front of the first
1339
+ * answer. Default `true`: the text shows in the empty input and picking an
1340
+ * option writes it before the option ("Create a" + "email"). Set to `false`
1341
+ * to show it as a hint only: a pick writes just the option, and typing the
1342
+ * text's first letters is ordinary typing. Use it where the lead-in does not
1343
+ * read naturally before an answer, as in verb-final languages.
1344
+ */
1345
+ prependPlaceholder?: boolean;
1311
1346
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
1312
1347
  showNonTappableOptions?: boolean;
1313
1348
  /**