@depict-ai/ui 4.10.19 → 4.10.21

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.
@@ -10,7 +10,7 @@ import $b8hua$babelruntimehelpersclassPrivateFieldGet from "@babel/runtime/helpe
10
10
  /*! Depict.ai search and product listing SDK */
11
11
  import { register_es_version } from "../../multi_import_deduplicator.mjs";
12
12
  register_es_version("ui", "ES10");
13
- const $8db9a15135765c11$export$83d89fbfd8236492 = "4.10.19";
13
+ const $8db9a15135765c11$export$83d89fbfd8236492 = "4.10.21";
14
14
  function $00a5b94f0c11efbb$export$d9f36cf74e24d595(media_query) {
15
15
  const signal = $b8hua$createSignal(false);
16
16
  $b8hua$onCleanup($b8hua$javascript_media_query(media_query, _ref => {
@@ -2113,6 +2113,63 @@ function $4711a82d08d2021b$export$fecbb157621501bd(_ref) {
2113
2113
  }));
2114
2114
  return outmost_element;
2115
2115
  }
2116
+
2117
+ /**
2118
+ * `HTMLElement.focus()` is a **silent no-op** on an element that is not being rendered
2119
+ * (`display: none`, `visibility: hidden`, a collapsed menu). Nothing throws, focus simply
2120
+ * stays where it was, so a caller that does not check believes it restored focus when it
2121
+ * left it on `<body>` — which puts the keyboard user back at the top of the document.
2122
+ *
2123
+ * That is reachable whenever the element which opened a modal stops being rendered while the
2124
+ * modal is open, and the common way for that to happen is the responsive-duplicate header:
2125
+ * a theme renders the same search trigger twice, once for desktop and once for mobile, and
2126
+ * hides one at the current breakpoint. Open the modal from the desktop trigger, cross the
2127
+ * breakpoint (rotate a tablet, resize a window), close the modal, and the remembered trigger
2128
+ * is still `isConnected` but no longer rendered. Verified against a live merchant storefront
2129
+ * on 4.10.19.
2130
+ *
2131
+ * So: verify that focus landed, and when it did not, look for a rendered twin of the same
2132
+ * control — the other half of the responsive pair — and use that instead.
2133
+ */ /**
2134
+ * An element can only take focus if it is actually being rendered.
2135
+ *
2136
+ * Injectable because it is the one part of this module that needs a layout engine: jsdom
2137
+ * reports no client rects for anything, so the specs pass their own predicate to exercise the
2138
+ * matching rules. The real predicate is only exercised in a browser.
2139
+ */
2140
+ const $1c5106dfe72d554c$export$e0652711c614c755 = element => !!element.getClientRects().length;
2141
+ /**
2142
+ * `document.activeElement` is the outermost shadow host when focus is inside a shadow tree,
2143
+ * so ask the element's own root rather than the document — matching how the rest of
2144
+ * modal_opener treats shadow-mounted modals.
2145
+ */
2146
+ const $1c5106dfe72d554c$var$has_focus = element => element.getRootNode().activeElement === element;
2147
+ /**
2148
+ * The accessible-name-ish identity we match twins on. Deliberately narrow: an explicit label
2149
+ * or the trimmed text. Two controls that share a tag and this string are the same control
2150
+ * rendered twice, which is exactly the responsive-duplicate case.
2151
+ */
2152
+ const $1c5106dfe72d554c$var$identity_of = element => (element.getAttribute("aria-label") || element.getAttribute("title") || element.textContent || "").trim().replace(/\s+/g, " ");
2153
+ function $1c5106dfe72d554c$export$5800d9d535a06e96(element) {
2154
+ let rendered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $1c5106dfe72d554c$export$e0652711c614c755;
2155
+ const identity = $1c5106dfe72d554c$var$identity_of(element);
2156
+ if (!identity) return; // nothing to match on — an icon-only button with no label
2157
+ const twins = [...element.ownerDocument.querySelectorAll(element.localName)].filter(candidate => candidate !== element && rendered(candidate) && $1c5106dfe72d554c$var$identity_of(candidate) === identity);
2158
+ return twins.length === 1 ? twins[0] : undefined;
2159
+ }
2160
+ function $1c5106dfe72d554c$export$51461d633c351649(element) {
2161
+ let rendered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $1c5106dfe72d554c$export$e0652711c614c755;
2162
+ element.focus({
2163
+ preventScroll: true
2164
+ });
2165
+ if ($1c5106dfe72d554c$var$has_focus(element)) return true;
2166
+ const twin = $1c5106dfe72d554c$export$5800d9d535a06e96(element, rendered);
2167
+ if (!twin) return false;
2168
+ twin.focus({
2169
+ preventScroll: true
2170
+ });
2171
+ return $1c5106dfe72d554c$var$has_focus(twin);
2172
+ }
2116
2173
  async function $d5f1e6a0f9117286$export$79b1565500412d9b(search_modal, modal_fn_opts, parent) {
2117
2174
  const body = parent || document.body || (await (0, $b8hua$observer).wait_for_element("body"));
2118
2175
  let dispose_and_remove;
@@ -2144,8 +2201,10 @@ async function $d5f1e6a0f9117286$export$79b1565500412d9b(search_modal, modal_fn_
2144
2201
  const modal_els = $b8hua$createRoot(dispose => {
2145
2202
  let closing_animation;
2146
2203
  let animation_started;
2204
+ let focus_target_after_close;
2147
2205
  dispose_and_remove = () => {
2148
2206
  const actually_close = () => {
2207
+ var _focus_target_after_c;
2149
2208
  dispose();
2150
2209
  on_dispose === null || on_dispose === void 0 || on_dispose();
2151
2210
  const {
@@ -2164,13 +2223,24 @@ async function $d5f1e6a0f9117286$export$79b1565500412d9b(search_modal, modal_fn_
2164
2223
  }
2165
2224
  el.remove();
2166
2225
  });
2167
- if (should_restore_focus && element_focused_before_open !== null && element_focused_before_open !== void 0 && element_focused_before_open.isConnected) {
2226
+ const requested_focus_target = (_focus_target_after_c = focus_target_after_close) === null || _focus_target_after_c === void 0 ? void 0 : _focus_target_after_c();
2227
+ if (should_restore_focus && (requested_focus_target !== null && requested_focus_target !== void 0 && requested_focus_target.isConnected || element_focused_before_open !== null && element_focused_before_open !== void 0 && element_focused_before_open.isConnected)) {
2168
2228
  restoring_focus = true;
2169
2229
  try {
2170
2230
  // preventScroll so this can't re-introduce the safari page-jump the blur() above works around
2171
- element_focused_before_open.focus({
2172
- preventScroll: true
2173
- });
2231
+ let focused = false;
2232
+ if (requested_focus_target !== null && requested_focus_target !== void 0 && requested_focus_target.isConnected) {
2233
+ requested_focus_target.focus({
2234
+ preventScroll: true
2235
+ });
2236
+ focused = requested_focus_target.getRootNode().activeElement === requested_focus_target;
2237
+ }
2238
+ if (!focused && element_focused_before_open !== null && element_focused_before_open !== void 0 && element_focused_before_open.isConnected)
2239
+ // restore_focus_to rather than a bare focus(): the remembered trigger can be
2240
+ // connected but no longer rendered (a responsive-duplicate header whose other
2241
+ // half is showing now), and focus() on an unrendered element silently does
2242
+ // nothing, leaving the keyboard user at the top of the page.
2243
+ $1c5106dfe72d554c$export$51461d633c351649(element_focused_before_open);
2174
2244
  } finally {
2175
2245
  // Cleared on a task instead of synchronously in case a browser delivers the focus event async
2176
2246
  setTimeout(() => restoring_focus = false, 0);
@@ -2190,7 +2260,8 @@ async function $d5f1e6a0f9117286$export$79b1565500412d9b(search_modal, modal_fn_
2190
2260
  ...extra_options_for_modal,
2191
2261
  close_modal_: close_modal_,
2192
2262
  open_modal_: open_modal_,
2193
- register_closing_animation_: animation => closing_animation = animation
2263
+ register_closing_animation_: animation => closing_animation = animation,
2264
+ set_focus_target_after_close_: get_target => focus_target_after_close = get_target
2194
2265
  });
2195
2266
  });
2196
2267
  body.append(...modal_els);
@@ -7928,20 +7999,28 @@ function $ac571292d606f30b$var$_classPrivateMethodGet(receiver, privateSet, fn)
7928
7999
  }
7929
8000
  var $ac571292d606f30b$var$_throwing_on_navigation = /*#__PURE__*/new WeakSet();
7930
8001
  var $ac571292d606f30b$var$_get_navigation_happened_promise = /*#__PURE__*/new WeakSet();
8002
+ var $ac571292d606f30b$var$_watch_for_navigation_to_same_href = /*#__PURE__*/new WeakSet();
7931
8003
  class $ac571292d606f30b$export$7e1297a3a19f10d8 {
7932
8004
  /**
7933
8005
  * Function that will be called when we want to navigate, or a string saying it's not an SPA. You can change this OTG
7934
8006
  */ /**
7935
8007
  * We store listing_id in history.state and do operate on this both here and in js-ui, this is the key to be used which js-ui provides
7936
8008
  */ /**
7937
- * Vue has async router that needs to be awaited (it navigates after a microtask)
7938
- * This standardises waiting for all kinds of routers
7939
- */
8009
+ * Called when a go_to_ didn't change location.href, for example when following a link to the page one is already on. href_change_ipns stays silent then, so whoever waits for a href change to react to a navigation has to listen here too
8010
+ */ /**
8011
+ * Vue has async router that needs to be awaited (it navigates after a microtask)
8012
+ * This standardises waiting for all kinds of routers
8013
+ */ /**
8014
+ * Calls navigation_to_same_href_listeners_ if the navigation we're about to request ends on the href we're already on
8015
+ * @returns function to stop watching, call it when the navigation failed
8016
+ */
7940
8017
  constructor(on_navigation, listing_query_state_key) {
8018
+ $ac571292d606f30b$var$_classPrivateMethodInitSpec(this, $ac571292d606f30b$var$_watch_for_navigation_to_same_href);
7941
8019
  $ac571292d606f30b$var$_classPrivateMethodInitSpec(this, $ac571292d606f30b$var$_get_navigation_happened_promise);
7942
8020
  $ac571292d606f30b$var$_classPrivateMethodInitSpec(this, $ac571292d606f30b$var$_throwing_on_navigation);
7943
8021
  $b8hua$babelruntimehelpersdefineProperty(this, "on_navigation_", void 0);
7944
8022
  $b8hua$babelruntimehelpersdefineProperty(this, "listing_query_state_key", void 0);
8023
+ $b8hua$babelruntimehelpersdefineProperty(this, "navigation_to_same_href_listeners_", new Set());
7945
8024
  $b8hua$babelruntimehelpersdefineProperty(this, "navigate_", {
7946
8025
  /**
7947
8026
  * Call this if you *just* want to replace the state object in history.state
@@ -7983,6 +8062,7 @@ class $ac571292d606f30b$export$7e1297a3a19f10d8 {
7983
8062
  }
7984
8063
  event_ === null || event_ === void 0 || event_.preventDefault();
7985
8064
  const promise = $ac571292d606f30b$var$_classPrivateMethodGet(this, $ac571292d606f30b$var$_get_navigation_happened_promise, $ac571292d606f30b$var$_get_navigation_happened_promise2).call(this, true);
8065
+ const stop_watching_for_same_href = $ac571292d606f30b$var$_classPrivateMethodGet(this, $ac571292d606f30b$var$_watch_for_navigation_to_same_href, $ac571292d606f30b$var$_watch_for_navigation_to_same_href2).call(this, new_url_);
7986
8066
  if (force_spa_navigation_ && wants_hard_navigation) {
7987
8067
  // Don't allow hard navigation if we're forcing SPA navigation, which we do for things where PageReplacer can be used for performance
7988
8068
  const new_state = history.state;
@@ -7996,7 +8076,7 @@ class $ac571292d606f30b$export$7e1297a3a19f10d8 {
7996
8076
  is_replace: is_replace_,
7997
8077
  new_url: new_url_ instanceof URL ? new_url_ : new URL(new_url_, location.href),
7998
8078
  scroll: scroll
7999
- });
8079
+ }, stop_watching_for_same_href);
8000
8080
  await promise;
8001
8081
  })
8002
8082
  });
@@ -8004,15 +8084,16 @@ class $ac571292d606f30b$export$7e1297a3a19f10d8 {
8004
8084
  this.on_navigation_ = on_navigation;
8005
8085
  }
8006
8086
  }
8007
- function $ac571292d606f30b$var$_throwing_on_navigation2() {
8087
+ function $ac571292d606f30b$var$_throwing_on_navigation2(options, on_throw_) {
8008
8088
  const {
8009
8089
  on_navigation_: on_navigation_
8010
8090
  } = this;
8011
8091
  if (typeof on_navigation_ !== "function") throw new Error("on_navigation_ is not a function");
8012
8092
  // make sure that we don't accidentally catchify if the SDK consumer has fucked up
8013
8093
  try {
8014
- return on_navigation_(...arguments);
8094
+ return on_navigation_(options);
8015
8095
  } catch (e) {
8096
+ on_throw_ === null || on_throw_ === void 0 || on_throw_();
8016
8097
  queueMicrotask(() => {
8017
8098
  throw e;
8018
8099
  });
@@ -8029,6 +8110,24 @@ function $ac571292d606f30b$var$_get_navigation_happened_promise2(is_replace) {
8029
8110
  (0, $b8hua$instant_exec_on_suspect_history_change).add(handler);
8030
8111
  });
8031
8112
  }
8113
+ function $ac571292d606f30b$var$_watch_for_navigation_to_same_href2(target_url) {
8114
+ const href_before = location.href;
8115
+ const stop_watching = () => {
8116
+ (0, $b8hua$instant_exec_on_suspect_history_change).delete(on_history_change);
8117
+ clearTimeout(timeout);
8118
+ };
8119
+ const notify_if_href_unchanged = $b8hua$catchify1(() => {
8120
+ stop_watching();
8121
+ if (location.href !== href_before) return;
8122
+ this.navigation_to_same_href_listeners_.forEach(listener => $b8hua$catchify1(listener)());
8123
+ });
8124
+ // The router has acted once it touches history, if the href is still the same then it took us to the page we're on
8125
+ const on_history_change = () => notify_if_href_unchanged();
8126
+ // A router asked to go to the exact href we're on might not touch history at all, so don't wait longer than 500ms for it. For any other target we can't tell a slow navigation from one that goes nowhere, so only stop listening after a while
8127
+ const timeout = target_url.href === href_before ? setTimeout(notify_if_href_unchanged, 500) : setTimeout(stop_watching, 10000);
8128
+ (0, $b8hua$instant_exec_on_suspect_history_change).add(on_history_change);
8129
+ return stop_watching;
8130
+ }
8032
8131
  var $e3efeb558d952696$var$_tmpl$ = ["<button", ' class="show-more major" type="button">', "</button>"],
8033
8132
  $e3efeb558d952696$var$_tmpl$2 = ["<h2", ' class="recs-title">', "</h2>"],
8034
8133
  $e3efeb558d952696$var$_tmpl$3 = ["<div", ' class="recommendation-grid"><!--$-->', "<!--/--><!--$-->", "<!--/--></div>"];
@@ -9278,6 +9377,7 @@ function $83c36ed4520d0335$export$f7658c347b037c3f() {
9278
9377
  var $584c06c09cf4609d$var$_tmpl$ = ["<div", ' style="', '" class="spacer"></div>'],
9279
9378
  $584c06c09cf4609d$var$_tmpl$2 = ['<div class="field"><!--$-->', "<!--/-->", "<!--$-->", "<!--/--></div>"],
9280
9379
  $584c06c09cf4609d$var$_tmpl$3 = ["<button", ' class="submit major" type="button"', ">", "</button>"];
9380
+ const $584c06c09cf4609d$var$keys_not_opening_modal = new Set(["Tab", "Shift", "Control", "Alt", "AltGraph", "Meta", "CapsLock", "Escape", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "PageUp", "PageDown", "Home", "End", "Insert", "ContextMenu", "NumLock", "ScrollLock", "Pause", "PrintScreen"]);
9281
9381
  function $584c06c09cf4609d$export$b94867ecbd698f21(_ref) {
9282
9382
  let {
9283
9383
  search_field_value_: [searchFieldValue, setSearchFieldValue],
@@ -9400,11 +9500,17 @@ var $fac58b5610eec6a9$var$_tmpl$ = ["<svg", ' xmlns="http://www.w3.org/2000/svg"
9400
9500
  function $fac58b5610eec6a9$export$8d8893ffd8aca39a() {
9401
9501
  return $b8hua$ssr($fac58b5610eec6a9$var$_tmpl$, $b8hua$ssrHydrationKey());
9402
9502
  }
9403
- function $a82a41ab7188eda2$export$93d9bfd0c9c1a5b8(close_modal, search_query_url_param_name_) {
9503
+ function $a82a41ab7188eda2$export$93d9bfd0c9c1a5b8(close_modal, search_query_url_param_name_, router_) {
9404
9504
  const [exit_iterable, exitable_iterable] = $b8hua$make_asyncIterable_exiter((0, $b8hua$href_change_ipns));
9505
+ const {
9506
+ navigation_to_same_href_listeners_: navigation_to_same_href_listeners_
9507
+ } = router_;
9405
9508
  let set_initial_values = false;
9406
9509
  let old_pathname;
9407
9510
  let old_param_value;
9511
+ // A card linking to the page one is already on doesn't change the href, close the modal anyway so the click does something
9512
+ navigation_to_same_href_listeners_.add(close_modal);
9513
+ $b8hua$onCleanup(() => navigation_to_same_href_listeners_.delete(close_modal));
9408
9514
  $b8hua$onCleanup($b8hua$catchify1(exit_iterable));
9409
9515
  $b8hua$catchify1(async () => {
9410
9516
  for await (const href of exitable_iterable) {
@@ -9423,6 +9529,33 @@ function $a82a41ab7188eda2$export$93d9bfd0c9c1a5b8(close_modal, search_query_url
9423
9529
  }
9424
9530
  })();
9425
9531
  }
9532
+ function $802b1d7ed155c277$export$9e9e2ae069cf2fe1(_ref) {
9533
+ let {
9534
+ props_search_field_value_: props_search_field_value_,
9535
+ props_submit_query_: props_submit_query_,
9536
+ dont_sync_search_field_value_except_on_submit_: dont_sync_search_field_value_except_on_submit_,
9537
+ set_focus_target_after_close_: set_focus_target_after_close_,
9538
+ get_search_page_input_element_: get_search_page_input_element_
9539
+ } = _ref;
9540
+ const search_field_value_ = dont_sync_search_field_value_except_on_submit_ ? $b8hua$createSignal("") : props_search_field_value_;
9541
+ let submits_in_flight = 0;
9542
+ const submit_query_ = async function () {
9543
+ let new_query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : $b8hua$untrack(search_field_value_[0]);
9544
+ submits_in_flight++;
9545
+ try {
9546
+ return await props_submit_query_(new_query, () => set_focus_target_after_close_(get_search_page_input_element_));
9547
+ } finally {
9548
+ submits_in_flight--;
9549
+ }
9550
+ };
9551
+ if (dont_sync_search_field_value_except_on_submit_) $b8hua$createEffect($b8hua$on(search_field_value_[0], value => submits_in_flight > 0 && props_search_field_value_[1](value), {
9552
+ defer: true
9553
+ }));
9554
+ return {
9555
+ search_field_value_: search_field_value_,
9556
+ submit_query_: submit_query_
9557
+ };
9558
+ }
9426
9559
  var $40411f2ec772c376$var$_tmpl$ = ["<div", ' class="discover-more"><button class="major" type="button">', "</button></div>"],
9427
9560
  $40411f2ec772c376$var$_tmpl$2 = ["<b", ">", "</b>"],
9428
9561
  $40411f2ec772c376$var$_tmpl$3 = ["<div", ' class="', '"><div class="', '" role="search" aria-label="Search modal with search field, query suggestions and result preview"><!--$-->', '<!--/--><div id="depict-suggestions-and-result-preview" class="padded"><!--$-->', "<!--/--><!--$-->", "<!--/--><!--$-->", "<!--/--></div><!--$-->", "<!--/--></div><!--$-->", "<!--/--></div>"],
@@ -9437,6 +9570,8 @@ function $40411f2ec772c376$var$RawClassicSearchModal(_ref) {
9437
9570
  search_query_url_param_name_: search_query_url_param_name_,
9438
9571
  previous_searches_: previous_searches_,
9439
9572
  close_modal_: close_modal_,
9573
+ set_focus_target_after_close_: set_focus_target_after_close_,
9574
+ get_search_page_input_element_: get_search_page_input_element_,
9440
9575
  depict_api_: depict_api_,
9441
9576
  merchant_: merchant_,
9442
9577
  market_: market_,
@@ -9461,15 +9596,16 @@ function $40411f2ec772c376$var$RawClassicSearchModal(_ref) {
9461
9596
  // As per feedback from stronger we sometimes want a modal with the search field value disconnected from the one in the rest of the UI, see https://depictaiworkspace.slack.com/archives/C02J16R9XEH/p1679065878487709.
9462
9597
  // This is desired for when the modal is opened from a UI element that visually does not look connected with the search page or current query
9463
9598
  // Basically the UI signals that the button that opens the modal starts a new search.
9464
- const search_field_value_ = dont_sync_search_field_value_except_on_submit_ ? $b8hua$createSignal("") : props_search_field_value;
9465
- const propagate_search_field_value_back = dont_sync_search_field_value_except_on_submit_ ? () => props_search_field_value[1]($b8hua$untrack(search_field_value_[0])) // Set actual search field value to the throwaway internal one before submitting
9466
- : undefined;
9467
- const submit_query_ = function () {
9468
- // submit_query expects to read the current search field value which is why we have to write the current one to the signal before calling it
9469
- // It will write the old one back and then write the new one after submit
9470
- propagate_search_field_value_back === null || propagate_search_field_value_back === void 0 || propagate_search_field_value_back();
9471
- return props_submit_query(...arguments);
9472
- };
9599
+ const {
9600
+ search_field_value_: search_field_value_,
9601
+ submit_query_: submit_query_
9602
+ } = $802b1d7ed155c277$export$9e9e2ae069cf2fe1({
9603
+ props_search_field_value_: props_search_field_value,
9604
+ props_submit_query_: props_submit_query,
9605
+ dont_sync_search_field_value_except_on_submit_: dont_sync_search_field_value_except_on_submit_,
9606
+ set_focus_target_after_close_: set_focus_target_after_close_,
9607
+ get_search_page_input_element_: get_search_page_input_element_
9608
+ });
9473
9609
  const [input_field, set_input_field] = $b8hua$createSignal();
9474
9610
  const [get_search_field_value_] = search_field_value_;
9475
9611
  // Search field alignment unused in ClassicSearchModal since the search field spans the whole modal
@@ -9524,7 +9660,7 @@ function $40411f2ec772c376$var$RawClassicSearchModal(_ref) {
9524
9660
  }
9525
9661
  })));
9526
9662
  if (disable_scrolling_) $e56d241d0f33d459$export$fe334901e8bebd57();
9527
- $a82a41ab7188eda2$export$93d9bfd0c9c1a5b8(close_modal_, search_query_url_param_name_);
9663
+ $a82a41ab7188eda2$export$93d9bfd0c9c1a5b8(close_modal_, search_query_url_param_name_, router_);
9528
9664
  window.addEventListener("keydown", close_on_escape_handler);
9529
9665
  $b8hua$onCleanup($b8hua$catchify1(() => window.removeEventListener("keydown", close_on_escape_handler)));
9530
9666
  if (closing_animation_) register_closing_animation_(closing_animation_);
@@ -10102,6 +10238,8 @@ function $06fcd2a345efd24d$var$RawSearchModalV2(_ref) {
10102
10238
  search_query_url_param_name_: search_query_url_param_name_,
10103
10239
  previous_searches_: previous_searches_,
10104
10240
  close_modal_: close_modal_,
10241
+ set_focus_target_after_close_: set_focus_target_after_close_,
10242
+ get_search_page_input_element_: get_search_page_input_element_,
10105
10243
  alignmentSignals_: alignmentSignals_,
10106
10244
  depict_api_: depict_api_,
10107
10245
  merchant_: merchant_,
@@ -10132,15 +10270,16 @@ function $06fcd2a345efd24d$var$RawSearchModalV2(_ref) {
10132
10270
  // As per feedback from stronger we sometimes want a modal with the search field value disconnected from the one in the rest of the UI, see https://depictaiworkspace.slack.com/archives/C02J16R9XEH/p1679065878487709.
10133
10271
  // This is desired for when the modal is opened from a UI element that visually does not look connected with the search page or current query
10134
10272
  // Basically the UI signals that the button that opens the modal starts a new search.
10135
- const search_field_value_ = dont_sync_search_field_value_except_on_submit_ ? $b8hua$createSignal("") : props_search_field_value;
10136
- const propagate_search_field_value_back = dont_sync_search_field_value_except_on_submit_ ? () => props_search_field_value[1]($b8hua$untrack(search_field_value_[0])) // Set actual search field value to the throwaway internal one before submitting
10137
- : undefined;
10138
- const submit_query_ = function () {
10139
- // submit_query expects to read the current search field value which is why we have to write the current one to the signal before calling it
10140
- // It will write the old one back and then write the new one after submit
10141
- propagate_search_field_value_back === null || propagate_search_field_value_back === void 0 || propagate_search_field_value_back();
10142
- return props_submit_query(...arguments);
10143
- };
10273
+ const {
10274
+ search_field_value_: search_field_value_,
10275
+ submit_query_: submit_query_
10276
+ } = $802b1d7ed155c277$export$9e9e2ae069cf2fe1({
10277
+ props_search_field_value_: props_search_field_value,
10278
+ props_submit_query_: props_submit_query,
10279
+ dont_sync_search_field_value_except_on_submit_: dont_sync_search_field_value_except_on_submit_,
10280
+ set_focus_target_after_close_: set_focus_target_after_close_,
10281
+ get_search_page_input_element_: get_search_page_input_element_
10282
+ });
10144
10283
  const [input_field, set_input_field] = $b8hua$createSignal();
10145
10284
  const [searching_for_value_, set_searching_for_value_] = $b8hua$createSignal();
10146
10285
  const [show_stale_content_results_, set_show_stale_content_results_] = $b8hua$createSignal(false);
@@ -10254,7 +10393,7 @@ function $06fcd2a345efd24d$var$RawSearchModalV2(_ref) {
10254
10393
  return (((_get_modal_search_res5 = get_modal_search_results_()) === null || _get_modal_search_res5 === void 0 ? void 0 : _get_modal_search_res5.loading) === false && !suggestions_response_.loading || !!prev) && totalNumberResults() === 0 && previous_searches_matching_query().length === 0;
10255
10394
  });
10256
10395
  if (disable_scrolling_) $e56d241d0f33d459$export$fe334901e8bebd57();
10257
- $a82a41ab7188eda2$export$93d9bfd0c9c1a5b8(close_modal_, search_query_url_param_name_);
10396
+ $a82a41ab7188eda2$export$93d9bfd0c9c1a5b8(close_modal_, search_query_url_param_name_, router_);
10258
10397
  addEventListener("keydown", close_on_escape_handler);
10259
10398
  $b8hua$onCleanup(() => removeEventListener("keydown", close_on_escape_handler));
10260
10399
  $b8hua$createEffect($b8hua$on(get_search_field_value_, () => {
@@ -12149,11 +12288,12 @@ async function $86b0ff0c85e5fc6c$export$e16630ecb9644a1c(_ref) {
12149
12288
  let {
12150
12289
  on_submit_with_unchanged_value_: on_submit_with_unchanged_value_,
12151
12290
  search_param_name_: search_param_name_,
12152
- set_search_field_value_: set_search_field_value_,
12291
+ search_field_value_: search_field_value_,
12153
12292
  get_search_query_: get_search_query_,
12154
12293
  url_transformer_: url_transformer_,
12155
12294
  router_: router_,
12156
12295
  after_submit_: after_submit_,
12296
+ before_navigate_: before_navigate_,
12157
12297
  get_new_query: get_new_query
12158
12298
  } = _ref;
12159
12299
  const new_search_query = get_new_query();
@@ -12161,21 +12301,92 @@ async function $86b0ff0c85e5fc6c$export$e16630ecb9644a1c(_ref) {
12161
12301
  if (previous_query === new_search_query && new URLSearchParams(location.search).has(search_param_name_)) {
12162
12302
  // don't push a history entry / re-search if someone submits a search again
12163
12303
  // do close the modal though
12304
+ search_field_value_.settle_(new_search_query);
12164
12305
  on_submit_with_unchanged_value_ === null || on_submit_with_unchanged_value_ === void 0 || on_submit_with_unchanged_value_();
12165
- return;
12306
+ return false;
12166
12307
  }
12167
- set_search_field_value_(previous_query); // restore the value to the previous query since this one goes to the new history entry
12168
12308
  const target_url = new URL(location.href);
12169
12309
  url_transformer_ === null || url_transformer_ === void 0 || url_transformer_(target_url);
12170
12310
  target_url.searchParams.set(search_param_name_, new_search_query);
12171
- await router_.navigate_.go_to_({
12172
- new_url_: target_url,
12173
- is_replace_: false,
12174
- force_spa_navigation_: true
12175
- });
12176
- set_search_field_value_(new_search_query);
12311
+ const end_submit = search_field_value_.begin_submit_(new_search_query, previous_query);
12312
+ before_navigate_ === null || before_navigate_ === void 0 || before_navigate_();
12313
+ let landed;
12314
+ try {
12315
+ await router_.navigate_.go_to_({
12316
+ new_url_: target_url,
12317
+ is_replace_: false,
12318
+ force_spa_navigation_: true
12319
+ });
12320
+ } finally {
12321
+ landed = end_submit();
12322
+ }
12323
+ if (!landed) return false;
12177
12324
  scrollTo(0, 0);
12178
12325
  after_submit_ === null || after_submit_ === void 0 || after_submit_();
12326
+ return true;
12327
+ }
12328
+ function $8a9827cc2842b300$export$d13a185c53aa5edf(persisted_, get_search_query_) {
12329
+ const [get_persisted, set_persisted] = persisted_;
12330
+ const [get_submitting, set_submitting] = $b8hua$createSignal();
12331
+ const get_value = $b8hua$createMemo(() => {
12332
+ var _get_submitting;
12333
+ return (_get_submitting = get_submitting()) !== null && _get_submitting !== void 0 ? _get_submitting : get_persisted();
12334
+ });
12335
+ const set_value = value => {
12336
+ const new_value = typeof value === "function" ? value($b8hua$untrack(get_value)) : value;
12337
+ if ($b8hua$untrack(get_submitting) === undefined) set_persisted(new_value);else set_submitting(new_value);
12338
+ return new_value;
12339
+ };
12340
+ let current_submit;
12341
+ const end_submit = landed => {
12342
+ current_submit.landed_ = landed;
12343
+ current_submit = undefined;
12344
+ $b8hua$batch(() => {
12345
+ const submitting = $b8hua$untrack(get_submitting);
12346
+ set_submitting(undefined);
12347
+ if (landed && submitting !== undefined) set_persisted(submitting);
12348
+ });
12349
+ };
12350
+ const abort_on_popstate = what_happened => {
12351
+ if (what_happened === "popstate" && current_submit) end_submit(false);
12352
+ };
12353
+ (0, $b8hua$instant_exec_on_suspect_history_change).add(abort_on_popstate);
12354
+ $b8hua$onCleanup(() => (0, $b8hua$instant_exec_on_suspect_history_change).delete(abort_on_popstate));
12355
+ $b8hua$createEffect($b8hua$on(get_search_query_, query => {
12356
+ const token = current_submit;
12357
+ if (!token || query !== token.query_) return;
12358
+ queueMicrotask(() => {
12359
+ if (current_submit === token) end_submit(true);
12360
+ });
12361
+ }, {
12362
+ defer: true
12363
+ }));
12364
+ const begin_submit_ = (submitted_query, query_of_current_history_entry) => {
12365
+ const token = current_submit = {
12366
+ query_: submitted_query,
12367
+ landed_: false
12368
+ };
12369
+ $b8hua$batch(() => {
12370
+ set_submitting(submitted_query);
12371
+ set_persisted(query_of_current_history_entry);
12372
+ });
12373
+ return () => {
12374
+ if (current_submit === token) end_submit(true);
12375
+ return token.landed_;
12376
+ };
12377
+ };
12378
+ const settle_ = query => {
12379
+ if (current_submit) return;
12380
+ $b8hua$batch(() => {
12381
+ set_submitting(undefined);
12382
+ set_persisted(query);
12383
+ });
12384
+ };
12385
+ return {
12386
+ value_: [get_value, set_value],
12387
+ begin_submit_: begin_submit_,
12388
+ settle_: settle_
12389
+ };
12179
12390
  }
12180
12391
  function $96d57a48e7bce64f$export$181cceed5c91919e(callback, alsoRaF, passiveListener) {
12181
12392
  let aligned_this_microtask = false;
@@ -12849,6 +13060,7 @@ function $da279c5a540c6846$export$a54ec244c8863715(_ref) {
12849
13060
  scroll_restoration_data_: scroll_restoration_data_,
12850
13061
  product_card_template_: product_card_template_,
12851
13062
  modalAlignmentSignalsRef_: modalAlignmentSignalsRef_,
13063
+ inputFieldRef_: inputFieldRef_,
12852
13064
  router_: router_,
12853
13065
  content_results_rows_: content_results_rows_,
12854
13066
  content_layout_options_: content_layout_options_,
@@ -13044,6 +13256,8 @@ function $da279c5a540c6846$export$a54ec244c8863715(_ref) {
13044
13256
  if (!search_field) break add_input_field;
13045
13257
  setModalBodyStyle({});
13046
13258
  modalAlignmentSignalsRef_ === null || modalAlignmentSignalsRef_ === void 0 || modalAlignmentSignalsRef_(alignmentSignals_);
13259
+ inputFieldRef_ === null || inputFieldRef_ === void 0 || inputFieldRef_(input_element);
13260
+ $b8hua$onCleanup(() => inputFieldRef_ === null || inputFieldRef_ === void 0 ? void 0 : inputFieldRef_(undefined));
13047
13261
  const [pollAlignment, setPollAlignment_] = $b8hua$createSignal(false);
13048
13262
  const align_position = $b8hua$catchify1((0, $1308a7816c3d4f2d$export$b3ad617e9036868))(alignmentSignals_, search_field, (0, $1308a7816c3d4f2d$export$3f238c96c45e6cc6) | (0, $1308a7816c3d4f2d$export$7895aadd1956b1c7) | (modalVersionUsed_ === 1 ? (0, $1308a7816c3d4f2d$export$902f8b4a7dae5d78) : (0, $1308a7816c3d4f2d$export$6060bc6bee850eb6) | (0, $1308a7816c3d4f2d$export$5097308c5200105a)), true, pollAlignment);
13049
13263
  div_with_field_class.addEventListener("click", $b8hua$catchify1(e => {
@@ -13412,14 +13626,16 @@ class $eb064bc3350276c1$export$ac6237957a15b3f0 {
13412
13626
  set_search_content_results_rows((0, $d53ebed6f63304e4$export$70ceae36059a1036));
13413
13627
  }; // do this every time after we have submitted a new query - otherwise there might already be a saved number of rows in the state
13414
13628
  const on_submit_with_unchanged_value_ = () => this.modal_open = false;
13415
- const [get_search_field_value_, set_search_field_value_] = state_.field_value;
13416
- const configured_submit_query_ = new_query => $86b0ff0c85e5fc6c$export$e16630ecb9644a1c({
13629
+ const search_field_value_ = $8a9827cc2842b300$export$d13a185c53aa5edf(state_.field_value, get_search_query_);
13630
+ const [get_search_field_value_] = search_field_value_.value_;
13631
+ const configured_submit_query_ = (new_query, before_navigate_) => $86b0ff0c85e5fc6c$export$e16630ecb9644a1c({
13417
13632
  on_submit_with_unchanged_value_: on_submit_with_unchanged_value_,
13418
- set_search_field_value_: set_search_field_value_,
13633
+ search_field_value_: search_field_value_,
13419
13634
  get_search_query_: get_search_query_,
13420
13635
  search_param_name_: search_query_url_param_name_,
13421
13636
  after_submit_: after_submit_,
13422
- get_new_query: () => new_query || $b8hua$untrack(get_search_field_value_),
13637
+ before_navigate_: before_navigate_,
13638
+ get_new_query: () => new_query !== null && new_query !== void 0 ? new_query : $b8hua$untrack(get_search_field_value_),
13423
13639
  url_transformer_: url_transformer,
13424
13640
  router_: $b8hua$babelruntimehelpersclassPrivateFieldGet(this, $eb064bc3350276c1$var$_router)
13425
13641
  });
@@ -13438,6 +13654,7 @@ class $eb064bc3350276c1$export$ac6237957a15b3f0 {
13438
13654
  search_query_url_param_name_: search_query_url_param_name_,
13439
13655
  reset_history_state_: reset_history_state_,
13440
13656
  state_: state_,
13657
+ search_field_value_: search_field_value_.value_,
13441
13658
  router_: $b8hua$babelruntimehelpersclassPrivateFieldGet(this, $eb064bc3350276c1$var$_router),
13442
13659
  url_transformer_: url_transformer,
13443
13660
  depict_api_: depict_api_,
@@ -13461,7 +13678,11 @@ class $eb064bc3350276c1$export$ac6237957a15b3f0 {
13461
13678
  $b8hua$onCleanup(() => _this.modal_open = false);
13462
13679
  return searchModalComponent(...arguments);
13463
13680
  }, {
13464
- search_field_value_: state_.field_value,
13681
+ search_field_value_: search_field_value_.value_,
13682
+ get_search_page_input_element_: () => {
13683
+ var _privately_shared_pro2;
13684
+ return (_privately_shared_pro2 = $eb064bc3350276c1$export$dde08b2dca8cc1ce.get(this)) === null || _privately_shared_pro2 === void 0 ? void 0 : _privately_shared_pro2.search_page_input_element_;
13685
+ },
13465
13686
  get_search_query_: get_search_query_,
13466
13687
  search_query_url_param_name_: search_query_url_param_name_,
13467
13688
  previous_searches_: previous_searches,
@@ -13626,6 +13847,7 @@ function $eb064bc3350276c1$export$f2dc7e4e4aa11abb(props) {
13626
13847
  const {
13627
13848
  state_: state_
13628
13849
  } = shared_properties;
13850
+ let registered_input_element;
13629
13851
  const grid_spacing_override = $b8hua$createMemo(() => {
13630
13852
  const {
13631
13853
  grid_spacing: grid_spacing
@@ -13657,7 +13879,7 @@ function $eb064bc3350276c1$export$f2dc7e4e4aa11abb(props) {
13657
13879
  var _depict_search$enable;
13658
13880
  return (_depict_search$enable = depict_search.enable_content_search) !== null && _depict_search$enable !== void 0 ? _depict_search$enable : $eb064bc3350276c1$var$content_search_default;
13659
13881
  },
13660
- search_field_value_: state_.field_value,
13882
+ search_field_value_: shared_properties.search_field_value_,
13661
13883
  get_search_query_: shared_properties.get_search_query_,
13662
13884
  clear_filters_on_next_submit_: shared_properties.clear_filters_on_next_submit_,
13663
13885
  open_modal_: function () {
@@ -13668,6 +13890,16 @@ function $eb064bc3350276c1$export$f2dc7e4e4aa11abb(props) {
13668
13890
  modalVersionUsed_: shared_properties.modalVersionUsed_,
13669
13891
  showSliderArrow_: () => props.showSliderArrow_,
13670
13892
  i18n_: shared_properties.i18n_,
13893
+ inputFieldRef_: input_element => {
13894
+ const shared_info_right_now = $eb064bc3350276c1$export$dde08b2dca8cc1ce.get(depict_search);
13895
+ if (!shared_info_right_now) return;
13896
+ if (input_element === undefined && shared_info_right_now.search_page_input_element_ !== registered_input_element) return;
13897
+ registered_input_element = input_element;
13898
+ $eb064bc3350276c1$export$dde08b2dca8cc1ce.set(depict_search, {
13899
+ ...shared_info_right_now,
13900
+ search_page_input_element_: input_element
13901
+ });
13902
+ },
13671
13903
  modalAlignmentSignalsRef_: style => {
13672
13904
  const shared_info_right_now = $eb064bc3350276c1$export$dde08b2dca8cc1ce.get(depict_search);
13673
13905
  if (!shared_info_right_now) return;
@@ -14114,7 +14346,7 @@ function $a3026fb727bc7550$export$316f6f283ae64765(props) {
14114
14346
  return shared_properties.BackIcon_;
14115
14347
  },
14116
14348
  get search_field_value_() {
14117
- return shared_properties.state_.field_value;
14349
+ return shared_properties.search_field_value_;
14118
14350
  },
14119
14351
  get submit_query_() {
14120
14352
  return shared_properties.configured_submit_query_;
@@ -14157,7 +14389,7 @@ function $a3026fb727bc7550$export$316f6f283ae64765(props) {
14157
14389
  return shared_properties.BackIcon_;
14158
14390
  },
14159
14391
  get search_field_value_() {
14160
- return shared_properties.state_.field_value;
14392
+ return shared_properties.search_field_value_;
14161
14393
  },
14162
14394
  get submit_query_() {
14163
14395
  return shared_properties.configured_submit_query_;