@onekeyfe/react-native-native-list 6.7.0-alpha.398 → 6.7.0-alpha.400

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.
@@ -61,10 +61,9 @@ import {
61
61
  type NormalizedPositionScroll,
62
62
  } from '../scrolling';
63
63
  import {
64
- applyRowPatches,
64
+ applyValidatedRowPatches,
65
65
  containNativeListInput,
66
66
  emptyNativeListSnapshot,
67
- validatePatches,
68
67
  validateSnapshot,
69
68
  } from '../validation';
70
69
  import { avatarPrefetchWindow } from '../avatarPrefetch';
@@ -3199,13 +3198,9 @@ export class NativeListWebEngine {
3199
3198
  }
3200
3199
 
3201
3200
  applyPatches(patches: readonly RowPatch[]) {
3202
- const accepted = containNativeListInput(() => {
3203
- const normalized = validatePatches(patches);
3204
- return {
3205
- patches: normalized,
3206
- snapshot: applyRowPatches(this.snapshot, normalized),
3207
- };
3208
- });
3201
+ const accepted = containNativeListInput(() =>
3202
+ applyValidatedRowPatches(this.snapshot, patches)
3203
+ );
3209
3204
  if (!accepted || accepted.patches.length === 0) return;
3210
3205
  patches = accepted.patches;
3211
3206
  const next = accepted.snapshot;
@@ -3214,7 +3209,8 @@ export class NativeListWebEngine {
3214
3209
  const selected =
3215
3210
  'selected' in patch.changes ? patch.changes.selected : undefined;
3216
3211
  if (selected === true) selection.add(patch.key);
3217
- else if (selected === false) selection.delete(patch.key);
3212
+ else if (selected === false || selected === null)
3213
+ selection.delete(patch.key);
3218
3214
  });
3219
3215
  const tableValuesOnly = patches.every((patch) => {
3220
3216
  const index = this.rows.findIndex((row) => row.key === patch.key);
@@ -226,7 +226,7 @@ function createIdentityRow(
226
226
  });
227
227
  column.insertBefore(segments, titleElement.nextSibling);
228
228
  }
229
- if (row.titleIcon || row.secondaryTitleIcon) {
229
+ if (row.titleIcon || row.secondaryTitleIcon || row.titleImage) {
230
230
  const badgeLine = titleElement.querySelector<HTMLElement>(
231
231
  ':scope > .ok-native-list-badges'
232
232
  );
@@ -258,6 +258,45 @@ function createIdentityRow(
258
258
  else icon.setAttribute('aria-hidden', 'true');
259
259
  return icon;
260
260
  });
261
+ if (row.titleImage) {
262
+ const descriptor = row.titleImage;
263
+ const holder = createElement(
264
+ document,
265
+ 'span',
266
+ 'ok-native-list-identity-title-image'
267
+ );
268
+ Object.assign(holder.style, {
269
+ flex: `0 0 ${descriptor.image.width}px`,
270
+ width: `${descriptor.image.width}px`,
271
+ height: `${descriptor.image.height}px`,
272
+ borderRadius: '50%',
273
+ overflow: 'hidden',
274
+ });
275
+ const image = primitives.thumbnail(descriptor.image);
276
+ if (image) {
277
+ Object.assign(image.style, {
278
+ width: '100%',
279
+ height: '100%',
280
+ borderRadius: 'inherit',
281
+ objectFit:
282
+ descriptor.image.contentFit === 'center'
283
+ ? 'none'
284
+ : descriptor.image.contentFit ?? 'cover',
285
+ });
286
+ image.setAttribute('alt', '');
287
+ holder.appendChild(image);
288
+ }
289
+ if (descriptor.hoverActionKey) {
290
+ setData(holder, 'nativeListHoverAction', descriptor.hoverActionKey);
291
+ setData(holder, 'nativeListIconHelp', true);
292
+ markActionAnchorSource(holder, 'leadingAction');
293
+ }
294
+ if (descriptor.accessibilityLabel) {
295
+ holder.setAttribute('role', 'img');
296
+ holder.setAttribute('aria-label', descriptor.accessibilityLabel);
297
+ } else holder.setAttribute('aria-hidden', 'true');
298
+ icons.push(holder);
299
+ }
261
300
  titleText.after(...icons);
262
301
  titleElement.style.display = 'flex';
263
302
  titleElement.style.alignItems = 'center';
@@ -300,7 +339,9 @@ function createIdentityRow(
300
339
  label.style.flex = '0 1 auto';
301
340
  label.style.minWidth = '0';
302
341
  label.style.marginInlineStart =
303
- row.titleIcon || row.secondaryTitleIcon ? '4px' : '8px';
342
+ row.titleIcon || row.secondaryTitleIcon || row.titleImage
343
+ ? '4px'
344
+ : '8px';
304
345
  label.style.maxWidth =
305
346
  suffix.maxWidth === undefined ? '' : `${suffix.maxWidth}px`;
306
347
  label.style.overflow = 'hidden';
@@ -317,7 +358,12 @@ function createIdentityRow(
317
358
  titleElement.insertBefore(label, badges);
318
359
  });
319
360
  }
