@akinon/next 2.0.0-beta.20 → 2.0.0-beta.22

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 (64) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/api/auth.ts +292 -60
  3. package/bin/pz-install-plugins.js +1 -1
  4. package/package.json +3 -3
  5. package/types/index.ts +19 -6
  6. package/types/next-auth.d.ts +1 -1
  7. package/with-pz-config.js +8 -1
  8. package/components/theme-editor/blocks/accordion-block.tsx +0 -136
  9. package/components/theme-editor/blocks/block-renderer-registry.tsx +0 -77
  10. package/components/theme-editor/blocks/button-block.tsx +0 -593
  11. package/components/theme-editor/blocks/counter-block.tsx +0 -348
  12. package/components/theme-editor/blocks/divider-block.tsx +0 -20
  13. package/components/theme-editor/blocks/embed-block.tsx +0 -208
  14. package/components/theme-editor/blocks/group-block.tsx +0 -116
  15. package/components/theme-editor/blocks/hotspot-block.tsx +0 -147
  16. package/components/theme-editor/blocks/icon-block.tsx +0 -230
  17. package/components/theme-editor/blocks/image-block.tsx +0 -137
  18. package/components/theme-editor/blocks/image-gallery-block.tsx +0 -269
  19. package/components/theme-editor/blocks/input-block.tsx +0 -123
  20. package/components/theme-editor/blocks/link-block.tsx +0 -216
  21. package/components/theme-editor/blocks/lottie-block.tsx +0 -325
  22. package/components/theme-editor/blocks/map-block.tsx +0 -89
  23. package/components/theme-editor/blocks/slider-block.tsx +0 -595
  24. package/components/theme-editor/blocks/tab-block.tsx +0 -10
  25. package/components/theme-editor/blocks/text-block.tsx +0 -52
  26. package/components/theme-editor/blocks/video-block.tsx +0 -122
  27. package/components/theme-editor/components/action-toolbar.tsx +0 -305
  28. package/components/theme-editor/components/designer-overlay.tsx +0 -74
  29. package/components/theme-editor/components/with-designer-features.tsx +0 -142
  30. package/components/theme-editor/dynamic-font-loader.tsx +0 -79
  31. package/components/theme-editor/hooks/use-designer-features.tsx +0 -100
  32. package/components/theme-editor/hooks/use-external-designer.tsx +0 -95
  33. package/components/theme-editor/hooks/use-native-widget-data.ts +0 -188
  34. package/components/theme-editor/hooks/use-visibility-context.ts +0 -27
  35. package/components/theme-editor/placeholder-registry.ts +0 -31
  36. package/components/theme-editor/sections/before-after-section.tsx +0 -245
  37. package/components/theme-editor/sections/contact-form-section.tsx +0 -563
  38. package/components/theme-editor/sections/countdown-campaign-banner-section.tsx +0 -433
  39. package/components/theme-editor/sections/coupon-banner-section.tsx +0 -710
  40. package/components/theme-editor/sections/divider-section.tsx +0 -62
  41. package/components/theme-editor/sections/featured-product-spotlight-section.tsx +0 -507
  42. package/components/theme-editor/sections/find-in-store-section.tsx +0 -1995
  43. package/components/theme-editor/sections/hover-showcase-section.tsx +0 -326
  44. package/components/theme-editor/sections/image-hotspot-section.tsx +0 -142
  45. package/components/theme-editor/sections/installment-options-section.tsx +0 -1065
  46. package/components/theme-editor/sections/notification-banner-section.tsx +0 -173
  47. package/components/theme-editor/sections/order-tracking-lookup-section.tsx +0 -1379
  48. package/components/theme-editor/sections/posts-slider-section.tsx +0 -472
  49. package/components/theme-editor/sections/pre-order-launch-banner-section.tsx +0 -663
  50. package/components/theme-editor/sections/section-renderer-registry.tsx +0 -89
  51. package/components/theme-editor/sections/section-wrapper.tsx +0 -135
  52. package/components/theme-editor/sections/shipping-threshold-progress-section.tsx +0 -586
  53. package/components/theme-editor/sections/stats-counter-section.tsx +0 -486
  54. package/components/theme-editor/sections/tabs-section.tsx +0 -578
  55. package/components/theme-editor/theme-block.tsx +0 -102
  56. package/components/theme-editor/theme-placeholder-client.tsx +0 -218
  57. package/components/theme-editor/theme-placeholder-wrapper.tsx +0 -732
  58. package/components/theme-editor/theme-placeholder.tsx +0 -288
  59. package/components/theme-editor/theme-section.tsx +0 -1224
  60. package/components/theme-editor/theme-settings-context.tsx +0 -13
  61. package/components/theme-editor/utils/index.ts +0 -792
  62. package/components/theme-editor/utils/iterator-utils.ts +0 -234
  63. package/components/theme-editor/utils/publish-window.ts +0 -86
  64. package/components/theme-editor/utils/visibility-rules.ts +0 -188
