@akinon/pz-theme 2.0.157-rc.13 → 2.0.158-beta.0
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 +8 -41
- package/package.json +4 -4
- package/src/__tests__/editor-locale-bridge.test.tsx +1 -32
- package/src/blocks/__tests__/order-detail-return.test.tsx +70 -5
- package/src/blocks/__tests__/text-block.test.tsx +6 -34
- package/src/blocks/item-template.tsx +19 -25
- package/src/blocks/order-detail-block.tsx +138 -133
- package/src/blocks/order-list-block.tsx +2 -25
- package/src/blocks/text-block.tsx +2 -6
- package/src/chrome/__tests__/page-context-builders.test.ts +1 -14
- package/src/chrome/page-context.ts +0 -4
- package/src/custom/README.md +219 -120
- package/src/custom/__tests__/use-theme-setting.test.tsx +0 -97
- package/src/custom/collect.ts +9 -4
- package/src/custom/property-types.ts +15 -15
- package/src/custom/use-theme-setting.ts +5 -21
- package/src/editor-locale-bridge.tsx +11 -39
- package/src/theme-placeholder-wrapper.tsx +0 -3
- package/src/utils/__tests__/order-action-rules.test.tsx +96 -0
- package/src/utils/order-action-rules.ts +115 -0
- package/src/__tests__/row-scope.test.tsx +0 -118
- package/src/blocks/__tests__/order-line-actions.test.tsx +0 -54
- package/src/blocks/__tests__/order-list-rows.test.tsx +0 -112
- package/src/blocks/order-line-actions.ts +0 -45
- package/src/blocks/row-scope.tsx +0 -35
- package/src/utils/__tests__/sanitize-rich-text.test.ts +0 -80
- package/src/utils/sanitize-rich-text.ts +0 -215
package/CHANGELOG.md
CHANGED
|
@@ -1,55 +1,22 @@
|
|
|
1
1
|
# @akinon/pz-theme
|
|
2
2
|
|
|
3
|
-
## 2.0.
|
|
3
|
+
## 2.0.158-beta.0
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- Updated dependencies [
|
|
8
|
-
- @akinon/next@2.0.
|
|
9
|
-
- @akinon/theme-contract@2.0.
|
|
7
|
+
- Updated dependencies [cbbbfd757]
|
|
8
|
+
- @akinon/next@2.0.158-beta.0
|
|
9
|
+
- @akinon/theme-contract@2.0.158-beta.0
|
|
10
10
|
|
|
11
|
-
## 2.0.157
|
|
11
|
+
## 2.0.157
|
|
12
12
|
|
|
13
13
|
### Patch Changes
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
- c761b9fd: ZERO-5296: fall back to the storefront default language in the text block
|
|
17
|
-
- 17a598da: ZERO-5296: report the storefront default language to the editor
|
|
18
|
-
- 3b05a407: ZERO-5232: allow richtext settings on custom blocks
|
|
19
|
-
- ad5240c4: ZERO-5254: add custom render and theme editor support to pz-rate-review
|
|
15
|
+
- 3002c2cc: ZERO-5302: The order detail's return and cancel links offer what commerce allows and what a storefront's order-action rules let through (`registerOrderActionRules`: which lines a return may start from, whether an order may be cancelled). With no rules registered, commerce's `is_refundable` and `is_cancellable` flags decide; the block no longer limits returns to delivered lines on its own.
|
|
20
16
|
- Updated dependencies [219164a3]
|
|
21
|
-
- Updated dependencies [86187b1c2]
|
|
22
|
-
- Updated dependencies [0cf9ea239]
|
|
23
|
-
- Updated dependencies [97d29893]
|
|
24
|
-
- Updated dependencies [324f97d55]
|
|
25
|
-
- Updated dependencies [51ea06888]
|
|
26
|
-
- Updated dependencies
|
|
27
|
-
- Updated dependencies [2fea41430]
|
|
28
|
-
- Updated dependencies [b55acb768]
|
|
29
|
-
- Updated dependencies [760258c1c]
|
|
30
|
-
- Updated dependencies [143be2b9d]
|
|
31
|
-
- Updated dependencies [7889b08fe]
|
|
32
|
-
- Updated dependencies [9f8cd3bc5]
|
|
33
|
-
- Updated dependencies [bfafa3f49]
|
|
34
|
-
- Updated dependencies [57d7eb305]
|
|
35
|
-
- Updated dependencies [d99a6a7d5]
|
|
36
|
-
- Updated dependencies [9db81a714]
|
|
37
|
-
- Updated dependencies [591e345e1]
|
|
38
|
-
- Updated dependencies [4de5303c5]
|
|
39
|
-
- Updated dependencies [95b139dc1]
|
|
40
|
-
- Updated dependencies [1d00f2d06]
|
|
41
|
-
- Updated dependencies [4ac7b2a1e]
|
|
42
|
-
- Updated dependencies [4998a9631]
|
|
43
|
-
- Updated dependencies [804d2bd6c]
|
|
44
|
-
- Updated dependencies [3909d3224]
|
|
45
|
-
- Updated dependencies [6a3d8a631]
|
|
46
|
-
- Updated dependencies [e18836b20]
|
|
47
|
-
- Updated dependencies [b1111d7b1]
|
|
48
|
-
- Updated dependencies [1595d458e]
|
|
49
|
-
- Updated dependencies [dca128112]
|
|
50
17
|
- Updated dependencies [9c778307]
|
|
51
|
-
- @akinon/next@2.0.157
|
|
52
|
-
- @akinon/theme-contract@2.0.157
|
|
18
|
+
- @akinon/next@2.0.157
|
|
19
|
+
- @akinon/theme-contract@2.0.157
|
|
53
20
|
|
|
54
21
|
## 2.0.156
|
|
55
22
|
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/pz-theme",
|
|
3
3
|
"description": "Theme package for Project Zero Next — ThemePlaceholder system and theme editor infrastructure",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.158-beta.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "jest"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
|
-
"@akinon/next": "2.0.
|
|
11
|
+
"@akinon/next": "2.0.158-beta.0",
|
|
12
12
|
"react": "^18.0.0 || ^19.0.0",
|
|
13
13
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@akinon/theme-contract": "2.0.
|
|
16
|
+
"@akinon/theme-contract": "2.0.158-beta.0",
|
|
17
17
|
"clsx": "2.1.1",
|
|
18
18
|
"lottie-web": "^5.13.0",
|
|
19
19
|
"react-multi-carousel": "2.8.4",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"zod": "4.4.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@akinon/next": "2.0.
|
|
24
|
+
"@akinon/next": "2.0.158-beta.0",
|
|
25
25
|
"@testing-library/jest-dom": "5.16.4",
|
|
26
26
|
"@testing-library/react": "16.3.2",
|
|
27
27
|
"@testing-library/user-event": "14.1.1",
|
|
@@ -28,7 +28,6 @@ const SETTINGS_LOCALES = [
|
|
|
28
28
|
const mockLocalization = {
|
|
29
29
|
locale: 'tr',
|
|
30
30
|
locales: SETTINGS_LOCALES as Array<Record<string, unknown>>,
|
|
31
|
-
defaultLocaleValue: 'tr',
|
|
32
31
|
setLocale: jest.fn()
|
|
33
32
|
};
|
|
34
33
|
|
|
@@ -107,7 +106,6 @@ beforeEach(() => {
|
|
|
107
106
|
postMessage.mockClear();
|
|
108
107
|
mockLocalization.locale = 'tr';
|
|
109
108
|
mockLocalization.locales = SETTINGS_LOCALES;
|
|
110
|
-
mockLocalization.defaultLocaleValue = 'tr';
|
|
111
109
|
mockLocalization.setLocale = jest.fn();
|
|
112
110
|
delete (window as { __iframeReadySent?: boolean }).__iframeReadySent;
|
|
113
111
|
});
|
|
@@ -146,8 +144,7 @@ describe('inside the editor', () => {
|
|
|
146
144
|
{ value: 'en', label: 'English' },
|
|
147
145
|
{ value: 'tr', label: 'Türkçe' },
|
|
148
146
|
{ value: 'de', label: 'de' }
|
|
149
|
-
]
|
|
150
|
-
defaultLocale: 'tr'
|
|
147
|
+
]
|
|
151
148
|
}
|
|
152
149
|
})
|
|
153
150
|
]);
|
|
@@ -157,34 +154,6 @@ describe('inside the editor', () => {
|
|
|
157
154
|
expect(targetOrigin).toBe(EDITOR_ORIGIN);
|
|
158
155
|
});
|
|
159
156
|
|
|
160
|
-
it('posts the languages before the document reports ready', () => {
|
|
161
|
-
// The editor holds every per-language write until IFRAME_READY and takes
|
|
162
|
-
// "ready without languages" to mean they are never coming, so the order
|
|
163
|
-
// of the two frames is part of the contract.
|
|
164
|
-
render(placeholder('header'));
|
|
165
|
-
|
|
166
|
-
const types = postMessage.mock.calls.map(([message]) => message?.type);
|
|
167
|
-
expect(types).toContain('LOCALE_UPDATE');
|
|
168
|
-
expect(types).toContain('IFRAME_READY');
|
|
169
|
-
expect(types.indexOf('LOCALE_UPDATE')).toBeLessThan(
|
|
170
|
-
types.indexOf('IFRAME_READY')
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("posts the brand's default language, whichever it is", () => {
|
|
175
|
-
// The editor's per-language text controls take the plain-string form to
|
|
176
|
-
// mean this language; left to guess, the editor assumed English.
|
|
177
|
-
mockLocalization.defaultLocaleValue = 'de';
|
|
178
|
-
|
|
179
|
-
render(<EditorLocaleBridge />);
|
|
180
|
-
|
|
181
|
-
expect(localeFrames()).toEqual([
|
|
182
|
-
expect.objectContaining({
|
|
183
|
-
data: expect.objectContaining({ locale: 'tr', defaultLocale: 'de' })
|
|
184
|
-
})
|
|
185
|
-
]);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
157
|
it("follows the editor's switch exactly once, with several placeholders mounted", () => {
|
|
189
158
|
render(
|
|
190
159
|
<>
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import OrderDetailBlock from '../order-detail-block';
|
|
4
|
+
import {
|
|
5
|
+
__resetOrderActionRulesForTests,
|
|
6
|
+
registerOrderActionRules
|
|
7
|
+
} from '../../utils/order-action-rules';
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* ZERO-5183 — the order detail is where an easy return starts and where a
|
|
@@ -64,6 +68,8 @@ const texts = (root: ParentNode, part: string) =>
|
|
|
64
68
|
(e.textContent || '').replace(/\s+/g, ' ').trim()
|
|
65
69
|
);
|
|
66
70
|
|
|
71
|
+
afterEach(() => __resetOrderActionRulesForTests());
|
|
72
|
+
|
|
67
73
|
beforeEach(() => {
|
|
68
74
|
order = {
|
|
69
75
|
id: 42,
|
|
@@ -164,7 +170,7 @@ describe('order detail — easy returns', () => {
|
|
|
164
170
|
expect(container.querySelector('[data-part="return-link"]')).toBeNull();
|
|
165
171
|
});
|
|
166
172
|
|
|
167
|
-
it('links
|
|
173
|
+
it('links a refundable line that has no request yet', () => {
|
|
168
174
|
// As commerce answers after a return: the order and its lines stay
|
|
169
175
|
// refundable while the request is open.
|
|
170
176
|
const flagged: Record<string, unknown>[] = (
|
|
@@ -194,15 +200,74 @@ describe('order detail — easy returns', () => {
|
|
|
194
200
|
};
|
|
195
201
|
expect(returnLink()).toBeNull();
|
|
196
202
|
|
|
197
|
-
// Commerce calls a shipped line refundable too
|
|
203
|
+
// Commerce calls a shipped line refundable too, and with no rule from
|
|
204
|
+
// the brand that is what decides (ZERO-5302).
|
|
198
205
|
order = {
|
|
199
206
|
...order,
|
|
200
207
|
orderitem_set: flagged.map((item) =>
|
|
201
|
-
item.id === 3
|
|
202
|
-
? { ...item, status: { value: '500', label: 'Gönderildi' } }
|
|
203
|
-
: item
|
|
208
|
+
item.id === 3 ? { ...item, status: { value: '500' } } : item
|
|
204
209
|
)
|
|
205
210
|
};
|
|
211
|
+
expect(returnLink()).not.toBeNull();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("asks the brand's rules about a line commerce lets go back (ZERO-5302)", () => {
|
|
215
|
+
const asked: string[] = [];
|
|
216
|
+
registerOrderActionRules({
|
|
217
|
+
returnLine: (item) => {
|
|
218
|
+
asked.push(String(item.status?.value));
|
|
219
|
+
return item.status?.value === '550';
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
const returnLink = () =>
|
|
223
|
+
render(
|
|
224
|
+
<OrderDetailBlock
|
|
225
|
+
block={blockOf(ALL_ON) as never}
|
|
226
|
+
placeholderId="p1"
|
|
227
|
+
sectionId="s1"
|
|
228
|
+
isDesigner={false}
|
|
229
|
+
/>
|
|
230
|
+
).container.querySelector('[data-part="return-link"]');
|
|
231
|
+
const withLine3 = (status: string) => ({
|
|
232
|
+
...order,
|
|
233
|
+
orderitem_set: (order?.orderitem_set as Record<string, unknown>[]).map(
|
|
234
|
+
(item) =>
|
|
235
|
+
item.id === 3
|
|
236
|
+
? { ...item, is_refundable: true, status: { value: status } }
|
|
237
|
+
: { ...item, is_refundable: false }
|
|
238
|
+
)
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
order = withLine3('550');
|
|
242
|
+
expect(returnLink()).not.toBeNull();
|
|
243
|
+
|
|
244
|
+
order = withLine3('500');
|
|
206
245
|
expect(returnLink()).toBeNull();
|
|
246
|
+
// Only the line commerce lets go back is put to the brand.
|
|
247
|
+
expect(new Set(asked)).toEqual(new Set(['550', '500']));
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('withholds the cancel link when the brand switches cancellation off (ZERO-5302)', () => {
|
|
251
|
+
order = { ...order, is_cancellable: true };
|
|
252
|
+
const cancelLink = () =>
|
|
253
|
+
render(
|
|
254
|
+
<OrderDetailBlock
|
|
255
|
+
block={
|
|
256
|
+
blockOf({
|
|
257
|
+
...ALL_ON,
|
|
258
|
+
showCancelLink: { desktop: true },
|
|
259
|
+
cancelLinkLabel: { desktop: 'Cancel' }
|
|
260
|
+
}) as never
|
|
261
|
+
}
|
|
262
|
+
placeholderId="p1"
|
|
263
|
+
sectionId="s1"
|
|
264
|
+
isDesigner={false}
|
|
265
|
+
/>
|
|
266
|
+
).container.querySelector('[data-part="cancel-link"]');
|
|
267
|
+
|
|
268
|
+
expect(cancelLink()).not.toBeNull();
|
|
269
|
+
|
|
270
|
+
registerOrderActionRules({ cancelOrder: () => false });
|
|
271
|
+
expect(cancelLink()).toBeNull();
|
|
207
272
|
});
|
|
208
273
|
});
|
|
@@ -2,31 +2,9 @@ import React from 'react';
|
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import TextBlock from '../text-block';
|
|
4
4
|
|
|
5
|
-
// The
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
const mockLocalization = { locale: 'en-us', defaultLocaleValue: 'en-us' };
|
|
9
|
-
|
|
10
|
-
jest.mock('@akinon/next/hooks', () => ({
|
|
11
|
-
__esModule: true,
|
|
12
|
-
useLocalization: () => ({
|
|
13
|
-
t: (path: string) => path,
|
|
14
|
-
setLocale: () => {},
|
|
15
|
-
setCurrency: () => {},
|
|
16
|
-
locale: mockLocalization.locale,
|
|
17
|
-
currency: 'USD',
|
|
18
|
-
locales: [{ value: 'en-us' }, { value: 'tr-tr' }],
|
|
19
|
-
currencies: ['USD'],
|
|
20
|
-
defaultLocaleValue: mockLocalization.defaultLocaleValue,
|
|
21
|
-
defaultCurrencyCode: 'USD',
|
|
22
|
-
localeUrlStrategy: 'hide-default-locale'
|
|
23
|
-
})
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
mockLocalization.locale = 'en-us';
|
|
28
|
-
mockLocalization.defaultLocaleValue = 'en-us';
|
|
29
|
-
});
|
|
5
|
+
// The mocked useLocalization (jest/__mocks__/akinon-next-hooks.js) returns
|
|
6
|
+
// locale: 'en-us'. process.env.NEXT_PUBLIC_DEFAULT_LOCALE is unset in the
|
|
7
|
+
// jest env, so the component's defaultLocale falls back to 'en'.
|
|
30
8
|
|
|
31
9
|
const renderBlock = (value: unknown, styles?: Record<string, unknown>) => {
|
|
32
10
|
const block: any = { id: 'b1', type: 'text', value, styles };
|
|
@@ -56,16 +34,10 @@ describe('TextBlock value-shape resolution', () => {
|
|
|
56
34
|
);
|
|
57
35
|
});
|
|
58
36
|
|
|
59
|
-
it(
|
|
60
|
-
|
|
61
|
-
// the block used to show: its default was read from an env variable
|
|
62
|
-
// that falls back to English, not from the storefront (ZERO-5296).
|
|
63
|
-
mockLocalization.locale = 'de-de';
|
|
64
|
-
mockLocalization.defaultLocaleValue = 'tr-tr';
|
|
65
|
-
|
|
66
|
-
const { container } = renderBlock({ en: 'EN', 'tr-tr': 'TR' });
|
|
37
|
+
it('falls back to defaultLocale ("en") when active locale is absent', () => {
|
|
38
|
+
const { container } = renderBlock({ en: 'EN', fr: 'FR' });
|
|
67
39
|
expect((container.querySelector('div') as HTMLDivElement).innerHTML).toBe(
|
|
68
|
-
'
|
|
40
|
+
'EN'
|
|
69
41
|
);
|
|
70
42
|
});
|
|
71
43
|
|
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
resolveItemProduct
|
|
16
16
|
} from './item-template-utils';
|
|
17
17
|
import { ThemeItemScopeProvider } from './product-block-utils';
|
|
18
|
-
import { ThemeRowScopeProvider } from './row-scope';
|
|
19
18
|
|
|
20
19
|
export {
|
|
21
20
|
findItemTemplate,
|
|
@@ -121,15 +120,20 @@ export const ItemTemplateList = ({
|
|
|
121
120
|
const scopesProducts = publishesProductItems(block.type);
|
|
122
121
|
// The same slice the iterator applied, so clone N is handed the row it
|
|
123
122
|
// was built from rather than row N.
|
|
124
|
-
const
|
|
123
|
+
const scopedRows = scopesProducts
|
|
124
|
+
? sliceIteratorItems(block, rows).items
|
|
125
|
+
: rows;
|
|
125
126
|
|
|
126
127
|
return (
|
|
127
128
|
<>
|
|
128
129
|
{clones.map((clone, index) => {
|
|
129
130
|
const key = clone.id || `${template.id}-item-${index}`;
|
|
130
|
-
const rowData = slicedRows[index] ?? {};
|
|
131
131
|
const row = (
|
|
132
132
|
<ThemeBlock
|
|
133
|
+
// Keyed here so the non-scoped branch is the element it always
|
|
134
|
+
// was: wrapping it in anything, even a fragment, would change the
|
|
135
|
+
// element type at this position and remount every existing row.
|
|
136
|
+
key={key}
|
|
133
137
|
block={clone}
|
|
134
138
|
placeholderId={placeholderId}
|
|
135
139
|
sectionId={sectionId}
|
|
@@ -139,32 +143,22 @@ export const ItemTemplateList = ({
|
|
|
139
143
|
currentBreakpoint={currentBreakpoint}
|
|
140
144
|
/>
|
|
141
145
|
);
|
|
142
|
-
const scoped = scopesProducts
|
|
143
|
-
? resolveItemProduct(block.type, rowData)
|
|
144
|
-
: null;
|
|
145
146
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
if (!scopesProducts) return row;
|
|
148
|
+
|
|
149
|
+
const scoped = resolveItemProduct(block.type, scopedRows[index]);
|
|
150
|
+
|
|
151
|
+
// Context only — the provider renders no element, so the markup a
|
|
152
|
+
// published row produces is unchanged.
|
|
149
153
|
return (
|
|
150
|
-
<
|
|
154
|
+
<ThemeItemScopeProvider
|
|
151
155
|
key={key}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
product={
|
|
157
|
+
scoped ?? (isDesigner ? DESIGNER_SAMPLE_PRODUCT : null)
|
|
158
|
+
}
|
|
155
159
|
>
|
|
156
|
-
{
|
|
157
|
-
|
|
158
|
-
product={
|
|
159
|
-
scoped ?? (isDesigner ? DESIGNER_SAMPLE_PRODUCT : null)
|
|
160
|
-
}
|
|
161
|
-
>
|
|
162
|
-
{row}
|
|
163
|
-
</ThemeItemScopeProvider>
|
|
164
|
-
) : (
|
|
165
|
-
row
|
|
166
|
-
)}
|
|
167
|
-
</ThemeRowScopeProvider>
|
|
160
|
+
{row}
|
|
161
|
+
</ThemeItemScopeProvider>
|
|
168
162
|
);
|
|
169
163
|
})}
|
|
170
164
|
</>
|