@aglyn/plugins-commerce 1.29.3 → 1.31.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.
Files changed (72) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/cart.js +11 -5
  3. package/src/lib/components/cart.js.map +1 -1
  4. package/src/lib/components/console/pos/pos-item-dialog.component.js +12 -0
  5. package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -1
  6. package/src/lib/components/console/pos-kiosk-page.component.js +3 -5
  7. package/src/lib/components/console/pos-kiosk-page.component.js.map +1 -1
  8. package/src/lib/components/console/product-add-ons-fields.component.d.ts +11 -0
  9. package/src/lib/components/console/product-add-ons-fields.component.js +229 -13
  10. package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
  11. package/src/lib/components/console/product-editor-dialog.component.js +5 -0
  12. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  13. package/src/lib/components/console/product-traffic-card.component.d.ts +24 -0
  14. package/src/lib/components/console/product-traffic-card.component.js +172 -0
  15. package/src/lib/components/console/product-traffic-card.component.js.map +1 -0
  16. package/src/lib/components/console/products-hub-card.component.js +181 -59
  17. package/src/lib/components/console/products-hub-card.component.js.map +1 -1
  18. package/src/lib/components/console/quote-editor-dialog.component.js +38 -0
  19. package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
  20. package/src/lib/components/console/shipping-settings-card.component.js +31 -9
  21. package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
  22. package/src/lib/components/product-add-ons.d.ts +21 -0
  23. package/src/lib/components/product-add-ons.js +77 -1
  24. package/src/lib/components/product-add-ons.js.map +1 -1
  25. package/src/lib/components/product-builder-mockup.d.ts +1 -1
  26. package/src/lib/components/product-builder-mockup.js +17 -5
  27. package/src/lib/components/product-builder-mockup.js.map +1 -1
  28. package/src/lib/components/product-choice-cards.js +14 -2
  29. package/src/lib/components/product-choice-cards.js.map +1 -1
  30. package/src/lib/model/commerce-pos-kiosk.js +8 -2
  31. package/src/lib/model/commerce-pos-kiosk.js.map +1 -1
  32. package/src/lib/model/commerce-pos-offline.d.ts +1 -1
  33. package/src/lib/model/commerce-pos-offline.js +8 -2
  34. package/src/lib/model/commerce-pos-offline.js.map +1 -1
  35. package/src/lib/model/commerce-quote-request.d.ts +1 -0
  36. package/src/lib/model/commerce-quote-request.js +6 -2
  37. package/src/lib/model/commerce-quote-request.js.map +1 -1
  38. package/src/lib/model/commerce-quotes.js +10 -5
  39. package/src/lib/model/commerce-quotes.js.map +1 -1
  40. package/src/lib/model/commerce-record-routes.js +31 -0
  41. package/src/lib/model/commerce-record-routes.js.map +1 -1
  42. package/src/lib/model/commerce-shipping.d.ts +39 -16
  43. package/src/lib/model/commerce-shipping.js +315 -30
  44. package/src/lib/model/commerce-shipping.js.map +1 -1
  45. package/src/lib/model/commerce.js +1 -1
  46. package/src/lib/model/commerce.js.map +1 -1
  47. package/src/lib/model/product-modifiers.d.ts +53 -2
  48. package/src/lib/model/product-modifiers.js +127 -27
  49. package/src/lib/model/product-modifiers.js.map +1 -1
  50. package/src/lib/model/product-write.d.ts +10 -1
  51. package/src/lib/model/product-write.js +13 -2
  52. package/src/lib/model/product-write.js.map +1 -1
  53. package/src/lib/server/carrier-shipping.js +3 -2
  54. package/src/lib/server/carrier-shipping.js.map +1 -1
  55. package/src/lib/server/cart-checkout.js +10 -4
  56. package/src/lib/server/cart-checkout.js.map +1 -1
  57. package/src/lib/server/cart.js +2 -2
  58. package/src/lib/server/cart.js.map +1 -1
  59. package/src/lib/server/checkout.js +6 -4
  60. package/src/lib/server/checkout.js.map +1 -1
  61. package/src/lib/server/draft-order.js +3 -3
  62. package/src/lib/server/draft-order.js.map +1 -1
  63. package/src/lib/server/pos-kiosk.js +1 -4
  64. package/src/lib/server/pos-kiosk.js.map +1 -1
  65. package/src/lib/server/product.d.ts +5 -0
  66. package/src/lib/server/product.js +10 -2
  67. package/src/lib/server/product.js.map +1 -1
  68. package/src/lib/server/products-write.js +10 -2
  69. package/src/lib/server/products-write.js.map +1 -1
  70. package/src/lib/transfer/product-register-cells.d.ts +7 -0
  71. package/src/lib/transfer/product-register-cells.js +88 -10
  72. package/src/lib/transfer/product-register-cells.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/shipping-settings-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport * as Aglyn from '@aglyn/aglyn'\nimport * as CommerceModel from '../../model'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Alert,\n AlertTitle,\n Button,\n Divider,\n FormControlLabel,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { doc, setDoc } from 'firebase/firestore'\nimport { useCallback, useEffect, useState } from 'react'\nimport { useFirestore, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n useFirestoreDoc,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n heldSaveLabel,\n isSeedChecking,\n seedCheckingText,\n useHeldSave,\n useSeedEdits,\n} from '@aglyn/tenant-feature-instance/hooks/use-seed-edits'\n\nexport interface ShippingSettingsCardProps {\n hostId: string\n}\n\n/**\n * Shipping settings (AGL-288): zones (countries, '*' = rest of world)\n * and rates (flat / free-over / subtotal or weight tiers), stored on\n * `hosts/{hostId}/settings/store` under `shipping`. Cart checkout (AGL-1707)\n * and buy-now (AGL-1720) both read this document and declare the rates as\n * Stripe `shipping_options` (`planCheckoutShipping`) — until those landed\n * nothing read it, and everything saved here was charged to nobody. Buy-now\n * resolves only for physical one-time sales; draft orders and POS still\n * resolve no shipping at all.\n *\n * WHAT A ZONE LAYOUT COSTS THE SHOPPER (AGL-1721). A session's rates are\n * charged as picked and never re-checked against the address, so the checkout\n * can only offer rates that hold for every country it will ship to. Saving\n * zones whose rates DIFFER therefore makes the storefront ask the shopper\n * where the parcel is going before it can price one, and a destination no\n * zone covers is refused outright rather than shipped for free. One zone, or\n * one '*' zone, needs neither: the shopper is asked nothing.\n *\n * AND THE MERCHANT HAS TO BE ABLE TO SEE IT (AGL-1791). Both consequences\n * were invisible here: a merchant saved zones and the checkouts they refused\n * were refused with nothing on this page saying so, which is a support ticket\n * from someone who did nothing wrong. The coverage block reads\n * `summarizeShippingCoverage` off the same `current` object the save writes,\n * so it moves as the form is typed rather than after a round trip.\n *\n * It escalates to a warning ONLY for a merchant who priced some destinations\n * and not others. A merchant whose rates reach nowhere is not misconfigured —\n * that store charges no shipping and refuses nobody — and warning them would\n * nag every store selling downloads.\n */\nexport function ShippingSettingsCard(props: ShippingSettingsCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const {\n data: store,\n status: storeStatus,\n /**\n * The settings doc this form is seeded from is unconfirmed by the server\n * (AGL-1358). `current` is `draft ?? store?.shipping ?? {}` and the save\n * writes `{shipping: current}`, so `merge: true` protects the doc's other\n * maps and nothing inside this one — `zones` and `rates` are arrays, and\n * a merge replaces an array wholesale. Against a cached read, adding one\n * rate restores that snapshot's whole price table, and a zone that\n * disappears with it means `resolveShippingRates` matches nothing, which\n * is a checkout offering no shipping option at all.\n */\n fromCache: storeFromCache,\n listen: storeListen,\n } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId, 'settings', 'store'),\n [firestore, hostId],\n )\n // What was typed, kept as edits over the stored settings, and Save held\n // until the server has confirmed them (AGL-4047).\n const form = useSeedEdits<CommerceModel.ShippingSettings>(store?.shipping ?? {})\n const current = form.values\n const checking = isSeedChecking({ fromCache: storeFromCache, unreadable: storeStatus === 'error' })\n /*\n * Live carrier rates (AGL-3612) are offered only where a plugin quotes\n * carriers for this site — the server asks core's quoter seam. A rate\n * already saved as `carrier` stays editable either way, so a merchant can\n * still see and change what checkout falls back to.\n */\n const { data: user } = useUser()\n const [carrier, setCarrier] = useState<{\n available: boolean\n services: Array<{ serviceKey: string; label: string }>\n }>({ available: false, services: [] })\n useEffect(() => {\n let live = true\n authorizedFetch(user, `/api/commerce/shipping/carrier-rates?hostId=${encodeURIComponent(hostId)}`)\n .then((response) => (response.ok ? response.json() : null))\n .then((answer) => {\n if (live && answer) setCarrier({ available: Boolean(answer.available), services: answer.services ?? [] })\n })\n .catch(() => undefined)\n return () => {\n live = false\n }\n }, [hostId, user])\n const update = (patch: Partial<CommerceModel.ShippingSettings>) =>\n form.edit(patch)\n\n const updateZone = (\n index: number,\n patch: Partial<CommerceModel.ShippingZone> | null,\n ) => {\n const zones = [...(current.zones ?? [])]\n if (patch === null) {\n const removed = zones.splice(index, 1)[0]\n update({\n zones,\n rates: (current.rates ?? []).filter(\n (rate) => rate.zoneId !== removed?.id,\n ),\n })\n return\n }\n zones[index] = {\n id: Aglyn.createResourceUid(),\n name: '',\n countries: [],\n ...zones[index],\n ...patch,\n }\n update({ zones })\n }\n\n const updateRate = (\n index: number,\n patch: Partial<CommerceModel.ShippingRate> | null,\n ) => {\n const rates = [...(current.rates ?? [])]\n if (patch === null) rates.splice(index, 1)\n else\n rates[index] = {\n id: Aglyn.createResourceUid(),\n zoneId: current.zones?.[0]?.id ?? '',\n name: '',\n kind: 'flat',\n ...rates[index],\n ...patch,\n }\n update({ rates })\n }\n\n const handleSave = useCallback(async () => {\n /**\n * Refuse a save whose seed the server never confirmed (AGL-1358).\n *\n * No create path to exempt: this is a FIXED document path, so the empty\n * `{}` that `store?.shipping ?? {}` yields when the cache has never seen\n * the map is not the harmless blank a fresh uid would be — it replaces\n * the real zones and rates with nothing.\n *\n * The guard WRAPS the write — an early return is a shape you can keep\n * while losing the protection.\n */\n const written = form.edits\n const verdict = await writeGuardedBySeed(\n {\n subject: 'shipping settings',\n unreadable: storeStatus === 'error',\n fromCache: storeFromCache,\n listen: storeListen,\n },\n async () => {\n await setDoc(\n doc(firestore, 'hosts', hostId, 'settings', 'store'),\n { shipping: current },\n { merge: true },\n )\n },\n )\n // Before `settle`, so a refusal keeps every zone and rate that\n // was typed on screen.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n form.settle(written)\n enqueueSnackbar('Shipping settings saved', {\n variant: 'success',\n persist: false,\n })\n }, [current, form, firestore, hostId, enqueueSnackbar, storeStatus, storeFromCache, storeListen])\n\n /**\n * Recomputed from `current` on every render, so the block answers for what\n * is typed rather than for what was last saved — a merchant deleting the\n * zone that covered France should see France go uncovered before they\n * commit it, not after.\n */\n const coverage = CommerceModel.summarizeShippingCoverage(current)\n const words = CommerceModel.describeShippingCoverage(coverage)\n /**\n * The one-click half of the fix: a zone claiming everywhere the merchant\n * has not named. It adds the ZONE only — a rate on it prices the parcel,\n * and choosing that price is the merchant's call, not ours. A rate row\n * defaulted here would post at whatever we picked, and a blank flat rate\n * resolves to free.\n */\n const addRestOfWorldZone = () =>\n updateZone(current.zones?.length ?? 0, {\n name: 'Rest of world',\n countries: ['*'],\n })\n\n const usd = (cents: number | undefined) =>\n cents == null ? '' : String(cents / 100)\n const cents = (raw: string) =>\n raw.trim() === '' ? undefined : Math.round(Number(raw) * 100)\n\n // A press while Save is held is kept, and saves once confirmed (AGL-4047).\n const held = useHeldSave(handleSave, {\n checking,\n subject: 'shipping settings',\n onRefused: (message) => enqueueSnackbar(message, { variant: 'warning', persist: false }),\n })\n\n return (\n <CardDisplay\n header={'Shipping'}\n help={pluginDocsHelp('shipping', { anchor: '#zones-and-rates' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1.5}>\n <Typography variant=\"subtitle2\">{'Zones'}</Typography>\n {(current.zones ?? []).map((zone, index) => (\n <Stack key={zone.id} direction=\"row\" spacing={1}>\n <TextField\n label=\"Zone name\"\n value={zone.name}\n onChange={(event) =>\n updateZone(index, { name: event.target.value })\n }\n size=\"small\"\n sx={{ width: 180 }}\n />\n <TextField\n label=\"Countries\"\n value={zone.countries.join(', ')}\n onChange={(event) =>\n updateZone(index, {\n countries: event.target.value\n .split(',')\n .map((code) => code.trim().toUpperCase())\n .filter(Boolean),\n })\n }\n size=\"small\"\n sx={{ flex: 1 }}\n placeholder=\"US, CA — or * for everywhere else\"\n />\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() => updateZone(index, null)}\n >\n {'✕'}\n </Button>\n </Stack>\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => updateZone(current.zones?.length ?? 0, {})}\n >\n {'Add zone'}\n </Button>\n\n <Divider />\n <Typography variant=\"subtitle2\">{'Rates'}</Typography>\n {(current.rates ?? []).map((rate, index) => (\n <Stack key={rate.id} spacing={1}>\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Zone\"\n value={rate.zoneId}\n onChange={(event) =>\n updateRate(index, { zoneId: event.target.value })\n }\n size=\"small\"\n select\n sx={{ width: 150 }}\n >\n {(current.zones ?? []).map((zone) => (\n <MenuItem key={zone.id} value={zone.id}>\n {zone.name || zone.countries.join(',')}\n </MenuItem>\n ))}\n </TextField>\n <TextField\n label=\"Name\"\n value={rate.name}\n onChange={(event) =>\n updateRate(index, { name: event.target.value })\n }\n size=\"small\"\n sx={{ flex: 1 }}\n placeholder=\"Standard\"\n /**\n * A rate with no name is DROPPED at checkout, silently\n * (AGL-1791): Stripe requires a `display_name`, so\n * `resolveCheckoutShippingOptions` skips the row rather than\n * emit a session Stripe would reject. Saved blank it looks\n * like a priced rate on this page and is not one anywhere\n * else, which is the same invisibility the coverage block\n * below exists to end — said on the row that causes it,\n * because the block can only report the destination it costs.\n */\n error={!rate.name.trim()}\n helperText={\n rate.name.trim() ? undefined : 'Needed — checkout drops it'\n }\n />\n <TextField\n label=\"Type\"\n value={rate.kind}\n onChange={(event) =>\n updateRate(index, {\n kind: event.target.value as CommerceModel.ShippingRate['kind'],\n })\n }\n size=\"small\"\n select\n sx={{ width: 170 }}\n >\n <MenuItem value=\"flat\">{'Flat'}</MenuItem>\n <MenuItem value=\"free_over\">{'Free over subtotal'}</MenuItem>\n <MenuItem value=\"price_tiers\">{'Subtotal tiers'}</MenuItem>\n <MenuItem value=\"weight_tiers\">{'Weight tiers'}</MenuItem>\n {carrier.available || rate.kind === 'carrier' ? (\n <MenuItem value=\"carrier\">{'Carrier rates'}</MenuItem>\n ) : null}\n </TextField>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() => updateRate(index, null)}\n >\n {'✕'}\n </Button>\n </Stack>\n {rate.kind === 'carrier' ? (\n <CarrierRateFields\n rate={rate}\n services={carrier.services}\n available={carrier.available}\n fallbacks={(current.rates ?? []).filter(\n (other) =>\n other.id !== rate.id &&\n other.zoneId === rate.zoneId &&\n other.kind !== 'carrier',\n )}\n onChange={(patch) => updateRate(index, patch)}\n />\n ) : rate.kind === 'flat' || rate.kind === 'free_over' ? (\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Price ($)\"\n value={usd(rate.amountCents)}\n onChange={(event) =>\n updateRate(index, { amountCents: cents(event.target.value) })\n }\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {rate.kind === 'free_over' ? (\n <TextField\n label=\"Free at subtotal ($)\"\n value={usd(rate.freeOverCents)}\n onChange={(event) =>\n updateRate(index, {\n freeOverCents: cents(event.target.value),\n })\n }\n size=\"small\"\n sx={{ width: 160 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ) : null}\n </Stack>\n ) : (\n <Stack spacing={1} sx={{ pl: 2 }}>\n {(rate.tiers ?? []).map((tier, tierIndex) => (\n <Stack key={tierIndex} direction=\"row\" spacing={1}>\n <TextField\n label={\n rate.kind === 'weight_tiers'\n ? 'Up to (g)'\n : 'Up to subtotal ($)'\n }\n value={\n rate.kind === 'weight_tiers'\n ? tier.upTo\n : tier.upTo / 100\n }\n onChange={(event) => {\n const tiers = [...(rate.tiers ?? [])]\n const value = Number(event.target.value) || 0\n tiers[tierIndex] = {\n ...tier,\n upTo:\n rate.kind === 'weight_tiers'\n ? Math.round(value)\n : Math.round(value * 100),\n }\n updateRate(index, { tiers })\n }}\n size=\"small\"\n sx={{ width: 160 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label=\"Price ($)\"\n value={tier.amountCents / 100}\n onChange={(event) => {\n const tiers = [...(rate.tiers ?? [])]\n tiers[tierIndex] = {\n ...tier,\n amountCents: Math.round(\n (Number(event.target.value) || 0) * 100,\n ),\n }\n updateRate(index, { tiers })\n }}\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() =>\n updateRate(index, {\n tiers: (rate.tiers ?? []).filter(\n (_item, itemIndex) => itemIndex !== tierIndex,\n ),\n })\n }\n >\n {'✕'}\n </Button>\n </Stack>\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() =>\n updateRate(index, {\n tiers: [\n ...(rate.tiers ?? []),\n { upTo: 0, amountCents: 0 },\n ],\n })\n }\n >\n {'Add tier'}\n </Button>\n </Stack>\n )}\n </Stack>\n ))}\n <Button\n size=\"small\"\n disabled={(current.zones?.length ?? 0) === 0}\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => updateRate(current.rates?.length ?? 0, {})}\n >\n {'Add rate'}\n </Button>\n\n <Stack spacing={0}>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={Boolean(current.localPickup)}\n onChange={(event) =>\n update({ localPickup: event.target.checked })\n }\n />\n }\n label=\"Offer free local pickup\"\n />\n {/*\n What the toggle does NOT do, said on the toggle (AGL-2325). It\n used to silently switch off every \"we don't ship there\" refusal,\n because pickup resolved for every destination and checkout read a\n non-empty list as coverage. It no longer does — but a merchant\n reading one line of label still has to be told that turning\n collection on is not the same as adding a destination.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {\n 'A free collection choice at checkout. It does not widen where ' +\n 'you ship — a destination none of your rates reaches is still ' +\n 'turned away. To let buyers choose WHERE to collect, with hours ' +\n 'and a ready-for-pickup email, turn on pickup for a location ' +\n 'under Inventory locations; this choice then gives way to it.'\n }\n </Typography>\n </Stack>\n\n <Divider />\n <Typography variant=\"subtitle2\">{'Coverage'}</Typography>\n {coverage.unserved.length > 0 ? (\n <Alert\n severity=\"warning\"\n action={\n coverage.hasRestOfWorldZone ? undefined : (\n <Button\n size=\"small\"\n color=\"inherit\"\n onClick={addRestOfWorldZone}\n >\n {'Add rest-of-world zone'}\n </Button>\n )\n }\n >\n <AlertTitle>{words.headline}</AlertTitle>\n {words.detail}\n </Alert>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {words.note}\n </Typography>\n )}\n {words.asks ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {words.asks}\n </Typography>\n ) : null}\n\n <Button\n variant=\"contained\"\n color=\"primary\"\n size=\"small\"\n disabled={!form.dirty || held.saving}\n onClick={held.press}\n sx={{ alignSelf: 'flex-start' }}\n >\n {heldSaveLabel(held, 'Save shipping settings')}\n </Button>\n {form.dirty && checking ? (\n <Typography variant=\"body2\" color=\"text.secondary\" role=\"status\">\n {seedCheckingText('shipping settings')}\n </Typography>\n ) : null}\n </Stack>\n </CardDisplay>\n )\n}\nShippingSettingsCard.displayName = 'ShippingSettingsCard'\n\nexport default ShippingSettingsCard\n\ninterface CarrierRateFieldsProps {\n rate: CommerceModel.ShippingRate\n services: Array<{ serviceKey: string; label: string }>\n available: boolean\n /** The zone's other rates, any of which checkout may fall back to. */\n fallbacks: CommerceModel.ShippingRate[]\n onChange: (patch: Partial<CommerceModel.ShippingRate>) => void\n}\n\n/**\n * A carrier rate's options (AGL-3612): which services checkout offers, what\n * is added to each quote, and the zone's rate offered when no live quote is.\n */\nfunction CarrierRateFields(props: CarrierRateFieldsProps) {\n const { rate, services, available, fallbacks, onChange } = props\n const options = rate.carrier ?? {}\n const set = (patch: Partial<CommerceModel.CarrierRateSettings>) =>\n onChange({ carrier: { ...options, ...patch } })\n const picked = new Set(options.services ?? [])\n return (\n <Stack spacing={1} sx={{ pl: 2 }}>\n {!available ? (\n <Alert severity=\"info\">\n {'Live carrier rates are not available on this site right now, so checkout offers the fallback rate.'}\n </Alert>\n ) : null}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Shoppers see each carrier’s price for their address. Leave every service unticked to offer all of them.'}\n </Typography>\n <Stack direction=\"row\" sx={{ flexWrap: 'wrap', columnGap: 2 }}>\n {services.map((service) => (\n <FormControlLabel\n key={service.serviceKey}\n control={\n <Switch\n size=\"small\"\n checked={picked.has(service.serviceKey)}\n onChange={(event) =>\n set({\n services: event.target.checked\n ? [...picked, service.serviceKey]\n : [...picked].filter((key) => key !== service.serviceKey),\n })\n }\n />\n }\n label={service.label}\n />\n ))}\n </Stack>\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Markup (%)\"\n value={options.markupPct ?? ''}\n onChange={(event) => {\n const pct = Number(event.target.value)\n set({ markupPct: Number.isFinite(pct) && pct > 0 ? Math.min(pct, 500) : 0 })\n }}\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label=\"Handling fee ($)\"\n value={options.handlingCents ? options.handlingCents / 100 : ''}\n onChange={(event) => {\n const dollars = Number(event.target.value)\n set({ handlingCents: Number.isFinite(dollars) && dollars > 0 ? Math.round(dollars * 100) : 0 })\n }}\n size=\"small\"\n sx={{ width: 150 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n select\n label=\"If no live rate\"\n value={options.fallbackRateId ?? ''}\n onChange={(event) => set({ fallbackRateId: event.target.value })}\n size=\"small\"\n sx={{ minWidth: 200 }}\n error={!options.fallbackRateId}\n helperText={\n options.fallbackRateId ? undefined : 'Pick a rate of this zone, or checkout can’t price without a quote'\n }\n >\n <MenuItem value=\"\">{'None'}</MenuItem>\n {fallbacks.map((fallback) => (\n <MenuItem key={fallback.id} value={fallback.id}>\n {fallback.name || 'Unnamed rate'}\n </MenuItem>\n ))}\n </TextField>\n </Stack>\n </Stack>\n )\n}\n"],"names":["Aglyn","CommerceModel","CardDisplay","useSnackbar","Alert","AlertTitle","Button","Divider","FormControlLabel","MenuItem","Stack","Switch","TextField","Typography","authorizedFetch","doc","setDoc","useCallback","useEffect","useState","useFirestore","useUser","useFirestoreDoc","writeGuardedBySeed","pluginDocsHelp","heldSaveLabel","isSeedChecking","seedCheckingText","useHeldSave","useSeedEdits","ShippingSettingsCard","props","current","hostId","firestore","enqueueSnackbar","data","store","status","storeStatus","fromCache","storeFromCache","listen","storeListen","form","shipping","values","checking","unreadable","user","carrier","setCarrier","available","services","live","encodeURIComponent","then","response","ok","json","answer","Boolean","catch","undefined","update","patch","edit","updateZone","index","zones","removed","splice","rates","filter","rate","zoneId","id","createResourceUid","name","countries","updateRate","kind","handleSave","written","edits","verdict","subject","merge","message","variant","persist","settle","coverage","summarizeShippingCoverage","words","describeShippingCoverage","addRestOfWorldZone","length","usd","cents","String","raw","trim","Math","round","Number","held","onRefused","header","help","anchor","contentGutterX","contentGutterY","spacing","map","zone","direction","label","value","onChange","event","target","size","sx","width","join","split","code","toUpperCase","flex","placeholder","color","onClick","alignSelf","select","error","helperText","CarrierRateFields","fallbacks","other","amountCents","slotProps","htmlInput","inputMode","freeOverCents","pl","tiers","tier","tierIndex","upTo","_item","itemIndex","disabled","control","checked","localPickup","unserved","severity","action","hasRestOfWorldZone","headline","detail","note","asks","dirty","saving","press","role","displayName","options","set","picked","Set","flexWrap","columnGap","service","has","serviceKey","key","markupPct","pct","isFinite","min","handlingCents","dollars","fallbackRateId","minWidth","fallback"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AACrC,YAAYC,mBAAmB,uBAAa;AAC5C,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,KAAK,EACLC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,gBAAgB,EAChBC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,GAAG,EAAEC,MAAM,QAAQ,qBAAoB;AAChD,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AACxD,SAASC,YAAY,EAAEC,OAAO,QAAQ,iCAAgC;AACtE,SACEC,eAAe,EACfC,kBAAkB,QACb,iCAAgC;AACvC,SAASC,cAAc,QAAQ,eAAc;AAC7C,SACEC,aAAa,EACbC,cAAc,EACdC,gBAAgB,EAChBC,WAAW,EACXC,YAAY,QACP,sDAAqD;AAM5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GACD,OAAO,SAASC,qBAAqBC,KAAgC;cAsL3DC,gBA6CAA;QAkMWA;IApanB,MAAM,EAAEC,MAAM,EAAE,GAAGF;IACnB,MAAMG,YAAYd;IAClB,MAAM,EAAEe,eAAe,EAAE,GAAGhC;IAC5B,MAAM,EACJiC,MAAMC,KAAK,EACXC,QAAQC,WAAW,EACnB;;;;;;;;;KASC,GACDC,WAAWC,cAAc,EACzBC,QAAQC,WAAW,EACpB,GAAGrB,gBACF,IAAMP,IAAImB,WAAW,SAASD,QAAQ,YAAY,UAClD;QAACC;QAAWD;KAAO;IAErB,wEAAwE;IACxE,kDAAkD;IAClD,MAAMW,OAAOf,qBAA6CQ,y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AACH,KAAK;4BAAC;wBAC9DI,MAAK;wBACLC,IAAI;4BAAE+D,UAAU;wBAAI;wBACpBnD,OAAO,CAACkC,QAAQgB,cAAc;wBAC9BjD,YACEiC,QAAQgB,cAAc,GAAG1H,YAAY;;0CAGvC,KAACtD;gCAAS6G,OAAM;0CAAI;;4BACnBoB,UAAUxB,GAAG,CAAC,CAACyE,yBACd,KAAClL;oCAA2B6G,OAAOqE,SAAS/G,EAAE;8CAC3C+G,SAAS7G,IAAI,IAAI;mCADL6G,SAAS/G,EAAE;;;;;;;AAQtC"}
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/shipping-settings-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport * as Aglyn from '@aglyn/aglyn'\nimport * as CommerceModel from '../../model'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Alert,\n AlertTitle,\n Autocomplete,\n Button,\n Divider,\n FormControlLabel,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { doc, setDoc } from 'firebase/firestore'\nimport { useCallback, useEffect, useState } from 'react'\nimport { useFirestore, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n useFirestoreDoc,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n heldSaveLabel,\n isSeedChecking,\n seedCheckingText,\n useHeldSave,\n useSeedEdits,\n} from '@aglyn/tenant-feature-instance/hooks/use-seed-edits'\n\nexport interface ShippingSettingsCardProps {\n hostId: string\n}\n\n/** Every country checkout can ship to, plus rest of world, for a zone. */\nconst ZONE_COUNTRY_OPTIONS: string[] = [\n '*',\n ...[...CommerceModel.STRIPE_SHIPPING_COUNTRY_CODES].sort((a, b) =>\n zoneCountryLabel(a).localeCompare(zoneCountryLabel(b)),\n ),\n]\n\nfunction zoneCountryLabel(code: string): string {\n if (code === '*') return 'Rest of world'\n return CommerceModel.CHECKOUT_SHIPPING_COUNTRY_NAMES[code] ?? code\n}\n\n/**\n * Shipping settings (AGL-288): zones (countries, '*' = rest of world)\n * and rates (flat / free-over / subtotal or weight tiers), stored on\n * `hosts/{hostId}/settings/store` under `shipping`. Cart checkout (AGL-1707)\n * and buy-now (AGL-1720) both read this document and declare the rates as\n * Stripe `shipping_options` (`planCheckoutShipping`) — until those landed\n * nothing read it, and everything saved here was charged to nobody. Buy-now\n * resolves only for physical one-time sales; draft orders and POS still\n * resolve no shipping at all.\n *\n * WHAT A ZONE LAYOUT COSTS THE SHOPPER (AGL-1721). A session's rates are\n * charged as picked and never re-checked against the address, so the checkout\n * can only offer rates that hold for every country it will ship to. Saving\n * zones whose rates DIFFER therefore makes the storefront ask the shopper\n * where the parcel is going before it can price one, and a destination no\n * zone covers is refused outright rather than shipped for free. One zone, or\n * one '*' zone, needs neither: the shopper is asked nothing.\n *\n * AND THE MERCHANT HAS TO BE ABLE TO SEE IT (AGL-1791). Both consequences\n * were invisible here: a merchant saved zones and the checkouts they refused\n * were refused with nothing on this page saying so, which is a support ticket\n * from someone who did nothing wrong. The coverage block reads\n * `summarizeShippingCoverage` off the same `current` object the save writes,\n * so it moves as the form is typed rather than after a round trip.\n *\n * It escalates to a warning ONLY for a merchant who priced some destinations\n * and not others. A merchant whose rates reach nowhere is not misconfigured —\n * that store charges no shipping and refuses nobody — and warning them would\n * nag every store selling downloads.\n */\nexport function ShippingSettingsCard(props: ShippingSettingsCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const {\n data: store,\n status: storeStatus,\n /**\n * The settings doc this form is seeded from is unconfirmed by the server\n * (AGL-1358). `current` is `draft ?? store?.shipping ?? {}` and the save\n * writes `{shipping: current}`, so `merge: true` protects the doc's other\n * maps and nothing inside this one — `zones` and `rates` are arrays, and\n * a merge replaces an array wholesale. Against a cached read, adding one\n * rate restores that snapshot's whole price table, and a zone that\n * disappears with it means `resolveShippingRates` matches nothing, which\n * is a checkout offering no shipping option at all.\n */\n fromCache: storeFromCache,\n listen: storeListen,\n } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId, 'settings', 'store'),\n [firestore, hostId],\n )\n // What was typed, kept as edits over the stored settings, and Save held\n // until the server has confirmed them (AGL-4047).\n const form = useSeedEdits<CommerceModel.ShippingSettings>(store?.shipping ?? {})\n const current = form.values\n const checking = isSeedChecking({ fromCache: storeFromCache, unreadable: storeStatus === 'error' })\n /*\n * Live carrier rates (AGL-3612) are offered only where a plugin quotes\n * carriers for this site — the server asks core's quoter seam. A rate\n * already saved as `carrier` stays editable either way, so a merchant can\n * still see and change what checkout falls back to.\n */\n const { data: user } = useUser()\n const [carrier, setCarrier] = useState<{\n available: boolean\n services: Array<{ serviceKey: string; label: string }>\n }>({ available: false, services: [] })\n useEffect(() => {\n let live = true\n authorizedFetch(user, `/api/commerce/shipping/carrier-rates?hostId=${encodeURIComponent(hostId)}`)\n .then((response) => (response.ok ? response.json() : null))\n .then((answer) => {\n if (live && answer) setCarrier({ available: Boolean(answer.available), services: answer.services ?? [] })\n })\n .catch(() => undefined)\n return () => {\n live = false\n }\n }, [hostId, user])\n const update = (patch: Partial<CommerceModel.ShippingSettings>) =>\n form.edit(patch)\n\n const updateZone = (\n index: number,\n patch: Partial<CommerceModel.ShippingZone> | null,\n ) => {\n const zones = [...(current.zones ?? [])]\n if (patch === null) {\n const removed = zones.splice(index, 1)[0]\n update({\n zones,\n rates: (current.rates ?? []).filter(\n (rate) => rate.zoneId !== removed?.id,\n ),\n })\n return\n }\n zones[index] = {\n id: Aglyn.createResourceUid(),\n name: '',\n countries: [],\n ...zones[index],\n ...patch,\n }\n update({ zones })\n }\n\n const updateRate = (\n index: number,\n patch: Partial<CommerceModel.ShippingRate> | null,\n ) => {\n const rates = [...(current.rates ?? [])]\n if (patch === null) rates.splice(index, 1)\n else\n rates[index] = {\n id: Aglyn.createResourceUid(),\n zoneId: current.zones?.[0]?.id ?? '',\n name: '',\n kind: 'flat',\n ...rates[index],\n ...patch,\n }\n update({ rates })\n }\n\n const handleSave = useCallback(async () => {\n /**\n * Refuse a save whose seed the server never confirmed (AGL-1358).\n *\n * No create path to exempt: this is a FIXED document path, so the empty\n * `{}` that `store?.shipping ?? {}` yields when the cache has never seen\n * the map is not the harmless blank a fresh uid would be — it replaces\n * the real zones and rates with nothing.\n *\n * The guard WRAPS the write — an early return is a shape you can keep\n * while losing the protection.\n */\n const written = form.edits\n const verdict = await writeGuardedBySeed(\n {\n subject: 'shipping settings',\n unreadable: storeStatus === 'error',\n fromCache: storeFromCache,\n listen: storeListen,\n },\n async () => {\n await setDoc(\n doc(firestore, 'hosts', hostId, 'settings', 'store'),\n { shipping: current },\n { merge: true },\n )\n },\n )\n // Before `settle`, so a refusal keeps every zone and rate that\n // was typed on screen.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n form.settle(written)\n enqueueSnackbar('Shipping settings saved', {\n variant: 'success',\n persist: false,\n })\n }, [current, form, firestore, hostId, enqueueSnackbar, storeStatus, storeFromCache, storeListen])\n\n /**\n * Recomputed from `current` on every render, so the block answers for what\n * is typed rather than for what was last saved — a merchant deleting the\n * zone that covered France should see France go uncovered before they\n * commit it, not after.\n */\n const coverage = CommerceModel.summarizeShippingCoverage(current)\n const words = CommerceModel.describeShippingCoverage(coverage)\n /**\n * The one-click half of the fix: a zone claiming everywhere the merchant\n * has not named. It adds the ZONE only — a rate on it prices the parcel,\n * and choosing that price is the merchant's call, not ours. A rate row\n * defaulted here would post at whatever we picked, and a blank flat rate\n * resolves to free.\n */\n const addRestOfWorldZone = () =>\n updateZone(current.zones?.length ?? 0, {\n name: 'Rest of world',\n countries: ['*'],\n })\n\n const usd = (cents: number | undefined) =>\n cents == null ? '' : String(cents / 100)\n const cents = (raw: string) =>\n raw.trim() === '' ? undefined : Math.round(Number(raw) * 100)\n\n // A press while Save is held is kept, and saves once confirmed (AGL-4047).\n const held = useHeldSave(handleSave, {\n checking,\n subject: 'shipping settings',\n onRefused: (message) => enqueueSnackbar(message, { variant: 'warning', persist: false }),\n })\n\n return (\n <CardDisplay\n header={'Shipping'}\n help={pluginDocsHelp('shipping', { anchor: '#zones-and-rates' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1.5}>\n <Typography variant=\"subtitle2\">{'Zones'}</Typography>\n {(current.zones ?? []).map((zone, index) => (\n <Stack key={zone.id} direction=\"row\" spacing={1}>\n <TextField\n label=\"Zone name\"\n value={zone.name}\n onChange={(event) =>\n updateZone(index, { name: event.target.value })\n }\n size=\"small\"\n sx={{ width: 180 }}\n />\n <Autocomplete\n multiple\n size=\"small\"\n sx={{ flex: 1, minWidth: 240 }}\n options={ZONE_COUNTRY_OPTIONS}\n value={zone.countries}\n filterSelectedOptions\n getOptionLabel={zoneCountryLabel}\n onChange={(_event, countries) =>\n updateZone(index, {\n // Rest of world stands alone: a zone that names it AND a\n // country says the same thing twice.\n countries:\n countries.at(-1) === '*'\n ? ['*']\n : countries.filter((code) => code !== '*'),\n })\n }\n renderInput={(params) => (\n <TextField\n {...params}\n label=\"Countries\"\n placeholder={zone.countries.length ? '' : 'Search countries, or Rest of world'}\n />\n )}\n />\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() => updateZone(index, null)}\n >\n {'✕'}\n </Button>\n </Stack>\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => updateZone(current.zones?.length ?? 0, {})}\n >\n {'Add zone'}\n </Button>\n\n <Divider />\n <Typography variant=\"subtitle2\">{'Rates'}</Typography>\n {(current.rates ?? []).map((rate, index) => (\n <Stack key={rate.id} spacing={1}>\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Zone\"\n value={rate.zoneId}\n onChange={(event) =>\n updateRate(index, { zoneId: event.target.value })\n }\n size=\"small\"\n select\n sx={{ width: 150 }}\n >\n {(current.zones ?? []).map((zone) => (\n <MenuItem key={zone.id} value={zone.id}>\n {zone.name || zone.countries.join(',')}\n </MenuItem>\n ))}\n </TextField>\n <TextField\n label=\"Name\"\n value={rate.name}\n onChange={(event) =>\n updateRate(index, { name: event.target.value })\n }\n size=\"small\"\n sx={{ flex: 1 }}\n placeholder=\"Standard\"\n /**\n * A rate with no name is DROPPED at checkout, silently\n * (AGL-1791): Stripe requires a `display_name`, so\n * `resolveCheckoutShippingOptions` skips the row rather than\n * emit a session Stripe would reject. Saved blank it looks\n * like a priced rate on this page and is not one anywhere\n * else, which is the same invisibility the coverage block\n * below exists to end — said on the row that causes it,\n * because the block can only report the destination it costs.\n */\n error={!rate.name.trim()}\n helperText={\n rate.name.trim() ? undefined : 'Needed — checkout drops it'\n }\n />\n <TextField\n label=\"Type\"\n value={rate.kind}\n onChange={(event) =>\n updateRate(index, {\n kind: event.target.value as CommerceModel.ShippingRate['kind'],\n })\n }\n size=\"small\"\n select\n sx={{ width: 170 }}\n >\n <MenuItem value=\"flat\">{'Flat'}</MenuItem>\n <MenuItem value=\"free_over\">{'Free over subtotal'}</MenuItem>\n <MenuItem value=\"price_tiers\">{'Subtotal tiers'}</MenuItem>\n <MenuItem value=\"weight_tiers\">{'Weight tiers'}</MenuItem>\n {carrier.available || rate.kind === 'carrier' ? (\n <MenuItem value=\"carrier\">{'Carrier rates'}</MenuItem>\n ) : null}\n </TextField>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() => updateRate(index, null)}\n >\n {'✕'}\n </Button>\n </Stack>\n {rate.kind === 'carrier' ? (\n <CarrierRateFields\n rate={rate}\n services={carrier.services}\n available={carrier.available}\n fallbacks={(current.rates ?? []).filter(\n (other) =>\n other.id !== rate.id &&\n other.zoneId === rate.zoneId &&\n other.kind !== 'carrier',\n )}\n onChange={(patch) => updateRate(index, patch)}\n />\n ) : rate.kind === 'flat' || rate.kind === 'free_over' ? (\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Price ($)\"\n value={usd(rate.amountCents)}\n onChange={(event) =>\n updateRate(index, { amountCents: cents(event.target.value) })\n }\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {rate.kind === 'free_over' ? (\n <TextField\n label=\"Free at subtotal ($)\"\n value={usd(rate.freeOverCents)}\n onChange={(event) =>\n updateRate(index, {\n freeOverCents: cents(event.target.value),\n })\n }\n size=\"small\"\n sx={{ width: 160 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ) : null}\n </Stack>\n ) : (\n <Stack spacing={1} sx={{ pl: 2 }}>\n {(rate.tiers ?? []).map((tier, tierIndex) => (\n <Stack key={tierIndex} direction=\"row\" spacing={1}>\n <TextField\n label={\n rate.kind === 'weight_tiers'\n ? 'Up to (g)'\n : 'Up to subtotal ($)'\n }\n value={\n rate.kind === 'weight_tiers'\n ? tier.upTo\n : tier.upTo / 100\n }\n onChange={(event) => {\n const tiers = [...(rate.tiers ?? [])]\n const value = Number(event.target.value) || 0\n tiers[tierIndex] = {\n ...tier,\n upTo:\n rate.kind === 'weight_tiers'\n ? Math.round(value)\n : Math.round(value * 100),\n }\n updateRate(index, { tiers })\n }}\n size=\"small\"\n sx={{ width: 160 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label=\"Price ($)\"\n value={tier.amountCents / 100}\n onChange={(event) => {\n const tiers = [...(rate.tiers ?? [])]\n tiers[tierIndex] = {\n ...tier,\n amountCents: Math.round(\n (Number(event.target.value) || 0) * 100,\n ),\n }\n updateRate(index, { tiers })\n }}\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() =>\n updateRate(index, {\n tiers: (rate.tiers ?? []).filter(\n (_item, itemIndex) => itemIndex !== tierIndex,\n ),\n })\n }\n >\n {'✕'}\n </Button>\n </Stack>\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() =>\n updateRate(index, {\n tiers: [\n ...(rate.tiers ?? []),\n { upTo: 0, amountCents: 0 },\n ],\n })\n }\n >\n {'Add tier'}\n </Button>\n </Stack>\n )}\n </Stack>\n ))}\n <Button\n size=\"small\"\n disabled={(current.zones?.length ?? 0) === 0}\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => updateRate(current.rates?.length ?? 0, {})}\n >\n {'Add rate'}\n </Button>\n\n <Stack spacing={0}>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={Boolean(current.localPickup)}\n onChange={(event) =>\n update({ localPickup: event.target.checked })\n }\n />\n }\n label=\"Offer free local pickup\"\n />\n {/*\n What the toggle does NOT do, said on the toggle (AGL-2325). It\n used to silently switch off every \"we don't ship there\" refusal,\n because pickup resolved for every destination and checkout read a\n non-empty list as coverage. It no longer does — but a merchant\n reading one line of label still has to be told that turning\n collection on is not the same as adding a destination.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {\n 'A free collection choice at checkout. It does not widen where ' +\n 'you ship — a destination none of your rates reaches is still ' +\n 'turned away. To let buyers choose WHERE to collect, with hours ' +\n 'and a ready-for-pickup email, turn on pickup for a location ' +\n 'under Inventory locations; this choice then gives way to it.'\n }\n </Typography>\n </Stack>\n\n <Divider />\n <Typography variant=\"subtitle2\">{'Coverage'}</Typography>\n {coverage.unserved.length > 0 ? (\n <Alert\n severity=\"warning\"\n action={\n coverage.hasRestOfWorldZone ? undefined : (\n <Button\n size=\"small\"\n color=\"inherit\"\n onClick={addRestOfWorldZone}\n >\n {'Add rest-of-world zone'}\n </Button>\n )\n }\n >\n <AlertTitle>{words.headline}</AlertTitle>\n {words.detail}\n </Alert>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {words.note}\n </Typography>\n )}\n {words.asks ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {words.asks}\n </Typography>\n ) : null}\n\n <Button\n variant=\"contained\"\n color=\"primary\"\n size=\"small\"\n disabled={!form.dirty || held.saving}\n onClick={held.press}\n sx={{ alignSelf: 'flex-start' }}\n >\n {heldSaveLabel(held, 'Save shipping settings')}\n </Button>\n {form.dirty && checking ? (\n <Typography variant=\"body2\" color=\"text.secondary\" role=\"status\">\n {seedCheckingText('shipping settings')}\n </Typography>\n ) : null}\n </Stack>\n </CardDisplay>\n )\n}\nShippingSettingsCard.displayName = 'ShippingSettingsCard'\n\nexport default ShippingSettingsCard\n\ninterface CarrierRateFieldsProps {\n rate: CommerceModel.ShippingRate\n services: Array<{ serviceKey: string; label: string }>\n available: boolean\n /** The zone's other rates, any of which checkout may fall back to. */\n fallbacks: CommerceModel.ShippingRate[]\n onChange: (patch: Partial<CommerceModel.ShippingRate>) => void\n}\n\n/**\n * A carrier rate's options (AGL-3612): which services checkout offers, what\n * is added to each quote, and the zone's rate offered when no live quote is.\n */\nfunction CarrierRateFields(props: CarrierRateFieldsProps) {\n const { rate, services, available, fallbacks, onChange } = props\n const options = rate.carrier ?? {}\n const set = (patch: Partial<CommerceModel.CarrierRateSettings>) =>\n onChange({ carrier: { ...options, ...patch } })\n const picked = new Set(options.services ?? [])\n return (\n <Stack spacing={1} sx={{ pl: 2 }}>\n {!available ? (\n <Alert severity=\"info\">\n {'Live carrier rates are not available on this site right now, so checkout offers the fallback rate.'}\n </Alert>\n ) : null}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Shoppers see each carrier’s price for their address. Leave every service unticked to offer all of them.'}\n </Typography>\n <Stack direction=\"row\" sx={{ flexWrap: 'wrap', columnGap: 2 }}>\n {services.map((service) => (\n <FormControlLabel\n key={service.serviceKey}\n control={\n <Switch\n size=\"small\"\n checked={picked.has(service.serviceKey)}\n onChange={(event) =>\n set({\n services: event.target.checked\n ? [...picked, service.serviceKey]\n : [...picked].filter((key) => key !== service.serviceKey),\n })\n }\n />\n }\n label={service.label}\n />\n ))}\n </Stack>\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Markup (%)\"\n value={options.markupPct ?? ''}\n onChange={(event) => {\n const pct = Number(event.target.value)\n set({ markupPct: Number.isFinite(pct) && pct > 0 ? Math.min(pct, 500) : 0 })\n }}\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label=\"Handling fee ($)\"\n value={options.handlingCents ? options.handlingCents / 100 : ''}\n onChange={(event) => {\n const dollars = Number(event.target.value)\n set({ handlingCents: Number.isFinite(dollars) && dollars > 0 ? Math.round(dollars * 100) : 0 })\n }}\n size=\"small\"\n sx={{ width: 150 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n select\n label=\"If no live rate\"\n value={options.fallbackRateId ?? ''}\n onChange={(event) => set({ fallbackRateId: event.target.value })}\n size=\"small\"\n sx={{ minWidth: 200 }}\n error={!options.fallbackRateId}\n helperText={\n options.fallbackRateId ? undefined : 'Pick a rate of this zone, or checkout can’t price without a quote'\n }\n >\n <MenuItem value=\"\">{'None'}</MenuItem>\n {fallbacks.map((fallback) => (\n <MenuItem key={fallback.id} value={fallback.id}>\n {fallback.name || 'Unnamed rate'}\n </MenuItem>\n ))}\n </TextField>\n </Stack>\n </Stack>\n )\n}\n"],"names":["Aglyn","CommerceModel","CardDisplay","useSnackbar","Alert","AlertTitle","Autocomplete","Button","Divider","FormControlLabel","MenuItem","Stack","Switch","TextField","Typography","authorizedFetch","doc","setDoc","useCallback","useEffect","useState","useFirestore","useUser","useFirestoreDoc","writeGuardedBySeed","pluginDocsHelp","heldSaveLabel","isSeedChecking","seedCheckingText","useHeldSave","useSeedEdits","ZONE_COUNTRY_OPTIONS","STRIPE_SHIPPING_COUNTRY_CODES","sort","a","b","zoneCountryLabel","localeCompare","code","CHECKOUT_SHIPPING_COUNTRY_NAMES","ShippingSettingsCard","props","current","hostId","firestore","enqueueSnackbar","data","store","status","storeStatus","fromCache","storeFromCache","listen","storeListen","form","shipping","values","checking","unreadable","user","carrier","setCarrier","available","services","live","encodeURIComponent","then","response","ok","json","answer","Boolean","catch","undefined","update","patch","edit","updateZone","index","zones","removed","splice","rates","filter","rate","zoneId","id","createResourceUid","name","countries","updateRate","kind","handleSave","written","edits","verdict","subject","merge","message","variant","persist","settle","coverage","summarizeShippingCoverage","words","describeShippingCoverage","addRestOfWorldZone","length","usd","cents","String","raw","trim","Math","round","Number","held","onRefused","header","help","anchor","contentGutterX","contentGutterY","spacing","map","zone","direction","label","value","onChange","event","target","size","sx","width","multiple","flex","minWidth","options","filterSelectedOptions","getOptionLabel","_event","at","renderInput","params","placeholder","color","onClick","alignSelf","select","join","error","helperText","CarrierRateFields","fallbacks","other","amountCents","slotProps","htmlInput","inputMode","freeOverCents","pl","tiers","tier","tierIndex","upTo","_item","itemIndex","disabled","control","checked","localPickup","unserved","severity","action","hasRestOfWorldZone","headline","detail","note","asks","dirty","saving","press","role","displayName","set","picked","Set","flexWrap","columnGap","service","has","serviceKey","key","markupPct","pct","isFinite","min","handlingCents","dollars","fallbackRateId","fallback"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AACrC,YAAYC,mBAAmB,uBAAa;AAC5C,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,KAAK,EACLC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,OAAO,EACPC,gBAAgB,EAChBC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,g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BAA0B;wBACjCT,UAAU,CAACC,QAAUuD,IAAI;gCAAEe,gBAAgBtE,MAAMC,MAAM,CAACH,KAAK;4BAAC;wBAC9DI,MAAK;wBACLC,IAAI;4BAAEI,UAAU;wBAAI;wBACpBc,OAAO,CAACb,QAAQ8D,cAAc;wBAC9BhD,YACEd,QAAQ8D,cAAc,GAAG/H,YAAY;;0CAGvC,KAAC/D;gCAASsH,OAAM;0CAAI;;4BACnB0B,UAAU9B,GAAG,CAAC,CAAC6E,yBACd,KAAC/L;oCAA2BsH,OAAOyE,SAASnH,EAAE;8CAC3CmH,SAASjH,IAAI,IAAI;mCADLiH,SAASnH,EAAE;;;;;;;AAQtC"}
@@ -12,6 +12,27 @@ export interface ProductAddOnsProps {
12
12
  }
