elseware-ui 2.36.4 → 2.36.5

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.mjs CHANGED
@@ -21046,10 +21046,10 @@ var getDefaultErrorMessage = (error) => {
21046
21046
  if (error instanceof Error) return error.message;
21047
21047
  if (typeof error === "object") {
21048
21048
  const anyErr = error;
21049
- if (anyErr?.data?.message && typeof anyErr.data.message === "string") {
21049
+ if (typeof anyErr?.data?.message === "string") {
21050
21050
  return anyErr.data.message;
21051
21051
  }
21052
- if (anyErr?.message && typeof anyErr.message === "string") {
21052
+ if (typeof anyErr?.message === "string") {
21053
21053
  return anyErr.message;
21054
21054
  }
21055
21055
  if (anyErr?.status) {
@@ -21065,20 +21065,107 @@ var getDefaultErrorMessage = (error) => {
21065
21065
  };
21066
21066
  function AsyncComponentWrapper({
21067
21067
  children,
21068
- isLoading,
21069
- isSuccess = true,
21070
- isError,
21068
+ isLoading = false,
21069
+ isFetching = false,
21070
+ isSuccess,
21071
+ isError = false,
21072
+ isUninitialized = false,
21071
21073
  error,
21072
- errorFormatter
21074
+ isEmpty = false,
21075
+ loadingText = "Loading...",
21076
+ fetchingText = "Updating...",
21077
+ emptyText = "No data available.",
21078
+ loadingType = "spinner",
21079
+ skeletonCount = 3,
21080
+ skeletonClassName = "h-24 w-full rounded-md",
21081
+ spinnerProps,
21082
+ fetchingSpinnerProps,
21083
+ loadingFallback,
21084
+ emptyFallback,
21085
+ errorFallback,
21086
+ showFetchingIndicator = true,
21087
+ onRetry,
21088
+ errorFormatter,
21089
+ className,
21090
+ contentClassName
21073
21091
  }) {
21074
- const errorMessage = isError && error ? errorFormatter ? errorFormatter(error) : getDefaultErrorMessage(error) : void 0;
21075
- return /* @__PURE__ */ jsxs("div", { children: [
21076
- isLoading && /* @__PURE__ */ jsx("div", { className: "flex w-full py-10 items-center justify-center", children: /* @__PURE__ */ jsx(AiOutlineLoading, { className: "animate-spin" }) }),
21077
- isError && errorMessage && /* @__PURE__ */ jsx("div", { className: "p-5", children: /* @__PURE__ */ jsx(FormResponse_default, { text: errorMessage, variant: "danger" }) }),
21078
- !isLoading && !isError && isSuccess && /* @__PURE__ */ jsx("div", { children })
21092
+ const errorMessage = useMemo(() => {
21093
+ if (!isError) return "";
21094
+ return errorFormatter ? errorFormatter(error) : getDefaultErrorMessage(error);
21095
+ }, [isError, error, errorFormatter]);
21096
+ const hasSuccess = isSuccess ?? (!isLoading && !isError && !isUninitialized);
21097
+ const renderLoading = () => {
21098
+ if (loadingFallback) return loadingFallback;
21099
+ if (loadingType === "skeleton") {
21100
+ return /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3 py-4", children: Array.from({ length: skeletonCount }).map((_, index) => /* @__PURE__ */ jsx(Skeleton, { className: skeletonClassName }, index)) });
21101
+ }
21102
+ return /* @__PURE__ */ jsx(
21103
+ Spinner_default,
21104
+ {
21105
+ centered: true,
21106
+ label: loadingText,
21107
+ type: "border",
21108
+ size: "md",
21109
+ variant: "primary",
21110
+ ...spinnerProps
21111
+ }
21112
+ );
21113
+ };
21114
+ const renderError = () => {
21115
+ if (typeof errorFallback === "function") {
21116
+ return errorFallback(errorMessage);
21117
+ }
21118
+ if (errorFallback) {
21119
+ return errorFallback;
21120
+ }
21121
+ return /* @__PURE__ */ jsxs("div", { className: "p-5", children: [
21122
+ /* @__PURE__ */ jsx(FormResponse_default, { text: errorMessage, variant: "danger" }),
21123
+ onRetry && /* @__PURE__ */ jsx(
21124
+ "button",
21125
+ {
21126
+ type: "button",
21127
+ onClick: onRetry,
21128
+ className: "mt-3 rounded-md border px-4 py-2",
21129
+ children: "Retry"
21130
+ }
21131
+ )
21132
+ ] });
21133
+ };
21134
+ const renderEmpty = () => {
21135
+ if (emptyFallback) return emptyFallback;
21136
+ return /* @__PURE__ */ jsx("div", { className: "py-10 text-center text-gray-500", children: emptyText });
21137
+ };
21138
+ if (isLoading) {
21139
+ return /* @__PURE__ */ jsx("div", { className, "aria-live": "polite", children: renderLoading() });
21140
+ }
21141
+ if (isError) {
21142
+ return /* @__PURE__ */ jsx("div", { className, "aria-live": "polite", children: renderError() });
21143
+ }
21144
+ if (hasSuccess && isEmpty) {
21145
+ return /* @__PURE__ */ jsx("div", { className, "aria-live": "polite", children: renderEmpty() });
21146
+ }
21147
+ if (!hasSuccess) {
21148
+ return null;
21149
+ }
21150
+ return /* @__PURE__ */ jsxs("div", { className, children: [
21151
+ showFetchingIndicator && isFetching && /* @__PURE__ */ jsxs("div", { className: "mb-3 flex items-center gap-2 text-sm text-gray-500", children: [
21152
+ /* @__PURE__ */ jsx(
21153
+ Spinner_default,
21154
+ {
21155
+ size: "xs",
21156
+ type: "border",
21157
+ variant: "primary",
21158
+ showLabel: false,
21159
+ ariaLabel: fetchingText,
21160
+ ...fetchingSpinnerProps
21161
+ }
21162
+ ),
21163
+ /* @__PURE__ */ jsx("span", { children: fetchingText })
21164
+ ] }),
21165
+ /* @__PURE__ */ jsx("div", { className: cn(contentClassName), children })
21079
21166
  ] });
21080
21167
  }
21081
- var AsyncComponentWrapper_default = AsyncComponentWrapper;
21168
+ var AsyncComponentWrapper_default = React2.memo(AsyncComponentWrapper);
21082
21169
  function Modal({
21083
21170
  title,
21084
21171
  show = false,