@sesionario/blocks 1.31.0 → 1.31.1

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/dist/index.js CHANGED
@@ -1142,6 +1142,9 @@ function useZoomPanGestures(options = {}) {
1142
1142
  clearSnapBack
1143
1143
  };
1144
1144
  }
1145
+ function isBrokenImage(img) {
1146
+ return img.complete && img.naturalWidth === 0;
1147
+ }
1145
1148
  function SafeImage({
1146
1149
  src,
1147
1150
  fallback,
@@ -1150,10 +1153,17 @@ function SafeImage({
1150
1153
  ...imgProps
1151
1154
  }) {
1152
1155
  const [failed, setFailed] = useState(false);
1156
+ const imgRef = useRef(null);
1153
1157
  const resolvedSrc = typeof src === "string" && src.length > 0 ? src : null;
1154
- useEffect(() => {
1158
+ useLayoutEffect(() => {
1155
1159
  setFailed(false);
1156
1160
  }, [resolvedSrc]);
1161
+ useLayoutEffect(() => {
1162
+ const img = imgRef.current;
1163
+ if (img && isBrokenImage(img)) {
1164
+ setFailed(true);
1165
+ }
1166
+ }, [resolvedSrc, failed]);
1157
1167
  if (!resolvedSrc || failed) {
1158
1168
  return /* @__PURE__ */ jsx(Fragment, { children: fallback });
1159
1169
  }
@@ -1161,6 +1171,7 @@ function SafeImage({
1161
1171
  "img",
1162
1172
  {
1163
1173
  ...imgProps,
1174
+ ref: imgRef,
1164
1175
  src: resolvedSrc,
1165
1176
  alt,
1166
1177
  onError: (event) => {
@@ -2110,23 +2121,27 @@ function TenantAvatar({
2110
2121
  }) {
2111
2122
  const sizeClass = size === "sm" ? "size-6" : "size-8";
2112
2123
  const textClass = size === "sm" ? "text-xs" : "text-sm";
2113
- return /* @__PURE__ */ jsx(
2124
+ const initials = getInitials(name);
2125
+ return /* @__PURE__ */ jsxs(
2114
2126
  "div",
2115
2127
  {
2116
2128
  className: cn(
2117
- "flex shrink-0 items-center justify-center overflow-hidden rounded-full font-medium",
2129
+ "relative flex shrink-0 items-center justify-center overflow-hidden rounded-full font-medium",
2118
2130
  sizeClass
2119
2131
  ),
2120
2132
  style: avatarFallbackStyle(name),
2121
- children: /* @__PURE__ */ jsx(
2122
- SafeImage,
2123
- {
2124
- src: logo,
2125
- alt: "",
2126
- className: "size-full object-cover",
2127
- fallback: /* @__PURE__ */ jsx("span", { className: textClass, children: getInitials(name) })
2128
- }
2129
- )
2133
+ children: [
2134
+ /* @__PURE__ */ jsx("span", { className: textClass, children: initials }),
2135
+ logo ? /* @__PURE__ */ jsx(
2136
+ SafeImage,
2137
+ {
2138
+ src: logo,
2139
+ alt: "",
2140
+ className: "absolute inset-0 size-full object-cover",
2141
+ fallback: null
2142
+ }
2143
+ ) : null
2144
+ ]
2130
2145
  }
2131
2146
  );
2132
2147
  }
@@ -2646,30 +2661,26 @@ function MenuAvatar({
2646
2661
  sizeClass
2647
2662
  }) {
2648
2663
  const initials = getInitials(name);
2649
- const initialsFallback = /* @__PURE__ */ jsx(
2650
- "span",
2651
- {
2652
- className: "flex size-full items-center justify-center text-xs font-semibold",
2653
- style: avatarFallbackStyle(name),
2654
- children: initials
2655
- }
2656
- );
2657
- return /* @__PURE__ */ jsx(
2664
+ return /* @__PURE__ */ jsxs(
2658
2665
  "span",
2659
2666
  {
2660
2667
  className: cn(
2661
2668
  "relative flex shrink-0 overflow-hidden rounded-full",
2662
2669
  sizeClass
2663
2670
  ),
2664
- children: /* @__PURE__ */ jsx(
2665
- SafeImage,
2666
- {
2667
- src: image,
2668
- alt: "",
2669
- className: "aspect-square size-full object-cover",
2670
- fallback: initialsFallback
2671
- }
2672
- )
2671
+ style: avatarFallbackStyle(name),
2672
+ children: [
2673
+ /* @__PURE__ */ jsx("span", { className: "flex size-full items-center justify-center text-xs font-semibold", children: initials }),
2674
+ image ? /* @__PURE__ */ jsx(
2675
+ SafeImage,
2676
+ {
2677
+ src: image,
2678
+ alt: "",
2679
+ className: "absolute inset-0 aspect-square size-full object-cover",
2680
+ fallback: null
2681
+ }
2682
+ ) : null
2683
+ ]
2673
2684
  }
2674
2685
  );
2675
2686
  }