@deneb-ui/ui 2.0.78 → 2.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SiteDataProvider.d.ts +11 -0
- package/dist/SiteDataProvider.js +134 -13
- package/package.json +2 -2
|
@@ -135,3 +135,14 @@ export declare function useShop(fallback?: GenericRecord): GenericRecord;
|
|
|
135
135
|
* Hook to retrieve customer reviews / testimonials cleanly from SiteData.
|
|
136
136
|
*/
|
|
137
137
|
export declare function useReviews(fallback?: GenericRecord[]): GenericRecord[];
|
|
138
|
+
/**
|
|
139
|
+
* Hook to retrieve common storefront metadata (website title, slogan, branding, etc.)
|
|
140
|
+
* with safe hierarchical fallbacks across content.common, shop profile, and user fallbacks.
|
|
141
|
+
* Never throws ReferenceError or crashes on missing data.
|
|
142
|
+
*/
|
|
143
|
+
export declare function useCommon(fallback?: GenericRecord): GenericRecord;
|
|
144
|
+
/**
|
|
145
|
+
* Hook to retrieve contact information (WhatsApp, phone, address, email, map link)
|
|
146
|
+
* with robust fallbacks across contact, common, and shop profile.
|
|
147
|
+
*/
|
|
148
|
+
export declare function useContact(fallback?: GenericRecord): GenericRecord;
|
package/dist/SiteDataProvider.js
CHANGED
|
@@ -24,6 +24,8 @@ exports.useSiteApi = useSiteApi;
|
|
|
24
24
|
exports.useSiteCatalog = useSiteCatalog;
|
|
25
25
|
exports.useShop = useShop;
|
|
26
26
|
exports.useReviews = useReviews;
|
|
27
|
+
exports.useCommon = useCommon;
|
|
28
|
+
exports.useContact = useContact;
|
|
27
29
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
30
|
const react_1 = require("react");
|
|
29
31
|
const core_1 = require("@deneb-ui/core");
|
|
@@ -260,9 +262,18 @@ function SiteDataProvider({ children, initialSiteData, fallbackSiteData, liveCat
|
|
|
260
262
|
const currentHome = isRecord(currentContent.home) ? currentContent.home : null;
|
|
261
263
|
const currentCommon = isRecord(currentContent.common) ? currentContent.common : {};
|
|
262
264
|
const currentContact = isRecord(currentContent.contact) ? currentContent.contact : {};
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
const rawLiveProducts = Array.isArray(live.products) ? live.products : currentContent.products;
|
|
266
|
+
const nextProducts = Array.isArray(rawLiveProducts)
|
|
267
|
+
? rawLiveProducts.map((p) => {
|
|
268
|
+
if (!isRecord(p))
|
|
269
|
+
return p;
|
|
270
|
+
const customData = isRecord(p.customData) ? p.customData : {};
|
|
271
|
+
return {
|
|
272
|
+
...customData,
|
|
273
|
+
...p,
|
|
274
|
+
};
|
|
275
|
+
})
|
|
276
|
+
: rawLiveProducts;
|
|
266
277
|
const nextServices = Array.isArray(live.services)
|
|
267
278
|
? live.services
|
|
268
279
|
: currentContent.services;
|
|
@@ -293,12 +304,18 @@ function SiteDataProvider({ children, initialSiteData, fallbackSiteData, liveCat
|
|
|
293
304
|
if (cleanWa) {
|
|
294
305
|
nextContact.whatsappNumber = cleanWa;
|
|
295
306
|
nextCommon.whatsappNumber = cleanWa;
|
|
296
|
-
// Dynamically update any hardcoded or static wa.me URLs across home
|
|
307
|
+
// Dynamically update any hardcoded or static wa.me URLs across home and common
|
|
297
308
|
const waRegex = /(https?:\/\/(?:wa\.me|api\.whatsapp\.com\/send\?phone=))\d+/gi;
|
|
298
309
|
for (const key of ['whatsappCtaUrl', 'whatsappOrderUrl', 'whatsappUrl']) {
|
|
299
310
|
if (typeof nextHome[key] === 'string' && waRegex.test(nextHome[key])) {
|
|
300
311
|
nextHome[key] = nextHome[key].replace(waRegex, `$1${cleanWa}`);
|
|
301
312
|
}
|
|
313
|
+
if (typeof nextCommon[key] === 'string' && waRegex.test(nextCommon[key])) {
|
|
314
|
+
nextCommon[key] = nextCommon[key].replace(waRegex, `$1${cleanWa}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (!nextCommon.whatsappUrl || waRegex.test(nextCommon.whatsappUrl)) {
|
|
318
|
+
nextCommon.whatsappUrl = `https://wa.me/${cleanWa}`;
|
|
302
319
|
}
|
|
303
320
|
}
|
|
304
321
|
}
|
|
@@ -312,6 +329,7 @@ function SiteDataProvider({ children, initialSiteData, fallbackSiteData, liveCat
|
|
|
312
329
|
if (typeof street === 'string' && street.trim()) {
|
|
313
330
|
nextContact.address = street;
|
|
314
331
|
nextCommon.address = street;
|
|
332
|
+
nextCommon.footerAddress = street;
|
|
315
333
|
}
|
|
316
334
|
if (typeof address.mapLocation === 'string' && address.mapLocation.trim()) {
|
|
317
335
|
nextContact.googleMapLink = address.mapLocation;
|
|
@@ -639,19 +657,32 @@ function useProducts(fallback = []) {
|
|
|
639
657
|
const content = isRecord(siteData?.content) ? siteData.content : null;
|
|
640
658
|
if (!content)
|
|
641
659
|
return fallback;
|
|
660
|
+
let rawList = null;
|
|
642
661
|
if (Array.isArray(content.products) && content.products.length > 0) {
|
|
643
|
-
|
|
662
|
+
rawList = content.products;
|
|
644
663
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
if (
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
664
|
+
else {
|
|
665
|
+
const home = isRecord(content.home) ? content.home : null;
|
|
666
|
+
if (home) {
|
|
667
|
+
if (Array.isArray(home.products) && home.products.length > 0) {
|
|
668
|
+
rawList = home.products;
|
|
669
|
+
}
|
|
670
|
+
else if (Array.isArray(home.featuredProducts) && home.featuredProducts.length > 0) {
|
|
671
|
+
rawList = home.featuredProducts;
|
|
672
|
+
}
|
|
652
673
|
}
|
|
653
674
|
}
|
|
654
|
-
|
|
675
|
+
if (!rawList)
|
|
676
|
+
return fallback;
|
|
677
|
+
return rawList.map((p) => {
|
|
678
|
+
if (!isRecord(p))
|
|
679
|
+
return p;
|
|
680
|
+
const customData = isRecord(p.customData) ? p.customData : {};
|
|
681
|
+
return {
|
|
682
|
+
...customData,
|
|
683
|
+
...p,
|
|
684
|
+
};
|
|
685
|
+
});
|
|
655
686
|
}
|
|
656
687
|
/**
|
|
657
688
|
* Hook to retrieve services cleanly from SiteData, supporting both
|
|
@@ -744,3 +775,93 @@ function useReviews(fallback = []) {
|
|
|
744
775
|
}
|
|
745
776
|
return fallback;
|
|
746
777
|
}
|
|
778
|
+
/**
|
|
779
|
+
* Hook to retrieve common storefront metadata (website title, slogan, branding, etc.)
|
|
780
|
+
* with safe hierarchical fallbacks across content.common, shop profile, and user fallbacks.
|
|
781
|
+
* Never throws ReferenceError or crashes on missing data.
|
|
782
|
+
*/
|
|
783
|
+
function useCommon(fallback = {}) {
|
|
784
|
+
const siteData = useSiteData();
|
|
785
|
+
const content = isRecord(siteData?.content) ? siteData.content : null;
|
|
786
|
+
const common = isRecord(content?.common) ? content.common : {};
|
|
787
|
+
const contact = isRecord(content?.contact) ? content.contact : {};
|
|
788
|
+
const shop = useShop();
|
|
789
|
+
const websiteTitle = (typeof common.websiteTitle === 'string' && common.websiteTitle.trim()) ||
|
|
790
|
+
(typeof shop.name === 'string' && shop.name.trim()) ||
|
|
791
|
+
(typeof shop.businessName === 'string' && shop.businessName.trim()) ||
|
|
792
|
+
(typeof fallback.websiteTitle === 'string' && fallback.websiteTitle.trim()) ||
|
|
793
|
+
'Store';
|
|
794
|
+
const whatsappNumber = (typeof common.whatsappNumber === 'string' && common.whatsappNumber.trim()) ||
|
|
795
|
+
(typeof contact.whatsappNumber === 'string' && contact.whatsappNumber.trim()) ||
|
|
796
|
+
(typeof shop.whatsappNumber === 'string' && shop.whatsappNumber.trim()) ||
|
|
797
|
+
(typeof shop.phone === 'string' && shop.phone.trim()) ||
|
|
798
|
+
(typeof fallback.whatsappNumber === 'string' && fallback.whatsappNumber.trim()) ||
|
|
799
|
+
'';
|
|
800
|
+
const cleanWa = whatsappNumber.replace(/\D+/g, '');
|
|
801
|
+
const whatsappUrl = (typeof common.whatsappUrl === 'string' && common.whatsappUrl.trim()) ||
|
|
802
|
+
(cleanWa ? `https://wa.me/${cleanWa}` : '') ||
|
|
803
|
+
(typeof fallback.whatsappUrl === 'string' && fallback.whatsappUrl.trim()) ||
|
|
804
|
+
'';
|
|
805
|
+
const address = (typeof common.address === 'string' && common.address.trim()) ||
|
|
806
|
+
(typeof common.footerAddress === 'string' && common.footerAddress.trim()) ||
|
|
807
|
+
(typeof contact.address === 'string' && contact.address.trim()) ||
|
|
808
|
+
(typeof shop.address === 'string' && shop.address.trim()) ||
|
|
809
|
+
(typeof fallback.address === 'string' && fallback.address.trim()) ||
|
|
810
|
+
'';
|
|
811
|
+
const logoUrl = (typeof common.logoUrl === 'string' && common.logoUrl.trim()) ||
|
|
812
|
+
(typeof shop.logoUrl === 'string' && shop.logoUrl.trim()) ||
|
|
813
|
+
(typeof fallback.logoUrl === 'string' && fallback.logoUrl.trim()) ||
|
|
814
|
+
'';
|
|
815
|
+
return {
|
|
816
|
+
...fallback,
|
|
817
|
+
...common,
|
|
818
|
+
websiteTitle,
|
|
819
|
+
whatsappNumber,
|
|
820
|
+
whatsappUrl,
|
|
821
|
+
address,
|
|
822
|
+
logoUrl,
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Hook to retrieve contact information (WhatsApp, phone, address, email, map link)
|
|
827
|
+
* with robust fallbacks across contact, common, and shop profile.
|
|
828
|
+
*/
|
|
829
|
+
function useContact(fallback = {}) {
|
|
830
|
+
const siteData = useSiteData();
|
|
831
|
+
const content = isRecord(siteData?.content) ? siteData.content : null;
|
|
832
|
+
const contact = isRecord(content?.contact) ? content.contact : {};
|
|
833
|
+
const common = isRecord(content?.common) ? content.common : {};
|
|
834
|
+
const shop = useShop();
|
|
835
|
+
const whatsappNumber = (typeof contact.whatsappNumber === 'string' && contact.whatsappNumber.trim()) ||
|
|
836
|
+
(typeof common.whatsappNumber === 'string' && common.whatsappNumber.trim()) ||
|
|
837
|
+
(typeof shop.whatsappNumber === 'string' && shop.whatsappNumber.trim()) ||
|
|
838
|
+
(typeof shop.phone === 'string' && shop.phone.trim()) ||
|
|
839
|
+
(typeof fallback.whatsappNumber === 'string' && fallback.whatsappNumber.trim()) ||
|
|
840
|
+
'';
|
|
841
|
+
const cleanWa = whatsappNumber.replace(/\D+/g, '');
|
|
842
|
+
const whatsappUrl = (typeof contact.whatsappUrl === 'string' && contact.whatsappUrl.trim()) ||
|
|
843
|
+
(typeof common.whatsappUrl === 'string' && common.whatsappUrl.trim()) ||
|
|
844
|
+
(cleanWa ? `https://wa.me/${cleanWa}` : '') ||
|
|
845
|
+
'';
|
|
846
|
+
const address = (typeof contact.address === 'string' && contact.address.trim()) ||
|
|
847
|
+
(typeof common.address === 'string' && common.address.trim()) ||
|
|
848
|
+
(typeof shop.address === 'string' && shop.address.trim()) ||
|
|
849
|
+
(typeof fallback.address === 'string' && fallback.address.trim()) ||
|
|
850
|
+
'';
|
|
851
|
+
const email = (typeof contact.email === 'string' && contact.email.trim()) ||
|
|
852
|
+
(typeof shop.email === 'string' && shop.email.trim()) ||
|
|
853
|
+
(typeof fallback.email === 'string' && fallback.email.trim()) ||
|
|
854
|
+
'';
|
|
855
|
+
const googleMapLink = (typeof contact.googleMapLink === 'string' && contact.googleMapLink.trim()) ||
|
|
856
|
+
(typeof fallback.googleMapLink === 'string' && fallback.googleMapLink.trim()) ||
|
|
857
|
+
'';
|
|
858
|
+
return {
|
|
859
|
+
...fallback,
|
|
860
|
+
...contact,
|
|
861
|
+
whatsappNumber,
|
|
862
|
+
whatsappUrl,
|
|
863
|
+
address,
|
|
864
|
+
email,
|
|
865
|
+
googleMapLink,
|
|
866
|
+
};
|
|
867
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deneb-ui/ui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.80",
|
|
4
4
|
"description": "Visual-first React component library for editable commerce storefronts. Built for Next.js and Fivora.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@deneb-ui/core": "^2.0.
|
|
53
|
+
"@deneb-ui/core": "^2.0.80"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"react": "^18.0.0 || ^19.0.0",
|