@akinon/pz-theme 2.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/package.json +27 -0
  3. package/readme.md +23 -0
  4. package/src/blocks/accordion-block.tsx +136 -0
  5. package/src/blocks/block-renderer-registry.tsx +77 -0
  6. package/src/blocks/button-block.tsx +593 -0
  7. package/src/blocks/counter-block.tsx +348 -0
  8. package/src/blocks/divider-block.tsx +20 -0
  9. package/src/blocks/embed-block.tsx +208 -0
  10. package/src/blocks/group-block.tsx +116 -0
  11. package/src/blocks/hotspot-block.tsx +147 -0
  12. package/src/blocks/icon-block.tsx +230 -0
  13. package/src/blocks/image-block.tsx +142 -0
  14. package/src/blocks/image-gallery-block.tsx +269 -0
  15. package/src/blocks/input-block.tsx +123 -0
  16. package/src/blocks/link-block.tsx +216 -0
  17. package/src/blocks/lottie-block.tsx +325 -0
  18. package/src/blocks/map-block.tsx +89 -0
  19. package/src/blocks/slider-block.tsx +595 -0
  20. package/src/blocks/tab-block.tsx +10 -0
  21. package/src/blocks/text-block.tsx +52 -0
  22. package/src/blocks/video-block.tsx +122 -0
  23. package/src/components/action-toolbar.tsx +305 -0
  24. package/src/components/designer-overlay.tsx +74 -0
  25. package/src/components/with-designer-features.tsx +142 -0
  26. package/src/dynamic-font-loader.tsx +79 -0
  27. package/src/hooks/use-designer-features.tsx +100 -0
  28. package/src/hooks/use-visibility-context.ts +27 -0
  29. package/src/index.ts +21 -0
  30. package/src/placeholder-registry.ts +31 -0
  31. package/src/sections/before-after-section.tsx +245 -0
  32. package/src/sections/contact-form-section.tsx +564 -0
  33. package/src/sections/countdown-campaign-banner-section.tsx +433 -0
  34. package/src/sections/coupon-banner-section.tsx +710 -0
  35. package/src/sections/divider-section.tsx +62 -0
  36. package/src/sections/featured-product-spotlight-section.tsx +507 -0
  37. package/src/sections/find-in-store-section.tsx +1995 -0
  38. package/src/sections/hover-showcase-section.tsx +326 -0
  39. package/src/sections/image-hotspot-section.tsx +142 -0
  40. package/src/sections/installment-options-section.tsx +1065 -0
  41. package/src/sections/notification-banner-section.tsx +173 -0
  42. package/src/sections/order-tracking-lookup-section.tsx +1379 -0
  43. package/src/sections/posts-slider-section.tsx +472 -0
  44. package/src/sections/pre-order-launch-banner-section.tsx +687 -0
  45. package/src/sections/section-renderer-registry.tsx +89 -0
  46. package/src/sections/section-wrapper.tsx +135 -0
  47. package/src/sections/shipping-threshold-progress-section.tsx +586 -0
  48. package/src/sections/stats-counter-section.tsx +486 -0
  49. package/src/sections/tabs-section.tsx +578 -0
  50. package/src/theme-block.tsx +102 -0
  51. package/src/theme-page-context.tsx +27 -0
  52. package/src/theme-placeholder-client.tsx +218 -0
  53. package/src/theme-placeholder-wrapper.tsx +786 -0
  54. package/src/theme-placeholder.tsx +305 -0
  55. package/src/theme-section.tsx +1241 -0
  56. package/src/theme-settings-context.tsx +13 -0
  57. package/src/utils/index.ts +791 -0
  58. package/src/utils/iterator-utils.test.ts +224 -0
  59. package/src/utils/iterator-utils.ts +617 -0
  60. package/src/utils/page-context-discovery.ts +119 -0
  61. package/src/utils/publish-window.ts +86 -0
  62. package/src/utils/visibility-rules.ts +188 -0
