@akinon/projectzero 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 (140) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/app-template/CHANGELOG.md +170 -0
  3. package/app-template/next.config.mjs +0 -1
  4. package/app-template/package.json +31 -30
  5. package/app-template/src/app/[pz]/[...prettyurl]/page.tsx +2 -2
  6. package/app-template/src/app/[pz]/account/layout.tsx +2 -1
  7. package/app-template/src/app/{[commerce]/[locale]/[currency] → [pz]}/blog/[slug]/page.tsx +4 -2
  8. package/app-template/src/app/[pz]/category/[pk]/page.tsx +11 -1
  9. package/app-template/src/app/[pz]/group-product/[pk]/page.tsx +2 -2
  10. package/app-template/src/app/[pz]/layout.tsx +3 -1
  11. package/app-template/src/app/[pz]/list/page.tsx +11 -1
  12. package/app-template/src/app/[pz]/page.tsx +13 -35
  13. package/app-template/src/app/[pz]/pages/[slug]/page.tsx +19 -0
  14. package/app-template/src/app/[pz]/product/[pk]/page.tsx +2 -2
  15. package/app-template/src/app/api/barcode-search/route.ts +1 -1
  16. package/app-template/src/app/api/cache/route.ts +1 -1
  17. package/app-template/src/app/api/image-proxy/route.ts +1 -1
  18. package/app-template/src/app/api/logout/route.ts +1 -1
  19. package/app-template/src/app/api/product-categories/route.ts +1 -1
  20. package/app-template/src/app/api/similar-product-list/route.ts +1 -1
  21. package/app-template/src/app/api/similar-products/route.ts +1 -1
  22. package/app-template/src/app/api/virtual-try-on/route.ts +1 -1
  23. package/app-template/src/app/api/web-vitals/route.ts +1 -1
  24. package/app-template/src/components/quantity-selector.tsx +16 -4
  25. package/app-template/src/components/widget-content.tsx +3 -3
  26. package/app-template/src/routes/index.ts +6 -6
  27. package/app-template/src/utils/__tests__/theme-page-context.test.ts +145 -0
  28. package/app-template/src/utils/theme-page-context.ts +309 -0
  29. package/app-template/src/views/basket/basket-item.tsx +107 -691
  30. package/app-template/src/views/basket/index.ts +0 -2
  31. package/app-template/src/views/basket/summary.tsx +75 -496
  32. package/app-template/src/views/breadcrumb.tsx +38 -13
  33. package/app-template/src/views/category/category-header.tsx +66 -289
  34. package/app-template/src/views/category/category-info.tsx +24 -173
  35. package/app-template/src/views/category/filters/index.tsx +48 -208
  36. package/app-template/src/views/category/layout.tsx +5 -7
  37. package/app-template/src/views/checkout/index.tsx +0 -5
  38. package/app-template/src/views/checkout/steps/payment/index.tsx +2 -5
  39. package/app-template/src/views/checkout/steps/payment/options/credit-card/index.tsx +1 -72
  40. package/app-template/src/views/checkout/steps/payment/payment-option-buttons.tsx +40 -171
  41. package/app-template/src/views/checkout/steps/shipping/address-box.tsx +12 -74
  42. package/app-template/src/views/checkout/steps/shipping/addresses.tsx +45 -128
  43. package/app-template/src/views/checkout/steps/shipping/shipping-options.tsx +27 -232
  44. package/app-template/src/views/checkout/summary.tsx +29 -303
  45. package/app-template/src/views/footer.tsx +13 -415
  46. package/app-template/src/views/guest-login/index.tsx +1 -1
  47. package/app-template/src/views/header/action-menu.tsx +45 -277
  48. package/app-template/src/views/header/band.tsx +21 -6
  49. package/app-template/src/views/header/index.tsx +47 -109
  50. package/app-template/src/views/header/mini-basket.tsx +45 -820
  51. package/app-template/src/views/header/navbar.tsx +111 -178
  52. package/app-template/src/views/header/search/index.tsx +32 -71
  53. package/app-template/src/views/header/search/results.tsx +65 -127
  54. package/app-template/src/views/product/accordion-wrapper.tsx +43 -135
  55. package/app-template/src/views/product/index.ts +1 -1
  56. package/app-template/src/views/product/layout.tsx +7 -2
  57. package/app-template/src/views/product/misc-buttons.tsx +25 -339
  58. package/app-template/src/views/product/product-actions.tsx +8 -137
  59. package/app-template/src/views/product/product-info.tsx +31 -69
  60. package/app-template/src/views/product/product-share.tsx +8 -11
  61. package/app-template/src/views/product/slider.tsx +79 -117
  62. package/app-template/src/views/product-item/index.tsx +46 -119
  63. package/app-template/src/widgets/footer-social.tsx +16 -47
  64. package/app-template/src/widgets/footer-subscription/index.tsx +17 -183
  65. package/codemods/migrate-auth-v5/index.js +339 -0
  66. package/codemods/migrate-auth-v5/transform.js +86 -0
  67. package/dist/commands/plugins.js +23 -2
  68. package/package.json +1 -1
  69. package/app-template/src/app/[commerce]/[locale]/[currency]/pages/[slug]/page.tsx +0 -15
  70. package/app-template/src/views/basket/basket-summary-context.tsx +0 -560
  71. package/app-template/src/views/basket/designer-context.tsx +0 -617
  72. package/app-template/src/views/breadcrumb/breadcrumb-client.tsx +0 -190
  73. package/app-template/src/views/breadcrumb/breadcrumb-registrar.tsx +0 -286
  74. package/app-template/src/views/breadcrumb/constants.ts +0 -15
  75. package/app-template/src/views/breadcrumb/index.tsx +0 -127
  76. package/app-template/src/views/category/native-widget-context.tsx +0 -257
  77. package/app-template/src/views/category/product-list-registrar.tsx +0 -665
  78. package/app-template/src/views/checkout/checkout-address-registrar.tsx +0 -254
  79. package/app-template/src/views/checkout/checkout-buttons-registrar.tsx +0 -183
  80. package/app-template/src/views/checkout/checkout-delivery-method-registrar.tsx +0 -259
  81. package/app-template/src/views/checkout/checkout-payment-options-registrar.tsx +0 -253
  82. package/app-template/src/views/checkout/checkout-summary-registrar.tsx +0 -183
  83. package/app-template/src/views/checkout/constants.ts +0 -5
  84. package/app-template/src/views/checkout/steps/payment/options/masterpass-rest.tsx +0 -15
  85. package/app-template/src/views/checkout/steps/payment/options/saved-card.tsx +0 -18
  86. package/app-template/src/views/footer/footer-app-banner-context.tsx +0 -326
  87. package/app-template/src/views/footer/footer-bottom-context.tsx +0 -215
  88. package/app-template/src/views/footer/footer-bottom-wrapper.tsx +0 -74
  89. package/app-template/src/views/footer/footer-layout-constants.ts +0 -35
  90. package/app-template/src/views/footer/footer-layout-registrar.tsx +0 -342
  91. package/app-template/src/views/footer/footer-layout-switcher.tsx +0 -110
  92. package/app-template/src/views/footer/footer-menu-context.tsx +0 -211
  93. package/app-template/src/views/footer/footer-native-widgets.tsx +0 -60
  94. package/app-template/src/views/footer/footer-social-context.tsx +0 -254
  95. package/app-template/src/views/footer/footer-subscription-context.tsx +0 -210
  96. package/app-template/src/views/footer/footer-utils.ts +0 -43
  97. package/app-template/src/views/footer/footer-value-props-context.tsx +0 -326
  98. package/app-template/src/views/footer/logo-settings.ts +0 -183
  99. package/app-template/src/views/footer/native-widget-config.ts +0 -262
  100. package/app-template/src/views/footer/subscription-settings.ts +0 -122
  101. package/app-template/src/views/footer/use-footer-logo.ts +0 -162
  102. package/app-template/src/views/header/designer-context.tsx +0 -261
  103. package/app-template/src/views/header/header-announcement-registrar.tsx +0 -267
  104. package/app-template/src/views/header/header-client-wrapper.tsx +0 -496
  105. package/app-template/src/views/header/header-content.tsx +0 -1026
  106. package/app-template/src/views/header/header-currency-registrar.tsx +0 -348
  107. package/app-template/src/views/header/header-icons-context.tsx +0 -262
  108. package/app-template/src/views/header/header-language-registrar.tsx +0 -348
  109. package/app-template/src/views/header/header-layout-context.tsx +0 -143
  110. package/app-template/src/views/header/header-layout-registrar.tsx +0 -658
  111. package/app-template/src/views/header/header-logo-context.tsx +0 -228
  112. package/app-template/src/views/header/header-logo.tsx +0 -118
  113. package/app-template/src/views/header/header-mini-basket-context.tsx +0 -524
  114. package/app-template/src/views/header/header-search-registrar.tsx +0 -511
  115. package/app-template/src/views/header/header-text-slider-registrar.tsx +0 -382
  116. package/app-template/src/views/header/inline-search.tsx +0 -262
  117. package/app-template/src/views/header/navbar-menu-context.tsx +0 -219
  118. package/app-template/src/views/header/search/search-input.tsx +0 -61
  119. package/app-template/src/views/header/server-settings-parser.ts +0 -1105
  120. package/app-template/src/views/header/use-header-icons.ts +0 -241
  121. package/app-template/src/views/header/use-header-logo.ts +0 -213
  122. package/app-template/src/views/header/use-navbar-menu.ts +0 -179
  123. package/app-template/src/views/product/accordion-section.tsx +0 -61
  124. package/app-template/src/views/product/custom-button-group.tsx +0 -69
  125. package/app-template/src/views/product/favorites-button-section.tsx +0 -69
  126. package/app-template/src/views/product/find-in-store-section.tsx +0 -60
  127. package/app-template/src/views/product/product-info-section.tsx +0 -140
  128. package/app-template/src/views/product/quantity-section.tsx +0 -73
  129. package/app-template/src/views/product/sale-tag.tsx +0 -10
  130. package/app-template/src/views/product/share-section.tsx +0 -357
  131. package/app-template/src/views/product/variants-section.tsx +0 -126
  132. package/app-template/src/views/product-detail/constants.ts +0 -272
  133. package/app-template/src/views/product-detail/index.ts +0 -10
  134. package/app-template/src/views/product-detail/product-detail-registrar.tsx +0 -616
  135. package/app-template/src/widgets/footer-app-banner.tsx +0 -444
  136. package/app-template/src/widgets/footer-bottom.tsx +0 -127
  137. package/app-template/src/widgets/footer-menu-compact.tsx +0 -238
  138. package/app-template/src/widgets/footer-menu-two.tsx +0 -298
  139. package/app-template/src/widgets/footer-social-client.tsx +0 -251
  140. package/app-template/src/widgets/footer-value-props.tsx +0 -201
