@onekeyfe/react-native-native-list 6.7.0-2 → 6.7.0-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 (148) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -9
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +35 -7
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
  5. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
  6. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
  9. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
  10. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
  11. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
  12. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +149 -3
  14. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  16. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
  18. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  19. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
  20. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1953 -117
  21. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
  22. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  23. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  24. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  25. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  26. package/docs/ROW_TEMPLATES.md +70 -11
  27. package/docs/SPEC.md +1235 -20
  28. package/docs/STYLE_SPEC.md +6 -0
  29. package/ios/HybridNativeList.swift +21 -2
  30. package/ios/NativeListAccessoryStack.swift +235 -39
  31. package/ios/NativeListActivityDetailsView.swift +30 -11
  32. package/ios/NativeListActivityRenderer.swift +8 -2
  33. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  34. package/ios/NativeListDataRowRenderer.swift +155 -27
  35. package/ios/NativeListDesignAssets.swift +9 -0
  36. package/ios/NativeListIdentityRenderer.swift +239 -31
  37. package/ios/NativeListLeadingVisual.swift +119 -22
  38. package/ios/NativeListMarketRenderer.swift +113 -18
  39. package/ios/NativeListMessageRenderer.swift +34 -1
  40. package/ios/NativeListModels.swift +42 -2
  41. package/ios/NativeListRendererRegistry.swift +1 -0
  42. package/ios/NativeListResolvedText.swift +2 -1
  43. package/ios/NativeListRowHost.swift +14 -0
  44. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  45. package/ios/RNCNativeListView.swift +1052 -58
  46. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  47. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  48. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
  49. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
  50. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
  51. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
  52. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  53. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  54. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
  55. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
  56. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  57. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  58. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
  59. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
  60. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
  61. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
  62. package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
  63. package/ios/tests/NativeListActivityPresentationTests.swift +153 -0
  64. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  65. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  66. package/ios/tests/NativeListLifecycleTests.swift +2789 -3
  67. package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
  68. package/lib/module/NativeList.js +223 -36
  69. package/lib/module/NativeList.web.js +260 -33
  70. package/lib/module/index.js +1 -1
  71. package/lib/module/models.js +3 -0
  72. package/lib/module/selection.js +1 -1
  73. package/lib/module/validation.js +1386 -81
  74. package/lib/module/web/NativeListWebEngine.js +914 -80
  75. package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
  76. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  77. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  78. package/lib/module/web/templates/IdentityRowRenderer.js +145 -5
  79. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  80. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  81. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  82. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  83. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  84. package/lib/module/web/templates/RowRendererRegistry.js +8 -3
  85. package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
  86. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  87. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  88. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  89. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  90. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  91. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  92. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  93. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  94. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  95. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  96. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  97. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  98. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  99. package/lib/typescript/src/NativeList.d.ts +3 -3
  100. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  101. package/lib/typescript/src/NativeList.types.d.ts +29 -1
  102. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  103. package/lib/typescript/src/index.d.ts +2 -2
  104. package/lib/typescript/src/models.d.ts +196 -17
  105. package/lib/typescript/src/validation.d.ts +20 -0
  106. package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
  107. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  108. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  109. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  110. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  111. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  112. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
  113. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  114. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  115. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  116. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  117. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  118. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  119. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  120. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  121. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  122. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  123. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  124. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  125. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  126. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  127. package/package.json +3 -3
  128. package/react-native-native-list.podspec +1 -0
  129. package/src/NativeList.nitro.ts +2 -0
  130. package/src/NativeList.tsx +418 -89
  131. package/src/NativeList.types.ts +34 -1
  132. package/src/NativeList.web.tsx +417 -66
  133. package/src/index.ts +2 -0
  134. package/src/models.ts +355 -143
  135. package/src/selection.ts +1 -0
  136. package/src/validation.ts +3315 -166
  137. package/src/web/NativeListWebEngine.ts +1473 -113
  138. package/src/web/templates/ActivityRowRenderer.ts +732 -8
  139. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  140. package/src/web/templates/DataRowRenderer.ts +93 -20
  141. package/src/web/templates/IdentityRowRenderer.ts +217 -6
  142. package/src/web/templates/MarketRowRenderer.ts +19 -3
  143. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  144. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  145. package/src/web/templates/MessageRowRenderer.ts +23 -7
  146. package/src/web/templates/RowContainerStyle.ts +2 -0
  147. package/src/web/templates/RowRendererRegistry.ts +21 -6
  148. package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
@@ -1,6 +1,7 @@
1
- import type { ActivityRow } from '../../models';
1
+ import type { ActivityAmount, ActivityRow, LeadingVisual } from '../../models';
2
2
  import { createElement, tagSlot, markActionAnchorSource } from './RowElements';
3
3
  import { RowVisualStyle, type RowPrimitives } from './RowVisual';
