@akinon/pz-theme 2.0.164 → 2.0.165-rc.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 CHANGED
@@ -1,5 +1,57 @@
1
1
  # @akinon/pz-theme
2
2
 
3
+ ## 2.0.165-rc.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 8e040731e: ZERO-5235: let brands hang actions on order detail lines
8
+ - c761b9fd4: ZERO-5296: fall back to the storefront default language in the text block
9
+ - 17a598dae: ZERO-5296: report the storefront default language to the editor
10
+ - 3b05a407d: ZERO-5232: allow richtext settings on custom blocks
11
+ - Updated dependencies [86187b1c2]
12
+ - Updated dependencies [08390a87]
13
+ - Updated dependencies [0cf9ea239]
14
+ - Updated dependencies [324f97d55]
15
+ - Updated dependencies [4c3465ae]
16
+ - Updated dependencies [51ea06888]
17
+ - Updated dependencies
18
+ - Updated dependencies [549da545]
19
+ - Updated dependencies [2fea41430]
20
+ - Updated dependencies [b55acb768]
21
+ - Updated dependencies [760258c1c]
22
+ - Updated dependencies [143be2b9d]
23
+ - Updated dependencies [7889b08fe]
24
+ - Updated dependencies [9f8cd3bc5]
25
+ - Updated dependencies [d635d345]
26
+ - Updated dependencies [bfafa3f49]
27
+ - Updated dependencies [d860c917]
28
+ - Updated dependencies [ac6cada1]
29
+ - Updated dependencies [e90c0e02]
30
+ - Updated dependencies [dc7f9ca5]
31
+ - Updated dependencies [57d7eb305]
32
+ - Updated dependencies [0145dc3f]
33
+ - Updated dependencies [d99a6a7d5]
34
+ - Updated dependencies [92086b29]
35
+ - Updated dependencies [227b7408]
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
+ - Updated dependencies [9a7b0937]
51
+ - Updated dependencies [8853822c]
52
+ - @akinon/next@2.0.165-rc.0
53
+ - @akinon/theme-contract@2.0.165-rc.0
54
+
3
55
  ## 2.0.164
4
56
 
5
57
  ### Patch Changes
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.164",
4
+ "version": "2.0.165-rc.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.164",
11
+ "@akinon/next": "2.0.165-rc.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.164",
16
+ "@akinon/theme-contract": "2.0.165-rc.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.164",
24
+ "@akinon/next": "2.0.165-rc.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,6 +28,7 @@ const SETTINGS_LOCALES = [
28
28
  const mockLocalization = {
29
29
  locale: 'tr',
30
30
  locales: SETTINGS_LOCALES as Array<Record<string, unknown>>,
31
+ defaultLocaleValue: 'tr',
31
32
  setLocale: jest.fn()
32
33
  };
33
34
 
@@ -106,6 +107,7 @@ beforeEach(() => {
106
107
  postMessage.mockClear();
107
108
  mockLocalization.locale = 'tr';
108
109
  mockLocalization.locales = SETTINGS_LOCALES;
110
+ mockLocalization.defaultLocaleValue = 'tr';
109
111
  mockLocalization.setLocale = jest.fn();
110
112
  delete (window as { __iframeReadySent?: boolean }).__iframeReadySent;
111
113
  });
@@ -144,7 +146,8 @@ describe('inside the editor', () => {
144
146
  { value: 'en', label: 'English' },
145
147
  { value: 'tr', label: 'Türkçe' },
146
148
  { value: 'de', label: 'de' }
147
- ]
149
+ ],
150
+ defaultLocale: 'tr'
148
151
  }
149
152
  })
150
153
  ]);
@@ -154,6 +157,34 @@ describe('inside the editor', () => {
154
157
  expect(targetOrigin).toBe(EDITOR_ORIGIN);
155
158
  });
