@aglyn/plugins-commerce 1.29.2 → 1.30.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 (54) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/console/pos/pos-item-dialog.component.js +12 -0
  3. package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -1
  4. package/src/lib/components/console/pos-kiosk-page.component.js +3 -5
  5. package/src/lib/components/console/pos-kiosk-page.component.js.map +1 -1
  6. package/src/lib/components/console/product-add-ons-fields.component.d.ts +11 -0
  7. package/src/lib/components/console/product-add-ons-fields.component.js +229 -13
  8. package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
  9. package/src/lib/components/console/products-hub-card.component.js +51 -14
  10. package/src/lib/components/console/products-hub-card.component.js.map +1 -1
  11. package/src/lib/components/console/quote-editor-dialog.component.js +38 -0
  12. package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
  13. package/src/lib/components/product-add-ons.d.ts +21 -0
  14. package/src/lib/components/product-add-ons.js +77 -1
  15. package/src/lib/components/product-add-ons.js.map +1 -1
  16. package/src/lib/components/product-builder-mockup.d.ts +1 -1
  17. package/src/lib/components/product-builder-mockup.js +17 -5
  18. package/src/lib/components/product-builder-mockup.js.map +1 -1
  19. package/src/lib/components/product-choice-cards.js +14 -2
  20. package/src/lib/components/product-choice-cards.js.map +1 -1
  21. package/src/lib/model/commerce-pos-kiosk.js +8 -2
  22. package/src/lib/model/commerce-pos-kiosk.js.map +1 -1
  23. package/src/lib/model/commerce-pos-offline.d.ts +1 -1
  24. package/src/lib/model/commerce-pos-offline.js +8 -2
  25. package/src/lib/model/commerce-pos-offline.js.map +1 -1
  26. package/src/lib/model/commerce-quote-request.d.ts +1 -0
  27. package/src/lib/model/commerce-quote-request.js +6 -2
  28. package/src/lib/model/commerce-quote-request.js.map +1 -1
  29. package/src/lib/model/commerce-quotes.js +10 -5
  30. package/src/lib/model/commerce-quotes.js.map +1 -1
  31. package/src/lib/model/commerce-record-routes.d.ts +13 -1
  32. package/src/lib/model/commerce-record-routes.js +22 -2
  33. package/src/lib/model/commerce-record-routes.js.map +1 -1
  34. package/src/lib/model/commerce.js +1 -1
  35. package/src/lib/model/commerce.js.map +1 -1
  36. package/src/lib/model/product-modifiers.d.ts +53 -2
  37. package/src/lib/model/product-modifiers.js +127 -27
  38. package/src/lib/model/product-modifiers.js.map +1 -1
  39. package/src/lib/plan-entitlements.d.ts +1 -2
  40. package/src/lib/plan-entitlements.js +3 -12
  41. package/src/lib/plan-entitlements.js.map +1 -1
  42. package/src/lib/server/pos-kiosk.js +1 -4
  43. package/src/lib/server/pos-kiosk.js.map +1 -1
  44. package/src/lib/server/product.d.ts +5 -0
  45. package/src/lib/server/product.js +10 -2
  46. package/src/lib/server/product.js.map +1 -1
  47. package/src/lib/server/site-page-resolver.d.ts +12 -1
  48. package/src/lib/server/site-page-resolver.js +100 -9
  49. package/src/lib/server/site-page-resolver.js.map +1 -1
  50. package/src/lib/server.js +4 -2
  51. package/src/lib/server.js.map +1 -1
  52. package/src/lib/transfer/product-register-cells.d.ts +7 -0
  53. package/src/lib/transfer/product-register-cells.js +88 -10
  54. package/src/lib/transfer/product-register-cells.js.map +1 -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,SACEC,qBAAqB,EACrBC,wBAAwB,QAInB,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,CAAC,CAACI,OAAOC,QAAU;YAACD,MAAME,EAAE;YAAED;SAAM;IACpE,OAAO;WAAIT;WAAWG;KAAO,CAACQ,IAAI,CAChC,CAACC,GAAGC;YAAOP,YAA8BA;eAA/B,EAACA,aAAAA,MAAMQ,GAAG,CAACF,EAAEd,OAAO,aAAnBQ,aAAwB,OAAMA,cAAAA,MAAMQ,GAAG,CAACD,EAAEf,OAAO,aAAnBQ,cAAwB;;AAErE;AAEA,0CAA0C,GAC1C,OAAO,SAASS,eAAeP,KAAgD;IAC7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ACtB;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,OA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CAECyF,uBACE,KAAC3F;oCACC2D,MAAK;oCACL8B,SAASA;oCACT1C,UAAUA,YAAa,CAAC0C,WAAWH;oCACnCzC,UAAU,CAACoB,QACTpB,SACE/B,gBACEC,QACAC,OACAW,MAAME,EAAE,EACRoC,MAAMC,MAAM,CAACuB,OAAO,GAChB9D,MAAMU,OAAO,CACVd,GAAG,CAAC,CAACgB,QAAUA,MAAMV,EAAE,EACvBT,MAAM,CAAC,CAACS,KAAOA,OAAOO,OAAOP,EAAE,IAAIqD,OAAOQ,QAAQ,CAAC7D,OACtDqD,OAAO9D,MAAM,CAAC,CAACS,KAAOA,OAAOO,OAAOP,EAAE;;gCAMpDiC,OAAOgB,WAAW1C;+BAtBbA,OAAOP,EAAE;wBAyBpB;;kCAEF,KAACzB;kCAAgBsE,eAAe/C;;;eAvC3BA,MAAME,EAAE;QA0CnB;;AAGN;AAEAgD,cAAce,WAAW,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,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;QACAC,OAAOA,SAASoB,QAAQvB;OACpBI,UAAU;QAAEA;IAAQ,IAAI,CAAC,GACzBC,QAAQ;QAAEA;IAAM,IAAI,CAAC;AAE7B;AAcA,uDAAuD,GACvD,OAAO,SAASyB,qBAAqBC,KAAgC;IACnE,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,cAAc,EAAEC,QAAQ,EAAE,GAAGN;IACnE,MAAM,CAACO,MAAMC,QAAQ,GAAG7C,SAAS;IACjC,MAAM8C,UAAU/C,OAAuB;IACvC,MAAMgD,QAAQH,QAAQH;IACtB,qBACE,MAAC/C;QAAIsD,IAAI;YAAEC,IAAI;QAAE;;0BACf,KAACtD;gBACCW,SAASkC,SAAS,SAAS;gBAC3BU,OAAM;gBACNC,MAAK;gBACLC,iBAAeL;gBACfM,SAAS;oBACPR,QAAQ;oBACR,iEAAiE;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"],"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;AACxD,SACEC,YAAY,EACZC,sBAAsB,EACtBC,gBAAgB,QAGX,gCAA4B;AACnC,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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EC,MAAM,EAAEC,MAAM,EAAEC,cAAc,EAAEC,QAAQ,EAAE,GAAGN;IACnE,MAAM,CAACO,MAAMC,QAAQ,GAAGpD,SAAS;IACjC,MAAMqD,UAAUtD,OAAuB;IACvC,MAAMuD,QAAQH,QAAQH;IACtB,qBACE,MAACtD;QAAI6D,IAAI;YAAEC,IAAI;QAAE;;0BACf,KAAC7D;gBACCc,SAASsC,SAAS,SAAS;gBAC3BU,OAAM;gBACNC,MAAK;gBACLC,iBAAeL;gBACfM,SAAS;oBACPR,QAAQ;oBACR,iEAAiE;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,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,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-choice-cards.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 Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Card from '@mui/material/Card'\nimport CardActionArea from '@mui/material/CardActionArea'\nimport CardContent from '@mui/material/CardContent'\nimport CardMedia from '@mui/material/CardMedia'\nimport Chip from '@mui/material/Chip'\nimport Collapse from '@mui/material/Collapse'\nimport List from '@mui/material/List'\nimport ListItem from '@mui/material/ListItem'\nimport ListItemText from '@mui/material/ListItemText'\nimport Stack from '@mui/material/Stack'\nimport Typography from '@mui/material/Typography'\nimport { useId, useState, type ReactNode } from 'react'\nimport {\n modifierGroupRequired,\n modifierOptionIsCombo,\n modifierOptionPriceCents,\n type ModifierSelection,\n type ProductModifierGroup,\n type ProductModifierOption,\n} from '../model/product-modifiers'\nimport { addOnGroupHint, withGroupAnswer } from './product-add-ons'\n\n/*\n * THE PRODUCT BUILDER'S PICTURE CARDS (AGL-4205).\n *\n * A Product detail block set to show its choices as picture cards draws each\n * of the product's options (size, style) and each of its add-on groups as a\n * row of cards: the choice's picture, its name, what it costs, and the\n * owner's short note. A combo's card folds out what it includes. A group\n * that takes one choice behaves as radio buttons, one that takes several as\n * check boxes up to its maximum, and a required group is marked and cannot\n * be emptied. Its own chunk: only a page that shows cards downloads it.\n */\n\n/** A variant as the cards read it. */\nexport interface CardVariant {\n id: string\n options?: Record<string, string>\n priceUsd: number | null\n soldOut?: boolean\n imageUrl?: string\n note?: string\n}\n\n/**\n * The variant a card for one option value stands for: the one the shopper's\n * other picks make with this value, else the first that carries the value.\n */\nexport function variantForOptionValue<V extends CardVariant>(\n variants: readonly V[],\n selections: Readonly<Record<string, string>>,\n optionName: string,\n value: string,\n): V | undefined {\n const wanted = { ...selections, [optionName]: value }\n return (\n variants.find((variant) =>\n Object.entries(wanted).every(([name, picked]) => (variant.options?.[name] ?? picked) === picked),\n ) ?? variants.find((variant) => variant.options?.[optionName] === value)\n )\n}\n\n/**\n * A group's answer after a card is pressed. One-choice groups act as radio\n * buttons (an optional one can be cleared by pressing its pick again); a\n * several-choice group adds or removes the choice, never past its maximum.\n * The answer keeps the group's own order.\n */\nexport function pressChoice(\n group: Pick<ProductModifierGroup, 'min' | 'max' | 'options'>,\n chosen: readonly string[],\n optionId: string,\n): string[] {\n const picked = chosen.includes(optionId)\n if (group.max === 1) {\n if (picked) return group.min > 0 ? [...chosen] : []\n return [optionId]\n }\n if (picked) return chosen.filter((id) => id !== optionId)\n if (chosen.length >= group.max) return [...chosen]\n return group.options.map((option) => option.id).filter((id) => id === optionId || chosen.includes(id))\n}\n\n/** What a card says a choice adds: its price, or that it adds nothing. */\nexport function addOnPriceLabel(cents: number, formatCents: (cents: number) => string): string {\n return cents > 0 ? `+${formatCents(cents)}` : 'No extra charge'\n}\n\ninterface ChoiceCardProps {\n name: string\n price: string\n note?: string\n imageUrl?: string\n selected: boolean\n disabled?: boolean\n role: 'radio' | 'checkbox'\n onPress: () => void\n badge?: ReactNode\n includes?: readonly string[]\n}\n\n/** One card: picture, name, price and note, pressed to pick; a combo's contents fold out below. */\nfunction ChoiceCard(props: ChoiceCardProps) {\n const { name, price, note, imageUrl, selected, disabled, role, onPress, badge, includes } = props\n const { hostId } = Aglyn.useSite()\n const [open, setOpen] = useState(false)\n const contentsId = useId()\n const src = imageUrl ? Aglyn.siteRelativeMediaSrc(imageUrl, { hostId }) : undefined\n return (\n <Card\n variant=\"outlined\"\n sx={{\n display: 'flex',\n flexDirection: 'column',\n borderWidth: 2,\n borderColor: selected ? 'primary.main' : 'divider',\n bgcolor: selected ? 'action.selected' : 'background.paper',\n opacity: disabled && !selected ? 0.6 : 1,\n }}\n >\n <CardActionArea\n role={role}\n aria-checked={selected}\n disabled={disabled}\n onClick={onPress}\n sx={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'stretch' }}\n >\n {src ? (\n <CardMedia\n component=\"img\"\n image={src}\n alt=\"\"\n sx={{ aspectRatio: '4 / 3', objectFit: 'cover' }}\n {...Aglyn.DEFERRED_IMAGE_ATTRIBUTES}\n />\n ) : null}\n <CardContent sx={{ flex: 1, p: 1.5, '&:last-child': { pb: 1.5 } }}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'flex-start', justifyContent: 'space-between' }}>\n <Typography variant=\"subtitle2\" component=\"span\">\n {name}\n </Typography>\n {badge}\n </Stack>\n <Typography variant=\"body2\" color={selected ? 'primary' : 'text.primary'} sx={{ fontWeight: 600 }}>\n {price}\n </Typography>\n {note ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {note}\n </Typography>\n ) : null}\n </CardContent>\n </CardActionArea>\n {includes?.length ? (\n <Box sx={{ px: 1, pb: 1 }}>\n <Button\n size=\"small\"\n aria-expanded={open}\n aria-controls={contentsId}\n onClick={() => setOpen((was) => !was)}\n >\n {open ? 'Hide what’s included' : 'What’s included'}\n </Button>\n <Collapse in={open} id={contentsId}>\n <List dense disablePadding aria-label={`${name} includes`}>\n {includes.map((item) => (\n <ListItem key={item} disableGutters sx={{ py: 0 }}>\n <ListItemText primary={item} slotProps={{ primary: { variant: 'body2' } }} />\n </ListItem>\n ))}\n </List>\n </Collapse>\n </Box>\n ) : null}\n </Card>\n )\n}\n\n/** A heading, its hint, and the grid of cards under it. */\nfunction CardGroup(props: {\n label: string\n hint: string\n required: boolean\n role: 'radiogroup' | 'group'\n children: ReactNode\n}) {\n const { label, hint, required, role, children } = props\n const labelId = useId()\n return (\n <Box component=\"section\" aria-labelledby={labelId}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', mb: 1 }}>\n <Typography id={labelId} variant=\"subtitle1\" component=\"h2\">\n {label}\n </Typography>\n <Chip\n size=\"small\"\n variant=\"outlined\"\n color={required ? 'primary' : 'default'}\n label={hint}\n />\n </Stack>\n <Box\n role={role}\n aria-labelledby={labelId}\n aria-required={required || undefined}\n sx={{\n display: 'grid',\n gridTemplateColumns: (theme) => `repeat(auto-fill, minmax(${theme.spacing(19)}, 1fr))`,\n gap: 1.5,\n }}\n >\n {children}\n </Box>\n </Box>\n )\n}\n\nexport interface ProductChoiceCardsProps {\n /** The options the shopper chooses among (size, style), with their values. */\n options: ReadonlyArray<{ name: string; values: readonly string[] }>\n variants: readonly CardVariant[]\n selections: Readonly<Record<string, string>>\n onSelect: (optionName: string, value: string) => void\n /** The add-on groups the website offers; empty draws none. */\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 /** What a card says where a variant has no price yet. */\n unpricedLabel: string\n disabled?: boolean\n}\n\n/** The product's options and add-ons as picture cards (AGL-4205). */\nexport function ProductChoiceCards(props: ProductChoiceCardsProps) {\n const {\n options,\n variants,\n selections,\n onSelect,\n groups,\n variantId,\n value,\n onChange,\n formatCents,\n unpricedLabel,\n disabled,\n } = props\n const addOnCard = (group: ProductModifierGroup, option: ProductModifierOption, chosen: string[]) => {\n const selected = chosen.includes(option.id)\n const full = group.max > 1 && chosen.length >= group.max\n return (\n <ChoiceCard\n key={option.id}\n name={option.name}\n price={addOnPriceLabel(modifierOptionPriceCents(option, variantId), formatCents)}\n note={option.note}\n imageUrl={option.imageUrl}\n selected={selected}\n disabled={disabled || (!selected && full)}\n role={group.max === 1 ? 'radio' : 'checkbox'}\n badge={modifierOptionIsCombo(option) ? <Chip size=\"small\" color=\"secondary\" label=\"Combo\" /> : null}\n includes={modifierOptionIsCombo(option) ? option.includes : undefined}\n onPress={() => onChange(withGroupAnswer(groups, value, group.id, pressChoice(group, chosen, option.id)))}\n />\n )\n }\n return (\n <Stack spacing={3} sx={{ mb: 2 }}>\n {options.map((option) => (\n <CardGroup key={option.name} label={option.name} hint=\"Choose one\" required role=\"radiogroup\">\n {option.values.map((choice) => {\n const variant = variantForOptionValue(variants, selections, option.name, choice)\n return (\n <ChoiceCard\n key={choice}\n name={choice}\n price={\n typeof variant?.priceUsd === 'number'\n ? formatCents(Math.round(variant.priceUsd * 100))\n : unpricedLabel\n }\n note={variant?.note}\n imageUrl={variant?.imageUrl}\n selected={selections[option.name] === choice}\n role=\"radio\"\n badge={variant?.soldOut ? <Chip size=\"small\" variant=\"outlined\" label=\"Sold out\" /> : null}\n onPress={() => onSelect(option.name, choice)}\n />\n )\n })}\n </CardGroup>\n ))}\n {groups.map((group) => {\n const chosen = value.filter((pick) => pick.groupId === group.id).map((pick) => pick.optionId)\n return (\n <CardGroup\n key={group.id}\n label={group.name}\n hint={addOnGroupHint(group)}\n required={modifierGroupRequired(group)}\n role={group.max === 1 ? 'radiogroup' : 'group'}\n >\n {group.options.map((option) => addOnCard(group, option, chosen))}\n </CardGroup>\n )\n })}\n </Stack>\n )\n}\n\nProductChoiceCards.displayName = 'ProductChoiceCards'\n\nexport default ProductChoiceCards\n"],"names":["Aglyn","Box","Button","Card","CardActionArea","CardContent","CardMedia","Chip","Collapse","List","ListItem","ListItemText","Stack","Typography","useId","useState","modifierGroupRequired","modifierOptionIsCombo","modifierOptionPriceCents","addOnGroupHint","withGroupAnswer","variantForOptionValue","variants","selections","optionName","value","wanted","find","variant","Object","entries","every","name","picked","options","pressChoice","group","chosen","optionId","includes","max","min","filter","id","length","map","option","addOnPriceLabel","cents","formatCents","ChoiceCard","props","price","note","imageUrl","selected","disabled","role","onPress","badge","hostId","useSite","open","setOpen","contentsId","src","siteRelativeMediaSrc","undefined","sx","display","flexDirection","borderWidth","borderColor","bgcolor","opacity","aria-checked","onClick","flex","alignItems","component","image","alt","aspectRatio","objectFit","DEFERRED_IMAGE_ATTRIBUTES","p","pb","direction","spacing","justifyContent","color","fontWeight","px","size","aria-expanded","aria-controls","was","in","dense","disablePadding","aria-label","item","disableGutters","py","primary","slotProps","CardGroup","label","hint","required","children","labelId","aria-labelledby","mb","aria-required","gridTemplateColumns","theme","gap","ProductChoiceCards","onSelect","groups","variantId","onChange","unpricedLabel","addOnCard","full","values","choice","priceUsd","Math","round","soldOut","pick","groupId","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AACrC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,UAAU,qBAAoB;AACrC,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,UAAU,qBAAoB;AAC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G,CAAC,CAACuF,OAASA,KAAK9F,QAAQ;gBAC5F,qBACE,KAACoE;oBAECC,OAAOvE,MAAMJ,IAAI;oBACjB4E,MAAMzF,eAAeiB;oBACrByE,UAAU7F,sBAAsBoB;oBAChCqB,MAAMrB,MAAMI,GAAG,KAAK,IAAI,eAAe;8BAEtCJ,MAAMF,OAAO,CAACW,GAAG,CAAC,CAACC,SAAW8E,UAAUxF,OAAOU,QAAQT;mBANnDD,MAAMO,EAAE;YASnB;;;AAGN;AAEA2E,mBAAmBgB,WAAW,GAAG;AAEjC,eAAehB,mBAAkB"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-choice-cards.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 Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Card from '@mui/material/Card'\nimport CardActionArea from '@mui/material/CardActionArea'\nimport CardContent from '@mui/material/CardContent'\nimport CardMedia from '@mui/material/CardMedia'\nimport Chip from '@mui/material/Chip'\nimport Collapse from '@mui/material/Collapse'\nimport List from '@mui/material/List'\nimport ListItem from '@mui/material/ListItem'\nimport ListItemText from '@mui/material/ListItemText'\nimport Stack from '@mui/material/Stack'\nimport Typography from '@mui/material/Typography'\nimport { useId, useState, type ReactNode } from 'react'\nimport {\n modifierGroupIsWriteIn,\n modifierGroupRequired,\n modifierOptionIsCombo,\n modifierOptionPriceCents,\n type ModifierSelection,\n type ProductModifierGroup,\n type ProductModifierOption,\n} from '../model/product-modifiers'\nimport { addOnGroupHint, ProductWriteInField, withGroupAnswer } from './product-add-ons'\n\n/*\n * THE PRODUCT BUILDER'S PICTURE CARDS (AGL-4205).\n *\n * A Product detail block set to show its choices as picture cards draws each\n * of the product's options (size, style) and each of its add-on groups as a\n * row of cards: the choice's picture, its name, what it costs, and the\n * owner's short note. A combo's card folds out what it includes. A group\n * that takes one choice behaves as radio buttons, one that takes several as\n * check boxes up to its maximum, and a required group is marked and cannot\n * be emptied. Its own chunk: only a page that shows cards downloads it.\n */\n\n/** A variant as the cards read it. */\nexport interface CardVariant {\n id: string\n options?: Record<string, string>\n priceUsd: number | null\n soldOut?: boolean\n imageUrl?: string\n note?: string\n}\n\n/**\n * The variant a card for one option value stands for: the one the shopper's\n * other picks make with this value, else the first that carries the value.\n */\nexport function variantForOptionValue<V extends CardVariant>(\n variants: readonly V[],\n selections: Readonly<Record<string, string>>,\n optionName: string,\n value: string,\n): V | undefined {\n const wanted = { ...selections, [optionName]: value }\n return (\n variants.find((variant) =>\n Object.entries(wanted).every(([name, picked]) => (variant.options?.[name] ?? picked) === picked),\n ) ?? variants.find((variant) => variant.options?.[optionName] === value)\n )\n}\n\n/**\n * A group's answer after a card is pressed. One-choice groups act as radio\n * buttons (an optional one can be cleared by pressing its pick again); a\n * several-choice group adds or removes the choice, never past its maximum.\n * The answer keeps the group's own order.\n */\nexport function pressChoice(\n group: Pick<ProductModifierGroup, 'min' | 'max' | 'options'>,\n chosen: readonly string[],\n optionId: string,\n): string[] {\n const picked = chosen.includes(optionId)\n if (group.max === 1) {\n if (picked) return group.min > 0 ? [...chosen] : []\n return [optionId]\n }\n if (picked) return chosen.filter((id) => id !== optionId)\n if (chosen.length >= group.max) return [...chosen]\n return group.options.map((option) => option.id).filter((id) => id === optionId || chosen.includes(id))\n}\n\n/** What a card says a choice adds: its price, or that it adds nothing. */\nexport function addOnPriceLabel(cents: number, formatCents: (cents: number) => string): string {\n return cents > 0 ? `+${formatCents(cents)}` : 'No extra charge'\n}\n\ninterface ChoiceCardProps {\n name: string\n price: string\n note?: string\n imageUrl?: string\n selected: boolean\n disabled?: boolean\n role: 'radio' | 'checkbox'\n onPress: () => void\n badge?: ReactNode\n includes?: readonly string[]\n}\n\n/** One card: picture, name, price and note, pressed to pick; a combo's contents fold out below. */\nfunction ChoiceCard(props: ChoiceCardProps) {\n const { name, price, note, imageUrl, selected, disabled, role, onPress, badge, includes } = props\n const { hostId } = Aglyn.useSite()\n const [open, setOpen] = useState(false)\n const contentsId = useId()\n const src = imageUrl ? Aglyn.siteRelativeMediaSrc(imageUrl, { hostId }) : undefined\n return (\n <Card\n variant=\"outlined\"\n sx={{\n display: 'flex',\n flexDirection: 'column',\n borderWidth: 2,\n borderColor: selected ? 'primary.main' : 'divider',\n bgcolor: selected ? 'action.selected' : 'background.paper',\n opacity: disabled && !selected ? 0.6 : 1,\n }}\n >\n <CardActionArea\n role={role}\n aria-checked={selected}\n disabled={disabled}\n onClick={onPress}\n sx={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'stretch' }}\n >\n {src ? (\n <CardMedia\n component=\"img\"\n image={src}\n alt=\"\"\n sx={{ aspectRatio: '4 / 3', objectFit: 'cover' }}\n {...Aglyn.DEFERRED_IMAGE_ATTRIBUTES}\n />\n ) : null}\n <CardContent sx={{ flex: 1, p: 1.5, '&:last-child': { pb: 1.5 } }}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'flex-start', justifyContent: 'space-between' }}>\n <Typography variant=\"subtitle2\" component=\"span\">\n {name}\n </Typography>\n {badge}\n </Stack>\n <Typography variant=\"body2\" color={selected ? 'primary' : 'text.primary'} sx={{ fontWeight: 600 }}>\n {price}\n </Typography>\n {note ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {note}\n </Typography>\n ) : null}\n </CardContent>\n </CardActionArea>\n {includes?.length ? (\n <Box sx={{ px: 1, pb: 1 }}>\n <Button\n size=\"small\"\n aria-expanded={open}\n aria-controls={contentsId}\n onClick={() => setOpen((was) => !was)}\n >\n {open ? 'Hide what’s included' : 'What’s included'}\n </Button>\n <Collapse in={open} id={contentsId}>\n <List dense disablePadding aria-label={`${name} includes`}>\n {includes.map((item) => (\n <ListItem key={item} disableGutters sx={{ py: 0 }}>\n <ListItemText primary={item} slotProps={{ primary: { variant: 'body2' } }} />\n </ListItem>\n ))}\n </List>\n </Collapse>\n </Box>\n ) : null}\n </Card>\n )\n}\n\n/** A heading, its hint, and the grid of cards under it. */\nfunction CardGroup(props: {\n label: string\n hint: string\n required: boolean\n role: 'radiogroup' | 'group'\n children: ReactNode\n}) {\n const { label, hint, required, role, children } = props\n const labelId = useId()\n return (\n <Box component=\"section\" aria-labelledby={labelId}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', mb: 1 }}>\n <Typography id={labelId} variant=\"subtitle1\" component=\"h2\">\n {label}\n </Typography>\n <Chip\n size=\"small\"\n variant=\"outlined\"\n color={required ? 'primary' : 'default'}\n label={hint}\n />\n </Stack>\n <Box\n role={role}\n aria-labelledby={labelId}\n aria-required={required || undefined}\n sx={{\n display: 'grid',\n gridTemplateColumns: (theme) => `repeat(auto-fill, minmax(${theme.spacing(19)}, 1fr))`,\n gap: 1.5,\n }}\n >\n {children}\n </Box>\n </Box>\n )\n}\n\nexport interface ProductChoiceCardsProps {\n /** The options the shopper chooses among (size, style), with their values. */\n options: ReadonlyArray<{ name: string; values: readonly string[] }>\n variants: readonly CardVariant[]\n selections: Readonly<Record<string, string>>\n onSelect: (optionName: string, value: string) => void\n /** The add-on groups the website offers; empty draws none. */\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 /** What a card says where a variant has no price yet. */\n unpricedLabel: string\n disabled?: boolean\n}\n\n/** The product's options and add-ons as picture cards (AGL-4205). */\nexport function ProductChoiceCards(props: ProductChoiceCardsProps) {\n const {\n options,\n variants,\n selections,\n onSelect,\n groups,\n variantId,\n value,\n onChange,\n formatCents,\n unpricedLabel,\n disabled,\n } = props\n const addOnCard = (group: ProductModifierGroup, option: ProductModifierOption, chosen: string[]) => {\n const selected = chosen.includes(option.id)\n const full = group.max > 1 && chosen.length >= group.max\n return (\n <ChoiceCard\n key={option.id}\n name={option.name}\n price={addOnPriceLabel(modifierOptionPriceCents(option, variantId), formatCents)}\n note={option.note}\n imageUrl={option.imageUrl}\n selected={selected}\n disabled={disabled || (!selected && full)}\n role={group.max === 1 ? 'radio' : 'checkbox'}\n badge={modifierOptionIsCombo(option) ? <Chip size=\"small\" color=\"secondary\" label=\"Combo\" /> : null}\n includes={modifierOptionIsCombo(option) ? option.includes : undefined}\n onPress={() => onChange(withGroupAnswer(groups, value, group.id, pressChoice(group, chosen, option.id)))}\n />\n )\n }\n return (\n <Stack spacing={3} sx={{ mb: 2 }}>\n {options.map((option) => (\n <CardGroup key={option.name} label={option.name} hint=\"Choose one\" required role=\"radiogroup\">\n {option.values.map((choice) => {\n const variant = variantForOptionValue(variants, selections, option.name, choice)\n return (\n <ChoiceCard\n key={choice}\n name={choice}\n price={\n typeof variant?.priceUsd === 'number'\n ? formatCents(Math.round(variant.priceUsd * 100))\n : unpricedLabel\n }\n note={variant?.note}\n imageUrl={variant?.imageUrl}\n selected={selections[option.name] === choice}\n role=\"radio\"\n badge={variant?.soldOut ? <Chip size=\"small\" variant=\"outlined\" label=\"Sold out\" /> : null}\n onPress={() => onSelect(option.name, choice)}\n />\n )\n })}\n </CardGroup>\n ))}\n {groups.map((group) => {\n // A write-in (write-ins) is a text field among the cards: there is nothing to picture.\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.filter((pick) => pick.groupId === group.id).map((pick) => pick.optionId)\n return (\n <CardGroup\n key={group.id}\n label={group.name}\n hint={addOnGroupHint(group)}\n required={modifierGroupRequired(group)}\n role={group.max === 1 ? 'radiogroup' : 'group'}\n >\n {group.options.map((option) => addOnCard(group, option, chosen))}\n </CardGroup>\n )\n })}\n </Stack>\n )\n}\n\nProductChoiceCards.displayName = 'ProductChoiceCards'\n\nexport default ProductChoiceCards\n"],"names":["Aglyn","Box","Button","Card","CardActionArea","CardContent","CardMedia","Chip","Collapse","List","ListItem","ListItemText","Stack","Typography","useId","useState","modifierGroupIsWriteIn","modifierGroupRequired","modifierOptionIsCombo","modifierOptionPriceCents","addOnGroupHint","ProductWriteInField","withGroupAnswer","variantForOptionValue","variants","selections","optionName","value","wanted","find","variant","Object","entries","every","name","picked","options","pressChoice","group","chosen","optionId","includes","max","min","filter","id","length","map","option","addOnPriceLabel","cents","formatCents","ChoiceCard","props","price","note","imageUrl","selected","disabled","role","onPress","badge","hostId","useSite","open","setOpen","contentsId","src","siteRelativeMediaSrc","undefined","sx","display","flexDirection","borderWidth","borderColor","bgcolor","opacity","aria-checked","onClick","flex","alignItems","component","image","alt","aspectRatio","objectFit","DEFERRED_IMAGE_ATTRIBUTES","p","pb","direction","spacing","justifyContent","color","fontWeight","px","size","aria-expanded","aria-controls","was","in","dense","disablePadding","aria-label","item","disableGutters","py","primary","slotProps","CardGroup","label","hint","required","children","labelId","aria-labelledby","mb","aria-required","gridTemplateColumns","theme","gap","ProductChoiceCards","onSelect","groups","variantId","onChange","unpricedLabel","addOnCard","full","values","choice","priceUsd","Math","round","soldOut","pick","groupId","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AACrC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,UAAU,qBAAoB;AACrC,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,UAA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,qBACE,KAACjB;wBAECiB,OAAOA;wBACPoF,QAAQA;wBACRC,WAAWA;wBACXhG,OAAOA;wBACPiG,UAAUA;wBACVzE,aAAaA;wBACbO,UAAUA;uBAPLpB,MAAMO,EAAE;gBAUnB;gBACA,MAAMN,SAASZ,MAAMiB,MAAM,CAAC,CAAC0F,OAASA,KAAKC,OAAO,KAAKjG,MAAMO,EAAE,EAAEE,GAAG,CAAC,CAACuF,OAASA,KAAK9F,QAAQ;gBAC5F,qBACE,KAACoE;oBAECC,OAAOvE,MAAMJ,IAAI;oBACjB4E,MAAM1F,eAAekB;oBACrByE,UAAU9F,sBAAsBqB;oBAChCqB,MAAMrB,MAAMI,GAAG,KAAK,IAAI,eAAe;8BAEtCJ,MAAMF,OAAO,CAACW,GAAG,CAAC,CAACC,SAAW8E,UAAUxF,OAAOU,QAAQT;mBANnDD,MAAMO,EAAE;YASnB;;;AAGN;AAEA2E,mBAAmBgB,WAAW,GAAG;AAEjC,eAAehB,mBAAkB"}
@@ -15,7 +15,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */ import { posTipFromPercent, posTipProblem } from "./commerce-pos.js";
18
- import { modifierOptionPriceCents } from "./product-modifiers.js";
18
+ import { cleanWriteIn, modifierOptionPriceCents } from "./product-modifiers.js";
19
19
  /** Seconds without a touch before the kiosk asks "Still there?", by default. */ export const POS_KIOSK_IDLE_SECONDS_DEFAULT = 90;
20
20
  export const POS_KIOSK_IDLE_SECONDS_MIN = 30;
21
21
  export const POS_KIOSK_IDLE_SECONDS_MAX = 600;
@@ -78,7 +78,13 @@ const ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
78
78
  error: 'A choice on an item is no longer offered.'
79
79
  };
80
80
  }
81
- modifiers.push({
81
+ // A write-in's answer (write-ins), checked against its group when the order is priced.
82
+ const text = cleanWriteIn(pick == null ? void 0 : pick['text']);
83
+ modifiers.push(text ? {
84
+ groupId,
85
+ optionId,
86
+ text
87
+ } : {
82
88
  groupId,
83
89
  optionId
84
90
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-pos-kiosk.ts"],"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\nimport { posTipFromPercent, posTipProblem, type PosReceiptChannel } from './commerce-pos'\nimport { modifierOptionPriceCents, type ModifierSelection, type ProductModifierGroup } from './product-modifiers'\n\n/*==========================================\n * THE SELF-SERVICE KIOSK (AGL-3623).\n *\n * A register's second kind of paired screen: where the customer display\n * (AGL-3608) mirrors the cashier's basket, a kiosk lets the customer build\n * their own order — a product grid with categories and modifiers, a cart, a\n * tip, payment on the register's card reader or Tap to Pay, or \"pay at\n * counter\", which sends the order to the register's queue for a cashier.\n *\n * It pairs exactly like a display (the same six-digit code and the same\n * hashed device token, with `mode: 'kiosk'` on both), and it never holds a\n * staff session: every request carries the device token and the server\n * prices everything. These are the shapes the kiosk route and every client\n * of it — the web kiosk and the native POS app — agree on.\n *=========================================*/\n\n/** Which kind of paired screen a device token opens. */\nexport type PosDeviceMode = 'display' | 'kiosk'\n\n/** A product as the kiosk grid shows it: no cost, no stock count, no supplier. */\nexport interface PosKioskProduct {\n id: string\n name: string\n description?: string\n imageUrl?: string\n categoryIds: string[]\n /** The product's option axes (\"Size\": S, M, L), for the variant picker. */\n options: Array<{ name: string; values: string[] }>\n variants: PosKioskVariant[]\n modifierGroups: ProductModifierGroup[]\n}\n\nexport interface PosKioskVariant {\n id: string\n /** Option selections keyed by option name; empty for the default variant. */\n options: Record<string, string>\n priceCents: number\n /** A tracked variant at or below zero whose product refuses to oversell. */\n soldOut: boolean\n}\n\nexport interface PosKioskCategory {\n id: string\n name: string\n}\n\nexport interface PosKioskCatalog {\n products: PosKioskProduct[]\n categories: PosKioskCategory[]\n /** The store's currency, lower case (`usd`). */\n currency: string\n /**\n * Set when the store has more to offer than this answer lists, so the menu\n * offers a search that reaches the rest. Absent on an answer that lists\n * everything, which is every catalog the menu can show whole.\n */\n truncated?: boolean\n}\n\n/** What the kiosk offers, resolved on the server for one paired register. */\nexport interface PosKioskContext {\n branding: {\n name: string\n logoUrl: string | null\n logoDarkUrl: string | null\n message: string\n }\n currency: string\n tipping: { enabled: boolean; percentages: number[] }\n payments: {\n /** A Stripe Terminal smart reader is assigned to this register. */\n reader: boolean\n /** Card-present payments are switched on for the platform (Tap to Pay needs the native app too). */\n cardPresent: boolean\n /** \"Pay at counter\" sends the order to the register's queue. */\n payAtCounter: boolean\n }\n receipts: PosReceiptChannel[]\n offerMarketing: boolean\n /** Seconds without a touch before the kiosk asks \"Still there?\". */\n idleSeconds: number\n /** Stripe test mode: a test card can be tapped from the payment screen. */\n testMode: boolean\n}\n\n/** One cart line as the kiosk sends it: ids and a count, never a price. */\nexport interface PosKioskLine {\n productId: string\n variantId?: string\n quantity: number\n modifiers?: ModifierSelection[]\n}\n\n/** A line of a priced kiosk order, as the customer's screen shows it. */\nexport interface PosKioskSaleLine {\n name: string\n variantLabel?: string\n quantity: number\n amountCents: number\n}\n\nexport type PosKioskSaleStatus =\n /** Priced and waiting for a card at the kiosk. */\n | 'open'\n /** Sent to the register's queue; a cashier takes payment. */\n | 'queued'\n | 'paid'\n | 'voided'\n\n/** A kiosk order as its own screen reads it back. */\nexport interface PosKioskSale {\n orderId: string\n /** The order number the customer is called by. */\n number: number\n status: PosKioskSaleStatus\n lines: PosKioskSaleLine[]\n itemsCents: number\n discountCents: number\n taxCents: number\n totalCents: number\n tipCents: number\n paidCents: number\n dueCents: number\n /** The card payment in flight, if any. */\n payment: { id: string; status: string; failureMessage?: string } | null\n}\n\n/** Seconds without a touch before the kiosk asks \"Still there?\", by default. */\nexport const POS_KIOSK_IDLE_SECONDS_DEFAULT = 90\nexport const POS_KIOSK_IDLE_SECONDS_MIN = 30\nexport const POS_KIOSK_IDLE_SECONDS_MAX = 600\n\n/** How long \"Still there?\" waits before the kiosk clears itself. */\nexport const POS_KIOSK_IDLE_WARNING_SECONDS = 20\n\n/** The order-number screen returns to the start after this long. */\nexport const POS_KIOSK_DONE_SECONDS = 15\n\n/** Most lines one kiosk order carries. */\nexport const POS_KIOSK_MAX_LINES = 40\n\n/** Most of one line a customer may order at a kiosk. */\nexport const POS_KIOSK_MAX_QUANTITY = 20\n\n/** Most products the kiosk grid lists at once, for the whole menu, a category or a search. */\nexport const POS_KIOSK_CATALOG_LIMIT = 200\n\n/** Wrong staff PINs a kiosk takes before it locks its unlock screen. */\nexport const POS_KIOSK_UNLOCK_MAX_ATTEMPTS = 5\n\n/** How long a kiosk's unlock screen stays locked after too many wrong PINs. */\nexport const POS_KIOSK_UNLOCK_LOCKOUT_MS = 15 * 60 * 1000\n\n/** How long a staff unlock keeps the kiosk's settings open. */\nexport const POS_KIOSK_UNLOCK_TTL_MS = 5 * 60 * 1000\n\nconst ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/\n\n/**\n * The cart as the kiosk may send it, or why not. Ids are shape-checked and\n * quantities bounded here; everything else — whether the product exists, is\n * for sale, what it costs and whether its modifiers are valid — is the sale\n * route's to decide from the product documents.\n */\nexport function sanitizePosKioskLines(\n raw: unknown,\n): { ok: true; lines: PosKioskLine[] } | { ok: false; error: string } {\n if (!Array.isArray(raw) || raw.length === 0) return { ok: false, error: 'Your cart is empty.' }\n if (raw.length > POS_KIOSK_MAX_LINES) {\n return { ok: false, error: `An order can have at most ${POS_KIOSK_MAX_LINES} items.` }\n }\n const lines: PosKioskLine[] = []\n for (const entry of raw as Array<Record<string, unknown>>) {\n const productId = String(entry?.['productId'] ?? '')\n const variantId = entry?.['variantId'] == null ? '' : String(entry['variantId'])\n const quantity = Number(entry?.['quantity'])\n if (!ID_PATTERN.test(productId) || (variantId && !ID_PATTERN.test(variantId))) {\n return { ok: false, error: 'An item in your cart is no longer available.' }\n }\n if (!Number.isInteger(quantity) || quantity < 1 || quantity > POS_KIOSK_MAX_QUANTITY) {\n return { ok: false, error: `Order 1 to ${POS_KIOSK_MAX_QUANTITY} of each item.` }\n }\n const rawModifiers = Array.isArray(entry?.['modifiers']) ? (entry['modifiers'] as unknown[]) : []\n if (rawModifiers.length > 200) return { ok: false, error: 'Too many choices on one item.' }\n const modifiers: ModifierSelection[] = []\n for (const pick of rawModifiers as Array<Record<string, unknown>>) {\n const groupId = String(pick?.['groupId'] ?? '')\n const optionId = String(pick?.['optionId'] ?? '')\n if (!ID_PATTERN.test(groupId) || !ID_PATTERN.test(optionId)) {\n return { ok: false, error: 'A choice on an item is no longer offered.' }\n }\n modifiers.push({ groupId, optionId })\n }\n lines.push({\n productId,\n ...(variantId ? { variantId } : {}),\n quantity,\n ...(modifiers.length ? { modifiers } : {}),\n })\n }\n return { ok: true, lines }\n}\n\n/**\n * The tip a kiosk customer chose, recomputed from the server's own figure\n * for what is being paid: a percentage only from the store's presets, a\n * custom amount bounded like every register tip. Null when the choice is\n * not one the store offers.\n */\nexport function posKioskTipCents(\n choice: unknown,\n input: { baseCents: number; enabled: boolean; percentages: readonly number[]; percent?: unknown; cents?: unknown },\n): number | null {\n if (choice === undefined || choice === null || choice === 'none') return 0\n if (!input.enabled) return null\n if (choice === 'percent') {\n const percent = Math.round(Number(input.percent))\n if (!input.percentages.includes(percent)) return null\n return posTipFromPercent(input.baseCents, percent)\n }\n if (choice === 'custom') {\n const cents = Math.round(Number(input.cents))\n return posTipProblem(cents, input.baseCents) ? null : cents\n }\n return null\n}\n\n/** The idle timeout a merchant set, bounded. */\nexport function posKioskIdleSeconds(raw: unknown): number {\n const value = Math.round(Number(raw))\n if (!Number.isFinite(value) || value <= 0) return POS_KIOSK_IDLE_SECONDS_DEFAULT\n return Math.min(POS_KIOSK_IDLE_SECONDS_MAX, Math.max(POS_KIOSK_IDLE_SECONDS_MIN, value))\n}\n\n/**\n * The kiosk's estimate of its cart, from the catalog prices it was given —\n * shown while the customer shops and never sent. The order is priced again,\n * with tax, by the server when they check out.\n */\nexport function posKioskEstimateCents(\n lines: readonly PosKioskLine[],\n products: readonly PosKioskProduct[],\n): number {\n let total = 0\n for (const line of lines) {\n const product = products.find((candidate) => candidate.id === line.productId)\n if (!product) continue\n const variant =\n product.variants.find((candidate) => candidate.id === line.variantId) ?? product.variants[0]\n if (!variant) continue\n const extra = (line.modifiers ?? []).reduce((sum, pick) => {\n const group = product.modifierGroups.find((candidate) => candidate.id === pick.groupId)\n const option = group?.options.find((candidate) => candidate.id === pick.optionId)\n // A choice priced by variant adds its price on this one (AGL-4100).\n return sum + (option ? modifierOptionPriceCents(option, variant.id) : 0)\n }, 0)\n total += (variant.priceCents + extra) * line.quantity\n }\n return total\n}\n"],"names":["posTipFromPercent","posTipProblem","modifierOptionPriceCents","POS_KIOSK_IDLE_SECONDS_DEFAULT","POS_KIOSK_IDLE_SECONDS_MIN","POS_KIOSK_IDLE_SECONDS_MAX","POS_KIOSK_IDLE_WARNING_SECONDS","POS_KIOSK_DONE_SECONDS","POS_KIOSK_MAX_LINES","POS_KIOSK_MAX_QUANTITY","POS_KIOSK_CATALOG_LIMIT","POS_KIOSK_UNLOCK_MAX_ATTEMPTS","POS_KIOSK_UNLOCK_LOCKOUT_MS","POS_KIOSK_UNLOCK_TTL_MS","ID_PATTERN","sanitizePosKioskLines","raw","Array","isArray","length","ok","error","lines","entry","productId","String","variantId","quantity","Number","test","isInteger","rawModifiers","modifiers","pick","groupId","optionId","push","posKioskTipCents","choice","input","undefined","enabled","percent","Math","round","percentages","includes","baseCents","cents","posKioskIdleSeconds","value","isFinite","min","max","posKioskEstimateCents","products","total","line","product","find","candidate","id","variant","variants","extra","reduce","sum","group","mod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,CAACC,YAAcA,UAAUC,EAAE,KAAK5B,KAAKC,OAAO;YACtF,MAAMmC,SAASF,yBAAAA,MAAOG,OAAO,CAACX,IAAI,CAAC,CAACC,YAAcA,UAAUC,EAAE,KAAK5B,KAAKE,QAAQ;YAChF,oEAAoE;YACpE,OAAO+B,MAAOG,CAAAA,SAASnE,yBAAyBmE,QAAQP,QAAQD,EAAE,IAAI,CAAA;QACxE,GAAG;QACHL,SAAS,AAACM,CAAAA,QAAQS,UAAU,GAAGP,KAAI,IAAKP,KAAK9B,QAAQ;IACvD;IACA,OAAO6B;AACT"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-pos-kiosk.ts"],"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\nimport { posTipFromPercent, posTipProblem, type PosReceiptChannel } from './commerce-pos'\nimport { cleanWriteIn, modifierOptionPriceCents, type ModifierSelection, type ProductModifierGroup } from './product-modifiers'\n\n/*==========================================\n * THE SELF-SERVICE KIOSK (AGL-3623).\n *\n * A register's second kind of paired screen: where the customer display\n * (AGL-3608) mirrors the cashier's basket, a kiosk lets the customer build\n * their own order — a product grid with categories and modifiers, a cart, a\n * tip, payment on the register's card reader or Tap to Pay, or \"pay at\n * counter\", which sends the order to the register's queue for a cashier.\n *\n * It pairs exactly like a display (the same six-digit code and the same\n * hashed device token, with `mode: 'kiosk'` on both), and it never holds a\n * staff session: every request carries the device token and the server\n * prices everything. These are the shapes the kiosk route and every client\n * of it — the web kiosk and the native POS app — agree on.\n *=========================================*/\n\n/** Which kind of paired screen a device token opens. */\nexport type PosDeviceMode = 'display' | 'kiosk'\n\n/** A product as the kiosk grid shows it: no cost, no stock count, no supplier. */\nexport interface PosKioskProduct {\n id: string\n name: string\n description?: string\n imageUrl?: string\n categoryIds: string[]\n /** The product's option axes (\"Size\": S, M, L), for the variant picker. */\n options: Array<{ name: string; values: string[] }>\n variants: PosKioskVariant[]\n modifierGroups: ProductModifierGroup[]\n}\n\nexport interface PosKioskVariant {\n id: string\n /** Option selections keyed by option name; empty for the default variant. */\n options: Record<string, string>\n priceCents: number\n /** A tracked variant at or below zero whose product refuses to oversell. */\n soldOut: boolean\n}\n\nexport interface PosKioskCategory {\n id: string\n name: string\n}\n\nexport interface PosKioskCatalog {\n products: PosKioskProduct[]\n categories: PosKioskCategory[]\n /** The store's currency, lower case (`usd`). */\n currency: string\n /**\n * Set when the store has more to offer than this answer lists, so the menu\n * offers a search that reaches the rest. Absent on an answer that lists\n * everything, which is every catalog the menu can show whole.\n */\n truncated?: boolean\n}\n\n/** What the kiosk offers, resolved on the server for one paired register. */\nexport interface PosKioskContext {\n branding: {\n name: string\n logoUrl: string | null\n logoDarkUrl: string | null\n message: string\n }\n currency: string\n tipping: { enabled: boolean; percentages: number[] }\n payments: {\n /** A Stripe Terminal smart reader is assigned to this register. */\n reader: boolean\n /** Card-present payments are switched on for the platform (Tap to Pay needs the native app too). */\n cardPresent: boolean\n /** \"Pay at counter\" sends the order to the register's queue. */\n payAtCounter: boolean\n }\n receipts: PosReceiptChannel[]\n offerMarketing: boolean\n /** Seconds without a touch before the kiosk asks \"Still there?\". */\n idleSeconds: number\n /** Stripe test mode: a test card can be tapped from the payment screen. */\n testMode: boolean\n}\n\n/** One cart line as the kiosk sends it: ids and a count, never a price. */\nexport interface PosKioskLine {\n productId: string\n variantId?: string\n quantity: number\n modifiers?: ModifierSelection[]\n}\n\n/** A line of a priced kiosk order, as the customer's screen shows it. */\nexport interface PosKioskSaleLine {\n name: string\n variantLabel?: string\n quantity: number\n amountCents: number\n}\n\nexport type PosKioskSaleStatus =\n /** Priced and waiting for a card at the kiosk. */\n | 'open'\n /** Sent to the register's queue; a cashier takes payment. */\n | 'queued'\n | 'paid'\n | 'voided'\n\n/** A kiosk order as its own screen reads it back. */\nexport interface PosKioskSale {\n orderId: string\n /** The order number the customer is called by. */\n number: number\n status: PosKioskSaleStatus\n lines: PosKioskSaleLine[]\n itemsCents: number\n discountCents: number\n taxCents: number\n totalCents: number\n tipCents: number\n paidCents: number\n dueCents: number\n /** The card payment in flight, if any. */\n payment: { id: string; status: string; failureMessage?: string } | null\n}\n\n/** Seconds without a touch before the kiosk asks \"Still there?\", by default. */\nexport const POS_KIOSK_IDLE_SECONDS_DEFAULT = 90\nexport const POS_KIOSK_IDLE_SECONDS_MIN = 30\nexport const POS_KIOSK_IDLE_SECONDS_MAX = 600\n\n/** How long \"Still there?\" waits before the kiosk clears itself. */\nexport const POS_KIOSK_IDLE_WARNING_SECONDS = 20\n\n/** The order-number screen returns to the start after this long. */\nexport const POS_KIOSK_DONE_SECONDS = 15\n\n/** Most lines one kiosk order carries. */\nexport const POS_KIOSK_MAX_LINES = 40\n\n/** Most of one line a customer may order at a kiosk. */\nexport const POS_KIOSK_MAX_QUANTITY = 20\n\n/** Most products the kiosk grid lists at once, for the whole menu, a category or a search. */\nexport const POS_KIOSK_CATALOG_LIMIT = 200\n\n/** Wrong staff PINs a kiosk takes before it locks its unlock screen. */\nexport const POS_KIOSK_UNLOCK_MAX_ATTEMPTS = 5\n\n/** How long a kiosk's unlock screen stays locked after too many wrong PINs. */\nexport const POS_KIOSK_UNLOCK_LOCKOUT_MS = 15 * 60 * 1000\n\n/** How long a staff unlock keeps the kiosk's settings open. */\nexport const POS_KIOSK_UNLOCK_TTL_MS = 5 * 60 * 1000\n\nconst ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/\n\n/**\n * The cart as the kiosk may send it, or why not. Ids are shape-checked and\n * quantities bounded here; everything else — whether the product exists, is\n * for sale, what it costs and whether its modifiers are valid — is the sale\n * route's to decide from the product documents.\n */\nexport function sanitizePosKioskLines(\n raw: unknown,\n): { ok: true; lines: PosKioskLine[] } | { ok: false; error: string } {\n if (!Array.isArray(raw) || raw.length === 0) return { ok: false, error: 'Your cart is empty.' }\n if (raw.length > POS_KIOSK_MAX_LINES) {\n return { ok: false, error: `An order can have at most ${POS_KIOSK_MAX_LINES} items.` }\n }\n const lines: PosKioskLine[] = []\n for (const entry of raw as Array<Record<string, unknown>>) {\n const productId = String(entry?.['productId'] ?? '')\n const variantId = entry?.['variantId'] == null ? '' : String(entry['variantId'])\n const quantity = Number(entry?.['quantity'])\n if (!ID_PATTERN.test(productId) || (variantId && !ID_PATTERN.test(variantId))) {\n return { ok: false, error: 'An item in your cart is no longer available.' }\n }\n if (!Number.isInteger(quantity) || quantity < 1 || quantity > POS_KIOSK_MAX_QUANTITY) {\n return { ok: false, error: `Order 1 to ${POS_KIOSK_MAX_QUANTITY} of each item.` }\n }\n const rawModifiers = Array.isArray(entry?.['modifiers']) ? (entry['modifiers'] as unknown[]) : []\n if (rawModifiers.length > 200) return { ok: false, error: 'Too many choices on one item.' }\n const modifiers: ModifierSelection[] = []\n for (const pick of rawModifiers as Array<Record<string, unknown>>) {\n const groupId = String(pick?.['groupId'] ?? '')\n const optionId = String(pick?.['optionId'] ?? '')\n if (!ID_PATTERN.test(groupId) || !ID_PATTERN.test(optionId)) {\n return { ok: false, error: 'A choice on an item is no longer offered.' }\n }\n // A write-in's answer (write-ins), checked against its group when the order is priced.\n const text = cleanWriteIn(pick?.['text'])\n modifiers.push(text ? { groupId, optionId, text } : { groupId, optionId })\n }\n lines.push({\n productId,\n ...(variantId ? { variantId } : {}),\n quantity,\n ...(modifiers.length ? { modifiers } : {}),\n })\n }\n return { ok: true, lines }\n}\n\n/**\n * The tip a kiosk customer chose, recomputed from the server's own figure\n * for what is being paid: a percentage only from the store's presets, a\n * custom amount bounded like every register tip. Null when the choice is\n * not one the store offers.\n */\nexport function posKioskTipCents(\n choice: unknown,\n input: { baseCents: number; enabled: boolean; percentages: readonly number[]; percent?: unknown; cents?: unknown },\n): number | null {\n if (choice === undefined || choice === null || choice === 'none') return 0\n if (!input.enabled) return null\n if (choice === 'percent') {\n const percent = Math.round(Number(input.percent))\n if (!input.percentages.includes(percent)) return null\n return posTipFromPercent(input.baseCents, percent)\n }\n if (choice === 'custom') {\n const cents = Math.round(Number(input.cents))\n return posTipProblem(cents, input.baseCents) ? null : cents\n }\n return null\n}\n\n/** The idle timeout a merchant set, bounded. */\nexport function posKioskIdleSeconds(raw: unknown): number {\n const value = Math.round(Number(raw))\n if (!Number.isFinite(value) || value <= 0) return POS_KIOSK_IDLE_SECONDS_DEFAULT\n return Math.min(POS_KIOSK_IDLE_SECONDS_MAX, Math.max(POS_KIOSK_IDLE_SECONDS_MIN, value))\n}\n\n/**\n * The kiosk's estimate of its cart, from the catalog prices it was given —\n * shown while the customer shops and never sent. The order is priced again,\n * with tax, by the server when they check out.\n */\nexport function posKioskEstimateCents(\n lines: readonly PosKioskLine[],\n products: readonly PosKioskProduct[],\n): number {\n let total = 0\n for (const line of lines) {\n const product = products.find((candidate) => candidate.id === line.productId)\n if (!product) continue\n const variant =\n product.variants.find((candidate) => candidate.id === line.variantId) ?? product.variants[0]\n if (!variant) continue\n const extra = (line.modifiers ?? []).reduce((sum, pick) => {\n const group = product.modifierGroups.find((candidate) => candidate.id === pick.groupId)\n const option = group?.options.find((candidate) => candidate.id === pick.optionId)\n // A choice priced by variant adds its price on this one (AGL-4100).\n return sum + (option ? modifierOptionPriceCents(option, variant.id) : 0)\n }, 0)\n total += (variant.priceCents + extra) * line.quantity\n }\n return total\n}\n"],"names":["posTipFromPercent","posTipProblem","cleanWriteIn","modifierOptionPriceCents","POS_KIOSK_IDLE_SECONDS_DEFAULT","POS_KIOSK_IDLE_SECONDS_MIN","POS_KIOSK_IDLE_SECONDS_MAX","POS_KIOSK_IDLE_WARNING_SECONDS","POS_KIOSK_DONE_SECONDS","POS_KIOSK_MAX_LINES","POS_KIOSK_MAX_QUANTITY","POS_KIOSK_CATALOG_LIMIT","POS_KIOSK_UNLOCK_MAX_ATTEMPTS","POS_KIOSK_UNLOCK_LOCKOUT_MS","POS_KIOSK_UNLOCK_TTL_MS","ID_PATTERN","sanitizePosKioskLines","raw","Array","isArray","length","ok","error","lines","entry","productId","String","variantId","quantity","Number","test","isInteger","rawModifiers","modifiers","pick","groupId","optionId","text","push","posKioskTipCents","choice","input","undefined","enabled","percent","Math","round","percentages","includes","baseCents","cents","posKioskIdleSeconds","value","isFinite","min","max","posKioskEstimateCents","products","total","line","product","find","candidate","id","variant","variants","extra","reduce","sum","group","modifierGroups","option","options","priceCents"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,EAAEC,aAAa,QAAgC,oBAAgB;AACzF,SAASC,YAAY,EAAEC,wBAAwB,QAA2D,yBAAqB;AAiI/H,8EAA8E,GAC9E,OAAO,MAAMC,iCAAiC,GAAE;AAChD,OAAO,MAAMC,6BAA6B,GAAE;AAC5C,OAAO,MAAMC,6BAA6B,IAAG;AAE7C,kEAAkE,GAClE,OAAO,MAAMC,iCAAiC,GAAE;AAEhD,kEAAkE,GAClE,OAAO,MAAMC,yBAAyB,GAAE;AAExC,wCAAwC,GACxC,OAAO,MAAMC,sBAAsB,GAAE;AAErC,sDAAsD,GACtD,OAAO,MAAMC,yBAAyB,GAAE;AAExC,4FAA4F,GAC5F,OAAO,MAAMC,0BAA0B,IAAG;AAE1C,sEAAsE,GACtE,OAAO,MAAMC,gCAAgC,EAAC;AAE9C,6EAA6E,GAC7E,OAAO,MAAMC,8BAA8B,KAAK,KAAK,KAAI;AAEzD,6DAA6D,GAC7D,OAAO,MAAMC,0BAA0B,IAAI,KAAK,KAAI;AAEpD,MAAMC,aAAa;AAEnB;;;;;CAKC,GACD,OAAO,SAASC,sBACdC,GAAY;IAEZ,IAAI,CAACC,MAAMC,OAAO,CAACF,QAAQA,IAAIG,MAAM,KAAK,GAAG,OAAO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pC,IAAIC,QAAQ;IACZ,KAAK,MAAMC,QAAQpC,MAAO;YAItBqC,wBAEaD;QALf,MAAMC,UAAUH,SAASI,IAAI,CAAC,CAACC,YAAcA,UAAUC,EAAE,KAAKJ,KAAKlC,SAAS;QAC5E,IAAI,CAACmC,SAAS;QACd,MAAMI,WACJJ,yBAAAA,QAAQK,QAAQ,CAACJ,IAAI,CAAC,CAACC,YAAcA,UAAUC,EAAE,KAAKJ,KAAKhC,SAAS,aAApEiC,yBAAyEA,QAAQK,QAAQ,CAAC,EAAE;QAC9F,IAAI,CAACD,SAAS;QACd,MAAME,QAAQ,EAACP,kBAAAA,KAAK1B,SAAS,YAAd0B,kBAAkB,EAAE,EAAEQ,MAAM,CAAC,CAACC,KAAKlC;YAChD,MAAMmC,QAAQT,QAAQU,cAAc,CAACT,IAAI,CAAC,CAACC,YAAcA,UAAUC,EAAE,KAAK7B,KAAKC,OAAO;YACtF,MAAMoC,SAASF,yBAAAA,MAAOG,OAAO,CAACX,IAAI,CAAC,CAACC,YAAcA,UAAUC,EAAE,KAAK7B,KAAKE,QAAQ;YAChF,oEAAoE;YACpE,OAAOgC,MAAOG,CAAAA,SAASpE,yBAAyBoE,QAAQP,QAAQD,EAAE,IAAI,CAAA;QACxE,GAAG;QACHL,SAAS,AAACM,CAAAA,QAAQS,UAAU,GAAGP,KAAI,IAAKP,KAAK/B,QAAQ;IACvD;IACA,OAAO8B;AACT"}
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { type OrderTotals } from './commerce-orders';
18
- import type { ModifierSelection } from './product-modifiers';
18
+ import { type ModifierSelection } from './product-modifiers';
19
19
  /** The route both register clients sync through. */
20
20
  export declare const POS_OFFLINE_SYNC_ROUTE = "/api/commerce/pos-offline-sync";
21
21
  /** The most sales one sync request carries; a longer queue sends in batches. */
@@ -16,6 +16,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
16
16
  * limitations under the License.
17
17
  */ import { computeOrderTotals } from "./commerce-orders.js";
18
18
  import { computeTaxCents } from "./commerce-tax.js";
19
+ import { cleanWriteIn } from "./product-modifiers.js";
19
20
  import { POS_OFFLINE_CARD_MAX_SALE_CENTS_LIMIT } from "./pos-offline-card-limits.js";
20
21
  /*==========================================
21
22
  * THE OFFLINE REGISTER (AGL-3625): the contract every register client — the
@@ -217,10 +218,15 @@ function wholeCents(value) {
217
218
  'digital',
218
219
  'service'
219
220
  ].includes(line == null ? void 0 : line.productType) ? line.productType : undefined;
220
- const modifiers = Array.isArray(line == null ? void 0 : line.modifiers) ? line.modifiers.slice(0, 50).map((pick)=>({
221
+ const modifiers = Array.isArray(line == null ? void 0 : line.modifiers) ? line.modifiers.slice(0, 50).map((pick)=>{
222
+ const text = cleanWriteIn(pick == null ? void 0 : pick.text);
223
+ return _extends({
221
224
  groupId: cleanId(pick == null ? void 0 : pick.groupId),
222
225
  optionId: cleanId(pick == null ? void 0 : pick.optionId)
223
- })).filter((pick)=>pick.groupId && pick.optionId) : [];
226
+ }, text ? {
227
+ text
228
+ } : {});
229
+ }).filter((pick)=>pick.groupId && pick.optionId) : [];
224
230
  lines.push(_extends({
225
231
  productId
226
232
  }, variantId ? {