@doist/reactist 31.2.0 → 32.0.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,3 +1,19 @@
1
+ ## [32.0.0](https://github.com/Doist/reactist/compare/v31.3.0...v32.0.0) (2026-05-28)
2
+
3
+ ### ⚠ BREAKING CHANGES
4
+
5
+ - Revamped Avatar component (#1048)
6
+
7
+ ### Features
8
+
9
+ - Revamped Avatar component ([#1048](https://github.com/Doist/reactist/issues/1048)) ([fbf1e54](https://github.com/Doist/reactist/commit/fbf1e54f17d965912edac24d6ca049bf4c5d756a))
10
+
11
+ ## [31.3.0](https://github.com/Doist/reactist/compare/v31.2.0...v31.3.0) (2026-05-28)
12
+
13
+ ### Features
14
+
15
+ - **tooltip:** expose `--reactist-tooltip-font-size` custom property ([#1049](https://github.com/Doist/reactist/issues/1049)) ([65811a3](https://github.com/Doist/reactist/commit/65811a36bf3e3de2e34867254af876101bf9c284))
16
+
1
17
  ## [31.2.0](https://github.com/Doist/reactist/compare/v31.1.0...v31.2.0) (2026-05-20)
2
18
 
3
19
  ### Features
@@ -598,7 +598,7 @@ function Spinner(t0) {
598
598
  return t3;
599
599
  }
600
600
 
601
- var modules_95f1407a = {"tooltip":"_487c82cd"};
601
+ var modules_95f1407a = {"tooltip":"_64d17ef6"};
602
602
 
603
603
  const defaultShowTimeout = 500;
604
604
  const defaultHideTimeout = 100;
@@ -4483,132 +4483,296 @@ function useAutoExpand(t0) {
4483
4483
  React__namespace.useEffect(t3, t4);
4484
4484
  }
4485
4485
 
4486
+ /**
4487
+ * Supported avatar sizes, in CSS pixels.
4488
+ */
4489
+
4490
+ /**
4491
+ * Supported avatar clipping shapes.
4492
+ */
4493
+
4494
+ /**
4495
+ * Avatar image source.
4496
+ *
4497
+ * Use a string for a single image URL, or a source map keyed by intrinsic image width. Source maps
4498
+ * are converted to native `srcSet` width descriptors.
4499
+ */
4500
+
4501
+ const AVATAR_META_COLOR_COUNT = 20;
4502
+ const WHITESPACE_REGEXP = new RegExp('\\p{White_Space}+', 'gu');
4503
+ const GRAPHEME_SEGMENTER = typeof Intl !== 'undefined' && 'Segmenter' in Intl ? new Intl.Segmenter('und', {
4504
+ granularity: 'grapheme'
4505
+ }) : undefined;
4506
+ function normalizeAvatarName(name) {
4507
+ return name?.normalize('NFC').trim().replace(WHITESPACE_REGEXP, ' ') ?? '';
4508
+ }
4509
+ function getGraphemeClusters(value) {
4510
+ if (GRAPHEME_SEGMENTER) {
4511
+ return Array.from(GRAPHEME_SEGMENTER.segment(value), ({
4512
+ segment
4513
+ }) => segment);
4514
+ }
4515
+ return Array.from(value);
4516
+ }
4517
+ function getInitialGrapheme(value) {
4518
+ return getGraphemeClusters(value?.toUpperCase() ?? '')[0] ?? '';
4519
+ }
4486
4520
  function getInitials(name) {
4487
- if (!name) {
4521
+ const nameParts = normalizeAvatarName(name).split(' ').filter(Boolean);
4522
+ if (nameParts.length === 0) {
4488
4523
  return '';
4489
4524
  }
4490
- const seed = name.trim().split(' ');
4491
- const firstInitial = seed[0];
4492
- const lastInitial = seed[seed.length - 1];
4493
- let initials = firstInitial?.[0];
4494
- if (firstInitial != null && lastInitial != null && initials != null &&
4495
- // Better readable this way.
4496
- // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
4497
- firstInitial[0] !== lastInitial[0]) {
4498
- initials += lastInitial[0];
4499
- }
4500
- return initials?.toUpperCase();
4525
+ if (nameParts.length === 1) {
4526
+ return getGraphemeClusters(nameParts[0].toUpperCase()).slice(0, 2).join('');
4527
+ }
4528
+ return `${getInitialGrapheme(nameParts[0])}${getInitialGrapheme(nameParts[nameParts.length - 1])}`;
4501
4529
  }
4502
- function emailToIndex(email, maxIndex) {
4503
- const seed = email.split('@')[0];
4504
- const hash = seed ? seed.charCodeAt(0) + seed.charCodeAt(seed.length - 1) || 0 : 0;
4505
- return hash % maxIndex;
4530
+ function getSortedImageSources(image) {
4531
+ return Object.entries(image).map(([sourceSize, src]) => ({
4532
+ sourceSize: Number(sourceSize),
4533
+ src
4534
+ })).filter(({
4535
+ sourceSize,
4536
+ src
4537
+ }) => Number.isFinite(sourceSize) && sourceSize > 0 && src).sort((a, b) => a.sourceSize - b.sourceSize);
4506
4538
  }
4507
-
4508
- var modules_08f3eeac = {"avatar":"_38a1be89","size-xxs":"d32e92ae","size-xs":"_0667d719","size-s":"cf529fcf","size-m":"_6e268eab","size-l":"d64c62cf","size-xl":"_44fb77de","size-xxl":"_01f85e0e","size-xxxl":"_41a5fe19","tablet-size-xxs":"_6ab1577d","tablet-size-xs":"b52a4963","tablet-size-s":"_714a8419","tablet-size-m":"_81cd4d51","tablet-size-l":"bf0a4edb","tablet-size-xl":"e4f0dabd","tablet-size-xxl":"_67ea065d","tablet-size-xxxl":"_2af7f76f","desktop-size-xxs":"_759081dc","desktop-size-xs":"_8290d1c1","desktop-size-s":"_48ea172d","desktop-size-m":"_758f6641","desktop-size-l":"f9ada088","desktop-size-xl":"d3bb7470","desktop-size-xxl":"_9a312ee3","desktop-size-xxxl":"a1d30c23"};
4509
-
4510
- const AVATAR_COLORS = ['#fcc652', '#e9952c', '#e16b2d', '#d84b40', '#e8435a', '#e5198a', '#ad3889', '#86389c', '#a8a8a8', '#98be2f', '#5d9d50', '#5f9f85', '#5bbcb6', '#32a3bf', '#2bafeb', '#2d88c3', '#3863cc', '#5e5e5e'];
4511
- function Avatar(t0) {
4512
- const $ = reactCompilerRuntime.c(26);
4513
- let avatarUrl;
4514
- let className;
4515
- let exceptionallySetClassName;
4516
- let props;
4517
- let t1;
4518
- let t2;
4519
- let user;
4520
- if ($[0] !== t0) {
4521
- ({
4522
- user,
4523
- avatarUrl,
4524
- size: t1,
4525
- className,
4526
- colorList: t2,
4527
- exceptionallySetClassName,
4528
- ...props
4529
- } = t0);
4530
- $[0] = t0;
4531
- $[1] = avatarUrl;
4532
- $[2] = className;
4533
- $[3] = exceptionallySetClassName;
4534
- $[4] = props;
4535
- $[5] = t1;
4536
- $[6] = t2;
4537
- $[7] = user;
4538
- } else {
4539
- avatarUrl = $[1];
4540
- className = $[2];
4541
- exceptionallySetClassName = $[3];
4542
- props = $[4];
4543
- t1 = $[5];
4544
- t2 = $[6];
4545
- user = $[7];
4539
+ function getImagePropsFromSources(sources, sizes) {
4540
+ if (sources.length === 0) {
4541
+ return undefined;
4546
4542
  }
4547
- const size = t1 === undefined ? "l" : t1;
4548
- const colorList = t2 === undefined ? AVATAR_COLORS : t2;
4549
- let t3;
4550
- if ($[8] !== user.email || $[9] !== user.name) {
4551
- t3 = getInitials(user.name) || getInitials(user.email);
4552
- $[8] = user.email;
4553
- $[9] = user.name;
4554
- $[10] = t3;
4555
- } else {
4556
- t3 = $[10];
4543
+ return {
4544
+ src: sources[sources.length - 1].src,
4545
+ srcSet: sources.map(({
4546
+ sourceSize,
4547
+ src
4548
+ }) => `${src} ${sourceSize}w`).join(', '),
4549
+ sizes,
4550
+ sources
4551
+ };
4552
+ }
4553
+ function getSources(image, size) {
4554
+ if (!image) {
4555
+ return undefined;
4557
4556
  }
4558
- const userInitials = t3;
4559
- const avatarSize = size ? size : "l";
4560
- let t4;
4561
- if ($[11] !== avatarUrl || $[12] !== colorList || $[13] !== user.email) {
4562
- t4 = avatarUrl ? {
4563
- backgroundImage: `url(${avatarUrl})`,
4564
- textIndent: "-9999px"
4565
- } : {
4566
- backgroundColor: colorList[emailToIndex(user.email, colorList.length)]
4557
+ if (typeof image === 'string') {
4558
+ return {
4559
+ src: image
4567
4560
  };
4568
- $[11] = avatarUrl;
4569
- $[12] = colorList;
4570
- $[13] = user.email;
4571
- $[14] = t4;
4572
- } else {
4573
- t4 = $[14];
4574
4561
  }
4575
- const style = t4;
4576
- let t5;
4577
- if ($[15] !== avatarSize) {
4578
- t5 = getClassNames(modules_08f3eeac, "size", avatarSize);
4579
- $[15] = avatarSize;
4580
- $[16] = t5;
4581
- } else {
4582
- t5 = $[16];
4562
+ const sources = getSortedImageSources(image);
4563
+ return getImagePropsFromSources(sources, `${size}px`);
4564
+ }
4565
+ function getAvatarImageIdentityKey(image) {
4566
+ if (!image) {
4567
+ return 'fallback';
4583
4568
  }
4584
- const sizeClassName = t5;
4585
- let t6;
4586
- if ($[17] !== className || $[18] !== exceptionallySetClassName || $[19] !== sizeClassName) {
4587
- t6 = [className, modules_08f3eeac.avatar, sizeClassName, exceptionallySetClassName];
4588
- $[17] = className;
4589
- $[18] = exceptionallySetClassName;
4590
- $[19] = sizeClassName;
4591
- $[20] = t6;
4569
+ if (typeof image === 'string') {
4570
+ return image;
4571
+ }
4572
+ const sources = getSortedImageSources(image);
4573
+ if (sources.length === 0) {
4574
+ return 'fallback';
4575
+ }
4576
+ return sources.map(({
4577
+ sourceSize,
4578
+ src
4579
+ }) => `${sourceSize}:${src}`).join('|');
4580
+ }
4581
+ function getAvailableImageSources(imageProps, failedSources) {
4582
+ if (!imageProps) {
4583
+ return undefined;
4584
+ }
4585
+ if (failedSources.length === 0) {
4586
+ return imageProps;
4587
+ }
4588
+ if (!imageProps.sources) {
4589
+ return failedSources.includes(imageProps.src) ? undefined : imageProps;
4590
+ }
4591
+ return getImagePropsFromSources(imageProps.sources.filter(({
4592
+ src
4593
+ }) => !failedSources.includes(src)), imageProps.sizes);
4594
+ }
4595
+ function getAvatarMetaColorIndex(name) {
4596
+ const normalizedName = normalizeAvatarName(name);
4597
+ let hash = 0;
4598
+ for (const char of normalizedName) {
4599
+ hash = hash * 31 + (char.codePointAt(0) ?? 0) >>> 0;
4600
+ }
4601
+ return hash % AVATAR_META_COLOR_COUNT;
4602
+ }
4603
+
4604
+ var modules_08f3eeac = {"avatar":"acf9ee3d","size-80":"_5b32f21b","size-72":"_5dd2ceae","size-62":"_0737423f","size-50":"_47744c53","size-40":"_087775aa","size-36":"_02c89bce","size-30":"_3ed61ce0","size-28":"c9fa2651","size-24":"_89506d0e","size-20":"d7ab9fd7","size-18":"_32fef877","size-16":"_8962c0a0","size-12":"a06fa349","initials":"_80b6bfbf","meta-color-0":"_64da0562","meta-color-1":"ee7c29c0","meta-color-2":"_70215fb1","meta-color-3":"_488b23cd","meta-color-4":"f6b3e824","meta-color-5":"_88b828ae","meta-color-6":"f931ad92","meta-color-7":"_504e515a","meta-color-8":"_277cc6cd","meta-color-9":"db85100e","meta-color-10":"c76af5ed","meta-color-11":"ab7368dc","meta-color-12":"c2a85a75","meta-color-13":"_0e942ae0","meta-color-14":"_2f79016f","meta-color-15":"_118f815d","meta-color-16":"_6e5574e6","meta-color-17":"_49d688e7","meta-color-18":"d5233bf3","meta-color-19":"_710699d5","shape-circle":"_2b4e8069","shape-rounded":"_28fdd710","image":"bda7eadb"};
4605
+
4606
+ /**
4607
+ * Props for the `Avatar` component.
4608
+ */
4609
+
4610
+ /**
4611
+ * Displays an avatar from an image URL, a source map keyed by intrinsic
4612
+ * image width, or initials derived from the provided name (with a background
4613
+ * color).
4614
+ */
4615
+ const Avatar = polymorphicComponent(function Avatar({
4616
+ as,
4617
+ size,
4618
+ shape = 'circle',
4619
+ name,
4620
+ image,
4621
+ alt,
4622
+ exceptionallySetClassName,
4623
+ 'data-testid': testId,
4624
+ 'aria-hidden': ariaHidden,
4625
+ 'aria-label': ariaLabel,
4626
+ ...restProps
4627
+ }, ref) {
4628
+ const label = getAvatarLabel({
4629
+ alt,
4630
+ name,
4631
+ 'aria-label': ariaLabel
4632
+ });
4633
+ const isDecorative = Boolean(ariaHidden ?? label === '');
4634
+ return /*#__PURE__*/React__namespace.createElement(Box$1, _extends__default["default"]({
4635
+ as: as,
4636
+ ref: ref,
4637
+ className: classNames__default["default"](modules_08f3eeac.avatar, modules_08f3eeac[`size-${size}`], modules_08f3eeac[`shape-${shape}`], exceptionallySetClassName),
4638
+ "data-testid": testId,
4639
+ display: "inlineFlex",
4640
+ alignItems: "center",
4641
+ justifyContent: "center",
4642
+ flexShrink: 0,
4643
+ overflow: "hidden",
4644
+ textAlign: "center"
4645
+ }, restProps), /*#__PURE__*/React__namespace.createElement(AvatarImage
4646
+ // Allows `AvatarImage` to remount when the image map changes,
4647
+ // which resets error states without replacing the avatar root.
4648
+ , {
4649
+ key: getAvatarImageIdentityKey(image),
4650
+ size: size,
4651
+ name: name,
4652
+ image: image,
4653
+ label: label,
4654
+ "aria-hidden": isDecorative
4655
+ }));
4656
+ });
4657
+ function getAvatarLabel({
4658
+ alt,
4659
+ name,
4660
+ 'aria-label': ariaLabel
4661
+ }) {
4662
+ return ariaLabel ?? alt ?? normalizeAvatarName(name);
4663
+ }
4664
+ function AvatarImage(t0) {
4665
+ const $ = reactCompilerRuntime.c(22);
4666
+ const {
4667
+ size,
4668
+ name,
4669
+ image,
4670
+ label,
4671
+ "aria-hidden": ariaHidden
4672
+ } = t0;
4673
+ const imageSources = getSources(image, size);
4674
+ let t1;
4675
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
4676
+ t1 = [];
4677
+ $[0] = t1;
4592
4678
  } else {
4593
- t6 = $[20];
4679
+ t1 = $[0];
4594
4680
  }
4595
- let t7;
4596
- if ($[21] !== props || $[22] !== style || $[23] !== t6 || $[24] !== userInitials) {
4597
- t7 = /*#__PURE__*/React__namespace.createElement(Box$1, _extends__default["default"]({
4598
- className: t6,
4599
- style: style
4600
- }, props), userInitials);
4601
- $[21] = props;
4602
- $[22] = style;
4603
- $[23] = t6;
4604
- $[24] = userInitials;
4605
- $[25] = t7;
4681
+ const [failedImageSources, setFailedImageSources] = React__namespace.useState(t1);
4682
+ const availableImageSources = getAvailableImageSources(imageSources, failedImageSources);
4683
+ let t2;
4684
+ if ($[1] !== availableImageSources || $[2] !== name) {
4685
+ t2 = availableImageSources ? "" : getInitials(name);
4686
+ $[1] = availableImageSources;
4687
+ $[2] = name;
4688
+ $[3] = t2;
4606
4689
  } else {
4607
- t7 = $[25];
4690
+ t2 = $[3];
4608
4691
  }
4609
- return t7;
4692
+ const initials = t2;
4693
+ const hasInitials = initials !== "";
4694
+ if (availableImageSources) {
4695
+ let t3;
4696
+ if ($[4] !== availableImageSources || $[5] !== setFailedImageSources) {
4697
+ t3 = event => {
4698
+ const failedSource = getFailedImageSource(availableImageSources, event.currentTarget);
4699
+ setFailedImageSources(currentFailedSources => currentFailedSources.includes(failedSource) ? currentFailedSources : [...currentFailedSources, failedSource]);
4700
+ };
4701
+ $[4] = availableImageSources;
4702
+ $[5] = setFailedImageSources;
4703
+ $[6] = t3;
4704
+ } else {
4705
+ t3 = $[6];
4706
+ }
4707
+ let t4;
4708
+ if ($[7] !== ariaHidden || $[8] !== availableImageSources.sizes || $[9] !== availableImageSources.src || $[10] !== availableImageSources.srcSet || $[11] !== label || $[12] !== t3) {
4709
+ t4 = /*#__PURE__*/React__namespace.createElement("img", {
4710
+ className: modules_08f3eeac.image,
4711
+ src: availableImageSources.src,
4712
+ srcSet: availableImageSources.srcSet,
4713
+ sizes: availableImageSources.sizes,
4714
+ alt: label,
4715
+ "aria-hidden": ariaHidden,
4716
+ onError: t3
4717
+ });
4718
+ $[7] = ariaHidden;
4719
+ $[8] = availableImageSources.sizes;
4720
+ $[9] = availableImageSources.src;
4721
+ $[10] = availableImageSources.srcSet;
4722
+ $[11] = label;
4723
+ $[12] = t3;
4724
+ $[13] = t4;
4725
+ } else {
4726
+ t4 = $[13];
4727
+ }
4728
+ return t4;
4729
+ }
4730
+ if (hasInitials) {
4731
+ const t3 = modules_08f3eeac[`meta-color-${getAvatarMetaColorIndex(name)}`];
4732
+ let t4;
4733
+ if ($[14] !== t3) {
4734
+ t4 = classNames__default["default"](modules_08f3eeac.initials, t3);
4735
+ $[14] = t3;
4736
+ $[15] = t4;
4737
+ } else {
4738
+ t4 = $[15];
4739
+ }
4740
+ const t5 = label ? "img" : undefined;
4741
+ let t6;
4742
+ if ($[16] !== ariaHidden || $[17] !== initials || $[18] !== label || $[19] !== t4 || $[20] !== t5) {
4743
+ t6 = /*#__PURE__*/React__namespace.createElement("div", {
4744
+ className: t4,
4745
+ role: t5,
4746
+ "aria-label": label,
4747
+ "aria-hidden": ariaHidden
4748
+ }, initials);
4749
+ $[16] = ariaHidden;
4750
+ $[17] = initials;
4751
+ $[18] = label;
4752
+ $[19] = t4;
4753
+ $[20] = t5;
4754
+ $[21] = t6;
4755
+ } else {
4756
+ t6 = $[21];
4757
+ }
4758
+ return t6;
4759
+ }
4760
+ return null;
4761
+ }
4762
+ function getAbsoluteImageSource(src, image) {
4763
+ try {
4764
+ return new URL(src, image.ownerDocument.baseURI).href;
4765
+ } catch {
4766
+ return src;
4767
+ }
4768
+ }
4769
+ function getFailedImageSource(imageProps, image) {
4770
+ const failedSrc = image.currentSrc || image.src || imageProps.src;
4771
+ const matchingSource = imageProps.sources?.find(({
4772
+ src
4773
+ }) => src === failedSrc || getAbsoluteImageSource(src, image) === failedSrc);
4774
+ return matchingSource?.src ?? imageProps.src;
4610
4775
  }
4611
- Avatar.displayName = 'Avatar';
4612
4776
 
4613
4777
  var modules_33c7c985 = {"badge":"_2714fc40","badge-info":"_3397e001","badge-positive":"b7b8944a","badge-promote":"bfc2b0e9","badge-attention":"d45e594f","badge-warning":"_1e30e9b3"};
4614
4778