@alfadocs/ui-kit 1.22.0 → 1.23.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.
@@ -0,0 +1,90 @@
1
+ var h = Object.defineProperty;
2
+ var u = (n, e, r) => e in n ? h(n, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : n[e] = r;
3
+ var i = (n, e, r) => u(n, typeof e != "symbol" ? e + "" : e, r);
4
+ import { jsx as a, Fragment as y } from "react/jsx-runtime";
5
+ import { Component as f } from "react";
6
+ import { useTranslation as v } from "react-i18next";
7
+ import { E } from "./empty-state-X0sVPfVo.js";
8
+ function p({
9
+ size: n,
10
+ title: e,
11
+ description: r,
12
+ onRetry: o
13
+ }) {
14
+ const { t } = v();
15
+ return /* @__PURE__ */ a(
16
+ E,
17
+ {
18
+ variant: "error",
19
+ size: n,
20
+ ...e === void 0 ? {} : { title: e },
21
+ ...r === void 0 ? {} : { description: r },
22
+ ...o === void 0 ? {} : {
23
+ primaryAction: {
24
+ label: t("emptyState.error.cta"),
25
+ onClick: o
26
+ }
27
+ }
28
+ }
29
+ );
30
+ }
31
+ p.displayName = "ErrorBoundaryFallback";
32
+ class b extends f {
33
+ constructor() {
34
+ super(...arguments);
35
+ i(this, "state", { error: null });
36
+ i(this, "reset", () => {
37
+ this.setState({ error: null });
38
+ });
39
+ i(this, "handleRetry", () => {
40
+ var r, o;
41
+ (o = (r = this.props).onRetry) == null || o.call(r), this.reset();
42
+ });
43
+ }
44
+ static getDerivedStateFromError(r) {
45
+ return { error: r };
46
+ }
47
+ componentDidCatch(r, o) {
48
+ var t, s;
49
+ (s = (t = this.props).onError) == null || s.call(t, r, o);
50
+ }
51
+ /**
52
+ * A changed key clears the error. Compared by identity and in order, so a
53
+ * host passing a fresh array of the same values does not re-render into the
54
+ * same failure forever.
55
+ *
56
+ * `previousState` is load-bearing. React commits the caught error as an
57
+ * ordinary update, so the first `componentDidUpdate` after a catch still sees
58
+ * the props from the last HEALTHY commit. When the prop change is itself what
59
+ * crashed the child — `resetKeys={[patientId]}` around something that throws
60
+ * on the new patient, which is the documented use — the keys have moved, and
61
+ * without this guard the boundary would clear on the very commit that caught
62
+ * and render straight back into the failure. It settles on the second catch,
63
+ * but the subtree renders twice and `onError` fires twice for one crash.
64
+ */
65
+ componentDidUpdate(r, o) {
66
+ if (this.state.error === null || o.error === null) return;
67
+ const t = r.resetKeys, s = this.props.resetKeys;
68
+ if (t === void 0 || s === void 0) return;
69
+ (t.length !== s.length || s.some((l, d) => !Object.is(l, t[d]))) && this.reset();
70
+ }
71
+ render() {
72
+ const { error: r } = this.state, { children: o, fallback: t, title: s, description: c, onRetry: l, size: d } = this.props;
73
+ if (r === null) return /* @__PURE__ */ a(y, { children: o });
74
+ const m = typeof t == "function" ? t({ error: r, reset: this.handleRetry }) : t !== void 0 ? t : /* @__PURE__ */ a(
75
+ p,
76
+ {
77
+ size: d,
78
+ title: s,
79
+ description: c,
80
+ ...l === void 0 ? {} : { onRetry: this.handleRetry }
81
+ }
82
+ );
83
+ return /* @__PURE__ */ a("div", { "data-component": "error-boundary", children: m });
84
+ }
85
+ }
86
+ i(b, "displayName", "ErrorBoundary");
87
+ export {
88
+ b as E
89
+ };
90
+ //# sourceMappingURL=error-boundary-ayXFCcq4.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "packageVersion": "1.22.0",
3
+ "packageVersion": "1.23.0",
4
4
  "components": [
5
5
  {
6
6
  "kind": "component",
@@ -4612,6 +4612,20 @@
4612
4612
  }
4613
4613
  }
4614
4614
  },
