@propeller-commerce/propeller-v2-react-ui 0.20.0 → 0.21.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/dist/index.js CHANGED
@@ -2756,7 +2756,8 @@ function useSpareParts(options) {
2756
2756
  const [childMachines, setChildMachines] = useState([]);
2757
2757
  const [itemsFound, setItemsFound] = useState(0);
2758
2758
  const [internalLoading, setInternalLoading] = useState(false);
2759
- const [currentPage, setCurrentPage] = useState(1);
2759
+ const [internalPage, setInternalPage] = useState(1);
2760
+ const currentPage = options.page ?? internalPage;
2760
2761
  const [totalPages, setTotalPages] = useState(1);
2761
2762
  const fetchIdRef = useRef(0);
2762
2763
  const displayParts = useMemo(
@@ -2905,7 +2906,7 @@ function useSpareParts(options) {
2905
2906
  userKey
2906
2907
  ]);
2907
2908
  const goToPage = useCallback((page) => {
2908
- setCurrentPage((prev) => {
2909
+ setInternalPage((prev) => {
2909
2910
  if (page >= 1 && (totalPages <= 1 || page <= totalPages)) return page;
2910
2911
  return prev;
2911
2912
  });
@@ -2924,9 +2925,9 @@ function useSpareParts(options) {
2924
2925
  var inflightFetches4 = /* @__PURE__ */ new Set();
2925
2926
  var ROOT_MACHINE_FIELDS = `
2926
2927
  id
2927
- name(language: $language) { language value }
2928
- description(language: $language) { language value }
2929
- slug(language: $language) { language value }
2928
+ name { language value }
2929
+ description { language value }
2930
+ slug { language value }
2930
2931
  media {
2931
2932
  images {
2932
2933
  items { imageVariants(input: $imageVariantFilters) { url } }
@@ -8529,6 +8530,7 @@ function getMachineImageUrl(machine) {
8529
8530
  }
8530
8531
  function MachineCard(props) {
8531
8532
  const { machine, href, language } = props;
8533
+ const Wrapper = href ? "a" : "div";
8532
8534
  const showImage = props.showImage ?? true;
8533
8535
  const showDescription = props.showDescription ?? false;
8534
8536
  const name = getLocalizedValue(machine.name, language);
@@ -8540,10 +8542,9 @@ function MachineCard(props) {
8540
8542
  {
8541
8543
  className: cn(`propeller-machine-card group relative flex h-full flex-col overflow-hidden rounded-lg border border-border bg-background ${props.className ?? ""}`),
8542
8544
  children: /* @__PURE__ */ jsxs(
8543
- "a",
8545
+ Wrapper,
8544
8546
  {
8545
- href,
8546
- onClick: handleClick,
8547
+ ...href ? { href, onClick: handleClick } : {},
8547
8548
  className: "flex h-full flex-col focus:outline-none focus-visible:ring-2 focus-visible:ring-primary",
8548
8549
  children: [
8549
8550
  showImage && /* @__PURE__ */ jsx("div", { className: "propeller-machine-card__image aspect-square w-full overflow-hidden bg-background-subtle", children: imageUrl ? /* @__PURE__ */ jsx(
@@ -10448,7 +10449,7 @@ function MachineGrid(rawProps) {
10448
10449
  // node query threads through useSpareParts.
10449
10450
  imageVariantFilters: configuration?.imageVariantFiltersMedium
10450
10451
  });
10451
- const { displayParts, childMachines, isLoading: partsLoading, currentPage, totalPages, goToPage } = useSpareParts({
10452
+ const { displayParts, childMachines, isLoading: partsLoading, currentPage, totalPages } = useSpareParts({
10452
10453
  graphqlClient: props.graphqlClient,
10453
10454
  // Idle at the root (no slug).
10454
10455
  slug: isRoot ? void 0 : currentSlug,
@@ -10464,6 +10465,10 @@ function MachineGrid(rawProps) {
10464
10465
  sortField,
10465
10466
  sortOrder,
10466
10467
  pageSize: offset,
10468
+ // The hook takes the controlled page directly now. It used to own its own
10469
+ // counter, so the only way to drive it from URL state was the effect
10470
+ // below — undiscoverable unless you read this file (PWP-995b).
10471
+ page: listing.page,
10467
10472
  configuration: rawProps.configuration ?? props.configuration,
10468
10473
  onFiltersChange: setGridFilters,
10469
10474
  onPriceBoundsChange: (min, max) => {
@@ -10473,9 +10478,6 @@ function MachineGrid(rawProps) {
10473
10478
  onItemsFoundChange: setItemsFound,
10474
10479
  onMachineChange: setMachine
10475
10480
  });
10476
- useEffect(() => {
10477
- goToPage(listing.page);
10478
- }, [listing.page, goToPage]);
10479
10481
  const machineName = machine ? getLocalizedValue(machine.name, machineLanguage) : slugToLabel(currentSlug);
10480
10482
  const partProducts = useMemo(
10481
10483
  () => displayParts.map((p) => p.product).filter(Boolean),
@@ -10532,11 +10534,10 @@ function MachineGrid(rawProps) {
10532
10534
  );
10533
10535
  const childSlugHref = (child) => {
10534
10536
  const slug = getLocalizedValue(child.slug, machineLanguage);
10535
- if (!slug) return null;
10536
- return `${currentPath}/${slug}`;
10537
+ return slug ? `${currentPath}/${slug}` : void 0;
10537
10538
  };
10538
10539
  if (isRoot) {
10539
- const cards = rootMachines.map((m) => ({ machine: m, href: childSlugHref(m) })).filter((c) => c.href !== null);
10540
+ const cards = rootMachines.map((m) => ({ machine: m, href: childSlugHref(m) }));
10540
10541
  return /* @__PURE__ */ jsxs("div", { className: rawProps.className, children: [
10541
10542
  /* @__PURE__ */ jsx("h1", { className: "propeller-grid-title mb-6 text-2xl font-semibold", children: rawProps.rootTitle ?? "Machines" }),
10542
10543
  rootLoading ? /* @__PURE__ */ jsx("p", { className: "py-12 text-center text-foreground-subtle", children: getLabel(rawProps.machineCardLabels, "loading", "Loading\u2026") }) : cards.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-12 text-center text-foreground-subtle", children: getLabel(rawProps.machineCardLabels, "noMachines", "No machines found.") }) : /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4", children: cards.map(({ machine: m, href }) => /* @__PURE__ */ jsx(
@@ -10568,7 +10569,6 @@ function MachineGrid(rawProps) {
10568
10569
  /* @__PURE__ */ jsx("h1", { className: "propeller-grid-title mb-6 text-2xl font-semibold", children: machineName }),
10569
10570
  childMachines.length > 0 && /* @__PURE__ */ jsx("div", { className: "propeller-machine-children mb-8 grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4", children: childMachines.map((child) => {
10570
10571
  const href = childSlugHref(child);
10571
- if (!href) return null;
10572
10572
  return /* @__PURE__ */ jsx(
10573
10573
  MachineCard,
10574
10574
  {
@@ -10646,6 +10646,12 @@ function MachineGrid(rawProps) {
10646
10646
  columns: viewMode === "list" ? 1 : 3,
10647
10647
  showAvailability: rawProps.showAvailability ?? false,
10648
10648
  showStock: rawProps.showStock ?? true,
10649
+ productCardComponent: rawProps.productCardComponent,
10650
+ productCardLabels: rawProps.productCardLabels,
10651
+ addToCartLabels: rawProps.addToCartLabels,
10652
+ stockLabels: rawProps.stockLabels,
10653
+ priceLabels: rawProps.priceLabels,
10654
+ labels: rawProps.labels,
10649
10655
  belowName: (product) => {
10650
10656
  const qty = quantityBySku.get(product.sku);
10651
10657
  if (!qty) return null;