@dropins/storefront-pdp 3.0.3-beta2 → 3.0.3-beta3
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.
|
@@ -7,6 +7,7 @@ type DefaultSlotContext = {
|
|
|
7
7
|
};
|
|
8
8
|
export interface ProductAttributesProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
9
|
scope?: string;
|
|
10
|
+
formatValue?: (value: string, id: string, label: string) => string;
|
|
10
11
|
slots?: {
|
|
11
12
|
Attributes?: SlotProps<DefaultSlotContext>;
|
|
12
13
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2026 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsxs as
|
|
3
|
+
import{jsxs as u,jsx as a}from"@dropins/tools/preact-jsx-runtime.js";import{useState as f,useMemo as L,useEffect as _}from"@dropins/tools/preact-compat.js";import{classes as j,Slot as C}from"@dropins/tools/lib.js";import{events as p}from"@dropins/tools/event-bus.js";import{i as I,t as M}from"../chunks/date.js";import{g as N}from"../chunks/getFetchedProductData.js";import{useText as T}from"@dropins/tools/i18n.js";import{c as y}from"../chunks/fetchProductData.js";import"../fragments.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/getProductConfigurationValues.js";import"../chunks/isProductConfigurationValid.js";const F=({initialData:b=null,scope:i,children:H,slots:e,formatValue:c,...m})=>{var s;const d=T("PDP.Product.Details.label").label,{globalLocale:g="en-US"}=y.getConfig(),[D,h]=f(g),[r,S]=f(b),x=L(()=>({data:r}),[r]);return _(()=>{const t=p.on("pdp/data",S,{scope:i}),o=p.on("locale",h);return()=>{t==null||t.off(),o==null||o.off()}},[i]),r?u("div",{...m,className:j(["pdp-attributes",m.className]),children:[d,e!=null&&e.Attributes?a(C,{name:"Attributes",slot:e==null?void 0:e.Attributes,context:{...x}}):a("ul",{children:(s=r==null?void 0:r.attributes)==null?void 0:s.map(({id:t,label:o,value:n},P)=>{if(t!=null&&t.startsWith("ac_")||!n)return null;const l=I(n)?M(n,D):n.toString(),A=c?c(l,t,o):l;return u("li",{children:[o,": ",a("span",{dangerouslySetInnerHTML:{__html:A}})]},`attribute-${P}`)})})]}):null};F.getInitialData=N;export{F as ProductAttributes,F as default};
|
|
4
4
|
//# sourceMappingURL=ProductAttributes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductAttributes.js","sources":["/@dropins/storefront-pdp/src/containers/ProductAttributes/ProductAttributes.tsx"],"sourcesContent":["/**\n * ADOBE CONFIDENTIAL\n * __________________\n * Copyright 2024 Adobe\n * All Rights Reserved.\n * __________________\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n */\n\nimport { HTMLAttributes, useEffect, useState, useMemo } from 'preact/compat';\nimport { classes, Container, Slot, SlotProps } from '@adobe-commerce/elsie/lib';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { events } from '@adobe-commerce/event-bus';\nimport { ProductModel } from '@/pdp/data/models';\nimport { isDateValid, toDateString } from '@/pdp/lib/date';\nimport { config, getFetchedProductData } from '@/pdp/api';\n\ntype DefaultSlotContext = {\n data: ProductModel | null;\n};\n\nexport interface ProductAttributesProps extends HTMLAttributes<HTMLDivElement> {\n scope?: string;\n slots?: {\n Attributes?: SlotProps<DefaultSlotContext>;\n };\n}\n\nexport const ProductAttributes: Container<\n ProductAttributesProps,\n ProductModel | null\n> = ({ initialData = null, scope, children, slots, ...props }) => {\n const DetailsLabel = useText('PDP.Product.Details.label').label;\n const { globalLocale = 'en-US' } = config.getConfig();\n\n const [locale, setLocale] = useState<string>(globalLocale);\n const [data, setData] = useState<ProductModel | null>(initialData);\n\n const defaultSlotContext: DefaultSlotContext = useMemo(\n () => ({ data }),\n [data]\n );\n\n // Listen for events\n useEffect(() => {\n const dataEvent = events.on('pdp/data', setData, { scope });\n const localeEvent = events.on('locale', setLocale);\n\n return () => {\n dataEvent?.off();\n localeEvent?.off();\n };\n }, [scope]);\n\n if (!data) return null;\n\n return (\n <div {...props} className={classes(['pdp-attributes', props.className])}>\n {DetailsLabel}\n {slots?.Attributes ? (\n <Slot\n name=\"Attributes\"\n slot={slots?.Attributes}\n context={{ ...defaultSlotContext }}\n />\n ) : (\n <ul>\n {data?.attributes?.map(\n (\n { id, label, value }: { id: string; label: string; value: any },\n index: number\n ) => {\n if (id?.startsWith('ac_') || !value) {\n return null;\n }\n\n const
|
|
1
|
+
{"version":3,"file":"ProductAttributes.js","sources":["/@dropins/storefront-pdp/src/containers/ProductAttributes/ProductAttributes.tsx"],"sourcesContent":["/**\n * ADOBE CONFIDENTIAL\n * __________________\n * Copyright 2024 Adobe\n * All Rights Reserved.\n * __________________\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n */\n\nimport { HTMLAttributes, useEffect, useState, useMemo } from 'preact/compat';\nimport { classes, Container, Slot, SlotProps } from '@adobe-commerce/elsie/lib';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { events } from '@adobe-commerce/event-bus';\nimport { ProductModel } from '@/pdp/data/models';\nimport { isDateValid, toDateString } from '@/pdp/lib/date';\nimport { config, getFetchedProductData } from '@/pdp/api';\n\ntype DefaultSlotContext = {\n data: ProductModel | null;\n};\n\nexport interface ProductAttributesProps extends HTMLAttributes<HTMLDivElement> {\n scope?: string;\n formatValue?: (value: string, id: string, label: string) => string;\n slots?: {\n Attributes?: SlotProps<DefaultSlotContext>;\n };\n}\n\nexport const ProductAttributes: Container<\n ProductAttributesProps,\n ProductModel | null\n> = ({ initialData = null, scope, children, slots, formatValue, ...props }) => {\n const DetailsLabel = useText('PDP.Product.Details.label').label;\n const { globalLocale = 'en-US' } = config.getConfig();\n\n const [locale, setLocale] = useState<string>(globalLocale);\n const [data, setData] = useState<ProductModel | null>(initialData);\n\n const defaultSlotContext: DefaultSlotContext = useMemo(\n () => ({ data }),\n [data]\n );\n\n // Listen for events\n useEffect(() => {\n const dataEvent = events.on('pdp/data', setData, { scope });\n const localeEvent = events.on('locale', setLocale);\n\n return () => {\n dataEvent?.off();\n localeEvent?.off();\n };\n }, [scope]);\n\n if (!data) return null;\n\n return (\n <div {...props} className={classes(['pdp-attributes', props.className])}>\n {DetailsLabel}\n {slots?.Attributes ? (\n <Slot\n name=\"Attributes\"\n slot={slots?.Attributes}\n context={{ ...defaultSlotContext }}\n />\n ) : (\n <ul>\n {data?.attributes?.map(\n (\n { id, label, value }: { id: string; label: string; value: any },\n index: number\n ) => {\n if (id?.startsWith('ac_') || !value) {\n return null;\n }\n\n const formatted = isDateValid(value)\n ? toDateString(value, locale)\n : value.toString();\n\n const __html = formatValue\n ? formatValue(formatted, id, label)\n : formatted;\n\n return (\n <li key={`attribute-${index}`}>\n {/* eslint-disable-next-line react/no-danger */}\n {label}: <span dangerouslySetInnerHTML={{ __html }} />\n </li>\n );\n }\n )}\n </ul>\n )}\n </div>\n );\n};\n\nProductAttributes.getInitialData = getFetchedProductData;\n"],"names":["ProductAttributes","initialData","scope","children","slots","formatValue","props","DetailsLabel","useText","globalLocale","config","locale","setLocale","useState","data","setData","defaultSlotContext","useMemo","useEffect","dataEvent","events","localeEvent","jsxs","classes","jsx","Slot","_a","id","label","value","index","formatted","isDateValid","toDateString","__html","getFetchedProductData"],"mappings":"snBAoCa,MAAAA,EAGT,CAAC,CAAE,YAAAC,EAAc,KAAM,MAAAC,EAAO,SAAAC,EAAU,MAAAC,EAAO,YAAAC,EAAa,GAAGC,KAAY,OACvE,MAAAC,EAAeC,EAAQ,2BAA2B,EAAE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gB,IA0CpB,EAEA9B,EAAkB,eAAiBmC"}
|
package/lib/number.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADOBE CONFIDENTIAL
|
|
3
|
+
* __________________
|
|
4
|
+
* Copyright 2026 Adobe
|
|
5
|
+
* All Rights Reserved.
|
|
6
|
+
* __________________
|
|
7
|
+
* NOTICE: All information contained herein is, and remains
|
|
8
|
+
* the property of Adobe and its suppliers, if any. The intellectual
|
|
9
|
+
* and technical concepts contained herein are proprietary to Adobe
|
|
10
|
+
* and its suppliers and are protected by all applicable intellectual
|
|
11
|
+
* property laws, including trade secret and copyright laws.
|
|
12
|
+
* Dissemination of this information or reproduction of this material
|
|
13
|
+
* is strictly forbidden unless prior written permission is obtained
|
|
14
|
+
* from Adobe.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isNumericValue(value: string): boolean;
|
|
17
|
+
export declare function formatNumeric(value: string, locale?: string): string;
|
|
18
|
+
//# sourceMappingURL=number.d.ts.map
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-pdp", "version": "3.0.3-
|
|
1
|
+
{"name": "@dropins/storefront-pdp", "version": "3.0.3-beta3", "@dropins/tools": "~1.5.0", "license": "SEE LICENSE IN LICENSE.md"}
|