@cartbot/vehicle-search-beta 3.0.13 → 3.0.14

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,11 +1,11 @@
1
1
  import { jsx as a, jsxs as $, Fragment as Se } from "react/jsx-runtime";
2
- import { useState as M, useEffect as P, useRef as O, useCallback as N, useMemo as pt } from "react";
2
+ import { useState as M, useEffect as V, useRef as O, useCallback as N, useMemo as pt } from "react";
3
3
  import vt from "react-dom";
4
4
  import ht from "js-cookie";
5
5
  import { Combobox as ut, ComboboxInput as mt, ComboboxButton as ft, ComboboxOptions as gt, ComboboxOption as bt } from "@headlessui/react";
6
6
  import wt from "fuzzysearch";
7
7
  import Ye from "pluralize";
8
- import te from "clsx";
8
+ import re from "clsx";
9
9
  import { MeiliSearch as yt } from "meilisearch";
10
10
  import xt from "lodash/debounce.js";
11
11
  import kt from "tinycolor2";
@@ -132,13 +132,13 @@ function W({
132
132
  }, J = (i) => {
133
133
  i.preventDefault(), i.stopPropagation(), u(""), k(null), D("");
134
134
  };
135
- P(() => {
135
+ V(() => {
136
136
  u(""), k(d || null);
137
137
  }, [d, v]);
138
- let re = /* @__PURE__ */ new Set(), g = [];
138
+ let ee = /* @__PURE__ */ new Set(), g = [];
139
139
  v && (v.forEach((i) => {
140
140
  String(i.value).split(/,(?![^(]*\))/).forEach((_) => {
141
- _ = _.trim(), _ && wt(G, _.toLowerCase()) && !re.has(_.toLowerCase()) && (re.add(_.toLowerCase()), g.push({
141
+ _ = _.trim(), _ && wt(G, _.toLowerCase()) && !ee.has(_.toLowerCase()) && (ee.add(_.toLowerCase()), g.push({
142
142
  ...i,
143
143
  value: _,
144
144
  refinement: i.value
@@ -280,7 +280,7 @@ function W({
280
280
  bt,
281
281
  {
282
282
  value: i,
283
- className: ({ focus: _ }) => te(
283
+ className: ({ focus: _ }) => re(
284
284
  "vs:group vs:relative vs:w-full vs:cursor-default vs:py-(--partbot-padding) vs:px-[calc(var(--partbot-padding)*1.3)] vs:text-left vs:border-none",
285
285
  _ ? "vs:bg-[rgb(var(--partbot-theme))] vs:text-[rgb(var(--partbot-button-label-color))]" : "vs:bg-white vs:text-stone-900 vs:hover:bg-theme vs:hover:text-button-label",
286
286
  B && "vs:font-bold!"
@@ -289,7 +289,7 @@ function W({
289
289
  /* @__PURE__ */ a(
290
290
  "span",
291
291
  {
292
- className: te(
292
+ className: re(
293
293
  i.value === (d == null ? void 0 : d.value) ? "vs:font-semibold" : "vs:font-normal",
294
294
  "vs:block vs:font-(family-name:--partbot-font-family) vs:whitespace-pre-wrap vs:text-left vs:text-(length:--partbot-font-size) vs:leading-none"
295
295
  ),
@@ -299,7 +299,7 @@ function W({
299
299
  i.value === (d == null ? void 0 : d.value) && /* @__PURE__ */ a(
300
300
  "span",
301
301
  {
302
- className: te(
302
+ className: re(
303
303
  "vs:text-[rgb(var(--partbot-theme))]",
304
304
  "vs:flex vs:items-center group-vs:hover:text-white"
305
305
  ),
@@ -364,7 +364,7 @@ function St({
364
364
  showButton: k = !0,
365
365
  onSubmit: H,
366
366
  store: J,
367
- useStoreVehicles: re = !0,
367
+ useStoreVehicles: ee = !0,
368
368
  fieldOrder: g = "MMY",
369
369
  // "MMY" (Make→Model→Year) or "YMM" (Year→Make→Model)
370
370
  enableFeatureFlags: L = !1,
@@ -383,19 +383,19 @@ function St({
383
383
  variant: null,
384
384
  engine: null,
385
385
  engine_capacity: null
386
- }), [Ke, Me] = M(!1), Ve = O([
386
+ }), [Ke, Me] = M(!1), Pe = O([
387
387
  "body",
388
388
  "series",
389
389
  "variant",
390
390
  "engine",
391
391
  "engine_capacity"
392
392
  ]), ke = O(
393
- F && F.length && Ve.current ? F.split(",").filter((t) => {
393
+ F && F.length && Pe.current ? F.split(",").filter((t) => {
394
394
  var r;
395
- return (r = Ve.current) == null ? void 0 : r.includes(t);
395
+ return (r = Pe.current) == null ? void 0 : r.includes(t);
396
396
  }) : null
397
397
  ), [K, We] = M(!1);
398
- P(() => {
398
+ V(() => {
399
399
  const t = navigator.userAgent;
400
400
  We(
401
401
  /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
@@ -409,7 +409,7 @@ function St({
409
409
  disable_session_recording: !1
410
410
  });
411
411
  }, []);
412
- const [ne, Je] = M({}), [Et, Xe] = M(""), Pe = N(async () => {
412
+ const [ne, Je] = M({}), [Et, Xe] = M(""), Ve = N(async () => {
413
413
  if (!y)
414
414
  return;
415
415
  const r = `${L ? "https://api.cartbot.io" : "https://api.partbot.io"}/v1/vehicles/auth`;
@@ -423,7 +423,7 @@ function St({
423
423
  },
424
424
  body: JSON.stringify(
425
425
  (() => {
426
- const p = { use_store_vehicles: re };
426
+ const p = { use_store_vehicles: ee };
427
427
  return J && (p.store = J), p;
428
428
  })()
429
429
  )
@@ -449,7 +449,7 @@ function St({
449
449
  _.current = o, oe.current = (l || []).map((p) => ({
450
450
  ...p,
451
451
  refinement: p.value
452
- })), X.current = Array.isArray(s) ? s.map((p) => p && p.value ? String(p.value).trim() : "").filter(Boolean) : [], T.current = Array.isArray(h) ? h.map((p) => String(p).trim().toUpperCase()) : null, console.log(
452
+ })), X.current = ee && Array.isArray(s) ? s.map((p) => p && p.value ? String(p.value).trim() : "").filter(Boolean) : [], T.current = Array.isArray(h) ? h.map((p) => String(p).trim().toUpperCase()) : null, console.log(
453
453
  "[VehicleSearch] PostHog popular makes:",
454
454
  T.current
455
455
  ), E.current = z || null, console.log(
@@ -463,10 +463,10 @@ function St({
463
463
  } catch (n) {
464
464
  console.error("[VehicleSearch] Auth failed:", n), Xe(n);
465
465
  }
466
- }, [y, J, re, L]);
467
- P(() => {
468
- Pe();
469
- }, [Pe]), P(() => {
466
+ }, [y, J, ee, L]);
467
+ V(() => {
468
+ Ve();
469
+ }, [Ve]), V(() => {
470
470
  if (ne.searchKey) {
471
471
  try {
472
472
  q.current = new yt({
@@ -499,7 +499,7 @@ function St({
499
499
  const l = kt(o).isDark();
500
500
  Ge(l);
501
501
  }, []);
502
- P(() => {
502
+ V(() => {
503
503
  async function t() {
504
504
  if (!e.make || !b.current)
505
505
  return;
@@ -544,7 +544,7 @@ function St({
544
544
  [...t.entries()].filter(([o]) => r.includes(o)).map(([o, l]) => [et(o), { value: l, refinement: l }])
545
545
  );
546
546
  Q(n);
547
- }, []), V = N(({ query: t, value: r, remove: n }) => {
547
+ }, []), P = N(({ query: t, value: r, remove: n }) => {
548
548
  if (G && "URLSearchParams" in window) {
549
549
  let o = new URLSearchParams(window.location.search);
550
550
  t = $e(t), t && r && o.set(t, r), t && !r && o.delete(t), n && n.forEach((s) => {
@@ -580,7 +580,7 @@ function St({
580
580
  const h = JSON.stringify({
581
581
  description: `${((o = e.make) == null ? void 0 : o.value) || ""} ${((l = e.model) == null ? void 0 : l.value) || ""} ${((s = e.year) == null ? void 0 : s.value) || ""} ${((c = e.body) == null ? void 0 : c.value) || ""} ${((f = e.series) == null ? void 0 : f.value) || ""} ${((S = e.variant) == null ? void 0 : S.value) || ""} ${((de = e.engine) == null ? void 0 : de.value) || ""} ${((ie = e.engine_capacity) == null ? void 0 : ie.value) || ""}`.trim(),
582
582
  vehicle_ids: ae,
583
- vehicle: e ? Object.entries(e).reduce((z, [p, ee]) => (z[p] = ee != null && ee.value ? ee.value : {}, z), {}) : {}
583
+ vehicle: e ? Object.entries(e).reduce((z, [p, te]) => (z[p] = te != null && te.value ? te.value : {}, z), {}) : {}
584
584
  });
585
585
  localStorage.setItem(
586
586
  "partbot_selected_vehicle",
@@ -596,13 +596,13 @@ function St({
596
596
  () => xt(Le, 100),
597
597
  [Le]
598
598
  );
599
- P(() => {
599
+ V(() => {
600
600
  Ce();
601
- }, [ae, Ce]), P(() => () => {
601
+ }, [ae, Ce]), V(() => () => {
602
602
  Ce.cancel();
603
- }, [Ce]), P(() => {
603
+ }, [Ce]), V(() => {
604
604
  ne.searchKey && (m || lt(), tt());
605
- }, [ne.searchKey, m]), P(() => {
605
+ }, [ne.searchKey, m]), V(() => {
606
606
  m && b.current && ce.length === 0 && !e.year && (console.log(
607
607
  "[VehicleSearch] YMM mode: Loading year range from dataset..."
608
608
  ), b.current.search("", {
@@ -633,7 +633,7 @@ function St({
633
633
  }).catch((t) => {
634
634
  console.error("[VehicleSearch] Error loading year range:", t);
635
635
  }));
636
- }, [m, ne.searchKey, ce.length, e.year]), P(() => {
636
+ }, [m, ne.searchKey, ce.length, e.year]), V(() => {
637
637
  typeof document > "u" || Ie();
638
638
  }, [Ie]);
639
639
  const Be = N(
@@ -641,7 +641,7 @@ function St({
641
641
  A.current = !0, ve([]), !m && !w && he([]), ge([]), be([]), we([]), xe([]), ye([]), Q((r) => ({
642
642
  make: t,
643
643
  year: m || w ? r.year : null
644
- })), V({
644
+ })), P({
645
645
  query: "make",
646
646
  value: (t == null ? void 0 : t.value) ?? "",
647
647
  remove: m ? ["model", "body", "series", "engine", "variant", "engine_capacity"] : w ? [
@@ -662,7 +662,7 @@ function St({
662
662
  ]
663
663
  }), t || ze([]);
664
664
  },
665
- [V, m, w]
665
+ [P, m, w]
666
666
  ), De = N(
667
667
  (t) => {
668
668
  A.current = !0, Q((r) => ({
@@ -675,7 +675,7 @@ function St({
675
675
  variant: null,
676
676
  engine: null,
677
677
  engine_capacity: null
678
- })), !m && !w && he([]), ge([]), be([]), we([]), xe([]), ye([]), V({
678
+ })), !m && !w && he([]), ge([]), be([]), we([]), xe([]), ye([]), P({
679
679
  query: "model",
680
680
  value: (t == null ? void 0 : t.value) ?? "",
681
681
  remove: m ? ["body", "series", "engine", "variant", "engine_capacity"] : w ? ["body", "series", "engine", "variant", "engine_capacity"] : [
@@ -688,7 +688,7 @@ function St({
688
688
  ]
689
689
  });
690
690
  },
691
- [V, m, w]
691
+ [P, m, w]
692
692
  ), Fe = N(
693
693
  (t) => {
694
694
  A.current = !0, m ? (pe([]), ve([]), Q({
@@ -704,7 +704,7 @@ function St({
704
704
  variant: null,
705
705
  engine: null,
706
706
  engine_capacity: null
707
- })), w || (ge([]), be([]), we([]), xe([]), ye([])), V({
707
+ })), w || (ge([]), be([]), we([]), xe([]), ye([])), P({
708
708
  query: "year",
709
709
  value: (t == null ? void 0 : t.value) ?? "",
710
710
  remove: m ? [
@@ -718,64 +718,64 @@ function St({
718
718
  ] : w ? [] : ["body", "series", "variant", "engine", "engine_capacity"]
719
719
  }), !w && (!t || t === "") && ze([]);
720
720
  },
721
- [V, m, w]
721
+ [P, m, w]
722
722
  ), ot = N(
723
723
  (t) => {
724
724
  A.current = !0, Q((r) => ({
725
725
  ...r,
726
726
  body: t !== "" ? t : null
727
- })), V({
727
+ })), P({
728
728
  query: "body",
729
729
  value: (t == null ? void 0 : t.value) ?? ""
730
730
  });
731
731
  },
732
- [V]
732
+ [P]
733
733
  ), at = N(
734
734
  (t) => {
735
735
  A.current = !0, Q((r) => ({
736
736
  ...r,
737
737
  series: t !== "" ? t : null
738
- })), V({
738
+ })), P({
739
739
  query: "series",
740
740
  value: (t == null ? void 0 : t.value) ?? ""
741
741
  });
742
742
  },
743
- [V]
743
+ [P]
744
744
  ), nt = N(
745
745
  (t) => {
746
746
  A.current = !0, Q((r) => ({
747
747
  ...r,
748
748
  variant: t !== "" ? t : null
749
- })), V({
749
+ })), P({
750
750
  query: "variant",
751
751
  value: (t == null ? void 0 : t.value) ?? ""
752
752
  });
753
753
  },
754
- [V]
754
+ [P]
755
755
  ), it = N(
756
756
  (t) => {
757
757
  A.current = !0, Q((r) => ({
758
758
  ...r,
759
759
  engine: t !== "" ? t : null
760
- })), V({
760
+ })), P({
761
761
  query: "engine",
762
762
  value: (t == null ? void 0 : t.value) ?? ""
763
763
  });
764
764
  },
765
- [V]
765
+ [P]
766
766
  ), st = N(
767
767
  (t) => {
768
768
  A.current = !0, Q((r) => ({
769
769
  ...r,
770
770
  engine_capacity: t !== "" ? t : null
771
- })), V({
771
+ })), P({
772
772
  query: "engine_capacity",
773
773
  value: (t == null ? void 0 : t.value) ?? ""
774
774
  });
775
775
  },
776
- [V]
776
+ [P]
777
777
  );
778
- P(() => {
778
+ V(() => {
779
779
  m && e.year && b.current && (async () => {
780
780
  try {
781
781
  const r = await b.current.search("", {
@@ -841,7 +841,7 @@ function St({
841
841
  pe(r);
842
842
  })();
843
843
  }, [v]);
844
- P(() => {
844
+ V(() => {
845
845
  if (b.current && e.make && e.make.refinement && y) {
846
846
  let t = [`make:${e.make.refinement}`], r = [];
847
847
  m && e.year && (r = [
@@ -900,10 +900,10 @@ function St({
900
900
  S.map((z) => String(z).trim().toUpperCase())
901
901
  );
902
902
  o.sort((z, p) => {
903
- const ee = h.has(z.value), Ae = h.has(p.value);
904
- if (ee && !Ae) return -1;
905
- if (!ee && Ae) return 1;
906
- if (ee && Ae) {
903
+ const te = h.has(z.value), Ae = h.has(p.value);
904
+ if (te && !Ae) return -1;
905
+ if (!te && Ae) return 1;
906
+ if (te && Ae) {
907
907
  const Ue = S.map(
908
908
  (dt) => String(dt).trim().toUpperCase()
909
909
  );
@@ -919,7 +919,7 @@ function St({
919
919
  });
920
920
  } else
921
921
  ve([]);
922
- }, [e.make, d, y, m, e.year]), P(() => {
922
+ }, [e.make, d, y, m, e.year]), V(() => {
923
923
  if (b.current && e.make && e.model) {
924
924
  console.log(
925
925
  "[VehicleSearch] Fetching year range for:",
@@ -964,7 +964,7 @@ function St({
964
964
  e.series,
965
965
  e.engine,
966
966
  e.engine_capacity
967
- ]), P(() => {
967
+ ]), V(() => {
968
968
  const t = w ? e.make && e.model : e.year && e.make && e.model;
969
969
  if (b.current && t) {
970
970
  const r = e.year ? [
@@ -998,7 +998,7 @@ function St({
998
998
  const t = ke.current ? ke.current.length + 3 : 3, r = k ? t + 1 : t;
999
999
  return `vs:lg:grid-cols-${r > 8 ? 8 : r}`;
1000
1000
  }, [k]);
1001
- P(() => {
1001
+ V(() => {
1002
1002
  const t = w ? e.make && e.model : e.make && e.model && e.year;
1003
1003
  if (b.current && t) {
1004
1004
  let r = [
@@ -1058,7 +1058,7 @@ function St({
1058
1058
  w
1059
1059
  ]);
1060
1060
  const [_e, Ee] = M(!1);
1061
- return P(() => {
1061
+ return V(() => {
1062
1062
  if (R)
1063
1063
  return _e ? document.body.style.overflow = "hidden" : document.body.style.overflow = "", () => {
1064
1064
  document.body.style.overflow = "";
@@ -1069,7 +1069,7 @@ function St({
1069
1069
  {
1070
1070
  onClick: () => Ee(!0),
1071
1071
  type: "button",
1072
- className: te(
1072
+ className: re(
1073
1073
  "vehicle-search-btn vs:md:hidden!",
1074
1074
  Y ? "vs:w-full! vs:flex! vs:shrink-0!" : "vs:w-auto! vs:inline-flex! vs:shrink!"
1075
1075
  ),
@@ -1080,7 +1080,7 @@ function St({
1080
1080
  "div",
1081
1081
  {
1082
1082
  onClick: () => Ee(!1),
1083
- className: te(
1083
+ className: re(
1084
1084
  "vs:z-10 vs:fixed vs:inset-0 vs:bg-stone-900 vs:transition-all vs:duration-300",
1085
1085
  _e ? "vs:opacity-75" : "vs:pointer-events-none vs:opacity-0"
1086
1086
  )
@@ -1089,7 +1089,7 @@ function St({
1089
1089
  /* @__PURE__ */ $(
1090
1090
  "div",
1091
1091
  {
1092
- className: te(
1092
+ className: re(
1093
1093
  "partbot-mmyvs-container",
1094
1094
  R && _e && "active",
1095
1095
  "w-full"
@@ -1123,7 +1123,7 @@ function St({
1123
1123
  "div",
1124
1124
  {
1125
1125
  ref: B,
1126
- className: te(
1126
+ className: re(
1127
1127
  "vs:grid vs:gap-3",
1128
1128
  I === "row" ? `${ct()} vs:grid-cols-1 vs:md:grid-cols-3` : "vs:grid-cols-1 vs:md:max-w-[400px] vs:md:gap-5",
1129
1129
  "vs:w-full vs:transition vs:lg:mx-auto"
@@ -1330,7 +1330,7 @@ function St({
1330
1330
  U && /* @__PURE__ */ a(
1331
1331
  "div",
1332
1332
  {
1333
- className: te(
1333
+ className: re(
1334
1334
  "vs:flex vs:w-full vs:justify-center vs:items-center",
1335
1335
  I === "row" ? "vs:md:items-end vs:md:justify-end" : "vs:md:justify-center",
1336
1336
  "vs:mt-4 vs:md:mt-3 vs:md:pr-1.5"
@@ -1485,7 +1485,7 @@ class $t extends HTMLElement {
1485
1485
  "0 0 0"
1486
1486
  ), G = `:host { --partbot-button-border-radius: ${this.getAttribute("data-button-border-radius") || "0.375rem"}; } .partbot-mmyvs-container { --partbot-button-border-radius: ${this.getAttribute("data-button-border-radius") || "0.375rem"}; }`, u = `:host { --partbot-font-size: ${this.getAttribute("data-font-size") || "0.875rem"}; } .partbot-mmyvs-container { --partbot-font-size: ${this.getAttribute("data-font-size") || "0.875rem"}; }`, x = `:host { --partbot-font-family: ${(this.getAttribute("data-font-family") || this.getAttribute("data-font")) && (this.getAttribute("data-font-family") || this.getAttribute("data-font")).trim() !== "" ? this.getAttribute("data-font-family") || this.getAttribute("data-font") : '"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif'}; } .partbot-mmyvs-container { --partbot-font-family: ${(this.getAttribute("data-font-family") || this.getAttribute("data-font")) && (this.getAttribute("data-font-family") || this.getAttribute("data-font")).trim() !== "" ? this.getAttribute("data-font-family") || this.getAttribute("data-font") : '"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif'}; }`, k = `:host { --partbot-padding: ${this.getAttribute("data-padding") || "0.5rem"}; } .partbot-mmyvs-container { --partbot-padding: ${this.getAttribute("data-padding") || "0.5rem"}; }`;
1487
1487
  const H = this.getAttribute("data-input-shadow"), J = H === "none" ? "none" : H || "0 1px 2px 0 rgb(0 0 0 / 0.05)";
1488
- let re = `:host { --partbot-input-shadow: ${J}; } .partbot-mmyvs-container { --partbot-input-shadow: ${J}; }`;
1488
+ let ee = `:host { --partbot-input-shadow: ${J}; } .partbot-mmyvs-container { --partbot-input-shadow: ${J}; }`;
1489
1489
  const g = this.getAttribute("data-input-border-color");
1490
1490
  let L = "229 231 235";
1491
1491
  if (g)
@@ -1496,7 +1496,7 @@ class $t extends HTMLElement {
1496
1496
  let w = `:host { --partbot-input-border-color: ${L}; } .partbot-mmyvs-container { --partbot-input-border-color: ${L}; }`;
1497
1497
  const i = this.getAttribute("data-input-border-width") || "1px";
1498
1498
  let B = `:host { --partbot-input-border-width: ${i}; } .partbot-mmyvs-container { --partbot-input-border-width: ${i}; }`;
1499
- v.textContent += F, v.textContent += j, v.textContent += U, v.textContent += C, v.textContent += Y, v.textContent += R, v.textContent += G, v.textContent += u, v.textContent += x, v.textContent += k, v.textContent += re, v.textContent += w, v.textContent += B, D.appendChild(v), D.appendChild(d);
1499
+ v.textContent += F, v.textContent += j, v.textContent += U, v.textContent += C, v.textContent += Y, v.textContent += R, v.textContent += G, v.textContent += u, v.textContent += x, v.textContent += k, v.textContent += ee, v.textContent += w, v.textContent += B, D.appendChild(v), D.appendChild(d);
1500
1500
  const _ = this.getAttribute("data-api-key");
1501
1501
  if (!_) {
1502
1502
  console.warn("Missing attributes: " + (_ ? "" : "data-api-key "));