4615
+ {
4616
+ "kind": "component",
4617
+ "id": "error-boundary",
4618
+ "capabilities": [],
4619
+ "state": [],
4620
+ "actions": [],
4621
+ "domHooks": {
4622
+ "root": {
4623
+ "attr": "data-component",
4624
+ "value": "error-boundary",
4625
+ "description": "Wraps whatever the boundary shows once it has caught — the default face or a host fallback alike. Present only after a catch, so its absence means the tree below is healthy."
4626
+ }
4627
+ }
4628
+ },
4615
4629
  {
4616
4630
  "kind": "component",
4617
4631
  "id": "face-scheme",
@@ -0,0 +1,88 @@
1
+ import { Component, type ErrorInfo, type ReactNode } from 'react';
2
+ /** What the boundary caught, handed to a render-prop fallback. */
3
+ export interface ErrorBoundaryState {
4
+ error: Error;
5
+ /**
6
+ * Runs `onRetry` if the host gave one, then clears the error and re-renders
7
+ * the children — the same call the default face's action makes, so a host
8
+ * that replaces the face does not silently lose its own recovery.
9
+ */
10
+ reset: () => void;
11
+ }
12
+ export interface ErrorBoundaryProps {
13
+ children?: ReactNode;
14
+ /**
15
+ * Replaces the default face. A function receives the error and a `reset`,
16
+ * so a host can offer its own recovery instead of a reload.
17
+ */
18
+ fallback?: ReactNode | ((state: ErrorBoundaryState) => ReactNode);
19
+ /** Report the crash — logging, telemetry, a support channel. */
20
+ onError?: (error: Error, info: ErrorInfo) => void;
21
+ /**
22
+ * Clear the error when any of these change, so a route change or a new
23
+ * record recovers without the user pressing anything.
24
+ */
25
+ resetKeys?: readonly unknown[];
26
+ /** Overrides for the default face; each falls back to the kit's own copy. */
27
+ title?: string;
28
+ description?: string;
29
+ /**
30
+ * Shown as the face's action, and run by a render-prop's `reset` too.
31
+ *
32
+ * Called BEFORE the boundary clears. That is enough for a synchronous
33
+ * recovery — a state flip, a cache clear. It is NOT enough on its own for an
34
+ * async one: the boundary clears on the next line, so a refetch that has not
35
+ * resolved re-renders into the same failure. Pair an async recovery with
36
+ * `resetKeys`, so the settled data is what clears the error.
37
+ */
38
+ onRetry?: () => void;
39
+ size?: 'sm' | 'md' | 'lg';
40
+ }
41
+ /**
42
+ * Catches a render error below it and shows the kit's error face instead of
43
+ * unmounting the tree to a blank page.
44
+ *
45
+ * A CLASS COMPONENT, by sanctioned exception — see
46
+ * `src/docs/23-constraints.mdx` §9. React 18 exposes `getDerivedStateFromError`
47
+ * and `componentDidCatch` on classes only; there is no hook form, and no
48
+ * function component can catch a descendant's render error. The exception is
49
+ * this file, and it is the reason the kit had no boundary at all.
50
+ *
51
+ * It catches RENDER errors. An event handler, a timeout or a rejected promise
52
+ * never reaches it — React does not route those through a boundary — so a host
53
+ * still handles its own async failures.
54
+ */
55
+ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
56
+ error: Error | null;
57
+ }> {
58
+ static displayName: string;
59
+ state: {
60
+ error: Error | null;
61
+ };
62
+ static getDerivedStateFromError(error: Error): {
63
+ error: Error;
64
+ };
65
+ componentDidCatch(error: Error, info: ErrorInfo): void;
66
+ /**
67
+ * A changed key clears the error. Compared by identity and in order, so a
68
+ * host passing a fresh array of the same values does not re-render into the
69
+ * same failure forever.
70
+ *
71
+ * `previousState` is load-bearing. React commits the caught error as an
72
+ * ordinary update, so the first `componentDidUpdate` after a catch still sees
73
+ * the props from the last HEALTHY commit. When the prop change is itself what
74
+ * crashed the child — `resetKeys={[patientId]}` around something that throws
75
+ * on the new patient, which is the documented use — the keys have moved, and
76
+ * without this guard the boundary would clear on the very commit that caught
77
+ * and render straight back into the failure. It settles on the second catch,
78
+ * but the subtree renders twice and `onError` fires twice for one crash.
79
+ */
80
+ componentDidUpdate(previous: ErrorBoundaryProps, previousState: {
81
+ error: Error | null;
82
+ }): void;
83
+ reset: () => void;
84
+ handleRetry: () => void;
85
+ render(): import("react/jsx-runtime").JSX.Element;
86
+ }
87
+ export { ErrorBoundary };
88
+ //# sourceMappingURL=error-boundary.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { ErrorBoundary } from './error-boundary';
2
+ export type { ErrorBoundaryProps, ErrorBoundaryState } from './error-boundary';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ import { E as a } from "../../_chunks/error-boundary-ayXFCcq4.js";
2
+ export {
3
+ a as ErrorBoundary
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -116,6 +116,7 @@ export * from './appointment-card';
116
116
  export * from './appointment-timeline';
117
117
  export * from './dialog';
118
118
  export * from './dropdown-menu';
119
+ export * from './error-boundary';
119
120
  export * from './finished-terminal';
120
121
  export * from './info-tip';
121
122
  export * from './live-region';