4
+ import { applyTextWeight, applyValueSegments } from './RowText';
4
5
  type Views = {
5
6
  column: HTMLElement;
6
7
  fields: Record<string, HTMLElement>;
@@ -12,7 +13,11 @@ type Views = {
12
13
  primitives: RowPrimitives;
13
14
  };
14
15
  const views = new WeakMap<HTMLElement, Views>();
15
- function bind(body: HTMLElement, row: ActivityRow, primitives: RowPrimitives) {
16
+ function bindLegacy(
17
+ body: HTMLElement,
18
+ row: ActivityRow,
19
+ primitives: RowPrimitives
20
+ ) {
16
21
  const v = views.get(body)!;
17
22
  v.primitives = primitives;
18
23
  body.style.cssText = '';
@@ -42,6 +47,7 @@ function bind(body: HTMLElement, row: ActivityRow, primitives: RowPrimitives) {
42
47
  }
43
48
  const visualKey = JSON.stringify([
44
49
  row.key,
50
+ row.hideLeading,
45
51
  row.leading,
46
52
  row.secondaryLeading,
47
53
  ]);
@@ -50,7 +56,7 @@ function bind(body: HTMLElement, row: ActivityRow, primitives: RowPrimitives) {
50
56
  primitives.dispose(node);
51
57
  node.remove();
52
58
  });
53
- v.visuals = [row.leading, row.secondaryLeading]
59
+ v.visuals = (row.hideLeading ? [] : [row.leading, row.secondaryLeading])
54
60
  .map((source) => primitives.visual(source))
55
61
  .filter((node): node is HTMLElement => !!node);
56
62
  v.visuals.forEach((node) => body.insertBefore(node, v.column));
@@ -81,7 +87,7 @@ function bind(body: HTMLElement, row: ActivityRow, primitives: RowPrimitives) {
81
87
  v.actions.appendChild(button);
82
88
  });
83
89
  }
84
- function create(
90
+ function createLegacy(
85
91
  document: Document,
86
92
  row: ActivityRow,
87
93
  primitives: RowPrimitives
@@ -130,10 +136,10 @@ function create(
130
136
  visualKey: '',
131
137
  primitives,
132
138
  });
133
- bind(body, row, primitives);
139
+ bindLegacy(body, row, primitives);
134
140
  return body;
135
141
  }
