@aglyn/plugins-commerce 1.15.1 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +13 -13
- package/src/lib/components/cart.js +2 -1
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/console/payments-settings-card.component.js +6 -1
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-api.d.ts +5 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -1
- package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +2 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js +13 -6
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-tender-panel.component.js +7 -4
- package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -1
- package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
- package/src/lib/components/console/product-add-ons-fields.component.js +96 -3
- package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
- package/src/lib/components/console/product-builder-fields.component.d.ts +39 -0
- package/src/lib/components/console/product-builder-fields.component.js +195 -0
- package/src/lib/components/console/product-builder-fields.component.js.map +1 -0
- package/src/lib/components/console/product-editor-dialog.component.js +35 -2
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-editor-dialog.component.js +43 -6
- package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/quote-messages.component.d.ts +21 -0
- package/src/lib/components/console/quote-messages.component.js +185 -0
- package/src/lib/components/console/quote-messages.component.js.map +1 -0
- package/src/lib/components/console/quote-pay-link.component.js +1 -1
- package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
- package/src/lib/components/console/quote-proofs.component.js +30 -3
- package/src/lib/components/console/quote-proofs.component.js.map +1 -1
- package/src/lib/components/console/quote-settings-card.component.d.ts +7 -3
- package/src/lib/components/console/quote-settings-card.component.js +154 -24
- package/src/lib/components/console/quote-settings-card.component.js.map +1 -1
- package/src/lib/components/product-builder-context.d.ts +22 -0
- package/src/lib/components/product-builder-context.js +21 -0
- package/src/lib/components/product-builder-context.js.map +1 -0
- package/src/lib/components/product-builder-mockup.d.ts +42 -0
- package/src/lib/components/product-builder-mockup.js +120 -0
- package/src/lib/components/product-builder-mockup.js.map +1 -0
- package/src/lib/components/product-builder-sample.d.ts +63 -0
- package/src/lib/components/product-builder-sample.js +96 -0
- package/src/lib/components/product-builder-sample.js.map +1 -0
- package/src/lib/components/product-choice-cards.d.ts +51 -0
- package/src/lib/components/product-choice-cards.js +311 -0
- package/src/lib/components/product-choice-cards.js.map +1 -0
- package/src/lib/components/product-detail-panels.d.ts +42 -0
- package/src/lib/components/product-detail-panels.js +185 -0
- package/src/lib/components/product-detail-panels.js.map +1 -0
- package/src/lib/components/product-detail.d.ts +20 -12
- package/src/lib/components/product-detail.js +136 -221
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.d.ts +7 -0
- package/src/lib/components/product-grid.js +11 -8
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/product-options-field-body.d.ts +9 -8
- package/src/lib/components/product-options-field-body.js +152 -3
- package/src/lib/components/product-options-field-body.js.map +1 -1
- package/src/lib/components/product-options-field.js +1 -1
- package/src/lib/components/product-options-field.js.map +1 -1
- package/src/lib/components/product-photo-fit.d.ts +49 -0
- package/src/lib/components/product-photo-fit.js +58 -0
- package/src/lib/components/product-photo-fit.js.map +1 -0
- package/src/lib/components/product-restock-notify.d.ts +12 -0
- package/src/lib/components/product-restock-notify.js +86 -0
- package/src/lib/components/product-restock-notify.js.map +1 -0
- package/src/lib/components/quote-messages-panel.d.ts +21 -0
- package/src/lib/components/quote-messages-panel.js +191 -0
- package/src/lib/components/quote-messages-panel.js.map +1 -0
- package/src/lib/components/quote-page-body.js +15 -1
- package/src/lib/components/quote-page-body.js.map +1 -1
- package/src/lib/components/quote-proof-panel.d.ts +6 -3
- package/src/lib/components/quote-proof-panel.js +139 -14
- package/src/lib/components/quote-proof-panel.js.map +1 -1
- package/src/lib/components/related-products.d.ts +7 -0
- package/src/lib/components/related-products.js +8 -6
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/constants/quote-page.d.ts +8 -0
- package/src/lib/constants/quote-page.js +11 -0
- package/src/lib/constants/quote-page.js.map +1 -1
- package/src/lib/model/commerce-cart.d.ts +6 -1
- package/src/lib/model/commerce-cart.js +5 -1
- package/src/lib/model/commerce-cart.js.map +1 -1
- package/src/lib/model/commerce-invoices.js +5 -1
- package/src/lib/model/commerce-invoices.js.map +1 -1
- package/src/lib/model/commerce-pos-ops.d.ts +3 -0
- package/src/lib/model/commerce-pos-ops.js +3 -0
- package/src/lib/model/commerce-pos-ops.js.map +1 -1
- package/src/lib/model/commerce-pos.d.ts +8 -0
- package/src/lib/model/commerce-pos.js.map +1 -1
- package/src/lib/model/commerce-quote-messages.d.ts +106 -0
- package/src/lib/model/commerce-quote-messages.js +146 -0
- package/src/lib/model/commerce-quote-messages.js.map +1 -0
- package/src/lib/model/commerce-quote-pay.d.ts +31 -2
- package/src/lib/model/commerce-quote-pay.js +31 -7
- package/src/lib/model/commerce-quote-pay.js.map +1 -1
- package/src/lib/model/commerce-quote-proofs.d.ts +47 -8
- package/src/lib/model/commerce-quote-proofs.js +73 -18
- package/src/lib/model/commerce-quote-proofs.js.map +1 -1
- package/src/lib/model/commerce-quote-request.d.ts +14 -4
- package/src/lib/model/commerce-quote-request.js +25 -2
- package/src/lib/model/commerce-quote-request.js.map +1 -1
- package/src/lib/model/commerce-quotes.d.ts +56 -3
- package/src/lib/model/commerce-quotes.js +47 -2
- package/src/lib/model/commerce-quotes.js.map +1 -1
- package/src/lib/model/commerce.d.ts +12 -1
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +1 -0
- package/src/lib/model/index.js +1 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/pos-cellular.d.ts +5 -0
- package/src/lib/model/pos-cellular.js.map +1 -1
- package/src/lib/model/product-card-rules.d.ts +41 -0
- package/src/lib/model/product-card-rules.js +90 -0
- package/src/lib/model/product-card-rules.js.map +1 -0
- package/src/lib/model/product-modifiers.d.ts +11 -0
- package/src/lib/model/product-modifiers.js +10 -0
- package/src/lib/model/product-modifiers.js.map +1 -1
- package/src/lib/model/product-write.d.ts +3 -0
- package/src/lib/server/billing-webhook.js +6 -2
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +15 -0
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/channel-order-updates.js +15 -1
- package/src/lib/server/channel-order-updates.js.map +1 -1
- package/src/lib/server/channel-orders.js +20 -0
- package/src/lib/server/channel-orders.js.map +1 -1
- package/src/lib/server/checkout.js +1 -1
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/local-fulfillment.js +1 -1
- package/src/lib/server/local-fulfillment.js.map +1 -1
- package/src/lib/server/pos-cellular-billing.d.ts +1 -1
- package/src/lib/server/pos-cellular-billing.js +2 -1
- package/src/lib/server/pos-cellular-billing.js.map +1 -1
- package/src/lib/server/pos-cellular.d.ts +3 -1
- package/src/lib/server/pos-cellular.js +15 -8
- package/src/lib/server/pos-cellular.js.map +1 -1
- package/src/lib/server/pos-offline-sync.d.ts +3 -3
- package/src/lib/server/pos-offline-sync.js +17 -4
- package/src/lib/server/pos-offline-sync.js.map +1 -1
- package/src/lib/server/pos-order.js +17 -6
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-payment.js +27 -11
- package/src/lib/server/pos-payment.js.map +1 -1
- package/src/lib/server/pos-reader-splash.js +10 -5
- package/src/lib/server/pos-reader-splash.js.map +1 -1
- package/src/lib/server/pos-readers.js +34 -10
- package/src/lib/server/pos-readers.js.map +1 -1
- package/src/lib/server/pos-return.js +19 -3
- package/src/lib/server/pos-return.js.map +1 -1
- package/src/lib/server/pos-stripe.d.ts +14 -0
- package/src/lib/server/pos-stripe.js +6 -2
- package/src/lib/server/pos-stripe.js.map +1 -1
- package/src/lib/server/pos-terminal-connection-token.js +23 -9
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
- package/src/lib/server/pos-terminal.d.ts +80 -14
- package/src/lib/server/pos-terminal.js +393 -123
- package/src/lib/server/pos-terminal.js.map +1 -1
- package/src/lib/server/product-drafts.d.ts +1 -1
- package/src/lib/server/product-drafts.js +4 -3
- package/src/lib/server/product-drafts.js.map +1 -1
- package/src/lib/server/product-writer.js +5 -4
- package/src/lib/server/product-writer.js.map +1 -1
- package/src/lib/server/product.d.ts +11 -0
- package/src/lib/server/product.js +18 -3
- package/src/lib/server/product.js.map +1 -1
- package/src/lib/server/products-write.js +4 -3
- package/src/lib/server/products-write.js.map +1 -1
- package/src/lib/server/quote-email.d.ts +26 -0
- package/src/lib/server/quote-email.js +73 -7
- package/src/lib/server/quote-email.js.map +1 -1
- package/src/lib/server/quote-messages.d.ts +72 -0
- package/src/lib/server/quote-messages.js +356 -0
- package/src/lib/server/quote-messages.js.map +1 -0
- package/src/lib/server/quote-pay.d.ts +42 -0
- package/src/lib/server/quote-pay.js +81 -4
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/quote-proofs.d.ts +1 -1
- package/src/lib/server/quote-proofs.js +63 -19
- package/src/lib/server/quote-proofs.js.map +1 -1
- package/src/lib/server/quote.d.ts +12 -0
- package/src/lib/server/quote.js +44 -14
- package/src/lib/server/quote.js.map +1 -1
- package/src/lib/server/refund.js +3 -1
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/reserve-stock.js +9 -0
- package/src/lib/server/reserve-stock.js.map +1 -1
- package/src/lib/server/returns.js +15 -1
- package/src/lib/server/returns.js.map +1 -1
- package/src/lib/server/reviews.js +15 -0
- package/src/lib/server/reviews.js.map +1 -1
- package/src/lib/server/sold-out-drop.d.ts +58 -0
- package/src/lib/server/sold-out-drop.js +81 -0
- package/src/lib/server/sold-out-drop.js.map +1 -0
- package/src/lib/server/stock-levels.js +9 -0
- package/src/lib/server/stock-levels.js.map +1 -1
- package/src/lib/server/stripe-refund.d.ts +7 -0
- package/src/lib/server/stripe-refund.js +26 -7
- package/src/lib/server/stripe-refund.js.map +1 -1
- package/src/lib/server.js +2 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/tenant-emails.js +85 -2
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-seller-payment-account.d.ts +29 -0
- package/src/lib/testing/fake-seller-payment-account.js +40 -0
- package/src/lib/testing/fake-seller-payment-account.js.map +1 -0
- package/src/lib/transfer/product-transfer.js +6 -5
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.js +4 -3
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/utils/quote-email-content.d.ts +6 -0
- package/src/lib/utils/quote-email-content.js +6 -3
- package/src/lib/utils/quote-email-content.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-options-field-body.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\nimport * as Aglyn from '@aglyn/aglyn'\nimport { formFieldDataKey } from '../model/commerce-product-field'\nimport { encodeProductFieldValue, productFieldLabel } from '../model/commerce-quote-request'\nimport Box from '@mui/material/Box'\nimport FormControl from '@mui/material/FormControl'\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 { forwardRef, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport type { ProductOptionsFieldProps } from './product-options-field'\n\n/** A product as the store's public catalog lists it. */\ninterface ListedProduct {\n id: string\n name: string\n slug: string\n}\n\n/** A product as its public page reads it: its options and the variants they make. */\ninterface ProductDetail {\n id: string\n name: string\n options: Array<{ name: string; values: string[] }>\n variants: Array<{ id: string; options?: Record<string, string> }>\n}\n\n/** The most products the picker lists. */\nconst PICKER_LIMIT = 100\n\n/** The variant whose options are exactly the ones picked, else none. */\nexport function variantForOptions(\n detail: Pick<ProductDetail, 'variants' | 'options'>,\n picked: Readonly<Record<string, string>>,\n): string | null {\n if (!detail.options.length) return detail.variants[0]?.id ?? null\n if (detail.options.some((option) => !picked[option.name])) return null\n const match = detail.variants.find((variant) =>\n detail.options.every((option) => variant.options?.[option.name] === picked[option.name]),\n )\n return match?.id ?? null\n}\n\n/**\n * The Product and options field's body (AGL-4098): a picker of the store's\n * products (or the one the author chose), then one picker per option. It\n * posts the readable line under its name and the exact choice beside it; a\n * real, invisible input carries the line, so a required field with nothing\n * picked stops the form like any required field.\n *\n * On the canvas and in Preview it draws with the store's products but sends\n * nothing, like every form field there.\n */\nconst ProductOptionsFieldBody = forwardRef<HTMLDivElement, ProductOptionsFieldProps>((props, ref) => {\n const { name: rawName, label, productId: fixedProductId, required, ...rest } = props\n const name = String(rawName ?? '').trim() || 'product'\n const { hostId } = Aglyn.useSite()\n const inputId = useId()\n const answerRef = useRef<HTMLInputElement>(null)\n const [products, setProducts] = useState<ListedProduct[] | null>(null)\n const [productId, setProductId] = useState(fixedProductId ?? '')\n const [detail, setDetail] = useState<ProductDetail | null>(null)\n const [picked, setPicked] = useState<Record<string, string>>({})\n\n // The store's products, or the one the author chose.\n useEffect(() => {\n if (!hostId) return\n let active = true\n const query = new URLSearchParams({\n hostId,\n ...(fixedProductId ? { ids: fixedProductId } : { sort: 'name', limit: String(PICKER_LIMIT) }),\n })\n void fetch(`/api/commerce/catalog?${query.toString()}`)\n .then((response) => (response.ok ? response.json() : { items: [] }))\n .then((payload) => {\n if (!active) return\n const items = Array.isArray(payload?.items) ? (payload.items as ListedProduct[]) : []\n setProducts(items)\n if (fixedProductId) setProductId(items[0]?.id ?? '')\n })\n .catch(() => active && setProducts([]))\n return () => {\n active = false\n }\n }, [hostId, fixedProductId])\n\n // The chosen product's options.\n const slug = products?.find((product) => product.id === productId)?.slug ?? ''\n useEffect(() => {\n setDetail(null)\n setPicked({})\n if (!hostId || !slug) return\n let active = true\n void fetch(`/api/commerce/product?hostId=${encodeURIComponent(hostId)}&slug=${encodeURIComponent(slug)}`)\n .then((response) => (response.ok ? response.json() : null))\n .then((payload) => {\n if (!active || !payload?.product) return\n const product = payload.product as ProductDetail\n setDetail({ ...product, options: product.options ?? [], variants: product.variants ?? [] })\n })\n .catch(() => undefined)\n return () => {\n active = false\n }\n }, [hostId, slug])\n\n const variantId = detail ? variantForOptions(detail, picked) : null\n const complete = Boolean(detail && variantId)\n const answer = complete && detail ? productFieldLabel(detail.name, picked) : ''\n const value = complete && detail\n ? encodeProductFieldValue({\n productId: detail.id,\n ...(variantId && variantId !== 'default' ? { variantId } : {}),\n ...(Object.keys(picked).length ? { options: picked } : {}),\n // Add-ons are chosen on the storefront from slice 8 on: they ride here as `modifiers`.\n })\n : ''\n\n // Every change is announced, as a typed answer is, to anything listening on the form.\n const announced = useRef(answer)\n useEffect(() => {\n if (announced.current === answer) return\n announced.current = answer\n answerRef.current?.dispatchEvent(new Event('change', { bubbles: true }))\n }, [answer])\n\n const listed = useMemo(() => products ?? [], [products])\n // On the canvas there is no site to list from: it says what the visitor will pick from.\n const placeholder = !hostId\n ? 'Your store’s products'\n : products === null\n ? 'Loading products…'\n : listed.length\n ? 'Choose a product'\n : 'No products to choose from yet'\n\n return (\n <FormControl ref={ref} fullWidth required={Boolean(required)} {...rest}>\n <FormLabel htmlFor={inputId}>{label || 'Product'}</FormLabel>\n <Stack spacing={1.5} sx={{ mt: 1, position: 'relative' }}>\n {fixedProductId ? null : (\n <TextField\n id={inputId}\n select\n size=\"small\"\n fullWidth\n value={productId}\n onChange={(event) => setProductId(event.target.value)}\n disabled={!listed.length}\n slotProps={{\n select: {\n displayEmpty: true,\n renderValue: (selected: unknown) =>\n listed.find((product) => product.id === selected)?.name ?? (\n <Box component=\"span\" sx={{ color: 'text.secondary' }}>\n {placeholder}\n </Box>\n ),\n },\n }}\n >\n {listed.map((product) => (\n <MenuItem key={product.id} value={product.id}>\n {product.name}\n </MenuItem>\n ))}\n </TextField>\n )}\n {fixedProductId && detail ? <FormHelperText sx={{ mx: 0 }}>{detail.name}</FormHelperText> : null}\n {(detail?.options ?? []).map((option) => (\n <TextField\n key={option.name}\n select\n size=\"small\"\n fullWidth\n label={option.name}\n value={picked[option.name] ?? ''}\n onChange={(event) => setPicked((current) => ({ ...current, [option.name]: event.target.value }))}\n >\n {option.values.map((choice) => (\n <MenuItem key={choice} value={choice}>\n {choice}\n </MenuItem>\n ))}\n </TextField>\n ))}\n {detail && Object.keys(picked).length === detail.options.length && detail.options.length && !variantId ? (\n <FormHelperText error sx={{ mx: 0 }}>\n {'That combination isn’t one we offer. Pick another.'}\n </FormHelperText>\n ) : null}\n {/* The answer the form sends and the browser checks, and the exact choice beside it. */}\n <Box\n component=\"input\"\n ref={answerRef}\n type=\"text\"\n name={name}\n value={answer}\n required={Boolean(required)}\n onChange={() => undefined}\n tabIndex={-1}\n aria-hidden=\"true\"\n autoComplete=\"off\"\n sx={{ position: 'absolute', left: 0, bottom: 0, width: 1, height: '1px', p: 0, border: 0, opacity: 0, pointerEvents: 'none' }}\n />\n {value ? <input type=\"hidden\" name={formFieldDataKey(name)} value={value} readOnly /> : null}\n </Stack>\n </FormControl>\n )\n})\nProductOptionsFieldBody.displayName = 'AglynProductOptionsFieldBody'\n\nexport default ProductOptionsFieldBody\n"],"names":["Aglyn","formFieldDataKey","encodeProductFieldValue","productFieldLabel","Box","FormControl","FormHelperText","FormLabel","MenuItem","Stack","TextField","forwardRef","useEffect","useId","useMemo","useRef","useState","PICKER_LIMIT","variantForOptions","detail","picked","options","length","variants","id","some","option","name","match","find","variant","every","ProductOptionsFieldBody","props","ref","products","rawName","label","productId","fixedProductId","required","rest","String","trim","hostId","useSite","inputId","answerRef","setProducts","setProductId","setDetail","setPicked","active","query","URLSearchParams","ids","sort","limit","fetch","toString","then","response","ok","json","items","payload","Array","isArray","catch","slug","product","encodeURIComponent","undefined","variantId","complete","Boolean","answer","value","Object","keys","announced","current","dispatchEvent","Event","bubbles","listed","placeholder","fullWidth","htmlFor","spacing","sx","mt","position","select","size","onChange","event","target","disabled","slotProps","displayEmpty","renderValue","selected","component","color","map","mx","values","choice","error","type","tabIndex","aria-hidden","autoComplete","left","bottom","width","height","p","border","opacity","pointerEvents","input","readOnly","displayName"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,gBAAgB,QAAQ,qCAAiC;AAClE,SAASC,uBAAuB,EAAEC,iBAAiB,QAAQ,qCAAiC;AAC5F,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,cAAc,yBAAwB;AAC7C,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,eAAe,0BAAyB;AAC/C,SAASC,UAAU,EAAEC,SAAS,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAkB/E,wCAAwC,GACxC,MAAMC,eAAe;AAErB,sEAAsE,GACtE,OAAO,SAASC,kBACdC,MAAmD,EACnDC,MAAwC;;QAELD;IAAnC,IAAI,CAACA,OAAOE,OAAO,CAACC,MAAM,EAAE,gBAAOH,oBAAAA,OAAOI,QAAQ,CAAC,EAAE,qBAAlBJ,kBAAoBK,EAAE,mBAAI;IAC7D,IAAIL,O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gB,IAAI;wBAAE;kCAC/B;yBAED;kCAEJ,KAACtG;wBACCmG,WAAU;wBACVrE,KAAKa;wBACL+D,MAAK;wBACLnF,MAAMA;wBACNkD,OAAOD;wBACPpC,UAAUmC,QAAQnC;wBAClBuD,UAAU,IAAMvB;wBAChBuC,UAAU,CAAC;wBACXC,eAAY;wBACZC,cAAa;wBACbvB,IAAI;4BAAEE,UAAU;4BAAYsB,MAAM;4BAAGC,QAAQ;4BAAGC,OAAO;4BAAGC,QAAQ;4BAAOC,GAAG;4BAAGC,QAAQ;4BAAGC,SAAS;4BAAGC,eAAe;wBAAO;;oBAE7H5C,sBAAQ,KAAC6C;wBAAMZ,MAAK;wBAASnF,MAAM1B,iBAAiB0B;wBAAOkD,OAAOA;wBAAO8C,QAAQ;yBAAM;;;;;AAIhG;AACA3F,wBAAwB4F,WAAW,GAAG;AAEtC,eAAe5F,wBAAuB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-options-field-body.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\nimport * as Aglyn from '@aglyn/aglyn'\nimport { formFieldDataKey } from '../model/commerce-product-field'\nimport { builderPicksLabel, encodeProductFieldValue, productFieldLabel } from '../model/commerce-quote-request'\nimport Box from '@mui/material/Box'\nimport FormControl from '@mui/material/FormControl'\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 Typography from '@mui/material/Typography'\nimport { forwardRef, useContext, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport { ProductBuilderContext, type ProductBuilderPicks } from './product-builder-context'\nimport type { ProductOptionsFieldProps } from './product-options-field'\n\n/** A product as the store's public catalog lists it. */\ninterface ListedProduct {\n id: string\n name: string\n slug: string\n}\n\n/** A product as its public page reads it: its options and the variants they make. */\ninterface ProductDetail {\n id: string\n name: string\n options: Array<{ name: string; values: string[] }>\n variants: Array<{ id: string; options?: Record<string, string> }>\n}\n\n/** The most products the picker lists. */\nconst PICKER_LIMIT = 100\n\n/** The variant whose options are exactly the ones picked, else none. */\nexport function variantForOptions(\n detail: Pick<ProductDetail, 'variants' | 'options'>,\n picked: Readonly<Record<string, string>>,\n): string | null {\n if (!detail.options.length) return detail.variants[0]?.id ?? null\n if (detail.options.some((option) => !picked[option.name])) return null\n const match = detail.variants.find((variant) =>\n detail.options.every((option) => variant.options?.[option.name] === picked[option.name]),\n )\n return match?.id ?? null\n}\n\n/**\n * The Product and options field's body (AGL-4098): a picker of the store's\n * products (or the one the author chose), then one picker per option. It\n * posts the readable line under its name and the exact choice beside it; a\n * real, invisible input carries the line, so a required field with nothing\n * picked stops the form like any required field.\n *\n * On the canvas and in Preview it draws with the store's products but sends\n * nothing, like every form field there.\n */\nconst StoreProductPicker = forwardRef<HTMLDivElement, ProductOptionsFieldProps>((props, ref) => {\n const { name: rawName, label, productId: fixedProductId, required, ...rest } = props\n const name = String(rawName ?? '').trim() || 'product'\n const { hostId } = Aglyn.useSite()\n const inputId = useId()\n const answerRef = useRef<HTMLInputElement>(null)\n const [products, setProducts] = useState<ListedProduct[] | null>(null)\n const [productId, setProductId] = useState(fixedProductId ?? '')\n const [detail, setDetail] = useState<ProductDetail | null>(null)\n const [picked, setPicked] = useState<Record<string, string>>({})\n\n // The store's products, or the one the author chose.\n useEffect(() => {\n if (!hostId) return\n let active = true\n const query = new URLSearchParams({\n hostId,\n ...(fixedProductId ? { ids: fixedProductId } : { sort: 'name', limit: String(PICKER_LIMIT) }),\n })\n void fetch(`/api/commerce/catalog?${query.toString()}`)\n .then((response) => (response.ok ? response.json() : { items: [] }))\n .then((payload) => {\n if (!active) return\n const items = Array.isArray(payload?.items) ? (payload.items as ListedProduct[]) : []\n setProducts(items)\n if (fixedProductId) setProductId(items[0]?.id ?? '')\n })\n .catch(() => active && setProducts([]))\n return () => {\n active = false\n }\n }, [hostId, fixedProductId])\n\n // The chosen product's options.\n const slug = products?.find((product) => product.id === productId)?.slug ?? ''\n useEffect(() => {\n setDetail(null)\n setPicked({})\n if (!hostId || !slug) return\n let active = true\n void fetch(`/api/commerce/product?hostId=${encodeURIComponent(hostId)}&slug=${encodeURIComponent(slug)}`)\n .then((response) => (response.ok ? response.json() : null))\n .then((payload) => {\n if (!active || !payload?.product) return\n const product = payload.product as ProductDetail\n setDetail({ ...product, options: product.options ?? [], variants: product.variants ?? [] })\n })\n .catch(() => undefined)\n return () => {\n active = false\n }\n }, [hostId, slug])\n\n const variantId = detail ? variantForOptions(detail, picked) : null\n const complete = Boolean(detail && variantId)\n const answer = complete && detail ? productFieldLabel(detail.name, picked) : ''\n const value = complete && detail\n ? encodeProductFieldValue({\n productId: detail.id,\n ...(variantId && variantId !== 'default' ? { variantId } : {}),\n ...(Object.keys(picked).length ? { options: picked } : {}),\n // Add-ons ride here as `modifiers` when the field sits in a product page's builder (AGL-4205).\n })\n : ''\n\n // Every change is announced, as a typed answer is, to anything listening on the form.\n const announced = useRef(answer)\n useEffect(() => {\n if (announced.current === answer) return\n announced.current = answer\n answerRef.current?.dispatchEvent(new Event('change', { bubbles: true }))\n }, [answer])\n\n const listed = useMemo(() => products ?? [], [products])\n // On the canvas there is no site to list from: it says what the visitor will pick from.\n const placeholder = !hostId\n ? 'Your store’s products'\n : products === null\n ? 'Loading products…'\n : listed.length\n ? 'Choose a product'\n : 'No products to choose from yet'\n\n return (\n <FormControl ref={ref} fullWidth required={Boolean(required)} {...rest}>\n <FormLabel htmlFor={inputId}>{label || 'Product'}</FormLabel>\n <Stack spacing={1.5} sx={{ mt: 1, position: 'relative' }}>\n {fixedProductId ? null : (\n <TextField\n id={inputId}\n select\n size=\"small\"\n fullWidth\n value={productId}\n onChange={(event) => setProductId(event.target.value)}\n disabled={!listed.length}\n slotProps={{\n select: {\n displayEmpty: true,\n renderValue: (selected: unknown) =>\n listed.find((product) => product.id === selected)?.name ?? (\n <Box component=\"span\" sx={{ color: 'text.secondary' }}>\n {placeholder}\n </Box>\n ),\n },\n }}\n >\n {listed.map((product) => (\n <MenuItem key={product.id} value={product.id}>\n {product.name}\n </MenuItem>\n ))}\n </TextField>\n )}\n {fixedProductId && detail ? <FormHelperText sx={{ mx: 0 }}>{detail.name}</FormHelperText> : null}\n {(detail?.options ?? []).map((option) => (\n <TextField\n key={option.name}\n select\n size=\"small\"\n fullWidth\n label={option.name}\n value={picked[option.name] ?? ''}\n onChange={(event) => setPicked((current) => ({ ...current, [option.name]: event.target.value }))}\n >\n {option.values.map((choice) => (\n <MenuItem key={choice} value={choice}>\n {choice}\n </MenuItem>\n ))}\n </TextField>\n ))}\n {detail && Object.keys(picked).length === detail.options.length && detail.options.length && !variantId ? (\n <FormHelperText error sx={{ mx: 0 }}>\n {'That combination isn’t one we offer. Pick another.'}\n </FormHelperText>\n ) : null}\n {/* The answer the form sends and the browser checks, and the exact choice beside it. */}\n <Box\n component=\"input\"\n ref={answerRef}\n type=\"text\"\n name={name}\n value={answer}\n required={Boolean(required)}\n onChange={() => undefined}\n tabIndex={-1}\n aria-hidden=\"true\"\n autoComplete=\"off\"\n sx={{ position: 'absolute', left: 0, bottom: 0, width: 1, height: '1px', p: 0, border: 0, opacity: 0, pointerEvents: 'none' }}\n />\n {value ? <input type=\"hidden\" name={formFieldDataKey(name)} value={value} readOnly /> : null}\n </Stack>\n </FormControl>\n )\n})\nStoreProductPicker.displayName = 'AglynStoreProductPicker'\n\n/** What the field posts for a product page's picks (AGL-4205): the line in words, and the exact choice. */\nexport function builderFieldValue(picks: ProductBuilderPicks): { answer: string; value: string } {\n if (!picks.ready) return { answer: '', value: '' }\n return {\n answer: builderPicksLabel(picks.productName, picks.options, picks.addOnNames, picks.quantity),\n value: encodeProductFieldValue({\n productId: picks.productId,\n ...(picks.variantId ? { variantId: picks.variantId } : {}),\n ...(Object.keys(picks.options).length ? { options: picks.options } : {}),\n ...(picks.modifiers.length ? { modifiers: picks.modifiers } : {}),\n ...(picks.quantity > 1 ? { quantity: picks.quantity } : {}),\n }),\n }\n}\n\n/**\n * The field inside a Product detail block (AGL-4205): the shopper already\n * picked on the page, so it lists those picks and posts them, and changes as\n * they do. Until every required choice is answered it posts nothing, so a\n * required field stops the form and says what is left to choose.\n */\nconst ProductBuilderAnswer = forwardRef<HTMLDivElement, ProductOptionsFieldProps & { picks: ProductBuilderPicks }>(\n (props, ref) => {\n const { name: rawName, label, productId: _fixed, required, picks, ...rest } = props\n const name = String(rawName ?? '').trim() || 'product'\n const labelId = useId()\n const answerRef = useRef<HTMLInputElement>(null)\n const { answer, value } = builderFieldValue(picks)\n const announced = useRef(answer)\n useEffect(() => {\n if (announced.current === answer) return\n announced.current = answer\n answerRef.current?.dispatchEvent(new Event('change', { bubbles: true }))\n }, [answer])\n const chosen = [\n ...Object.entries(picks.options).map(([option, picked]) => `${option}: ${picked}`),\n ...picks.addOnNames,\n ...(picks.quantity > 1 ? [`Quantity: ${picks.quantity}`] : []),\n ]\n return (\n <FormControl ref={ref} fullWidth required={Boolean(required)} {...rest}>\n <FormLabel id={labelId}>{label || 'Product'}</FormLabel>\n <Stack spacing={0.5} sx={{ mt: 1, position: 'relative' }} aria-labelledby={labelId}>\n <Typography variant=\"subtitle2\" component=\"p\">\n {picks.productName}\n </Typography>\n {chosen.map((line) => (\n <Typography key={line} variant=\"body2\" color=\"text.secondary\">\n {line}\n </Typography>\n ))}\n {picks.total ? (\n <Typography variant=\"body2\">{`Total: ${picks.total}`}</Typography>\n ) : null}\n <FormHelperText error={!picks.ready} sx={{ mx: 0 }}>\n {picks.ready ? 'Change your picks above and this follows.' : picks.problem || 'Finish your picks above.'}\n </FormHelperText>\n <Box\n component=\"input\"\n ref={answerRef}\n type=\"text\"\n name={name}\n value={answer}\n required={Boolean(required)}\n onChange={() => undefined}\n tabIndex={-1}\n aria-hidden=\"true\"\n autoComplete=\"off\"\n sx={{ position: 'absolute', left: 0, bottom: 0, width: 1, height: '1px', p: 0, border: 0, opacity: 0, pointerEvents: 'none' }}\n />\n {value ? <input type=\"hidden\" name={formFieldDataKey(name)} value={value} readOnly /> : null}\n </Stack>\n </FormControl>\n )\n },\n)\nProductBuilderAnswer.displayName = 'AglynProductBuilderAnswer'\n\n/**\n * The Product and options field's body: inside a Product detail block it\n * posts the shopper's picks there (AGL-4205), unless the author pinned it to\n * another product; anywhere else it asks for a product and its options.\n */\nconst ProductOptionsFieldBody = forwardRef<HTMLDivElement, ProductOptionsFieldProps>((props, ref) => {\n const picks = useContext(ProductBuilderContext)\n if (picks && (!props.productId || props.productId === picks.productId)) {\n return <ProductBuilderAnswer ref={ref} {...props} picks={picks} />\n }\n return <StoreProductPicker ref={ref} {...props} />\n})\nProductOptionsFieldBody.displayName = 'AglynProductOptionsFieldBody'\n\nexport default ProductOptionsFieldBody\n"],"names":["Aglyn","formFieldDataKey","builderPicksLabel","encodeProductFieldValue","productFieldLabel","Box","FormControl","FormHelperText","FormLabel","MenuItem","Stack","TextField","Typography","forwardRef","useContext","useEffect","useId","useMemo","useRef","useState","ProductBuilderContext","PICKER_LIMIT","variantForOptions","detail","picked","options","length","variants","id","some","option","name","match","find","variant","every","StoreProductPicker","props","ref","products","rawName","label","productId","fixedProductId","required","rest","String","trim","hostId","useSite","inputId","answerRef","setProducts","setProductId","setDetail","setPicked","active","query","URLSearchParams","ids","sort","limit","fetch","toString","then","response","ok","json","items","payload","Array","isArray","catch","slug","product","encodeURIComponent","undefined","variantId","complete","Boolean","answer","value","Object","keys","announced","current","dispatchEvent","Event","bubbles","listed","placeholder","fullWidth","htmlFor","spacing","sx","mt","position","select","size","onChange","event","target","disabled","slotProps","displayEmpty","renderValue","selected","component","color","map","mx","values","choice","error","type","tabIndex","aria-hidden","autoComplete","left","bottom","width","height","p","border","opacity","pointerEvents","input","readOnly","displayName","builderFieldValue","picks","ready","productName","addOnNames","quantity","modifiers","ProductBuilderAnswer","_fixed","labelId","chosen","entries","aria-labelledby","line","total","problem","ProductOptionsFieldBody"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,gBAAgB,QAAQ,qCAAiC;AAClE,SAASC,iBAAiB,EAAEC,uBAAuB,EAAEC,iBAAiB,QAAQ,qCAAiC;AAC/G,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,oBAAoB,+BAA8B;AACzD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,cAAc,yBAAwB;AAC7C,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,gBAAgB,2BAA0B;AACjD,SAASC,UAAU,EAAEC,UAAU,EAAEC,SAAS,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAC3F,SAASC,qBAAqB,QAAkC,+BAA2B;AAkB3F,wCAAwC,GACxC,MAAMC,eAAe;AAErB,sEAAsE,GACtE,OAAO,SAASC,kBACdC,MAAmD,EACnDC,MAAwC;;QAELD;IAAnC,IAAI,CAACA,OAAOE,OAAO,CAACC,MAAM,EAAE,gBAAOH,oBAAAA,OAAOI,QAAQ,CAAC,EAAE,qBAAlBJ,kBAAoBK,EAAE,mBAAI;IAC7D,IAAIL,OAAOE,OAAO,CAACI,IAAI,CAAC,CAACC,SAAW,CAACN,MAAM,CAACM,OAAOC,IAAI,CAAC,GAAG,OAAO;IAClE,MAAMC,QAAQT,OAAOI,QAAQ,CAACM,IAAI,CAAC,CAACC,UAClCX,OAAOE,OAAO,CAACU,KAAK,CAA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OAAO,CAACiB,MAAMC,KAAK;wBAAErC,IAAI;4BAAEgB,IAAI;wBAAE;kCAC9CoB,MAAMC,KAAK,GAAG,8CAA8CD,MAAMc,OAAO,IAAI;;kCAEhF,KAAC3I;wBACCsG,WAAU;wBACVrE,KAAKa;wBACL+D,MAAK;wBACLnF,MAAMA;wBACNkD,OAAOD;wBACPpC,UAAUmC,QAAQnC;wBAClBuD,UAAU,IAAMvB;wBAChBuC,UAAU,CAAC;wBACXC,eAAY;wBACZC,cAAa;wBACbvB,IAAI;4BAAEE,UAAU;4BAAYsB,MAAM;4BAAGC,QAAQ;4BAAGC,OAAO;4BAAGC,QAAQ;4BAAOC,GAAG;4BAAGC,QAAQ;4BAAGC,SAAS;4BAAGC,eAAe;wBAAO;;oBAE7H5C,sBAAQ,KAAC6C;wBAAMZ,MAAK;wBAASnF,MAAM9B,iBAAiB8B;wBAAOkD,OAAOA;wBAAO8C,QAAQ;yBAAM;;;;;AAIhG;AAEFS,qBAAqBR,WAAW,GAAG;AAEnC;;;;CAIC,GACD,MAAMiB,wCAA0BpI,WAAqD,CAACwB,OAAOC;IAC3F,MAAM4F,QAAQpH,WAAWM;IACzB,IAAI8G,SAAU,CAAA,CAAC7F,MAAMK,SAAS,IAAIL,MAAMK,SAAS,KAAKwF,MAAMxF,SAAS,AAAD,GAAI;QACtE,qBAAO,KAAC8F;YAAqBlG,KAAKA;WAASD;YAAO6F,OAAOA;;IAC3D;IACA,qBAAO,KAAC9F;QAAmBE,KAAKA;OAASD;AAC3C;AACA4G,wBAAwBjB,WAAW,GAAG;AAEtC,eAAeiB,wBAAuB"}
|
|
@@ -86,7 +86,7 @@ export const schema = {
|
|
|
86
86
|
{
|
|
87
87
|
name: 'productId',
|
|
88
88
|
label: 'Product',
|
|
89
|
-
description: 'Ask about one product only: the person picks its options. Leave it empty to let them pick from your store.',
|
|
89
|
+
description: 'Ask about one product only: the person picks its options. Leave it empty to let them pick from your store, or in a Product detail block to use the page’s picks.',
|
|
90
90
|
component: Aglyn.FieldComponentType.PRODUCT_SELECT
|
|
91
91
|
},
|
|
92
92
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-options-field.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\nimport * as Aglyn from '@aglyn/aglyn'\nimport { mdiPackageVariantClosed } from '@aglyn/shared-data-mdi'\nimport Box from '@mui/material/Box'\nimport CircularProgress from '@mui/material/CircularProgress'\nimport { forwardRef, lazy, Suspense } from 'react'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport { generatePresetId } from '../utils/generate-preset-id'\n\n/*\n * THE PRODUCT AND OPTIONS FIELD (AGL-4098): a form field that asks which of\n * the store's products, and which of its options, a person wants — on a\n * \"Request a quote\" form, say.\n *\n * It lives in Commerce because the products are Commerce's, and it is a form\n * field like any other: it knows nothing about the form around it and posts\n * plain strings under its name. Its answer is the product and options in\n * words (`Vinyl banner — 3 × 6 ft / Matte`); beside it, under `{name}__data`,\n * it posts the exact product, variant and options for this plugin to read\n * back when a quote is started from the request (`parseProductFieldValue`).\n * The forms plugin keeps that value apart from the answers a person reads.\n *\n * This shell is what a page loads until the field draws; the picker is a\n * chunk of its own. The component id is persisted in documents; never rename\n * it. The core's form reader restates it (`FORM_PLUGIN_ANSWER_ELEMENTS`).\n */\nexport const PRODUCT_OPTIONS_FIELD_ID: Aglyn.ComponentId = 'product-options-field'\n\nexport interface ProductOptionsFieldProps {\n /** What the product and options are sent as. */\n name?: string\n /** The question, above the picker. */\n label?: string\n /** One product to ask about; empty lets the person pick from the store. */\n productId?: string\n required?: boolean\n}\n\nconst ProductOptionsFieldBody = lazy(() => import('./product-options-field-body'))\n\n/** A product and its options, picked from the store; sent in words. */\nconst ProductOptionsField = forwardRef<HTMLDivElement, ProductOptionsFieldProps>((props, ref) => (\n <Suspense\n fallback={\n <Box sx={{ py: 1 }}>\n <CircularProgress size={20} aria-label=\"Loading the product field\" />\n </Box>\n }\n >\n <ProductOptionsFieldBody ref={ref} {...props} />\n </Suspense>\n))\nProductOptionsField.displayName = 'AglynProductOptionsField'\n\nexport const schema: Aglyn.ComponentSchema<ProductOptionsFieldProps> = {\n $id: PRODUCT_OPTIONS_FIELD_ID,\n pluginId: BUNDLE_ID,\n displayName: 'Product and options',\n description:\n 'A form field: the person picks one of your products and its options, such as size and finish. It arrives with the submission, and a quote started from it begins with that product.',\n category: Aglyn.ComponentCategory.FORMS,\n icon: { path: mdiPackageVariantClosed.path, sx: { color: 'info.main' } },\n flags: { selfClosing: Aglyn.FEATURE_FLAG.ENABLED },\n attributes: [\n {\n name: 'label',\n label: 'Label',\n description: 'The question above the picker, such as “What would you like priced?”.',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n {\n name: 'name',\n label: 'Field name',\n description: 'The name the choice is listed under in the Inbox and exports.',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n {\n name: 'productId',\n label: 'Product',\n description: 'Ask about one product only: the person picks its options. Leave it empty to let them pick from your store.',\n component: Aglyn.FieldComponentType.PRODUCT_SELECT,\n },\n {\n name: 'required',\n label: 'Required?',\n description: 'The form can’t be sent until a product (and each of its options) is picked.',\n component: Aglyn.FieldComponentType.SWITCH,\n },\n ],\n}\n\nexport const presets: Aglyn.PresetSchema[] = [\n {\n $id: generatePresetId(PRODUCT_OPTIONS_FIELD_ID),\n type: Aglyn.NodeType.PRESET,\n displayName: 'Product and options',\n pluginId: BUNDLE_ID,\n description: 'A product from your store and its options, for a quote request',\n category: Aglyn.ComponentCategory.FORMS,\n icon: { path: mdiPackageVariantClosed.path, sx: { color: 'info.main' } },\n data: {\n $id: null,\n componentId: PRODUCT_OPTIONS_FIELD_ID,\n pluginId: BUNDLE_ID,\n props: { name: 'product', label: 'Product', required: true },\n },\n },\n]\n\nexport default ProductOptionsField\n"],"names":["Aglyn","mdiPackageVariantClosed","Box","CircularProgress","forwardRef","lazy","Suspense","BUNDLE_ID","generatePresetId","PRODUCT_OPTIONS_FIELD_ID","ProductOptionsFieldBody","ProductOptionsField","props","ref","fallback","sx","py","size","aria-label","displayName","schema","$id","pluginId","description","category","ComponentCategory","FORMS","icon","path","color","flags","selfClosing","FEATURE_FLAG","ENABLED","attributes","name","label","component","FieldComponentType","TEXT_FIELD","PRODUCT_SELECT","SWITCH","presets","type","NodeType","PRESET","data","componentId","required"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,uBAAuB,QAAQ,yBAAwB;AAChE,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,sBAAsB,iCAAgC;AAC7D,SAASC,UAAU,EAAEC,IAAI,EAAEC,QAAQ,QAAQ,QAAO;AAClD,SAASC,SAAS,QAAQ,gCAA4B;AACtD,SAASC,gBAAgB,QAAQ,iCAA6B;AAE9D;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,2BAA8C,wBAAuB;AAYlF,MAAMC,wCAA0BL,KAAK,IAAM,MAAM,CAAC;AAElD,qEAAqE,GACrE,MAAMM,oCAAsBP,WAAqD,CAACQ,OAAOC,oBACvF,KAACP;QACCQ,wBACE,KAACZ;YAAIa,IAAI;gBAAEC,IAAI;YAAE;sBACf,cAAA,KAACb;gBAAiBc,MAAM;gBAAIC,cAAW;;;kBAI3C,cAAA,KAACR;YAAwBG,KAAKA;WAASD;;AAG3CD,oBAAoBQ,WAAW,GAAG;AAElC,OAAO,MAAMC,SAA0D;IACrEC,KAAKZ;IACLa,UAAUf;IACVY,aAAa;IACbI,aACE;IACFC,UAAUxB,MAAMyB,iBAAiB,CAACC,KAAK;IACvCC,MAAM;QAAEC,MAAM3B,wBAAwB2B,IAAI;QAAEb,IAAI;YAAEc,OAAO;QAAY;IAAE;IACvEC,OAAO;QAAEC,aAAa/B,MAAMgC,YAAY,CAACC,OAAO;IAAC;IACjDC,YAAY;QACV;YACEC,MAAM;YACNC,OAAO;YACPb,aAAa;YACbc,WAAWrC,MAAMsC,kBAAkB,CAACC,UAAU;QAChD;QACA;YACEJ,MAAM;YACNC,OAAO;YACPb,aAAa;YACbc,WAAWrC,MAAMsC,kBAAkB,CAACC,UAAU;QAChD;QACA;YACEJ,MAAM;YACNC,OAAO;YACPb,aAAa;YACbc,WAAWrC,MAAMsC,kBAAkB,CAACE,cAAc;QACpD;QACA;YACEL,MAAM;YACNC,OAAO;YACPb,aAAa;YACbc,WAAWrC,MAAMsC,kBAAkB,CAACG,MAAM;QAC5C;KACD;AACH,EAAC;AAED,OAAO,MAAMC,UAAgC;IAC3C;QACErB,KAAKb,iBAAiBC;QACtBkC,MAAM3C,MAAM4C,QAAQ,CAACC,MAAM;QAC3B1B,aAAa;QACbG,UAAUf;QACVgB,aAAa;QACbC,UAAUxB,MAAMyB,iBAAiB,CAACC,KAAK;QACvCC,MAAM;YAAEC,MAAM3B,wBAAwB2B,IAAI;YAAEb,IAAI;gBAAEc,OAAO;YAAY;QAAE;QACvEiB,MAAM;YACJzB,KAAK;YACL0B,aAAatC;YACba,UAAUf;YACVK,OAAO;gBAAEuB,MAAM;gBAAWC,OAAO;gBAAWY,UAAU;YAAK;QAC7D;IACF;CACD,CAAA;AAED,eAAerC,oBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-options-field.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\nimport * as Aglyn from '@aglyn/aglyn'\nimport { mdiPackageVariantClosed } from '@aglyn/shared-data-mdi'\nimport Box from '@mui/material/Box'\nimport CircularProgress from '@mui/material/CircularProgress'\nimport { forwardRef, lazy, Suspense } from 'react'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport { generatePresetId } from '../utils/generate-preset-id'\n\n/*\n * THE PRODUCT AND OPTIONS FIELD (AGL-4098): a form field that asks which of\n * the store's products, and which of its options, a person wants — on a\n * \"Request a quote\" form, say.\n *\n * It lives in Commerce because the products are Commerce's, and it is a form\n * field like any other: it knows nothing about the form around it and posts\n * plain strings under its name. Its answer is the product and options in\n * words (`Vinyl banner — 3 × 6 ft / Matte`); beside it, under `{name}__data`,\n * it posts the exact product, variant and options for this plugin to read\n * back when a quote is started from the request (`parseProductFieldValue`).\n * The forms plugin keeps that value apart from the answers a person reads.\n *\n * This shell is what a page loads until the field draws; the picker is a\n * chunk of its own. The component id is persisted in documents; never rename\n * it. The core's form reader restates it (`FORM_PLUGIN_ANSWER_ELEMENTS`).\n */\nexport const PRODUCT_OPTIONS_FIELD_ID: Aglyn.ComponentId = 'product-options-field'\n\nexport interface ProductOptionsFieldProps {\n /** What the product and options are sent as. */\n name?: string\n /** The question, above the picker. */\n label?: string\n /** One product to ask about; empty lets the person pick from the store. */\n productId?: string\n required?: boolean\n}\n\nconst ProductOptionsFieldBody = lazy(() => import('./product-options-field-body'))\n\n/** A product and its options, picked from the store; sent in words. */\nconst ProductOptionsField = forwardRef<HTMLDivElement, ProductOptionsFieldProps>((props, ref) => (\n <Suspense\n fallback={\n <Box sx={{ py: 1 }}>\n <CircularProgress size={20} aria-label=\"Loading the product field\" />\n </Box>\n }\n >\n <ProductOptionsFieldBody ref={ref} {...props} />\n </Suspense>\n))\nProductOptionsField.displayName = 'AglynProductOptionsField'\n\nexport const schema: Aglyn.ComponentSchema<ProductOptionsFieldProps> = {\n $id: PRODUCT_OPTIONS_FIELD_ID,\n pluginId: BUNDLE_ID,\n displayName: 'Product and options',\n description:\n 'A form field: the person picks one of your products and its options, such as size and finish. It arrives with the submission, and a quote started from it begins with that product.',\n category: Aglyn.ComponentCategory.FORMS,\n icon: { path: mdiPackageVariantClosed.path, sx: { color: 'info.main' } },\n flags: { selfClosing: Aglyn.FEATURE_FLAG.ENABLED },\n attributes: [\n {\n name: 'label',\n label: 'Label',\n description: 'The question above the picker, such as “What would you like priced?”.',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n {\n name: 'name',\n label: 'Field name',\n description: 'The name the choice is listed under in the Inbox and exports.',\n component: Aglyn.FieldComponentType.TEXT_FIELD,\n },\n {\n name: 'productId',\n label: 'Product',\n description: 'Ask about one product only: the person picks its options. Leave it empty to let them pick from your store, or in a Product detail block to use the page’s picks.',\n component: Aglyn.FieldComponentType.PRODUCT_SELECT,\n },\n {\n name: 'required',\n label: 'Required?',\n description: 'The form can’t be sent until a product (and each of its options) is picked.',\n component: Aglyn.FieldComponentType.SWITCH,\n },\n ],\n}\n\nexport const presets: Aglyn.PresetSchema[] = [\n {\n $id: generatePresetId(PRODUCT_OPTIONS_FIELD_ID),\n type: Aglyn.NodeType.PRESET,\n displayName: 'Product and options',\n pluginId: BUNDLE_ID,\n description: 'A product from your store and its options, for a quote request',\n category: Aglyn.ComponentCategory.FORMS,\n icon: { path: mdiPackageVariantClosed.path, sx: { color: 'info.main' } },\n data: {\n $id: null,\n componentId: PRODUCT_OPTIONS_FIELD_ID,\n pluginId: BUNDLE_ID,\n props: { name: 'product', label: 'Product', required: true },\n },\n },\n]\n\nexport default ProductOptionsField\n"],"names":["Aglyn","mdiPackageVariantClosed","Box","CircularProgress","forwardRef","lazy","Suspense","BUNDLE_ID","generatePresetId","PRODUCT_OPTIONS_FIELD_ID","ProductOptionsFieldBody","ProductOptionsField","props","ref","fallback","sx","py","size","aria-label","displayName","schema","$id","pluginId","description","category","ComponentCategory","FORMS","icon","path","color","flags","selfClosing","FEATURE_FLAG","ENABLED","attributes","name","label","component","FieldComponentType","TEXT_FIELD","PRODUCT_SELECT","SWITCH","presets","type","NodeType","PRESET","data","componentId","required"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,uBAAuB,QAAQ,yBAAwB;AAChE,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,sBAAsB,iCAAgC;AAC7D,SAASC,UAAU,EAAEC,IAAI,EAAEC,QAAQ,QAAQ,QAAO;AAClD,SAASC,SAAS,QAAQ,gCAA4B;AACtD,SAASC,gBAAgB,QAAQ,iCAA6B;AAE9D;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,2BAA8C,wBAAuB;AAYlF,MAAMC,wCAA0BL,KAAK,IAAM,MAAM,CAAC;AAElD,qEAAqE,GACrE,MAAMM,oCAAsBP,WAAqD,CAACQ,OAAOC,oBACvF,KAACP;QACCQ,wBACE,KAACZ;YAAIa,IAAI;gBAAEC,IAAI;YAAE;sBACf,cAAA,KAACb;gBAAiBc,MAAM;gBAAIC,cAAW;;;kBAI3C,cAAA,KAACR;YAAwBG,KAAKA;WAASD;;AAG3CD,oBAAoBQ,WAAW,GAAG;AAElC,OAAO,MAAMC,SAA0D;IACrEC,KAAKZ;IACLa,UAAUf;IACVY,aAAa;IACbI,aACE;IACFC,UAAUxB,MAAMyB,iBAAiB,CAACC,KAAK;IACvCC,MAAM;QAAEC,MAAM3B,wBAAwB2B,IAAI;QAAEb,IAAI;YAAEc,OAAO;QAAY;IAAE;IACvEC,OAAO;QAAEC,aAAa/B,MAAMgC,YAAY,CAACC,OAAO;IAAC;IACjDC,YAAY;QACV;YACEC,MAAM;YACNC,OAAO;YACPb,aAAa;YACbc,WAAWrC,MAAMsC,kBAAkB,CAACC,UAAU;QAChD;QACA;YACEJ,MAAM;YACNC,OAAO;YACPb,aAAa;YACbc,WAAWrC,MAAMsC,kBAAkB,CAACC,UAAU;QAChD;QACA;YACEJ,MAAM;YACNC,OAAO;YACPb,aAAa;YACbc,WAAWrC,MAAMsC,kBAAkB,CAACE,cAAc;QACpD;QACA;YACEL,MAAM;YACNC,OAAO;YACPb,aAAa;YACbc,WAAWrC,MAAMsC,kBAAkB,CAACG,MAAM;QAC5C;KACD;AACH,EAAC;AAED,OAAO,MAAMC,UAAgC;IAC3C;QACErB,KAAKb,iBAAiBC;QACtBkC,MAAM3C,MAAM4C,QAAQ,CAACC,MAAM;QAC3B1B,aAAa;QACbG,UAAUf;QACVgB,aAAa;QACbC,UAAUxB,MAAMyB,iBAAiB,CAACC,KAAK;QACvCC,MAAM;YAAEC,MAAM3B,wBAAwB2B,IAAI;YAAEb,IAAI;gBAAEc,OAAO;YAAY;QAAE;QACvEiB,MAAM;YACJzB,KAAK;YACL0B,aAAatC;YACba,UAAUf;YACVK,OAAO;gBAAEuB,MAAM;gBAAWC,OAAO;gBAAWY,UAAU;YAAK;QAC7D;IACF;CACD,CAAA;AAED,eAAerC,oBAAmB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import * as Aglyn from '@aglyn/aglyn';
|
|
18
|
+
/**
|
|
19
|
+
* How a product card draws its photo: `cover` fills the card's frame and
|
|
20
|
+
* crops what does not fit; `contain` shows the whole photo inside the same
|
|
21
|
+
* frame, so a wide or tall shot keeps its ends.
|
|
22
|
+
*/
|
|
23
|
+
export type ProductPhotoFit = 'cover' | 'contain';
|
|
24
|
+
/**
|
|
25
|
+
* The fit a stored value asks for. Anything but `contain` — no value, an
|
|
26
|
+
* older page, a value this build does not know — is `cover`, the way every
|
|
27
|
+
* card was drawn before the setting existed, so no existing site changes.
|
|
28
|
+
*/
|
|
29
|
+
export declare function productPhotoFit(value: unknown): ProductPhotoFit;
|
|
30
|
+
/**
|
|
31
|
+
* The photo's own styles for a fit. `contain` keeps the frame's size (the
|
|
32
|
+
* caller's aspect ratio or height), so the cards in a row stay aligned, and
|
|
33
|
+
* sits the photo on the theme's quiet neutral (the no-photo tile's colour)
|
|
34
|
+
* with a little room, so a transparent cut-out and a full shot both read as
|
|
35
|
+
* framed on purpose.
|
|
36
|
+
*/
|
|
37
|
+
export declare function productPhotoFitSx(fit: ProductPhotoFit): {
|
|
38
|
+
readonly objectFit: "contain";
|
|
39
|
+
readonly boxSizing: "border-box";
|
|
40
|
+
readonly p: 1.5;
|
|
41
|
+
readonly bgcolor: "action.hover";
|
|
42
|
+
} | {
|
|
43
|
+
readonly objectFit: "cover";
|
|
44
|
+
readonly boxSizing?: undefined;
|
|
45
|
+
readonly p?: undefined;
|
|
46
|
+
readonly bgcolor?: undefined;
|
|
47
|
+
};
|
|
48
|
+
/** The element setting both storefront card blocks carry. */
|
|
49
|
+
export declare const PRODUCT_PHOTO_FIT_ATTRIBUTE: Aglyn.AttributeSchema;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import * as Aglyn from "@aglyn/aglyn";
|
|
17
|
+
/**
|
|
18
|
+
* The fit a stored value asks for. Anything but `contain` — no value, an
|
|
19
|
+
* older page, a value this build does not know — is `cover`, the way every
|
|
20
|
+
* card was drawn before the setting existed, so no existing site changes.
|
|
21
|
+
*/ export function productPhotoFit(value) {
|
|
22
|
+
return value === 'contain' ? 'contain' : 'cover';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The photo's own styles for a fit. `contain` keeps the frame's size (the
|
|
26
|
+
* caller's aspect ratio or height), so the cards in a row stay aligned, and
|
|
27
|
+
* sits the photo on the theme's quiet neutral (the no-photo tile's colour)
|
|
28
|
+
* with a little room, so a transparent cut-out and a full shot both read as
|
|
29
|
+
* framed on purpose.
|
|
30
|
+
*/ export function productPhotoFitSx(fit) {
|
|
31
|
+
return fit === 'contain' ? {
|
|
32
|
+
objectFit: 'contain',
|
|
33
|
+
boxSizing: 'border-box',
|
|
34
|
+
p: 1.5,
|
|
35
|
+
bgcolor: 'action.hover'
|
|
36
|
+
} : {
|
|
37
|
+
objectFit: 'cover'
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** The element setting both storefront card blocks carry. */ export const PRODUCT_PHOTO_FIT_ATTRIBUTE = {
|
|
41
|
+
// Blank is `cover`, so a page that already places the block keeps its look.
|
|
42
|
+
name: 'photoFit',
|
|
43
|
+
label: 'Photo fit',
|
|
44
|
+
description: 'Fill the frame crops each photo to the card’s shape. Show the whole ' + 'photo fits it inside the card without cutting anything off.',
|
|
45
|
+
component: Aglyn.FieldComponentType.SELECT,
|
|
46
|
+
options: [
|
|
47
|
+
{
|
|
48
|
+
label: 'Fill the frame (crops to fit)',
|
|
49
|
+
value: 'cover'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
label: 'Show the whole photo',
|
|
53
|
+
value: 'contain'
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=product-photo-fit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-photo-fit.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 * as Aglyn from '@aglyn/aglyn'\n\n/**\n * How a product card draws its photo: `cover` fills the card's frame and\n * crops what does not fit; `contain` shows the whole photo inside the same\n * frame, so a wide or tall shot keeps its ends.\n */\nexport type ProductPhotoFit = 'cover' | 'contain'\n\n/**\n * The fit a stored value asks for. Anything but `contain` — no value, an\n * older page, a value this build does not know — is `cover`, the way every\n * card was drawn before the setting existed, so no existing site changes.\n */\nexport function productPhotoFit(value: unknown): ProductPhotoFit {\n return value === 'contain' ? 'contain' : 'cover'\n}\n\n/**\n * The photo's own styles for a fit. `contain` keeps the frame's size (the\n * caller's aspect ratio or height), so the cards in a row stay aligned, and\n * sits the photo on the theme's quiet neutral (the no-photo tile's colour)\n * with a little room, so a transparent cut-out and a full shot both read as\n * framed on purpose.\n */\nexport function productPhotoFitSx(fit: ProductPhotoFit) {\n return fit === 'contain'\n ? ({ objectFit: 'contain', boxSizing: 'border-box', p: 1.5, bgcolor: 'action.hover' } as const)\n : ({ objectFit: 'cover' } as const)\n}\n\n/** The element setting both storefront card blocks carry. */\nexport const PRODUCT_PHOTO_FIT_ATTRIBUTE: Aglyn.AttributeSchema = {\n // Blank is `cover`, so a page that already places the block keeps its look.\n name: 'photoFit',\n label: 'Photo fit',\n description:\n 'Fill the frame crops each photo to the card’s shape. Show the whole ' +\n 'photo fits it inside the card without cutting anything off.',\n component: Aglyn.FieldComponentType.SELECT,\n options: [\n { label: 'Fill the frame (crops to fit)', value: 'cover' },\n { label: 'Show the whole photo', value: 'contain' },\n ],\n}\n"],"names":["Aglyn","productPhotoFit","value","productPhotoFitSx","fit","objectFit","boxSizing","p","bgcolor","PRODUCT_PHOTO_FIT_ATTRIBUTE","name","label","description","component","FieldComponentType","SELECT","options"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AASrC;;;;CAIC,GACD,OAAO,SAASC,gBAAgBC,KAAc;IAC5C,OAAOA,UAAU,YAAY,YAAY;AAC3C;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,kBAAkBC,GAAoB;IACpD,OAAOA,QAAQ,YACV;QAAEC,WAAW;QAAWC,WAAW;QAAcC,GAAG;QAAKC,SAAS;IAAe,IACjF;QAAEH,WAAW;IAAQ;AAC5B;AAEA,2DAA2D,GAC3D,OAAO,MAAMI,8BAAqD;IAChE,4EAA4E;IAC5EC,MAAM;IACNC,OAAO;IACPC,aACE,yEACA;IACFC,WAAWb,MAAMc,kBAAkB,CAACC,MAAM;IAC1CC,SAAS;QACP;YAAEL,OAAO;YAAiCT,OAAO;QAAQ;QACzD;YAAES,OAAO;YAAwBT,OAAO;QAAU;KACnD;AACH,EAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ProductRestockNotifyProps {
|
|
2
|
+
hostId: string;
|
|
3
|
+
productId: string;
|
|
4
|
+
/** The site's fetch, which carries its App Check and session. */
|
|
5
|
+
siteFetch: (input: string, init?: RequestInit) => Promise<Response>;
|
|
6
|
+
}
|
|
7
|
+
/** An email field and "Notify me": the store emails the shopper when it is back. */
|
|
8
|
+
export declare function ProductRestockNotify(props: ProductRestockNotifyProps): import("react").JSX.Element;
|
|
9
|
+
export declare namespace ProductRestockNotify {
|
|
10
|
+
var displayName: string;
|
|
11
|
+
}
|
|
12
|
+
export default ProductRestockNotify;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ 'use client';
|
|
17
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
+
import Alert from "@mui/material/Alert";
|
|
19
|
+
import Box from "@mui/material/Box";
|
|
20
|
+
import Button from "@mui/material/Button";
|
|
21
|
+
import TextField from "@mui/material/TextField";
|
|
22
|
+
import { useState } from "react";
|
|
23
|
+
/** An email field and "Notify me": the store emails the shopper when it is back. */ export function ProductRestockNotify(props) {
|
|
24
|
+
const { hostId, productId, siteFetch } = props;
|
|
25
|
+
const [notifyEmail, setNotifyEmail] = useState('');
|
|
26
|
+
const [notifyState, setNotifyState] = useState('idle');
|
|
27
|
+
return notifyState === 'done' ? /*#__PURE__*/ _jsx(Alert, {
|
|
28
|
+
severity: "success",
|
|
29
|
+
sx: {
|
|
30
|
+
mb: 2
|
|
31
|
+
},
|
|
32
|
+
children: 'We will email you when it is back.'
|
|
33
|
+
}) : /*#__PURE__*/ _jsxs(Box, {
|
|
34
|
+
sx: {
|
|
35
|
+
display: 'flex',
|
|
36
|
+
gap: 1,
|
|
37
|
+
mb: 2
|
|
38
|
+
},
|
|
39
|
+
children: [
|
|
40
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
41
|
+
placeholder: "you@example.com",
|
|
42
|
+
type: "email",
|
|
43
|
+
// Third instance of the nameless-input defect (AGL-2392).
|
|
44
|
+
// Named for its job rather than "Email address": this row
|
|
45
|
+
// appears inside a product page that may also carry the
|
|
46
|
+
// newsletter block, and two fields both announced as
|
|
47
|
+
// "Email address" is barely better than none.
|
|
48
|
+
slotProps: {
|
|
49
|
+
htmlInput: {
|
|
50
|
+
'aria-label': 'Email address for back-in-stock alert'
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
value: notifyEmail,
|
|
54
|
+
onChange: (event)=>setNotifyEmail(event.target.value),
|
|
55
|
+
size: "small",
|
|
56
|
+
sx: {
|
|
57
|
+
flex: 1
|
|
58
|
+
}
|
|
59
|
+
}),
|
|
60
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
61
|
+
size: "small",
|
|
62
|
+
variant: "outlined",
|
|
63
|
+
disabled: !notifyEmail.trim(),
|
|
64
|
+
onClick: async ()=>{
|
|
65
|
+
const response = await siteFetch('/api/commerce/notify-restock', {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json'
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
hostId,
|
|
72
|
+
productId: productId,
|
|
73
|
+
email: notifyEmail
|
|
74
|
+
})
|
|
75
|
+
}).catch(()=>null);
|
|
76
|
+
if (response == null ? void 0 : response.ok) setNotifyState('done');
|
|
77
|
+
},
|
|
78
|
+
children: 'Notify me'
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
ProductRestockNotify.displayName = 'ProductRestockNotify';
|
|
84
|
+
export default ProductRestockNotify;
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=product-restock-notify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/product-restock-notify.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 Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport TextField from '@mui/material/TextField'\nimport { useState } from 'react'\n\n/*\n * THE BACK-IN-STOCK ALERT on a product page, in its own chunk (split out of\n * the Product detail block for AGL-4205): only a page showing a sold-out\n * variant downloads it.\n */\n\nexport interface ProductRestockNotifyProps {\n hostId: string\n productId: string\n /** The site's fetch, which carries its App Check and session. */\n siteFetch: (input: string, init?: RequestInit) => Promise<Response>\n}\n\n/** An email field and \"Notify me\": the store emails the shopper when it is back. */\nexport function ProductRestockNotify(props: ProductRestockNotifyProps) {\n const { hostId, productId, siteFetch } = props\n const [notifyEmail, setNotifyEmail] = useState('')\n const [notifyState, setNotifyState] = useState<'idle' | 'done'>('idle')\n return notifyState === 'done' ? (\n <Alert severity=\"success\" sx={{ mb: 2 }}>\n {'We will email you when it is back.'}\n </Alert>\n ) : (\n <Box sx={{ display: 'flex', gap: 1, mb: 2 }}>\n <TextField\n placeholder=\"you@example.com\"\n type=\"email\"\n // Third instance of the nameless-input defect (AGL-2392).\n // Named for its job rather than \"Email address\": this row\n // appears inside a product page that may also carry the\n // newsletter block, and two fields both announced as\n // \"Email address\" is barely better than none.\n slotProps={{\n htmlInput: {\n 'aria-label': 'Email address for back-in-stock alert',\n },\n }}\n value={notifyEmail}\n onChange={(event) => setNotifyEmail(event.target.value)}\n size=\"small\"\n sx={{ flex: 1 }}\n />\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={!notifyEmail.trim()}\n onClick={async () => {\n const response = await siteFetch('/api/commerce/notify-restock', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n hostId,\n productId: productId,\n email: notifyEmail,\n }),\n }).catch(() => null)\n if (response?.ok) setNotifyState('done')\n }}\n >\n {'Notify me'}\n </Button>\n </Box>\n )\n}\n\nProductRestockNotify.displayName = 'ProductRestockNotify'\n\nexport default ProductRestockNotify\n"],"names":["Alert","Box","Button","TextField","useState","ProductRestockNotify","props","hostId","productId","siteFetch","notifyEmail","setNotifyEmail","notifyState","setNotifyState","severity","sx","mb","display","gap","placeholder","type","slotProps","htmlInput","value","onChange","event","target","size","flex","variant","disabled","trim","onClick","response","method","headers","body","JSON","stringify","email","catch","ok","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,OAAOA,WAAW,sBAAqB;AACvC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,YAAY,uBAAsB;AACzC,OAAOC,eAAe,0BAAyB;AAC/C,SAASC,QAAQ,QAAQ,QAAO;AAehC,kFAAkF,GAClF,OAAO,SAASC,qBAAqBC,KAAgC;IACnE,MAAM,EAAEC,MAAM,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGH;IACzC,MAAM,CAACI,aAAaC,eAAe,GAAGP,SAAS;IAC/C,MAAM,CAACQ,aAAaC,eAAe,GAAGT,SAA0B;IAChE,OAAOQ,gBAAgB,uBACrB,KAACZ;QAAMc,UAAS;QAAUC,IAAI;YAAEC,IAAI;QAAE;kBACnC;uBAGH,MAACf;QAAIc,IAAI;YAAEE,SAAS;YAAQC,KAAK;YAAGF,IAAI;QAAE;;0BACxC,KAACb;gBACCgB,aAAY;gBACZC,MAAK;gBACL,0DAA0D;gBAC1D,0DAA0D;gBAC1D,wDAAwD;gBACxD,qDAAqD;gBACrD,8CAA8C;gBAC9CC,WAAW;oBACTC,WAAW;wBACT,cAAc;oBAChB;gBACF;gBACAC,OAAOb;gBACPc,UAAU,CAACC,QAAUd,eAAec,MAAMC,MAAM,CAACH,KAAK;gBACtDI,MAAK;gBACLZ,IAAI;oBAAEa,MAAM;gBAAE;;0BAEhB,KAAC1B;gBACCyB,MAAK;gBACLE,SAAQ;gBACRC,UAAU,CAACpB,YAAYqB,IAAI;gBAC3BC,SAAS;oBACP,MAAMC,WAAW,MAAMxB,UAAU,gCAAgC;wBAC/DyB,QAAQ;wBACRC,SAAS;4BAAE,gBAAgB;wBAAmB;wBAC9CC,MAAMC,KAAKC,SAAS,CAAC;4BACnB/B;4BACAC,WAAWA;4BACX+B,OAAO7B;wBACT;oBACF,GAAG8B,KAAK,CAAC,IAAM;oBACf,IAAIP,4BAAAA,SAAUQ,EAAE,EAAE5B,eAAe;gBACnC;0BAEC;;;;AAIT;AAEAR,qBAAqBqC,WAAW,GAAG;AAEnC,eAAerC,qBAAoB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type QuotePageView } from '../model';
|
|
2
|
+
/** The page's own fetch: the site's API, with the site's preview rules. */
|
|
3
|
+
type SiteFetch = (input: string, init?: RequestInit) => Promise<Response>;
|
|
4
|
+
export interface QuoteMessagesPanelProps {
|
|
5
|
+
view: QuotePageView;
|
|
6
|
+
hostId: string;
|
|
7
|
+
quoteId: string;
|
|
8
|
+
token: string;
|
|
9
|
+
siteFetch: SiteFetch;
|
|
10
|
+
/** The link was replaced. */
|
|
11
|
+
onReplaced: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The customer's conversation with the business about the quote (AGL-4207),
|
|
15
|
+
* on the quote page: what the business replied from the quote, what the
|
|
16
|
+
* customer wrote here, and a box to write more. The business is told in
|
|
17
|
+
* Aglyn and by email, and answers by email, in the same conversation as the
|
|
18
|
+
* quote. The same composer as the Inbox's reply (`ReplyComposer`).
|
|
19
|
+
*/
|
|
20
|
+
export declare function QuoteMessagesPanel(props: QuoteMessagesPanelProps): import("react").JSX.Element;
|
|
21
|
+
export default QuoteMessagesPanel;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ 'use client';
|
|
17
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
+
import { VISITOR_UPLOAD_HONEYPOT_FIELD } from "@aglyn/aglyn/app-utils/visitor-upload";
|
|
19
|
+
import { ReplyComposer, ReplyThread } from "@aglyn/shared-ui-jsx/components/reply-composer.component";
|
|
20
|
+
import Alert from "@mui/material/Alert";
|
|
21
|
+
import Box from "@mui/material/Box";
|
|
22
|
+
import Paper from "@mui/material/Paper";
|
|
23
|
+
import Stack from "@mui/material/Stack";
|
|
24
|
+
import Typography from "@mui/material/Typography";
|
|
25
|
+
import { useCallback, useRef, useState } from "react";
|
|
26
|
+
import { QUOTE_MESSAGE_MAX } from "../model/index.js";
|
|
27
|
+
const newKey = ()=>{
|
|
28
|
+
var _ref;
|
|
29
|
+
var _globalThis_crypto_randomUUID, _globalThis_crypto;
|
|
30
|
+
return (_ref = (_globalThis_crypto = globalThis.crypto) == null ? void 0 : (_globalThis_crypto_randomUUID = _globalThis_crypto.randomUUID) == null ? void 0 : _globalThis_crypto_randomUUID.call(_globalThis_crypto)) != null ? _ref : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The customer's conversation with the business about the quote (AGL-4207),
|
|
34
|
+
* on the quote page: what the business replied from the quote, what the
|
|
35
|
+
* customer wrote here, and a box to write more. The business is told in
|
|
36
|
+
* Aglyn and by email, and answers by email, in the same conversation as the
|
|
37
|
+
* quote. The same composer as the Inbox's reply (`ReplyComposer`).
|
|
38
|
+
*/ export function QuoteMessagesPanel(props) {
|
|
39
|
+
var _view_messages;
|
|
40
|
+
const { view, hostId, quoteId, token, siteFetch, onReplaced } = props;
|
|
41
|
+
const [messages, setMessages] = useState((_view_messages = view.messages) != null ? _view_messages : []);
|
|
42
|
+
const [seenView, setSeenView] = useState(view);
|
|
43
|
+
const [message, setMessage] = useState('');
|
|
44
|
+
const [sending, setSending] = useState(false);
|
|
45
|
+
const [error, setError] = useState('');
|
|
46
|
+
const [sent, setSent] = useState(false);
|
|
47
|
+
// Whatever a bot types into the hidden field, sent as typed.
|
|
48
|
+
const [honeypot, setHoneypot] = useState('');
|
|
49
|
+
const attempt = useRef('');
|
|
50
|
+
const business = view.storeName || 'the business';
|
|
51
|
+
const Business = `${business.charAt(0).toUpperCase()}${business.slice(1)}`;
|
|
52
|
+
// A newer view of the page (an answer, a reload) carries the conversation as it stands.
|
|
53
|
+
if (seenView !== view) {
|
|
54
|
+
var _view_messages1;
|
|
55
|
+
setSeenView(view);
|
|
56
|
+
setMessages((_view_messages1 = view.messages) != null ? _view_messages1 : []);
|
|
57
|
+
}
|
|
58
|
+
const send = useCallback(async ()=>{
|
|
59
|
+
if (sending || !message.trim()) return;
|
|
60
|
+
setSending(true);
|
|
61
|
+
setError('');
|
|
62
|
+
setSent(false);
|
|
63
|
+
// One key per message: a retry of the same press is answered from the first.
|
|
64
|
+
if (!attempt.current) attempt.current = newKey();
|
|
65
|
+
try {
|
|
66
|
+
var _payload_error;
|
|
67
|
+
const response = await siteFetch('/api/commerce/quote-message', {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
'Idempotency-Key': attempt.current
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify({
|
|
74
|
+
hostId,
|
|
75
|
+
q: quoteId,
|
|
76
|
+
t: token,
|
|
77
|
+
message: message.trim(),
|
|
78
|
+
[VISITOR_UPLOAD_HONEYPOT_FIELD]: honeypot
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
const payload = await response.json().catch(()=>({}));
|
|
82
|
+
attempt.current = '';
|
|
83
|
+
if (response.ok && Array.isArray(payload['messages'])) {
|
|
84
|
+
setMessages(payload['messages']);
|
|
85
|
+
setMessage('');
|
|
86
|
+
setSent(true);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (payload['replaced']) return onReplaced();
|
|
90
|
+
setError(String((_payload_error = payload['error']) != null ? _payload_error : 'Your message could not be sent. Try again.'));
|
|
91
|
+
} catch (unused) {
|
|
92
|
+
setError('Your message could not be sent. Check your connection and try again.');
|
|
93
|
+
} finally{
|
|
94
|
+
setSending(false);
|
|
95
|
+
}
|
|
96
|
+
}, [
|
|
97
|
+
sending,
|
|
98
|
+
message,
|
|
99
|
+
siteFetch,
|
|
100
|
+
hostId,
|
|
101
|
+
quoteId,
|
|
102
|
+
token,
|
|
103
|
+
honeypot,
|
|
104
|
+
onReplaced
|
|
105
|
+
]);
|
|
106
|
+
// An invoice has no conversation; a proof waiting on a sign-in keeps its conversation behind it too.
|
|
107
|
+
if (view.kind !== 'quote' || view.proofAccess && view.proofAccess !== 'open') return null;
|
|
108
|
+
return /*#__PURE__*/ _jsx(Paper, {
|
|
109
|
+
variant: "outlined",
|
|
110
|
+
sx: {
|
|
111
|
+
p: {
|
|
112
|
+
xs: 2,
|
|
113
|
+
sm: 3
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"data-quote-messages": "",
|
|
117
|
+
children: /*#__PURE__*/ _jsxs(Stack, {
|
|
118
|
+
spacing: 2,
|
|
119
|
+
children: [
|
|
120
|
+
/*#__PURE__*/ _jsxs(Stack, {
|
|
121
|
+
spacing: 0.5,
|
|
122
|
+
children: [
|
|
123
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
124
|
+
variant: "h6",
|
|
125
|
+
component: "h2",
|
|
126
|
+
children: 'Messages'
|
|
127
|
+
}),
|
|
128
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
129
|
+
variant: "body2",
|
|
130
|
+
color: "text.secondary",
|
|
131
|
+
children: `Questions about your ${view.proofOnly ? 'proof' : 'quote'}? Write to ${business} here.`
|
|
132
|
+
})
|
|
133
|
+
]
|
|
134
|
+
}),
|
|
135
|
+
/*#__PURE__*/ _jsx(ReplyThread, {
|
|
136
|
+
title: "Your conversation",
|
|
137
|
+
messages: messages.map((entry)=>({
|
|
138
|
+
id: entry.id,
|
|
139
|
+
atMs: entry.atMs,
|
|
140
|
+
// The business's words stand out on the customer's page.
|
|
141
|
+
direction: entry.from === 'business' ? 'in' : 'out',
|
|
142
|
+
label: entry.from === 'business' ? `${Business} wrote` : 'You wrote',
|
|
143
|
+
body: entry.body
|
|
144
|
+
}))
|
|
145
|
+
}),
|
|
146
|
+
/*#__PURE__*/ _jsx(Box, {
|
|
147
|
+
component: "input",
|
|
148
|
+
type: "text",
|
|
149
|
+
name: VISITOR_UPLOAD_HONEYPOT_FIELD,
|
|
150
|
+
tabIndex: -1,
|
|
151
|
+
autoComplete: "off",
|
|
152
|
+
"aria-hidden": "true",
|
|
153
|
+
value: honeypot,
|
|
154
|
+
onChange: (event)=>setHoneypot(event.target.value),
|
|
155
|
+
sx: {
|
|
156
|
+
position: 'absolute',
|
|
157
|
+
left: '-100vw',
|
|
158
|
+
width: 0,
|
|
159
|
+
height: 0,
|
|
160
|
+
opacity: 0
|
|
161
|
+
}
|
|
162
|
+
}),
|
|
163
|
+
/*#__PURE__*/ _jsx(ReplyComposer, {
|
|
164
|
+
to: Business,
|
|
165
|
+
message: message,
|
|
166
|
+
onMessageChange: (value)=>{
|
|
167
|
+
setMessage(value);
|
|
168
|
+
setSent(false);
|
|
169
|
+
},
|
|
170
|
+
messageMax: QUOTE_MESSAGE_MAX,
|
|
171
|
+
messagePlaceholder: `Write to ${business}`,
|
|
172
|
+
note: `${Business} gets your message right away and answers you by email.`,
|
|
173
|
+
busy: sending,
|
|
174
|
+
onSend: ()=>void send(),
|
|
175
|
+
sendLabel: "Send message"
|
|
176
|
+
}),
|
|
177
|
+
sent ? /*#__PURE__*/ _jsx(Alert, {
|
|
178
|
+
severity: "success",
|
|
179
|
+
children: `Sent. ${Business} will get back to you.`
|
|
180
|
+
}) : null,
|
|
181
|
+
error ? /*#__PURE__*/ _jsx(Alert, {
|
|
182
|
+
severity: "error",
|
|
183
|
+
children: error
|
|
184
|
+
}) : null
|
|
185
|
+
]
|
|
186
|
+
})
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
export default QuoteMessagesPanel;
|
|
190
|
+
|
|
191
|
+
//# sourceMappingURL=quote-messages-panel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/quote-messages-panel.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 { VISITOR_UPLOAD_HONEYPOT_FIELD } from '@aglyn/aglyn/app-utils/visitor-upload'\nimport { ReplyComposer, ReplyThread } from '@aglyn/shared-ui-jsx/components/reply-composer.component'\nimport Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport Paper from '@mui/material/Paper'\nimport Stack from '@mui/material/Stack'\nimport Typography from '@mui/material/Typography'\nimport { useCallback, useRef, useState, type ChangeEvent } from 'react'\nimport { QUOTE_MESSAGE_MAX, type QuotePageMessage, type QuotePageView } from '../model'\n\n/** The page's own fetch: the site's API, with the site's preview rules. */\ntype SiteFetch = (input: string, init?: RequestInit) => Promise<Response>\n\nexport interface QuoteMessagesPanelProps {\n view: QuotePageView\n hostId: string\n quoteId: string\n token: string\n siteFetch: SiteFetch\n /** The link was replaced. */\n onReplaced: () => void\n}\n\nconst newKey = () => globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`\n\n/**\n * The customer's conversation with the business about the quote (AGL-4207),\n * on the quote page: what the business replied from the quote, what the\n * customer wrote here, and a box to write more. The business is told in\n * Aglyn and by email, and answers by email, in the same conversation as the\n * quote. The same composer as the Inbox's reply (`ReplyComposer`).\n */\nexport function QuoteMessagesPanel(props: QuoteMessagesPanelProps) {\n const { view, hostId, quoteId, token, siteFetch, onReplaced } = props\n const [messages, setMessages] = useState<QuotePageMessage[]>(view.messages ?? [])\n const [seenView, setSeenView] = useState(view)\n const [message, setMessage] = useState('')\n const [sending, setSending] = useState(false)\n const [error, setError] = useState('')\n const [sent, setSent] = useState(false)\n // Whatever a bot types into the hidden field, sent as typed.\n const [honeypot, setHoneypot] = useState('')\n const attempt = useRef('')\n const business = view.storeName || 'the business'\n const Business = `${business.charAt(0).toUpperCase()}${business.slice(1)}`\n\n // A newer view of the page (an answer, a reload) carries the conversation as it stands.\n if (seenView !== view) {\n setSeenView(view)\n setMessages(view.messages ?? [])\n }\n\n const send = useCallback(async () => {\n if (sending || !message.trim()) return\n setSending(true)\n setError('')\n setSent(false)\n // One key per message: a retry of the same press is answered from the first.\n if (!attempt.current) attempt.current = newKey()\n try {\n const response = await siteFetch('/api/commerce/quote-message', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'Idempotency-Key': attempt.current },\n body: JSON.stringify({ hostId, q: quoteId, t: token, message: message.trim(), [VISITOR_UPLOAD_HONEYPOT_FIELD]: honeypot }),\n })\n const payload = (await response.json().catch(() => ({}))) as Record<string, any>\n attempt.current = ''\n if (response.ok && Array.isArray(payload['messages'])) {\n setMessages(payload['messages'] as QuotePageMessage[])\n setMessage('')\n setSent(true)\n return\n }\n if (payload['replaced']) return onReplaced()\n setError(String(payload['error'] ?? 'Your message could not be sent. Try again.'))\n } catch {\n setError('Your message could not be sent. Check your connection and try again.')\n } finally {\n setSending(false)\n }\n }, [sending, message, siteFetch, hostId, quoteId, token, honeypot, onReplaced])\n\n // An invoice has no conversation; a proof waiting on a sign-in keeps its conversation behind it too.\n if (view.kind !== 'quote' || (view.proofAccess && view.proofAccess !== 'open')) return null\n\n return (\n <Paper variant=\"outlined\" sx={{ p: { xs: 2, sm: 3 } }} data-quote-messages=\"\">\n <Stack spacing={2}>\n <Stack spacing={0.5}>\n <Typography variant=\"h6\" component=\"h2\">\n {'Messages'}\n </Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`Questions about your ${view.proofOnly ? 'proof' : 'quote'}? Write to ${business} here.`}\n </Typography>\n </Stack>\n <ReplyThread\n title=\"Your conversation\"\n messages={messages.map((entry) => ({\n id: entry.id,\n atMs: entry.atMs,\n // The business's words stand out on the customer's page.\n direction: entry.from === 'business' ? ('in' as const) : ('out' as const),\n label: entry.from === 'business' ? `${Business} wrote` : 'You wrote',\n body: entry.body,\n }))}\n />\n {/* Honeypot: people never see or fill this. */}\n <Box\n component=\"input\"\n type=\"text\"\n name={VISITOR_UPLOAD_HONEYPOT_FIELD}\n tabIndex={-1}\n autoComplete=\"off\"\n aria-hidden=\"true\"\n value={honeypot}\n onChange={(event: ChangeEvent<HTMLInputElement>) => setHoneypot(event.target.value)}\n sx={{ position: 'absolute', left: '-100vw', width: 0, height: 0, opacity: 0 }}\n />\n <ReplyComposer\n to={Business}\n message={message}\n onMessageChange={(value) => {\n setMessage(value)\n setSent(false)\n }}\n messageMax={QUOTE_MESSAGE_MAX}\n messagePlaceholder={`Write to ${business}`}\n note={`${Business} gets your message right away and answers you by email.`}\n busy={sending}\n onSend={() => void send()}\n sendLabel=\"Send message\"\n />\n {sent ? <Alert severity=\"success\">{`Sent. ${Business} will get back to you.`}</Alert> : null}\n {error ? <Alert severity=\"error\">{error}</Alert> : null}\n </Stack>\n </Paper>\n )\n}\n\nexport default QuoteMessagesPanel\n"],"names":["VISITOR_UPLOAD_HONEYPOT_FIELD","ReplyComposer","ReplyThread","Alert","Box","Paper","Stack","Typography","useCallback","useRef","useState","QUOTE_MESSAGE_MAX","newKey","globalThis","crypto","randomUUID","Date","now","Math","random","toString","slice","QuoteMessagesPanel","props","view","hostId","quoteId","token","siteFetch","onReplaced","messages","setMessages","seenView","setSeenView","message","setMessage","sending","setSending","error","setError","sent","setSent","honeypot","setHoneypot","attempt","business","storeName","Business","charAt","toUpperCase","send","trim","current","payload","response","method","headers","body","JSON","stringify","q","t","json","catch","ok","Array","isArray","String","kind","proofAccess","variant","sx","p","xs","sm","data-quote-messages","spacing","component","color","proofOnly","title","map","entry","id","atMs","direction","from","label","type","name","tabIndex","autoComplete","aria-hidden","value","onChange","event","target","position","left","width","height","opacity","to","onMessageChange","messageMax","messagePlaceholder","note","busy","onSend","sendLabel","severity"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SAASA,6BAA6B,QAAQ,wCAAuC;AACrF,SAASC,aAAa,EAAEC,WAAW,QAAQ,2DAA0D;AACrG,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,SAAS,oBAAmB;AACnC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