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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +23 -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,486 +0,0 @@
1
- 'use client';
2
-
3
- import React, { useEffect, useMemo, useRef, useState } from 'react';
4
- import clsx from 'clsx';
5
- import { twMerge } from 'tailwind-merge';
6
-
7
- import ThemeBlock, { Block } from '../theme-block';
8
- import { Section } from '../theme-section';
9
- import { useThemeSettingsContext } from '../theme-settings-context';
10
- import { getCSSStyles, getResponsiveValue } from '../utils';
11
-
12
- interface StatsCounterSectionProps {
13
- section: Section;
14
- currentBreakpoint?: string;
15
- placeholderId?: string;
16
- isDesigner?: boolean;
17
- selectedBlockId?: string | null;
18
- }
19
-
20
- interface CounterTarget {
21
- blockId: string;
22
- endValue: number;
23
- decimals: number;
24
- useGrouping: boolean;
25
- }
26
-
27
- type CounterAnimationEasing = 'linear' | 'ease-out' | 'ease-in-out';
28
-
29
- const NUMBER_TOKEN_REGEX = /-?\d[\d.,]*/;
30
-
31
- const parseNumber = (value: unknown, fallback: number): number => {
32
- if (value === undefined || value === null || value === '') return fallback;
33
- if (typeof value === 'number') {
34
- return Number.isFinite(value) ? value : fallback;
35
- }
36
-
37
- if (typeof value === 'string') {
38
- const trimmed = value.trim();
39
- if (!trimmed) return fallback;
40
-
41
- const directParsed = Number(trimmed);
42
- if (Number.isFinite(directParsed)) return directParsed;
43
-
44
- const numericToken = trimmed
45
- // Keep only numeric-safe chars so values like `1400ms` or `1,400` can still be parsed.
46
- .replace(/[^\d.,-]/g, '')
47
- .replace(/,/g, '');
48
- const tokenParsed = Number(numericToken);
49
-
50
- return Number.isFinite(tokenParsed) ? tokenParsed : fallback;
51
- }
52
-
53
- return fallback;
54
- };
55
-
56
- const parseBoolean = (value: unknown, fallback: boolean): boolean => {
57
- if (typeof value === 'boolean') return value;
58
- if (typeof value === 'string') {
59
- const normalized = value.trim().toLowerCase();
60
- if (normalized === 'true') return true;
61
- if (normalized === 'false') return false;
62
- }
63
- if (typeof value === 'number') return value !== 0;
64
- return fallback;
65
- };
66
-
67
- const readEasingValue = (value: unknown): string | null => {
68
- if (typeof value === 'string') return value;
69
-
70
- if (typeof value === 'object' && value !== null) {
71
- const objectValue = value as Record<string, unknown>;
72
-
73
- if (typeof objectValue.value === 'string') {
74
- return objectValue.value;
75
- }
76
-
77
- if (typeof objectValue.label === 'string') {
78
- return objectValue.label;
79
- }
80
-
81
- const firstString = Object.values(objectValue).find(
82
- (item) => typeof item === 'string'
83
- );
84
-
85
- if (typeof firstString === 'string') {
86
- return firstString;
87
- }
88
- }
89
-
90
- return null;
91
- };
92
-
93
- const parseAnimationEasing = (value: unknown): CounterAnimationEasing => {
94
- const raw = readEasingValue(value);
95
- if (!raw) return 'linear';
96
-
97
- const normalized = raw
98
- .trim()
99
- .toLowerCase()
100
- .replace(/_/g, '-')
101
- .replace(/\s+/g, '-');
102
-
103
- if (normalized === 'ease-out' || normalized === 'easeout') return 'ease-out';
104
- if (
105
- normalized === 'ease-in-out' ||
106
- normalized === 'easeinout' ||
107
- normalized === 'ease-inout'
108
- ) {
109
- return 'ease-in-out';
110
- }
111
-
112
- return 'linear';
113
- };
114
-
115
- const applyAnimationEasing = (
116
- progress: number,
117
- easing: CounterAnimationEasing
118
- ): number => {
119
- if (easing === 'ease-out') {
120
- // Cubic ease-out: stronger acceleration contrast for visible difference.
121
- return 1 - Math.pow(1 - progress, 3);
122
- }
123
-
124
- if (easing === 'ease-in-out') {
125
- // Cubic ease-in-out: noticeably slower start and end.
126
- return progress < 0.5
127
- ? 4 * progress * progress * progress
128
- : 1 - Math.pow(-2 * progress + 2, 3) / 2;
129
- }
130
-
131
- return progress;
132
- };
133
-
134
- const clampNumber = (value: number, min: number, max: number) =>
135
- Math.min(Math.max(value, min), max);
136
-
137
- const stripHtml = (value: string): string =>
138
- value
139
- .replace(/<[^>]*>/g, ' ')
140
- .replace(/&nbsp;/gi, ' ')
141
- .replace(/\s+/g, ' ')
142
- .trim();
143
-
144
- const resolveTextValue = (raw: unknown): string | null => {
145
- let value = raw;
146
-
147
- if (typeof value === 'string' && value.trim().startsWith('{')) {
148
- try {
149
- value = JSON.parse(value);
150
- } catch {
151
- // Keep original string.
152
- }
153
- }
154
-
155
- if (typeof value === 'string') {
156
- return value;
157
- }
158
-
159
- if (typeof value === 'object' && value !== null) {
160
- const objectValue = value as Record<string, unknown>;
161
- const firstString = Object.values(objectValue).find(
162
- (item) => typeof item === 'string'
163
- );
164
- return typeof firstString === 'string' ? firstString : null;
165
- }
166
-
167
- return null;
168
- };
169
-
170
- const getCounterTargetFromText = (value: string): Omit<CounterTarget, 'blockId'> | null => {
171
- const plain = stripHtml(value);
172
- const tokenMatch = plain.match(NUMBER_TOKEN_REGEX);
173
-
174
- if (!tokenMatch) return null;
175
-
176
- const token = tokenMatch[0];
177
- const normalized = token.replace(/,/g, '');
178
- const endValue = Number(normalized);
179
-
180
- if (!Number.isFinite(endValue)) return null;
181
-
182
- const decimals = normalized.includes('.')
183
- ? normalized.split('.')[1]?.length || 0
184
- : 0;
185
-
186
- return {
187
- endValue,
188
- decimals,
189
- useGrouping: token.includes(',')
190
- };
191
- };
192
-
193
- const collectCounterTargets = (blocks: Block[]): CounterTarget[] => {
194
- const targets: CounterTarget[] = [];
195
-
196
- const walk = (block: Block) => {
197
- const isCounterValueBlock =
198
- block.type === 'text' &&
199
- (block.properties?.statsRole === 'value' || block.label === 'Value');
200
-
201
- if (isCounterValueBlock) {
202
- const rawText = resolveTextValue(block.value);
203
- if (!rawText) return;
204
- const parsed = getCounterTargetFromText(rawText);
205
- if (parsed) {
206
- targets.push({
207
- blockId: block.id,
208
- ...parsed
209
- });
210
- }
211
- }
212
-
213
- if (block.blocks && block.blocks.length > 0) {
214
- block.blocks.forEach(walk);
215
- }
216
- };
217
-
218
- blocks.forEach(walk);
219
- return targets;
220
- };
221
-
222
- const formatAnimatedNumber = (
223
- value: number,
224
- decimals: number,
225
- useGrouping: boolean
226
- ): string => {
227
- if (decimals > 0) {
228
- const rounded = Number(value.toFixed(decimals));
229
- if (!useGrouping) return rounded.toFixed(decimals);
230
-
231
- return rounded.toLocaleString(undefined, {
232
- minimumFractionDigits: decimals,
233
- maximumFractionDigits: decimals
234
- });
235
- }
236
-
237
- const rounded = Math.round(value);
238
- return useGrouping ? rounded.toLocaleString() : String(rounded);
239
- };
240
-
241
- const injectAnimatedValues = (
242
- blocks: Block[],
243
- animatedValues: Record<string, string>
244
- ): Block[] => {
245
- const replaceTokenInContent = (content: string, replacement: string): string => {
246
- if (content.includes('<') && content.includes('>')) {
247
- return content.replace(/>([^<]*)</, (fullMatch, innerText: string) => {
248
- const nextInner = innerText.replace(NUMBER_TOKEN_REGEX, replacement);
249
- return fullMatch.replace(innerText, nextInner);
250
- });
251
- }
252
-
253
- return content.replace(NUMBER_TOKEN_REGEX, replacement);
254
- };
255
-
256
- const walk = (block: Block): Block => {
257
- const cloned: Block = {
258
- ...block,
259
- properties: block.properties ? { ...block.properties } : block.properties,
260
- styles: block.styles ? { ...block.styles } : block.styles
261
- };
262
-
263
- if (
264
- cloned.type === 'text' &&
265
- animatedValues[cloned.id] !== undefined
266
- ) {
267
- const replacement = animatedValues[cloned.id];
268
-
269
- if (typeof cloned.value === 'string') {
270
- const raw = cloned.value.trim();
271
-
272
- if (raw.startsWith('{')) {
273
- try {
274
- const parsed = JSON.parse(cloned.value) as Record<string, unknown>;
275
- const nextValue = Object.fromEntries(
276
- Object.entries(parsed).map(([key, value]) => [
277
- key,
278
- typeof value === 'string'
279
- ? replaceTokenInContent(value, replacement)
280
- : value
281
- ])
282
- );
283
- cloned.value = JSON.stringify(nextValue);
284
- } catch {
285
- cloned.value = replaceTokenInContent(cloned.value, replacement);
286
- }
287
- } else {
288
- cloned.value = replaceTokenInContent(cloned.value, replacement);
289
- }
290
- } else if (typeof cloned.value === 'object' && cloned.value !== null) {
291
- const parsed = cloned.value as Record<string, unknown>;
292
- cloned.value = Object.fromEntries(
293
- Object.entries(parsed).map(([key, value]) => [
294
- key,
295
- typeof value === 'string'
296
- ? replaceTokenInContent(value, replacement)
297
- : value
298
- ])
299
- );
300
- }
301
- }
302
-
303
- if (cloned.blocks && cloned.blocks.length > 0) {
304
- cloned.blocks = cloned.blocks.map(walk);
305
- }
306
-
307
- return cloned;
308
- };
309
-
310
- return blocks.map(walk);
311
- };
312
-
313
- const StatsCounterSection: React.FC<StatsCounterSectionProps> = ({
314
- section,
315
- currentBreakpoint = 'desktop',
316
- placeholderId = '',
317
- isDesigner = false,
318
- selectedBlockId = null
319
- }) => {
320
- const themeSettings = useThemeSettingsContext();
321
-
322
- const sortedBlocks = useMemo(
323
- () =>
324
- [...(section.blocks || [])]
325
- .sort((a, b) => (a.order || 0) - (b.order || 0))
326
- .filter((block) => (isDesigner ? true : !block.hidden)),
327
- [section.blocks, isDesigner]
328
- );
329
-
330
- const targets = useMemo(() => collectCounterTargets(sortedBlocks), [sortedBlocks]);
331
- const targetsKey = useMemo(
332
- () =>
333
- targets
334
- .map(
335
- (target) =>
336
- `${target.blockId}:${target.endValue}:${target.decimals}:${target.useGrouping}`
337
- )
338
- .join('|'),
339
- [targets]
340
- );
341
-
342
- const countUpEnabled = parseBoolean(
343
- getResponsiveValue(section.properties?.['count-up-enabled'], currentBreakpoint, true),
344
- true
345
- );
346
- const countUpDuration = clampNumber(
347
- parseNumber(
348
- getResponsiveValue(section.properties?.['count-up-duration'], currentBreakpoint, 1400),
349
- 1400
350
- ),
351
- 300,
352
- 10000
353
- );
354
- const animationEasing = parseAnimationEasing(
355
- getResponsiveValue(section.properties?.['count-up-easing'], currentBreakpoint, 'linear')
356
- );
357
-
358
- const [animatedValues, setAnimatedValues] = useState<Record<string, string>>({});
359
- const targetsRef = useRef<CounterTarget[]>(targets);
360
-
361
- useEffect(() => {
362
- targetsRef.current = targets;
363
- }, [targets]);
364
-
365
- useEffect(() => {
366
- const currentTargets = targetsRef.current;
367
-
368
- if (currentTargets.length === 0) {
369
- setAnimatedValues({});
370
- return;
371
- }
372
-
373
- const buildValues = (progress: number): Record<string, string> => {
374
- const next: Record<string, string> = {};
375
-
376
- currentTargets.forEach((target) => {
377
- const currentValue = target.endValue * progress;
378
- next[target.blockId] = formatAnimatedNumber(
379
- currentValue,
380
- target.decimals,
381
- target.useGrouping
382
- );
383
- });
384
-
385
- return next;
386
- };
387
-
388
- if (!countUpEnabled) {
389
- setAnimatedValues(buildValues(1));
390
- return;
391
- }
392
-
393
- let rafId = 0;
394
- const startTime = performance.now();
395
- const duration = Math.max(countUpDuration, 1);
396
-
397
- const tick = (now: number) => {
398
- const progress = Math.min((now - startTime) / duration, 1);
399
- setAnimatedValues(buildValues(applyAnimationEasing(progress, animationEasing)));
400
-
401
- if (progress < 1) {
402
- rafId = window.requestAnimationFrame(tick);
403
- }
404
- };
405
-
406
- setAnimatedValues(buildValues(0));
407
- rafId = window.requestAnimationFrame(tick);
408
-
409
- return () => {
410
- if (rafId) {
411
- window.cancelAnimationFrame(rafId);
412
- }
413
- };
414
- }, [countUpEnabled, countUpDuration, animationEasing, targetsKey]);
415
-
416
- const renderedBlocks = useMemo(
417
- () => injectAnimatedValues(sortedBlocks, animatedValues),
418
- [sortedBlocks, animatedValues]
419
- );
420
-
421
- const maxWidth = getResponsiveValue(
422
- section.styles?.['max-width'],
423
- currentBreakpoint,
424
- 'normal'
425
- );
426
- const maxWidthClass =
427
- maxWidth === 'narrow'
428
- ? 'max-w-4xl'
429
- : maxWidth === 'normal'
430
- ? 'max-w-7xl'
431
- : '';
432
- const hasMaxWidth = maxWidth !== 'none' && maxWidth !== 'full';
433
-
434
- const filteredStyles = Object.fromEntries(
435
- Object.entries(section.styles || {}).filter(([key]) => !['max-width'].includes(key))
436
- );
437
- const sectionStyles = getCSSStyles(filteredStyles, themeSettings, currentBreakpoint);
438
-
439
- const postBlockAction = (type: string, blockId: string, label?: string) => {
440
- if (!window.parent) return;
441
- window.parent.postMessage(
442
- {
443
- type,
444
- data: {
445
- placeholderId,
446
- sectionId: section.id,
447
- blockId,
448
- ...(label ? { label } : {})
449
- }
450
- },
451
- '*'
452
- );
453
- };
454
-
455
- const renderBlock = (block: Block) => (
456
- <ThemeBlock
457
- key={block.id}
458
- block={block}
459
- placeholderId={placeholderId}
460
- sectionId={section.id}
461
- isDesigner={isDesigner}
462
- isSelected={selectedBlockId === block.id}
463
- selectedBlockId={selectedBlockId}
464
- currentBreakpoint={currentBreakpoint}
465
- onMoveUp={() => postBlockAction('MOVE_BLOCK_UP', block.id)}
466
- onMoveDown={() => postBlockAction('MOVE_BLOCK_DOWN', block.id)}
467
- onDuplicate={() => postBlockAction('DUPLICATE_BLOCK', block.id)}
468
- onToggleVisibility={() => postBlockAction('TOGGLE_BLOCK_VISIBILITY', block.id)}
469
- onDelete={() => postBlockAction('DELETE_BLOCK', block.id)}
470
- onRename={(newLabel) => postBlockAction('RENAME_BLOCK', block.id, newLabel)}
471
- />
472
- );
473
-
474
- return (
475
- <div
476
- className={twMerge(
477
- clsx('stats-counter-section w-full', hasMaxWidth && 'mx-auto', maxWidthClass)
478
- )}
479
- style={sectionStyles}
480
- >
481
- {renderedBlocks.map(renderBlock)}
482
- </div>
483
- );
484
- };
485
-
486
- export default StatsCounterSection;