@akinon/next 2.0.0-beta.2 → 2.0.0-beta.20
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/.eslintrc.js +12 -0
- package/CHANGELOG.md +377 -7
- package/__tests__/next-config.test.ts +83 -0
- package/__tests__/tsconfig.json +23 -0
- package/api/auth.ts +133 -44
- package/api/barcode-search.ts +59 -0
- package/api/cache.ts +41 -5
- package/api/client.ts +21 -4
- package/api/form.ts +85 -0
- package/api/image-proxy.ts +75 -0
- package/api/product-categories.ts +53 -0
- package/api/similar-product-list.ts +63 -0
- package/api/similar-products.ts +111 -0
- package/api/virtual-try-on.ts +382 -0
- package/assets/styles/index.scss +84 -0
- package/babel.config.js +6 -0
- package/bin/pz-generate-routes.js +115 -0
- package/bin/pz-prebuild.js +1 -0
- package/bin/pz-predev.js +1 -0
- package/bin/pz-run-tests.js +99 -0
- package/bin/run-prebuild-tests.js +46 -0
- package/components/accordion.tsx +20 -5
- package/components/button.tsx +51 -36
- package/components/client-root.tsx +138 -2
- package/components/file-input.tsx +65 -3
- package/components/index.ts +1 -0
- package/components/input.tsx +1 -1
- package/components/link.tsx +46 -16
- package/components/logger-popup.tsx +213 -0
- package/components/modal.tsx +32 -16
- package/components/plugin-module.tsx +62 -3
- package/components/price.tsx +2 -2
- package/components/select.tsx +1 -1
- package/components/selected-payment-option-view.tsx +21 -0
- package/components/theme-editor/blocks/accordion-block.tsx +136 -0
- package/components/theme-editor/blocks/block-renderer-registry.tsx +77 -0
- package/components/theme-editor/blocks/button-block.tsx +593 -0
- package/components/theme-editor/blocks/counter-block.tsx +348 -0
- package/components/theme-editor/blocks/divider-block.tsx +20 -0
- package/components/theme-editor/blocks/embed-block.tsx +208 -0
- package/components/theme-editor/blocks/group-block.tsx +116 -0
- package/components/theme-editor/blocks/hotspot-block.tsx +147 -0
- package/components/theme-editor/blocks/icon-block.tsx +230 -0
- package/components/theme-editor/blocks/image-block.tsx +137 -0
- package/components/theme-editor/blocks/image-gallery-block.tsx +269 -0
- package/components/theme-editor/blocks/input-block.tsx +123 -0
- package/components/theme-editor/blocks/link-block.tsx +216 -0
- package/components/theme-editor/blocks/lottie-block.tsx +325 -0
- package/components/theme-editor/blocks/map-block.tsx +89 -0
- package/components/theme-editor/blocks/slider-block.tsx +595 -0
- package/components/theme-editor/blocks/tab-block.tsx +10 -0
- package/components/theme-editor/blocks/text-block.tsx +52 -0
- package/components/theme-editor/blocks/video-block.tsx +122 -0
- package/components/theme-editor/components/action-toolbar.tsx +305 -0
- package/components/theme-editor/components/designer-overlay.tsx +74 -0
- package/components/theme-editor/components/with-designer-features.tsx +142 -0
- package/components/theme-editor/dynamic-font-loader.tsx +79 -0
- package/components/theme-editor/hooks/use-designer-features.tsx +100 -0
- package/components/theme-editor/hooks/use-external-designer.tsx +95 -0
- package/components/theme-editor/hooks/use-native-widget-data.ts +188 -0
- package/components/theme-editor/hooks/use-visibility-context.ts +27 -0
- package/components/theme-editor/placeholder-registry.ts +31 -0
- package/components/theme-editor/sections/before-after-section.tsx +245 -0
- package/components/theme-editor/sections/contact-form-section.tsx +563 -0
- package/components/theme-editor/sections/countdown-campaign-banner-section.tsx +433 -0
- package/components/theme-editor/sections/coupon-banner-section.tsx +710 -0
- package/components/theme-editor/sections/divider-section.tsx +62 -0
- package/components/theme-editor/sections/featured-product-spotlight-section.tsx +507 -0
- package/components/theme-editor/sections/find-in-store-section.tsx +1995 -0
- package/components/theme-editor/sections/hover-showcase-section.tsx +326 -0
- package/components/theme-editor/sections/image-hotspot-section.tsx +142 -0
- package/components/theme-editor/sections/installment-options-section.tsx +1065 -0
- package/components/theme-editor/sections/notification-banner-section.tsx +173 -0
- package/components/theme-editor/sections/order-tracking-lookup-section.tsx +1379 -0
- package/components/theme-editor/sections/posts-slider-section.tsx +472 -0
- package/components/theme-editor/sections/pre-order-launch-banner-section.tsx +663 -0
- package/components/theme-editor/sections/section-renderer-registry.tsx +89 -0
- package/components/theme-editor/sections/section-wrapper.tsx +135 -0
- package/components/theme-editor/sections/shipping-threshold-progress-section.tsx +586 -0
- package/components/theme-editor/sections/stats-counter-section.tsx +486 -0
- package/components/theme-editor/sections/tabs-section.tsx +578 -0
- package/components/theme-editor/theme-block.tsx +102 -0
- package/components/theme-editor/theme-placeholder-client.tsx +218 -0
- package/components/theme-editor/theme-placeholder-wrapper.tsx +732 -0
- package/components/theme-editor/theme-placeholder.tsx +288 -0
- package/components/theme-editor/theme-section.tsx +1224 -0
- package/components/theme-editor/theme-settings-context.tsx +13 -0
- package/components/theme-editor/utils/index.ts +792 -0
- package/components/theme-editor/utils/iterator-utils.ts +234 -0
- package/components/theme-editor/utils/publish-window.ts +86 -0
- package/components/theme-editor/utils/visibility-rules.ts +188 -0
- package/data/client/account.ts +17 -2
- package/data/client/api.ts +2 -0
- package/data/client/basket.ts +66 -5
- package/data/client/checkout.ts +391 -99
- package/data/client/misc.ts +38 -2
- package/data/client/product.ts +19 -2
- package/data/client/user.ts +16 -8
- package/data/server/category.ts +11 -9
- package/data/server/flatpage.ts +11 -4
- package/data/server/form.ts +15 -4
- package/data/server/landingpage.ts +11 -4
- package/data/server/list.ts +5 -4
- package/data/server/menu.ts +11 -3
- package/data/server/product.ts +111 -55
- package/data/server/seo.ts +14 -4
- package/data/server/special-page.ts +5 -4
- package/data/server/widget.ts +90 -5
- package/data/urls.ts +16 -5
- package/hocs/client/with-segment-defaults.tsx +2 -2
- package/hocs/server/with-segment-defaults.tsx +65 -20
- package/hooks/index.ts +4 -0
- package/hooks/use-localization.ts +24 -10
- package/hooks/use-logger-context.tsx +114 -0
- package/hooks/use-logger.ts +92 -0
- package/hooks/use-loyalty-availability.ts +21 -0
- package/hooks/use-payment-options.ts +2 -1
- package/hooks/use-pz-params.ts +37 -0
- package/hooks/use-router.ts +51 -14
- package/hooks/use-sentry-uncaught-errors.ts +24 -0
- package/instrumentation/index.ts +10 -1
- package/instrumentation/node.ts +2 -20
- package/jest.config.js +25 -0
- package/lib/cache-handler.mjs +534 -16
- package/lib/cache.ts +272 -37
- package/localization/index.ts +2 -1
- package/localization/provider.tsx +2 -5
- package/middlewares/bfcache-headers.ts +18 -0
- package/middlewares/checkout-provider.ts +1 -1
- package/middlewares/complete-gpay.ts +32 -26
- package/middlewares/complete-masterpass.ts +33 -26
- package/middlewares/complete-wallet.ts +182 -0
- package/middlewares/default.ts +360 -215
- package/middlewares/index.ts +10 -2
- package/middlewares/locale.ts +34 -11
- package/middlewares/masterpass-rest-callback.ts +230 -0
- package/middlewares/oauth-login.ts +200 -57
- package/middlewares/pretty-url.ts +21 -8
- package/middlewares/redirection-payment.ts +32 -26
- package/middlewares/saved-card-redirection.ts +33 -26
- package/middlewares/three-d-redirection.ts +32 -26
- package/middlewares/url-redirection.ts +11 -1
- package/middlewares/wallet-complete-redirection.ts +206 -0
- package/package.json +25 -10
- package/plugins.d.ts +19 -4
- package/plugins.js +10 -1
- package/redux/actions.ts +47 -0
- package/redux/middlewares/checkout.ts +63 -138
- package/redux/middlewares/index.ts +14 -10
- package/redux/middlewares/pre-order/address.ts +7 -2
- package/redux/middlewares/pre-order/attribute-based-shipping-option.ts +7 -1
- package/redux/middlewares/pre-order/data-source-shipping-option.ts +7 -1
- package/redux/middlewares/pre-order/delivery-option.ts +7 -1
- package/redux/middlewares/pre-order/index.ts +16 -10
- package/redux/middlewares/pre-order/installment-option.ts +8 -1
- package/redux/middlewares/pre-order/payment-option-reset.ts +37 -0
- package/redux/middlewares/pre-order/payment-option.ts +7 -1
- package/redux/middlewares/pre-order/pre-order-validation.ts +8 -3
- package/redux/middlewares/pre-order/redirection.ts +8 -2
- package/redux/middlewares/pre-order/set-pre-order.ts +6 -2
- package/redux/middlewares/pre-order/shipping-option.ts +7 -1
- package/redux/middlewares/pre-order/shipping-step.ts +5 -1
- package/redux/reducers/checkout.ts +23 -3
- package/redux/reducers/index.ts +11 -3
- package/redux/reducers/root.ts +7 -2
- package/redux/reducers/widget.ts +80 -0
- package/sentry/index.ts +69 -13
- package/tailwind/content.js +16 -0
- package/types/commerce/account.ts +5 -1
- package/types/commerce/checkout.ts +35 -1
- package/types/commerce/widget.ts +33 -0
- package/types/index.ts +101 -6
- package/types/next-auth.d.ts +2 -2
- package/types/widget.ts +80 -0
- package/utils/app-fetch.ts +7 -2
- package/utils/generate-commerce-search-params.ts +3 -2
- package/utils/get-checkout-path.ts +3 -0
- package/utils/get-root-hostname.ts +28 -0
- package/utils/index.ts +64 -10
- package/utils/localization.ts +4 -0
- package/utils/mobile-3d-iframe.ts +8 -2
- package/utils/override-middleware.ts +7 -12
- package/utils/pz-segments.ts +92 -0
- package/utils/redirect-ignore.ts +35 -0
- package/utils/redirect.ts +9 -3
- package/utils/redirection-iframe.ts +8 -2
- package/utils/widget-styles.ts +107 -0
- package/views/error-page.tsx +93 -0
- package/with-pz-config.js +13 -6
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
|
2
|
+
import { BlockRendererProps } from './block-renderer-registry';
|
|
3
|
+
|
|
4
|
+
interface LottieAnimationData {
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const LottieBlock = ({ block }: BlockRendererProps) => {
|
|
9
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
10
|
+
const animationRef = useRef<unknown>(null);
|
|
11
|
+
const [error, setError] = useState<string | null>(null);
|
|
12
|
+
const [loading, setLoading] = useState<boolean>(false);
|
|
13
|
+
const [animationData, setAnimationData] = useState<LottieAnimationData | null>(null);
|
|
14
|
+
|
|
15
|
+
const properties = block.properties || {};
|
|
16
|
+
|
|
17
|
+
// Resolve responsive values
|
|
18
|
+
const resolveValue = <T,>(val: unknown, fallback: T): T => {
|
|
19
|
+
if (val && typeof val === 'object' && 'desktop' in (val as Record<string, unknown>)) {
|
|
20
|
+
return ((val as Record<string, T>).desktop as T) ?? fallback;
|
|
21
|
+
}
|
|
22
|
+
return (val as T) ?? fallback;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const source =
|
|
26
|
+
typeof block.value === 'object' && block.value !== null
|
|
27
|
+
? (block.value as Record<string, string>).en ||
|
|
28
|
+
(block.value as Record<string, string>).tr ||
|
|
29
|
+
Object.values(block.value as Record<string, string>)[0] ||
|
|
30
|
+
''
|
|
31
|
+
: (block.value as string) || '';
|
|
32
|
+
|
|
33
|
+
const fileUrl = resolveValue<string>(properties.file, '');
|
|
34
|
+
const autoplay = resolveValue<boolean>(properties.autoplay, true);
|
|
35
|
+
const loop = resolveValue<boolean>(properties.loop, true);
|
|
36
|
+
const speed = resolveValue<number>(properties.speed, 1);
|
|
37
|
+
const direction = resolveValue<string>(properties.direction, 'forward');
|
|
38
|
+
const hoverPlay = resolveValue<boolean>(properties.hover, false);
|
|
39
|
+
const mode = resolveValue<string>(properties.mode, 'normal');
|
|
40
|
+
|
|
41
|
+
const animationUrl = source || fileUrl;
|
|
42
|
+
|
|
43
|
+
// Fetch animation data from URL
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!animationUrl) {
|
|
46
|
+
setAnimationData(null);
|
|
47
|
+
setError(null);
|
|
48
|
+
setLoading(false);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let cancelled = false;
|
|
53
|
+
|
|
54
|
+
const fetchAnimation = async () => {
|
|
55
|
+
try {
|
|
56
|
+
setLoading(true);
|
|
57
|
+
setError(null);
|
|
58
|
+
|
|
59
|
+
const response = await fetch(animationUrl);
|
|
60
|
+
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(`HTTP ${response.status}: Failed to load animation`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const contentType = response.headers.get('content-type');
|
|
66
|
+
if (contentType && !contentType.includes('application/json')) {
|
|
67
|
+
throw new Error('Invalid file type. Expected JSON format.');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const data = await response.json();
|
|
71
|
+
|
|
72
|
+
// Basic validation for Lottie JSON structure
|
|
73
|
+
if (!data || typeof data !== 'object' || !data.v || !data.layers) {
|
|
74
|
+
throw new Error('Invalid Lottie JSON format');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!cancelled) {
|
|
78
|
+
setAnimationData(data);
|
|
79
|
+
setError(null);
|
|
80
|
+
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
if (!cancelled) {
|
|
83
|
+
console.error('Lottie fetch error:', err);
|
|
84
|
+
setError(
|
|
85
|
+
err instanceof Error
|
|
86
|
+
? err.message
|
|
87
|
+
: 'Network error: Failed to load animation'
|
|
88
|
+
);
|
|
89
|
+
setAnimationData(null);
|
|
90
|
+
}
|
|
91
|
+
} finally {
|
|
92
|
+
if (!cancelled) {
|
|
93
|
+
setLoading(false);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
fetchAnimation();
|
|
99
|
+
|
|
100
|
+
return () => {
|
|
101
|
+
cancelled = true;
|
|
102
|
+
};
|
|
103
|
+
}, [animationUrl]);
|
|
104
|
+
|
|
105
|
+
// Initialize lottie-web animation
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (!animationData || !containerRef.current) return;
|
|
108
|
+
|
|
109
|
+
let lottie: typeof import('lottie-web').default | null = null;
|
|
110
|
+
let anim: ReturnType<typeof import('lottie-web').default.loadAnimation> | null = null;
|
|
111
|
+
let mounted = true;
|
|
112
|
+
|
|
113
|
+
const initAnimation = async () => {
|
|
114
|
+
try {
|
|
115
|
+
const lottieModule = await import('lottie-web');
|
|
116
|
+
lottie = lottieModule.default;
|
|
117
|
+
|
|
118
|
+
if (!mounted || !containerRef.current) return;
|
|
119
|
+
|
|
120
|
+
// Create a new container div for each animation
|
|
121
|
+
const animContainer = document.createElement('div');
|
|
122
|
+
animContainer.style.width = '100%';
|
|
123
|
+
animContainer.style.height = '100%';
|
|
124
|
+
|
|
125
|
+
// Clear and append new container
|
|
126
|
+
if (containerRef.current) {
|
|
127
|
+
containerRef.current.innerHTML = '';
|
|
128
|
+
containerRef.current.appendChild(animContainer);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!mounted) return;
|
|
132
|
+
|
|
133
|
+
anim = lottie.loadAnimation({
|
|
134
|
+
container: animContainer,
|
|
135
|
+
renderer: 'svg',
|
|
136
|
+
loop: mode === 'bounce' ? false : loop,
|
|
137
|
+
autoplay: hoverPlay ? false : autoplay,
|
|
138
|
+
animationData: animationData
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
animationRef.current = anim;
|
|
142
|
+
|
|
143
|
+
// Set speed
|
|
144
|
+
if (anim && typeof anim.setSpeed === 'function') {
|
|
145
|
+
anim.setSpeed(speed);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Set direction
|
|
149
|
+
if (anim && typeof anim.setDirection === 'function') {
|
|
150
|
+
anim.setDirection(direction === 'reverse' ? -1 : 1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Bounce mode: reverse direction on complete
|
|
154
|
+
if (mode === 'bounce' && loop && anim) {
|
|
155
|
+
anim.addEventListener('complete', () => {
|
|
156
|
+
if (anim && typeof anim.setDirection === 'function' && typeof anim.play === 'function') {
|
|
157
|
+
anim.setDirection(anim.playDirection === 1 ? -1 : 1);
|
|
158
|
+
anim.play();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
} catch (err) {
|
|
163
|
+
console.error('Lottie init error:', err);
|
|
164
|
+
if (mounted) {
|
|
165
|
+
setError('Failed to initialize animation player');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
initAnimation();
|
|
171
|
+
|
|
172
|
+
return () => {
|
|
173
|
+
mounted = false;
|
|
174
|
+
|
|
175
|
+
// Cleanup animation with delay to avoid removeChild errors
|
|
176
|
+
const cleanup = () => {
|
|
177
|
+
try {
|
|
178
|
+
if (anim && typeof anim.destroy === 'function') {
|
|
179
|
+
anim.destroy();
|
|
180
|
+
}
|
|
181
|
+
} catch (e) {
|
|
182
|
+
// Silently ignore cleanup errors
|
|
183
|
+
console.debug('Animation cleanup error (safe to ignore):', e);
|
|
184
|
+
}
|
|
185
|
+
animationRef.current = null;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// Delay cleanup slightly to avoid race conditions
|
|
189
|
+
setTimeout(cleanup, 0);
|
|
190
|
+
};
|
|
191
|
+
}, [animationData, autoplay, loop, speed, direction, hoverPlay, mode]);
|
|
192
|
+
|
|
193
|
+
// Hover handlers
|
|
194
|
+
const handleMouseEnter = useCallback(() => {
|
|
195
|
+
if (hoverPlay && animationRef.current) {
|
|
196
|
+
try {
|
|
197
|
+
(animationRef.current as { play: () => void }).play();
|
|
198
|
+
} catch (e) {
|
|
199
|
+
console.warn('Error playing animation:', e);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}, [hoverPlay]);
|
|
203
|
+
|
|
204
|
+
const handleMouseLeave = useCallback(() => {
|
|
205
|
+
if (hoverPlay && animationRef.current) {
|
|
206
|
+
try {
|
|
207
|
+
(animationRef.current as { stop: () => void }).stop();
|
|
208
|
+
} catch (e) {
|
|
209
|
+
console.warn('Error stopping animation:', e);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}, [hoverPlay]);
|
|
213
|
+
|
|
214
|
+
// Placeholder when no animation URL
|
|
215
|
+
if (!animationUrl) {
|
|
216
|
+
return (
|
|
217
|
+
<div
|
|
218
|
+
style={{
|
|
219
|
+
minHeight: '200px',
|
|
220
|
+
display: 'flex',
|
|
221
|
+
flexDirection: 'column',
|
|
222
|
+
alignItems: 'center',
|
|
223
|
+
justifyContent: 'center',
|
|
224
|
+
backgroundColor: '#f5f3ff',
|
|
225
|
+
color: '#666',
|
|
226
|
+
fontSize: '14px',
|
|
227
|
+
gap: '8px'
|
|
228
|
+
}}
|
|
229
|
+
>
|
|
230
|
+
<svg
|
|
231
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
232
|
+
width="32"
|
|
233
|
+
height="32"
|
|
234
|
+
viewBox="0 0 24 24"
|
|
235
|
+
fill="none"
|
|
236
|
+
stroke="currentColor"
|
|
237
|
+
strokeWidth="1.5"
|
|
238
|
+
strokeLinecap="round"
|
|
239
|
+
strokeLinejoin="round"
|
|
240
|
+
style={{ opacity: 0.4 }}
|
|
241
|
+
>
|
|
242
|
+
<circle cx="12" cy="12" r="10" />
|
|
243
|
+
<polygon points="10 8 16 12 10 16 10 8" />
|
|
244
|
+
</svg>
|
|
245
|
+
<span>Add a Lottie animation URL or upload a file</span>
|
|
246
|
+
</div>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Loading state
|
|
251
|
+
if (loading) {
|
|
252
|
+
return (
|
|
253
|
+
<div
|
|
254
|
+
style={{
|
|
255
|
+
minHeight: '200px',
|
|
256
|
+
display: 'flex',
|
|
257
|
+
flexDirection: 'column',
|
|
258
|
+
alignItems: 'center',
|
|
259
|
+
justifyContent: 'center',
|
|
260
|
+
backgroundColor: '#f5f3ff',
|
|
261
|
+
color: '#666',
|
|
262
|
+
fontSize: '14px',
|
|
263
|
+
gap: '8px'
|
|
264
|
+
}}
|
|
265
|
+
>
|
|
266
|
+
<div
|
|
267
|
+
style={{
|
|
268
|
+
width: '32px',
|
|
269
|
+
height: '32px',
|
|
270
|
+
border: '3px solid #e0e7ff',
|
|
271
|
+
borderTopColor: '#8b5cf6',
|
|
272
|
+
borderRadius: '50%',
|
|
273
|
+
animation: 'spin 1s linear infinite'
|
|
274
|
+
}}
|
|
275
|
+
/>
|
|
276
|
+
<span>Loading animation...</span>
|
|
277
|
+
<style>
|
|
278
|
+
{`
|
|
279
|
+
@keyframes spin {
|
|
280
|
+
to { transform: rotate(360deg); }
|
|
281
|
+
}
|
|
282
|
+
`}
|
|
283
|
+
</style>
|
|
284
|
+
</div>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Error state
|
|
289
|
+
if (error) {
|
|
290
|
+
return (
|
|
291
|
+
<div
|
|
292
|
+
style={{
|
|
293
|
+
minHeight: '200px',
|
|
294
|
+
display: 'flex',
|
|
295
|
+
flexDirection: 'column',
|
|
296
|
+
alignItems: 'center',
|
|
297
|
+
justifyContent: 'center',
|
|
298
|
+
backgroundColor: '#fef2f2',
|
|
299
|
+
color: '#dc2626',
|
|
300
|
+
fontSize: '14px',
|
|
301
|
+
gap: '8px'
|
|
302
|
+
}}
|
|
303
|
+
>
|
|
304
|
+
<span>⚠ {error}</span>
|
|
305
|
+
</div>
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return (
|
|
310
|
+
<div
|
|
311
|
+
ref={containerRef}
|
|
312
|
+
onMouseEnter={handleMouseEnter}
|
|
313
|
+
onMouseLeave={handleMouseLeave}
|
|
314
|
+
style={{
|
|
315
|
+
width: '100%',
|
|
316
|
+
height: '100%',
|
|
317
|
+
display: 'flex',
|
|
318
|
+
alignItems: 'center',
|
|
319
|
+
justifyContent: 'center'
|
|
320
|
+
}}
|
|
321
|
+
/>
|
|
322
|
+
);
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
export default LottieBlock;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { getResponsiveValue } from '../utils';
|
|
3
|
+
import { BlockRendererProps } from './block-renderer-registry';
|
|
4
|
+
|
|
5
|
+
const placeholderContainerStyles: React.CSSProperties = {
|
|
6
|
+
minHeight: '300px',
|
|
7
|
+
display: 'flex',
|
|
8
|
+
flexDirection: 'column',
|
|
9
|
+
alignItems: 'center',
|
|
10
|
+
justifyContent: 'center',
|
|
11
|
+
backgroundColor: '#f0f0f0',
|
|
12
|
+
color: '#666',
|
|
13
|
+
fontSize: '14px',
|
|
14
|
+
gap: '8px'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const getMapEmbedUrl = (
|
|
18
|
+
address: string,
|
|
19
|
+
properties?: {
|
|
20
|
+
zoom?: number;
|
|
21
|
+
mapType?: string;
|
|
22
|
+
}
|
|
23
|
+
) => {
|
|
24
|
+
|
|
25
|
+
const encodedAddress = encodeURIComponent(address);
|
|
26
|
+
const zoom = properties?.zoom ?? 14;
|
|
27
|
+
const mapType = properties?.mapType === 'satellite' ? 'k' : 'm';
|
|
28
|
+
|
|
29
|
+
return `https://maps.google.com/maps?q=${encodedAddress}&z=${zoom}&t=${mapType}&output=embed`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const MapBlock = ({ block, currentBreakpoint = 'desktop' }: BlockRendererProps) => {
|
|
33
|
+
const address =
|
|
34
|
+
typeof block.value === 'object' && block.value !== null
|
|
35
|
+
? (block.value as Record<string, string>).en ||
|
|
36
|
+
(block.value as Record<string, string>).tr ||
|
|
37
|
+
Object.values(block.value as Record<string, string>)[0] ||
|
|
38
|
+
''
|
|
39
|
+
: (block.value as string) || '';
|
|
40
|
+
|
|
41
|
+
const properties = block.properties || {};
|
|
42
|
+
|
|
43
|
+
const zoom = getResponsiveValue(properties.zoom, currentBreakpoint, 14) as number;
|
|
44
|
+
|
|
45
|
+
const mapType = getResponsiveValue(properties.mapType, currentBreakpoint, 'roadmap') as string;
|
|
46
|
+
|
|
47
|
+
if (!address) {
|
|
48
|
+
return (
|
|
49
|
+
<div style={placeholderContainerStyles}>
|
|
50
|
+
<svg
|
|
51
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
52
|
+
width="32"
|
|
53
|
+
height="32"
|
|
54
|
+
viewBox="0 0 24 24"
|
|
55
|
+
fill="none"
|
|
56
|
+
stroke="currentColor"
|
|
57
|
+
strokeWidth="1.5"
|
|
58
|
+
strokeLinecap="round"
|
|
59
|
+
strokeLinejoin="round"
|
|
60
|
+
style={{ opacity: 0.4 }}
|
|
61
|
+
>
|
|
62
|
+
<path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z" />
|
|
63
|
+
<circle cx="12" cy="10" r="3" />
|
|
64
|
+
</svg>
|
|
65
|
+
<span>Enter an address to display the map</span>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const embedUrl = getMapEmbedUrl(address, { zoom, mapType });
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<iframe
|
|
74
|
+
src={embedUrl}
|
|
75
|
+
style={{
|
|
76
|
+
width: '100%',
|
|
77
|
+
height: '100%',
|
|
78
|
+
border: 'none',
|
|
79
|
+
minHeight: '300px'
|
|
80
|
+
}}
|
|
81
|
+
loading="lazy"
|
|
82
|
+
allowFullScreen
|
|
83
|
+
referrerPolicy="no-referrer-when-downgrade"
|
|
84
|
+
title="Google Maps"
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default MapBlock;
|