@livo-tv/blocks 1.2.0 → 1.3.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.
package/README.md CHANGED
@@ -62,7 +62,7 @@ import { CurtainPicker, CurtainPickerSkeleton } from "@livo-tv/blocks";
62
62
  />;
63
63
  ```
64
64
 
65
- Image tiles use the asset URL. Video tiles show a muted looping preview only while the card is on screen, and freeze on `prefers-reduced-motion`. Pass `isDefault` on each item (org setting or platform flag). Use `CurtainPickerSkeleton` for a layout-matched loading grid.
65
+ Image tiles use the asset URL. Video tiles show a muted looping preview only while the card is on screen, and freeze on `prefers-reduced-motion`. `variant="compact"` is a selected preview plus a dense thumbnail grid (thumbs stay frozen). Pass `isDefault` on each item (org setting or platform flag). Use `CurtainPickerSkeleton` for a layout-matched loading state.
66
66
 
67
67
  ## Avatar
68
68
 
package/dist/index.cjs CHANGED
@@ -2354,13 +2354,14 @@ function CurtainPreview({
2354
2354
  url,
2355
2355
  alt = "",
2356
2356
  className,
2357
- playWhenVisible = true
2357
+ playWhenVisible = true,
2358
+ frozen = false
2358
2359
  }) {
2359
2360
  const prefersReduced = useMediaQuery2("(prefers-reduced-motion: reduce)");
2360
2361
  const video = isVideoKind(kind);
2361
- const observe = playWhenVisible && video && !prefersReduced;
2362
+ const observe = !frozen && playWhenVisible && video && !prefersReduced;
2362
2363
  const [setNode, inView] = useElementInView(observe);
2363
- const shouldPlay = video && !prefersReduced && (!playWhenVisible || inView);
2364
+ const shouldPlay = !frozen && video && !prefersReduced && (!playWhenVisible || inView);
2364
2365
  if (!url) {
2365
2366
  return /* @__PURE__ */ jsxRuntime.jsx(
2366
2367
  "div",
@@ -2442,13 +2443,43 @@ function groupHeading(group, copy) {
2442
2443
  return headings[group];
2443
2444
  }
2444
2445
  function gridClass(variant) {
2445
- return variant === "compact" ? "grid gap-3 sm:grid-cols-2" : "grid gap-4 sm:grid-cols-2 lg:grid-cols-3";
2446
+ return variant === "compact" ? "grid grid-cols-3 gap-2 sm:grid-cols-4 lg:grid-cols-6" : "grid gap-4 sm:grid-cols-2 lg:grid-cols-3";
2447
+ }
2448
+ function selectionRing(selectable) {
2449
+ return selectable && "has-[:checked]:ring-ring has-[:checked]:ring-2 has-[:focus-visible]:ring-ring has-[:focus-visible]:ring-2";
2450
+ }
2451
+ function resolvePreviewItem(selectedId, ready, allowNone) {
2452
+ if (selectedId) {
2453
+ return ready.find((curtain) => curtain.id === selectedId) ?? ready[0] ?? null;
2454
+ }
2455
+ if (allowNone) return null;
2456
+ return ready[0] ?? null;
2457
+ }
2458
+ function itemActions(item, onMakeDefault, onDelete, canMakeDefault, canDelete) {
2459
+ if (!item) return {};
2460
+ return {
2461
+ onMakeDefault: onMakeDefault && (canMakeDefault ? canMakeDefault(item) : !item.isDefault) ? () => onMakeDefault(item) : void 0,
2462
+ onDelete: onDelete && (canDelete ? canDelete(item) : true) ? () => onDelete(item) : void 0
2463
+ };
2446
2464
  }
2447
2465
  function CurtainPickerSkeleton({
2448
2466
  count = 6,
2449
2467
  variant = "default",
2450
2468
  className
2451
2469
  }) {
2470
+ if (variant === "compact") {
2471
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("space-y-4", className), "aria-hidden": "true", children: [
2472
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-w-sm space-y-3", children: [
2473
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aspect-video rounded-md bg-skeleton" }),
2474
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-4 w-2/3 rounded bg-skeleton" }),
2475
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-3 w-1/2 rounded bg-skeleton" })
2476
+ ] }),
2477
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { className: gridClass("compact"), children: Array.from({ length: count }, (_, index) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "space-y-1.5 rounded-lg border p-1.5", children: [
2478
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aspect-video rounded-md bg-skeleton" }),
2479
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-3 w-3/4 rounded bg-skeleton" })
2480
+ ] }, index)) })
2481
+ ] });
2482
+ }
2452
2483
  return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: cn(gridClass(variant), className), "aria-hidden": "true", children: Array.from({ length: count }, (_, index) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "space-y-3 rounded-xl border p-4", children: [
2453
2484
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aspect-video rounded-md bg-skeleton" }),
2454
2485
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-4 w-2/3 rounded bg-skeleton" }),
@@ -2475,9 +2506,20 @@ function CurtainPicker({
2475
2506
  const copy = { ...DEFAULT_CURTAIN_PICKER_LABELS, ...labels };
2476
2507
  const groupName = React7__namespace.useId();
2477
2508
  const selectable = typeof onChange === "function";
2509
+ const compact = variant === "compact";
2478
2510
  const selectedId = value === "" ? null : value ?? null;
2479
2511
  const ready = curtains.filter((curtain) => curtain.publicUrl);
2480
2512
  const showEmpty = ready.length === 0 && !allowNone;
2513
+ const previewItem = resolvePreviewItem(selectedId, ready, allowNone);
2514
+ const selectedItem = selectedId ? ready.find((curtain) => curtain.id === selectedId) ?? null : null;
2515
+ const actionTarget = selectedItem ?? (!selectable ? previewItem : null);
2516
+ const compactActions = compact ? itemActions(
2517
+ actionTarget,
2518
+ onMakeDefault,
2519
+ onDelete,
2520
+ canMakeDefault,
2521
+ canDelete
2522
+ ) : {};
2481
2523
  const grouped = React7__namespace.useMemo(() => {
2482
2524
  if (!groupByOwner) {
2483
2525
  return [{ group: null, items: ready }];
@@ -2505,46 +2547,174 @@ function CurtainPicker({
2505
2547
  checked: selectedId === null,
2506
2548
  disabled,
2507
2549
  copy,
2550
+ compact,
2508
2551
  onSelect: () => onChange(null)
2509
2552
  }
2510
2553
  ) : null;
2511
- if (grouped.length === 0 && noneTile) {
2512
- return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: cn(gridClass(variant), className), children: /* @__PURE__ */ jsxRuntime.jsx("li", { children: noneTile }) });
2513
- }
2514
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("space-y-6", className), children: grouped.map((section, index) => /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "space-y-3", children: [
2515
- section.group ? /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-muted-foreground text-sm font-medium", children: groupHeading(section.group, copy) }) : null,
2516
- /* @__PURE__ */ jsxRuntime.jsxs("ul", { className: gridClass(variant), children: [
2517
- index === 0 && noneTile ? /* @__PURE__ */ jsxRuntime.jsx("li", { children: noneTile }) : null,
2518
- section.items.map((item) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(
2519
- CurtainPickerCard,
2554
+ const sections = grouped.length === 0 && noneTile ? [{ group: null, items: [] }] : grouped;
2555
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn(compact ? "space-y-4" : "space-y-6", className), children: [
2556
+ compact ? /* @__PURE__ */ jsxRuntime.jsx(
2557
+ SelectedPreview,
2558
+ {
2559
+ item: previewItem,
2560
+ copy,
2561
+ disabled,
2562
+ actionsPending,
2563
+ onMakeDefault: compactActions.onMakeDefault,
2564
+ onDelete: compactActions.onDelete
2565
+ }
2566
+ ) : null,
2567
+ sections.map((section, index) => /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "space-y-3", children: [
2568
+ section.group ? /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-muted-foreground text-sm font-medium", children: groupHeading(section.group, copy) }) : null,
2569
+ /* @__PURE__ */ jsxRuntime.jsxs("ul", { className: gridClass(variant), children: [
2570
+ index === 0 && noneTile ? /* @__PURE__ */ jsxRuntime.jsx("li", { children: noneTile }) : null,
2571
+ section.items.map((item) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(
2572
+ CurtainPickerCard,
2573
+ {
2574
+ item,
2575
+ name: groupName,
2576
+ selectable,
2577
+ checked: selectedId === item.id,
2578
+ disabled,
2579
+ actionsPending,
2580
+ copy,
2581
+ compact,
2582
+ onSelect: onChange ? () => onChange(item.id) : void 0,
2583
+ onMakeDefault: compact ? void 0 : itemActions(
2584
+ item,
2585
+ onMakeDefault,
2586
+ onDelete,
2587
+ canMakeDefault,
2588
+ canDelete
2589
+ ).onMakeDefault,
2590
+ onDelete: compact ? void 0 : itemActions(
2591
+ item,
2592
+ onMakeDefault,
2593
+ onDelete,
2594
+ canMakeDefault,
2595
+ canDelete
2596
+ ).onDelete
2597
+ }
2598
+ ) }, item.id))
2599
+ ] })
2600
+ ] }, section.group ?? "all"))
2601
+ ] });
2602
+ }
2603
+ function SelectedPreview({
2604
+ item,
2605
+ copy,
2606
+ disabled,
2607
+ actionsPending,
2608
+ onMakeDefault,
2609
+ onDelete
2610
+ }) {
2611
+ const owner = item ? ownerLabel(item.ownerType, copy) : null;
2612
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-w-sm space-y-3", children: [
2613
+ item ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2614
+ /* @__PURE__ */ jsxRuntime.jsx(
2615
+ CurtainPreview,
2520
2616
  {
2521
- item,
2522
- name: groupName,
2523
- selectable,
2524
- checked: selectedId === item.id,
2525
- disabled,
2526
- actionsPending,
2527
- copy,
2528
- onSelect: onChange ? () => onChange(item.id) : void 0,
2529
- onMakeDefault: onMakeDefault && (canMakeDefault ? canMakeDefault(item) : !item.isDefault) ? () => onMakeDefault(item) : void 0,
2530
- onDelete: onDelete && (canDelete ? canDelete(item) : true) ? () => onDelete(item) : void 0
2617
+ kind: item.kind,
2618
+ url: item.publicUrl,
2619
+ alt: "",
2620
+ className: "pointer-events-none"
2531
2621
  }
2532
- ) }, item.id))
2533
- ] })
2534
- ] }, section.group ?? "all")) });
2622
+ ),
2623
+ /* @__PURE__ */ jsxRuntime.jsx(
2624
+ ItemMeta,
2625
+ {
2626
+ title: item.title,
2627
+ detail: [kindLabel(item.kind, copy), owner].filter(Boolean).join(" \xB7 "),
2628
+ isDefault: item.isDefault,
2629
+ defaultBadge: copy.defaultBadge
2630
+ }
2631
+ )
2632
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2633
+ /* @__PURE__ */ jsxRuntime.jsx(
2634
+ "div",
2635
+ {
2636
+ className: "aspect-video rounded-md bg-gradient-to-br from-zinc-900 to-zinc-950",
2637
+ "aria-hidden": "true"
2638
+ }
2639
+ ),
2640
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2641
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-medium", children: copy.none }),
2642
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs", children: copy.noneDescription })
2643
+ ] })
2644
+ ] }),
2645
+ /* @__PURE__ */ jsxRuntime.jsx(
2646
+ ManageActions,
2647
+ {
2648
+ disabled,
2649
+ actionsPending,
2650
+ copy,
2651
+ onMakeDefault,
2652
+ onDelete
2653
+ }
2654
+ )
2655
+ ] });
2656
+ }
2657
+ function ItemMeta({
2658
+ title,
2659
+ detail,
2660
+ isDefault,
2661
+ defaultBadge
2662
+ }) {
2663
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-2", children: [
2664
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0", children: [
2665
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate font-medium", children: title }),
2666
+ detail ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs", children: detail }) : null
2667
+ ] }),
2668
+ isDefault ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground shrink-0 text-xs", children: defaultBadge }) : null
2669
+ ] });
2670
+ }
2671
+ function ManageActions({
2672
+ disabled,
2673
+ actionsPending,
2674
+ copy,
2675
+ onMakeDefault,
2676
+ onDelete
2677
+ }) {
2678
+ if (!onMakeDefault && !onDelete) return null;
2679
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-2", children: [
2680
+ onMakeDefault ? /* @__PURE__ */ jsxRuntime.jsx(
2681
+ Button,
2682
+ {
2683
+ type: "button",
2684
+ size: "sm",
2685
+ variant: "secondary",
2686
+ disabled: disabled || actionsPending,
2687
+ onClick: onMakeDefault,
2688
+ children: copy.makeDefault
2689
+ }
2690
+ ) : null,
2691
+ onDelete ? /* @__PURE__ */ jsxRuntime.jsx(
2692
+ Button,
2693
+ {
2694
+ type: "button",
2695
+ size: "sm",
2696
+ variant: "destructive",
2697
+ disabled: disabled || actionsPending,
2698
+ onClick: onDelete,
2699
+ children: copy.delete
2700
+ }
2701
+ ) : null
2702
+ ] });
2535
2703
  }
2536
2704
  function NoneTile({
2537
2705
  name,
2538
2706
  checked,
2539
2707
  disabled,
2540
2708
  copy,
2709
+ compact,
2541
2710
  onSelect
2542
2711
  }) {
2543
2712
  return /* @__PURE__ */ jsxRuntime.jsxs(
2544
2713
  "label",
2545
2714
  {
2546
2715
  className: cn(
2547
- "block cursor-pointer space-y-3 rounded-xl border p-4 transition-shadow",
2716
+ "block cursor-pointer transition-shadow",
2717
+ compact ? "flex min-h-11 flex-col gap-1.5 rounded-lg border p-1.5" : "space-y-3 rounded-xl border p-4",
2548
2718
  "has-[:checked]:ring-ring has-[:checked]:ring-2",
2549
2719
  "has-[:focus-visible]:ring-ring has-[:focus-visible]:ring-2",
2550
2720
  disabled && "pointer-events-none opacity-50"
@@ -2563,7 +2733,7 @@ function NoneTile({
2563
2733
  }
2564
2734
  ),
2565
2735
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aspect-video rounded-md bg-gradient-to-br from-zinc-900 to-zinc-950" }),
2566
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2736
+ compact ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate text-xs font-medium", children: copy.none }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2567
2737
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-medium", children: copy.none }),
2568
2738
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs", children: copy.noneDescription })
2569
2739
  ] })
@@ -2579,25 +2749,36 @@ function CurtainPickerCard({
2579
2749
  disabled,
2580
2750
  actionsPending,
2581
2751
  copy,
2752
+ compact,
2582
2753
  onSelect,
2583
2754
  onMakeDefault,
2584
2755
  onDelete
2585
2756
  }) {
2586
2757
  const owner = ownerLabel(item.ownerType, copy);
2587
- const media = /* @__PURE__ */ jsxRuntime.jsx(CurtainPreview, { kind: item.kind, url: item.publicUrl, alt: item.title });
2588
- const meta = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-2", children: [
2589
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0", children: [
2590
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate font-medium", children: item.title }),
2591
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs", children: [kindLabel(item.kind, copy), owner].filter(Boolean).join(" \xB7 ") })
2592
- ] }),
2593
- item.isDefault ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground shrink-0 text-xs", children: copy.defaultBadge }) : null
2594
- ] });
2758
+ const media = /* @__PURE__ */ jsxRuntime.jsx(
2759
+ CurtainPreview,
2760
+ {
2761
+ kind: item.kind,
2762
+ url: item.publicUrl,
2763
+ alt: item.title,
2764
+ frozen: compact
2765
+ }
2766
+ );
2767
+ const meta = compact ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate text-xs font-medium", children: item.title }) : /* @__PURE__ */ jsxRuntime.jsx(
2768
+ ItemMeta,
2769
+ {
2770
+ title: item.title,
2771
+ detail: [kindLabel(item.kind, copy), owner].filter(Boolean).join(" \xB7 "),
2772
+ isDefault: item.isDefault,
2773
+ defaultBadge: copy.defaultBadge
2774
+ }
2775
+ );
2595
2776
  return /* @__PURE__ */ jsxRuntime.jsxs(
2596
2777
  "div",
2597
2778
  {
2598
2779
  className: cn(
2599
- "space-y-3 rounded-xl border p-4",
2600
- selectable && "has-[:checked]:ring-ring has-[:checked]:ring-2 has-[:focus-visible]:ring-ring has-[:focus-visible]:ring-2",
2780
+ compact ? "rounded-lg border p-1.5" : "space-y-3 rounded-xl border p-4",
2781
+ selectionRing(selectable),
2601
2782
  disabled && "opacity-50"
2602
2783
  ),
2603
2784
  children: [
@@ -2605,7 +2786,7 @@ function CurtainPickerCard({
2605
2786
  "label",
2606
2787
  {
2607
2788
  className: cn(
2608
- "block space-y-3",
2789
+ compact ? "flex min-h-11 flex-col gap-1.5" : "block space-y-3",
2609
2790
  disabled ? "pointer-events-none" : "cursor-pointer"
2610
2791
  ),
2611
2792
  children: [
@@ -2625,34 +2806,20 @@ function CurtainPickerCard({
2625
2806
  meta
2626
2807
  ]
2627
2808
  }
2628
- ) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2809
+ ) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: compact ? "space-y-1.5" : "space-y-3", children: [
2629
2810
  media,
2630
2811
  meta
2631
2812
  ] }),
2632
- onMakeDefault || onDelete ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-2", children: [
2633
- onMakeDefault ? /* @__PURE__ */ jsxRuntime.jsx(
2634
- Button,
2635
- {
2636
- type: "button",
2637
- size: "sm",
2638
- variant: "secondary",
2639
- disabled: disabled || actionsPending,
2640
- onClick: onMakeDefault,
2641
- children: copy.makeDefault
2642
- }
2643
- ) : null,
2644
- onDelete ? /* @__PURE__ */ jsxRuntime.jsx(
2645
- Button,
2646
- {
2647
- type: "button",
2648
- size: "sm",
2649
- variant: "destructive",
2650
- disabled: disabled || actionsPending,
2651
- onClick: onDelete,
2652
- children: copy.delete
2653
- }
2654
- ) : null
2655
- ] }) : null
2813
+ compact ? null : /* @__PURE__ */ jsxRuntime.jsx(
2814
+ ManageActions,
2815
+ {
2816
+ disabled,
2817
+ actionsPending,
2818
+ copy,
2819
+ onMakeDefault,
2820
+ onDelete
2821
+ }
2822
+ )
2656
2823
  ]
2657
2824
  }
2658
2825
  );