@@ -1,234 +0,0 @@
1
- import { Block } from '../theme-block';
2
-
3
- interface IteratorOptions {
4
- iteratorBlock: Block;
5
- sectionDataSource?: any;
6
- isDesigner?: boolean;
7
- forceIteratorCount?: number;
8
- forceIteratorOffset?: number;
9
- }
10
-
11
- const parsePositiveNumber = (value: unknown, fallback: number): number => {
12
- if (typeof value === 'number' && Number.isFinite(value)) {
13
- return Math.max(0, Math.floor(value));
14
- }
15
- if (typeof value === 'string') {
16
- const parsed = Number(value);
17
- if (Number.isFinite(parsed)) {
18
- return Math.max(0, Math.floor(parsed));
19
- }
20
- }
21
- return fallback;
22
- };
23
-
24
- const extractProducts = (
25
- collectionData: any,
26
- dataPath: string | undefined
27
- ): Record<string, unknown>[] | null => {
28
- if (!collectionData) return null;
29
-
30
- // Respect explicit iterator path first.
31
- if (dataPath) {
32
- if (Array.isArray(collectionData)) {
33
- if (dataPath === 'products' || dataPath === 'items') {
34
- return collectionData as Record<string, unknown>[];
35
- }
36
- } else if (collectionData && typeof collectionData === 'object') {
37
- const pathParts = dataPath.split('.');
38
- let value: unknown = collectionData;
39
-
40
- for (const part of pathParts) {
41
- value = (value as Record<string, unknown>)?.[part];
42
- if (value === undefined) break;
43
- }
44
-
45
- if (Array.isArray(value)) {
46
- return value as Record<string, unknown>[];
47
- }
48
- }
49
- }
50
-
51
- // Fallback to generic products array for backward compatibility.
52
- if (Array.isArray(collectionData)) {
53
- return collectionData as Record<string, unknown>[];
54
- }
55
-
56
- if (Array.isArray((collectionData as any)?.products)) {
57
- return (collectionData as any).products;
58
- }
59
-
60
- return null;
61
- };
62
-
63
- const getProductsFromDataSource = (
64
- sectionDataSource: any,
65
- dataPath: string | undefined,
66
- isDesigner: boolean
67
- ): Record<string, unknown>[] => {
68
- if (!sectionDataSource?.details) {
69
- return [];
70
- }
71
-
72
- const isEditorMode =
73
- isDesigner && typeof window !== 'undefined' && window.parent !== window;
74
-
75
- const collection = sectionDataSource.details.collection;
76
-
77
- // In editor mode, prefer live products; on storefront, prefer fetched data.
78
- // Fall back to the other source if the primary one yields no products.
79
- const candidates = isEditorMode
80
- ? [collection?.products, collection?.data]
81
- : [collection?.data, collection?.products];
82
-
83
- for (const candidate of candidates) {
84
- const products = extractProducts(candidate, dataPath);
85
- if (products && products.length > 0) {
86
- return products;
87
- }
88
- }
89
-
90
- return [];
91
- };
92
-
93
- const replaceBlockValues = (
94
- blockToReplace: Block,
95
- productData: Record<string, unknown>,
96
- productIndex: number
97
- ): Block => {
98
- const newBlock: Block = {
99
- ...blockToReplace,
100
- properties: blockToReplace.properties
101
- ? { ...blockToReplace.properties }
102
- : blockToReplace.properties
103
- };
104
-
105
- const isPlaceholderMode = !productData || Object.keys(productData).length === 0;
106
-
107
- if (newBlock.properties?.dataBinding && !isPlaceholderMode) {
108
- const bindingPath = newBlock.properties.dataBinding.replace('item.', '');
109
- const pathParts = bindingPath.split('.');
110
-
111
- let value: unknown = productData;
112
- for (const part of pathParts) {
113
- const arrayMatch = part.match(/^(.+)\[(\d+)\]$/);
114
- if (arrayMatch) {
115
- const [, arrayName, indexStr] = arrayMatch;
116
- const obj = value as Record<string, unknown>;
117
- const arr = obj?.[arrayName];
118
- if (Array.isArray(arr)) {
119
- value = arr[parseInt(indexStr, 10)];
120
- } else {
121
- value = undefined;
122
- }
123
- } else {
124
- value = (value as Record<string, unknown>)?.[part];
125
- }
126
- if (value === undefined) break;
127
- }
128
-
129
- if (value !== undefined) {
130
- if (newBlock.properties.tag === 'a') {
131
- newBlock.properties = {
132
- ...newBlock.properties,
133
- href: value
134
- };
135
- } else {
136
- newBlock.value = value;
137
- }
138
- }
139
- } else if (isPlaceholderMode && newBlock.type === 'image') {
140
- const placeholderImages = [
141
- '/assets/images/product-placeholder-1.jpg',
142
- '/assets/images/product-placeholder-2.jpg',
143
- '/assets/images/product-placeholder-3.jpg',
144
- '/assets/images/product-placeholder-4.jpg'
145
- ];
146
-
147
- const placeholderIndex = productIndex % placeholderImages.length;
148
-
149
- if (
150
- newBlock.value &&
151
- typeof newBlock.value === 'string' &&
152
- newBlock.value.includes('product-placeholder')
153
- ) {
154
- newBlock.value = placeholderImages[placeholderIndex];
155
- }
156
- }
157
-
158
- if (newBlock.blocks && newBlock.blocks.length > 0) {
159
- newBlock.blocks = newBlock.blocks.map(childBlock =>
160
- replaceBlockValues(childBlock, productData, productIndex)
161
- );
162
- }
163
-
164
- return newBlock;
165
- };
166
-
167
- export const buildIteratorBlock = ({
168
- iteratorBlock,
169
- sectionDataSource,
170
- isDesigner = false,
171
- forceIteratorCount,
172
- forceIteratorOffset
173
- }: IteratorOptions): Block => {
174
- if (
175
- !iteratorBlock.isIterator ||
176
- !iteratorBlock.blocks ||
177
- iteratorBlock.blocks.length === 0
178
- ) {
179
- return iteratorBlock;
180
- }
181
-
182
- const template = iteratorBlock.blocks[0];
183
- const dataPath =
184
- iteratorBlock.iteratorDataPath || iteratorBlock.properties?.iteratorDataPath;
185
- const products = getProductsFromDataSource(
186
- sectionDataSource,
187
- dataPath,
188
- isDesigner
189
- );
190
-
191
- const useIteratorCount =
192
- forceIteratorCount !== undefined
193
- ? true
194
- : iteratorBlock.properties?.useIteratorCount === true ||
195
- iteratorBlock.properties?.useIteratorCount === 'true';
196
- const iteratorCount =
197
- forceIteratorCount !== undefined
198
- ? Math.max(1, Math.floor(forceIteratorCount))
199
- : parsePositiveNumber(iteratorBlock.properties?.iteratorCount, 1);
200
- const iteratorOffset =
201
- forceIteratorOffset !== undefined
202
- ? Math.max(0, Math.floor(forceIteratorOffset))
203
- : parsePositiveNumber(iteratorBlock.properties?.iteratorOffset, 0);
204
-
205
- const displayProducts =
206
- products.length > 0
207
- ? useIteratorCount
208
- ? products.slice(iteratorOffset, iteratorOffset + iteratorCount)
209
- : products
210
- : [];
211
-
212
- const actualCount =
213
- displayProducts.length > 0 ? displayProducts.length : Math.max(iteratorCount, 1);
214
-
215
- const clonedBlocks = Array.from({ length: actualCount }, (_, index) => {
216
- const product = displayProducts[index] || {};
217
-
218
- const templateCopy: Block = {
219
- ...template,
220
- id: `${template.id}-clone-${index}`,
221
- properties: template.properties
222
- ? { ...template.properties }
223
- : template.properties,
224
- blocks: template.blocks ? template.blocks.map(b => ({ ...b })) : undefined
225
- };
226
-
227
- return replaceBlockValues(templateCopy, product, index);
228
- });
229
-
230
- return {
231
- ...iteratorBlock,
232
- blocks: clonedBlocks
233
- };
234
- };
@@ -1,86 +0,0 @@
1
- export interface PublishWindowValue {
2
- enabled?: boolean;
3
- startAt?: string;
4
- endAt?: string;
5
- }
6
-
7
- export type PublishWindowStatus =
8
- | 'inactive'
9
- | 'scheduled'
10
- | 'active'
11
- | 'expired';
12
-
13
- const isPublishWindowShape = (value: unknown): value is PublishWindowValue => {
14
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
15
- return false;
16
- }
17
-
18
- const candidate = value as Record<string, unknown>;
19
- return (
20
- candidate.enabled !== undefined ||
21
- candidate.startAt !== undefined ||
22
- candidate.endAt !== undefined
23
- );
24
- };
25
-
26
- export const normalizePublishWindowValue = (
27
- value: unknown
28
- ): PublishWindowValue => {
29
- if (isPublishWindowShape(value)) {
30
- return {
31
- enabled: value.enabled === true,
32
- startAt: typeof value.startAt === 'string' ? value.startAt : '',
33
- endAt: typeof value.endAt === 'string' ? value.endAt : ''
34
- };
35
- }
36
-
37
- if (value && typeof value === 'object' && !Array.isArray(value)) {
38
- const responsiveValue = value as Record<string, unknown>;
39
- const nestedValue =
40
- responsiveValue.desktop ||
41
- responsiveValue.mobile ||
42
- responsiveValue.tablet;
43
-
44
- if (nestedValue && nestedValue !== value) {
45
- return normalizePublishWindowValue(nestedValue);
46
- }
47
- }
48
-
49
- return {
50
- enabled: false,
51
- startAt: '',
52
- endAt: ''
53
- };
54
- };
55
-
56
- const parsePublishTime = (value?: string): number | null => {
57
- if (!value) return null;
58
- const parsed = Date.parse(value);
59
- return Number.isNaN(parsed) ? null : parsed;
60
- };
61
-
62
- export const getPublishWindowStatus = (
63
- value: unknown,
64
- now: Date = new Date()
65
- ): PublishWindowStatus => {
66
- const publishWindow = normalizePublishWindowValue(value);
67
-
68
- if (!publishWindow.enabled) return 'inactive';
69
-
70
- const currentTime = now.getTime();
71
- const startAt = parsePublishTime(publishWindow.startAt);
72
- const endAt = parsePublishTime(publishWindow.endAt);
73
-
74
- if (startAt !== null && currentTime < startAt) return 'scheduled';
75
- if (endAt !== null && currentTime > endAt) return 'expired';
76
-
77
- return 'active';
78
- };
79
-
80
- export const isPublishWindowVisible = (
81
- value: unknown,
82
- now: Date = new Date()
83
- ): boolean => {
84
- const status = getPublishWindowStatus(value, now);
85
- return status === 'inactive' || status === 'active';
86
- };
@@ -1,188 +0,0 @@
1
- import { Block } from '../theme-block';
2
- import { Section } from '../theme-section';
3
-
4
- export type VisibilityAuthState = 'all' | 'authenticated' | 'guest';
5
- export type VisibilityPathMatchType =
6
- | 'any'
7
- | 'equals'
8
- | 'contains'
9
- | 'startsWith';
10
-
11
- export interface VisibilityRules {
12
- enabled?: boolean;
13
- authState?: VisibilityAuthState;
14
- allowedBreakpoints?: string[];
15
- allowedLocales?: string[];
16
- allowedCurrencies?: string[];
17
- pathnameMatchType?: VisibilityPathMatchType;
18
- pathnameValue?: string;
19
- queryParamKey?: string;
20
- queryParamValue?: string;
21
- }
22
-
23
- export interface VisibilityRuleContext {
24
- authState: 'authenticated' | 'guest' | 'loading';
25
- breakpoint: string;
26
- locale: string;
27
- currency: string;
28
- pathname: string;
29
- searchParams?: {
30
- get: (key: string) => string | null;
31
- } | null;
32
- }
33
-
34
- const normalizeStringArray = (value: unknown): string[] => {
35
- if (!Array.isArray(value)) return [];
36
- return value
37
- .map(item => String(item || '').trim())
38
- .filter(Boolean);
39
- };
40
-
41
- export const normalizeVisibilityRules = (value: unknown): VisibilityRules => {
42
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
43
- return {
44
- enabled: false,
45
- authState: 'all',
46
- allowedBreakpoints: [],
47
- allowedLocales: [],
48
- allowedCurrencies: [],
49
- pathnameMatchType: 'any',
50
- pathnameValue: '',
51
- queryParamKey: '',
52
- queryParamValue: ''
53
- };
54
- }
55
-
56
- const rules = value as Record<string, unknown>;
57
- return {
58
- enabled: rules.enabled === true,
59
- authState:
60
- rules.authState === 'authenticated' || rules.authState === 'guest'
61
- ? rules.authState
62
- : 'all',
63
- allowedBreakpoints: normalizeStringArray(rules.allowedBreakpoints),
64
- allowedLocales: normalizeStringArray(rules.allowedLocales),
65
- allowedCurrencies: normalizeStringArray(rules.allowedCurrencies).map(item =>
66
- item.toUpperCase()
67
- ),
68
- pathnameMatchType:
69
- rules.pathnameMatchType === 'equals' ||
70
- rules.pathnameMatchType === 'contains' ||
71
- rules.pathnameMatchType === 'startsWith'
72
- ? rules.pathnameMatchType
73
- : 'any',
74
- pathnameValue: String(rules.pathnameValue || '').trim(),
75
- queryParamKey: String(rules.queryParamKey || '').trim(),
76
- queryParamValue: String(rules.queryParamValue || '').trim()
77
- };
78
- };
79
-
80
- export const evaluateVisibilityRules = (
81
- rawRules: unknown,
82
- context: VisibilityRuleContext
83
- ): boolean => {
84
- const rules = normalizeVisibilityRules(rawRules);
85
- if (!rules.enabled) return true;
86
-
87
- if (rules.authState && rules.authState !== 'all') {
88
- if (context.authState === 'loading') return false;
89
- if (rules.authState === 'authenticated') {
90
- if (context.authState !== 'authenticated') return false;
91
- } else if (context.authState !== 'guest') {
92
- return false;
93
- }
94
- }
95
-
96
- if (
97
- rules.allowedBreakpoints &&
98
- rules.allowedBreakpoints.length > 0 &&
99
- !rules.allowedBreakpoints.includes(context.breakpoint)
100
- ) {
101
- return false;
102
- }
103
-
104
- if (
105
- rules.allowedLocales &&
106
- rules.allowedLocales.length > 0 &&
107
- !rules.allowedLocales.includes(context.locale)
108
- ) {
109
- return false;
110
- }
111
-
112
- if (
113
- rules.allowedCurrencies &&
114
- rules.allowedCurrencies.length > 0 &&
115
- !rules.allowedCurrencies.includes(String(context.currency || '').toUpperCase())
116
- ) {
117
- return false;
118
- }
119
-
120
- const pathname = String(context.pathname || '');
121
- if (rules.pathnameMatchType && rules.pathnameMatchType !== 'any') {
122
- const ruleValue = String(rules.pathnameValue || '').trim();
123
- if (!ruleValue) return false;
124
-
125
- if (rules.pathnameMatchType === 'equals' && pathname !== ruleValue) {
126
- return false;
127
- }
128
-
129
- if (
130
- rules.pathnameMatchType === 'contains' &&
131
- !pathname.includes(ruleValue)
132
- ) {
133
- return false;
134
- }
135
-
136
- if (
137
- rules.pathnameMatchType === 'startsWith' &&
138
- !pathname.startsWith(ruleValue)
139
- ) {
140
- return false;
141
- }
142
- }
143
-
144
- if (rules.queryParamKey) {
145
- const actualValue = context.searchParams?.get(rules.queryParamKey) ?? null;
146
- if (actualValue === null) return false;
147
- if (rules.queryParamValue && actualValue !== rules.queryParamValue) {
148
- return false;
149
- }
150
- }
151
-
152
- return true;
153
- };
154
-
155
- const applyBlockVisibility = (
156
- block: Block,
157
- context: VisibilityRuleContext
158
- ): Block => {
159
- const blocks = block.blocks?.map(child => applyBlockVisibility(child, context));
160
- const isVisibleByRules = evaluateVisibilityRules(
161
- block.properties?.visibilityRules,
162
- context
163
- );
164
-
165
- return {
166
- ...block,
167
- hidden: Boolean(block.hidden) || !isVisibleByRules,
168
- blocks
169
- };
170
- };
171
-
172
- export const applyVisibilityRulesToSections = (
173
- sections: Section[],
174
- context: VisibilityRuleContext
175
- ): Section[] =>
176
- sections.map(section => {
177
- const blocks = section.blocks.map(block => applyBlockVisibility(block, context));
178
- const isVisibleByRules = evaluateVisibilityRules(
179
- section.properties?.visibilityRules,
180
- context
181
- );
182
-
183
- return {
184
- ...section,
185
- hidden: Boolean(section.hidden) || !isVisibleByRules,
186
- blocks
187
- };
188
- });