rockin 0.0.41 → 0.0.43

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/ui/index.js CHANGED
@@ -10,7 +10,7 @@ export { Bubble, BubbleContent, BubbleGroup, BubbleReactions } from "./bubble.js
10
10
  export { Button, buttonVariants } from "./button.js"
11
11
  export { ButtonGroup, ButtonGroupSeparator, ButtonGroupText, buttonGroupVariants } from "./button-group.js"
12
12
  export { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "./card.js"
13
- export { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, useCarousel } from "./carousel.js"
13
+ export { Carousel, CarouselContent, CarouselDots, CarouselItem, CarouselNext, CarouselPrevious, useCarousel } from "./carousel.js"
14
14
  export { ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent } from "./chart.js"
15
15
  export { Checkbox } from "./checkbox.js"
16
16
  export { CodeBlock } from "./code-block.js"
@@ -29,7 +29,7 @@ export { default as AnimatedDiv } from "./farmer/div.js"
29
29
  export { BlogCardAnimation, Bottom, FadeContainer, ListItemVariant, Top, activityItemAnimation, fromLeftChildren, fromLeftVariant, fromRightVariant, fromTopVariant, hamFastFadeContainer, headingFromLeft, kanbanOrderCardAnimation, kanbanOrderCardLayoutTransition, kanbanOrderCardReducedMotionAnimation, mobileNavItemSideways, opacityVariant, popUp, popUpFromBottomForText, searchBarSlideAnimation, svgVariant } from "./farmer/variants.js"
30
30
  export { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTitle } from "./field.js"
31
31
  export { DEFAULT_I18N, DEFAULT_OPERATORS, Filters, FiltersContent, createFilter, createFilterGroup } from "./filters.js"
32
- export { Image } from "./image.js"
32
+ export { Image, ImageFallback, ImagePlaceholder, ImageProvider, ImageRoot, ImageSource } from "./image.js"
33
33
  export { Input } from "./input.js"
34
34
  export { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea } from "./input-group.js"
35
35
  export { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, REGEXP_ONLY_DIGITS } from "./input-otp.js"
@@ -37,6 +37,7 @@ export { Item, ItemActions, ItemContent, ItemDescription, ItemFooter, ItemGroup,
37
37
  export { BlobSpeech, JellyAction, JellyBlob, JellyBlobMascot, JellyBlobMascotDemo, JellyEmpty, JellyGroup, JellyLink, JellyMascot, JellyMini, useJellyMood } from "./jelly.js"
38
38
  export { Kbd, KbdGroup } from "./kbd.js"
39
39
  export { Label } from "./label.js"
40
+ export { List, ListGroup, ListItem, ListLabel, createListController, listItemVariants, listPrimitive } from "./list.js"
40
41
  export { Message, MessageAvatar, MessageContent, MessageFooter, MessageGroup, MessageHeader } from "./message.js"
41
42
  export { MessageScroller, MessageScrollerButton, MessageScrollerContent, MessageScrollerItem, MessageScrollerProvider, MessageScrollerViewport, useMessageScroller, useMessageScrollerScrollable, useMessageScrollerVisibility } from "./message-scroller.js"
42
43
  export { NumberStepper, RollingNumber } from "./numberstepper.js"
@@ -58,3 +59,4 @@ export { Textarea } from "./textarea.js"
58
59
  export { ThemeSwitcher } from "./theme-switcher.js"
59
60
  export { ThemeToggle } from "./theme-toggle.js"
60
61
  export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip.js"
62
+ export { UiAgent } from "./ui-agent.js"
@@ -0,0 +1,379 @@
1
+ "use client";
2
+
3
+ // src/ui/list.tsx
4
+ import {
5
+ createController,
6
+ createRovingFocus,
7
+ definePrimitive,
8
+ idPart,
9
+ live,
10
+ selects,
11
+ spatialMove
12
+ } from "@ui-sdk/core";
13
+ import { createParts } from "@ui-sdk/react/primitive";
14
+ import { cva } from "class-variance-authority";
15
+ import { cn } from "cn";
16
+ import { jsx } from "react/jsx-runtime";
17
+ var orientationOf = (value) => value === "horizontal" || value === "grid" ? value : "vertical";
18
+ var fromOptions = (options) => ({
19
+ orientation: orientationOf(options.orientation)
20
+ });
21
+ var itemSelector = '[data-slot="list-item"]';
22
+ var pageKeys = /* @__PURE__ */ new Set([
23
+ "ArrowUp",
24
+ "ArrowDown",
25
+ "ArrowLeft",
26
+ "ArrowRight",
27
+ "Home",
28
+ "End"
29
+ ]);
30
+ var labelId = (id, key) => `${id}-label-${idPart(key)}`;
31
+ var spatial = spatialMove();
32
+ var steps = {
33
+ vertical: { ArrowDown: 1, ArrowUp: -1 },
34
+ horizontal: { ArrowRight: 1, ArrowLeft: -1 },
35
+ grid: {}
36
+ };
37
+ var activates = (event) => (event.key === "Enter" || event.key === " ") && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey;
38
+ function createListController() {
39
+ return createController();
40
+ }
41
+ var list = definePrimitive({
42
+ name: "list",
43
+ options: {
44
+ orientation: "string",
45
+ loop: "boolean",
46
+ controller: "value"
47
+ },
48
+ state: (options) => ({
49
+ ...fromOptions(options),
50
+ stop: null,
51
+ labels: [],
52
+ /** The item shown as current: the hovered one, or the focused one while keys drive. */
53
+ highlighted: null,
54
+ /** True after arrow-key navigation until the mouse really moves, like cmdk. */
55
+ pointerHidden: false
56
+ }),
57
+ live: ["labels", "highlighted", "pointerHidden"],
58
+ sync: fromOptions,
59
+ api: (context) => {
60
+ const { store, options } = context;
61
+ const move = (event, ctx) => {
62
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
63
+ return;
64
+ }
65
+ const { orientation } = store.get();
66
+ if (orientation === "grid") return spatial(event, ctx);
67
+ const { items: items2, from, rtl } = ctx;
68
+ if (!items2.length) return;
69
+ if (event.key === "Home") return items2[0].key;
70
+ if (event.key === "End") return items2[items2.length - 1].key;
71
+ let step = steps[orientation][event.key];
72
+ if (step === void 0) return;
73
+ if (orientation === "horizontal" && rtl) step = -step;
74
+ const index = items2.findIndex((item) => item.key === from.key);
75
+ let next = index + step;
76
+ if (next < 0 || next >= items2.length) {
77
+ if (!options().loop) return from.key;
78
+ next = (next + items2.length) % items2.length;
79
+ }
80
+ return items2[next].key;
81
+ };
82
+ const roving = createRovingFocus(
83
+ context,
84
+ {
85
+ slot: "item",
86
+ key: "stop",
87
+ disabled: (item) => !!item.props?.disabled,
88
+ move
89
+ }
90
+ );
91
+ let hovered = null;
92
+ let pointer = { x: Number.NaN, y: Number.NaN };
93
+ const itemOf = (target) => {
94
+ const el = target?.closest?.(
95
+ itemSelector
96
+ );
97
+ return el ? roving.items().find((item) => item.el === el) : void 0;
98
+ };
99
+ const focusedItem = () => itemOf(document.activeElement)?.el === document.activeElement ? itemOf(document.activeElement) : void 0;
100
+ const highlight = (key) => {
101
+ if (store.get().highlighted !== key) store.set({ highlighted: key });
102
+ };
103
+ const enabled = () => roving.items().filter((item) => !item.props?.disabled);
104
+ const items = () => enabled().map((item) => ({
105
+ value: item.key,
106
+ label: (item.el.getAttribute("aria-label") ?? item.el.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 80)
107
+ }));
108
+ return {
109
+ focus: (value) => roving.focus(value),
110
+ items,
111
+ open(target) {
112
+ const wanted = items().find(
113
+ (item) => item.value === target || item.label.toLowerCase().includes(target.toLowerCase())
114
+ );
115
+ if (!wanted) {
116
+ throw new Error(
117
+ `No item "${target}". Items: ${items().map((item) => item.label).join(", ")}`
118
+ );
119
+ }
120
+ enabled().find((item) => item.key === wanted.value)?.el.click();
121
+ },
122
+ internal: {
123
+ roving,
124
+ keydown(event, el) {
125
+ if (event.defaultPrevented || event.target !== el) return;
126
+ const moved = roving.keydown(event, el);
127
+ if (moved) {
128
+ highlight(moved.key);
129
+ if (!store.get().pointerHidden) store.set({ pointerHidden: true });
130
+ return;
131
+ }
132
+ if (!activates(event)) return;
133
+ event.preventDefault();
134
+ if (el.getAttribute("aria-disabled") !== "true") el.click();
135
+ },
136
+ pointermove(event) {
137
+ if (event.pointerType !== "mouse" && event.pointerType !== "pen") {
138
+ return;
139
+ }
140
+ if (event.clientX === pointer.x && event.clientY === pointer.y) return;
141
+ pointer = { x: event.clientX, y: event.clientY };
142
+ if (store.get().pointerHidden) store.set({ pointerHidden: false });
143
+ const item = itemOf(event.target);
144
+ if (!item || item.props?.disabled) return;
145
+ hovered = item.key;
146
+ highlight(item.key);
147
+ const focused = focusedItem();
148
+ if (focused && focused.el !== item.el) {
149
+ item.el.focus({ preventScroll: true });
150
+ } else if (!focused) {
151
+ roving.remember(item.key);
152
+ }
153
+ },
154
+ pointerleave() {
155
+ hovered = null;
156
+ highlight(focusedItem()?.key ?? null);
157
+ },
158
+ focusin(event) {
159
+ const item = itemOf(event.target);
160
+ if (item && item.el === event.target) highlight(item.key);
161
+ },
162
+ focusout(event, root) {
163
+ if (root.contains(event.relatedTarget)) return;
164
+ highlight(hovered && !store.get().pointerHidden ? hovered : null);
165
+ },
166
+ /**
167
+ * Keys pressed while nothing has focus (fresh page load, after closing a
168
+ * drawer) act on the hovered item, like cmdk: arrows move from it and
169
+ * Enter opens it. Focus in an input or another control is left alone.
170
+ */
171
+ listenToPage() {
172
+ const onKeyDown = (event) => {
173
+ if (event.defaultPrevented || !hovered) return;
174
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
175
+ const active = document.activeElement;
176
+ if (active && active !== document.body && active !== document.documentElement) {
177
+ return;
178
+ }
179
+ if (event.key !== "Enter" && !pageKeys.has(event.key)) return;
180
+ const item = roving.items().find((candidate) => candidate.key === hovered);
181
+ if (!item) return;
182
+ if (event.key === "Enter") {
183
+ event.preventDefault();
184
+ if (!item.props?.disabled) item.el.click();
185
+ return;
186
+ }
187
+ item.el.focus({ preventScroll: true });
188
+ const moved = roving.keydown(event, item.el);
189
+ event.preventDefault();
190
+ highlight(moved?.key ?? item.key);
191
+ if (!store.get().pointerHidden) store.set({ pointerHidden: true });
192
+ };
193
+ document.addEventListener("keydown", onKeyDown);
194
+ return () => document.removeEventListener("keydown", onKeyDown);
195
+ }
196
+ }
197
+ };
198
+ },
199
+ slots: (slot) => ({
200
+ root: slot({
201
+ role: "list",
202
+ selects: selects({ stop: [], labels: [], highlighted: [] }),
203
+ state: (state) => ({ orientation: state.orientation }),
204
+ attrs: (state) => ({ "data-orientation": state.orientation }),
205
+ live: live((state) => ({
206
+ "data-pointer-hidden": state.pointerHidden ? "" : void 0
207
+ })),
208
+ on: {
209
+ pointermove: (event, { api }) => api.internal.pointermove(event),
210
+ pointerleave: (_event, { api }) => api.internal.pointerleave(),
211
+ focusin: (event, { api }) => api.internal.focusin(event),
212
+ focusout: (event, { el, api }) => {
213
+ if (el) api.internal.focusout(event, el);
214
+ }
215
+ },
216
+ bind: (_el, { api }) => api.internal.listenToPage()
217
+ }),
218
+ item: slot({
219
+ role: "listitem",
220
+ props: { value: "id", disabled: "boolean" },
221
+ selects: selects({
222
+ stop: ({ key }) => [key, null],
223
+ labels: [],
224
+ highlighted: ({ key }) => [key],
225
+ pointerHidden: []
226
+ }),
227
+ state: (state, { key, props }) => ({
228
+ highlighted: state.highlighted === key,
229
+ disabled: !!props.disabled
230
+ }),
231
+ attrs: (state, { key, props, api }) => ({
232
+ tabindex: api.internal.roving.tabIndex(state, { key, props }),
233
+ "aria-disabled": props.disabled ? "true" : void 0,
234
+ "data-disabled": props.disabled ? "" : void 0,
235
+ "data-orientation": state.orientation
236
+ }),
237
+ live: live((state, { key }) => ({
238
+ "data-highlighted": state.highlighted === key ? "" : void 0
239
+ })),
240
+ on: {
241
+ keydown: (event, { el, api }) => {
242
+ if (el) api.internal.keydown(event, el);
243
+ },
244
+ click: (event, { props }) => {
245
+ if (props.disabled) event.preventDefault();
246
+ }
247
+ },
248
+ bind: (el, part) => part.api.internal.roving.bind(el, part)
249
+ }),
250
+ group: slot({
251
+ role: "group",
252
+ props: { value: "id" },
253
+ selects: selects({
254
+ stop: [],
255
+ labels: ({ key }) => [key],
256
+ highlighted: [],
257
+ pointerHidden: []
258
+ }),
259
+ live: live((state, { id, key }) => ({
260
+ "aria-labelledby": state.labels.includes(key) ? labelId(id, key) : void 0
261
+ }))
262
+ }),
263
+ label: slot({
264
+ props: { value: { kind: "string", from: "group" } },
265
+ selects: selects({
266
+ stop: [],
267
+ labels: [],
268
+ highlighted: [],
269
+ pointerHidden: []
270
+ }),
271
+ attrs: (_state, { id, key }) => ({ id: labelId(id, key) }),
272
+ bind: (_el, { key, store }) => {
273
+ store.set({ labels: [...store.get().labels, key] });
274
+ return () => store.set({
275
+ labels: store.get().labels.filter((label) => label !== key)
276
+ });
277
+ }
278
+ })
279
+ }),
280
+ agent: {
281
+ actions: ["open", "focus"],
282
+ items: (api) => api.items()
283
+ }
284
+ });
285
+ var Parts = createParts(list, {
286
+ root: "div",
287
+ item: "div",
288
+ group: "div",
289
+ label: "div"
290
+ });
291
+ var withClass = (className, base) => typeof className === "function" ? (state) => cn(base, className(state)) : cn(base, className);
292
+ function List({ className, ...props }) {
293
+ return /* @__PURE__ */ jsx(
294
+ Parts.Root,
295
+ {
296
+ ...props,
297
+ className: withClass(
298
+ className,
299
+ "outline-none data-pointer-hidden:cursor-none data-pointer-hidden:**:cursor-none data-[orientation=horizontal]:flex data-[orientation=horizontal]:flex-row data-[orientation=vertical]:flex data-[orientation=vertical]:flex-col"
300
+ )
301
+ }
302
+ );
303
+ }
304
+ var surface = "data-highlighted:bg-(--list-item-hover) active:bg-(--list-item-active) data-active:bg-(--list-item-active)";
305
+ var ring = "data-highlighted:ring-2 data-highlighted:ring-(--list-item-ring) data-active:ring-2 data-active:ring-(--list-item-ring)";
306
+ var focusRing = "focus-visible:ring-2 focus-visible:ring-(--list-item-ring) data-active:ring-2 data-active:ring-(--list-item-ring)";
307
+ var listItemVariants = cva(
308
+ cn(
309
+ "relative cursor-pointer transition-[background-color,box-shadow] duration-150 ease-out outline-none [-webkit-tap-highlight-color:transparent] motion-reduce:transition-none",
310
+ "[--list-item-active:var(--color-muted)] [--list-item-hover:color-mix(in_oklab,var(--color-muted)_60%,transparent)] [--list-item-ring:var(--color-ring)]",
311
+ "data-disabled:cursor-not-allowed data-disabled:opacity-60"
312
+ ),
313
+ {
314
+ variants: {
315
+ highlight: {
316
+ /** Tinted background on hover, focus, press and active. */
317
+ background: surface,
318
+ /** Ring only; the background never changes. */
319
+ outline: ring,
320
+ /** Background on highlight, plus a ring on keyboard focus and active. */
321
+ both: cn(surface, focusRing),
322
+ /** No built-in states. Style `data-highlighted`, `:focus-visible` and `data-active` yourself. */
323
+ none: ""
324
+ },
325
+ ring: {
326
+ /** Ring drawn inside the item; safe for full-width rows and scroll areas. */
327
+ inset: "ring-inset",
328
+ /** Ring drawn outside the item, for spaced cards in a grid. */
329
+ offset: "ring-offset-2 ring-offset-background"
330
+ }
331
+ },
332
+ defaultVariants: { highlight: "background", ring: "inset" }
333
+ }
334
+ );
335
+ function ListItem({
336
+ className,
337
+ highlight,
338
+ ring: ringPlacement,
339
+ active,
340
+ ...props
341
+ }) {
342
+ return /* @__PURE__ */ jsx(
343
+ Parts.Item,
344
+ {
345
+ "aria-current": active ? "true" : void 0,
346
+ "data-active": active ? "" : void 0,
347
+ "data-highlight": highlight ?? "background",
348
+ ...props,
349
+ className: withClass(
350
+ className,
351
+ listItemVariants({ highlight, ring: ringPlacement })
352
+ )
353
+ }
354
+ );
355
+ }
356
+ function ListGroup({ className, ...props }) {
357
+ return /* @__PURE__ */ jsx(Parts.Group, { ...props, className: withClass(className, "") });
358
+ }
359
+ function ListLabel({ className, ...props }) {
360
+ return /* @__PURE__ */ jsx(
361
+ Parts.Label,
362
+ {
363
+ ...props,
364
+ className: withClass(
365
+ className,
366
+ "text-xs font-medium text-muted-foreground"
367
+ )
368
+ }
369
+ );
370
+ }
371
+ export {
372
+ List,
373
+ ListGroup,
374
+ ListItem,
375
+ ListLabel,
376
+ createListController,
377
+ listItemVariants,
378
+ list as listPrimitive
379
+ };
@@ -0,0 +1,81 @@
1
+ "use client";
2
+
3
+ // src/ui/ui-agent.tsx
4
+ import * as React from "react";
5
+ var stateAttrs = [
6
+ "data-highlighted",
7
+ "data-active",
8
+ "data-open",
9
+ "data-pressed",
10
+ "data-disabled",
11
+ "data-pointer-hidden",
12
+ "aria-current",
13
+ "aria-expanded",
14
+ "aria-selected",
15
+ "aria-checked",
16
+ "aria-disabled"
17
+ ];
18
+ var localHosts = /^(localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0)$|\.(local|localhost)$/;
19
+ function brief(el) {
20
+ if (!el || el === document.body) return null;
21
+ const name = (el.getAttribute("aria-label") ?? el.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 60);
22
+ const state = stateAttrs.filter((attr) => el.hasAttribute(attr)).map((attr) => {
23
+ const value = el.getAttribute(attr);
24
+ return value ? `${attr}=${value}` : attr;
25
+ });
26
+ if (el === document.activeElement) state.push("focused");
27
+ return {
28
+ tag: el.tagName.toLowerCase(),
29
+ slot: el.getAttribute("data-slot") ?? void 0,
30
+ role: el.getAttribute("role") ?? void 0,
31
+ name: name || void 0,
32
+ state: state.length ? state : void 0
33
+ };
34
+ }
35
+ function isLocal() {
36
+ return process.env.NODE_ENV === "development" || localHosts.test(window.location.hostname);
37
+ }
38
+ function UiAgent({ prod = false }) {
39
+ React.useEffect(() => {
40
+ if (!prod && !isLocal()) return;
41
+ let cancelled = false;
42
+ import("@ui-sdk/react/agent").then(({ createAgent }) => {
43
+ if (cancelled || window.agent) return;
44
+ const agent = createAgent();
45
+ window.agent = agent;
46
+ window.ui = {
47
+ snap: () => agent.snapshot().filter((entry) => !entry.offPage).map(({ ref, component, label, actions, ...rest }) => ({
48
+ ref,
49
+ component,
50
+ label,
51
+ actions,
52
+ ..."value" in rest ? { value: rest.value } : {},
53
+ ..."open" in rest ? { open: rest.open } : {},
54
+ ..."checked" in rest ? { checked: rest.checked } : {}
55
+ })),
56
+ focus: () => brief(document.activeElement),
57
+ state: (selector, limit = 20) => Array.from(document.querySelectorAll(selector)).slice(0, limit).map(brief).filter((item) => item !== null),
58
+ keys: (...keys) => {
59
+ for (const key of keys) {
60
+ const target = document.activeElement ?? document.body;
61
+ target.dispatchEvent(
62
+ new KeyboardEvent("keydown", {
63
+ key,
64
+ bubbles: true,
65
+ cancelable: true
66
+ })
67
+ );
68
+ }
69
+ return brief(document.activeElement);
70
+ }
71
+ };
72
+ });
73
+ return () => {
74
+ cancelled = true;
75
+ };
76
+ }, [prod]);
77
+ return null;
78
+ }
79
+ export {
80
+ UiAgent
81
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rockin",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "Reusable React UI components, hooks, icons, utilities, and styles for Rock Star projects.",
5
5
  "keywords": [
6
6
  "react",