@akinon/pz-theme 2.0.160-rc.21 → 2.0.160
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 +6 -50
- package/package.json +4 -4
- package/src/__tests__/editor-locale-bridge.test.tsx +1 -32
- 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 +95 -113
- 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/__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
|
@@ -33,20 +33,19 @@ export type PropertyType = (typeof CUSTOM_PROPERTY_TYPES)[number];
|
|
|
33
33
|
* The subset whose value provably survives the full round trip — panel write,
|
|
34
34
|
* persistence, and resolution back into a prop.
|
|
35
35
|
*
|
|
36
|
-
* The
|
|
37
|
-
* guessed:
|
|
38
|
-
* (`theme-basic-properties.tsx:1547-1548` passes arrays and locale objects
|
|
39
|
-
* through without the per-breakpoint wrapper). `getResponsiveValue` then
|
|
40
|
-
* rejects an array with a devWarn and returns the fallback, and a locale
|
|
41
|
-
* object has no `desktop` key so it does too. They can never deliver a
|
|
42
|
-
* value until a per-type resolver exists.
|
|
36
|
+
* The three excluded members are excluded for reasons that were verified, not
|
|
37
|
+
* guessed:
|
|
43
38
|
*
|
|
44
|
-
* `
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
39
|
+
* - `multiselect` and `localetext` are stored UNBUCKETED by the editor
|
|
40
|
+
* (`theme-basic-properties.tsx:1547-1548` passes arrays and locale objects
|
|
41
|
+
* through without the per-breakpoint wrapper). `getResponsiveValue` then
|
|
42
|
+
* rejects an array with a devWarn and returns the fallback, and a locale
|
|
43
|
+
* object has no `desktop` key so it does too. They can never deliver a
|
|
44
|
+
* value until a per-type resolver exists.
|
|
45
|
+
* - `richtext` has no safe renderer here. The allowlist sanitizer this repo
|
|
46
|
+
* already owns parses by assigning to `innerHTML` on a live element, so the
|
|
47
|
+
* sink is its first act — and pz-theme renders server-side, where there is
|
|
48
|
+
* no `document` at all.
|
|
50
49
|
*
|
|
51
50
|
* Declaring one of these throws at define time rather than shipping a control
|
|
52
51
|
* that silently shows the default forever.
|
|
@@ -60,11 +59,12 @@ export const SUPPORTED_PROPERTY_TYPES: readonly PropertyType[] = [
|
|
|
60
59
|
'color',
|
|
61
60
|
'image',
|
|
62
61
|
'file',
|
|
63
|
-
'richtext',
|
|
64
62
|
'typography',
|
|
65
63
|
'icon'
|
|
66
64
|
];
|
|
67
65
|
|
|
68
|
-
export const isSupportedPropertyType = (
|
|
66
|
+
export const isSupportedPropertyType = (
|
|
67
|
+
type: unknown
|
|
68
|
+
): type is PropertyType =>
|
|
69
69
|
typeof type === 'string' &&
|
|
70
70
|
(SUPPORTED_PROPERTY_TYPES as readonly string[]).includes(type);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { getResponsiveValue } from '../utils';
|
|
4
|
-
import { sanitizeRichText } from '../utils/sanitize-rich-text';
|
|
5
4
|
import { devWarn } from '../utils/dev-warn';
|
|
6
5
|
import {
|
|
7
6
|
isLocalizedValue,
|
|
@@ -239,11 +238,6 @@ export function useThemeSetting<
|
|
|
239
238
|
|
|
240
239
|
const defaults = splitDefault(declaration, valueLocale);
|
|
241
240
|
|
|
242
|
-
const finish = (value: unknown): TValue =>
|
|
243
|
-
(declaration.type === 'richtext'
|
|
244
|
-
? sanitizeRichText(typeof value === 'string' ? value : '')
|
|
245
|
-
: value) as TValue;
|
|
246
|
-
|
|
247
241
|
if (!context) {
|
|
248
242
|
// A missing block context is never an error on its own: a developer
|
|
249
243
|
// previewing the component in a storybook or a unit test should see the
|
|
@@ -260,7 +254,7 @@ export function useThemeSetting<
|
|
|
260
254
|
`unreachable and the declared default is used instead. Render this ` +
|
|
261
255
|
`component through a block registered with registerCustomBlocks().`
|
|
262
256
|
);
|
|
263
|
-
return
|
|
257
|
+
return defaults.page as TValue;
|
|
264
258
|
}
|
|
265
259
|
|
|
266
260
|
// Reported on every render rather than once from an effect: the collection
|
|
@@ -277,17 +271,7 @@ export function useThemeSetting<
|
|
|
277
271
|
// attribute keys that were never declared. `node` rather than `block` so a
|
|
278
272
|
// setting declared inside a custom SECTION reads the section's own
|
|
279
273
|
// properties, which is where the editor writes it.
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
// The rich text control writes per language — `{ tr: '<p>…</p>', en: … }` —
|
|
283
|
-
// and the editor stores that map as it is, with no breakpoint key: the same
|
|
284
|
-
// shape that keeps `localetext` out (see `property-types.ts`). Read the
|
|
285
|
-
// page's language out of it first; what is left is a string or a breakpoint
|
|
286
|
-
// map, which the responsive read below already understands.
|
|
287
|
-
const stored =
|
|
288
|
-
declaration.type === 'richtext'
|
|
289
|
-
? resolveLocalizedValue(authored, valueLocale)
|
|
290
|
-
: authored;
|
|
274
|
+
const stored = context.node.properties?.[key];
|
|
291
275
|
|
|
292
276
|
// The sentinel again, for the same reason: handing `getResponsiveValue` an
|
|
293
277
|
// undefined fallback would resolve an undeclared default to `''`, so a
|
|
@@ -296,15 +280,15 @@ export function useThemeSetting<
|
|
|
296
280
|
const resolved = getResponsiveValue(stored, breakpoint, NOT_AUTHORED);
|
|
297
281
|
|
|
298
282
|
if (resolved === NOT_AUTHORED) {
|
|
299
|
-
return
|
|
283
|
+
return resolveAuthoredDefault(defaults.page, breakpoint) as TValue;
|
|
300
284
|
}
|
|
301
285
|
|
|
302
286
|
// The default-language text as the editor seeded it when the block was
|
|
303
287
|
// placed, never changed since: still the author's copy, so it follows the
|
|
304
288
|
// page's language. Anything the merchant typed is theirs and shows as typed.
|
|
305
289
|
if (defaults.perLocale && resolved === defaults.base) {
|
|
306
|
-
return
|
|
290
|
+
return defaults.page as TValue;
|
|
307
291
|
}
|
|
308
292
|
|
|
309
|
-
return
|
|
293
|
+
return resolved as TValue;
|
|
310
294
|
}
|
|
@@ -4,28 +4,14 @@ import { useEffect } from 'react';
|
|
|
4
4
|
import { useLocalization } from '@akinon/next/hooks';
|
|
5
5
|
|
|
6
6
|
import { isTrustedEditorEvent, postToEditor } from './editor-bridge';
|
|
7
|
-
import { useValueLocale } from './utils/localized-value';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* The storefront half of the editor's Language dropdown.
|
|
11
10
|
*
|
|
12
11
|
* The editor starts that dropdown with English only and fills it from the
|
|
13
|
-
* `LOCALE_UPDATE` frame the preview posts (`{ locale, locales
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* The frame carries the storefront's default language as well. The editor's
|
|
18
|
-
* per-language text controls store a plain string in that language and a map
|
|
19
|
-
* in every other, so an editor that never heard it assumed English and gave
|
|
20
|
-
* every Turkish-default store a stray `en` key (ZERO-5296).
|
|
21
|
-
*
|
|
22
|
-
* It is posted BEFORE the document reports ready (`IFRAME_READY`): the bridge
|
|
23
|
-
* is a child of the placeholder wrapper, whose own effect posts that frame,
|
|
24
|
-
* and React runs a child's effects first. The editor relies on the order — it
|
|
25
|
-
* holds every per-language write until the preview is ready, and takes
|
|
26
|
-
* "ready without languages" to mean a storefront that will never send them.
|
|
27
|
-
*
|
|
28
|
-
* For a long time the only code answering either direction
|
|
12
|
+
* `LOCALE_UPDATE` frame the preview posts (`{ locale, locales }`); when the
|
|
13
|
+
* merchant picks another language it posts `LOCALE_UPDATE` back and expects the
|
|
14
|
+
* preview to follow. For a long time the only code answering either direction
|
|
29
15
|
* was the app-template's `LanguageSelect` — brand code. A brand whose header no
|
|
30
16
|
* longer renders that component (a header composed through ChromeSlot, a
|
|
31
17
|
* custom header section, a project older than the template) left the editor
|
|
@@ -68,7 +54,6 @@ export interface EditorLocaleOption {
|
|
|
68
54
|
interface LocaleState {
|
|
69
55
|
locale: string;
|
|
70
56
|
locales: EditorLocaleOption[];
|
|
71
|
-
defaultLocale?: string;
|
|
72
57
|
setLocale: (locale: string) => void;
|
|
73
58
|
}
|
|
74
59
|
|
|
@@ -101,22 +86,15 @@ const toEditorLocales = (locales: unknown): EditorLocaleOption[] =>
|
|
|
101
86
|
: entry.value
|
|
102
87
|
}));
|
|
103
88
|
|
|
104
|
-
const announcementKey = (
|
|
105
|
-
locale,
|
|
106
|
-
locales,
|
|
107
|
-
defaultLocale
|
|
108
|
-
}: Omit<LocaleState, 'setLocale'>) =>
|
|
109
|
-
JSON.stringify([locale, locales, defaultLocale ?? null]);
|
|
89
|
+
const announcementKey = (locale: string, locales: EditorLocaleOption[]) =>
|
|
90
|
+
JSON.stringify([locale, locales]);
|
|
110
91
|
|
|
111
|
-
const announce = ({ locale, locales
|
|
112
|
-
const key = announcementKey(
|
|
92
|
+
const announce = ({ locale, locales }: LocaleState) => {
|
|
93
|
+
const key = announcementKey(locale, locales);
|
|
113
94
|
if (key === lastAnnounced) return;
|
|
114
95
|
lastAnnounced = key;
|
|
115
96
|
|
|
116
|
-
postToEditor({
|
|
117
|
-
type: 'LOCALE_UPDATE',
|
|
118
|
-
data: { locale, locales, defaultLocale }
|
|
119
|
-
});
|
|
97
|
+
postToEditor({ type: 'LOCALE_UPDATE', data: { locale, locales } });
|
|
120
98
|
};
|
|
121
99
|
|
|
122
100
|
const handleEditorMessage = (event: MessageEvent) => {
|
|
@@ -137,7 +115,7 @@ const handleEditorMessage = (event: MessageEvent) => {
|
|
|
137
115
|
|
|
138
116
|
// The editor is already showing `requested`. Recording it as announced keeps
|
|
139
117
|
// the switch from being echoed back when the new locale reaches the page.
|
|
140
|
-
lastAnnounced = announcementKey(
|
|
118
|
+
lastAnnounced = announcementKey(requested, current.locales);
|
|
141
119
|
current.setLocale(requested);
|
|
142
120
|
};
|
|
143
121
|
|
|
@@ -148,7 +126,6 @@ const handleEditorMessage = (event: MessageEvent) => {
|
|
|
148
126
|
*/
|
|
149
127
|
export function EditorLocaleBridge(): null {
|
|
150
128
|
const { locale, locales, setLocale } = useLocalization();
|
|
151
|
-
const { defaultLocale } = useValueLocale();
|
|
152
129
|
|
|
153
130
|
useEffect(() => {
|
|
154
131
|
if (!isFramed()) return;
|
|
@@ -170,14 +147,9 @@ export function EditorLocaleBridge(): null {
|
|
|
170
147
|
useEffect(() => {
|
|
171
148
|
if (!isFramed() || !locale) return;
|
|
172
149
|
|
|
173
|
-
current = {
|
|
174
|
-
locale,
|
|
175
|
-
locales: toEditorLocales(locales),
|
|
176
|
-
defaultLocale,
|
|
177
|
-
setLocale
|
|
178
|
-
};
|
|
150
|
+
current = { locale, locales: toEditorLocales(locales), setLocale };
|
|
179
151
|
announce(current);
|
|
180
|
-
}, [locale, locales,
|
|
152
|
+
}, [locale, locales, setLocale]);
|
|
181
153
|
|
|
182
154
|
return null;
|
|
183
155
|
}
|
|
@@ -1166,9 +1166,6 @@ export default function ThemePlaceholderWrapper({
|
|
|
1166
1166
|
Tells the editor which languages this storefront has and follows its
|
|
1167
1167
|
language switch. Every placeholder renders one; they share a single
|
|
1168
1168
|
listener and a single announcement (see editor-locale-bridge.tsx).
|
|
1169
|
-
A child of this wrapper on purpose: its effect, and so its frame,
|
|
1170
|
-
runs before the effect below that posts IFRAME_READY, and the editor
|
|
1171
|
-
counts on hearing the languages before the ready report.
|
|
1172
1169
|
*/}
|
|
1173
1170
|
<EditorLocaleBridge />
|
|
1174
1171
|
{themeBackgroundCSS && (
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { ItemTemplateList } from '../blocks/item-template';
|
|
4
|
-
import { useThemeProduct } from '../blocks/product-block-utils';
|
|
5
|
-
import { useThemeRowScope } from '../blocks/row-scope';
|
|
6
|
-
import blockRendererRegistry from '../blocks/block-renderer-registry';
|
|
7
|
-
import { resetCustomCatalog } from '../custom/catalog';
|
|
8
|
-
import { resetCustomCollection } from '../custom/collect';
|
|
9
|
-
import { isCustomThemeType, registerCustomBlocks } from '../custom';
|
|
10
|
-
import type { Block } from '../theme-block';
|
|
11
|
-
|
|
12
|
-
const READER = 'custom:acme:row-reader';
|
|
13
|
-
|
|
14
|
-
function RowReader() {
|
|
15
|
-
const scope = useThemeRowScope();
|
|
16
|
-
const product = useThemeProduct();
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<span
|
|
20
|
-
data-testid="reader"
|
|
21
|
-
data-list={scope?.listType ?? ''}
|
|
22
|
-
data-index={scope?.index ?? ''}
|
|
23
|
-
data-number={String(scope?.row.number ?? '')}
|
|
24
|
-
data-product={String(product?.pk ?? '')}
|
|
25
|
-
/>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const template = (): Block =>
|
|
30
|
-
({
|
|
31
|
-
id: 'tpl',
|
|
32
|
-
type: 'group',
|
|
33
|
-
label: 'Row',
|
|
34
|
-
order: 0,
|
|
35
|
-
hidden: false,
|
|
36
|
-
value: '',
|
|
37
|
-
properties: { role: { desktop: 'item-template' } },
|
|
38
|
-
styles: {},
|
|
39
|
-
blocks: [
|
|
40
|
-
{
|
|
41
|
-
id: 'tpl-reader',
|
|
42
|
-
type: READER,
|
|
43
|
-
label: 'Reader',
|
|
44
|
-
order: 0,
|
|
45
|
-
hidden: false,
|
|
46
|
-
value: '',
|
|
47
|
-
properties: {},
|
|
48
|
-
styles: {},
|
|
49
|
-
blocks: []
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
} as Block);
|
|
53
|
-
|
|
54
|
-
const list = (type: string): Block =>
|
|
55
|
-
({
|
|
56
|
-
id: 'list',
|
|
57
|
-
type,
|
|
58
|
-
label: 'List',
|
|
59
|
-
order: 0,
|
|
60
|
-
hidden: false,
|
|
61
|
-
value: '',
|
|
62
|
-
properties: {},
|
|
63
|
-
styles: {},
|
|
64
|
-
blocks: [template()]
|
|
65
|
-
} as Block);
|
|
66
|
-
|
|
67
|
-
const renderRows = (type: string, items: Record<string, unknown>[]) =>
|
|
68
|
-
render(
|
|
69
|
-
<ItemTemplateList
|
|
70
|
-
block={list(type)}
|
|
71
|
-
items={items}
|
|
72
|
-
placeholderId="p1"
|
|
73
|
-
sectionId="s1"
|
|
74
|
-
/>
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
beforeAll(() => {
|
|
78
|
-
registerCustomBlocks('acme', { 'row-reader': RowReader });
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
afterAll(() => {
|
|
82
|
-
const map = (
|
|
83
|
-
blockRendererRegistry as unknown as { renderers: Map<string, unknown> }
|
|
84
|
-
).renderers;
|
|
85
|
-
Array.from(map.keys())
|
|
86
|
-
.filter(isCustomThemeType)
|
|
87
|
-
.forEach((key) => map.delete(key));
|
|
88
|
-
resetCustomCatalog();
|
|
89
|
-
resetCustomCollection();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('the row scope', () => {
|
|
93
|
-
it('hands every repeated row to the blocks inside it, on any list', () => {
|
|
94
|
-
renderRows('order-list', [{ number: 'ORD-1' }, { number: 'ORD-2' }]);
|
|
95
|
-
|
|
96
|
-
const readers = screen.getAllByTestId('reader');
|
|
97
|
-
expect(readers).toHaveLength(2);
|
|
98
|
-
expect(readers[0]).toHaveAttribute('data-list', 'order-list');
|
|
99
|
-
expect(readers[0]).toHaveAttribute('data-index', '0');
|
|
100
|
-
expect(readers[0]).toHaveAttribute('data-number', 'ORD-1');
|
|
101
|
-
expect(readers[1]).toHaveAttribute('data-number', 'ORD-2');
|
|
102
|
-
expect(readers[0]).toHaveAttribute('data-product', '');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('keeps the product scope on product lists next to the row scope', () => {
|
|
106
|
-
renderRows('product-grid', [{ pk: 7, name: 'Sneaker' }]);
|
|
107
|
-
|
|
108
|
-
const reader = screen.getByTestId('reader');
|
|
109
|
-
expect(reader).toHaveAttribute('data-list', 'product-grid');
|
|
110
|
-
expect(reader).toHaveAttribute('data-product', '7');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('is closed outside a repeated row', () => {
|
|
114
|
-
render(<RowReader />);
|
|
115
|
-
|
|
116
|
-
expect(screen.getByTestId('reader')).toHaveAttribute('data-list', '');
|
|
117
|
-
});
|
|
118
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
registerOrderLineActions,
|
|
4
|
-
renderOrderLineActions
|
|
5
|
-
} from '../order-line-actions';
|
|
6
|
-
|
|
7
|
-
const context = {
|
|
8
|
-
order: { id: 7, number: '20920397829', created_date: '2026-10-01' },
|
|
9
|
-
line: {
|
|
10
|
-
key: '1',
|
|
11
|
-
name: 'Product',
|
|
12
|
-
image: '',
|
|
13
|
-
href: '',
|
|
14
|
-
price: '100',
|
|
15
|
-
total: 100,
|
|
16
|
-
quantity: 1,
|
|
17
|
-
item: { id: 1, status: { value: '550', label: 'Delivered' } }
|
|
18
|
-
},
|
|
19
|
-
isDesigner: false
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
describe('order line actions registry', () => {
|
|
23
|
-
it('renders nothing until a brand registers', () => {
|
|
24
|
-
expect(renderOrderLineActions(context)).toBeNull();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('hands the line and order to the registered renderer', () => {
|
|
28
|
-
const renderer = jest.fn(() => <span>action</span>);
|
|
29
|
-
const unregister = registerOrderLineActions(renderer);
|
|
30
|
-
|
|
31
|
-
expect(renderOrderLineActions(context)).toEqual(<span>action</span>);
|
|
32
|
-
expect(renderer).toHaveBeenCalledWith(context);
|
|
33
|
-
|
|
34
|
-
unregister();
|
|
35
|
-
expect(renderOrderLineActions(context)).toBeNull();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('swallows a throwing renderer so a brand bug cannot break the line', () => {
|
|
39
|
-
const unregister = registerOrderLineActions(() => {
|
|
40
|
-
throw new Error('boom');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(renderOrderLineActions(context)).toBeNull();
|
|
44
|
-
unregister();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('only forgets the renderer it was asked to forget', () => {
|
|
48
|
-
const first = registerOrderLineActions(() => 'first');
|
|
49
|
-
registerOrderLineActions(() => 'second');
|
|
50
|
-
|
|
51
|
-
first();
|
|
52
|
-
expect(renderOrderLineActions(context)).toBe('second');
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import OrderListBlock from '../order-list-block';
|
|
4
|
-
|
|
5
|
-
const captured: { items: Record<string, unknown>[] } = { items: [] };
|
|
6
|
-
|
|
7
|
-
jest.mock('../item-template', () => ({
|
|
8
|
-
__esModule: true,
|
|
9
|
-
hasItemTemplate: () => true,
|
|
10
|
-
ItemTemplateList: ({ items }: { items: Record<string, unknown>[] }) => {
|
|
11
|
-
captured.items = items;
|
|
12
|
-
return <div data-testid="item-template-list" />;
|
|
13
|
-
}
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
jest.mock('next-auth/react', () => ({
|
|
17
|
-
useSession: () => ({ data: null, status: 'authenticated' })
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
jest.mock('@akinon/next/hooks', () => ({
|
|
21
|
-
__esModule: true,
|
|
22
|
-
useLocalization: () => ({ locale: 'tr', currency: 'try' })
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
jest.mock('@akinon/next/redux/hooks', () => ({
|
|
26
|
-
__esModule: true,
|
|
27
|
-
useAppSelector: () => undefined,
|
|
28
|
-
useAppDispatch: () => jest.fn()
|
|
29
|
-
}));
|
|
30
|
-
|
|
31
|
-
jest.mock('@akinon/next/data/client/account', () => ({
|
|
32
|
-
__esModule: true,
|
|
33
|
-
useGetOrdersQuery: () => ({
|
|
34
|
-
data: {
|
|
35
|
-
count: 1,
|
|
36
|
-
results: [
|
|
37
|
-
{
|
|
38
|
-
id: 42,
|
|
39
|
-
number: 'ORD-42',
|
|
40
|
-
amount: '100.00',
|
|
41
|
-
created_date: '2026-09-01T10:00:00Z',
|
|
42
|
-
status: { value: '550', label: 'Delivered' },
|
|
43
|
-
orderitem_set: [
|
|
44
|
-
{
|
|
45
|
-
id: 7,
|
|
46
|
-
status: { value: 550, label: 'Delivered' },
|
|
47
|
-
product: {
|
|
48
|
-
sku: 'SKU-1',
|
|
49
|
-
base_code: 'BASE-1',
|
|
50
|
-
name: 'Sneaker',
|
|
51
|
-
image: '/s.jpg'
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
status: { value: '400', label: 'Approved' },
|
|
56
|
-
product: { name: 'Boot' }
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
},
|
|
62
|
-
isLoading: false
|
|
63
|
-
})
|
|
64
|
-
}));
|
|
65
|
-
|
|
66
|
-
describe('order list rows', () => {
|
|
67
|
-
it('publishes the order items with their product codes and status code', () => {
|
|
68
|
-
render(
|
|
69
|
-
<OrderListBlock
|
|
70
|
-
block={{
|
|
71
|
-
id: 'order-list-1',
|
|
72
|
-
type: 'order-list',
|
|
73
|
-
properties: {},
|
|
74
|
-
styles: {},
|
|
75
|
-
blocks: []
|
|
76
|
-
}}
|
|
77
|
-
placeholderId="p1"
|
|
78
|
-
sectionId="s1"
|
|
79
|
-
/>
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
expect(captured.items).toHaveLength(1);
|
|
83
|
-
expect(captured.items[0]).toMatchObject({
|
|
84
|
-
id: 42,
|
|
85
|
-
number: 'ORD-42',
|
|
86
|
-
createdDate: '2026-09-01T10:00:00Z'
|
|
87
|
-
});
|
|
88
|
-
expect(captured.items[0].items).toEqual([
|
|
89
|
-
{
|
|
90
|
-
id: 7,
|
|
91
|
-
name: 'Sneaker',
|
|
92
|
-
image: '/s.jpg',
|
|
93
|
-
status: 'Delivered',
|
|
94
|
-
statusValue: '550',
|
|
95
|
-
product: {
|
|
96
|
-
sku: 'SKU-1',
|
|
97
|
-
base_code: 'BASE-1',
|
|
98
|
-
name: 'Sneaker',
|
|
99
|
-
image: '/s.jpg'
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
id: 1,
|
|
104
|
-
name: 'Boot',
|
|
105
|
-
image: '',
|
|
106
|
-
status: 'Approved',
|
|
107
|
-
statusValue: '400',
|
|
108
|
-
product: { sku: '', base_code: '', name: 'Boot', image: '' }
|
|
109
|
-
}
|
|
110
|
-
]);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
import type { GroupedOrderLine, OrderLineLike } from './product-block-utils';
|
|
3
|
-
|
|
4
|
-
export interface OrderLineActionsOrder {
|
|
5
|
-
id?: number;
|
|
6
|
-
number?: string;
|
|
7
|
-
created_date?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type OrderLineActionsItem = OrderLineLike & {
|
|
11
|
-
status?: { value?: string; label?: string };
|
|
12
|
-
[key: string]: unknown;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export interface OrderLineActionsContext {
|
|
16
|
-
order: OrderLineActionsOrder;
|
|
17
|
-
line: GroupedOrderLine<OrderLineActionsItem>;
|
|
18
|
-
isDesigner: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type OrderLineActionsRenderer = (
|
|
22
|
-
context: OrderLineActionsContext
|
|
23
|
-
) => ReactNode;
|
|
24
|
-
|
|
25
|
-
let renderer: OrderLineActionsRenderer | null = null;
|
|
26
|
-
|
|
27
|
-
export const registerOrderLineActions = (
|
|
28
|
-
fn: OrderLineActionsRenderer
|
|
29
|
-
): (() => void) => {
|
|
30
|
-
renderer = fn;
|
|
31
|
-
return () => {
|
|
32
|
-
if (renderer === fn) renderer = null;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const renderOrderLineActions = (
|
|
37
|
-
context: OrderLineActionsContext
|
|
38
|
-
): ReactNode => {
|
|
39
|
-
if (!renderer) return null;
|
|
40
|
-
try {
|
|
41
|
-
return renderer(context) ?? null;
|
|
42
|
-
} catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
};
|
package/src/blocks/row-scope.tsx
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
|
|
5
|
-
export interface ThemeRowScopeValue {
|
|
6
|
-
listType: string;
|
|
7
|
-
row: Record<string, unknown>;
|
|
8
|
-
index: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const ThemeRowScopeContext = React.createContext<ThemeRowScopeValue | null>(
|
|
12
|
-
null
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
export const ThemeRowScopeProvider = ({
|
|
16
|
-
listType,
|
|
17
|
-
row,
|
|
18
|
-
index,
|
|
19
|
-
children
|
|
20
|
-
}: ThemeRowScopeValue & { children: React.ReactNode }) => {
|
|
21
|
-
const value = React.useMemo(
|
|
22
|
-
() => ({ listType, row, index }),
|
|
23
|
-
[listType, row, index]
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<ThemeRowScopeContext.Provider value={value}>
|
|
28
|
-
{children}
|
|
29
|
-
</ThemeRowScopeContext.Provider>
|
|
30
|
-
);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/** Non-null while a repeated row of any list renders; null everywhere else. */
|
|
34
|
-
export const useThemeRowScope = (): ThemeRowScopeValue | null =>
|
|
35
|
-
React.useContext(ThemeRowScopeContext);
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { sanitizeRichText } from '../sanitize-rich-text';
|
|
2
|
-
|
|
3
|
-
describe('sanitizeRichText', () => {
|
|
4
|
-
it('keeps the markup the editor writes', () => {
|
|
5
|
-
const html =
|
|
6
|
-
'<p>Sipariş <b>verirseniz</b> <i>yarın</i> <u>kapınızda</u></p><ul><li>bir</li></ul><h2>Başlık</h2><br>';
|
|
7
|
-
|
|
8
|
-
expect(sanitizeRichText(html)).toBe(
|
|
9
|
-
'<p>Sipariş <b>verirseniz</b> <i>yarın</i> <u>kapınızda</u></p><ul><li>bir</li></ul><h2>Başlık</h2><br />'
|
|
10
|
-
);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('drops scripts, event handlers and unknown tags but keeps their text', () => {
|
|
14
|
-
const html =
|
|
15
|
-
'<p onclick="x()">a<script>alert(1)</script><custom>b</custom><img src=x onerror=alert(1)></p>';
|
|
16
|
-
|
|
17
|
-
expect(sanitizeRichText(html)).toBe('<p>ab</p>');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('keeps only safe links and forces rel on new-tab links', () => {
|
|
21
|
-
expect(
|
|
22
|
-
sanitizeRichText(
|
|
23
|
-
'<a href="javascript:alert(1)">x</a><a href="https://gant.com" target="_blank">y</a><a href="/sss">z</a>'
|
|
24
|
-
)
|
|
25
|
-
).toBe(
|
|
26
|
-
'<a>x</a><a href="https://gant.com" target="_blank" rel="noopener noreferrer">y</a><a href="/sss">z</a>'
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('keeps only the colour and emphasis styles', () => {
|
|
31
|
-
expect(
|
|
32
|
-
sanitizeRichText(
|
|
33
|
-
'<span style="color: #9a2320; position: fixed; background: url(x)">a</span>'
|
|
34
|
-
)
|
|
35
|
-
).toBe('<span style="color: #9a2320">a</span>');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('leaves text, entities and placeholders untouched', () => {
|
|
39
|
-
expect(sanitizeRichText('{{countdown}} & {{add_day|4}}')).toBe(
|
|
40
|
-
'{{countdown}} & {{add_day|4}}'
|
|
41
|
-
);
|
|
42
|
-
expect(sanitizeRichText('')).toBe('');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('reads tag names the way the browser does, so no element slips through as text', () => {
|
|
46
|
-
expect(
|
|
47
|
-
sanitizeRichText(
|
|
48
|
-
'<x_y onmouseover=alert(1) style=position:fixed;inset:0>a</x_y>'
|
|
49
|
-
)
|
|
50
|
-
).toBe('a');
|
|
51
|
-
expect(sanitizeRichText('<svg/onload=alert(1)>b')).toBe('b');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('never lets an unfinished tag run into the markup that follows', () => {
|
|
55
|
-
expect(sanitizeRichText('<img src=x onerror=alert(1)')).toBe(
|
|
56
|
-
'<img src=x onerror=alert(1)'
|
|
57
|
-
);
|
|
58
|
-
expect(sanitizeRichText('<p>a</p><b')).toBe('<p>a</p><b');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('escapes every < that does not become a kept tag', () => {
|
|
62
|
-
expect(sanitizeRichText('a < b <3 c')).toBe('a < b <3 c');
|
|
63
|
-
expect(sanitizeRichText('<!DOCTYPE html><?xml version="1.0"?>x')).toBe(
|
|
64
|
-
'<!DOCTYPE html><?xml version="1.0"?>x'
|
|
65
|
-
);
|
|
66
|
-
expect(sanitizeRichText('</>')).toBe('</>');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('reads a quoted attribute value holding > as part of the tag', () => {
|
|
70
|
-
expect(sanitizeRichText('<a href="/x" title="a>b">t</a>')).toBe(
|
|
71
|
-
'<a href="/x">t</a>'
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('drops an unterminated comment or script to the end', () => {
|
|
76
|
-
expect(sanitizeRichText('a<!-- b')).toBe('a');
|
|
77
|
-
expect(sanitizeRichText('<!-->x')).toBe('x');
|
|
78
|
-
expect(sanitizeRichText('a<script>alert(1)')).toBe('a');
|
|
79
|
-
});
|
|
80
|
-
});
|