@@ -0,0 +1,79 @@
1
+ 'use client';
2
+
3
+ import { useEffect } from 'react';
4
+
5
+ interface DynamicFontLoaderProps {
6
+ fontFamily?: string;
7
+ fontWeight?: string;
8
+ fontSubsets?: string;
9
+ }
10
+
11
+ /**
12
+ * Client-side component to dynamically load Google Fonts
13
+ * Used for theme editor buttons that use custom fonts
14
+ */
15
+ export function DynamicFontLoader({
16
+ fontFamily,
17
+ fontWeight,
18
+ fontSubsets
19
+ }: DynamicFontLoaderProps) {
20
+ useEffect(() => {
21
+ if (!fontFamily || fontFamily === 'inherit') return;
22
+
23
+ // Clean font family name (remove quotes and extra spaces)
24
+ const cleanFontFamily = fontFamily.replace(/['"]/g, '').trim();
25
+
26
+ // Skip if it's a system font
27
+ const systemFonts = [
28
+ 'Arial',
29
+ 'Helvetica',
30
+ 'Times New Roman',
31
+ 'Georgia',
32
+ 'Courier New',
33
+ 'Verdana'
34
+ ];
35
+ if (systemFonts.includes(cleanFontFamily)) return;
36
+
37
+ // Build Google Fonts URL
38
+ const params = new URLSearchParams();
39
+
40
+ // Font family with weights
41
+ const weights = fontWeight || '100;300;400;500;600;700;800;900';
42
+ const fontParam = `${cleanFontFamily.replace(/\s+/g, '+')}:wght@${weights}`;
43
+ params.append('family', fontParam);
44
+
45
+ // Subsets
46
+ if (fontSubsets) {
47
+ params.append('subset', fontSubsets);
48
+ }
49
+
50
+ // Display swap for better performance
51
+ params.append('display', 'swap');
52
+
53
+ const fontUrl = `https://fonts.googleapis.com/css2?${params.toString()}`;
54
+
55
+ // Check if link already exists
56
+ const existingLink = document.querySelector(`link[href="${fontUrl}"]`);
57
+ if (existingLink) return;
58
+
59
+ // Create and append link element
60
+ const link = document.createElement('link');
61
+ link.href = fontUrl;
62
+ link.rel = 'stylesheet';
63
+ link.id = `google-font-${cleanFontFamily
64
+ .replace(/\s+/g, '-')
65
+ .toLowerCase()}`;
66
+
67
+ document.head.appendChild(link);
68
+
69
+ // Cleanup on unmount
70
+ return () => {
71
+ const linkToRemove = document.getElementById(link.id);
72
+ if (linkToRemove) {
73
+ document.head.removeChild(linkToRemove);
74
+ }
75
+ };
76
+ }, [fontFamily, fontWeight, fontSubsets]);
77
+
78
+ return null;
79
+ }
@@ -0,0 +1,100 @@
1
+ 'use client';
2
+
3
+ import { useCallback } from 'react';
4
+
5
+ interface BlockInfo {
6
+ id: string;
7
+ type: string;
8
+ label: string;
9
+ }
10
+
11
+ interface UseDesignerFeaturesProps {
12
+ blockId: string;
13
+ placeholderId: string;
14
+ sectionId: string;
15
+ isDesigner: boolean;
16
+ blockInfo?: BlockInfo;
17
+ }
18
+
19
+ export function useDesignerFeatures({
20
+ blockId,
21
+ placeholderId,
22
+ sectionId,
23
+ isDesigner,
24
+ blockInfo
25
+ }: UseDesignerFeaturesProps) {
26
+ const handleClick = useCallback(
27
+ (e: React.MouseEvent) => {
28
+ if (isDesigner) {
29
+ e.preventDefault();
30
+ e.stopPropagation();
31
+
32
+ if (window.parent) {
33
+ window.parent.postMessage(
34
+ {
35
+ type: 'SELECT_BLOCK',
36
+ data: {
37
+ placeholderId,
38
+ sectionId,
39
+ blockId,
40
+ blockType: blockInfo?.type,
41
+ blockLabel: blockInfo?.label
42
+ }
43
+ },
44
+ '*'
45
+ );
46
+ }
47
+ }
48
+ },
49
+ [isDesigner, blockId, placeholderId, sectionId, blockInfo]
50
+ );
51
+
52
+ const createActionHandler = useCallback(
53
+ (actionType: string) => () => {
54
+ if (window.parent) {
55
+ window.parent.postMessage(
56
+ {
57
+ type: actionType,
58
+ data: {
59
+ placeholderId,
60
+ sectionId,
61
+ blockId
62
+ }
63
+ },
64
+ '*'
65
+ );
66
+ }
67
+ },
68
+ [blockId, placeholderId, sectionId]
69
+ );
70
+
71
+ const handleRename = useCallback(
72
+ (newLabel: string) => {
73
+ if (window.parent) {
74
+ window.parent.postMessage(
75
+ {
76
+ type: 'RENAME_BLOCK',
77
+ data: {
78
+ placeholderId,
79
+ sectionId,
80
+ blockId,
81
+ label: newLabel
82
+ }
83
+ },
84
+ '*'
85
+ );
86
+ }
87
+ },
88
+ [blockId, placeholderId, sectionId]
89
+ );
90
+
91
+ return {
92
+ handleClick,
93
+ onMoveUp: createActionHandler('MOVE_BLOCK_UP'),
94
+ onMoveDown: createActionHandler('MOVE_BLOCK_DOWN'),
95
+ onDuplicate: createActionHandler('DUPLICATE_BLOCK'),
96
+ onToggleVisibility: createActionHandler('TOGGLE_BLOCK_VISIBILITY'),
97
+ onDelete: createActionHandler('DELETE_BLOCK'),
98
+ onRename: handleRename
99
+ };
100
+ }
@@ -0,0 +1,27 @@
1
+ 'use client';
2
+
3
+ import { usePathname, useSearchParams } from 'next/navigation';
4
+ import { useSession } from 'next-auth/react';
5
+
6
+ import { useLocalization } from '@akinon/next/hooks/use-localization';
7
+
8
+ export const useVisibilityContext = (currentBreakpoint = 'desktop') => {
9
+ const pathname = usePathname();
10
+ const searchParams = useSearchParams();
11
+ const { status } = useSession();
12
+ const { locale, currency } = useLocalization();
13
+
14
+ return {
15
+ authState:
16
+ status === 'authenticated'
17
+ ? ('authenticated' as const)
18
+ : status === 'loading'
19
+ ? ('loading' as const)
20
+ : ('guest' as const),
21
+ breakpoint: currentBreakpoint,
22
+ locale: String(locale || ''),
23
+ currency: String(currency || ''),
24
+ pathname: String(pathname || ''),
25
+ searchParams
26
+ };
27
+ };
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ // Main entry - re-exports common APIs
2
+ // For specific path-based imports use e.g., '@akinon/pz-theme/src/theme-placeholder'
3
+
4
+ export { default as ThemePlaceholder } from './theme-placeholder';
5
+ export { default as ThemeSection } from './theme-section';
6
+ export { default as ThemeBlock } from './theme-block';
7
+ export { ThemeSettingsProvider, useThemeSettingsContext } from './theme-settings-context';
8
+ export { ThemePageContextProvider, useThemePageContext } from './theme-page-context';
9
+ export {
10
+ registerPlaceholder,
11
+ unregisterPlaceholder
12
+ } from './placeholder-registry';
13
+
14
+ export * from './utils';
15
+ export * from './hooks/use-designer-features';
16
+ export * from './hooks/use-visibility-context';
17
+
18
+ export { WithDesignerFeatures } from './components/with-designer-features';
19
+
20
+ export type { Section } from './theme-section';
21
+ export type { Block } from './theme-block';
@@ -0,0 +1,31 @@
1
+ const placeholderRegistry = new Set<string>();
2
+ let registryTimeout: NodeJS.Timeout | null = null;
3
+
4
+ export const registerPlaceholder = (slug: string) => {
5
+ placeholderRegistry.add(slug);
6
+
7
+ if (registryTimeout) {
8
+ clearTimeout(registryTimeout);
9
+ }
10
+
11
+ registryTimeout = setTimeout(() => {
12
+ if (
13
+ typeof window !== 'undefined' &&
14
+ window.parent &&
15
+ window.self !== window.top
16
+ ) {
17
+ const availablePlaceholders = Array.from(placeholderRegistry);
18
+ window.parent.postMessage(
19
+ {
20
+ type: 'PLACEHOLDERS_AVAILABLE',
21
+ data: { placeholders: availablePlaceholders }
22
+ },
23
+ '*'
24
+ );
25
+ }
26
+ }, 100);
27
+ };
28
+
29
+ export const unregisterPlaceholder = (slug: string) => {
30
+ placeholderRegistry.delete(slug);
31
+ };
@@ -0,0 +1,245 @@
1
+ 'use client';
2
+
3
+ import React, { useState, useRef, useEffect, useCallback } from 'react';
4
+ import { getResponsiveValue, resolveThemeCssVariables } from '../utils';
5
+ import { Section } from '../theme-section';
6
+ import { useThemeSettingsContext } from '../theme-settings-context';
7
+ import { twMerge } from 'tailwind-merge';
8
+ import clsx from 'clsx';
9
+ import ThemeBlock from '../theme-block';
10
+
11
+ interface BeforeAfterSectionProps {
12
+ section: Section;
13
+ currentBreakpoint?: string;
14
+ isDesigner?: boolean;
15
+ placeholderId?: string;
16
+ selectedBlockId?: string | null;
17
+ }
18
+
19
+ export default function BeforeAfterSection({
20
+ section,
21
+ currentBreakpoint = 'desktop',
22
+ isDesigner = false,
23
+ placeholderId = '',
24
+ selectedBlockId = null
25
+ }: BeforeAfterSectionProps) {
26
+ const themeSettings = useThemeSettingsContext();
27
+ const [sliderPosition, setSliderPosition] = useState(50);
28
+ const [isResizing, setIsResizing] = useState(false);
29
+ const containerRef = useRef<HTMLDivElement>(null);
30
+ const [containerWidth, setContainerWidth] = useState(0);
31
+
32
+ const styles = section.styles || {};
33
+ const properties = section.properties || {};
34
+
35
+ const beforeBlock = section.blocks?.find(b => b.label === 'Before Image');
36
+ const afterBlock = section.blocks?.find(b => b.label === 'After Image');
37
+
38
+ const height = getResponsiveValue(styles.height, currentBreakpoint, '500px') as string | number;
39
+ const width = getResponsiveValue(styles.width, currentBreakpoint, '100%') as string;
40
+ const maxWidth = getResponsiveValue(styles['max-width'], currentBreakpoint, 'normal') as string;
41
+
42
+ const sliderColor = resolveThemeCssVariables(
43
+ getResponsiveValue(styles['slider-color'], currentBreakpoint, '#ffffff') as string,
44
+ themeSettings
45
+ );
46
+
47
+ const renderBlock = (block: any) => {
48
+ return (
49
+ <ThemeBlock
50
+ key={block.id}
51
+ block={block}
52
+ placeholderId={placeholderId}
53
+ sectionId={section.id}
54
+ isDesigner={isDesigner}
55
+ isSelected={selectedBlockId === block.id}
56
+ selectedBlockId={selectedBlockId}
57
+ currentBreakpoint={currentBreakpoint}
58
+ onMoveUp={() => {
59
+ if (window.parent) window.parent.postMessage({ type: 'MOVE_BLOCK_UP', data: { placeholderId, sectionId: section.id, blockId: block.id } }, '*');
60
+ }}
61
+ onMoveDown={() => {
62
+ if (window.parent) window.parent.postMessage({ type: 'MOVE_BLOCK_DOWN', data: { placeholderId, sectionId: section.id, blockId: block.id } }, '*');
63
+ }}
64
+ onDuplicate={() => {
65
+ if (window.parent) window.parent.postMessage({ type: 'DUPLICATE_BLOCK', data: { placeholderId, sectionId: section.id, blockId: block.id } }, '*');
66
+ }}
67
+ onToggleVisibility={() => {
68
+ if (window.parent) window.parent.postMessage({ type: 'TOGGLE_BLOCK_VISIBILITY', data: { placeholderId, sectionId: section.id, blockId: block.id } }, '*');
69
+ }}
70
+ onDelete={() => {
71
+ if (window.parent) window.parent.postMessage({ type: 'DELETE_BLOCK', data: { placeholderId, sectionId: section.id, blockId: block.id } }, '*');
72
+ }}
73
+ onRename={(newLabel) => {
74
+ if (window.parent) window.parent.postMessage({ type: 'RENAME_BLOCK', data: { placeholderId, sectionId: section.id, blockId: block.id, label: newLabel } }, '*');
75
+ }}
76
+ />
77
+ );
78
+ };
79
+
80
+ useEffect(() => {
81
+ if (!containerRef.current) return;
82
+
83
+ setContainerWidth(containerRef.current.offsetWidth);
84
+
85
+ const observer = new ResizeObserver((entries) => {
86
+ for (const entry of entries) {
87
+ setContainerWidth(entry.contentRect.width);
88
+ }
89
+ });
90
+
91
+ observer.observe(containerRef.current);
92
+
93
+ return () => observer.disconnect();
94
+ }, []);
95
+
96
+ const handleStart = (clientX: number) => {
97
+ setIsResizing(true);
98
+ if (containerRef.current) {
99
+ const rect = containerRef.current.getBoundingClientRect();
100
+ const x = Math.max(0, Math.min(clientX - rect.left, rect.width));
101
+ setSliderPosition((x / rect.width) * 100);
102
+ }
103
+ };
104
+
105
+ const handleMouseDown = (e: React.MouseEvent) => handleStart(e.clientX);
106
+ const handleTouchStart = (e: React.TouchEvent) => handleStart(e.touches[0].clientX);
107
+
108
+ const handleMove = useCallback(
109
+ (clientX: number) => {
110
+ if (!isResizing || !containerRef.current) return;
111
+
112
+ const rect = containerRef.current.getBoundingClientRect();
113
+ const x = Math.max(0, Math.min(clientX - rect.left, rect.width));
114
+ const percentage = (x / rect.width) * 100;
115
+
116
+ setSliderPosition(percentage);
117
+ },
118
+ [isResizing]
119
+ );
120
+
121
+ const handleMouseMove = (e: React.MouseEvent) => {
122
+ if (isResizing) handleMove(e.clientX);
123
+ };
124
+
125
+ const handleTouchMove = (e: React.TouchEvent) => {
126
+ if (isResizing) handleMove(e.touches[0].clientX);
127
+ };
128
+
129
+ useEffect(() => {
130
+ const handleGlobalEnd = () => setIsResizing(false);
131
+ const handleGlobalMove = (e: MouseEvent) => {
132
+ if (isResizing) {
133
+ e.preventDefault();
134
+ handleMove(e.clientX);
135
+ }
136
+ };
137
+
138
+ const handleGlobalTouchMove = (e: TouchEvent) => {
139
+ if (isResizing) {
140
+ handleMove(e.touches[0].clientX);
141
+ }
142
+ }
143
+
144
+ if (isResizing) {
145
+ window.addEventListener('mouseup', handleGlobalEnd);
146
+ window.addEventListener('touchend', handleGlobalEnd);
147
+ window.addEventListener('mousemove', handleGlobalMove);
148
+ window.addEventListener('touchmove', handleGlobalTouchMove, { passive: false });
149
+ }
150
+
151
+ return () => {
152
+ window.removeEventListener('mouseup', handleGlobalEnd);
153
+ window.removeEventListener('touchend', handleGlobalEnd);
154
+ window.removeEventListener('mousemove', handleGlobalMove);
155
+ window.removeEventListener('touchmove', handleGlobalTouchMove);
156
+ };
157
+ }, [isResizing, handleMove]);
158
+
159
+
160
+ const maxWidthClass =
161
+ maxWidth === 'narrow'
162
+ ? 'max-w-4xl'
163
+ : maxWidth === 'normal'
164
+ ? 'max-w-7xl'
165
+ : maxWidth === 'full'
166
+ ? 'w-full'
167
+ : '';
168
+
169
+ const hasMaxWidth = maxWidth !== 'none' && maxWidth !== 'full';
170
+
171
+ return (
172
+ <div
173
+ className={twMerge(
174
+ clsx(
175
+ 'relative mx-auto select-none overflow-hidden group/before-after',
176
+ hasMaxWidth && 'mx-auto',
177
+ maxWidthClass
178
+ )
179
+ )}
180
+ style={{
181
+ height: typeof height === 'number' ? `${height}px` : height,
182
+ width: width === 'fill' ? '100%' : width,
183
+ maxWidth: maxWidth === 'none' ? 'none' : undefined
184
+ }}
185
+ ref={containerRef}
186
+ onMouseDown={handleMouseDown}
187
+ onTouchStart={handleTouchStart}
188
+ onMouseMove={handleMouseMove}
189
+ onTouchMove={handleTouchMove}
190
+ >
191
+ <div className="absolute inset-0 w-full h-full">
192
+ {afterBlock ? (
193
+ <div className="w-full h-full pointer-events-none">
194
+ {renderBlock(afterBlock)}
195
+ </div>
196
+ ) : (
197
+ <div className="w-full h-full bg-gray-200 flex items-center justify-center text-gray-400 select-none pointer-events-none">
198
+ No After Image
199
+ </div>
200
+ )}
201
+ </div>
202
+
203
+ <div
204
+ className="absolute top-0 left-0 h-full overflow-hidden border-r"
205
+ style={{
206
+ width: `${sliderPosition}%`,
207
+ borderColor: sliderColor
208
+ }}
209
+ >
210
+ <div
211
+ className="relative h-full"
212
+ style={{ width: containerWidth ? `${containerWidth}px` : '100%' }}
213
+ >
214
+ {beforeBlock ? (
215
+ <div className="absolute top-0 left-0 w-full h-full pointer-events-none">
216
+ {renderBlock(beforeBlock)}
217
+ </div>
218
+ ) : (
219
+ <div className="absolute top-0 left-0 w-full h-full bg-gray-300 flex items-center justify-center text-gray-500 select-none pointer-events-none">
220
+ No Before Image
221
+ </div>
222
+ )}
223
+ </div>
224
+ </div>
225
+
226
+ <div
227
+ className={clsx(
228
+ "absolute top-0 bottom-0 w-1 z-20 cursor-ew-resize"
229
+ )}
230
+ style={{
231
+ left: `${sliderPosition}%`,
232
+ backgroundColor: sliderColor,
233
+ transform: 'translateX(-50%)'
234
+ }}
235
+ >
236
+ <div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-8 h-8 bg-white rounded-full shadow-lg flex items-center justify-center text-gray-800 pointer-events-none">
237
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
238
+ <path d="M10 15l-3-3 3-3" />
239
+ <path d="M14 15l3-3-3-3" />
240
+ </svg>
241
+ </div>
242
+ </div>
243
+ </div>
244
+ );
245
+ }