@magicx-eng/ai-autocomplete-angular 0.63.1 → 0.64.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.
@@ -1,4 +1,4 @@
1
- import { WEEKDAY_LABELS as WEEKDAY_LABELS$1, cellIso as cellIso$1, monthLabel as monthLabel$1, cellDay as cellDay$1, isoDate as isoDate$1, isDimmedDay, dateCellMarks as dateCellMarks$1, visibleDateRange as visibleDateRange$1, SMART_SUGGESTION_SPARKLE_SVG, isSmartSuggestion, isTraditionalAutocompleteSuggestion, uiStringsFor, productInitial, productImageSources as productImageSources$1, productPhotoFill, attachProductRowWheel, optionsGridTemplateColumns, highlightParts, optionLabel as optionLabel$1, optionImageSources as optionImageSources$1, formatOptionCount as formatOptionCount$1, sanitizeOptionIconSvg as sanitizeOptionIconSvg$1, isMultiSelectToggleTap, planOptionsGrid, optionsShowLeadingVisuals as optionsShowLeadingVisuals$1, sameOptionRows, isOptionsGridMobileViewport, pointerMayHighlight, syncHighlightScroll, needsOptionsGridMeasurement, releasePanelHug, measureOptionsGrid, optionEnterDelayMs, TIME_WHEEL_COLUMNS, formatTime as formatTime$1, timeWheelRows, timeWheelIndex, TIME_WHEEL_ROW_HEIGHT, withTimeWheelIndex, timeWheelIndexFromScroll, buildAttributionUrl, containScroll, findMultiSelectDone, fitMultiSelectDone, syncPanelHug, queryLive, attachScrollArrow, destroyPanelMorph, settlePanelMorph, attachViewportFit, hasSkippablePill, isCalendarFormat, labelTraditionalAutocomplete, getFooterHint, dateFloorFor, AIAutocomplete, withoutTraditionalAutocomplete, dateSelectionFor, editingSuggestion, identifiedParamLabel, dropdownPillsFor, attachChipRemove, renderEditableContent, startingHintOptions, cancelStartingHint, chipIdFromTap, keepCaretOnChip, getCursorOffset, extractPlainText, plainTextLength, setCursorOffset, HANDOFF_NOT_HANDLED, ModeController, watchEditorHeight, buildSubmitResult as buildSubmitResult$1, withSkippedParams as withSkippedParams$1, formatDate as formatDate$1, parseDate as parseDate$1, parseLooseDate as parseLooseDate$1, DATE_RANGE_META_END as DATE_RANGE_META_END$1, DATE_RANGE_META_START as DATE_RANGE_META_START$1, formatDateRange as formatDateRange$1, parseLooseDateRange as parseLooseDateRange$1, selectedRangeFor as selectedRangeFor$1, parseTime as parseTime$1, TIME_META_KEY as TIME_META_KEY$1, formatPlace as formatPlace$1, LOCATION_META_KEY as LOCATION_META_KEY$1, DEFAULT_OPTION_COUNT_UNIT as DEFAULT_OPTION_COUNT_UNIT$1, optionCountLabel as optionCountLabel$1, optionHasImage as optionHasImage$1, optionImageSrc as optionImageSrc$1, PRODUCT_PATH_PREFIX as PRODUCT_PATH_PREFIX$1, productFromMatchedItem as productFromMatchedItem$1, productsFromCustomFields as productsFromCustomFields$1 } from '@magicx-eng/ai-autocomplete-vanilla';
1
+ import { WEEKDAY_LABELS as WEEKDAY_LABELS$1, cellIso as cellIso$1, monthLabel as monthLabel$1, cellDay as cellDay$1, isoDate as isoDate$1, isDimmedDay, dateCellMarks as dateCellMarks$1, visibleDateRange as visibleDateRange$1, SMART_SUGGESTION_SPARKLE_SVG, isSmartSuggestion, isTraditionalAutocompleteSuggestion, uiStringsFor, productInitial, productImageSources as productImageSources$1, productPhotoFill, attachProductRowWheel, optionsGridTemplateColumns, highlightParts, optionLabel as optionLabel$1, optionImageSources as optionImageSources$1, formatOptionCount as formatOptionCount$1, sanitizeOptionIconSvg as sanitizeOptionIconSvg$1, isMultiSelectToggleTap, planOptionsGrid, optionsShowLeadingVisuals as optionsShowLeadingVisuals$1, sameOptionRows, isOptionsGridMobileViewport, pointerMayHighlight, syncHighlightScroll, needsOptionsGridMeasurement, releasePanelHug, measureOptionsGrid, optionEnterDelayMs, TIME_WHEEL_COLUMNS, formatTime as formatTime$1, timeWheelRows, timeWheelIndex, TIME_WHEEL_ROW_HEIGHT, withTimeWheelIndex, timeWheelIndexFromScroll, buildAttributionUrl, containScroll, findMultiSelectDone, fitMultiSelectDone, syncPanelHug, queryLive, attachScrollArrow, destroyPanelMorph, settlePanelMorph, attachViewportFit, hasSkippablePill, isCalendarFormat, labelTraditionalAutocomplete, getFooterHint, dateFloorFor, AIAutocomplete, withoutTraditionalAutocomplete, dateSelectionFor, editingSuggestion, identifiedParamLabel, dropdownPillsFor, attachChipRemove, renderEditableContent, startingHintOptions, cancelStartingHint, chipIdFromTap, keepCaretOnChip, getCursorOffset, extractPlainText, plainTextLength, settlePickFocus, setCursorOffset, HANDOFF_NOT_HANDLED, ModeController, watchEditorHeight, focusEditorFromTap, buildSubmitResult as buildSubmitResult$1, withSkippedParams as withSkippedParams$1, formatDate as formatDate$1, parseDate as parseDate$1, parseLooseDate as parseLooseDate$1, DATE_RANGE_META_END as DATE_RANGE_META_END$1, DATE_RANGE_META_START as DATE_RANGE_META_START$1, formatDateRange as formatDateRange$1, parseLooseDateRange as parseLooseDateRange$1, selectedRangeFor as selectedRangeFor$1, parseTime as parseTime$1, TIME_META_KEY as TIME_META_KEY$1, formatPlace as formatPlace$1, LOCATION_META_KEY as LOCATION_META_KEY$1, DEFAULT_OPTION_COUNT_UNIT as DEFAULT_OPTION_COUNT_UNIT$1, optionCountLabel as optionCountLabel$1, optionHasImage as optionHasImage$1, optionImageSrc as optionImageSrc$1, PRODUCT_PATH_PREFIX as PRODUCT_PATH_PREFIX$1, productFromMatchedItem as productFromMatchedItem$1, productsFromCustomFields as productsFromCustomFields$1 } from '@magicx-eng/ai-autocomplete-vanilla';
2
2
  import * as i1 from '@angular/common';