320
- if (row.badges?.length && !row.titleIcon && !row.secondaryTitleIcon) {
361
+ if (
362
+ row.badges?.length &&
363
+ !row.titleIcon &&
364
+ !row.secondaryTitleIcon &&
365
+ !row.titleImage
366
+ ) {
321
367
  const titleText = titleElement.querySelector<HTMLElement>(
322
368
  ':scope > [data-nl-slot="title"]'
323
369
  );
@@ -513,6 +559,7 @@ type Views = {
513
559
  node: HTMLElement;
514
560
  defaults: RowVisualStyle;
515
561
  };
562
+ titleImage?: { key: string; node: HTMLElement };
516
563
  primitives: RowPrimitives;
517
564
  };
518
565
  const views = new WeakMap<HTMLElement, Views>();
@@ -520,10 +567,21 @@ function bind(body: HTMLElement, row: IdentityRow, primitives: RowPrimitives) {
520
567
  const v = views.get(body)!;
521
568
  v.primitives = primitives;
522
569
  let used = false;
570
+ let usedTitleImage = false;
523
571
  const next = createIdentityRow(
524
572
  body.ownerDocument,
525
573
  {
526
574
  ...primitives,
575
+ thumbnail: (source) => {
576
+ usedTitleImage = true;
577
+ const key = JSON.stringify([row.key, source]);
578
+ if (v.titleImage?.key !== key) {
579
+ if (v.titleImage) primitives.dispose(v.titleImage.node);
580
+ const node = primitives.thumbnail(source);
581
+ v.titleImage = node ? { key, node } : undefined;
582
+ }
583
+ return v.titleImage?.node;
584
+ },
527
585
  visual: (source, presentation) => {
528
586
  used = true;
529
587
  const key = JSON.stringify([row.key, source, presentation]);
@@ -550,6 +608,10 @@ function bind(body: HTMLElement, row: IdentityRow, primitives: RowPrimitives) {
550
608
  primitives.dispose(v.visual.node);
551
609
  v.visual = undefined;
552
610
  }
611
+ if (!usedTitleImage && v.titleImage) {
612
+ primitives.dispose(v.titleImage.node);
613
+ v.titleImage = undefined;
614
+ }
553
615
  body.replaceChildren(...Array.from(next.childNodes));
554
616
  body.className = next.className;
555
617
  body.style.cssText = next.style.cssText;
@@ -640,7 +702,11 @@ function create(
640
702
  function recycle(body: HTMLElement) {
641
703
  const v = views.get(body);
642
704
  if (v?.visual) v.primitives.dispose(v.visual.node);
643
- if (v) v.visual = undefined;
705
+ if (v?.titleImage) v.primitives.dispose(v.titleImage.node);
706
+ if (v) {
707
+ v.visual = undefined;
708
+ v.titleImage = undefined;
709
+ }
644
710
  body.replaceChildren();
645
711
  }
646
712
  export const identityRowRenderer = {