156
159
 
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
+
157
188
  it("follows the editor's switch exactly once, with several placeholders mounted", () => {
158
189
  render(
159
190
  <>
@@ -0,0 +1,54 @@
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
+ });
@@ -2,9 +2,31 @@ import React from 'react';
2
2
  import { render } from '@testing-library/react';
3
3
  import TextBlock from '../text-block';
4
4
 
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'.
5
+ // The page's language and the storefront's default, as the localization
6
+ // provider reports them. Most cases run on an English-default store showing
7
+ // English; the fallback case moves both.
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
+ });
8
30
 
9
31
  const renderBlock = (value: unknown, styles?: Record<string, unknown>) => {
10
32
  const block: any = { id: 'b1', type: 'text', value, styles };
@@ -34,10 +56,16 @@ describe('TextBlock value-shape resolution', () => {
34
56
  );
35
57
  });
36
58
 
37
- it('falls back to defaultLocale ("en") when active locale is absent', () => {
38
- const { container } = renderBlock({ en: 'EN', fr: 'FR' });
59
+ it("falls back to the storefront's default language when the active one is absent", () => {
60
+ // A Turkish-default store showing German. The entry under `en` is what
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' });
39
67
  expect((container.querySelector('div') as HTMLDivElement).innerHTML).toBe(
40
- 'EN'
68
+ 'TR'
41
69
  );
42
70
  });
43
71
 
@@ -9,6 +9,7 @@ import { getResponsiveValue, partAttrs } from '../utils';
9
9
  import { formatDate, formatMoney } from './commerce-format';
10
10
  import { readMoneyStyle } from './money-style';
11
11
  import { hasItemTemplate, ItemTemplateList } from './item-template';
12
+ import { renderOrderLineActions } from './order-line-actions';
12
13
  import { BlockRendererProps } from './block-renderer-registry';
13
14
  import {
14
15
  DesignerPlaceholder,
@@ -24,7 +25,7 @@ import {
24
25
  useOrderActionRules
25
26
  } from '../utils/order-action-rules';
26
27
 
27
- interface OrderItemLike {
28
+ type OrderItemLike = {
28
29
  id?: number;
29
30
  price?: string;
30
31
  quantity?: string | number;
@@ -43,7 +44,7 @@ interface OrderItemLike {
43
44
  absolute_url?: string;
44
45
  attributes?: Record<string, unknown>;
45
46
  } | null;
46
- }
47
+ };
47
48
 
48
49
  interface AddressLike {
49
50
  first_name?: string;
@@ -408,7 +409,7 @@ const formatAddress = (address: AddressLike | null | undefined): string[] => {
408
409
  * currencyText, currencyPosition.
409
410
  * Parts: detail, header, number, date, header-total, status,
410
411
  * invoice-link, cancel-link, return-link, list, item, image, name, quantity,
411
- * color, size, item-status, item-tracking, item-return-code,
412
+ * color, size, item-status, item-tracking, item-return-code, item-actions,
412
413
  * item-return-method, item-return-carrier, item-pickup-date, price, shipment,
413
414
  * delivery, tracking, addresses, address, address-label, totals, total-row,
414
415
  * total-label, total-value, grand-total, payment-info, payment-info-label.
@@ -955,6 +956,21 @@ const OrderDetailBlock = ({
955
956
  showPickupDate && returnDetails.pickupDate
956
957
  ? formatPickupDate(returnDetails.pickupDate, locale)
957
958
  : '';
959
+ const lineActions = renderOrderLineActions({
960
+ order,
961
+ line,
962
+ isDesigner
963
+ });
964
+ const showLineMeta =
965
+ showShipmentStatus &&
966
+ Boolean(
967
+ item.status?.label ||
968
+ trackingValue ||
969
+ returnCodeValue ||
970
+ returnMethodValue ||
971
+ returnCarrierValue ||
972
+ pickupDateValue
973
+ );
958
974
 
959
975
  return (
960
976
  <li
@@ -1070,98 +1086,100 @@ const OrderDetailBlock = ({
1070
1086
  </div>
1071
1087
  </div>
1072
1088
 
1073
- {showShipmentStatus &&
1074
- (item.status?.label ||
1075
- trackingValue ||
1076
- returnCodeValue ||
1077
- returnMethodValue ||
1078
- returnCarrierValue ||
1079
- pickupDateValue) && (
1080
- <div
1081
- style={{
1082
- display: 'flex',
1083
- flexDirection: 'column',
1084
- alignItems: isMobile ? 'flex-start' : 'flex-end',
1085
- textAlign: isMobile ? 'left' : 'right',
1086
- gap: '4px',
1087
- flex: isMobile ? '1 1 100%' : '0 0 auto'
1088
- }}
1089
- >
1090
- {item.status?.label && (
1091
- <span
1092
- data-order-detail-item-status=""
1093
- data-order-status-value={item.status.value}
1094
- {...partAttrs('item-status')}
1095
- style={{ display: 'inline-block' }}
1096
- >
1097
- {item.status.label}
1098
- </span>
1099
- )}
1100
- {/* Label and value in their own spans, so a
1101
- composition can colour them apart. */}
1102
- {returnMethodValue && (
1103
- <span
1104
- data-order-detail-item-return-method=""
1105
- {...partAttrs('item-return-method')}
1106
- style={{ opacity: 0.8 }}
1107
- >
1108
- <span data-label="">{returnMethodLabel}</span>{' '}
1109
- <span data-value="">{returnMethodValue}</span>
1110
- </span>
1111
- )}
1112
- {returnCarrierValue && (
1113
- <span
1114
- data-order-detail-item-return-carrier=""
1115
- {...partAttrs('item-return-carrier')}
1116
- style={{ opacity: 0.8 }}
1117
- >
1118
- <span data-label="">{returnCarrierLabel}</span>{' '}
1119
- <span data-value="">{returnCarrierValue}</span>
1120
- </span>
1121
- )}
1122
- {pickupDateValue && (
1123
- <span
1124
- data-order-detail-item-pickup-date=""
1125
- {...partAttrs('item-pickup-date')}
1126
- style={{ opacity: 0.8 }}
1127
- >
1128
- <span data-label="">{pickupDateLabel}</span>{' '}
1129
- <span data-value="">{pickupDateValue}</span>
1130
- </span>
1131
- )}
1132
- {trackingValue && (
1133
- <span
1134
- data-order-detail-item-tracking=""
1135
- {...partAttrs('item-tracking')}
1136
- style={{ opacity: 0.8 }}
1137
- >
1138
- {lineTrackingLabel}{' '}
1139
- {item.tracking_url ? (
1140
- <a
1141
- href={isDesigner ? '#' : item.tracking_url}
1142
- onClick={guard}
1143
- target={isDesigner ? undefined : '_blank'}
1144
- rel="noreferrer"
1145
- style={{ color: 'inherit' }}
1146
- >
1147
- {item.tracking_number || item.tracking_url}
1148
- </a>
1149
- ) : (
1150
- trackingValue
1151
- )}
1152
- </span>
1153
- )}
1154
- {returnCodeValue && (
1155
- <span
1156
- data-order-detail-item-return-code=""
1157
- {...partAttrs('item-return-code')}
1158
- style={{ opacity: 0.8 }}
1159
- >
1160
- {returnCodeLabel} {returnCodeValue}
1161
- </span>
1162
- )}
1163
- </div>
1164
- )}
1089
+ {(showLineMeta || lineActions) && (
1090
+ <div
1091
+ style={{
1092
+ display: 'flex',
1093
+ flexDirection: 'column',
1094
+ alignItems: isMobile ? 'flex-start' : 'flex-end',
1095
+ textAlign: isMobile ? 'left' : 'right',
1096
+ gap: '4px',
1097
+ flex: isMobile ? '1 1 100%' : '0 0 auto'
1098
+ }}
1099
+ >
1100
+ {lineActions && (
1101
+ <div
1102
+ data-order-detail-item-actions=""
1103
+ {...partAttrs('item-actions')}
1104
+ >
1105
+ {lineActions}
1106
+ </div>
1107
+ )}
1108
+ {showLineMeta && item.status?.label && (
1109
+ <span
1110
+ data-order-detail-item-status=""
1111
+ data-order-status-value={item.status.value}
1112
+ {...partAttrs('item-status')}
1113
+ style={{ display: 'inline-block' }}
1114
+ >
1115
+ {item.status.label}
1116
+ </span>
1117
+ )}
1118
+ {/* Label and value in their own spans, so a
1119
+ composition can colour them apart. */}
1120
+ {showLineMeta && returnMethodValue && (
1121
+ <span
1122
+ data-order-detail-item-return-method=""
1123
+ {...partAttrs('item-return-method')}
1124
+ style={{ opacity: 0.8 }}
1125
+ >
1126
+ <span data-label="">{returnMethodLabel}</span>{' '}
1127
+ <span data-value="">{returnMethodValue}</span>
1128
+ </span>
1129
+ )}
1130
+ {showLineMeta && returnCarrierValue && (
1131
+ <span
1132
+ data-order-detail-item-return-carrier=""
1133
+ {...partAttrs('item-return-carrier')}
1134
+ style={{ opacity: 0.8 }}
1135
+ >
1136
+ <span data-label="">{returnCarrierLabel}</span>{' '}
1137
+ <span data-value="">{returnCarrierValue}</span>
1138
+ </span>
1139
+ )}
1140
+ {showLineMeta && pickupDateValue && (
1141
+ <span
1142
+ data-order-detail-item-pickup-date=""
1143
+ {...partAttrs('item-pickup-date')}
1144
+ style={{ opacity: 0.8 }}
1145
+ >
1146
+ <span data-label="">{pickupDateLabel}</span>{' '}
1147
+ <span data-value="">{pickupDateValue}</span>
1148
+ </span>
1149
+ )}
1150
+ {showLineMeta && trackingValue && (
1151
+ <span
1152
+ data-order-detail-item-tracking=""
1153
+ {...partAttrs('item-tracking')}
1154
+ style={{ opacity: 0.8 }}
1155
+ >
1156
+ {lineTrackingLabel}{' '}
1157
+ {item.tracking_url ? (
1158
+ <a
1159
+ href={isDesigner ? '#' : item.tracking_url}
1160
+ onClick={guard}
1161
+ target={isDesigner ? undefined : '_blank'}
1162
+ rel="noreferrer"
1163
+ style={{ color: 'inherit' }}
1164
+ >
1165
+ {item.tracking_number || item.tracking_url}
1166
+ </a>
1167
+ ) : (
1168
+ trackingValue
1169
+ )}
1170
+ </span>
1171
+ )}
1172
+ {showLineMeta && returnCodeValue && (
1173
+ <span
1174
+ data-order-detail-item-return-code=""
1175
+ {...partAttrs('item-return-code')}
1176
+ style={{ opacity: 0.8 }}
1177
+ >
1178
+ {returnCodeLabel} {returnCodeValue}
1179
+ </span>
1180
+ )}
1181
+ </div>
1182
+ )}
1165
1183
  </div>
1166
1184
  </li>
1167
1185
  );
@@ -0,0 +1,45 @@
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
+ };
@@ -19,7 +19,7 @@ const TextBlock = ({
19
19
  }: BlockRendererProps) => {
20
20
  const { locale } = useLocalization();
21
21
  const localize = useLocalizeHref();
22
- const defaultLocale = process.env.NEXT_PUBLIC_DEFAULT_LOCALE || 'en';
22
+ const { defaultLocale } = useValueLocale();
23
23
  const themeSettings = useThemeSettingsContext();
24
24
 
25
25
  const getLocalizedContent = (): string => {
@@ -35,7 +35,10 @@ const TextBlock = ({
35
35
 
36
36
  if (typeof value === 'object' && value !== null) {
37
37
  return (
38
- value[locale] || value[defaultLocale] || Object.values(value)[0] || ''
38
+ value[locale] ||
39
+ (defaultLocale && value[defaultLocale]) ||
40
+ Object.values(value)[0] ||
41
+ ''
39
42
  );
40
43
  }
41
44