3
3
  import { CommonModule, isPlatformBrowser } from '@angular/common';
4
4
  import * as i0 from '@angular/core';
@@ -2355,6 +2355,20 @@ class AIAutocompleteController {
2355
2355
  return;
2356
2356
  this.core.prepareSubmit();
2357
2357
  }
2358
+ /**
2359
+ * The result to submit from your own button, with `custom_fields` that
2360
+ * answer it: prepares the submit as `prepareSubmit()` does, then waits for
2361
+ * the answer to the query when the stored one is for another, for up to
2362
+ * `submitAnswerTimeoutMs`, with `isSubmitting$` true meanwhile. Resolves
2363
+ * without a `custom_fields` key when no answer came, and to null when there
2364
+ * is nothing to submit (the input changed while it waited, or a submit is
2365
+ * already in progress).
2366
+ */
2367
+ awaitSubmitResult() {
2368
+ if (this.isDestroyed)
2369
+ return Promise.resolve(null);
2370
+ return this.core.awaitSubmitResult();
2371
+ }
2358
2372
  /**
2359
2373
  * Records a submit in telemetry. Enter is recorded by the SDK; call this
2360
2374
  * from a submit button you render, so each submit is counted once.
@@ -2513,6 +2527,13 @@ class AIAutocompleteController {
2513
2527
  return;
2514
2528
  this.core.handleKeyDown(event);
2515
2529
  }
2530
+ /**
2531
+ * Whether a pick puts focus in the field (`focusInputOnSelect`): by default
2532
+ * yes where the pointer hovers, no on a touch device.
2533
+ */
2534
+ focusesInputOnSelect() {
2535
+ return this.isDestroyed ? false : this.core.focusesInputOnSelect();
2536
+ }
2516
2537
  /** Notify the core of focus state. */
