@atom63/widgets 0.1.0-beta.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,236 @@
1
+ import { WidgetCard, WidgetCardHeader, WidgetCardTitle, WidgetCardContent, WidgetBlock, WidgetBlockFooter } from '../chunk-US2CE3BV.js';
2
+ import { cn, widgetTypeStyle, widgetInsetStyle } from '../chunk-F5NV6XJ5.js';
3
+ import { LoaderCircle, AlertCircle, RefreshCw } from 'lucide-react';
4
+ import { jsx, jsxs } from 'react/jsx-runtime';
5
+ import { useReducedMotion, AnimatePresence, motion } from 'motion/react';
6
+ import { useRef, useLayoutEffect } from 'react';
7
+ import { Button } from '@atom63/ui-react';
8
+
9
+ function WidgetContentFallback() {
10
+ return /* @__PURE__ */ jsx(
11
+ "output",
12
+ {
13
+ "aria-busy": "true",
14
+ className: "a63-WidgetContentFallback",
15
+ "data-slot": "widget-content-fallback",
16
+ children: /* @__PURE__ */ jsx(LoaderCircle, { "aria-hidden": true, className: "a63-WidgetContentFallback-icon a63-Widget-spin" })
17
+ }
18
+ );
19
+ }
20
+
21
+ // src/runtime/widget-host-transition-config.ts
22
+ var WIDGET_HOST_SIZE_TRANSITION_DURATION = 0.32;
23
+ var WIDGET_HOST_SIZE_TRANSITION_EASE = [0.5, 0, 0, 1];
24
+ var WIDGET_HOST_CROSSFADE_BLUR = "6px";
25
+ var widgetHostSizeMotionTransition = {
26
+ duration: WIDGET_HOST_SIZE_TRANSITION_DURATION,
27
+ ease: WIDGET_HOST_SIZE_TRANSITION_EASE
28
+ };
29
+ function shouldReduceWidgetHostMotion(reduceMotion) {
30
+ return reduceMotion === true;
31
+ }
32
+ function getWidgetHostCrossfadeMotion(phase, reduceMotion) {
33
+ if (shouldReduceWidgetHostMotion(reduceMotion)) {
34
+ return { filter: "none", opacity: 1 };
35
+ }
36
+ if (phase === "active") {
37
+ return { filter: "none", opacity: 1 };
38
+ }
39
+ return { filter: `blur(${WIDGET_HOST_CROSSFADE_BLUR})`, opacity: 0 };
40
+ }
41
+ function getWidgetHostSlideFadeMotion(phase, reduceMotion) {
42
+ if (shouldReduceWidgetHostMotion(reduceMotion) || phase === "active") {
43
+ return { opacity: 1 };
44
+ }
45
+ return { opacity: 0 };
46
+ }
47
+ function WidgetHostContentTransition({
48
+ children,
49
+ className,
50
+ contentClassName,
51
+ contentKey,
52
+ originClassName
53
+ }) {
54
+ const reduceMotion = useReducedMotion();
55
+ const slotRef = useRef(null);
56
+ const frozenExitWidthRef = useRef(null);
57
+ useLayoutEffect(() => {
58
+ frozenExitWidthRef.current = slotRef.current?.offsetWidth ?? null;
59
+ }, [contentKey]);
60
+ const prefersReducedMotion = shouldReduceWidgetHostMotion(reduceMotion);
61
+ const frozenExitWidth = frozenExitWidthRef.current;
62
+ return /* @__PURE__ */ jsx(
63
+ "div",
64
+ {
65
+ className: cn("a63-WidgetHostContentTransition", className),
66
+ "data-slot": "widget-host-content-transition",
67
+ ref: slotRef,
68
+ children: /* @__PURE__ */ jsx(AnimatePresence, { initial: false, mode: "sync", children: /* @__PURE__ */ jsx(
69
+ motion.div,
70
+ {
71
+ animate: {
72
+ ...getWidgetHostCrossfadeMotion("active", reduceMotion),
73
+ width: "100%"
74
+ },
75
+ className: cn("a63-WidgetHostContentTransition-layer", originClassName, contentClassName),
76
+ exit: {
77
+ ...getWidgetHostCrossfadeMotion("exit", reduceMotion),
78
+ width: frozenExitWidth ?? "100%"
79
+ },
80
+ initial: {
81
+ ...getWidgetHostCrossfadeMotion("enter", reduceMotion),
82
+ width: "100%"
83
+ },
84
+ style: {
85
+ willChange: prefersReducedMotion ? void 0 : "opacity, filter"
86
+ },
87
+ transition: prefersReducedMotion ? { duration: 0 } : widgetHostSizeMotionTransition,
88
+ children
89
+ },
90
+ contentKey
91
+ ) })
92
+ }
93
+ );
94
+ }
95
+
96
+ // src/runtime/widget-fill.ts
97
+ var WIDGET_FILL_STYLE = { blockSize: "100%", inlineSize: "100%" };
98
+ function WidgetHostErrorFallback({
99
+ message,
100
+ onRetry,
101
+ size,
102
+ title = "Widget failed to load"
103
+ }) {
104
+ return /* @__PURE__ */ jsx("div", { className: "a63-WidgetHostFallback", "data-slot": "widget-host-error-fallback", children: /* @__PURE__ */ jsxs(WidgetCard, { size, style: WIDGET_FILL_STYLE, children: [
105
+ /* @__PURE__ */ jsx(WidgetCardHeader, { children: /* @__PURE__ */ jsx(
106
+ WidgetCardTitle,
107
+ {
108
+ icon: /* @__PURE__ */ jsx(AlertCircle, { "aria-hidden": true, className: "a63-WidgetHostErrorFallback-icon" }),
109
+ children: title
110
+ }
111
+ ) }),
112
+ /* @__PURE__ */ jsxs(WidgetCardContent, { className: "a63-WidgetHostErrorFallback-content", children: [
113
+ message ? /* @__PURE__ */ jsx(
114
+ "p",
115
+ {
116
+ className: "a63-WidgetHostErrorFallback-message",
117
+ style: widgetTypeStyle("body", size),
118
+ children: message
119
+ }
120
+ ) : null,
121
+ onRetry ? /* @__PURE__ */ jsxs(Button, { onClick: onRetry, size: "sm", type: "button", variant: "ghost", children: [
122
+ /* @__PURE__ */ jsx(RefreshCw, { "aria-hidden": true }),
123
+ "Retry"
124
+ ] }) : null
125
+ ] })
126
+ ] }) });
127
+ }
128
+ function WidgetHostLoadingShell({
129
+ content,
130
+ size
131
+ }) {
132
+ return /* @__PURE__ */ jsx("div", { className: "a63-WidgetHostFallback", "data-slot": "widget-host-loading-shell", children: /* @__PURE__ */ jsx(WidgetCard, { size, style: WIDGET_FILL_STYLE, children: /* @__PURE__ */ jsx(WidgetCardContent, { className: "a63-WidgetHostLoadingShell-content", children: content ?? /* @__PURE__ */ jsx(WidgetContentFallback, {}) }) }) });
133
+ }
134
+ function WidgetHostOptionalHeader({
135
+ children,
136
+ visible
137
+ }) {
138
+ const reduceMotion = useReducedMotion();
139
+ const prefersReducedMotion = shouldReduceWidgetHostMotion(reduceMotion);
140
+ return /* @__PURE__ */ jsx(AnimatePresence, { initial: false, children: visible ? /* @__PURE__ */ jsx(
141
+ motion.div,
142
+ {
143
+ animate: prefersReducedMotion ? { height: "auto", opacity: 1 } : { height: "auto", opacity: 1 },
144
+ className: "a63-WidgetHostOptionalHeader",
145
+ "data-slot": "widget-host-optional-header",
146
+ exit: prefersReducedMotion ? { height: 0, opacity: 0 } : { height: 0, opacity: 0 },
147
+ initial: prefersReducedMotion ? { height: "auto", opacity: 1 } : { height: 0, opacity: 0 },
148
+ transition: prefersReducedMotion ? { duration: 0 } : widgetHostSizeMotionTransition,
149
+ children
150
+ },
151
+ "widget-host-optional-header"
152
+ ) : null });
153
+ }
154
+ function WidgetHostTitleTransition({
155
+ children,
156
+ className,
157
+ contentKey,
158
+ variant = "crossfade"
159
+ }) {
160
+ const reduceMotion = useReducedMotion();
161
+ const prefersReducedMotion = shouldReduceWidgetHostMotion(reduceMotion);
162
+ const slide = variant === "slide";
163
+ const phaseMotion = slide ? getWidgetHostSlideFadeMotion : getWidgetHostCrossfadeMotion;
164
+ return /* @__PURE__ */ jsx(
165
+ "div",
166
+ {
167
+ className: cn("a63-WidgetHostTitleTransition", className),
168
+ "data-slot": "widget-host-title-transition",
169
+ "data-variant": variant,
170
+ children: /* @__PURE__ */ jsx(AnimatePresence, { initial: false, mode: "sync", children: /* @__PURE__ */ jsx(
171
+ motion.div,
172
+ {
173
+ animate: phaseMotion("active", reduceMotion),
174
+ className: "a63-WidgetHostTitleTransition-layer",
175
+ exit: phaseMotion("exit", reduceMotion),
176
+ initial: phaseMotion("enter", reduceMotion),
177
+ layout: false,
178
+ style: {
179
+ willChange: prefersReducedMotion ? void 0 : slide ? "opacity" : "opacity, filter"
180
+ },
181
+ transition: prefersReducedMotion ? { duration: 0 } : widgetHostSizeMotionTransition,
182
+ children
183
+ },
184
+ contentKey
185
+ ) })
186
+ }
187
+ );
188
+ }
189
+ function WidgetHostedShell({
190
+ children,
191
+ className,
192
+ contentClassName,
193
+ contentKey,
194
+ contentSlotClassName,
195
+ footer,
196
+ header,
197
+ size,
198
+ style,
199
+ ...cardProps
200
+ }) {
201
+ const transition = /* @__PURE__ */ jsx(
202
+ WidgetHostContentTransition,
203
+ {
204
+ className: contentSlotClassName,
205
+ contentClassName,
206
+ contentKey,
207
+ children
208
+ }
209
+ );
210
+ return (
211
+ // A widget with a header reads as two anchored bands — title at the top,
212
+ // content settling against the bottom — so the slack lands BETWEEN them
213
+ // rather than under the content. A consumer `justify-*` utility in
214
+ // `className` still wins, for the widgets that ask for something else.
215
+ /* @__PURE__ */ jsxs(
216
+ WidgetCard,
217
+ {
218
+ className: cn(header && "a63-WidgetHostedShell-anchored", className),
219
+ size,
220
+ style: { ...WIDGET_FILL_STYLE, ...style },
221
+ ...cardProps,
222
+ children: [
223
+ header,
224
+ footer ? /* @__PURE__ */ jsxs(WidgetBlock, { style: widgetInsetStyle(size, header ? "body" : "face"), children: [
225
+ transition,
226
+ /* @__PURE__ */ jsx(WidgetBlockFooter, { children: footer })
227
+ ] }) : transition
228
+ ]
229
+ }
230
+ )
231
+ );
232
+ }
233
+
234
+ export { WIDGET_HOST_CROSSFADE_BLUR, WIDGET_HOST_SIZE_TRANSITION_DURATION, WIDGET_HOST_SIZE_TRANSITION_EASE, WidgetContentFallback, WidgetHostContentTransition, WidgetHostErrorFallback, WidgetHostLoadingShell, WidgetHostOptionalHeader, WidgetHostTitleTransition, WidgetHostedShell, getWidgetHostCrossfadeMotion, getWidgetHostSlideFadeMotion, shouldReduceWidgetHostMotion, widgetHostSizeMotionTransition };
235
+ //# sourceMappingURL=index.js.map
236
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/runtime/widget-content-fallback.tsx","../../src/runtime/widget-host-transition-config.ts","../../src/runtime/widget-host-content-transition.tsx","../../src/runtime/widget-fill.ts","../../src/runtime/widget-host-error-fallback.tsx","../../src/runtime/widget-host-loading-shell.tsx","../../src/runtime/widget-host-optional-header.tsx","../../src/runtime/widget-host-title-transition.tsx","../../src/runtime/widget-hosted-shell.tsx"],"names":["j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,MAAM,CAAA,EAChE,QAAA,EAAA;AAAA,YAAA,UAAA;AAAA,4BACDJ,GAAAA,CAAC,iBAAA,EAAA,EAAmB,QAAA,EAAA,MAAA,EAAO;AAAA,WAAA,EAC7B,CAAA,GAEA;AAAA;AAAA;AAAA;AAEJ;AAEJ","file":"index.js","sourcesContent":["import { LoaderCircle } from 'lucide-react'\n\n/** Shared centered spinner for widget content loading (module defer + data fetch). */\nexport function WidgetContentFallback() {\n return (\n <output\n aria-busy=\"true\"\n className=\"a63-WidgetContentFallback\"\n data-slot=\"widget-content-fallback\"\n >\n <LoaderCircle aria-hidden className=\"a63-WidgetContentFallback-icon a63-Widget-spin\" />\n </output>\n )\n}\n","/** Shell + content size transition duration (seconds) for widget resize + crossfade. */\nexport const WIDGET_HOST_SIZE_TRANSITION_DURATION = 0.32\n\nexport const WIDGET_HOST_SIZE_TRANSITION_EASE = [0.5, 0, 0, 1] as const\n\n/** Blur amount for hosted content/title crossfades — masks reflow during shell resize. */\nexport const WIDGET_HOST_CROSSFADE_BLUR = '6px'\n\n/** Shared motion transition for desktop shell resize and inner content crossfade. */\nexport const widgetHostSizeMotionTransition = {\n duration: WIDGET_HOST_SIZE_TRANSITION_DURATION,\n ease: WIDGET_HOST_SIZE_TRANSITION_EASE,\n} as const\n\ntype WidgetHostMotionPhase = 'active' | 'enter' | 'exit'\n\n/** Motion returns null when no reduced-motion preference is set — treat that as animated. */\nexport function shouldReduceWidgetHostMotion(reduceMotion: boolean | null): boolean {\n return reduceMotion === true\n}\n\n/**\n * Opacity + blur crossfade for inner widget content and title chrome.\n * Blur is applied on clipped inner layers only — not the widget card shell —\n * so themed backdrop-filter on the shell stays intact.\n *\n * The resting state is `none`, not `blur(0px)`. Any filter value other than\n * `none` establishes a backdrop root, which neutralises `backdrop-filter` on\n * everything below it — so a resting `blur(0px)` silently disables the blur\n * ramp inside widgets that put text over photography. `none` costs nothing at\n * rest and the animated phases still carry the blur.\n */\nexport function getWidgetHostCrossfadeMotion(\n phase: WidgetHostMotionPhase,\n reduceMotion: boolean | null\n) {\n if (shouldReduceWidgetHostMotion(reduceMotion)) {\n return { filter: 'none', opacity: 1 }\n }\n\n if (phase === 'active') {\n return { filter: 'none', opacity: 1 }\n }\n\n return { filter: `blur(${WIDGET_HOST_CROSSFADE_BLUR})`, opacity: 0 }\n}\n\n/**\n * Opacity-only swap for copy inside a locked height box (film title/year).\n * No blur (glyph bounds) and no translate — even a small `y` shifts the\n * visual mass of the line and reads as the text plate changing height.\n */\nexport function getWidgetHostSlideFadeMotion(\n phase: WidgetHostMotionPhase,\n reduceMotion: boolean | null\n) {\n if (shouldReduceWidgetHostMotion(reduceMotion) || phase === 'active') {\n return { opacity: 1 }\n }\n\n return { opacity: 0 }\n}\n","import { AnimatePresence, motion, useReducedMotion } from 'motion/react'\nimport { type ReactNode, useLayoutEffect, useRef } from 'react'\nimport { cn } from '../utils'\nimport {\n getWidgetHostCrossfadeMotion,\n shouldReduceWidgetHostMotion,\n widgetHostSizeMotionTransition,\n} from './widget-host-transition-config'\n\n/**\n * Crossfade inner widget content while the outer card shell stays mounted.\n *\n * Each layer grows from its top-start corner. `originClassName` adds a class\n * to the layer to change that (a consumer utility such as `origin-center`\n * outranks the stylesheet's default).\n */\nexport function WidgetHostContentTransition({\n children,\n className,\n contentClassName,\n contentKey,\n originClassName,\n}: {\n children: ReactNode\n className?: string\n contentClassName?: string\n contentKey: string\n originClassName?: string\n}) {\n const reduceMotion = useReducedMotion()\n const slotRef = useRef<HTMLDivElement>(null)\n const frozenExitWidthRef = useRef<number | null>(null)\n\n // contentKey is an intentional re-measure trigger — it freezes the outgoing slot width right before the content swaps, even though the effect body doesn't read it.\n useLayoutEffect(() => {\n frozenExitWidthRef.current = slotRef.current?.offsetWidth ?? null\n }, [contentKey])\n\n const prefersReducedMotion = shouldReduceWidgetHostMotion(reduceMotion)\n const frozenExitWidth = frozenExitWidthRef.current\n\n return (\n <div\n className={cn('a63-WidgetHostContentTransition', className)}\n data-slot=\"widget-host-content-transition\"\n ref={slotRef}\n >\n <AnimatePresence initial={false} mode=\"sync\">\n <motion.div\n animate={{\n ...getWidgetHostCrossfadeMotion('active', reduceMotion),\n width: '100%',\n }}\n className={cn('a63-WidgetHostContentTransition-layer', originClassName, contentClassName)}\n exit={{\n ...getWidgetHostCrossfadeMotion('exit', reduceMotion),\n width: frozenExitWidth ?? '100%',\n }}\n initial={{\n ...getWidgetHostCrossfadeMotion('enter', reduceMotion),\n width: '100%',\n }}\n key={contentKey}\n style={{\n willChange: prefersReducedMotion ? undefined : 'opacity, filter',\n }}\n transition={prefersReducedMotion ? { duration: 0 } : widgetHostSizeMotionTransition}\n >\n {children}\n </motion.div>\n </AnimatePresence>\n </div>\n )\n}\n","import type { CSSProperties } from 'react'\n\n/**\n * Fills the host box. Passed as `style`, which lands on the surface's outer\n * shell: the runtime shells size the widget itself, not its face.\n */\nexport const WIDGET_FILL_STYLE: CSSProperties = { blockSize: '100%', inlineSize: '100%' }\n","import { Button } from '@atom63/ui-react'\nimport { AlertCircle, RefreshCw } from 'lucide-react'\nimport { widgetTypeStyle } from '../layout'\nimport { WidgetCard, WidgetCardContent, WidgetCardHeader, WidgetCardTitle } from '../primitives'\nimport type { WidgetSize } from '../types'\nimport { WIDGET_FILL_STYLE } from './widget-fill'\n\n/** Widget card shell for runtime error boundaries (lazy load, render crash). */\nexport function WidgetHostErrorFallback({\n message,\n onRetry,\n size,\n title = 'Widget failed to load',\n}: {\n message?: string\n onRetry?: () => void\n size: WidgetSize\n title?: string\n}) {\n return (\n <div className=\"a63-WidgetHostFallback\" data-slot=\"widget-host-error-fallback\">\n <WidgetCard size={size} style={WIDGET_FILL_STYLE}>\n <WidgetCardHeader>\n <WidgetCardTitle\n icon={<AlertCircle aria-hidden className=\"a63-WidgetHostErrorFallback-icon\" />}\n >\n {title}\n </WidgetCardTitle>\n </WidgetCardHeader>\n <WidgetCardContent className=\"a63-WidgetHostErrorFallback-content\">\n {message ? (\n <p\n className=\"a63-WidgetHostErrorFallback-message\"\n style={widgetTypeStyle('body', size)}\n >\n {message}\n </p>\n ) : null}\n {onRetry ? (\n <Button onClick={onRetry} size=\"sm\" type=\"button\" variant=\"ghost\">\n <RefreshCw aria-hidden />\n Retry\n </Button>\n ) : null}\n </WidgetCardContent>\n </WidgetCard>\n </div>\n )\n}\n","import type { ReactNode } from 'react'\nimport { WidgetCard, WidgetCardContent } from '../primitives'\nimport type { WidgetSize } from '../types'\nimport { WidgetContentFallback } from './widget-content-fallback'\nimport { WIDGET_FILL_STYLE } from './widget-fill'\n\n/**\n * Card shell with a centered spinner only — no title (avoids header flash on\n * resolve). Takes the footprint it is standing in for, so the chrome it paints\n * while loading matches the chrome the widget paints once resolved.\n */\nexport function WidgetHostLoadingShell({\n content,\n size,\n}: {\n content?: ReactNode\n size: WidgetSize\n}) {\n return (\n <div className=\"a63-WidgetHostFallback\" data-slot=\"widget-host-loading-shell\">\n <WidgetCard size={size} style={WIDGET_FILL_STYLE}>\n <WidgetCardContent className=\"a63-WidgetHostLoadingShell-content\">\n {content ?? <WidgetContentFallback />}\n </WidgetCardContent>\n </WidgetCard>\n </div>\n )\n}\n","import { AnimatePresence, motion, useReducedMotion } from 'motion/react'\nimport type { ReactNode } from 'react'\nimport {\n shouldReduceWidgetHostMotion,\n widgetHostSizeMotionTransition,\n} from './widget-host-transition-config'\n\n/** Header slot that only exists on some sizes (e.g. profile small). */\nexport function WidgetHostOptionalHeader({\n children,\n visible,\n}: {\n children: ReactNode\n visible: boolean\n}) {\n const reduceMotion = useReducedMotion()\n const prefersReducedMotion = shouldReduceWidgetHostMotion(reduceMotion)\n\n return (\n <AnimatePresence initial={false}>\n {visible ? (\n <motion.div\n animate={\n prefersReducedMotion ? { height: 'auto', opacity: 1 } : { height: 'auto', opacity: 1 }\n }\n className=\"a63-WidgetHostOptionalHeader\"\n data-slot=\"widget-host-optional-header\"\n exit={prefersReducedMotion ? { height: 0, opacity: 0 } : { height: 0, opacity: 0 }}\n initial={\n prefersReducedMotion ? { height: 'auto', opacity: 1 } : { height: 0, opacity: 0 }\n }\n key=\"widget-host-optional-header\"\n transition={prefersReducedMotion ? { duration: 0 } : widgetHostSizeMotionTransition}\n >\n {children}\n </motion.div>\n ) : null}\n </AnimatePresence>\n )\n}\n","import { AnimatePresence, motion, useReducedMotion } from 'motion/react'\nimport type { ReactNode } from 'react'\nimport { cn } from '../utils'\nimport {\n getWidgetHostCrossfadeMotion,\n getWidgetHostSlideFadeMotion,\n shouldReduceWidgetHostMotion,\n widgetHostSizeMotionTransition,\n} from './widget-host-transition-config'\n\nexport type WidgetHostTitleMotion = 'crossfade' | 'slide'\n\n/** Crossfade title or header-end chrome while the header row stays mounted. */\nexport function WidgetHostTitleTransition({\n children,\n className,\n contentKey,\n variant = 'crossfade',\n}: {\n children: ReactNode\n className?: string\n contentKey: string\n variant?: WidgetHostTitleMotion\n}) {\n const reduceMotion = useReducedMotion()\n const prefersReducedMotion = shouldReduceWidgetHostMotion(reduceMotion)\n const slide = variant === 'slide'\n const phaseMotion = slide ? getWidgetHostSlideFadeMotion : getWidgetHostCrossfadeMotion\n\n return (\n <div\n // Crossfade keeps both layers in-flow on one grid cell (max height).\n // Slide never lets animated layers size the shell — parent height only.\n className={cn('a63-WidgetHostTitleTransition', className)}\n data-slot=\"widget-host-title-transition\"\n data-variant={variant}\n >\n <AnimatePresence initial={false} mode=\"sync\">\n <motion.div\n animate={phaseMotion('active', reduceMotion)}\n // Slide layers pin to the reserved box so enter/exit cannot grow it.\n className=\"a63-WidgetHostTitleTransition-layer\"\n exit={phaseMotion('exit', reduceMotion)}\n initial={phaseMotion('enter', reduceMotion)}\n key={contentKey}\n layout={false}\n style={{\n willChange: prefersReducedMotion ? undefined : slide ? 'opacity' : 'opacity, filter',\n }}\n transition={prefersReducedMotion ? { duration: 0 } : widgetHostSizeMotionTransition}\n >\n {children}\n </motion.div>\n </AnimatePresence>\n </div>\n )\n}\n","import type { ComponentProps, ReactNode } from 'react'\nimport { widgetInsetStyle } from '../layout'\nimport { WidgetBlock, WidgetBlockFooter, WidgetCard } from '../primitives'\nimport { cn } from '../utils'\nimport { WIDGET_FILL_STYLE } from './widget-fill'\nimport { WidgetHostContentTransition } from './widget-host-content-transition'\n\n/**\n * Stable widget card shell with optional header and crossfading body content.\n *\n * ⚠ **`children` must supply their own inset** when there is no `footer`. This\n * shell only wraps the body in a padded `WidgetBlock` when a `footer` is given.\n * Pass a raw `<div>` and it sits flush against the face edge — which reads as a\n * misaligned widget, not a missing wrapper, so it is easy to miss.\n *\n * Use one of:\n * - `WidgetCardContent` — footprint-aware `widgetInsetStyle(size, 'body')`\n * - `WidgetBlock` with `style={widgetInsetStyle(size, 'body')}`\n * - chrome-less faces with `style={widgetInsetStyle(size, 'face')}`\n *\n * Give that slot `flex: 1` when the composition anchors anything to the bottom\n * (`justify-content: space-between`, a pinned footer row). The slot otherwise\n * sizes to its content, leaving the children bunched at the top above dead\n * space.\n *\n * The padding is deliberately NOT unconditional: widgets that pad themselves\n * would double up.\n *\n * The shell fills its host box. A `style` passed here lands on the surface's\n * outer shell, after that fill.\n */\nexport function WidgetHostedShell({\n children,\n className,\n contentClassName,\n contentKey,\n contentSlotClassName,\n footer,\n header,\n size,\n style,\n ...cardProps\n}: {\n children: ReactNode\n className?: string\n contentClassName?: string\n contentKey: string\n contentSlotClassName?: string\n /** Pinned below the crossfading body inside the same block gap rhythm. */\n footer?: ReactNode\n header?: ReactNode\n} & Omit<ComponentProps<typeof WidgetCard>, 'children'>) {\n const transition = (\n <WidgetHostContentTransition\n className={contentSlotClassName}\n contentClassName={contentClassName}\n contentKey={contentKey}\n >\n {children}\n </WidgetHostContentTransition>\n )\n\n return (\n // A widget with a header reads as two anchored bands — title at the top,\n // content settling against the bottom — so the slack lands BETWEEN them\n // rather than under the content. A consumer `justify-*` utility in\n // `className` still wins, for the widgets that ask for something else.\n <WidgetCard\n className={cn(header && 'a63-WidgetHostedShell-anchored', className)}\n size={size}\n style={{ ...WIDGET_FILL_STYLE, ...style }}\n {...cardProps}\n >\n {header}\n {footer ? (\n <WidgetBlock style={widgetInsetStyle(size, header ? 'body' : 'face')}>\n {transition}\n <WidgetBlockFooter>{footer}</WidgetBlockFooter>\n </WidgetBlock>\n ) : (\n transition\n )}\n </WidgetCard>\n )\n}\n"]}
@@ -0,0 +1,90 @@
1
+ import * as React from 'react';
2
+ import { W as WidgetSize } from '../types-C0zDKyo1.js';
3
+
4
+ /** Title and optional description for one feedback state. */
5
+ interface WidgetFeedbackCopy {
6
+ title: string;
7
+ description?: string;
8
+ }
9
+ type WidgetFeedbackState = 'loading' | 'error' | 'empty';
10
+ /**
11
+ * The shared async-state contract for widget views.
12
+ *
13
+ * Top-level props on purpose: `listening` and `profile` used to carry these
14
+ * inside their `data` object while every other widget took them as props, so a
15
+ * host had to remember which shape a given widget wanted. One shape, one place.
16
+ */
17
+ interface WidgetStateProps {
18
+ /** Truthy renders the error state. Accepts `unknown` so hosts can pass a query error straight through. */
19
+ error?: unknown;
20
+ isLoading?: boolean;
21
+ /** Background refresh — content stays mounted, controls show activity. */
22
+ isRefreshing?: boolean;
23
+ onRetry?: () => void;
24
+ }
25
+ /** Per-widget wording for the shared feedback surface. */
26
+ interface WidgetStateCopy {
27
+ empty?: WidgetFeedbackCopy;
28
+ error?: WidgetFeedbackCopy;
29
+ loading?: WidgetFeedbackCopy;
30
+ }
31
+ /**
32
+ * Resolve which feedback state a view should render, if any.
33
+ *
34
+ * `error` wins over `isLoading`: a failed refresh must not sit behind a spinner
35
+ * forever. `isEmpty` is only consulted once the data settles.
36
+ */
37
+ declare function resolveWidgetFeedbackState({ error, isEmpty, isLoading, }: {
38
+ error?: unknown;
39
+ isEmpty?: boolean;
40
+ isLoading?: boolean;
41
+ }): WidgetFeedbackState | null;
42
+ /** Error message text, when the host passed a real Error. */
43
+ declare function getWidgetErrorDescription(error: unknown): string | undefined;
44
+ /**
45
+ * Build a widget's feedback copy from its three state titles.
46
+ *
47
+ * Every widget needs the same thing: a title per state, plus the error's own
48
+ * message on the error state. Six widgets hand-rolled that in two different
49
+ * shapes — a map of thunks in some, an object plus a `feedbackState === 'error'`
50
+ * ternary at the call site in others. This is the one shape.
51
+ *
52
+ * @example
53
+ * const WEATHER_STATE_COPY = widgetStateCopy({
54
+ * empty: 'No weather data yet',
55
+ * error: 'Unable to load weather',
56
+ * loading: 'Loading weather',
57
+ * })
58
+ *
59
+ * <WidgetStateFeedback copy={WEATHER_STATE_COPY(feedbackState, error)} … />
60
+ */
61
+ declare function widgetStateCopy(titles: Record<WidgetFeedbackState, string>): (state: WidgetFeedbackState, error?: unknown) => WidgetFeedbackCopy;
62
+
63
+ interface WidgetStateFeedbackProps {
64
+ className?: string;
65
+ copy: WidgetFeedbackCopy;
66
+ onRetry?: () => void;
67
+ /** Falls back to the nearest WidgetSurface size when omitted. */
68
+ size?: WidgetSize;
69
+ state: WidgetFeedbackState;
70
+ }
71
+ /**
72
+ * The one way a widget reports loading, error, or empty.
73
+ *
74
+ * Deliberately owns its own inset and draws no border or fill. A widget-wide
75
+ * failure has no region to mark, and inheriting host padding made the same
76
+ * state render three different ways — flush and clipped where the shell had no
77
+ * padding, full-bleed where the shell passed none, correct only where the shell
78
+ * happened to pad. Self-padding makes the treatment identical wherever it is
79
+ * mounted.
80
+ *
81
+ * The one-row footprints (1x1 and 2x1) differ in width, not height, so they
82
+ * share the compact density. Stepping them apart put a 28px badge beside a 32px
83
+ * one in tiles of identical height. The 2x2 footprint gets the large density.
84
+ *
85
+ * On the error state the description moves into a disclosure next to the retry
86
+ * button, so technical detail never crowds the tile.
87
+ */
88
+ declare const WidgetStateFeedback: React.NamedExoticComponent<WidgetStateFeedbackProps>;
89
+
90
+ export { type WidgetFeedbackCopy, type WidgetFeedbackState, type WidgetStateCopy, WidgetStateFeedback, type WidgetStateFeedbackProps, type WidgetStateProps, getWidgetErrorDescription, resolveWidgetFeedbackState, widgetStateCopy };
@@ -0,0 +1,158 @@
1
+ import { useWidgetSurfaceSize } from '../chunk-US2CE3BV.js';
2
+ import { cn, widgetTypeStyle } from '../chunk-F5NV6XJ5.js';
3
+ import { Button, Popover, PopoverTrigger, PopoverContent, PopoverTitle, PopoverDescription, CopyButton } from '@atom63/ui-react';
4
+ import { LoaderCircle, AlertTriangle, Inbox, RefreshCw, Ellipsis } from 'lucide-react';
5
+ import { memo } from 'react';
6
+ import { jsxs, jsx } from 'react/jsx-runtime';
7
+
8
+ // src/state/types.ts
9
+ function resolveWidgetFeedbackState({
10
+ error,
11
+ isEmpty,
12
+ isLoading
13
+ }) {
14
+ if (error) {
15
+ return "error";
16
+ }
17
+ if (isLoading) {
18
+ return "loading";
19
+ }
20
+ if (isEmpty) {
21
+ return "empty";
22
+ }
23
+ return null;
24
+ }
25
+ function getWidgetErrorDescription(error) {
26
+ return error instanceof Error ? error.message : void 0;
27
+ }
28
+ function widgetStateCopy(titles) {
29
+ return (state, error) => ({
30
+ description: state === "error" ? getWidgetErrorDescription(error) : void 0,
31
+ title: titles[state]
32
+ });
33
+ }
34
+ var STATE_ICON = {
35
+ empty: Inbox,
36
+ error: AlertTriangle,
37
+ loading: LoaderCircle
38
+ };
39
+ var RETRY_LABEL = "Try again";
40
+ function WidgetErrorActions({
41
+ description,
42
+ onRetry
43
+ }) {
44
+ if (!description && !onRetry) {
45
+ return null;
46
+ }
47
+ return /* @__PURE__ */ jsxs(
48
+ "div",
49
+ {
50
+ className: "a63-WidgetStateFeedback-actions",
51
+ "data-slot": "widget-state-actions",
52
+ children: [
53
+ onRetry ? /* @__PURE__ */ jsxs(
54
+ Button,
55
+ {
56
+ className: "a63-WidgetStateFeedback-action",
57
+ onClick: onRetry,
58
+ size: "sm",
59
+ type: "button",
60
+ variant: "outline",
61
+ children: [
62
+ /* @__PURE__ */ jsx(RefreshCw, { "aria-hidden": true, className: "a63-WidgetStateFeedback-retryIcon" }),
63
+ RETRY_LABEL
64
+ ]
65
+ }
66
+ ) : null,
67
+ description ? /* @__PURE__ */ jsxs(Popover, { children: [
68
+ /* @__PURE__ */ jsx(
69
+ PopoverTrigger,
70
+ {
71
+ render: /* @__PURE__ */ jsx(
72
+ Button,
73
+ {
74
+ "aria-label": "View error details",
75
+ className: "a63-WidgetStateFeedback-action",
76
+ size: "icon-sm",
77
+ type: "button",
78
+ variant: "outline",
79
+ children: /* @__PURE__ */ jsx(Ellipsis, { "aria-hidden": true, className: "a63-WidgetStateFeedback-detailsIcon" })
80
+ }
81
+ )
82
+ }
83
+ ),
84
+ /* @__PURE__ */ jsxs(
85
+ PopoverContent,
86
+ {
87
+ align: "center",
88
+ className: "a63-WidgetErrorDetails",
89
+ side: "top",
90
+ sideOffset: 8,
91
+ children: [
92
+ /* @__PURE__ */ jsxs("div", { className: "a63-WidgetErrorDetails-header", children: [
93
+ /* @__PURE__ */ jsx(PopoverTitle, { children: "Error details" }),
94
+ /* @__PURE__ */ jsx(PopoverDescription, { children: "Technical information you can copy when reporting this problem." })
95
+ ] }),
96
+ /* @__PURE__ */ jsx("p", { className: "a63-WidgetErrorDetails-message", children: description }),
97
+ /* @__PURE__ */ jsx(CopyButton, { label: "Error details", size: "sm", value: description, variant: "outline", children: "Copy details" })
98
+ ]
99
+ }
100
+ )
101
+ ] }) : null
102
+ ]
103
+ }
104
+ );
105
+ }
106
+ var WidgetStateFeedback = memo(
107
+ ({ className, copy, onRetry, size, state }) => {
108
+ const surfaceSize = useWidgetSurfaceSize();
109
+ const resolvedSize = size ?? surfaceSize ?? "small";
110
+ const density = resolvedSize === "large" ? "large" : "compact";
111
+ const typeSize = density === "large" ? "large" : "medium";
112
+ const Icon = STATE_ICON[state];
113
+ const description = state === "error" ? void 0 : copy.description;
114
+ return /* @__PURE__ */ jsxs(
115
+ "div",
116
+ {
117
+ className: cn("a63-WidgetStateFeedback", className),
118
+ "data-density": density,
119
+ "data-slot": "widget-state-feedback",
120
+ "data-state": state,
121
+ role: state === "error" ? "alert" : "status",
122
+ children: [
123
+ /* @__PURE__ */ jsx("div", { className: "a63-WidgetStateFeedback-badge", children: /* @__PURE__ */ jsx(
124
+ Icon,
125
+ {
126
+ "aria-hidden": true,
127
+ className: cn("a63-WidgetStateFeedback-icon", state === "loading" && "a63-Widget-spin")
128
+ }
129
+ ) }),
130
+ /* @__PURE__ */ jsxs("div", { className: "a63-WidgetStateFeedback-text", children: [
131
+ /* @__PURE__ */ jsx(
132
+ "p",
133
+ {
134
+ className: "a63-WidgetStateFeedback-title",
135
+ style: widgetTypeStyle("body", typeSize, { weight: 500 }),
136
+ children: copy.title
137
+ }
138
+ ),
139
+ description ? /* @__PURE__ */ jsx(
140
+ "p",
141
+ {
142
+ className: "a63-WidgetStateFeedback-description",
143
+ style: widgetTypeStyle("body", typeSize),
144
+ children: description
145
+ }
146
+ ) : null
147
+ ] }),
148
+ state === "error" ? /* @__PURE__ */ jsx(WidgetErrorActions, { description: copy.description, onRetry }) : null
149
+ ]
150
+ }
151
+ );
152
+ }
153
+ );
154
+ WidgetStateFeedback.displayName = "WidgetStateFeedback";
155
+
156
+ export { WidgetStateFeedback, getWidgetErrorDescription, resolveWidgetFeedbackState, widgetStateCopy };
157
+ //# sourceMappingURL=index.js.map
158
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/state/types.ts","../../src/state/widget-state-feedback.tsx"],"names":[],"mappings":";;;;;;;;AAqCO,SAAS,0BAAA,CAA2B;AAAA,EACzC,KAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAAA,EAI+B;AAC7B,EAAA,IAAI,KAAA,EAAO;AACT,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAA,EAAW;AACb,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA;AACT;AAGO,SAAS,0BAA0B,KAAA,EAAoC;AAC5E,EAAA,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,MAAA;AAClD;AAmBO,SA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AAQ,CAAA;AAAA,gBAEtC,QAAA,EAAA;AAAA;AAAA,aACH,GACE;AAAA,WAAA,EACN,CAAA;AAAA,UACC,KAAA,KAAU,0BACT,GAAA,CAAC,kBAAA,EAAA,EAAmB,aAAa,IAAA,CAAK,WAAA,EAAa,SAAkB,CAAA,GACnE;AAAA;AAAA;AAAA,KACN;AAAA,EAEJ;AACF;AAEA,mBAAA,CAAoB,WAAA,GAAc,qBAAA","file":"index.js","sourcesContent":["/** Title and optional description for one feedback state. */\nexport interface WidgetFeedbackCopy {\n title: string\n description?: string\n}\n\nexport type WidgetFeedbackState = 'loading' | 'error' | 'empty'\n\n/**\n * The shared async-state contract for widget views.\n *\n * Top-level props on purpose: `listening` and `profile` used to carry these\n * inside their `data` object while every other widget took them as props, so a\n * host had to remember which shape a given widget wanted. One shape, one place.\n */\nexport interface WidgetStateProps {\n /** Truthy renders the error state. Accepts `unknown` so hosts can pass a query error straight through. */\n error?: unknown\n isLoading?: boolean\n /** Background refresh — content stays mounted, controls show activity. */\n isRefreshing?: boolean\n onRetry?: () => void\n}\n\n/** Per-widget wording for the shared feedback surface. */\nexport interface WidgetStateCopy {\n empty?: WidgetFeedbackCopy\n error?: WidgetFeedbackCopy\n loading?: WidgetFeedbackCopy\n}\n\n/**\n * Resolve which feedback state a view should render, if any.\n *\n * `error` wins over `isLoading`: a failed refresh must not sit behind a spinner\n * forever. `isEmpty` is only consulted once the data settles.\n */\nexport function resolveWidgetFeedbackState({\n error,\n isEmpty,\n isLoading,\n}: {\n error?: unknown\n isEmpty?: boolean\n isLoading?: boolean\n}): WidgetFeedbackState | null {\n if (error) {\n return 'error'\n }\n if (isLoading) {\n return 'loading'\n }\n if (isEmpty) {\n return 'empty'\n }\n return null\n}\n\n/** Error message text, when the host passed a real Error. */\nexport function getWidgetErrorDescription(error: unknown): string | undefined {\n return error instanceof Error ? error.message : undefined\n}\n\n/**\n * Build a widget's feedback copy from its three state titles.\n *\n * Every widget needs the same thing: a title per state, plus the error's own\n * message on the error state. Six widgets hand-rolled that in two different\n * shapes — a map of thunks in some, an object plus a `feedbackState === 'error'`\n * ternary at the call site in others. This is the one shape.\n *\n * @example\n * const WEATHER_STATE_COPY = widgetStateCopy({\n * empty: 'No weather data yet',\n * error: 'Unable to load weather',\n * loading: 'Loading weather',\n * })\n *\n * <WidgetStateFeedback copy={WEATHER_STATE_COPY(feedbackState, error)} … />\n */\nexport function widgetStateCopy(\n titles: Record<WidgetFeedbackState, string>\n): (state: WidgetFeedbackState, error?: unknown) => WidgetFeedbackCopy {\n return (state, error) => ({\n description: state === 'error' ? getWidgetErrorDescription(error) : undefined,\n title: titles[state],\n })\n}\n","import {\n Button,\n CopyButton,\n Popover,\n PopoverContent,\n PopoverDescription,\n PopoverTitle,\n PopoverTrigger,\n} from '@atom63/ui-react'\nimport { AlertTriangle, Ellipsis, Inbox, LoaderCircle, RefreshCw } from 'lucide-react'\nimport { memo } from 'react'\nimport { widgetTypeStyle } from '../layout'\nimport { useWidgetSurfaceSize } from '../primitives'\nimport type { WidgetSize } from '../types'\nimport { cn } from '../utils'\nimport type { WidgetFeedbackCopy, WidgetFeedbackState } from './types'\n\nconst STATE_ICON = {\n empty: Inbox,\n error: AlertTriangle,\n loading: LoaderCircle,\n} as const\n\nconst RETRY_LABEL = 'Try again'\n\nfunction WidgetErrorActions({\n description,\n onRetry,\n}: {\n description?: string\n onRetry?: () => void\n}) {\n if (!description && !onRetry) {\n return null\n }\n\n return (\n <div\n // The row gap is `--a63-space-2`, which follows the density axis like the\n // a63 controls in it, so the row keeps its proportion under compact\n // density instead of the controls shrinking around a fixed gap.\n className=\"a63-WidgetStateFeedback-actions\"\n data-slot=\"widget-state-actions\"\n >\n {onRetry ? (\n <Button\n className=\"a63-WidgetStateFeedback-action\"\n onClick={onRetry}\n size=\"sm\"\n type=\"button\"\n variant=\"outline\"\n >\n <RefreshCw aria-hidden className=\"a63-WidgetStateFeedback-retryIcon\" />\n {RETRY_LABEL}\n </Button>\n ) : null}\n {description ? (\n <Popover>\n <PopoverTrigger\n render={\n <Button\n aria-label=\"View error details\"\n className=\"a63-WidgetStateFeedback-action\"\n size=\"icon-sm\"\n type=\"button\"\n variant=\"outline\"\n >\n <Ellipsis aria-hidden className=\"a63-WidgetStateFeedback-detailsIcon\" />\n </Button>\n }\n />\n <PopoverContent\n align=\"center\"\n className=\"a63-WidgetErrorDetails\"\n side=\"top\"\n sideOffset={8}\n >\n <div className=\"a63-WidgetErrorDetails-header\">\n <PopoverTitle>Error details</PopoverTitle>\n <PopoverDescription>\n Technical information you can copy when reporting this problem.\n </PopoverDescription>\n </div>\n {/* Fixed type, not the widget ramp, on purpose: this sits inside a\n portalled Popover, which renders at document level where\n `--widget-u` is not inherited. */}\n <p className=\"a63-WidgetErrorDetails-message\">{description}</p>\n <CopyButton label=\"Error details\" size=\"sm\" value={description} variant=\"outline\">\n Copy details\n </CopyButton>\n </PopoverContent>\n </Popover>\n ) : null}\n </div>\n )\n}\n\nexport interface WidgetStateFeedbackProps {\n className?: string\n copy: WidgetFeedbackCopy\n onRetry?: () => void\n /** Falls back to the nearest WidgetSurface size when omitted. */\n size?: WidgetSize\n state: WidgetFeedbackState\n}\n\n/**\n * The one way a widget reports loading, error, or empty.\n *\n * Deliberately owns its own inset and draws no border or fill. A widget-wide\n * failure has no region to mark, and inheriting host padding made the same\n * state render three different ways — flush and clipped where the shell had no\n * padding, full-bleed where the shell passed none, correct only where the shell\n * happened to pad. Self-padding makes the treatment identical wherever it is\n * mounted.\n *\n * The one-row footprints (1x1 and 2x1) differ in width, not height, so they\n * share the compact density. Stepping them apart put a 28px badge beside a 32px\n * one in tiles of identical height. The 2x2 footprint gets the large density.\n *\n * On the error state the description moves into a disclosure next to the retry\n * button, so technical detail never crowds the tile.\n */\nexport const WidgetStateFeedback = memo<WidgetStateFeedbackProps>(\n ({ className, copy, onRetry, size, state }) => {\n const surfaceSize = useWidgetSurfaceSize()\n const resolvedSize = size ?? surfaceSize ?? 'small'\n const density = resolvedSize === 'large' ? 'large' : 'compact'\n const typeSize = density === 'large' ? 'large' : 'medium'\n const Icon = STATE_ICON[state]\n const description = state === 'error' ? undefined : copy.description\n\n return (\n <div\n className={cn('a63-WidgetStateFeedback', className)}\n data-density={density}\n data-slot=\"widget-state-feedback\"\n data-state={state}\n role={state === 'error' ? 'alert' : 'status'}\n >\n <div className=\"a63-WidgetStateFeedback-badge\">\n <Icon\n aria-hidden\n className={cn('a63-WidgetStateFeedback-icon', state === 'loading' && 'a63-Widget-spin')}\n />\n </div>\n <div className=\"a63-WidgetStateFeedback-text\">\n <p\n className=\"a63-WidgetStateFeedback-title\"\n style={widgetTypeStyle('body', typeSize, { weight: 500 })}\n >\n {copy.title}\n </p>\n {description ? (\n <p\n className=\"a63-WidgetStateFeedback-description\"\n style={widgetTypeStyle('body', typeSize)}\n >\n {description}\n </p>\n ) : null}\n </div>\n {state === 'error' ? (\n <WidgetErrorActions description={copy.description} onRetry={onRetry} />\n ) : null}\n </div>\n )\n }\n)\n\nWidgetStateFeedback.displayName = 'WidgetStateFeedback'\n"]}
@@ -0,0 +1,3 @@
1
+ type WidgetSize = 'small' | 'medium' | 'large';
2
+
3
+ export type { WidgetSize as W };