payaza-storefront-layouts 1.0.13 → 1.0.14
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutPreview.d.ts","sourceRoot":"","sources":["../../src/preview/LayoutPreview.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAe,eAAe,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"LayoutPreview.d.ts","sourceRoot":"","sources":["../../src/preview/LayoutPreview.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAe,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAUjE,UAAU,kBAAkB;IAC1B,MAAM,EAAE,eAAe,GAAG,MAAM,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AA4LD,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,2CAEtD"}
|
|
@@ -3,13 +3,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useEffect, useState, useCallback } from 'react';
|
|
4
4
|
import { getPreviewDataByLayout } from '../lib/preview-data';
|
|
5
5
|
import { ToastProvider, StoreProvider, LoadingProvider, AuthProvider, } from '../index';
|
|
6
|
-
import { ShadowDOMWrapper } from './ShadowDOMWrapper';
|
|
7
6
|
import { PreviewRouter } from './PreviewRouter';
|
|
8
7
|
/**
|
|
9
8
|
* LayoutPreview Component
|
|
10
9
|
*
|
|
11
10
|
* Renders a layout component with embedded preview data and client-side routing.
|
|
12
|
-
*
|
|
11
|
+
* Handles routing via URL query params and provides all necessary context providers.
|
|
12
|
+
*
|
|
13
|
+
* Note: This component does NOT include ShadowDOM. For style isolation, wrap this
|
|
14
|
+
* component with ShadowDOMWrapper from the package.
|
|
15
|
+
*
|
|
13
16
|
* This component is used to preview layouts in standalone applications
|
|
14
17
|
* and demonstrates that layouts are self-sustaining with embedded data.
|
|
15
18
|
*/
|
|
@@ -98,21 +101,21 @@ function LayoutPreviewWithRouter({ layout, className, initialRoute, onRouteChang
|
|
|
98
101
|
window.removeEventListener('hashchange', checkUrlChange);
|
|
99
102
|
};
|
|
100
103
|
}, [isClient, onRouteChange, getRouteFromUrl]);
|
|
101
|
-
//
|
|
102
|
-
const
|
|
104
|
+
// Navigation handler - called by PreviewRouter or external navigation
|
|
105
|
+
const handleNavigate = useCallback((route) => {
|
|
103
106
|
// Normalize route (ensure it starts with /)
|
|
104
107
|
const normalizedRoute = route.startsWith('/') ? route : `/${route}`;
|
|
105
|
-
// Update
|
|
106
|
-
|
|
108
|
+
// Update state immediately for instant UI update
|
|
109
|
+
setCurrentRoute(normalizedRoute);
|
|
110
|
+
onRouteChange?.(normalizedRoute);
|
|
111
|
+
// Update URL with query param using pushState if in browser
|
|
112
|
+
// This allows external components (like ShadowDOMWrapper) to sync
|
|
107
113
|
if (typeof window !== 'undefined') {
|
|
108
114
|
const newUrl = new URL(window.location.href);
|
|
109
115
|
// Encode the route for URL (handles /contact -> %2Fcontact)
|
|
110
116
|
newUrl.searchParams.set('route', normalizedRoute);
|
|
111
117
|
window.history.pushState({ route: normalizedRoute }, '', newUrl.toString());
|
|
112
|
-
//
|
|
113
|
-
setCurrentRoute(normalizedRoute);
|
|
114
|
-
onRouteChange?.(normalizedRoute);
|
|
115
|
-
// Trigger a custom event to notify PreviewClient of the change
|
|
118
|
+
// Trigger a custom event to notify external components of the change
|
|
116
119
|
// This ensures Next.js searchParams updates
|
|
117
120
|
window.dispatchEvent(new PopStateEvent('popstate'));
|
|
118
121
|
}
|
|
@@ -129,11 +132,7 @@ function LayoutPreviewWithRouter({ layout, className, initialRoute, onRouteChang
|
|
|
129
132
|
if (!isClient) {
|
|
130
133
|
return (_jsx("div", { className: `flex items-center justify-center p-8 ${className || ''}`, children: _jsx("div", { className: "text-center", children: _jsx("p", { className: "text-sm text-gray-500", children: "Loading preview..." }) }) }));
|
|
131
134
|
}
|
|
132
|
-
return (_jsx("div", { style: style, className: `min-h-screen w-full ${className || ''}`, children: _jsx(
|
|
133
|
-
const normalized = route.startsWith('/') ? route : `/${route}`;
|
|
134
|
-
setCurrentRoute(normalized);
|
|
135
|
-
onRouteChange?.(normalized);
|
|
136
|
-
} }) }) }) }) }) }) }));
|
|
135
|
+
return (_jsx("div", { style: style, className: `min-h-screen w-full ${className || ''}`, children: _jsx(ToastProvider, { children: _jsx(StoreProvider, { initialConfig: previewData, storeSlug: previewData.slug, children: _jsx(LoadingProvider, { children: _jsx(AuthProvider, { children: _jsx(PreviewRouter, { storeConfig: previewData, route: currentRoute.startsWith('/') ? currentRoute : `/${currentRoute}`, onNavigate: handleNavigate }) }) }) }) }) }));
|
|
137
136
|
}
|
|
138
137
|
// Main component - always uses the same implementation
|
|
139
138
|
// Router hooks are called conditionally inside, but component structure is consistent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreviewRouter.d.ts","sourceRoot":"","sources":["../../src/preview/PreviewRouter.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAsGhD,UAAU,kBAAkB;IAC1B,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACtC;AAkHD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"PreviewRouter.d.ts","sourceRoot":"","sources":["../../src/preview/PreviewRouter.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAsGhD,UAAU,kBAAkB;IAC1B,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACtC;AAkHD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,kBAAkB,2CA+oBnF"}
|
|
@@ -399,7 +399,20 @@ export function PreviewRouter({ storeConfig, route, onNavigate }) {
|
|
|
399
399
|
return _jsx("div", { children: "Contact page not available" });
|
|
400
400
|
}
|
|
401
401
|
// Route: /account
|
|
402
|
-
if (firstSegment === 'account') {
|
|
402
|
+
if (firstSegment === 'account' && !secondSegment) {
|
|
403
|
+
if (isElectronics) {
|
|
404
|
+
return (_jsx(ElectronicsPageWrapper, { storeConfig: storeConfig, children: _jsx(AccountPage, { storeConfig: storeConfig }) }));
|
|
405
|
+
}
|
|
406
|
+
if (isMotivational) {
|
|
407
|
+
return (_jsx(MotivationalPageWrapper, { storeConfig: storeConfig, children: _jsx(AccountPage, { storeConfig: storeConfig }) }));
|
|
408
|
+
}
|
|
409
|
+
return _jsx(AccountPage, { storeConfig: storeConfig });
|
|
410
|
+
}
|
|
411
|
+
// Route: /account/orders/[orderId]
|
|
412
|
+
if (firstSegment === 'account' && secondSegment === 'orders' && thirdSegment) {
|
|
413
|
+
// Render AccountPage with orders tab - order detail can be shown within AccountPage
|
|
414
|
+
// AccountPage uses searchParams for tab, so we navigate to account with tab=orders
|
|
415
|
+
// For preview, we'll show AccountPage with orders tab active
|
|
403
416
|
if (isElectronics) {
|
|
404
417
|
return (_jsx(ElectronicsPageWrapper, { storeConfig: storeConfig, children: _jsx(AccountPage, { storeConfig: storeConfig }) }));
|
|
405
418
|
}
|
|
@@ -448,6 +461,22 @@ export function PreviewRouter({ storeConfig, route, onNavigate }) {
|
|
|
448
461
|
}
|
|
449
462
|
return _jsx(SizeGuidePage, { storeConfig: storeConfig });
|
|
450
463
|
}
|
|
464
|
+
// Route: /order/success
|
|
465
|
+
if (firstSegment === 'order' && secondSegment === 'success') {
|
|
466
|
+
// Simple order success page
|
|
467
|
+
const primaryColor = storeConfig.branding.primaryColor;
|
|
468
|
+
return (_jsx(GenericPageWrapper, { storeConfig: storeConfig, children: _jsx("div", { className: "min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8", children: _jsx("div", { className: "max-w-md w-full space-y-8 bg-white p-8 rounded-xl shadow-sm", children: _jsxs("div", { className: "text-center", children: [_jsx("div", { className: "mx-auto h-16 w-16 mb-4 rounded-full flex items-center justify-center", style: { backgroundColor: `${primaryColor}20`, color: primaryColor }, children: _jsx("svg", { className: "h-8 w-8", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M5 13l4 4L19 7" }) }) }), _jsx("h2", { className: "text-3xl font-extrabold text-gray-900 mb-2", children: "Order Confirmed!" }), _jsx("p", { className: "text-gray-600 mb-8", children: "Thank you for your purchase. Your order has been received." }), _jsxs("div", { className: "space-y-4", children: [_jsx("button", { onClick: () => onNavigate?.('/'), className: "w-full px-4 py-2 rounded-lg text-white font-medium", style: { backgroundColor: primaryColor }, children: "Continue Shopping" }), _jsx("button", { onClick: () => onNavigate?.('/account'), className: "w-full px-4 py-2 rounded-lg border border-gray-300 text-gray-700 font-medium hover:bg-gray-50", children: "View Order Details" })] })] }) }) }) }));
|
|
469
|
+
}
|
|
470
|
+
// Route: /payment/callback
|
|
471
|
+
if (firstSegment === 'payment' && secondSegment === 'callback') {
|
|
472
|
+
// Simple payment callback success page
|
|
473
|
+
return (_jsx(GenericPageWrapper, { storeConfig: storeConfig, children: _jsx("div", { className: "min-h-screen flex items-center justify-center p-4 bg-gray-50", children: _jsxs("div", { className: "max-w-md w-full bg-white rounded-2xl shadow-sm p-8 text-center", children: [_jsx("div", { className: "flex justify-center mb-6", children: _jsx("div", { className: "h-16 w-16 rounded-full bg-green-100 flex items-center justify-center", children: _jsx("svg", { className: "h-8 w-8 text-green-600", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M5 13l4 4L19 7" }) }) }) }), _jsx("h1", { className: "text-2xl font-bold text-gray-900 mb-2", children: "Payment Successful" }), _jsx("p", { className: "text-gray-600 mb-8", children: "Your payment has been processed successfully." }), _jsx("button", { onClick: () => onNavigate?.('/order/success'), className: "w-full px-4 py-2 rounded-lg text-white font-medium", style: { backgroundColor: storeConfig.branding.primaryColor }, children: "View Order Confirmation" })] }) }) }));
|
|
474
|
+
}
|
|
475
|
+
// Route: /payment/error
|
|
476
|
+
if (firstSegment === 'payment' && secondSegment === 'error') {
|
|
477
|
+
// Simple payment error page
|
|
478
|
+
return (_jsx(GenericPageWrapper, { storeConfig: storeConfig, children: _jsx("div", { className: "min-h-screen flex items-center justify-center p-4 bg-gray-50", children: _jsxs("div", { className: "max-w-md w-full bg-white rounded-2xl shadow-sm p-8 text-center", children: [_jsx("div", { className: "flex justify-center mb-6", children: _jsx("div", { className: "h-16 w-16 rounded-full bg-red-100 flex items-center justify-center", children: _jsx("svg", { className: "h-8 w-8 text-red-600", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }) }) }), _jsx("h1", { className: "text-2xl font-bold text-gray-900 mb-2", children: "Payment Failed" }), _jsx("p", { className: "text-gray-600 mb-8", children: "There was an issue processing your payment. Please try again." }), _jsxs("div", { className: "space-y-3", children: [_jsx("button", { onClick: () => onNavigate?.('/checkout'), className: "w-full px-4 py-2 rounded-lg text-white font-medium", style: { backgroundColor: storeConfig.branding.primaryColor }, children: "Return to Checkout" }), _jsx("button", { onClick: () => onNavigate?.('/cart'), className: "w-full px-4 py-2 rounded-lg border border-gray-300 text-gray-700 font-medium hover:bg-gray-50", children: "Return to Cart" })] })] }) }) }));
|
|
479
|
+
}
|
|
451
480
|
// Fallback for generic pages - show 404 for now
|
|
452
481
|
if (firstSegment) {
|
|
453
482
|
return (_jsx("div", { className: "min-h-screen flex items-center justify-center", children: _jsxs("div", { className: "text-center", children: [_jsx("p", { className: "text-lg font-semibold text-gray-600", children: "Page not found" }), _jsxs("p", { className: "text-sm text-gray-500 mt-2", children: ["Route: ", route] })] }) }));
|