2517
2538
  setFocused(focused) {
2518
2539
  if (this.isDestroyed)
@@ -3084,13 +3105,13 @@ class AIAutocompleteEditorHostDirective {
3084
3105
  this.lastState = state;
3085
3106
  this.renderEditor(state);
3086
3107
  // Post-promote refocus + caret-after-bold placement (mirrors React's
3087
- // useLayoutEffect on newParamId).
3108
+ // useLayoutEffect on newParamId). Where a pick leaves the editor
3109
+ // unfocused (a touch device by default), see `settlePickFocus`.
3088
3110
  const currentParamId = state.newParamId ?? "";
3089
3111
  if (currentParamId && currentParamId !== this.lastSeenParamId) {
3090
3112
  this.lastSeenParamId = currentParamId;
3091
- el.focus();
3092
3113
  const desired = state.caretOffset ?? plainTextLength(el);
3093
- setCursorOffset(el, desired);
3114
+ settlePickFocus(el, desired, this.controller.focusesInputOnSelect());
3094
3115
  }
3095
3116
  else if (!currentParamId) {
3096
3117
  this.lastSeenParamId = "";
@@ -3267,6 +3288,18 @@ class AIAutocompleteComponent {
3267
3288
  * all of it off: nothing is marked, and every press emits.
3268
3289
  */
3269
3290
  this.submitProgress = true;
3291
+ /**
3292
+ * When true, a submit (Enter, the submit button) whose `custom_fields` do
3293
+ * not answer the submitted query first gets the full answer for it, then
3294
+ * emits `submitted` with that answer's `custom_fields`. The submit shows as
3295
+ * in progress while it waits, a second submit is ignored, and typing,
3296
+ * tapping or pressing elsewhere cancels it without emitting. After
3297
+ * `submitAnswerTimeoutMs`, or when the request fails, `submitted` emits
3298
+ * once with no `custom_fields` key: treat a missing block as "no filters
3299
+ * known". Default: false, where `submitted` emits at once and a block that
3300
+ * does not answer the query is marked `custom_fields_stale: true`.
3301
+ */
3302
+ this.awaitAnswerOnSubmit = false;
3270
3303
  /**
3271
3304
  * When true (default), the editor is cleared and a new session starts after
3272
3305
  * `submitted` emits — on Enter and on the submit button. Set to false to
@@ -3332,12 +3365,16 @@ class AIAutocompleteComponent {
3332
3365
  dropdownTrigger: this.dropdownTrigger,
3333
3366
  optionsPosition: this.optionsPosition,
3334
3367
  closeDropdownOnBlur: this.closeDropdownOnBlur,
3368
+ focusInputOnSelect: this.focusInputOnSelect,
3369
+ startingState: this.startingState,
3335
3370
  prependPlaceholder: this.prependPlaceholder,
3336
3371
  showNonTappableOptions: this.showNonTappableOptions,
3337
3372
  allOption: this.allOption,
3338
3373
  locationSearch: this.locationSearch,
3339
3374
  showProducts: this.showProducts,
3340
3375
  submitProgress: this.submitProgress,
3376
+ awaitAnswerOnSubmit: this.awaitAnswerOnSubmit,
3377
+ submitAnswerTimeoutMs: this.submitAnswerTimeoutMs,
3341
3378
  source: "full-sdk",
3342
3379
  products: this.products,
3343
3380
  mapProducts: this.mapProducts,
@@ -3433,12 +3470,16 @@ class AIAutocompleteComponent {
3433
3470
  changes["dropdownTrigger"] ||
3434
3471
  changes["optionsPosition"] ||
3435
3472
  changes["closeDropdownOnBlur"] ||
3473
+ changes["focusInputOnSelect"] ||
3474
+ changes["startingState"] ||
3436
3475
  changes["prependPlaceholder"] ||
3437
3476
  changes["showNonTappableOptions"] ||
3438
3477
  changes["allOption"] ||
3439
3478
  changes["locationSearch"] ||
3440
3479
  changes["showProducts"] ||
3441
3480
  changes["submitProgress"] ||
3481
+ changes["awaitAnswerOnSubmit"] ||
3482
+ changes["submitAnswerTimeoutMs"] ||
3442
3483
  changes["products"] ||
3443
3484
  changes["mapProducts"]) {
3444
3485
  this.controller.update({
@@ -3453,12 +3494,16 @@ class AIAutocompleteComponent {
3453
3494
  dropdownTrigger: this.dropdownTrigger,
3454
3495
  optionsPosition: this.optionsPosition,
3455
3496
  closeDropdownOnBlur: this.closeDropdownOnBlur,
3497
+ focusInputOnSelect: this.focusInputOnSelect,
3498
+ startingState: this.startingState,
3456
3499
  prependPlaceholder: this.prependPlaceholder,
3457
3500
  showNonTappableOptions: this.showNonTappableOptions,
3458
3501
  allOption: this.allOption,
3459
3502
  locationSearch: this.locationSearch,
3460
3503
  showProducts: this.showProducts,
3461
3504
  submitProgress: this.submitProgress,
3505
+ awaitAnswerOnSubmit: this.awaitAnswerOnSubmit,
3506
+ submitAnswerTimeoutMs: this.submitAnswerTimeoutMs,
3462
3507
  // Same reference on an unrelated change is a no-op in the core; only a
3463
3508
  // genuinely swapped (or removed) integration clears the strip.
3464
3509
  products: this.products,
@@ -3582,7 +3627,9 @@ class AIAutocompleteComponent {
3582
3627
  // during the tap; the click that ends the tap must not take it back.
3583
3628
  if (document.activeElement?.closest("[data-aia-location]"))
3584
3629
  return;
3585
- this.focus();
3630
+ const editor = this.editorRef?.nativeElement;
3631
+ if (editor)
3632
+ focusEditorFromTap(editor);
3586
3633
  }
3587
3634
  onSubmitButtonClick(event) {
3588
3635
  event.stopPropagation();
@@ -3627,9 +3674,12 @@ class AIAutocompleteComponent {
3627
3674
  * the React component uses — so the emitted query reflects whatever's in
3628
3675
  * the DOM right now, not a possibly-stale state snapshot.
3629
3676
  */
3677
+ // `answered` is the core's own result for the submit: its catalog report
3678
+ // answers the query, or is left out or marked, where the report in state is
3679
+ // the last response's and may be an earlier query's.
3630
3680
  // `fromButton`: the SDK records an Enter submit itself before it calls back
3631
3681
  // here; a click on our own button never passes through it.
3632
- handleSubmit(_result, fromButton = false) {
3682
+ handleSubmit(answered, fromButton = false) {
3633
3683
  const editor = this.editorRef?.nativeElement;
3634
3684
  if (!editor)
3635
3685
  return;
@@ -3639,7 +3689,8 @@ class AIAutocompleteComponent {
3639
3689
  const result = buildSubmitResult$1(text, params, state.skippedParams, {
3640
3690
  identifiedParams: state.identifiedParams,
3641
3691
  isReady: state.isReady,
3642
- customFields: state.customFields,
3692
+ customFields: answered.custom_fields ?? null,
3693
+ customFieldsStale: answered.custom_fields_stale === true,
3643
3694
  });
3644
3695
  if (fromButton)
3645
3696
  this.controller.recordSubmit(result);
@@ -3661,15 +3712,19 @@ class AIAutocompleteComponent {
3661
3712
  // (The core ignores a second Enter itself.)
3662
3713
  if (state.isSubmitting)
3663
3714
  return;
3715
+ if (this.awaitAnswerOnSubmit) {
3716
+ // The core calls back for Enter once the answer to the submit arrived;
3717
+ // the button waits for it here. Null: the shopper changed the input
3718
+ // while it waited.
3719
+ void this.controller.awaitSubmitResult().then((answered) => {
3720
+ if (answered)
3721
+ this.handleSubmit(answered, true);
3722
+ });
3723
+ return;
3724
+ }
3664
3725
  this.controller.prepareSubmit();
3665
3726
  // Use the same handler for button clicks and Enter.
3666
- this.handleSubmit({
3667
- query: state.text.trim(),
3668
- raw_query: "",
3669
- completed_params: [],
3670
- identified_params: [],
3671
- is_ready: state.isReady,
3672
- }, true);
3727
+ this.handleSubmit(this.controller.getResult(), true);
3673
3728
  }
3674
3729
  measurePillWrap() {
3675
3730
  const container = this.pillContainerRef?.nativeElement;
@@ -3696,7 +3751,7 @@ class AIAutocompleteComponent {
3696
3751
  }
3697
3752
  }
3698
3753
  AIAutocompleteComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AIAutocompleteComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
3699
- AIAutocompleteComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: AIAutocompleteComponent, isStandalone: true, selector: "ai-autocomplete", inputs: { apiConfig: "apiConfig", additionalContext: "additionalContext", language: "language", currency: "currency", productId: "productId", visitorId: "visitorId", analyticsConsent: "analyticsConsent", optionOverrides: "optionOverrides", maskCompletedText: "maskCompletedText", columns: "columns", pillPlacement: "pillPlacement", mode: "mode", optionsPosition: "optionsPosition", animations: "animations", optionsStyle: "optionsStyle", dropdownTrigger: "dropdownTrigger", closeDropdownOnBlur: "closeDropdownOnBlur", prependPlaceholder: "prependPlaceholder", showNonTappableOptions: "showNonTappableOptions", allOption: "allOption", locationSearch: "locationSearch", showSkipButton: "showSkipButton", showOptionIcons: "showOptionIcons", showOptionImages: "showOptionImages", showOptionCounts: "showOptionCounts", productsLayout: "productsLayout", productImageFallback: "productImageFallback", showProductVendor: "showProductVendor", showChipIcons: "showChipIcons", showChipImages: "showChipImages", showChipRemove: "showChipRemove", autoFocus: "autoFocus", value: "value", completedParams: "completedParams", showProducts: "showProducts", submitProgress: "submitProgress", products: "products", mapProducts: "mapProducts", onProductAddToCart: "onProductAddToCart", submitButton: "submitButton", resetOnSubmit: "resetOnSubmit" }, outputs: { submitted: "submitted", resultChange: "resultChange", errored: "errored", valueChange: "valueChange", completedParamsChange: "completedParamsChange", focused: "focused", blurred: "blurred", productSelect: "productSelect" }, providers: [
3754
+ AIAutocompleteComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: AIAutocompleteComponent, isStandalone: true, selector: "ai-autocomplete", inputs: { apiConfig: "apiConfig", additionalContext: "additionalContext", language: "language", currency: "currency", productId: "productId", visitorId: "visitorId", analyticsConsent: "analyticsConsent", optionOverrides: "optionOverrides", maskCompletedText: "maskCompletedText", columns: "columns", pillPlacement: "pillPlacement", mode: "mode", optionsPosition: "optionsPosition", animations: "animations", optionsStyle: "optionsStyle", dropdownTrigger: "dropdownTrigger", closeDropdownOnBlur: "closeDropdownOnBlur", focusInputOnSelect: "focusInputOnSelect", startingState: "startingState", prependPlaceholder: "prependPlaceholder", showNonTappableOptions: "showNonTappableOptions", allOption: "allOption", locationSearch: "locationSearch", showSkipButton: "showSkipButton", showOptionIcons: "showOptionIcons", showOptionImages: "showOptionImages", showOptionCounts: "showOptionCounts", productsLayout: "productsLayout", productImageFallback: "productImageFallback", showProductVendor: "showProductVendor", showChipIcons: "showChipIcons", showChipImages: "showChipImages", showChipRemove: "showChipRemove", autoFocus: "autoFocus", value: "value", completedParams: "completedParams", showProducts: "showProducts", submitProgress: "submitProgress", awaitAnswerOnSubmit: "awaitAnswerOnSubmit", submitAnswerTimeoutMs: "submitAnswerTimeoutMs", products: "products", mapProducts: "mapProducts", onProductAddToCart: "onProductAddToCart", submitButton: "submitButton", resetOnSubmit: "resetOnSubmit" }, outputs: { submitted: "submitted", resultChange: "resultChange", errored: "errored", valueChange: "valueChange", completedParamsChange: "completedParamsChange", focused: "focused", blurred: "blurred", productSelect: "productSelect" }, providers: [
3700
3755
  {
3701
3756
  provide: NG_VALUE_ACCESSOR,
3702
3757
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -3754,6 +3809,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
3754
3809
  type: Input
3755
3810
  }], closeDropdownOnBlur: [{
3756
3811
  type: Input
3812
+ }], focusInputOnSelect: [{
3813
+ type: Input
3814
+ }], startingState: [{
3815
+ type: Input
3757
3816
  }], prependPlaceholder: [{
3758
3817
  type: Input
3759
3818
  }], showNonTappableOptions: [{
@@ -3792,6 +3851,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
3792
3851
  type: Input
3793
3852
  }], submitProgress: [{
3794
3853
  type: Input
3854
+ }], awaitAnswerOnSubmit: [{
3855
+ type: Input
3856
+ }], submitAnswerTimeoutMs: [{
3857
+ type: Input
3795
3858
  }], products: [{
3796
3859
  type: Input
3797
3860
  }], mapProducts: [{
@@ -3944,12 +4007,18 @@ class AIAutocompleteInputDirective {
3944
4007
  this.lastSeenParamId = current;
3945
4008
  const offset = this.controller.getState().caretOffset ?? el.value.length;
3946
4009
  const clamped = Math.min(Math.max(offset, 0), el.value.length);
4010
+ const focused = typeof document !== "undefined" && document.activeElement === el;
4011
+ // Where a pick does not focus the field (a touch device by default,
4012
+ // `focusInputOnSelect`), the keyboard stays away: no focus, and no
4013
+ // caret either (`setSelectionRange` focuses the field in Safari). The
4014
+ // next tap on the field places the caret.
4015
+ if (!focused && !this.controller.focusesInputOnSelect())
4016
+ return;
3947
4017
  // Only grab focus if we don't already have it — don't yank focus back
3948
4018
  // from wherever the user moved it after selecting (e.g. a host-app
3949
4019
  // button). setSelectionRange still positions the caret regardless.
3950
- if (typeof document !== "undefined" && document.activeElement !== el) {
4020
+ if (!focused && typeof document !== "undefined")
3951
4021
  el.focus();
3952
- }
3953
4022
  try {
3954
4023
  el.setSelectionRange(clamped, clamped);
3955
4024
  }