@@ -1,60 +0,0 @@
1
- 'use client';
2
-
3
- import { useEffect } from 'react';
4
- import type { FooterNativeWidgetSection, FooterNativeWidgetBlock } from './native-widget-config';
5
-
6
- interface FooterNativeWidgetsProps {
7
- sections: FooterNativeWidgetSection[];
8
- }
9
-
10
- interface MappedBlock {
11
- id: string;
12
- type: string;
13
- label: string;
14
- styles?: Record<string, unknown>;
15
- properties?: Record<string, unknown>;
16
- value?: unknown;
17
- blocks?: MappedBlock[];
18
- }
19
-
20
- const mapBlock = (block: FooterNativeWidgetBlock): MappedBlock => ({
21
- id: block.id,
22
- type: block.type,
23
- label: block.label,
24
- styles: block.styles,
25
- properties: block.properties,
26
- value: block.value,
27
- blocks: block.blocks?.map(mapBlock)
28
- });
29
-
30
- export default function FooterNativeWidgets({
31
- sections
32
- }: FooterNativeWidgetsProps) {
33
- useEffect(() => {
34
- if (typeof window === 'undefined') return;
35
- const isInIframe = window.self !== window.top;
36
- if (!isInIframe || !window.parent || !sections.length) {
37
- return;
38
- }
39
-
40
- const widgets = sections.map((section) => ({
41
- placeholderId: section.placeholderId,
42
- section: {
43
- id: section.sectionId,
44
- type: 'native',
45
- label: section.label,
46
- blocks: section.blocks.map(mapBlock)
47
- }
48
- }));
49
-
50
- window.parent.postMessage(
51
- {
52
- type: 'REGISTER_NATIVE_WIDGETS',
53
- data: { widgets }
54
- },
55
- '*'
56
- );
57
- }, [sections]);
58
-
59
- return null;
60
- }
@@ -1,254 +0,0 @@
1
- 'use client';
2
-
3
- import {
4
- createContext,
5
- useCallback,
6
- useContext,
7
- useEffect,
8
- useMemo,
9
- useRef,
10
- useState,
11
- type PropsWithChildren
12
- } from 'react';
13
- import { useExternalDesigner } from '@akinon/next/components/theme-editor/hooks/use-external-designer';
14
- import { useNativeWidgetData } from '@akinon/next/components/theme-editor/hooks/use-native-widget-data';
15
-
16
- import {
17
- FOOTER_PLACEHOLDER_ID,
18
- FOOTER_SOCIAL_SECTION_ID,
19
- FOOTER_SOCIAL_WIDGET_SLUG,
20
- FOOTER_SOCIAL_ICONS_BLOCK_ID,
21
- type FooterNativeWidgetBlock
22
- } from './native-widget-config';
23
-
24
- export { FOOTER_SOCIAL_ICONS_BLOCK_ID };
25
-
26
- type FooterSocialBlockState = FooterNativeWidgetBlock;
27
-
28
- interface FooterSocialContextValue {
29
- isDesigner: boolean;
30
- selectedBlockId: string | null;
31
- getBlock: (blockId: string) => FooterSocialBlockState | undefined;
32
- blockVersion: number;
33
- }
34
-
35
- const FooterSocialContext = createContext<FooterSocialContextValue>({
36
- isDesigner: false,
37
- selectedBlockId: null,
38
- getBlock: () => undefined,
39
- blockVersion: 0
40
- });
41
-
42
- const BLOCK_META = [
43
- {
44
- id: FOOTER_SOCIAL_ICONS_BLOCK_ID,
45
- type: 'social-icons-list',
46
- label: 'Social Icons'
47
- }
48
- ];
49
-
50
- const toBlockState = (
51
- block: Partial<FooterNativeWidgetBlock>
52
- ): FooterSocialBlockState => {
53
- const fallback = BLOCK_META.find((meta) => meta.id === block.id);
54
- return {
55
- id: block.id ?? fallback?.id ?? '',
56
- type: block.type ?? fallback?.type,
57
- label: block.label ?? fallback?.label,
58
- styles: block.styles,
59
- properties: block.properties,
60
- value: block.value
61
- } as FooterSocialBlockState;
62
- };
63
-
64
- const mapFromSnapshot = (
65
- blocks?: FooterNativeWidgetBlock[],
66
- defaultIcons?: SocialIconItem[]
67
- ): Map<string, FooterSocialBlockState> => {
68
- const map = new Map<string, FooterSocialBlockState>();
69
- blocks?.forEach((block) => {
70
- map.set(block.id, toBlockState(block));
71
- });
72
-
73
- BLOCK_META.forEach((meta) => {
74
- if (!map.has(meta.id)) {
75
- const defaultProperties =
76
- meta.id === FOOTER_SOCIAL_ICONS_BLOCK_ID && defaultIcons?.length
77
- ? { icons: defaultIcons }
78
- : undefined;
79
-
80
- map.set(
81
- meta.id,
82
- toBlockState({
83
- ...meta,
84
- properties: defaultProperties
85
- })
86
- );
87
- } else if (
88
- meta.id === FOOTER_SOCIAL_ICONS_BLOCK_ID &&
89
- defaultIcons?.length
90
- ) {
91
- const existing = map.get(meta.id);
92
- const existingIcons = (existing?.properties as any)?.icons;
93
- if (
94
- !existingIcons ||
95
- (Array.isArray(existingIcons) && existingIcons.length === 0)
96
- ) {
97
- map.set(
98
- meta.id,
99
- toBlockState({
100
- ...existing,
101
- properties: { ...existing?.properties, icons: defaultIcons }
102
- })
103
- );
104
- }
105
- }
106
- });
107
-
108
- return map;
109
- };
110
-
111
- export interface SocialIconItem {
112
- icon: string;
113
- link: string;
114
- size?: number;
115
- color?: string;
116
- }
117
-
118
- interface FooterSocialProviderProps {
119
- initialBlocks?: FooterNativeWidgetBlock[];
120
- defaultIcons?: SocialIconItem[];
121
- }
122
-
123
- export function FooterSocialProvider({
124
- initialBlocks,
125
- defaultIcons,
126
- children
127
- }: PropsWithChildren<FooterSocialProviderProps>) {
128
- const designerState = useExternalDesigner({
129
- placeholderId: FOOTER_PLACEHOLDER_ID
130
- });
131
-
132
- const [blockMap, setBlockMap] = useState(() =>
133
- mapFromSnapshot(initialBlocks, defaultIcons)
134
- );
135
- const blockMapRef = useRef(blockMap);
136
- const [blockVersion, setBlockVersion] = useState(0);
137
-
138
- const isDesignerRef = useRef(false);
139
- const [isDesignerChecked, setIsDesignerChecked] = useState(false);
140
-
141
- useEffect(() => {
142
- if (typeof window === 'undefined') return;
143
- isDesignerRef.current = window.self !== window.top;
144
- setIsDesignerChecked(true);
145
- }, []);
146
-
147
- const isDesigner = isDesignerRef.current;
148
-
149
- const widgetData = useNativeWidgetData({
150
- widgetSlug: FOOTER_SOCIAL_WIDGET_SLUG,
151
- sectionId: FOOTER_SOCIAL_SECTION_ID,
152
- skip: !isDesignerChecked || isDesigner,
153
- blockMeta: BLOCK_META
154
- });
155
-
156
- const mergeBlocks = useCallback(
157
- (blocks: Partial<FooterNativeWidgetBlock>[] | undefined) => {
158
- if (!blocks?.length) return;
159
-
160
- setBlockMap((prev) => {
161
- const next = new Map(prev);
162
- blocks.forEach((block) => {
163
- if (!block.id) return;
164
- const existing = next.get(block.id);
165
-
166
- next.set(
167
- block.id,
168
- toBlockState({
169
- ...existing,
170
- ...block,
171
- styles:
172
- block.styles && Object.keys(block.styles).length > 0
173
- ? block.styles
174
- : existing?.styles,
175
- properties:
176
- block.properties && Object.keys(block.properties).length > 0
177
- ? block.properties
178
- : existing?.properties,
179
- value: block.value !== undefined ? block.value : existing?.value
180
- })
181
- );
182
- });
183
- blockMapRef.current = next;
184
- return next;
185
- });
186
- setBlockVersion((prev) => prev + 1);
187
- },
188
- []
189
- );
190
-
191
- useEffect(() => {
192
- if (!isDesignerChecked || isDesigner || widgetData.isLoading) return;
193
-
194
- const blocksToMerge: Partial<FooterNativeWidgetBlock>[] = [];
195
- widgetData.blocks.forEach((block) => {
196
- blocksToMerge.push(block as FooterNativeWidgetBlock);
197
- });
198
-
199
- if (blocksToMerge.length > 0) {
200
- mergeBlocks(blocksToMerge);
201
- }
202
- }, [
203
- isDesigner,
204
- isDesignerChecked,
205
- widgetData.isLoading,
206
- widgetData.blocks,
207
- mergeBlocks
208
- ]);
209
-
210
- useEffect(() => {
211
- const handleMessage = (event: MessageEvent) => {
212
- const { type, data } = event.data || {};
213
- if (
214
- (type === 'UPDATE_THEME' || type === 'LOAD_THEME') &&
215
- data?.theme?.placeholders
216
- ) {
217
- const placeholder = data.theme.placeholders.find(
218
- (p: { slug: string }) => p.slug === FOOTER_PLACEHOLDER_ID
219
- );
220
- const section = placeholder?.sections?.find(
221
- (s: { id: string }) => s.id === FOOTER_SOCIAL_SECTION_ID
222
- );
223
- mergeBlocks(section?.blocks);
224
- }
225
- };
226
-
227
- window.addEventListener('message', handleMessage);
228
- return () => window.removeEventListener('message', handleMessage);
229
- }, [mergeBlocks]);
230
-
231
- const getBlock = useCallback(
232
- (blockId: string) => blockMapRef.current.get(blockId),
233
- []
234
- );
235
-
236
- const contextValue = useMemo(
237
- () => ({
238
- ...designerState,
239
- getBlock,
240
- blockVersion
241
- }),
242
- [designerState, getBlock, blockVersion]
243
- );
244
-
245
- return (
246
- <FooterSocialContext.Provider value={contextValue}>
247
- {children}
248
- </FooterSocialContext.Provider>
249
- );
250
- }
251
-
252
- export function useFooterSocialDesigner() {
253
- return useContext(FooterSocialContext);
254
- }
@@ -1,210 +0,0 @@
1
- 'use client';
2
-
3
- import {
4
- createContext,
5
- useCallback,
6
- useContext,
7
- useEffect,
8
- useMemo,
9
- useRef,
10
- useState,
11
- type PropsWithChildren
12
- } from 'react';
13
- import { useExternalDesigner } from '@akinon/next/components/theme-editor/hooks/use-external-designer';
14
- import { useNativeWidgetData } from '@akinon/next/components/theme-editor/hooks/use-native-widget-data';
15
-
16
- import {
17
- FOOTER_PLACEHOLDER_ID,
18
- FOOTER_SUBSCRIPTION_SECTION_ID,
19
- FOOTER_SUBSCRIPTION_WIDGET_SLUG,
20
- type FooterNativeWidgetBlock
21
- } from './native-widget-config';
22
- import {
23
- FOOTER_SUBSCRIPTION_BLOCKS,
24
- type FooterSubscriptionBlockSnapshot
25
- } from './subscription-settings';
26
-
27
- type FooterSubscriptionBlockState = FooterNativeWidgetBlock;
28
-
29
- interface FooterSubscriptionContextValue {
30
- isDesigner: boolean;
31
- selectedBlockId: string | null;
32
- getBlock: (blockId: string) => FooterSubscriptionBlockState | undefined;
33
- blockVersion: number;
34
- }
35
-
36
- const FooterSubscriptionContext = createContext<FooterSubscriptionContextValue>(
37
- {
38
- isDesigner: false,
39
- selectedBlockId: null,
40
- getBlock: () => undefined,
41
- blockVersion: 0
42
- }
43
- );
44
-
45
- const BLOCK_META = Object.values(FOOTER_SUBSCRIPTION_BLOCKS);
46
-
47
- const toBlockState = (
48
- block: Partial<FooterNativeWidgetBlock>
49
- ): FooterSubscriptionBlockState => {
50
- const fallback = BLOCK_META.find((meta) => meta.id === block.id);
51
- return {
52
- id: block.id ?? fallback?.id ?? '',
53
- type: block.type ?? fallback?.type,
54
- label: block.label ?? fallback?.label,
55
- styles: block.styles,
56
- properties: block.properties,
57
- value: block.value
58
- } as FooterSubscriptionBlockState;
59
- };
60
-
61
- const mapFromSnapshot = (
62
- blocks?: FooterSubscriptionBlockSnapshot
63
- ): Map<string, FooterSubscriptionBlockState> => {
64
- const map = new Map<string, FooterSubscriptionBlockState>();
65
- blocks?.forEach((block) => {
66
- map.set(block.id, toBlockState(block));
67
- });
68
-
69
- BLOCK_META.forEach((meta) => {
70
- if (!map.has(meta.id)) {
71
- map.set(meta.id, toBlockState(meta));
72
- }
73
- });
74
-
75
- return map;
76
- };
77
-
78
- interface FooterSubscriptionProviderProps {
79
- initialBlocks?: FooterSubscriptionBlockSnapshot;
80
- }
81
-
82
- export function FooterSubscriptionProvider({
83
- initialBlocks,
84
- children
85
- }: PropsWithChildren<FooterSubscriptionProviderProps>) {
86
- const designerState = useExternalDesigner({
87
- placeholderId: FOOTER_PLACEHOLDER_ID
88
- });
89
-
90
- const [blockMap, setBlockMap] = useState(() =>
91
- mapFromSnapshot(initialBlocks)
92
- );
93
- const blockMapRef = useRef(blockMap);
94
- const [blockVersion, setBlockVersion] = useState(0);
95
-
96
- const isDesignerRef = useRef(false);
97
- const [isDesignerChecked, setIsDesignerChecked] = useState(false);
98
-
99
- useEffect(() => {
100
- if (typeof window === 'undefined') return;
101
- isDesignerRef.current = window.self !== window.top;
102
- setIsDesignerChecked(true);
103
- }, []);
104
-
105
- const isDesigner = isDesignerRef.current;
106
-
107
- const widgetData = useNativeWidgetData({
108
- widgetSlug: FOOTER_SUBSCRIPTION_WIDGET_SLUG,
109
- sectionId: FOOTER_SUBSCRIPTION_SECTION_ID,
110
- skip: !isDesignerChecked || isDesigner,
111
- blockMeta: BLOCK_META
112
- });
113
-
114
- const mergeBlocks = useCallback(
115
- (blocks: FooterNativeWidgetBlock[] | undefined) => {
116
- if (!blocks?.length) return;
117
-
118
- setBlockMap((prev) => {
119
- const next = new Map(prev);
120
- blocks.forEach((block) => {
121
- const existing = next.get(block.id);
122
-
123
- next.set(
124
- block.id,
125
- toBlockState({
126
- ...existing,
127
- ...block,
128
- styles:
129
- block.styles && Object.keys(block.styles).length > 0
130
- ? block.styles
131
- : existing?.styles,
132
- properties:
133
- block.properties && Object.keys(block.properties).length > 0
134
- ? block.properties
135
- : existing?.properties,
136
- value: block.value !== undefined ? block.value : existing?.value
137
- })
138
- );
139
- });
140
- blockMapRef.current = next;
141
- return next;
142
- });
143
- setBlockVersion((prev) => prev + 1);
144
- },
145
- []
146
- );
147
-
148
- useEffect(() => {
149
- if (!isDesignerChecked || isDesigner || widgetData.isLoading) return;
150
-
151
- const blocksToMerge: FooterNativeWidgetBlock[] = [];
152
- widgetData.blocks.forEach((block) => {
153
- blocksToMerge.push(block as FooterNativeWidgetBlock);
154
- });
155
-
156
- if (blocksToMerge.length > 0) {
157
- mergeBlocks(blocksToMerge);
158
- }
159
- }, [
160
- isDesigner,
161
- isDesignerChecked,
162
- widgetData.isLoading,
163
- widgetData.blocks,
164
- mergeBlocks
165
- ]);
166
-
167
- useEffect(() => {
168
- const handleMessage = (event: MessageEvent) => {
169
- const { type, data } = event.data || {};
170
- if (
171
- (type === 'UPDATE_THEME' || type === 'LOAD_THEME') &&
172
- data?.theme?.placeholders
173
- ) {
174
- const placeholder = data.theme.placeholders.find(
175
- (p: { slug: string }) => p.slug === FOOTER_PLACEHOLDER_ID
176
- );
177
- const section = placeholder?.sections?.find(
178
- (s: { id: string }) => s.id === FOOTER_SUBSCRIPTION_SECTION_ID
179
- );
180
- mergeBlocks(section?.blocks);
181
- }
182
- };
183
-
184
- window.addEventListener('message', handleMessage);
185
- return () => window.removeEventListener('message', handleMessage);
186
- }, [mergeBlocks]);
187
-
188
- const getBlock = useCallback(
189
- (blockId: string) => blockMapRef.current.get(blockId),
190
- []
191
- );
192
-
193
- const contextValue = useMemo(
194
- () => ({
195
- ...designerState,
196
- getBlock,
197
- blockVersion
198
- }),
199
- [designerState, getBlock, blockVersion]
200
- );
201
-
202
- return (
203
- <FooterSubscriptionContext.Provider value={contextValue}>
204
- {children}
205
- </FooterSubscriptionContext.Provider>
206
- );
207
- }
208
-
209
- export const useFooterSubscriptionDesigner = () =>
210
- useContext(FooterSubscriptionContext);
@@ -1,43 +0,0 @@
1
- /**
2
- * Footer Utilities
3
- *
4
- * Shared utility functions for footer components.
5
- */
6
-
7
- /**
8
- * Convert block styles to CSS properties
9
- */
10
- export function convertBlockStyles(
11
- styles: Record<string, unknown>
12
- ): React.CSSProperties {
13
- const styleMap: Record<string, string | null> = {
14
- 'background-color': 'backgroundColor',
15
- 'padding-top': 'paddingTop',
16
- 'padding-bottom': 'paddingBottom',
17
- 'border-top-width': 'borderTopWidth',
18
- 'border-top-color': 'borderTopColor'
19
- };
20
-
21
- const result: Record<string, unknown> = {};
22
-
23
- Object.entries(styles).forEach(([key, value]) => {
24
- if (value === undefined || value === null || value === '') return;
25
-
26
- const cssKey = styleMap[key] || key;
27
- if (cssKey === null) return;
28
-
29
- // Extract desktop value if responsive
30
- if (value && typeof value === 'object' && 'desktop' in value) {
31
- result[cssKey] = (value as Record<string, unknown>).desktop;
32
- } else {
33
- result[cssKey] = value;
34
- }
35
- });
36
-
37
- // Auto-add border-style: solid if border-top-width is set
38
- if (result.borderTopWidth && !result.borderTopStyle) {
39
- result.borderTopStyle = 'solid';
40
- }
41
-
42
- return result as React.CSSProperties;
43
- }