@magicx-eng/ai-autocomplete-vanilla 0.16.1 → 0.17.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 +38 -5
- package/dist/index.d.mts +76 -8
- package/dist/index.d.ts +76 -8
- 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
|
@@ -112,6 +112,7 @@ const ac = new AIAutocomplete(container, {
|
|
|
112
112
|
|
|
113
113
|
// Events
|
|
114
114
|
onSubmit: (result) => { ... },
|
|
115
|
+
onResult: (result) => { ... }, // after every successful round-trip — see "Reading the query as it's built"
|
|
115
116
|
onError: (error) => { ... },
|
|
116
117
|
onChange: (text) => { ... },
|
|
117
118
|
onParamsChange: (params) => { ... },
|
|
@@ -135,6 +136,7 @@ ac.destroy(); // Remove DOM, listeners, timers
|
|
|
135
136
|
ac.setMode("dark"); // Switch color mode
|
|
136
137
|
ac.update({ animations: false, optionsPosition: "above" });
|
|
137
138
|
ac.selectProduct(product); // Emit onProductSelect (Tier 3 / custom strips)
|
|
139
|
+
ac.getResult(); // The AutocompleteResult as it stands right now
|
|
138
140
|
```
|
|
139
141
|
|
|
140
142
|
> **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.
|
|
@@ -553,13 +555,42 @@ The SDK handles token refresh transparently: if a request returns 401, it calls
|
|
|
553
555
|
|
|
554
556
|
### `AutocompleteResult`
|
|
555
557
|
|
|
556
|
-
The object passed to `onSubmit
|
|
558
|
+
The structured query as the SDK currently understands it. The same object is passed to `onSubmit` when the user submits, to `onResult` after every successful round-trip, and returned by `ac.getResult()` on demand:
|
|
557
559
|
|
|
558
560
|
| Field | Type | Description |
|
|
559
561
|
|---|---|---|
|
|
560
|
-
| `query` | `string` | Plain text as the user sees it. |
|
|
561
|
-
| `raw_query` | `string` |
|
|
562
|
-
| `completed_params` | `CompletedParam[]` |
|
|
562
|
+
| `query` | `string` | Plain text as the user sees it, trimmed. |
|
|
563
|
+
| `raw_query` | `string` | `query` with each completed param replaced by its placeholder token (e.g. `"Create a {{TASK_1}}"`). |
|
|
564
|
+
| `completed_params` | `CompletedParam[]` | Filled parameter values in query order, followed by any the user skipped (see below). |
|
|
565
|
+
| `identified_params` | `IdentifiedParam[]` | Parameters the server recognised in the user's own words, as `{ type, value }` — e.g. `{ type: "due_date", value: "Friday" }` when the user typed "by Friday" instead of picking a date. They are not tokenized in `raw_query`, and they are tentative: each response replaces the set, and an entry drops out as soon as its text is edited away. |
|
|
566
|
+
| `is_ready` | `boolean` | Whether the server considers the query complete enough to act on. |
|
|
567
|
+
|
|
568
|
+
#### Reading the query as it's built
|
|
569
|
+
|
|
570
|
+
You don't have to wait for submit. `onResult` fires after **every** successful round-trip with the result as it now stands, so you can mirror the structured query live — a preview panel, a draft saved as the user goes, analytics on how far they got:
|
|
571
|
+
|
|
572
|
+
```ts
|
|
573
|
+
const ac = new AIAutocomplete(el, {
|
|
574
|
+
onResult: (result) => {
|
|
575
|
+
preview.textContent = result.raw_query;
|
|
576
|
+
if (result.is_ready) enableRunButton();
|
|
577
|
+
},
|
|
578
|
+
onSubmit: (result) => run(result),
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// Or subscribe later / more than once:
|
|
582
|
+
const off = ac.on("result", (result) => save(result));
|
|
583
|
+
|
|
584
|
+
// Or read it on demand, from a place that has no event handy:
|
|
585
|
+
const draft = ac.getResult();
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
What "every successful round-trip" means in practice:
|
|
589
|
+
|
|
590
|
+
- It fires once per response the SDK applied — including the very first request on mount (an empty result) and after a response that promoted text the user had already typed into a completed param.
|
|
591
|
+
- It does **not** fire for a request that failed (`onError` does), was cancelled, or was superseded by a newer one before it returned.
|
|
592
|
+
- Keystrokes that haven't been sent yet don't fire it. Typing is debounced and only reaches the server once at least two new characters have been added, so `onResult` lags the input by a beat; `ac.getResult()` always reflects the input as it is right now.
|
|
593
|
+
- A submit is the last result you saw plus whatever the user typed since. Both are built by the same exported `buildSubmitResult`, so the shapes never drift.
|
|
563
594
|
|
|
564
595
|
#### Skipped parameters
|
|
565
596
|
|
|
@@ -585,7 +616,9 @@ const offA = ac.on("change", logToAnalytics);
|
|
|
585
616
|
const offB = ac.on("change", syncToStore);
|
|
586
617
|
```
|
|
587
618
|
|
|
588
|
-
Events: `submit`, `error`, `change`, `paramsChange`, `stateChange`, `focus`, `blur`, `productSelect`.
|
|
619
|
+
Events: `submit`, `result`, `error`, `change`, `paramsChange`, `stateChange`, `focus`, `blur`, `productSelect`.
|
|
620
|
+
|
|
621
|
+
`result` carries an `AutocompleteResult` after every successful round-trip — see [Reading the query as it's built](#reading-the-query-as-its-built). Prefer it over `stateChange` when what you want is the structured query: `stateChange` fires on every internal update (focus, highlight, keystroke) and hands you raw state you would have to assemble yourself.
|
|
589
622
|
|
|
590
623
|
**Errors in your callbacks are contained.** A listener that throws is logged to the console (once per event per instance) and the remaining listeners still run — the SDK's own state is unaffected, so a bug in one handler can't stall the widget. The same holds for `subscribe()` listeners and `optionOverrides` functions; an override that throws falls back to that suggestion's existing options rather than blanking the list. One exception is deliberate: if an `onSubmit` handler throws, Tier 1 skips its auto-reset so the user's typed query isn't cleared out from under a failed submit.
|
|
591
624
|
|
package/dist/index.d.mts
CHANGED
|
@@ -208,10 +208,33 @@ interface ProductsConfig {
|
|
|
208
208
|
/** Optional cap the SDK applies after `transform`. */
|
|
209
209
|
limit?: number;
|
|
210
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* The structured query as the SDK currently understands it.
|
|
213
|
+
*
|
|
214
|
+
* Delivered to `onResult` after every successful suggestion round-trip and to
|
|
215
|
+
* `onSubmit` when the user submits. Both are built by `buildSubmitResult`, so
|
|
216
|
+
* a submit is just the last result the consumer already saw — plus whatever
|
|
217
|
+
* the user typed in between.
|
|
218
|
+
*/
|
|
211
219
|
interface AutocompleteResult {
|
|
220
|
+
/** Plain text as the user sees it, trimmed. */
|
|
212
221
|
query: string;
|
|
222
|
+
/** `query` with each completed param replaced by its `{{PLACEHOLDER}}` token. */
|
|
213
223
|
raw_query: string;
|
|
224
|
+
/**
|
|
225
|
+
* Params the user filled (in query order), followed by any they skipped
|
|
226
|
+
* (`text: "skipped"`, no placeholder). See `withSkippedParams`.
|
|
227
|
+
*/
|
|
214
228
|
completed_params: CompletedParam[];
|
|
229
|
+
/**
|
|
230
|
+
* Params the server identified in the user's own words — spans it matched to
|
|
231
|
+
* a parameter type without the user picking an option. Tentative: replaced
|
|
232
|
+
* wholesale by every response and dropped as soon as the text no longer
|
|
233
|
+
* matches. Never tokenized in `raw_query`.
|
|
234
|
+
*/
|
|
235
|
+
identified_params: IdentifiedParam[];
|
|
236
|
+
/** Whether the server considers the query complete enough to act on. */
|
|
237
|
+
is_ready: boolean;
|
|
215
238
|
}
|
|
216
239
|
|
|
217
240
|
/** A calendar month on screen. `month` is 0-based, matching `Date#getMonth`. */
|
|
@@ -561,7 +584,22 @@ interface CoreOptions {
|
|
|
561
584
|
* the dropdown changes — no request, no markup, no layout shift.
|
|
562
585
|
*/
|
|
563
586
|
products?: ProductsConfig;
|
|
587
|
+
/** Called when the user submits (Enter, or the submit button in Tier 1). */
|
|
564
588
|
onSubmit?: (result: AutocompleteResult) => void;
|
|
589
|
+
/**
|
|
590
|
+
* Called after every successful suggestion round-trip with the structured
|
|
591
|
+
* query as the SDK now understands it — the same `AutocompleteResult` shape
|
|
592
|
+
* `onSubmit` delivers, so a consumer can mirror the query as it is built
|
|
593
|
+
* (a live preview, a draft, analytics) without waiting for submit.
|
|
594
|
+
*
|
|
595
|
+
* Fires once per response that was applied, including the initial request
|
|
596
|
+
* on mount (an empty result) and after a response that promoted typed text
|
|
597
|
+
* into a completed param. Does not fire for a request that failed, was
|
|
598
|
+
* aborted, or was superseded by a newer one before it returned. Nothing
|
|
599
|
+
* fires for a keystroke that hasn't been sent yet — read `getResult()` for
|
|
600
|
+
* the current value on demand.
|
|
601
|
+
*/
|
|
602
|
+
onResult?: (result: AutocompleteResult) => void;
|
|
565
603
|
onError?: (error: Error) => void;
|
|
566
604
|
onChange?: (text: string) => void;
|
|
567
605
|
onParamsChange?: (params: CompletedParamState[]) => void;
|
|
@@ -591,6 +629,7 @@ interface CoreOptions {
|
|
|
591
629
|
|
|
592
630
|
type AIAutocompleteEvents = {
|
|
593
631
|
submit: [result: AutocompleteResult];
|
|
632
|
+
result: [result: AutocompleteResult];
|
|
594
633
|
error: [error: Error];
|
|
595
634
|
change: [text: string];
|
|
596
635
|
paramsChange: [params: CompletedParamState[]];
|
|
@@ -599,7 +638,7 @@ type AIAutocompleteEvents = {
|
|
|
599
638
|
blur: [];
|
|
600
639
|
productSelect: [product: Product];
|
|
601
640
|
};
|
|
602
|
-
type CoreUpdateOptions = Partial<Omit<CoreOptions, "onSubmit" | "onError" | "onChange" | "onParamsChange" | "onStateChange" | "onFocus" | "onBlur" | "onProductSelect" | "styleRoot">>;
|
|
641
|
+
type CoreUpdateOptions = Partial<Omit<CoreOptions, "onSubmit" | "onResult" | "onError" | "onChange" | "onParamsChange" | "onStateChange" | "onFocus" | "onBlur" | "onProductSelect" | "styleRoot">>;
|
|
603
642
|
declare class AIAutocomplete {
|
|
604
643
|
private inputStore;
|
|
605
644
|
private store;
|
|
@@ -782,6 +821,14 @@ declare class AIAutocomplete {
|
|
|
782
821
|
*/
|
|
783
822
|
subscribe(listener: (state: CoreState) => void): () => void;
|
|
784
823
|
getState(): CoreState;
|
|
824
|
+
/**
|
|
825
|
+
* The structured query as the SDK understands it right now — the same
|
|
826
|
+
* object `onResult` delivers after each response and `onSubmit` delivers
|
|
827
|
+
* on submit. Read it on demand from a place that has no event handy (a
|
|
828
|
+
* custom submit button, a "save draft" action).
|
|
829
|
+
*/
|
|
830
|
+
getResult(): AutocompleteResult;
|
|
831
|
+
private buildResult;
|
|
785
832
|
get listboxId(): string;
|
|
786
833
|
get isReady(): boolean;
|
|
787
834
|
/**
|
|
@@ -1289,6 +1336,16 @@ declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean
|
|
|
1289
1336
|
hint: string;
|
|
1290
1337
|
};
|
|
1291
1338
|
|
|
1339
|
+
/**
|
|
1340
|
+
* Projects client-side identified-param state onto its wire shape.
|
|
1341
|
+
*
|
|
1342
|
+
* The one place the `{ type, value }` form is spelled out. Both the request
|
|
1343
|
+
* body (`api.ts`) and the `AutocompleteResult` handed to `onResult` /
|
|
1344
|
+
* `onSubmit` go through it, so the params the consumer receives are exactly
|
|
1345
|
+
* the ones the server was told about.
|
|
1346
|
+
*/
|
|
1347
|
+
declare function toWireIdentifiedParams(params: IdentifiedParamState[]): IdentifiedParam[];
|
|
1348
|
+
|
|
1292
1349
|
declare class ModeController {
|
|
1293
1350
|
private container;
|
|
1294
1351
|
private mode;
|
|
@@ -1342,14 +1399,25 @@ declare const SKIPPED_PARAM_TEXT = "skipped";
|
|
|
1342
1399
|
declare function withSkippedParams(completed: CompletedParam[], skipped: SkippedParamState[]): CompletedParam[];
|
|
1343
1400
|
|
|
1344
1401
|
/**
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
|
|
1402
|
+
* Fields of an {@link AutocompleteResult} that come from the latest server
|
|
1403
|
+
* response rather than from the input. Both default to "nothing yet".
|
|
1404
|
+
*/
|
|
1405
|
+
interface SubmitResultExtras {
|
|
1406
|
+
/** Server-identified params (`state.identifiedParams`). Default: none. */
|
|
1407
|
+
identifiedParams?: IdentifiedParamState[];
|
|
1408
|
+
/** Server's "query is complete" verdict (`state.isReady`). Default: false. */
|
|
1409
|
+
isReady?: boolean;
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Builds the `AutocompleteResult` handed to `onSubmit` and `onResult`: the
|
|
1413
|
+
* placeholder-tokenized raw query plus the completed params, with skipped
|
|
1414
|
+
* suggestions folded in (see {@link withSkippedParams}), the server-identified
|
|
1415
|
+
* params in their wire shape, and the server's readiness verdict.
|
|
1348
1416
|
*
|
|
1349
1417
|
* Shared by every submit path — vanilla Enter / submit button, the React Tier 1
|
|
1350
|
-
* component, the Angular Tier 1 component —
|
|
1351
|
-
* result contains.
|
|
1418
|
+
* component, the Angular Tier 1 component — and by the core's per-response
|
|
1419
|
+
* `result` event, so none of them can drift on what a result contains.
|
|
1352
1420
|
*/
|
|
1353
|
-
declare function buildSubmitResult(text: string, completedParams: CompletedParamState[], skippedParams?: SkippedParamState[]): AutocompleteResult;
|
|
1421
|
+
declare function buildSubmitResult(text: string, completedParams: CompletedParamState[], skippedParams?: SkippedParamState[], extras?: SubmitResultExtras): AutocompleteResult;
|
|
1354
1422
|
|
|
1355
|
-
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 DateMonthView, type FormatType, type IdentifiedParam, type IdentifiedParamState, type InputItem, type LooseDateOptions, 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, type OptionOverrides, type OptionsGridLayout, type OptionsGridPlan, PLACEHOLDER_FADE_OUT_MS, PLACEHOLDER_LEAVING_ATTR, PLACEHOLDER_SWAP_GAP_MS, PLACEHOLDER_TYPE_MS, PLACEHOLDER_WORD_PAUSE_MS, type Product, type ProductsConfig, type RecentlySuggested, type RenderMode, SCROLL_ARROW_ATTR, SCROLL_ARROW_BOTTOM_VAR, SCROLL_ARROW_CLASS, SCROLL_ARROW_LABEL, SCROLL_ARROW_VISIBLE_ATTR, SKIPPED_PARAM_TEXT, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type Suggestion, type SuggestionOption, type TaskKind, WEEKDAY_LABELS, addMonths, attachScrollArrow, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, computeOptionsGridLayout, createStore, cursorIsAtEnd, extractPlainText, formatDate, getCursorOffset, getFooterHint, identifiedParamLabel, isOptionsGridMobileViewport, isoDate, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionEnterDelayMs, optionsEntranceDurationMs, optionsGridTemplateColumns, parseDate, parseLooseDate, plainTextLength, planOptionsGrid, previousGraphemeBoundary, renderEditableContent, resolveFormatType, resolveIdentifiedDate, scrollCaretIntoView, selectedIsoFromText, setCursorOffset, withSkippedParams };
|
|
1423
|
+
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 DateMonthView, type FormatType, type IdentifiedParam, type IdentifiedParamState, type InputItem, type LooseDateOptions, 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, type OptionOverrides, type OptionsGridLayout, type OptionsGridPlan, PLACEHOLDER_FADE_OUT_MS, PLACEHOLDER_LEAVING_ATTR, PLACEHOLDER_SWAP_GAP_MS, PLACEHOLDER_TYPE_MS, PLACEHOLDER_WORD_PAUSE_MS, type Product, type ProductsConfig, type RecentlySuggested, type RenderMode, SCROLL_ARROW_ATTR, SCROLL_ARROW_BOTTOM_VAR, SCROLL_ARROW_CLASS, SCROLL_ARROW_LABEL, SCROLL_ARROW_VISIBLE_ATTR, SKIPPED_PARAM_TEXT, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type TaskKind, WEEKDAY_LABELS, addMonths, attachScrollArrow, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, computeOptionsGridLayout, createStore, cursorIsAtEnd, extractPlainText, formatDate, getCursorOffset, getFooterHint, identifiedParamLabel, isOptionsGridMobileViewport, isoDate, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionEnterDelayMs, optionsEntranceDurationMs, optionsGridTemplateColumns, parseDate, parseLooseDate, plainTextLength, planOptionsGrid, previousGraphemeBoundary, renderEditableContent, resolveFormatType, resolveIdentifiedDate, scrollCaretIntoView, selectedIsoFromText, setCursorOffset, toWireIdentifiedParams, withSkippedParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -208,10 +208,33 @@ interface ProductsConfig {
|
|
|
208
208
|
/** Optional cap the SDK applies after `transform`. */
|
|
209
209
|
limit?: number;
|
|
210
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* The structured query as the SDK currently understands it.
|
|
213
|
+
*
|
|
214
|
+
* Delivered to `onResult` after every successful suggestion round-trip and to
|
|
215
|
+
* `onSubmit` when the user submits. Both are built by `buildSubmitResult`, so
|
|
216
|
+
* a submit is just the last result the consumer already saw — plus whatever
|
|
217
|
+
* the user typed in between.
|
|
218
|
+
*/
|
|
211
219
|
interface AutocompleteResult {
|
|
220
|
+
/** Plain text as the user sees it, trimmed. */
|
|
212
221
|
query: string;
|
|
222
|
+
/** `query` with each completed param replaced by its `{{PLACEHOLDER}}` token. */
|
|
213
223
|
raw_query: string;
|
|
224
|
+
/**
|
|
225
|
+
* Params the user filled (in query order), followed by any they skipped
|
|
226
|
+
* (`text: "skipped"`, no placeholder). See `withSkippedParams`.
|
|
227
|
+
*/
|
|
214
228
|
completed_params: CompletedParam[];
|
|
229
|
+
/**
|
|
230
|
+
* Params the server identified in the user's own words — spans it matched to
|
|
231
|
+
* a parameter type without the user picking an option. Tentative: replaced
|
|
232
|
+
* wholesale by every response and dropped as soon as the text no longer
|
|
233
|
+
* matches. Never tokenized in `raw_query`.
|
|
234
|
+
*/
|
|
235
|
+
identified_params: IdentifiedParam[];
|
|
236
|
+
/** Whether the server considers the query complete enough to act on. */
|
|
237
|
+
is_ready: boolean;
|
|
215
238
|
}
|
|
216
239
|
|
|
217
240
|
/** A calendar month on screen. `month` is 0-based, matching `Date#getMonth`. */
|
|
@@ -561,7 +584,22 @@ interface CoreOptions {
|
|
|
561
584
|
* the dropdown changes — no request, no markup, no layout shift.
|
|
562
585
|
*/
|
|
563
586
|
products?: ProductsConfig;
|
|
587
|
+
/** Called when the user submits (Enter, or the submit button in Tier 1). */
|
|
564
588
|
onSubmit?: (result: AutocompleteResult) => void;
|
|
589
|
+
/**
|
|
590
|
+
* Called after every successful suggestion round-trip with the structured
|
|
591
|
+
* query as the SDK now understands it — the same `AutocompleteResult` shape
|
|
592
|
+
* `onSubmit` delivers, so a consumer can mirror the query as it is built
|
|
593
|
+
* (a live preview, a draft, analytics) without waiting for submit.
|
|
594
|
+
*
|
|
595
|
+
* Fires once per response that was applied, including the initial request
|
|
596
|
+
* on mount (an empty result) and after a response that promoted typed text
|
|
597
|
+
* into a completed param. Does not fire for a request that failed, was
|
|
598
|
+
* aborted, or was superseded by a newer one before it returned. Nothing
|
|
599
|
+
* fires for a keystroke that hasn't been sent yet — read `getResult()` for
|
|
600
|
+
* the current value on demand.
|
|
601
|
+
*/
|
|
602
|
+
onResult?: (result: AutocompleteResult) => void;
|
|
565
603
|
onError?: (error: Error) => void;
|
|
566
604
|
onChange?: (text: string) => void;
|
|
567
605
|
onParamsChange?: (params: CompletedParamState[]) => void;
|
|
@@ -591,6 +629,7 @@ interface CoreOptions {
|
|
|
591
629
|
|
|
592
630
|
type AIAutocompleteEvents = {
|
|
593
631
|
submit: [result: AutocompleteResult];
|
|
632
|
+
result: [result: AutocompleteResult];
|
|
594
633
|
error: [error: Error];
|
|
595
634
|
change: [text: string];
|
|
596
635
|
paramsChange: [params: CompletedParamState[]];
|
|
@@ -599,7 +638,7 @@ type AIAutocompleteEvents = {
|
|
|
599
638
|
blur: [];
|
|
600
639
|
productSelect: [product: Product];
|
|
601
640
|
};
|
|
602
|
-
type CoreUpdateOptions = Partial<Omit<CoreOptions, "onSubmit" | "onError" | "onChange" | "onParamsChange" | "onStateChange" | "onFocus" | "onBlur" | "onProductSelect" | "styleRoot">>;
|
|
641
|
+
type CoreUpdateOptions = Partial<Omit<CoreOptions, "onSubmit" | "onResult" | "onError" | "onChange" | "onParamsChange" | "onStateChange" | "onFocus" | "onBlur" | "onProductSelect" | "styleRoot">>;
|
|
603
642
|
declare class AIAutocomplete {
|
|
604
643
|
private inputStore;
|
|
605
644
|
private store;
|
|
@@ -782,6 +821,14 @@ declare class AIAutocomplete {
|
|
|
782
821
|
*/
|
|
783
822
|
subscribe(listener: (state: CoreState) => void): () => void;
|
|
784
823
|
getState(): CoreState;
|
|
824
|
+
/**
|
|
825
|
+
* The structured query as the SDK understands it right now — the same
|
|
826
|
+
* object `onResult` delivers after each response and `onSubmit` delivers
|
|
827
|
+
* on submit. Read it on demand from a place that has no event handy (a
|
|
828
|
+
* custom submit button, a "save draft" action).
|
|
829
|
+
*/
|
|
830
|
+
getResult(): AutocompleteResult;
|
|
831
|
+
private buildResult;
|
|
785
832
|
get listboxId(): string;
|
|
786
833
|
get isReady(): boolean;
|
|
787
834
|
/**
|
|
@@ -1289,6 +1336,16 @@ declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean
|
|
|
1289
1336
|
hint: string;
|
|
1290
1337
|
};
|
|
1291
1338
|
|
|
1339
|
+
/**
|
|
1340
|
+
* Projects client-side identified-param state onto its wire shape.
|
|
1341
|
+
*
|
|
1342
|
+
* The one place the `{ type, value }` form is spelled out. Both the request
|
|
1343
|
+
* body (`api.ts`) and the `AutocompleteResult` handed to `onResult` /
|
|
1344
|
+
* `onSubmit` go through it, so the params the consumer receives are exactly
|
|
1345
|
+
* the ones the server was told about.
|
|
1346
|
+
*/
|
|
1347
|
+
declare function toWireIdentifiedParams(params: IdentifiedParamState[]): IdentifiedParam[];
|
|
1348
|
+
|
|
1292
1349
|
declare class ModeController {
|
|
1293
1350
|
private container;
|
|
1294
1351
|
private mode;
|
|
@@ -1342,14 +1399,25 @@ declare const SKIPPED_PARAM_TEXT = "skipped";
|
|
|
1342
1399
|
declare function withSkippedParams(completed: CompletedParam[], skipped: SkippedParamState[]): CompletedParam[];
|
|
1343
1400
|
|
|
1344
1401
|
/**
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
|
|
1402
|
+
* Fields of an {@link AutocompleteResult} that come from the latest server
|
|
1403
|
+
* response rather than from the input. Both default to "nothing yet".
|
|
1404
|
+
*/
|
|
1405
|
+
interface SubmitResultExtras {
|
|
1406
|
+
/** Server-identified params (`state.identifiedParams`). Default: none. */
|
|
1407
|
+
identifiedParams?: IdentifiedParamState[];
|
|
1408
|
+
/** Server's "query is complete" verdict (`state.isReady`). Default: false. */
|
|
1409
|
+
isReady?: boolean;
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Builds the `AutocompleteResult` handed to `onSubmit` and `onResult`: the
|
|
1413
|
+
* placeholder-tokenized raw query plus the completed params, with skipped
|
|
1414
|
+
* suggestions folded in (see {@link withSkippedParams}), the server-identified
|
|
1415
|
+
* params in their wire shape, and the server's readiness verdict.
|
|
1348
1416
|
*
|
|
1349
1417
|
* Shared by every submit path — vanilla Enter / submit button, the React Tier 1
|
|
1350
|
-
* component, the Angular Tier 1 component —
|
|
1351
|
-
* result contains.
|
|
1418
|
+
* component, the Angular Tier 1 component — and by the core's per-response
|
|
1419
|
+
* `result` event, so none of them can drift on what a result contains.
|
|
1352
1420
|
*/
|
|
1353
|
-
declare function buildSubmitResult(text: string, completedParams: CompletedParamState[], skippedParams?: SkippedParamState[]): AutocompleteResult;
|
|
1421
|
+
declare function buildSubmitResult(text: string, completedParams: CompletedParamState[], skippedParams?: SkippedParamState[], extras?: SubmitResultExtras): AutocompleteResult;
|
|
1354
1422
|
|
|
1355
|
-
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 DateMonthView, type FormatType, type IdentifiedParam, type IdentifiedParamState, type InputItem, type LooseDateOptions, 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, type OptionOverrides, type OptionsGridLayout, type OptionsGridPlan, PLACEHOLDER_FADE_OUT_MS, PLACEHOLDER_LEAVING_ATTR, PLACEHOLDER_SWAP_GAP_MS, PLACEHOLDER_TYPE_MS, PLACEHOLDER_WORD_PAUSE_MS, type Product, type ProductsConfig, type RecentlySuggested, type RenderMode, SCROLL_ARROW_ATTR, SCROLL_ARROW_BOTTOM_VAR, SCROLL_ARROW_CLASS, SCROLL_ARROW_LABEL, SCROLL_ARROW_VISIBLE_ATTR, SKIPPED_PARAM_TEXT, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type Suggestion, type SuggestionOption, type TaskKind, WEEKDAY_LABELS, addMonths, attachScrollArrow, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, computeOptionsGridLayout, createStore, cursorIsAtEnd, extractPlainText, formatDate, getCursorOffset, getFooterHint, identifiedParamLabel, isOptionsGridMobileViewport, isoDate, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionEnterDelayMs, optionsEntranceDurationMs, optionsGridTemplateColumns, parseDate, parseLooseDate, plainTextLength, planOptionsGrid, previousGraphemeBoundary, renderEditableContent, resolveFormatType, resolveIdentifiedDate, scrollCaretIntoView, selectedIsoFromText, setCursorOffset, withSkippedParams };
|
|
1423
|
+
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 DateMonthView, type FormatType, type IdentifiedParam, type IdentifiedParamState, type InputItem, type LooseDateOptions, 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, type OptionOverrides, type OptionsGridLayout, type OptionsGridPlan, PLACEHOLDER_FADE_OUT_MS, PLACEHOLDER_LEAVING_ATTR, PLACEHOLDER_SWAP_GAP_MS, PLACEHOLDER_TYPE_MS, PLACEHOLDER_WORD_PAUSE_MS, type Product, type ProductsConfig, type RecentlySuggested, type RenderMode, SCROLL_ARROW_ATTR, SCROLL_ARROW_BOTTOM_VAR, SCROLL_ARROW_CLASS, SCROLL_ARROW_LABEL, SCROLL_ARROW_VISIBLE_ATTR, SKIPPED_PARAM_TEXT, type ScrollArrowArgs, type ScrollArrowController, type Segment, type SkippedParamState, type Store, type SubmitResultExtras, type Suggestion, type SuggestionOption, type TaskKind, WEEKDAY_LABELS, addMonths, attachScrollArrow, buildAttributionUrl, buildDateOptions, buildQuery, buildSubmitResult, cellDay, cellIso, computeOptionsGridLayout, createStore, cursorIsAtEnd, extractPlainText, formatDate, getCursorOffset, getFooterHint, identifiedParamLabel, isOptionsGridMobileViewport, isoDate, measureOptionsGrid, monthLabel, needsOptionsGridMeasurement, optionEnterDelayMs, optionsEntranceDurationMs, optionsGridTemplateColumns, parseDate, parseLooseDate, plainTextLength, planOptionsGrid, previousGraphemeBoundary, renderEditableContent, resolveFormatType, resolveIdentifiedDate, scrollCaretIntoView, selectedIsoFromText, setCursorOffset, toWireIdentifiedParams, withSkippedParams };
|