136
- function recycle(body: HTMLElement) {
142
+ function recycleLegacy(body: HTMLElement) {
137
143
  const v = views.get(body);
138
144
  if (!v) return;
139
145
  v.visuals.forEach((node) => {
@@ -145,13 +151,731 @@ function recycle(body: HTMLElement) {
145
151
  v.visualKey = '';
146
152
  v.actions.replaceChildren();
147
153
  }
154
+ type AmountViews = {
155
+ element: HTMLElement;
156
+ primary: HTMLElement;
157
+ secondary: HTMLElement;
158
+ visual?: HTMLElement;
159
+ visualKey: string;
160
+ };
161
+ type HistoryViews = {
162
+ content: HTMLElement;
163
+ identity: HTMLElement;
164
+ visual: HTMLElement;
165
+ text: HTMLElement;
166
+ titleLine: HTMLElement;
167
+ title: HTMLElement;
168
+ badges: HTMLElement;
169
+ description: HTMLElement;
170
+ descriptionTime: HTMLElement;
171
+ descriptionDot: HTMLElement;
172
+ descriptionAddress: HTMLButtonElement;
173
+ amounts: HTMLElement;
174
+ amountRows: Map<string, AmountViews>;
175
+ fee: HTMLElement;
176
+ feeLabel: HTMLElement;
177
+ feeValues: HTMLElement;
178
+ feePrimary: HTMLElement;
179
+ feeSecondary: HTMLElement;
180
+ actions: HTMLElement;
181
+ actionButtons: Map<string, HTMLButtonElement>;
182
+ visualKey: string;
183
+ visuals: {
184
+ node: HTMLElement;
185
+ style: RowVisualStyle;
186
+ background: string;
187
+ loaded: boolean;
188
+ fallback?: HTMLElement;
189
+ fallbackStyle?: RowVisualStyle;
190
+ }[];
191
+ primitives: RowPrimitives;
192
+ };
193
+ const histories = new WeakMap<HTMLElement, HistoryViews>();
194
+ const isHistory = (row: ActivityRow) =>
195
+ row.presentation !== undefined || row.amounts !== undefined;
196
+ const ellipsis =
197
+ 'min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;';
198
+ function valueText(
199
+ node: HTMLElement,
200
+ text: string | undefined,
201
+ segments: ActivityAmount['textSegments'],
202
+ size: number,
203
+ line: number,
204
+ weight: number
205
+ ) {
206
+ node.textContent = text ?? '';
207
+ applyTextWeight(node, weight);
208
+ applyValueSegments(node, segments, size, line, weight);
209
+ }
210
+ function createHistory(body: HTMLElement, primitives: RowPrimitives) {
211
+ const document = body.ownerDocument;
212
+ const node = (name: string) =>
213
+ createElement(document, 'div', `ok-native-list-history-${name}`);
214
+ const content = node('content');
215
+ const identity = node('identity');
216
+ const visual = node('visual');
217
+ const text = node('text');
218
+ const titleLine = node('title-line');
219
+ const title = tagSlot(node('title'), 'title');
220
+ const badges = node('badges');
221
+ const description = node('description');
222
+ description.dataset.nlSlot = 'description';
223
+ const descriptionTime = createElement(document, 'span');
224
+ const descriptionDot = createElement(document, 'span', undefined, '•');
225
+ const descriptionAddress = createElement(
226
+ document,
227
+ 'button'
228
+ ) as HTMLButtonElement;
229
+ descriptionAddress.type = 'button';
230
+ description.append(descriptionTime, descriptionDot, descriptionAddress);
231
+ const amounts = node('amounts');
232
+ const fee = node('fee');
233
+ const feeLabel = node('fee-label');
234
+ const feeValues = node('fee-values');
235
+ const feePrimary = node('fee-primary');
236
+ const feeSecondary = node('fee-secondary');
237
+ const actions = node('actions');
238
+ titleLine.append(title, badges);
239
+ text.append(titleLine, description);
240
+ identity.append(visual, text);
241
+ feeValues.append(feePrimary, feeSecondary);
242
+ fee.append(feeLabel, feeValues);
243
+ content.append(identity, amounts, fee);
244
+ body.replaceChildren(content, actions);
245
+ const v: HistoryViews = {
246
+ content,
247
+ identity,
248
+ visual,
249
+ text,
250
+ titleLine,
251
+ title,
252
+ badges,
253
+ description,
254
+ descriptionTime,
255
+ descriptionDot,
256
+ descriptionAddress,
257
+ amounts,
258
+ amountRows: new Map(),
259
+ fee,
260
+ feeLabel,
261
+ feeValues,
262
+ feePrimary,
263
+ feeSecondary,
264
+ actions,
265
+ actionButtons: new Map(),
266
+ visualKey: '',
267
+ visuals: [],
268
+ primitives,
269
+ };
270
+ histories.set(body, v);
271
+ return v;
272
+ }
273
+ const historyIconPaths: Readonly<Record<string, readonly string[]>> = {
274
+ ArrowTopOutline: [
275
+ 'M19.414 10 18 11.414l-5-5V21h-2V6.414l-5 5L4.586 10 12 2.586z',
276
+ ],
277
+ ArrowBottomOutline: [
278
+ 'm13 17.586 5-5L19.414 14 12 21.414 4.586 14 6 12.586l5 5V3h2z',
279
+ ],
280
+ SwitchHorOutline: [
281
+ 'm9.414 13-3 3H21v2H6.414l3 3L8 22.414 2.586 17 8 11.586zm12-6L16 12.414 14.586 11l3-3H3V6h14.586l-3-3L16 1.586z',
282
+ ],
283
+ CoinsOutline: [
284
+ 'M9 3a7 7 0 0 1 6.328 4.008 7 7 0 1 1-6.657 9.983A7 7 0 0 1 9 3m5.718 6.008a5 5 0 1 0 .566 9.985 5 5 0 0 0-.566-9.985M9 5a5 5 0 0 0-.941 9.91 7 7 0 0 1 5.11-7.667A4.99 4.99 0 0 0 8.999 5Z',
285
+ ],
286
+ ShieldCheckDoneOutline: [
287
+ 'M15.914 9.75 11 14.664 8.086 11.75 9.5 10.336l1.5 1.5 3.5-3.5z',
288
+ 'M12.325 2.055 21 5.036v6.876c0 2.807-1.149 4.83-2.813 6.404-1.615 1.53-3.745 2.66-5.712 3.722l-.475.256-.475-.256c-1.967-1.061-4.097-2.192-5.713-3.722C4.15 16.741 3 14.72 3 11.912V5.036l8.675-2.981.325-.113zM5 6.463v5.45c0 2.165.851 3.686 2.188 4.951 1.275 1.208 2.965 2.154 4.812 3.154 1.847-1 3.537-1.946 4.813-3.154C18.148 15.6 19 14.078 19 11.912v-5.45l-7-2.405z',
289
+ ],
290
+ UnlockedOutline: [
291
+ 'M13 18h-2v-5h2z',
292
+ 'M12 2a5 5 0 0 1 5 5h-2a3 3 0 0 0-6 0v2h11v13H4V9h3V7a5 5 0 0 1 5-5M6 20h12v-9H6z',
293
+ ],
294
+ Document2Outline: [
295
+ 'M12 16H8v-2h4zm4-4H8v-2h8zm0-4H8V6h8z',
296
+ 'M20 22H4V2h16zM6 20h12V4H6z',
297
+ ],
298
+ CryptoCoinOutline: [
299
+ 'M11 16.387a4.5 4.5 0 0 1 0-8.775V6h2v1.613a4.5 4.5 0 0 1 2.856 2.067l-1.712 1.032a2.5 2.5 0 1 0 0 2.576l1.712 1.032A4.5 4.5 0 0 1 13 16.386V18h-2z',
300
+ 'M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10m-2 0a8 8 0 1 0-16 0 8 8 0 0 0 16 0',
301
+ ],
302
+ ImageSquareWavesOutline: [
303
+ 'M14.25 7a2 2 0 1 1 0 4 2 2 0 0 1 0-4',
304
+ 'M21 21H3V3h18zM5 16.414V19h12.586L14 15.414l-2 2-4-4zm0-2.828 3-3 4 4 2-2 5 5V5H5z',
305
+ ],
306
+ DotHorOutline: ['M6 14H2v-4h4zm8 0h-4v-4h4zm8 0h-4v-4h4z'],
307
+ };
308
+ function historyIcon(
309
+ node: HTMLElement,
310
+ source: LeadingVisual | undefined,
311
+ size: number
312
+ ) {
313
+ const name =
314
+ source?.kind === 'icon'
315
+ ? source.name
316
+ : source?.kind === 'token'
317
+ ? source.fallbackIcon?.name
318
+ : undefined;
319
+ const paths = name && historyIconPaths[name];
320
+ if (!paths) return;
321
+ const placeholder = node.querySelector<HTMLElement>(
322
+ '.ok-native-list-visual-fallback'
323
+ );
324
+ if (!placeholder && source && 'image' in source && source.image) return;
325
+ const fallback = placeholder ?? node;
326
+ Object.assign(fallback.style, {
327
+ display: 'flex',
328
+ alignItems: 'center',
329
+ justifyContent: 'center',
330
+ width: '100%',
331
+ height: '100%',
332
+ });
333
+ if (source?.kind === 'icon' && source.tintColor)
334
+ fallback.style.color = source.tintColor;
335
+ else if (source && 'fallbackIcon' in source && source.fallbackIcon?.tintColor)
336
+ fallback.style.color = source.fallbackIcon.tintColor;
337
+ const svg = node.ownerDocument.createElementNS(
338
+ 'http://www.w3.org/2000/svg',
339
+ 'svg'
340
+ );
341
+ svg.setAttribute('viewBox', '0 0 24 24');
342
+ svg.setAttribute('width', String(size));
343
+ svg.setAttribute('height', String(size));
344
+ svg.setAttribute('fill', 'currentColor');
345
+ svg.setAttribute('aria-hidden', 'true');
346
+ for (const d of paths) {
347
+ const path = node.ownerDocument.createElementNS(
348
+ 'http://www.w3.org/2000/svg',
349
+ 'path'
350
+ );
351
+ path.setAttribute('d', d);
352
+ path.setAttribute('fill-rule', 'evenodd');
353
+ svg.append(path);
354
+ }
355
+ fallback.replaceChildren(svg);
356
+ }
357
+ function bindHistory(
358
+ body: HTMLElement,
359
+ row: ActivityRow,
360
+ primitives: RowPrimitives
361
+ ) {
362
+ const v = histories.get(body) ?? createHistory(body, primitives);
363
+ v.primitives = primitives;
364
+ const table = row.presentation === 'table';
365
+ const footer = Boolean(row.footerActions?.length);
366
+ body.className = 'ok-native-list-row ok-native-list-history';
367
+ body.style.cssText = '';
368
+ body.removeAttribute('data-nl-container-background');
369
+ body.removeAttribute('data-nl-container-border');
370
+ Object.assign(body.style, {
371
+ display: 'flex',
372
+ flexDirection: 'column',
373
+ alignItems: 'stretch',
374
+ justifyContent: 'flex-start',
375
+ width: 'calc(100% - 16px)',
376
+ margin: '0 8px',
377
+ padding: `${table ? 12 : 8}px 12px`,
378
+ height:
379
+ !table && !footer && row.height !== 60 ? 'calc(100% - 8px)' : '100%',
380
+ borderRadius: '12px',
381
+ gap: '8px',
382
+ });
383
+ Object.assign(v.content.style, {
384
+ display: 'flex',
385
+ alignItems: 'center',
386
+ gap: '12px',
387
+ minWidth: '0',
388
+ width: '100%',
389
+ });
390
+ Object.assign(v.identity.style, {
391
+ display: 'flex',
392
+ alignItems: 'center',
393
+ gap: row.hideLeading ? '0' : '12px',
394
+ minWidth: '0',
395
+ flex: '1 1 0',
396
+ });
397
+ Object.assign(v.visual.style, {
398
+ display: row.hideLeading ? 'none' : '',
399
+ position: 'relative',
400
+ width: '40px',
401
+ height: '40px',
402
+ flex: '0 0 40px',
403
+ });
404
+ const visualKey = JSON.stringify([
405
+ row.key,
406
+ row.hideLeading,
407
+ row.leading,
408
+ row.secondaryLeading,
409
+ ]);
410
+ if (v.visualKey !== visualKey) {
411
+ Array.from(v.visual.children).forEach((n) =>
412
+ primitives.dispose(n as HTMLElement)
413
+ );
414
+ v.visual.replaceChildren();
415
+ v.visuals = [];
416
+ const sources = row.hideLeading
417
+ ? []
418
+ : [row.leading, row.secondaryLeading].filter(Boolean);
419
+ sources.forEach((source) => {
420
+ const visual = primitives.visual(source);
421
+ if (!visual) return;
422
+ historyIcon(visual, source, table || sources.length > 1 ? 24 : 28);
423
+ const retained = {
424
+ node: visual,
425
+ style: new RowVisualStyle(visual),
426
+ background: visual.style.background,
427
+ loaded: false,
428
+ };
429
+ // Only placeholder-backed sources restore their frame background on load.
430
+ const image = source && 'image' in source ? source.image : undefined;
431
+ if (image?.loadingStrategy && image.loadingStrategy !== 'none') {
432
+ visual
433
+ .querySelector('.ok-native-list-visual-main')
434
+ ?.addEventListener('load', () => {
435
+ retained.background =
436
+ source && 'backgroundColor' in source && source.backgroundColor
437
+ ? source.backgroundColor
438
+ : 'transparent';
439
+ retained.loaded = true;
440
+ });
441
+ }
442
+ v.visuals.push(retained);
443
+ v.visual.append(visual);
444
+ });
445
+ v.visualKey = visualKey;
446
+ }
447
+ const sources = row.hideLeading
448
+ ? []
449
+ : [row.leading, row.secondaryLeading].filter(Boolean);
450
+ v.visuals.forEach((retained, index) => {
451
+ const { node: visual, style, background, loaded } = retained;
452
+ const source = sources[index];
453
+ const previousToken = visual.querySelector<HTMLElement>(
454
+ ':scope > .ok-native-list-history-token'
455
+ );
456
+ if (previousToken) {
457
+ visual.append(...Array.from(previousToken.children));
458
+ previousToken.remove();
459
+ }
460
+ const currentFallback = visual.querySelector<HTMLElement>(
461
+ ':scope > .ok-native-list-visual-fallback:not(.ok-native-list-visual-corner)'
462
+ );
463
+ if (currentFallback && retained.fallback !== currentFallback) {
464
+ retained.fallback = currentFallback;
465
+ retained.fallbackStyle = new RowVisualStyle(currentFallback);
466
+ }
467
+ // A terminal image error creates a new fallback node after the factory bind.
468
+ retained.fallbackStyle?.restore();
469
+ const size = sources.length > 1 ? (index ? 28 : 24) : 40;
470
+ style.apply(row.style?.image, size, size, 0);
471
+ Object.assign(visual.style, {
472
+ background,
473
+ position: '',
474
+ left: '',
475
+ top: '',
476
+ });
477
+ const svg = visual.querySelector<SVGElement>(
478
+ '.ok-native-list-visual-fallback > svg'
479
+ );
480
+ if (svg) {
481
+ const iconSize = String(table || sources.length > 1 ? 24 : 28);
482
+ svg.setAttribute('width', iconSize);
483
+ svg.setAttribute('height', iconSize);
484
+ }
485
+ Object.assign(visual.style, {
486
+ display: 'inline-flex',
487
+ alignItems: 'center',
488
+ justifyContent: 'center',
489
+ });
490
+ if (sources.length > 1)
491
+ Object.assign(visual.style, {
492
+ position: 'absolute',
493
+ left: index ? '12px' : '0',
494
+ top: index ? '12px' : '0',
495
+ border: index ? '2px solid var(--nl-row)' : '0',
496
+ boxSizing: 'border-box',
497
+ });
498
+ if (!table && sources.length > 1) {
499
+ const token = visual.ownerDocument.createElement('span');
500
+ token.className = 'ok-native-list-history-token';
501
+ Object.assign(token.style, {
502
+ display: 'flex',
503
+ alignItems: 'center',
504
+ justifyContent: 'center',
505
+ position: 'relative',
506
+ width: '24px',
507
+ height: '24px',
508
+ flex: '0 0 24px',
509
+ borderRadius: 'inherit',
510
+ boxSizing: 'border-box',
511
+ overflow: 'hidden',
512
+ background:
513
+ source && 'backgroundColor' in source
514
+ ? source.backgroundColor ?? ''
515
+ : '',
516
+ border:
517
+ source && 'borderColor' in source && source.borderColor
518
+ ? `1px solid ${source.borderColor}`
519
+ : '0',
520
+ });
521
+ token.append(
522
+ ...Array.from(visual.children).filter(
523
+ (child) => !child.classList.contains('ok-native-list-visual-corner')
524
+ )
525
+ );
526
+ const fallback = token.querySelector<HTMLElement>(
527
+ ':scope > .ok-native-list-visual-fallback'
528
+ );
529
+ if (fallback) {
530
+ fallback.style.width = '24px';
531
+ fallback.style.height = '24px';
532
+ fallback.style.flexShrink = '0';
533
+ }
534
+ const mainImage = token.querySelector<HTMLImageElement>(
535
+ ':scope > .ok-native-list-visual-main'
536
+ );
537
+ if (mainImage) {
538
+ mainImage.style.width = '100%';
539
+ mainImage.style.height = '100%';
540
+ }
541
+ visual.append(token);
542
+ }
543
+ if (table) {
544
+ visual.style.background = loaded
545
+ ? background
546
+ : source && 'backgroundColor' in source && source.backgroundColor
547
+ ? source.backgroundColor
548
+ : 'var(--nl-strong)';
549
+ const borderColor =
550
+ source && 'borderColor' in source && source.borderColor
551
+ ? source.borderColor
552
+ : 'var(--nl-separator)';
553
+ visual.style.border = `1px solid ${borderColor}`;
554
+ visual.style.boxSizing = 'border-box';
555
+ } else if (sources.length === 1 && source?.kind === 'token') {
556
+ visual.style.border = source.borderColor
557
+ ? `1px solid ${source.borderColor}`
558
+ : '0';
559
+ visual.style.boxSizing = 'border-box';
560
+ const mainImage = visual.querySelector<HTMLImageElement>(
561
+ ':scope > .ok-native-list-visual-main'
562
+ );
563
+ if (mainImage) {
564
+ mainImage.style.width = '100%';
565
+ mainImage.style.height = '100%';
566
+ }
567
+ }
568
+ });
569
+ Object.assign(v.text.style, {
570
+ minWidth: '0',
571
+ flex: '1 1 auto',
572
+ display: 'flex',
573
+ flexDirection: 'column',
574
+ gap: table ? '4px' : '0',
575
+ });
576
+ Object.assign(v.titleLine.style, {
577
+ display: 'flex',
578
+ alignItems: 'center',
579
+ minWidth: '0',
580
+ });
581
+ v.title.style.cssText =
582
+ ellipsis +
583
+ `font-size:${table ? 14 : 16}px;line-height:${
584
+ table ? 20 : 24
585
+ }px;font-weight:500;`;
586
+ v.title.textContent = row.title;
587
+ applyTextWeight(v.title, 500);
588
+ if (row.style?.title) primitives.textStyle(v.title, row.style.title);
589
+ v.badges.style.cssText = 'display:flex;flex:0 0 auto;gap:8px;margin-left:8px';
590
+ v.badges.replaceChildren();
591
+ for (const badge of row.badges ?? []) {
592
+ const element = createElement(
593
+ body.ownerDocument,
594
+ 'span',
595
+ 'ok-native-list-badge',
596
+ badge.text
597
+ );
598
+ element.dataset.tone = badge.tone ?? '';
599
+ element.style.cssText =
600
+ 'height:20px;font-size:12px;line-height:16px;padding:2px 8px;border-radius:4px;box-sizing:border-box';
601
+ applyTextWeight(element, 500);
602
+ if (badge.tone === 'neutral')
603
+ Object.assign(element.style, {
604
+ background: 'var(--nl-strong)',
605
+ color: 'var(--nl-secondary)',
606
+ });
607
+ if (badge.tone === 'warning')
608
+ Object.assign(element.style, {
609
+ background:
610
+ 'var(--nl-caution-background,color-mix(in srgb,var(--nl-caution) 12%,transparent))',
611
+ color: 'var(--nl-caution)',
612
+ });
613
+ v.badges.append(element);
614
+ }
615
+ v.badges.style.display = row.badges?.length ? 'flex' : 'none';
616
+ v.description.style.cssText =
617
+ ellipsis +
618
+ 'display:flex;max-width:100%;color:var(--nl-secondary);font-family:inherit;font-size:14px;line-height:20px;font-weight:400;font-variant-numeric:tabular-nums;';
619
+ applyTextWeight(v.description, 400);
620
+ const split = row.description?.indexOf(' • ') ?? -1;
621
+ v.descriptionTime.textContent =
622
+ split >= 0 ? row.description!.slice(0, split) : '';
623
+ v.descriptionTime.style.display = split >= 0 ? 'inline' : 'none';
624
+ v.descriptionTime.style.flexShrink = '0';
625
+ v.descriptionDot.style.cssText = `flex-shrink:0;margin:0 4px;display:${
626
+ split >= 0 ? 'inline' : 'none'
627
+ }`;
628
+ v.descriptionAddress.style.cssText =
629
+ ellipsis +
630
+ 'appearance:none;display:block;max-width:100%;border:0;padding:0;background:transparent;text-align:left;color:inherit;font:inherit;font-variant-numeric:inherit;';
631
+ v.descriptionAddress.textContent =
632
+ split >= 0 ? row.description!.slice(split + 3) : row.description ?? '';
633
+ v.description.style.display = row.description ? 'flex' : 'none';
634
+ v.descriptionAddress.tabIndex = row.descriptionActionKey ? 0 : -1;
635
+ if (row.descriptionActionKey) {
636
+ v.descriptionAddress.dataset.nativeListAction = row.descriptionActionKey;
637
+ markActionAnchorSource(v.descriptionAddress, 'description');
638
+ v.descriptionAddress.style.cursor = 'pointer';
639
+ } else {
640
+ delete v.descriptionAddress.dataset.nativeListAction;
641
+ delete v.descriptionAddress.dataset.nativeListAnchorSource;
642
+ v.descriptionAddress.style.cursor = 'inherit';
643
+ }
644
+ if (row.style?.description)
645
+ primitives.textStyle(v.description, row.style.description);
646
+ v.description.style.display = row.description ? 'flex' : 'none';
647
+ Object.assign(v.amounts.style, {
648
+ display: 'flex',
649
+ flexDirection: 'column',
650
+ minWidth: '0',
651
+ gap: table ? '4px' : '0',
652
+ flex: table ? '1 1 0' : '0 1 auto',
653
+ maxWidth: table ? '50%' : '50%',
654
+ alignItems: table ? 'stretch' : 'flex-end',
655
+ alignSelf: table ? 'stretch' : 'center',
656
+ });
657
+ const amountKeys = new Set<string>();
658
+ for (const amount of row.amounts ?? []) {
659
+ amountKeys.add(amount.key);
660
+ let view = v.amountRows.get(amount.key);
661
+ if (!view) {
662
+ const element = createElement(body.ownerDocument, 'div');
663
+ const primary = tagSlot(
664
+ createElement(body.ownerDocument, 'span'),
665
+ 'primaryAmount'
666
+ );
667
+ const secondary = tagSlot(
668
+ createElement(body.ownerDocument, 'span'),
669
+ 'secondaryAmount'
670
+ );
671
+ element.append(primary, secondary);
672
+ view = { element, primary, secondary, visualKey: '' };
673
+ v.amountRows.set(amount.key, view);
674
+ }
675
+ view.element.style.cssText = `display:flex;align-items:center;gap:4px;min-width:0;max-width:100%;${
676
+ table ? '' : 'justify-content:flex-end;'
677
+ }`;
678
+ const secondary = amount.tone === 'secondary';
679
+ const size = table || secondary ? 14 : 16;
680
+ const line = table || secondary ? 20 : 24;
681
+ const weight = table || secondary ? 400 : 500;
682
+ view.primary.style.cssText =
683
+ ellipsis +
684
+ `font-size:${size}px;line-height:${line}px;font-weight:${weight};color:${
685
+ amount.tone === 'positive'
686
+ ? 'var(--nl-positive)'
687
+ : amount.tone === 'negative'
688
+ ? 'var(--nl-negative)'
689
+ : secondary
690
+ ? 'var(--nl-secondary)'
691
+ : 'var(--nl-primary)'
692
+ };`;
693
+ valueText(
694
+ view.primary,
695
+ amount.text,
696
+ amount.textSegments,
697
+ size,
698
+ line,
699
+ weight
700
+ );
701
+ const roleStyle = secondary
702
+ ? row.style?.secondaryAmount
703
+ : row.style?.primaryAmount;
704
+ if (roleStyle) primitives.textStyle(view.primary, roleStyle);
705
+ view.secondary.style.cssText =
706
+ ellipsis +
707
+ 'font-size:14px;line-height:20px;font-weight:400;color:var(--nl-secondary);';
708
+ valueText(
709
+ view.secondary,
710
+ amount.secondaryText,
711
+ amount.secondaryTextSegments,
712
+ 14,
713
+ 20,
714
+ 400
715
+ );
716
+ view.secondary.hidden = !table || !amount.secondaryText;
717
+ const amountVisualKey = JSON.stringify(table ? amount.leading : undefined);
718
+ if (view.visualKey !== amountVisualKey) {
719
+ if (view.visual) {
720
+ primitives.dispose(view.visual);
721
+ view.visual.remove();
722
+ }
723
+ view.visual = table ? primitives.visual(amount.leading) : undefined;
724
+ if (view.visual) {
725
+ new RowVisualStyle(view.visual).apply(
726
+ { width: 20, height: 20 },
727
+ 20,
728
+ 20,
729
+ 0
730
+ );
731
+ historyIcon(view.visual, amount.leading, 16);
732
+ if (amount.leading?.kind === 'token' && amount.leading.image) {
733
+ view.visual.style.border = amount.leading.borderColor
734
+ ? `1px solid ${amount.leading.borderColor}`
735
+ : '0';
736
+ view.visual.style.boxSizing = 'border-box';
737
+ }
738
+ view.element.prepend(view.visual);
739
+ }
740
+ view.visualKey = amountVisualKey;
741
+ }
742
+ v.amounts.append(view.element);
743
+ }
744
+ for (const [key, view] of v.amountRows) {
745
+ if (!amountKeys.has(key)) {
746
+ if (view.visual) primitives.dispose(view.visual);
747
+ view.element.remove();
748
+ v.amountRows.delete(key);
749
+ }
750
+ }
751
+ v.fee.style.cssText =
752
+ 'display:flex;flex-direction:column;flex:.6 1 0;min-width:0;gap:4px';
753
+ v.fee.hidden = !table || !row.fee;
754
+ v.fee.style.display = table && row.fee ? 'flex' : 'none';
755
+ v.fee.style.opacity = row.fee?.hidden ? '0' : '1';
756
+ v.feeLabel.style.cssText =
757
+ 'font-size:14px;line-height:20px;color:var(--nl-secondary);';
758
+ v.feeLabel.textContent = row.fee?.label ?? '';
759
+ applyTextWeight(v.feeLabel, 400);
760
+ v.feeValues.style.cssText =
761
+ 'display:flex;align-items:center;gap:4px;min-width:0';
762
+ v.feePrimary.style.cssText =
763
+ ellipsis + 'font-size:14px;line-height:20px;font-weight:400;';
764
+ v.feeSecondary.style.cssText =
765
+ ellipsis +
766
+ 'font-size:14px;line-height:20px;font-weight:400;color:var(--nl-secondary);';
767
+ valueText(
768
+ v.feePrimary,
769
+ row.fee?.primary,
770
+ row.fee?.primaryTextSegments,
771
+ 14,
772
+ 20,
773
+ 400
774
+ );
775
+ valueText(
776
+ v.feeSecondary,
777
+ row.fee?.secondary,
778
+ row.fee?.secondaryTextSegments,
779
+ 14,
780
+ 20,
781
+ 400
782
+ );
783
+ v.actions.style.cssText = `display:flex;gap:12px;padding-left:${
784
+ row.hideLeading ? 0 : 52
785
+ }px;padding-bottom:4px;`;
786
+ v.actions.style.display = footer ? 'flex' : 'none';
787
+ const actionKeys = new Set<string>();
788
+ for (const [index, action] of (row.footerActions ?? []).entries()) {
789
+ actionKeys.add(action.key);
790
+ let button = v.actionButtons.get(action.key);
791
+ if (!button) {
792
+ button = createElement(
793
+ body.ownerDocument,
794
+ 'button',
795
+ 'ok-native-list-action-button'
796
+ ) as HTMLButtonElement;
797
+ button.type = 'button';
798
+ v.actionButtons.set(action.key, button);
799
+ }
800
+ if (button.textContent !== action.label) button.textContent = action.label;
801
+ button.toggleAttribute('disabled', Boolean(action.disabled));
802
+ button.dataset.nativeListAction = action.key;
803
+ markActionAnchorSource(button, 'footerAction', index);
804
+ button.style.cssText =
805
+ 'font-family:inherit;font-size:14px;line-height:20px;font-weight:500;padding:4px 10px;border:1px solid transparent;border-radius:8px;background:var(--nl-strong);color:var(--nl-primary);white-space:nowrap;';
806
+ applyTextWeight(button, 500);
807
+ if (action.tone === 'primary')
808
+ Object.assign(button.style, {
809
+ background: 'var(--nl-primary)',
810
+ color: 'var(--nl-inverse-text)',
811
+ });
812
+ if (v.actions.children[index] !== button)
813
+ v.actions.insertBefore(button, v.actions.children[index] ?? null);
814
+ }
815
+ for (const [key, button] of v.actionButtons) {
816
+ if (!actionKeys.has(key)) {
817
+ button.remove();
818
+ v.actionButtons.delete(key);
819
+ }
820
+ }
821
+ }
822
+ function recycle(body: HTMLElement) {
823
+ const v = histories.get(body);
824
+ if (v) {
825
+ Array.from(v.visual.children).forEach((n) =>
826
+ v.primitives.dispose(n as HTMLElement)
827
+ );
828
+ for (const view of v.amountRows.values())
829
+ if (view.visual) v.primitives.dispose(view.visual);
830
+ histories.delete(body);
831
+ }
832
+ recycleLegacy(body);
833
+ views.delete(body);
834
+ }
835
+ function bind(body: HTMLElement, row: ActivityRow, primitives: RowPrimitives) {
836
+ if (isHistory(row)) {
837
+ if (views.has(body)) {
838
+ recycleLegacy(body);
839
+ views.delete(body);
840
+ }
841
+ bindHistory(body, row, primitives);
842
+ } else {
843
+ if (histories.has(body)) recycle(body);
844
+ if (!views.has(body)) {
845
+ const initial = createLegacy(body.ownerDocument, row, primitives);
846
+ body.replaceChildren(...Array.from(initial.childNodes));
847
+ body.className = initial.className;
848
+ views.set(body, views.get(initial)!);
849
+ views.delete(initial);
850
+ }
851
+ bindLegacy(body, row, primitives);
852
+ }
853
+ }
854
+ function create(
855
+ document: Document,
856
+ row: ActivityRow,
857
+ primitives: RowPrimitives
858
+ ) {
859
+ const body = document.createElement('div');
860
+ body.dataset.nlRenderer = 'activity';
861
+ bind(body, row, primitives);
862
+ return body;
863
+ }
148
864
  export const activityRowRenderer = {
149
865
  key: 'activity' as const,
150
866
  create,
151
867
  bind,
152
868
  recycle,
153
- measure: (row: ActivityRow, _width: number) =>
154
- row.footerActions?.length ? 100 : 60,
869
+ measure: (row: ActivityRow, _width: number) => {
870
+ if (!isHistory(row)) return row.footerActions?.length ? 100 : 60;
871
+ const extra =
872
+ row.presentation === 'table'
873
+ ? Math.max(0, (row.amounts?.length ?? 0) - 2) * 24
874
+ : 0;
875
+ if (row.footerActions?.length)
876
+ return (row.presentation === 'table' ? 68 : 60) + extra + 42;
877
+ return 68 + extra;
878
+ },
155
879
  measureRendered: (
156
880
  _body: HTMLElement,
157
881
  _row: ActivityRow