13
13
  /** The picks with one group's answer replaced, in the groups' own order. */
14
14
  export declare function withGroupAnswer(groups: readonly ProductModifierGroup[], value: readonly ModifierSelection[], groupId: string, optionIds: readonly string[]): ModifierSelection[];
15
+ /**
16
+ * The picks with a write-in's answer replaced (write-ins): the
17
+ * text as typed so far, kept while it is being typed; an empty answer leaves
18
+ * the group unanswered. The server cleans and checks it.
19
+ */
20
+ export declare function withWriteInAnswer(groups: readonly ProductModifierGroup[], value: readonly ModifierSelection[], group: ProductModifierGroup, text: string): ModifierSelection[];
21
+ export interface ProductWriteInFieldProps {
22
+ group: ProductModifierGroup;
23
+ groups: readonly ProductModifierGroup[];
24
+ variantId?: string;
25
+ value: readonly ModifierSelection[];
26
+ onChange: (next: ModifierSelection[]) => void;
27
+ formatCents: (cents: number) => string;
28
+ disabled?: boolean;
29
+ }
30
+ /**
31
+ * One write-in on a product's page: a text field named after the group, with
32
+ * the merchant's note, what a filled answer adds and a count of characters
33
+ * under it, or what is wrong with what was typed.
34
+ */
35
+ export declare function ProductWriteInField(props: ProductWriteInFieldProps): import("react").JSX.Element;
15
36
  /** What a group asks for, said under it. */
