@onekeyfe/react-native-native-list 6.7.0-57 → 6.7.0-59

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.
@@ -168,9 +168,10 @@ type HistoryViews = {
168
168
  title: HTMLElement;
169
169
  badges: HTMLElement;
170
170
  description: HTMLElement;
171
- descriptionTime: HTMLElement;
172
- descriptionDot: HTMLElement;
173
- descriptionAddress: HTMLButtonElement;
171
+ /** Description text before the action, or nothing. */
172
+ descriptionPrefix: HTMLElement;
173
+ /** Description text that opens the action; the whole text without one. */
174
+ descriptionAction: HTMLButtonElement;
174
175
  amounts: HTMLElement;
175
176
  amountRows: Map<string, AmountViews>;
176
177
  fee: HTMLElement;
@@ -196,6 +197,8 @@ const isHistory = (row: ActivityRow) =>
196
197
  row.presentation !== undefined || row.amounts !== undefined;
197
198
  const ellipsis =
198
199
  'min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;';
200
+ /** Width a description prefix always leaves for the action text after it. */
201
+ const descriptionActionReserve = '3em';
199
202
  function valueText(
200
203
  node: HTMLElement,
201
204
  text: string | undefined,
@@ -221,14 +224,13 @@ function createHistory(body: HTMLElement, primitives: RowPrimitives) {
221
224
  const badges = node('badges');
222
225
  const description = node('description');
223
226
  description.dataset.nlSlot = 'description';
224
- const descriptionTime = createElement(document, 'span');
225
- const descriptionDot = createElement(document, 'span', undefined, '•');
226
- const descriptionAddress = createElement(
227
+ const descriptionPrefix = createElement(document, 'span');
228
+ const descriptionAction = createElement(
227
229
  document,
228
230
  'button'
229
231
  ) as HTMLButtonElement;
230
- descriptionAddress.type = 'button';
231
- description.append(descriptionTime, descriptionDot, descriptionAddress);
232
+ descriptionAction.type = 'button';
233
+ description.append(descriptionPrefix, descriptionAction);
232
234
  const amounts = node('amounts');
233
235
  const fee = node('fee');
234
236
  const feeLabel = node('fee-label');
@@ -252,9 +254,8 @@ function createHistory(body: HTMLElement, primitives: RowPrimitives) {
252
254
  title,
253
255
  badges,
254
256
  description,
255
- descriptionTime,
256
- descriptionDot,
257
- descriptionAddress,
257
+ descriptionPrefix,
258
+ descriptionAction,
258
259
  amounts,
259
260
  amountRows: new Map(),
260
261
  fee,
@@ -579,29 +580,38 @@ function bindHistory(
579
580
  ellipsis +
580
581
  '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;';
581
582
  applyTextWeight(v.description, 400);
582
- const split = row.description?.indexOf(' • ') ?? -1;
583
- v.descriptionTime.textContent =
584
- split >= 0 ? row.description!.slice(0, split) : '';
585
- v.descriptionTime.style.display = split >= 0 ? 'inline' : 'none';
586
- v.descriptionTime.style.flexShrink = '0';
587
- v.descriptionDot.style.cssText = `flex-shrink:0;margin:0 4px;display:${
588
- split >= 0 ? 'inline' : 'none'
589
- }`;
590
- v.descriptionAddress.style.cssText =
591
- ellipsis +
592
- 'appearance:none;display:block;max-width:100%;border:0;padding:0;background:transparent;text-align:left;color:inherit;font:inherit;font-variant-numeric:inherit;';
593
- v.descriptionAddress.textContent =
594
- split >= 0 ? row.description!.slice(split + 3) : row.description ?? '';
583
+ // The caller states where the action text starts; the string is not parsed.
584
+ const description = row.description ?? '';
585
+ const actionStart = row.descriptionActionKey
586
+ ? Math.min(Math.max(row.descriptionActionStart ?? 0, 0), description.length)
587
+ : 0;
588
+ const actionText = description.slice(actionStart);
589
+ const boundAction =
590
+ row.descriptionActionKey && actionText ? row.descriptionActionKey : '';
591
+ // `pre` keeps the space a prefix ends with; a line break stays a space.
592
+ v.descriptionPrefix.textContent = description
593
+ .slice(0, actionStart)
594
+ .replace(/\r\n|[\r\n]/g, ' ');
595
+ // The prefix keeps its width and the action truncates first, as the tail of
596
+ // the one native label does. A prefix wider than the row is capped instead,
597
+ // or it would squeeze the action to nothing and leave no pointer target.
598
+ v.descriptionPrefix.style.cssText = `${ellipsis}flex-shrink:0;max-width:${
599
+ actionText ? `calc(100% - ${descriptionActionReserve})` : '100%'
600
+ };white-space:pre;display:${actionStart > 0 ? 'block' : 'none'}`;
601
+ v.descriptionAction.style.cssText = `${ellipsis}appearance:none;max-width:100%;border:0;padding:0;background:transparent;text-align:left;color:inherit;font:inherit;font-variant-numeric:inherit;display:${
602
+ actionText ? 'block' : 'none'
603
+ };`;
604
+ v.descriptionAction.textContent = actionText;
595
605
  v.description.style.display = row.description ? 'flex' : 'none';
596
- v.descriptionAddress.tabIndex = row.descriptionActionKey ? 0 : -1;
597
- if (row.descriptionActionKey) {
598
- v.descriptionAddress.dataset.nativeListAction = row.descriptionActionKey;
599
- markActionAnchorSource(v.descriptionAddress, 'description');
600
- v.descriptionAddress.style.cursor = 'pointer';
606
+ v.descriptionAction.tabIndex = boundAction ? 0 : -1;
607
+ if (boundAction) {
608
+ v.descriptionAction.dataset.nativeListAction = boundAction;
609
+ markActionAnchorSource(v.descriptionAction, 'description');
610
+ v.descriptionAction.style.cursor = 'pointer';
601
611
  } else {
602
- delete v.descriptionAddress.dataset.nativeListAction;
603
- delete v.descriptionAddress.dataset.nativeListAnchorSource;
604
- v.descriptionAddress.style.cursor = 'inherit';
612
+ delete v.descriptionAction.dataset.nativeListAction;
613
+ delete v.descriptionAction.dataset.nativeListAnchorSource;
614
+ v.descriptionAction.style.cursor = 'inherit';
605
615
  }
606
616
  if (row.style?.description)
607
617
  primitives.textStyle(v.description, row.style.description);