@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.
- package/CHANGELOG.md +14 -0
- package/app-template/CHANGELOG.md +170 -0
- package/app-template/next.config.mjs +0 -1
- package/app-template/package.json +31 -30
- package/app-template/src/app/[pz]/[...prettyurl]/page.tsx +2 -2
- package/app-template/src/app/[pz]/account/layout.tsx +2 -1
- package/app-template/src/app/{[commerce]/[locale]/[currency] → [pz]}/blog/[slug]/page.tsx +4 -2
- package/app-template/src/app/[pz]/category/[pk]/page.tsx +11 -1
- package/app-template/src/app/[pz]/group-product/[pk]/page.tsx +2 -2
- package/app-template/src/app/[pz]/layout.tsx +3 -1
- package/app-template/src/app/[pz]/list/page.tsx +11 -1
- package/app-template/src/app/[pz]/page.tsx +13 -35
- package/app-template/src/app/[pz]/pages/[slug]/page.tsx +19 -0
- package/app-template/src/app/[pz]/product/[pk]/page.tsx +2 -2
- package/app-template/src/app/api/barcode-search/route.ts +1 -1
- package/app-template/src/app/api/cache/route.ts +1 -1
- package/app-template/src/app/api/image-proxy/route.ts +1 -1
- package/app-template/src/app/api/logout/route.ts +1 -1
- package/app-template/src/app/api/product-categories/route.ts +1 -1
- package/app-template/src/app/api/similar-product-list/route.ts +1 -1
- package/app-template/src/app/api/similar-products/route.ts +1 -1
- package/app-template/src/app/api/virtual-try-on/route.ts +1 -1
- package/app-template/src/app/api/web-vitals/route.ts +1 -1
- package/app-template/src/components/quantity-selector.tsx +16 -4
- package/app-template/src/components/widget-content.tsx +3 -3
- package/app-template/src/routes/index.ts +6 -6
- package/app-template/src/utils/__tests__/theme-page-context.test.ts +145 -0
- package/app-template/src/utils/theme-page-context.ts +309 -0
- package/app-template/src/views/basket/basket-item.tsx +107 -691
- package/app-template/src/views/basket/index.ts +0 -2
- package/app-template/src/views/basket/summary.tsx +75 -496
- package/app-template/src/views/breadcrumb.tsx +38 -13
- package/app-template/src/views/category/category-header.tsx +66 -289
- package/app-template/src/views/category/category-info.tsx +24 -173
- package/app-template/src/views/category/filters/index.tsx +48 -208
- package/app-template/src/views/category/layout.tsx +5 -7
- package/app-template/src/views/checkout/index.tsx +0 -5
- package/app-template/src/views/checkout/steps/payment/index.tsx +2 -5
- package/app-template/src/views/checkout/steps/payment/options/credit-card/index.tsx +1 -72
- package/app-template/src/views/checkout/steps/payment/payment-option-buttons.tsx +40 -171
- package/app-template/src/views/checkout/steps/shipping/address-box.tsx +12 -74
- package/app-template/src/views/checkout/steps/shipping/addresses.tsx +45 -128
- package/app-template/src/views/checkout/steps/shipping/shipping-options.tsx +27 -232
- package/app-template/src/views/checkout/summary.tsx +29 -303
- package/app-template/src/views/footer.tsx +13 -415
- package/app-template/src/views/guest-login/index.tsx +1 -1
- package/app-template/src/views/header/action-menu.tsx +45 -277
- package/app-template/src/views/header/band.tsx +21 -6
- package/app-template/src/views/header/index.tsx +47 -109
- package/app-template/src/views/header/mini-basket.tsx +45 -820
- package/app-template/src/views/header/navbar.tsx +111 -178
- package/app-template/src/views/header/search/index.tsx +32 -71
- package/app-template/src/views/header/search/results.tsx +65 -127
- package/app-template/src/views/product/accordion-wrapper.tsx +43 -135
- package/app-template/src/views/product/index.ts +1 -1
- package/app-template/src/views/product/layout.tsx +7 -2
- package/app-template/src/views/product/misc-buttons.tsx +25 -339
- package/app-template/src/views/product/product-actions.tsx +8 -137
- package/app-template/src/views/product/product-info.tsx +31 -69
- package/app-template/src/views/product/product-share.tsx +8 -11
- package/app-template/src/views/product/slider.tsx +79 -117
- package/app-template/src/views/product-item/index.tsx +46 -119
- package/app-template/src/widgets/footer-social.tsx +16 -47
- package/app-template/src/widgets/footer-subscription/index.tsx +17 -183
- package/codemods/migrate-auth-v5/index.js +339 -0
- package/codemods/migrate-auth-v5/transform.js +86 -0
- package/dist/commands/plugins.js +23 -2
- package/package.json +1 -1
- package/app-template/src/app/[commerce]/[locale]/[currency]/pages/[slug]/page.tsx +0 -15
- package/app-template/src/views/basket/basket-summary-context.tsx +0 -560
- package/app-template/src/views/basket/designer-context.tsx +0 -617
- package/app-template/src/views/breadcrumb/breadcrumb-client.tsx +0 -190
- package/app-template/src/views/breadcrumb/breadcrumb-registrar.tsx +0 -286
- package/app-template/src/views/breadcrumb/constants.ts +0 -15
- package/app-template/src/views/breadcrumb/index.tsx +0 -127
- package/app-template/src/views/category/native-widget-context.tsx +0 -257
- package/app-template/src/views/category/product-list-registrar.tsx +0 -665
- package/app-template/src/views/checkout/checkout-address-registrar.tsx +0 -254
- package/app-template/src/views/checkout/checkout-buttons-registrar.tsx +0 -183
- package/app-template/src/views/checkout/checkout-delivery-method-registrar.tsx +0 -259
- package/app-template/src/views/checkout/checkout-payment-options-registrar.tsx +0 -253
- package/app-template/src/views/checkout/checkout-summary-registrar.tsx +0 -183
- package/app-template/src/views/checkout/constants.ts +0 -5
- package/app-template/src/views/checkout/steps/payment/options/masterpass-rest.tsx +0 -15
- package/app-template/src/views/checkout/steps/payment/options/saved-card.tsx +0 -18
- package/app-template/src/views/footer/footer-app-banner-context.tsx +0 -326
- package/app-template/src/views/footer/footer-bottom-context.tsx +0 -215
- package/app-template/src/views/footer/footer-bottom-wrapper.tsx +0 -74
- package/app-template/src/views/footer/footer-layout-constants.ts +0 -35
- package/app-template/src/views/footer/footer-layout-registrar.tsx +0 -342
- package/app-template/src/views/footer/footer-layout-switcher.tsx +0 -110
- package/app-template/src/views/footer/footer-menu-context.tsx +0 -211
- package/app-template/src/views/footer/footer-native-widgets.tsx +0 -60
- package/app-template/src/views/footer/footer-social-context.tsx +0 -254
- package/app-template/src/views/footer/footer-subscription-context.tsx +0 -210
- package/app-template/src/views/footer/footer-utils.ts +0 -43
- package/app-template/src/views/footer/footer-value-props-context.tsx +0 -326
- package/app-template/src/views/footer/logo-settings.ts +0 -183
- package/app-template/src/views/footer/native-widget-config.ts +0 -262
- package/app-template/src/views/footer/subscription-settings.ts +0 -122
- package/app-template/src/views/footer/use-footer-logo.ts +0 -162
- package/app-template/src/views/header/designer-context.tsx +0 -261
- package/app-template/src/views/header/header-announcement-registrar.tsx +0 -267
- package/app-template/src/views/header/header-client-wrapper.tsx +0 -496
- package/app-template/src/views/header/header-content.tsx +0 -1026
- package/app-template/src/views/header/header-currency-registrar.tsx +0 -348
- package/app-template/src/views/header/header-icons-context.tsx +0 -262
- package/app-template/src/views/header/header-language-registrar.tsx +0 -348
- package/app-template/src/views/header/header-layout-context.tsx +0 -143
- package/app-template/src/views/header/header-layout-registrar.tsx +0 -658
- package/app-template/src/views/header/header-logo-context.tsx +0 -228
- package/app-template/src/views/header/header-logo.tsx +0 -118
- package/app-template/src/views/header/header-mini-basket-context.tsx +0 -524
- package/app-template/src/views/header/header-search-registrar.tsx +0 -511
- package/app-template/src/views/header/header-text-slider-registrar.tsx +0 -382
- package/app-template/src/views/header/inline-search.tsx +0 -262
- package/app-template/src/views/header/navbar-menu-context.tsx +0 -219
- package/app-template/src/views/header/search/search-input.tsx +0 -61
- package/app-template/src/views/header/server-settings-parser.ts +0 -1105
- package/app-template/src/views/header/use-header-icons.ts +0 -241
- package/app-template/src/views/header/use-header-logo.ts +0 -213
- package/app-template/src/views/header/use-navbar-menu.ts +0 -179
- package/app-template/src/views/product/accordion-section.tsx +0 -61
- package/app-template/src/views/product/custom-button-group.tsx +0 -69
- package/app-template/src/views/product/favorites-button-section.tsx +0 -69
- package/app-template/src/views/product/find-in-store-section.tsx +0 -60
- package/app-template/src/views/product/product-info-section.tsx +0 -140
- package/app-template/src/views/product/quantity-section.tsx +0 -73
- package/app-template/src/views/product/sale-tag.tsx +0 -10
- package/app-template/src/views/product/share-section.tsx +0 -357
- package/app-template/src/views/product/variants-section.tsx +0 -126
- package/app-template/src/views/product-detail/constants.ts +0 -272
- package/app-template/src/views/product-detail/index.ts +0 -10
- package/app-template/src/views/product-detail/product-detail-registrar.tsx +0 -616
- package/app-template/src/widgets/footer-app-banner.tsx +0 -444
- package/app-template/src/widgets/footer-bottom.tsx +0 -127
- package/app-template/src/widgets/footer-menu-compact.tsx +0 -238
- package/app-template/src/widgets/footer-menu-two.tsx +0 -298
- package/app-template/src/widgets/footer-social-client.tsx +0 -251
- package/app-template/src/widgets/footer-value-props.tsx +0 -201
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Header Designer Context
|
|
5
|
-
*
|
|
6
|
-
* Provides a lightweight native-widget bridge so Theme Editor can
|
|
7
|
-
* select header blocks without rewriting the header as a widget.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
createContext,
|
|
12
|
-
PropsWithChildren,
|
|
13
|
-
useCallback,
|
|
14
|
-
useContext,
|
|
15
|
-
useEffect,
|
|
16
|
-
useRef,
|
|
17
|
-
useState
|
|
18
|
-
} from 'react';
|
|
19
|
-
import { useExternalDesigner } from '@akinon/next/components/theme-editor/hooks/use-external-designer';
|
|
20
|
-
|
|
21
|
-
type BlockDefinition = {
|
|
22
|
-
id: string;
|
|
23
|
-
type: string;
|
|
24
|
-
label: string;
|
|
25
|
-
properties?: Record<string, unknown>;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type ThemeBlock = {
|
|
29
|
-
id: string;
|
|
30
|
-
type: string;
|
|
31
|
-
label: string;
|
|
32
|
-
styles?: Record<string, unknown>;
|
|
33
|
-
properties?: Record<string, unknown>;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
type ThemeSection = {
|
|
37
|
-
id: string;
|
|
38
|
-
blocks?: ThemeBlock[];
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type ThemePlaceholder = {
|
|
42
|
-
slug: string;
|
|
43
|
-
sections?: ThemeSection[];
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
interface HeaderDesignerContextValue {
|
|
47
|
-
isDesigner: boolean;
|
|
48
|
-
selectedSectionId: string | null;
|
|
49
|
-
selectedBlockId: string | null;
|
|
50
|
-
getBlockStyles: (blockId: string) => Record<string, unknown> | undefined;
|
|
51
|
-
getBlockProperties: (blockId: string) => Record<string, unknown> | undefined;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const HEADER_PLACEHOLDER_ID = 'header';
|
|
55
|
-
export const HEADER_SECTION_ID = 'header-structure';
|
|
56
|
-
|
|
57
|
-
// Block definitions used by WithDesignerFeatures wrappers
|
|
58
|
-
const headerBlocks = {
|
|
59
|
-
CONTAINER: {
|
|
60
|
-
id: 'header-container',
|
|
61
|
-
type: 'group',
|
|
62
|
-
label: 'Header Container'
|
|
63
|
-
},
|
|
64
|
-
LOGO: {
|
|
65
|
-
id: 'header-logo-image',
|
|
66
|
-
type: 'image',
|
|
67
|
-
label: 'Logo'
|
|
68
|
-
},
|
|
69
|
-
NAVBAR: {
|
|
70
|
-
id: 'header-navbar',
|
|
71
|
-
type: 'group',
|
|
72
|
-
label: 'Navigation Bar'
|
|
73
|
-
},
|
|
74
|
-
NAV_ITEM: {
|
|
75
|
-
id: 'header-nav-menu-item',
|
|
76
|
-
type: 'text',
|
|
77
|
-
label: 'Navigation Item'
|
|
78
|
-
},
|
|
79
|
-
SEARCH: {
|
|
80
|
-
id: 'header-icon-search',
|
|
81
|
-
type: 'icon-button',
|
|
82
|
-
label: 'Search Icon',
|
|
83
|
-
properties: {
|
|
84
|
-
icon: 'search',
|
|
85
|
-
iconSize: '20'
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
USER_MENU: {
|
|
89
|
-
id: 'header-icon-profile',
|
|
90
|
-
type: 'icon-button',
|
|
91
|
-
label: 'Profile Icon',
|
|
92
|
-
properties: {
|
|
93
|
-
icon: 'person',
|
|
94
|
-
iconSize: '20'
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
MINI_BASKET: {
|
|
98
|
-
id: 'header-icon-cart',
|
|
99
|
-
type: 'icon-button',
|
|
100
|
-
label: 'Cart Icon',
|
|
101
|
-
properties: {
|
|
102
|
-
icon: 'cart',
|
|
103
|
-
iconSize: '20'
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
MOBILE_MENU_BUTTON: {
|
|
107
|
-
id: 'header-mobile-menu-button',
|
|
108
|
-
type: 'icon-button',
|
|
109
|
-
label: 'Mobile Menu Button',
|
|
110
|
-
properties: {
|
|
111
|
-
icon: 'hamburger',
|
|
112
|
-
iconSize: '18'
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} satisfies Record<string, BlockDefinition>;
|
|
116
|
-
|
|
117
|
-
export const HEADER_BLOCKS = headerBlocks;
|
|
118
|
-
|
|
119
|
-
type HeaderBlockDefinition =
|
|
120
|
-
(typeof HEADER_BLOCKS)[keyof typeof HEADER_BLOCKS];
|
|
121
|
-
type HeaderBlockId = HeaderBlockDefinition['id'];
|
|
122
|
-
|
|
123
|
-
const blockLookup = new Map<HeaderBlockId, BlockDefinition>(
|
|
124
|
-
Object.values(HEADER_BLOCKS).map((block) => [block.id, block as BlockDefinition])
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
const HeaderDesignerContext = createContext<HeaderDesignerContextValue>({
|
|
128
|
-
isDesigner: false,
|
|
129
|
-
selectedSectionId: null,
|
|
130
|
-
selectedBlockId: null,
|
|
131
|
-
getBlockStyles: () => undefined,
|
|
132
|
-
getBlockProperties: () => undefined
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
export function HeaderDesignerProvider({
|
|
136
|
-
children
|
|
137
|
-
}: PropsWithChildren) {
|
|
138
|
-
const designerState = useExternalDesigner({
|
|
139
|
-
placeholderId: HEADER_PLACEHOLDER_ID
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const [themeBlocks, setThemeBlocks] = useState<Map<string, ThemeBlock>>(
|
|
143
|
-
new Map()
|
|
144
|
-
);
|
|
145
|
-
const themeBlocksRef = useRef<Map<string, ThemeBlock>>(new Map());
|
|
146
|
-
|
|
147
|
-
const registerNativeWidget = useCallback(() => {
|
|
148
|
-
if (typeof window === 'undefined') return;
|
|
149
|
-
const isInIframe = window.self !== window.top;
|
|
150
|
-
if (!isInIframe || !window.parent) return;
|
|
151
|
-
|
|
152
|
-
const sectionBlocks = Object.values(HEADER_BLOCKS).map((blockDef) => {
|
|
153
|
-
const block = blockDef as BlockDefinition;
|
|
154
|
-
const storedBlock = themeBlocksRef.current.get(block.id);
|
|
155
|
-
return {
|
|
156
|
-
id: block.id,
|
|
157
|
-
type: block.type,
|
|
158
|
-
label: block.label,
|
|
159
|
-
properties: storedBlock?.properties ?? block.properties ?? {},
|
|
160
|
-
styles: storedBlock?.styles ?? {}
|
|
161
|
-
};
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
window.parent.postMessage(
|
|
165
|
-
{
|
|
166
|
-
type: 'REGISTER_NATIVE_WIDGETS',
|
|
167
|
-
data: {
|
|
168
|
-
widgets: [
|
|
169
|
-
{
|
|
170
|
-
placeholderId: HEADER_PLACEHOLDER_ID,
|
|
171
|
-
section: {
|
|
172
|
-
id: HEADER_SECTION_ID,
|
|
173
|
-
type: 'native',
|
|
174
|
-
label: 'Header Layout',
|
|
175
|
-
blocks: sectionBlocks
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
]
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
'*'
|
|
182
|
-
);
|
|
183
|
-
}, []);
|
|
184
|
-
|
|
185
|
-
useEffect(() => {
|
|
186
|
-
if (typeof window === 'undefined') return;
|
|
187
|
-
registerNativeWidget();
|
|
188
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
189
|
-
}, []); // Only register once
|
|
190
|
-
|
|
191
|
-
useEffect(() => {
|
|
192
|
-
if (typeof window === 'undefined') return;
|
|
193
|
-
|
|
194
|
-
const handleMessage = (event: MessageEvent) => {
|
|
195
|
-
const { type, data } = event.data || {};
|
|
196
|
-
|
|
197
|
-
if (
|
|
198
|
-
(type === 'UPDATE_THEME' || type === 'LOAD_THEME') &&
|
|
199
|
-
data?.theme?.placeholders
|
|
200
|
-
) {
|
|
201
|
-
const placeholder = (data.theme.placeholders as ThemePlaceholder[]).find(
|
|
202
|
-
(p) => p.slug === HEADER_PLACEHOLDER_ID
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
const headerSection = placeholder?.sections?.find(
|
|
206
|
-
(section) => section.id === HEADER_SECTION_ID
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
if (headerSection?.blocks) {
|
|
210
|
-
const incoming = new Map<string, ThemeBlock>();
|
|
211
|
-
headerSection.blocks.forEach((block) => {
|
|
212
|
-
incoming.set(block.id, block);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
const merged = new Map(themeBlocksRef.current);
|
|
216
|
-
incoming.forEach((block, id) => {
|
|
217
|
-
merged.set(id, block);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
themeBlocksRef.current = merged;
|
|
221
|
-
setThemeBlocks(merged);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
window.addEventListener('message', handleMessage);
|
|
227
|
-
return () => window.removeEventListener('message', handleMessage);
|
|
228
|
-
}, []);
|
|
229
|
-
|
|
230
|
-
const getBlockStyles = useCallback(
|
|
231
|
-
(blockId: string) => {
|
|
232
|
-
return themeBlocks.get(blockId)?.styles;
|
|
233
|
-
},
|
|
234
|
-
[themeBlocks]
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
const getBlockProperties = useCallback(
|
|
238
|
-
(blockId: string) => {
|
|
239
|
-
const block = themeBlocks.get(blockId);
|
|
240
|
-
if (block?.properties) {
|
|
241
|
-
return block.properties;
|
|
242
|
-
}
|
|
243
|
-
return blockLookup.get(blockId as HeaderBlockId)?.properties;
|
|
244
|
-
},
|
|
245
|
-
[themeBlocks]
|
|
246
|
-
);
|
|
247
|
-
|
|
248
|
-
return (
|
|
249
|
-
<HeaderDesignerContext.Provider
|
|
250
|
-
value={{
|
|
251
|
-
...designerState,
|
|
252
|
-
getBlockStyles,
|
|
253
|
-
getBlockProperties
|
|
254
|
-
}}
|
|
255
|
-
>
|
|
256
|
-
{children}
|
|
257
|
-
</HeaderDesignerContext.Provider>
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export const useHeaderDesigner = () => useContext(HeaderDesignerContext);
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createContext,
|
|
5
|
-
useContext,
|
|
6
|
-
useEffect,
|
|
7
|
-
useRef,
|
|
8
|
-
useState,
|
|
9
|
-
PropsWithChildren
|
|
10
|
-
} from 'react';
|
|
11
|
-
|
|
12
|
-
export const HEADER_ANNOUNCEMENT_PLACEHOLDER_ID = 'header';
|
|
13
|
-
export const HEADER_ANNOUNCEMENT_SECTION_ID = 'header-announcement-bar';
|
|
14
|
-
|
|
15
|
-
declare global {
|
|
16
|
-
interface Window {
|
|
17
|
-
__headerAnnouncementRegistered?: boolean;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface ThemeSection {
|
|
22
|
-
id: string;
|
|
23
|
-
visible?: boolean;
|
|
24
|
-
properties?: Record<string, unknown>;
|
|
25
|
-
styles?: Record<string, unknown>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface ThemePlaceholder {
|
|
29
|
-
slug: string;
|
|
30
|
-
sections: ThemeSection[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface HeaderAnnouncementProperties {
|
|
34
|
-
visible?: boolean;
|
|
35
|
-
text?: string | Record<string, string>;
|
|
36
|
-
link?: string | Record<string, string>;
|
|
37
|
-
target?: string | Record<string, string>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface HeaderAnnouncementContextValue {
|
|
41
|
-
isDesigner: boolean;
|
|
42
|
-
isAnnouncementSectionSelected: boolean;
|
|
43
|
-
isSectionVisible: boolean;
|
|
44
|
-
properties: HeaderAnnouncementProperties;
|
|
45
|
-
sectionStyles: Record<string, unknown>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const HeaderAnnouncementContext = createContext<HeaderAnnouncementContextValue>({
|
|
49
|
-
isDesigner: false,
|
|
50
|
-
isAnnouncementSectionSelected: false,
|
|
51
|
-
isSectionVisible: false,
|
|
52
|
-
properties: {},
|
|
53
|
-
sectionStyles: {}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export const useHeaderAnnouncement = () => useContext(HeaderAnnouncementContext);
|
|
57
|
-
|
|
58
|
-
interface HeaderAnnouncementRegistrarProps extends PropsWithChildren {
|
|
59
|
-
initialSettings?: {
|
|
60
|
-
sectionStyles?: Record<string, unknown>;
|
|
61
|
-
properties?: HeaderAnnouncementProperties;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default function HeaderAnnouncementRegistrar({
|
|
66
|
-
children,
|
|
67
|
-
initialSettings = {}
|
|
68
|
-
}: HeaderAnnouncementRegistrarProps) {
|
|
69
|
-
const isDesignerRef = useRef(false);
|
|
70
|
-
const [sectionProperties, setSectionProperties] =
|
|
71
|
-
useState<HeaderAnnouncementProperties>(
|
|
72
|
-
initialSettings.properties
|
|
73
|
-
? initialSettings.properties
|
|
74
|
-
: {
|
|
75
|
-
text: '₺1500 üzeri siparişlerde ücretsiz kargo 🚚',
|
|
76
|
-
visible: true
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
const [sectionStyles, setSectionStyles] = useState<Record<string, unknown>>(
|
|
80
|
-
initialSettings.sectionStyles || {
|
|
81
|
-
'background-color': '#111827',
|
|
82
|
-
color: '#ffffff',
|
|
83
|
-
'padding-top': '10px',
|
|
84
|
-
'padding-bottom': '10px',
|
|
85
|
-
'text-align': 'center',
|
|
86
|
-
'font-size': '14px'
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
const [isAnnouncementSelected, setIsAnnouncementSelected] = useState(false);
|
|
90
|
-
const [isSectionVisible, setIsSectionVisible] = useState(
|
|
91
|
-
initialSettings.properties?.visible ?? true
|
|
92
|
-
);
|
|
93
|
-
const hasRegisteredNativeWidget = useRef(false);
|
|
94
|
-
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
if (typeof window === 'undefined') return;
|
|
97
|
-
isDesignerRef.current = window.self !== window.top;
|
|
98
|
-
}, []);
|
|
99
|
-
|
|
100
|
-
const isDesigner = isDesignerRef.current;
|
|
101
|
-
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
const isInIframe =
|
|
104
|
-
typeof window !== 'undefined' && window.self !== window.top;
|
|
105
|
-
if (!isInIframe || !window.parent) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
typeof window !== 'undefined' &&
|
|
111
|
-
window.__headerAnnouncementRegistered &&
|
|
112
|
-
hasRegisteredNativeWidget.current
|
|
113
|
-
) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const nativeWidgetConfig = {
|
|
118
|
-
placeholderId: HEADER_ANNOUNCEMENT_PLACEHOLDER_ID,
|
|
119
|
-
autoAdd: false,
|
|
120
|
-
section: {
|
|
121
|
-
id: HEADER_ANNOUNCEMENT_SECTION_ID,
|
|
122
|
-
type: 'native',
|
|
123
|
-
label: 'Announcement Bar',
|
|
124
|
-
blocks: [],
|
|
125
|
-
properties:
|
|
126
|
-
initialSettings.properties || {
|
|
127
|
-
text: '₺1500 üzeri siparişlerde ücretsiz kargo 🚚',
|
|
128
|
-
link: '',
|
|
129
|
-
target: '_self',
|
|
130
|
-
visible: true
|
|
131
|
-
},
|
|
132
|
-
styles:
|
|
133
|
-
initialSettings.sectionStyles || {
|
|
134
|
-
'background-color': '#111827',
|
|
135
|
-
color: '#ffffff',
|
|
136
|
-
'font-size': '13px',
|
|
137
|
-
'font-weight': '500',
|
|
138
|
-
'text-align': 'center',
|
|
139
|
-
'padding-top': '8px',
|
|
140
|
-
'padding-bottom': '8px',
|
|
141
|
-
'padding-left': '12px',
|
|
142
|
-
'padding-right': '12px'
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
window.parent.postMessage(
|
|
148
|
-
{
|
|
149
|
-
type: 'REGISTER_NATIVE_WIDGETS',
|
|
150
|
-
data: { widgets: [nativeWidgetConfig] }
|
|
151
|
-
},
|
|
152
|
-
'*'
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
window.__headerAnnouncementRegistered = true;
|
|
156
|
-
hasRegisteredNativeWidget.current = true;
|
|
157
|
-
}, [initialSettings.properties, initialSettings.sectionStyles]);
|
|
158
|
-
|
|
159
|
-
useEffect(() => {
|
|
160
|
-
if (typeof window === 'undefined') return;
|
|
161
|
-
|
|
162
|
-
const handleMessage = (event: MessageEvent) => {
|
|
163
|
-
const { type, data } = event.data || {};
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
(type === 'UPDATE_THEME' || type === 'LOAD_THEME') &&
|
|
167
|
-
data?.theme?.placeholders
|
|
168
|
-
) {
|
|
169
|
-
const placeholder = data.theme.placeholders?.find(
|
|
170
|
-
(p: ThemePlaceholder) => p.slug === HEADER_ANNOUNCEMENT_PLACEHOLDER_ID
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
const section = placeholder?.sections?.find(
|
|
174
|
-
(s: ThemeSection) => s.id === HEADER_ANNOUNCEMENT_SECTION_ID
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
if (section) {
|
|
178
|
-
const visibleValue = section.properties?.visible;
|
|
179
|
-
const isVisible =
|
|
180
|
-
typeof visibleValue === 'boolean'
|
|
181
|
-
? visibleValue
|
|
182
|
-
: (visibleValue as Record<string, boolean>)?.desktop === true ||
|
|
183
|
-
(visibleValue as Record<string, boolean>)?.mobile === true ||
|
|
184
|
-
typeof section.visible === 'boolean'
|
|
185
|
-
? Boolean(section.visible ?? true)
|
|
186
|
-
: true;
|
|
187
|
-
|
|
188
|
-
setIsSectionVisible(isVisible);
|
|
189
|
-
|
|
190
|
-
if (section.properties) {
|
|
191
|
-
setSectionProperties(section.properties as HeaderAnnouncementProperties);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (section.styles) {
|
|
195
|
-
setSectionStyles(section.styles);
|
|
196
|
-
}
|
|
197
|
-
} else if (placeholder) {
|
|
198
|
-
setIsSectionVisible(false);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (type === 'UPDATE_SECTION_PROPERTY' || type === 'UPDATE_PROPERTY') {
|
|
203
|
-
const { sectionId, key, value, properties } = data || {};
|
|
204
|
-
if (sectionId === HEADER_ANNOUNCEMENT_SECTION_ID) {
|
|
205
|
-
if (key && value !== undefined) {
|
|
206
|
-
setSectionProperties((prev) => ({ ...prev, [key]: value }));
|
|
207
|
-
}
|
|
208
|
-
if (properties) {
|
|
209
|
-
setSectionProperties(properties as HeaderAnnouncementProperties);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (type === 'UPDATE_SECTION_STYLE' || type === 'UPDATE_STYLE') {
|
|
215
|
-
const { sectionId, key, value, styles } = data || {};
|
|
216
|
-
if (sectionId === HEADER_ANNOUNCEMENT_SECTION_ID) {
|
|
217
|
-
if (key && value !== undefined) {
|
|
218
|
-
setSectionStyles((prev) => ({ ...prev, [key]: value }));
|
|
219
|
-
}
|
|
220
|
-
if (styles) {
|
|
221
|
-
setSectionStyles(styles);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (type === 'SELECT_SECTION') {
|
|
227
|
-
const { placeholderId, sectionId } = data || {};
|
|
228
|
-
setIsAnnouncementSelected(
|
|
229
|
-
placeholderId === HEADER_ANNOUNCEMENT_PLACEHOLDER_ID &&
|
|
230
|
-
sectionId === HEADER_ANNOUNCEMENT_SECTION_ID
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (type === 'DESELECT' || type === 'CLEAR_SELECTION') {
|
|
235
|
-
setIsAnnouncementSelected(false);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (type === 'TOGGLE_SECTION_VISIBILITY') {
|
|
239
|
-
const { sectionId } = data || {};
|
|
240
|
-
if (sectionId === HEADER_ANNOUNCEMENT_SECTION_ID) {
|
|
241
|
-
setIsSectionVisible((prev) => !prev);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
window.addEventListener('message', handleMessage);
|
|
247
|
-
return () => window.removeEventListener('message', handleMessage);
|
|
248
|
-
}, []);
|
|
249
|
-
|
|
250
|
-
if (!children) {
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return (
|
|
255
|
-
<HeaderAnnouncementContext.Provider
|
|
256
|
-
value={{
|
|
257
|
-
isDesigner,
|
|
258
|
-
isAnnouncementSectionSelected: isAnnouncementSelected,
|
|
259
|
-
isSectionVisible,
|
|
260
|
-
properties: sectionProperties,
|
|
261
|
-
sectionStyles
|
|
262
|
-
}}
|
|
263
|
-
>
|
|
264
|
-
{children}
|
|
265
|
-
</HeaderAnnouncementContext.Provider>
|
|
266
|
-
);
|
|
267
|
-
}
|