16
37
  export declare function addOnGroupHint(group: Pick<ProductModifierGroup, 'min' | 'max'>): string;
17
38
  /**
@@ -14,6 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */ 'use client';
17
+ import { _ as _extends } from "@swc/helpers/_/_extends";
17
18
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
19
  import Checkbox from "@mui/material/Checkbox";
19
20
  import FormControl from "@mui/material/FormControl";
@@ -24,7 +25,7 @@ import FormLabel from "@mui/material/FormLabel";
24
25
  import MenuItem from "@mui/material/MenuItem";
25
26
  import Stack from "@mui/material/Stack";
26
27
  import TextField from "@mui/material/TextField";
27
- import { modifierGroupRequired, modifierOptionPriceCents } from "../model/product-modifiers.js";
28
+ import { modifierGroupIsWriteIn, modifierGroupRequired, modifierOptionPriceCents, writeInMaxLength, writeInProblem } from "../model/product-modifiers.js";
28
29
  /** The picks with one group's answer replaced, in the groups' own order. */ export function withGroupAnswer(groups, value, groupId, optionIds) {
29
30
  const others = value.filter((pick)=>pick.groupId !== groupId);
30
31
  const answer = optionIds.map((optionId)=>({
@@ -43,6 +44,70 @@ import { modifierGroupRequired, modifierOptionPriceCents } from "../model/produc
43
44
  return ((_order_get = order.get(a.groupId)) != null ? _order_get : 0) - ((_order_get1 = order.get(b.groupId)) != null ? _order_get1 : 0);
44
45
  });
45
46
  }
47
+ /**
48
+ * The picks with a write-in's answer replaced (write-ins): the
49
+ * text as typed so far, kept while it is being typed; an empty answer leaves
50
+ * the group unanswered. The server cleans and checks it.
51
+ */ export function withWriteInAnswer(groups, value, group, text) {
52
+ const option = group.options[0];
53
+ const others = value.filter((pick)=>pick.groupId !== group.id);
54
+ const answer = option && text.trim() ? [
55
+ {
56
+ groupId: group.id,
57
+ optionId: option.id,
58
+ text
59
+ }
60
+ ] : [];
61
+ const order = new Map(groups.map((entry, index)=>[
62
+ entry.id,
63
+ index
64
+ ]));
65
+ return [
66
+ ...others,
67
+ ...answer
68
+ ].sort((x, y)=>{
69
+ var _order_get, _order_get1;
70
+ return ((_order_get = order.get(x.groupId)) != null ? _order_get : 0) - ((_order_get1 = order.get(y.groupId)) != null ? _order_get1 : 0);
71
+ });
72
+ }
73
+ /**
74
+ * One write-in on a product's page: a text field named after the group, with
75
+ * the merchant's note, what a filled answer adds and a count of characters
76
+ * under it, or what is wrong with what was typed.
77
+ */ export function ProductWriteInField(props) {
78
+ var _ref;
79
+ var _value_find;
80
+ const { group, groups, variantId, value, onChange, formatCents, disabled } = props;
81
+ const option = group.options[0];
82
+ const text = (_ref = (_value_find = value.find((pick)=>pick.groupId === group.id)) == null ? void 0 : _value_find.text) != null ? _ref : '';
83
+ const limit = writeInMaxLength(group);
84
+ const problem = writeInProblem(group, text);
85
+ const cents = option ? modifierOptionPriceCents(option, variantId) : 0;
86
+ const hint = [
87
+ option == null ? void 0 : option.note,
88
+ cents > 0 ? `Adds ${formatCents(cents)}` : null,
89
+ `${Array.from(text).length}/${limit}`
90
+ ].filter(Boolean).join(' · ');
91
+ return /*#__PURE__*/ _jsx(TextField, {
92
+ size: "small",
93
+ fullWidth: true,
94
+ required: modifierGroupRequired(group),
95
+ disabled: disabled,
96
+ label: group.name,
97
+ value: text,
98
+ error: Boolean(problem),
99
+ onChange: (event)=>onChange(withWriteInAnswer(groups, value, group, event.target.value)),
100
+ helperText: problem != null ? problem : hint,
101
+ slotProps: {
102
+ htmlInput: _extends({
103
+ maxLength: limit
104
+ }, group.digitsOnly ? {
105
+ inputMode: 'numeric',
106
+ pattern: '[0-9]*'
107
+ } : {})
108
+ }
109
+ });
110
+ }
46
111
  /** What a group asks for, said under it. */ export function addOnGroupHint(group) {
47
112
  if (group.max === 1) return group.min > 0 ? 'Choose one' : 'Optional';
48
113
  if (group.min > 0 && group.min === group.max) return `Choose ${group.min}`;
@@ -67,6 +132,17 @@ import { modifierGroupRequired, modifierOptionPriceCents } from "../model/produc
67
132
  mb: 1.5
68
133
  },
69
134
  children: groups.map((group)=>{
135
+ if (modifierGroupIsWriteIn(group)) {
136
+ return /*#__PURE__*/ _jsx(ProductWriteInField, {
137
+ group: group,
138
+ groups: groups,
139
+ variantId: variantId,
140
+ value: value,
141
+ onChange: onChange,
142
+ formatCents: formatCents,
143
+ disabled: disabled
144
+ }, group.id);
145
+ }
70
146
  const chosen = value.filter((pick)=>pick.groupId === group.id).map((pick)=>pick.optionId);
71
147
  const required = modifierGroupRequired(group);
72
148
  if (group.max === 1) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-add-ons.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport Checkbox from '@mui/material/Checkbox'\nimport FormControl from '@mui/material/FormControl'\nimport FormControlLabel from '@mui/material/FormControlLabel'\nimport FormGroup from '@mui/material/FormGroup'\nimport FormHelperText from '@mui/material/FormHelperText'\nimport FormLabel from '@mui/material/FormLabel'\nimport MenuItem from '@mui/material/MenuItem'\nimport Stack from '@mui/material/Stack'\nimport TextField from '@mui/material/TextField'\nimport {\n modifierGroupRequired,\n modifierOptionPriceCents,\n type ModifierSelection,\n type ProductModifierGroup,\n type ProductModifierOption,\n} from '../model/product-modifiers'\n\nexport interface ProductAddOnsProps {\n /** The groups the website shows, as the product's page received them. */\n groups: readonly ProductModifierGroup[]\n /** The variant picked: a choice priced by variant shows its price on it. */\n variantId?: string\n value: readonly ModifierSelection[]\n onChange: (next: ModifierSelection[]) => void\n /** The store's money, e.g. `$1,250.00`. */\n formatCents: (cents: number) => string\n disabled?: boolean\n}\n\n/** The picks with one group's answer replaced, in the groups' own order. */\nexport function withGroupAnswer(\n groups: readonly ProductModifierGroup[],\n value: readonly ModifierSelection[],\n groupId: string,\n optionIds: readonly string[],\n): ModifierSelection[] {\n const others = value.filter((pick) => pick.groupId !== groupId)\n const answer = optionIds.map((optionId) => ({ groupId, optionId }))\n const order = new Map(groups.map((group, index) => [group.id, index]))\n return [...others, ...answer].sort(\n (a, b) => (order.get(a.groupId) ?? 0) - (order.get(b.groupId) ?? 0),\n )\n}\n\n/** What a group asks for, said under it. */\nexport function addOnGroupHint(group: Pick<ProductModifierGroup, 'min' | 'max'>): string {\n if (group.max === 1) return group.min > 0 ? 'Choose one' : 'Optional'\n if (group.min > 0 && group.min === group.max) return `Choose ${group.min}`\n if (group.min > 0) return `Choose ${group.min} to ${group.max}`\n return `Choose up to ${group.max}`\n}\n\n/**\n * The add-ons a product's page offers (AGL-4100): a group that takes one\n * choice is a select, one that takes several is a set of checkboxes, each\n * choice with what it adds on the picked variant. A required group is marked\n * as the form builder marks a required field. Its own chunk, loaded only by a\n * product that has add-ons on the website.\n */\nexport function ProductAddOns(props: ProductAddOnsProps) {\n const { groups, variantId, value, onChange, formatCents, disabled } = props\n const priceLabel = (option: ProductModifierOption) => {\n const cents = modifierOptionPriceCents(option, variantId)\n return cents > 0 ? `${option.name} (+${formatCents(cents)})` : option.name\n }\n return (\n <Stack spacing={1.5} sx={{ mb: 1.5 }}>\n {groups.map((group) => {\n const chosen = value\n .filter((pick) => pick.groupId === group.id)\n .map((pick) => pick.optionId)\n const required = modifierGroupRequired(group)\n if (group.max === 1) {\n return (\n <TextField\n key={group.id}\n select\n size=\"small\"\n fullWidth\n required={required}\n disabled={disabled}\n label={group.name}\n value={chosen[0] ?? ''}\n onChange={(event) =>\n onChange(\n withGroupAnswer(\n groups,\n value,\n group.id,\n event.target.value ? [String(event.target.value)] : [],\n ),\n )\n }\n helperText={addOnGroupHint(group)}\n >\n {required ? null : (\n <MenuItem value=\"\">\n <em>{'None'}</em>\n </MenuItem>\n )}\n {group.options.map((option) => (\n <MenuItem key={option.id} value={option.id}>\n {priceLabel(option)}\n </MenuItem>\n ))}\n </TextField>\n )\n }\n const full = chosen.length >= group.max\n return (\n <FormControl\n key={group.id}\n component=\"fieldset\"\n required={required}\n disabled={disabled}\n variant=\"standard\"\n >\n <FormLabel component=\"legend\">{group.name}</FormLabel>\n <FormGroup>\n {group.options.map((option) => {\n const checked = chosen.includes(option.id)\n return (\n <FormControlLabel\n key={option.id}\n control={\n <Checkbox\n size=\"small\"\n checked={checked}\n disabled={disabled || (!checked && full)}\n onChange={(event) =>\n onChange(\n withGroupAnswer(\n groups,\n value,\n group.id,\n event.target.checked\n ? group.options\n .map((entry) => entry.id)\n .filter((id) => id === option.id || chosen.includes(id))\n : chosen.filter((id) => id !== option.id),\n ),\n )\n }\n />\n }\n label={priceLabel(option)}\n />\n )\n })}\n </FormGroup>\n <FormHelperText>{addOnGroupHint(group)}</FormHelperText>\n </FormControl>\n )\n })}\n </Stack>\n )\n}\n\nProductAddOns.displayName = 'ProductAddOns'\n\nexport default ProductAddOns\n"],"names":["Checkbox","FormControl","FormControlLabel","FormGroup","FormHelperText","FormLabel","MenuItem","Stack","TextField","modifierGroupRequired","modifierOptionPriceCents","withGroupAnswer","groups","value","groupId","optionIds","others","filter","pick","answer","map","optionId","order","Map","group","index","id","sort","a","b","get","addOnGroupHint","max","min","ProductAddOns","props","variantId","onChange","formatCents","disabled","priceLabel","option","cents","name","spacing","sx","mb","chosen","required","select","size","fullWidth","label","event","target","String","helperText","em","options","full","length","component","variant","checked","includes","control","entry","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,OAAOA,cAAc,yBAAwB;AAC7C,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,sBAAsB,iCAAgC;AAC7D,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,cAAc,yBAAwB;AAC7C,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,eAAe,0BAAyB;AAC/C,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ER,KAACzD;wBAAUwD,WAAU;kCAAUrC,MAAMmB,IAAI;;kCACzC,KAACxC;kCACEqB,MAAMkC,OAAO,CAACtC,GAAG,CAAC,CAACqB;4BAClB,MAAMsB,UAAUhB,OAAOiB,QAAQ,CAACvB,OAAOf,EAAE;4BACzC,qBACE,KAACxB;gCAEC+D,uBACE,KAACjE;oCACCkD,MAAK;oCACLa,SAASA;oCACTxB,UAAUA,YAAa,CAACwB,WAAWJ;oCACnCtB,UAAU,CAACgB,QACThB,SACE1B,gBACEC,QACAC,OACAW,MAAME,EAAE,EACR2B,MAAMC,MAAM,CAACS,OAAO,GAChBvC,MAAMkC,OAAO,CACVtC,GAAG,CAAC,CAAC8C,QAAUA,MAAMxC,EAAE,EACvBT,MAAM,CAAC,CAACS,KAAOA,OAAOe,OAAOf,EAAE,IAAIqB,OAAOiB,QAAQ,CAACtC,OACtDqB,OAAO9B,MAAM,CAAC,CAACS,KAAOA,OAAOe,OAAOf,EAAE;;gCAMpD0B,OAAOZ,WAAWC;+BAtBbA,OAAOf,EAAE;wBAyBpB;;kCAEF,KAACtB;kCAAgB2B,eAAeP;;;eAvC3BA,MAAME,EAAE;QA0CnB;;AAGN;AAEAQ,cAAciC,WAAW,GAAG;AAE5B,eAAejC,cAAa"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-add-ons.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport Checkbox from '@mui/material/Checkbox'\nimport FormControl from '@mui/material/FormControl'\nimport FormControlLabel from '@mui/material/FormControlLabel'\nimport FormGroup from '@mui/material/FormGroup'\nimport FormHelperText from '@mui/material/FormHelperText'\nimport FormLabel from '@mui/material/FormLabel'\nimport MenuItem from '@mui/material/MenuItem'\nimport Stack from '@mui/material/Stack'\nimport TextField from '@mui/material/TextField'\nimport {\n modifierGroupIsWriteIn,\n modifierGroupRequired,\n modifierOptionPriceCents,\n writeInMaxLength,\n writeInProblem,\n type ModifierSelection,\n type ProductModifierGroup,\n type ProductModifierOption,\n} from '../model/product-modifiers'\n\nexport interface ProductAddOnsProps {\n /** The groups the website shows, as the product's page received them. */\n groups: readonly ProductModifierGroup[]\n /** The variant picked: a choice priced by variant shows its price on it. */\n variantId?: string\n value: readonly ModifierSelection[]\n onChange: (next: ModifierSelection[]) => void\n /** The store's money, e.g. `$1,250.00`. */\n formatCents: (cents: number) => string\n disabled?: boolean\n}\n\n/** The picks with one group's answer replaced, in the groups' own order. */\nexport function withGroupAnswer(\n groups: readonly ProductModifierGroup[],\n value: readonly ModifierSelection[],\n groupId: string,\n optionIds: readonly string[],\n): ModifierSelection[] {\n const others = value.filter((pick) => pick.groupId !== groupId)\n const answer = optionIds.map((optionId) => ({ groupId, optionId }))\n const order = new Map(groups.map((group, index) => [group.id, index]))\n return [...others, ...answer].sort(\n (a, b) => (order.get(a.groupId) ?? 0) - (order.get(b.groupId) ?? 0),\n )\n}\n\n/**\n * The picks with a write-in's answer replaced (write-ins): the\n * text as typed so far, kept while it is being typed; an empty answer leaves\n * the group unanswered. The server cleans and checks it.\n */\nexport function withWriteInAnswer(\n groups: readonly ProductModifierGroup[],\n value: readonly ModifierSelection[],\n group: ProductModifierGroup,\n text: string,\n): ModifierSelection[] {\n const option = group.options[0]\n const others = value.filter((pick) => pick.groupId !== group.id)\n const answer = option && text.trim() ? [{ groupId: group.id, optionId: option.id, text }] : []\n const order = new Map(groups.map((entry, index) => [entry.id, index]))\n return [...others, ...answer].sort((x, y) => (order.get(x.groupId) ?? 0) - (order.get(y.groupId) ?? 0))\n}\n\nexport interface ProductWriteInFieldProps {\n group: ProductModifierGroup\n groups: readonly ProductModifierGroup[]\n variantId?: string\n value: readonly ModifierSelection[]\n onChange: (next: ModifierSelection[]) => void\n formatCents: (cents: number) => string\n disabled?: boolean\n}\n\n/**\n * One write-in on a product's page: a text field named after the group, with\n * the merchant's note, what a filled answer adds and a count of characters\n * under it, or what is wrong with what was typed.\n */\nexport function ProductWriteInField(props: ProductWriteInFieldProps) {\n const { group, groups, variantId, value, onChange, formatCents, disabled } = props\n const option = group.options[0]\n const text = value.find((pick) => pick.groupId === group.id)?.text ?? ''\n const limit = writeInMaxLength(group)\n const problem = writeInProblem(group, text)\n const cents = option ? modifierOptionPriceCents(option, variantId) : 0\n const hint = [option?.note, cents > 0 ? `Adds ${formatCents(cents)}` : null, `${Array.from(text).length}/${limit}`]\n .filter(Boolean)\n .join(' · ')\n return (\n <TextField\n size=\"small\"\n fullWidth\n required={modifierGroupRequired(group)}\n disabled={disabled}\n label={group.name}\n value={text}\n error={Boolean(problem)}\n onChange={(event) => onChange(withWriteInAnswer(groups, value, group, event.target.value))}\n helperText={problem ?? hint}\n slotProps={{\n htmlInput: {\n maxLength: limit,\n ...(group.digitsOnly ? { inputMode: 'numeric', pattern: '[0-9]*' } : {}),\n },\n }}\n />\n )\n}\n\n/** What a group asks for, said under it. */\nexport function addOnGroupHint(group: Pick<ProductModifierGroup, 'min' | 'max'>): string {\n if (group.max === 1) return group.min > 0 ? 'Choose one' : 'Optional'\n if (group.min > 0 && group.min === group.max) return `Choose ${group.min}`\n if (group.min > 0) return `Choose ${group.min} to ${group.max}`\n return `Choose up to ${group.max}`\n}\n\n/**\n * The add-ons a product's page offers (AGL-4100): a group that takes one\n * choice is a select, one that takes several is a set of checkboxes, each\n * choice with what it adds on the picked variant. A required group is marked\n * as the form builder marks a required field. Its own chunk, loaded only by a\n * product that has add-ons on the website.\n */\nexport function ProductAddOns(props: ProductAddOnsProps) {\n const { groups, variantId, value, onChange, formatCents, disabled } = props\n const priceLabel = (option: ProductModifierOption) => {\n const cents = modifierOptionPriceCents(option, variantId)\n return cents > 0 ? `${option.name} (+${formatCents(cents)})` : option.name\n }\n return (\n <Stack spacing={1.5} sx={{ mb: 1.5 }}>\n {groups.map((group) => {\n if (modifierGroupIsWriteIn(group)) {\n return (\n <ProductWriteInField\n key={group.id}\n group={group}\n groups={groups}\n variantId={variantId}\n value={value}\n onChange={onChange}\n formatCents={formatCents}\n disabled={disabled}\n />\n )\n }\n const chosen = value\n .filter((pick) => pick.groupId === group.id)\n .map((pick) => pick.optionId)\n const required = modifierGroupRequired(group)\n if (group.max === 1) {\n return (\n <TextField\n key={group.id}\n select\n size=\"small\"\n fullWidth\n required={required}\n disabled={disabled}\n label={group.name}\n value={chosen[0] ?? ''}\n onChange={(event) =>\n onChange(\n withGroupAnswer(\n groups,\n value,\n group.id,\n event.target.value ? [String(event.target.value)] : [],\n ),\n )\n }\n helperText={addOnGroupHint(group)}\n >\n {required ? null : (\n <MenuItem value=\"\">\n <em>{'None'}</em>\n </MenuItem>\n )}\n {group.options.map((option) => (\n <MenuItem key={option.id} value={option.id}>\n {priceLabel(option)}\n </MenuItem>\n ))}\n </TextField>\n )\n }\n const full = chosen.length >= group.max\n return (\n <FormControl\n key={group.id}\n component=\"fieldset\"\n required={required}\n disabled={disabled}\n variant=\"standard\"\n >\n <FormLabel component=\"legend\">{group.name}</FormLabel>\n <FormGroup>\n {group.options.map((option) => {\n const checked = chosen.includes(option.id)\n return (\n <FormControlLabel\n key={option.id}\n control={\n <Checkbox\n size=\"small\"\n checked={checked}\n disabled={disabled || (!checked && full)}\n onChange={(event) =>\n onChange(\n withGroupAnswer(\n groups,\n value,\n group.id,\n event.target.checked\n ? group.options\n .map((entry) => entry.id)\n .filter((id) => id === option.id || chosen.includes(id))\n : chosen.filter((id) => id !== option.id),\n ),\n )\n }\n />\n }\n label={priceLabel(option)}\n />\n )\n })}\n </FormGroup>\n <FormHelperText>{addOnGroupHint(group)}</FormHelperText>\n </FormControl>\n )\n })}\n </Stack>\n )\n}\n\nProductAddOns.displayName = 'ProductAddOns'\n\nexport default ProductAddOns\n"],"names":["Checkbox","FormControl","FormControlLabel","FormGroup","FormHelperText","FormLabel","MenuItem","Stack","TextField","modifierGroupIsWriteIn","modifierGroupRequired","modifierOptionPriceCents","writeInMaxLength","writeInProblem","withGroupAnswer","groups","value","groupId","optionIds","others","filter","pick","answer","map","optionId","order","Map","group","index","id","sort","a","b","get","withWriteInAnswer","text","option","options","trim","entry","x","y","ProductWriteInField","props","variantId","onChange","formatCents","disabled","find","limit","problem","cents","hint","note","Array","from","length","Boolean","join","size","fullWidth","required","label","name","error","event","target","helperText","slotProps","htmlInput","maxLength","digitsOnly","inputMode","pattern","addOnGroupHint","max","min","ProductAddOns","priceLabel","spacing","sx","mb","chosen","select","String","em","full","component","variant","checked","includes","control","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,OAAOA,cAAc,yBAAwB;AAC7C,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,sBAAsB,iCAAgC;AAC7D,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,cAAc,yBAAwB;AAC7C,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,eAAe,0BAAyB;AAC/C,SACEC,sBAAsB,EACtBC,qBAAqB,EACrBC,wBAAwB,EACxBC,gBAAgB,EAChBC,cAAc,QAIT,gCAA4B;AAcnC,0EAA0E,GAC1E,OAAO,SAASC,gBACdC,MAAuC,EACvCC,KAAmC,EACnCC,OAAe,EACfC,SAA4B;IAE5B,MAAMC,SAASH,MAAMI,MAAM,CAAC,CAACC,OAASA,KAAKJ,OAAO,KAAKA;IACvD,MAAMK,SAASJ,UAAUK,GAAG,CAAC,CAACC,WAAc,CAAA;YAAEP;YAASO;QAAS,CAAA;IAChE,MAAMC,QAAQ,IAAIC,IAAIX,OAAOQ,GAAG,CAA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W,GAAG;AAE5B,eAAef,cAAa"}
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
- import type { ModifierSelection, ProductModifierGroup } from '../model/product-modifiers';
2
+ import { type ModifierSelection, type ProductModifierGroup } from '../model/product-modifiers';
3
3
  import { type ProductBuilderPicks } from './product-builder-context';
4
4
  /** The free-mockup button's words when the site builder typed none. */
5
5
  export declare const MOCKUP_LABEL_DEFAULT = "Get a free mockup";
@@ -22,6 +22,7 @@ import Collapse from "@mui/material/Collapse";
22
22
  import Paper from "@mui/material/Paper";
23
23
  import Typography from "@mui/material/Typography";
24
24
  import { useRef, useState } from "react";
25
+ import { cleanWriteIn, modifierGroupIsWriteIn, modifierLineText } from "../model/product-modifiers.js";
25
26
  import { ProductBuilderContext } from "./product-builder-context.js";
26
27
  /*
27
28
  * THE FREE MOCKUP ON A PRODUCT PAGE (AGL-4205), in its own chunk: only a
@@ -37,10 +38,19 @@ import { ProductBuilderContext } from "./product-builder-context.js";
37
38
  const { product, variant, addOns, quantity, ready, problem, total } = input;
38
39
  const names = [];
39
40
  for (const group of (_product_modifierGroups = product.modifierGroups) != null ? _product_modifierGroups : []){
41
+ const writeIn = modifierGroupIsWriteIn(group);
40
42
  for (const option of group.options){
41
- if (addOns.some((pick)=>pick.groupId === group.id && pick.optionId === option.id)) {
42
- names.push(option.name);
43
- }
43
+ const pick = addOns.find((entry)=>entry.groupId === group.id && entry.optionId === option.id);
44
+ if (!pick) continue;
45
+ // A write-in names its answer ("Engraving: For Sam"), as the order line does.
46
+ const text = writeIn ? cleanWriteIn(pick.text, group) : '';
47
+ if (writeIn && !text) continue;
48
+ names.push(modifierLineText({
49
+ name: option.name,
50
+ group: group.name,
51
+ text,
52
+ nameOnOrder: group.nameOnOrder
53
+ }));
44
54
  }
45
55
  }
46
56
  const options = Object.fromEntries(Object.entries((_ref = variant == null ? void 0 : variant.options) != null ? _ref : {}).filter(([, value])=>Boolean(value)));
@@ -51,10 +61,12 @@ import { ProductBuilderContext } from "./product-builder-context.js";
51
61
  variantId: variant.id
52
62
  } : {}, {
53
63
  options,
54
- modifiers: addOns.map((pick)=>({
64
+ modifiers: addOns.map((pick)=>_extends({
55
65
  groupId: pick.groupId,
56
66
  optionId: pick.optionId
57
- })),
67
+ }, pick.text ? {
68
+ text: pick.text
69
+ } : {})),
58
70
  addOnNames: names,
59
71
  quantity,
60
72
  ready: ready && Boolean(variant)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-builder-mockup.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Collapse from '@mui/material/Collapse'\nimport Paper from '@mui/material/Paper'\nimport Typography from '@mui/material/Typography'\nimport { useRef, useState, type ReactNode } from 'react'\nimport type { ModifierSelection, ProductModifierGroup } from '../model/product-modifiers'\nimport { ProductBuilderContext, type ProductBuilderPicks } from './product-builder-context'\n\n/*\n * THE FREE MOCKUP ON A PRODUCT PAGE (AGL-4205), in its own chunk: only a\n * product that offers one, or the canvas, downloads it. The button opens\n * what the site builder dropped into the Product detail block, a request\n * form whose Product and options field reads the picks from the context.\n */\n\n/** The free-mockup button's words when the site builder typed none. */\nexport const MOCKUP_LABEL_DEFAULT = 'Get a free mockup'\n\n/**\n * The picks a request form in the block reads: ids and words only, and\n * whether every required choice is answered.\n */\nexport function productBuilderPicks(input: {\n product: { id: string; name: string; modifierGroups?: readonly ProductModifierGroup[] }\n variant: { id: string; options?: Record<string, string> } | undefined\n addOns: readonly ModifierSelection[]\n quantity: number\n ready: boolean\n problem?: string\n total?: string\n}): ProductBuilderPicks {\n const { product, variant, addOns, quantity, ready, problem, total } = input\n const names: string[] = []\n for (const group of product.modifierGroups ?? []) {\n for (const option of group.options) {\n if (addOns.some((pick) => pick.groupId === group.id && pick.optionId === option.id)) {\n names.push(option.name)\n }\n }\n }\n const options = Object.fromEntries(\n Object.entries(variant?.options ?? {}).filter(([, value]) => Boolean(value)),\n )\n return {\n productId: product.id,\n productName: product.name,\n ...(variant && variant.id !== 'default' ? { variantId: variant.id } : {}),\n options,\n modifiers: addOns.map((pick) => ({ groupId: pick.groupId, optionId: pick.optionId })),\n addOnNames: names,\n quantity,\n ready: ready && Boolean(variant),\n ...(problem ? { problem } : {}),\n ...(total ? { total } : {}),\n }\n}\n\nexport interface ProductBuilderMockupProps {\n picks: Parameters<typeof productBuilderPicks>[0]\n /** The button's words; the default when blank. */\n label?: string\n /** A priced product's button sits under Buy now; an unpriced one's is the main action. */\n priced: boolean\n /** On the canvas the form stays open, and an empty block says what to drop in. */\n canvas: boolean\n hasRequestForm: boolean\n children?: ReactNode\n}\n\n/** \"Get a free mockup\" and the request form it opens. */\nexport function ProductBuilderMockup(props: ProductBuilderMockupProps) {\n const { picks, label, priced, canvas, hasRequestForm, children } = props\n const [open, setOpen] = useState(false)\n const formRef = useRef<HTMLDivElement>(null)\n const shown = open || canvas\n return (\n <Box sx={{ mb: 2 }}>\n <Button\n variant={priced ? 'text' : 'contained'}\n color=\"primary\"\n size=\"large\"\n aria-expanded={shown}\n onClick={() => {\n setOpen(true)\n // After the form has opened, so it is where the page scrolls to.\n window.setTimeout(() => formRef.current?.scrollIntoView?.({ behavior: 'smooth', block: 'start' }), 50)\n }}\n >\n {label?.trim() || MOCKUP_LABEL_DEFAULT}\n </Button>\n <Collapse in={shown} ref={formRef}>\n <Paper variant=\"outlined\" sx={{ p: 2, mt: 1 }}>\n <ProductBuilderContext.Provider value={productBuilderPicks(picks)}>\n {hasRequestForm ? (\n children\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Drop a request form here: a form with a Product and options field, the ' +\n 'contact fields and a File upload for artwork. It opens with the shopper’s picks.'}\n </Typography>\n )}\n </ProductBuilderContext.Provider>\n </Paper>\n </Collapse>\n </Box>\n )\n}\n\nProductBuilderMockup.displayName = 'ProductBuilderMockup'\n\nexport default ProductBuilderMockup\n"],"names":["Box","Button","Collapse","Paper","Typography","useRef","useState","ProductBuilderContext","MOCKUP_LABEL_DEFAULT","productBuilderPicks","input","product","variant","addOns","quantity","ready","problem","total","names","group","modifierGroups","option","options","some","pick","groupId","id","optionId","push","name","Object","fromEntries","entries","filter","value","Boolean","productId","productName","variantId","modifiers","map","addOnNames","ProductBuilderMockup","props","picks","label","priced","canvas","hasRequestForm","children","open","setOpen","formRef","shown","sx","mb","color","size","aria-expanded","onClick","window","setTimeout","current","scrollIntoView","behavior","block","trim","in","ref","p","mt","Provider","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,OAAOA,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,cAAc,yBAAwB;AAC7C,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,MAAM,EAAEC,QAAQ,QAAwB,QAAO;AAExD,SAASC,qBAAqB,QAAkC,+BAA2B;AAE3F;;;;;CAKC,GAED,qEAAqE,GACrE,OAAO,MAAMC,uBAAuB,oBAAmB;AAEvD;;;CAGC,GACD,OAAO,SAASC,oBAAoBC,KAQnC;QAGqBC;IAFpB,MAAM,EAAEA,OAAO,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,KAAK,EAAE,GAAGP;IACtE,MAAMQ,QAAkB,EAAE;IAC1B,KAAK,MAAMC,UAASR,0BAAAA,QAAQS,cAAc,YAAtBT,0BAA0B,EAAE,CAAE;QAChD,KAAK,MAAMU,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;oBACjES,OAAOC,UAAU,CAAC;4BAAMT,iCAAAA;gCAAAA,mBAAAA,QAAQU,OAAO,sBAAfV,kCAAAA,iBAAiBW,cAAc,qBAA/BX,qCAAAA,kBAAkC;4BAAEY,UAAU;4BAAUC,OAAO;wBAAQ;uBAAI;gBACrG;0BAECpB,CAAAA,yBAAAA,MAAOqB,IAAI,OAAM1D;;0BAEpB,KAACN;gBAASiE,IAAId;gBAAOe,KAAKhB;0BACxB,cAAA,KAACjD;oBAAMS,SAAQ;oBAAW0C,IAAI;wBAAEe,GAAG;wBAAGC,IAAI;oBAAE;8BAC1C,cAAA,KAAC/D,sBAAsBgE,QAAQ;wBAACrC,OAAOzB,oBAAoBmC;kCACxDI,iBACCC,yBAEA,KAAC7C;4BAAWQ,SAAQ;4BAAQ4C,OAAM;sCAC/B,4EACC;;;;;;;AAQlB;AAEAd,qBAAqB8B,WAAW,GAAG;AAEnC,eAAe9B,qBAAoB"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-builder-mockup.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Collapse from '@mui/material/Collapse'\nimport Paper from '@mui/material/Paper'\nimport Typography from '@mui/material/Typography'\nimport { useRef, useState, type ReactNode } from 'react'\nimport {\n cleanWriteIn,\n modifierGroupIsWriteIn,\n modifierLineText,\n type ModifierSelection,\n type ProductModifierGroup,\n} from '../model/product-modifiers'\nimport { ProductBuilderContext, type ProductBuilderPicks } from './product-builder-context'\n\n/*\n * THE FREE MOCKUP ON A PRODUCT PAGE (AGL-4205), in its own chunk: only a\n * product that offers one, or the canvas, downloads it. The button opens\n * what the site builder dropped into the Product detail block, a request\n * form whose Product and options field reads the picks from the context.\n */\n\n/** The free-mockup button's words when the site builder typed none. */\nexport const MOCKUP_LABEL_DEFAULT = 'Get a free mockup'\n\n/**\n * The picks a request form in the block reads: ids and words only, and\n * whether every required choice is answered.\n */\nexport function productBuilderPicks(input: {\n product: { id: string; name: string; modifierGroups?: readonly ProductModifierGroup[] }\n variant: { id: string; options?: Record<string, string> } | undefined\n addOns: readonly ModifierSelection[]\n quantity: number\n ready: boolean\n problem?: string\n total?: string\n}): ProductBuilderPicks {\n const { product, variant, addOns, quantity, ready, problem, total } = input\n const names: string[] = []\n for (const group of product.modifierGroups ?? []) {\n const writeIn = modifierGroupIsWriteIn(group)\n for (const option of group.options) {\n const pick = addOns.find((entry) => entry.groupId === group.id && entry.optionId === option.id)\n if (!pick) continue\n // A write-in names its answer (\"Engraving: For Sam\"), as the order line does.\n const text = writeIn ? cleanWriteIn(pick.text, group) : ''\n if (writeIn && !text) continue\n names.push(modifierLineText({ name: option.name, group: group.name, text, nameOnOrder: group.nameOnOrder }))\n }\n }\n const options = Object.fromEntries(\n Object.entries(variant?.options ?? {}).filter(([, value]) => Boolean(value)),\n )\n return {\n productId: product.id,\n productName: product.name,\n ...(variant && variant.id !== 'default' ? { variantId: variant.id } : {}),\n options,\n modifiers: addOns.map((pick) => ({\n groupId: pick.groupId,\n optionId: pick.optionId,\n ...(pick.text ? { text: pick.text } : {}),\n })),\n addOnNames: names,\n quantity,\n ready: ready && Boolean(variant),\n ...(problem ? { problem } : {}),\n ...(total ? { total } : {}),\n }\n}\n\nexport interface ProductBuilderMockupProps {\n picks: Parameters<typeof productBuilderPicks>[0]\n /** The button's words; the default when blank. */\n label?: string\n /** A priced product's button sits under Buy now; an unpriced one's is the main action. */\n priced: boolean\n /** On the canvas the form stays open, and an empty block says what to drop in. */\n canvas: boolean\n hasRequestForm: boolean\n children?: ReactNode\n}\n\n/** \"Get a free mockup\" and the request form it opens. */\nexport function ProductBuilderMockup(props: ProductBuilderMockupProps) {\n const { picks, label, priced, canvas, hasRequestForm, children } = props\n const [open, setOpen] = useState(false)\n const formRef = useRef<HTMLDivElement>(null)\n const shown = open || canvas\n return (\n <Box sx={{ mb: 2 }}>\n <Button\n variant={priced ? 'text' : 'contained'}\n color=\"primary\"\n size=\"large\"\n aria-expanded={shown}\n onClick={() => {\n setOpen(true)\n // After the form has opened, so it is where the page scrolls to.\n window.setTimeout(() => formRef.current?.scrollIntoView?.({ behavior: 'smooth', block: 'start' }), 50)\n }}\n >\n {label?.trim() || MOCKUP_LABEL_DEFAULT}\n </Button>\n <Collapse in={shown} ref={formRef}>\n <Paper variant=\"outlined\" sx={{ p: 2, mt: 1 }}>\n <ProductBuilderContext.Provider value={productBuilderPicks(picks)}>\n {hasRequestForm ? (\n children\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Drop a request form here: a form with a Product and options field, the ' +\n 'contact fields and a File upload for artwork. It opens with the shopper’s picks.'}\n </Typography>\n )}\n </ProductBuilderContext.Provider>\n </Paper>\n </Collapse>\n </Box>\n )\n}\n\nProductBuilderMockup.displayName = 'ProductBuilderMockup'\n\nexport default ProductBuilderMockup\n"],"names":["Box","Button","Collapse","Paper","Typography","useRef","useState","cleanWriteIn","modifierGroupIsWriteIn","modifierLineText","ProductBuilderContext","MOCKUP_LABEL_DEFAULT","productBuilderPicks","input","product","variant","addOns","quantity","ready","problem","total","names","group","modifierGroups","writeIn","option","options","pick","find","entry","groupId","id","optionId","text","push","name","nameOnOrder","Object","fromEntries","entries","filter","value","Boolean","productId","productName","variantId","modifiers","map","addOnNames","ProductBuilderMockup","props","picks","label","priced","canvas","hasRequestForm","children","open","setOpen","formRef","shown","sx","mb","color","size","aria-expanded","onClick","window","setTimeout","current","scrollIntoView","behavior","block","trim","in","ref","p","mt","Provider","displayName"],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MAAOqB,IAAI,OAAM9D;;0BAEpB,KAACT;gBAASwE,IAAId;gBAAOe,KAAKhB;0BACxB,cAAA,KAACxD;oBAAMY,SAAQ;oBAAW8C,IAAI;wBAAEe,GAAG;wBAAGC,IAAI;oBAAE;8BAC1C,cAAA,KAACnE,sBAAsBoE,QAAQ;wBAACrC,OAAO7B,oBAAoBuC;kCACxDI,iBACCC,yBAEA,KAACpD;4BAAWW,SAAQ;4BAAQgD,OAAM;sCAC/B,4EACC;;;;;;;AAQlB;AAEAd,qBAAqB8B,WAAW,GAAG;AAEnC,eAAe9B,qBAAoB"}
@@ -31,8 +31,8 @@ import ListItemText from "@mui/material/ListItemText";
31
31
  import Stack from "@mui/material/Stack";
32
32
  import Typography from "@mui/material/Typography";
33
33
  import { useId, useState } from "react";
34
- import { modifierGroupRequired, modifierOptionIsCombo, modifierOptionPriceCents } from "../model/product-modifiers.js";
35
- import { addOnGroupHint, withGroupAnswer } from "./product-add-ons.js";
34
+ import { modifierGroupIsWriteIn, modifierGroupRequired, modifierOptionIsCombo, modifierOptionPriceCents } from "../model/product-modifiers.js";
35
+ import { addOnGroupHint, ProductWriteInField, withGroupAnswer } from "./product-add-ons.js";
36
36
  /**
37
37
  * The variant a card for one option value stands for: the one the shopper's
38
38
  * other picks make with this value, else the first that carries the value.
@@ -293,6 +293,18 @@ import { addOnGroupHint, withGroupAnswer } from "./product-add-ons.js";
293
293
  })
294
294
  }, option.name)),
295
295
  groups.map((group)=>{
296
+ // A write-in (write-ins) is a text field among the cards: there is nothing to picture.
297
+ if (modifierGroupIsWriteIn(group)) {
298
+ return /*#__PURE__*/ _jsx(ProductWriteInField, {
299
+ group: group,
300
+ groups: groups,
301
+ variantId: variantId,
302
+ value: value,
303
+ onChange: onChange,
304
+ formatCents: formatCents,
305
+ disabled: disabled
306
+ }, group.id);
307
+ }
296
308
  const chosen = value.filter((pick)=>pick.groupId === group.id).map((pick)=>pick.optionId);
297
309
  return /*#__PURE__*/ _jsx(CardGroup, {
298
310
  label: group.name,