@alexgorbatchev/shadcn 0.0.86 → 0.0.87

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.
@@ -2829,6 +2829,7 @@ function StarRating2({
2829
2829
  }
2830
2830
  // src/components/ReviewList.tsx
2831
2831
  import { useRef as useRef3, useState as useState4 } from "react";
2832
+ import { ChevronRightIcon as ChevronRightIcon3 } from "lucide-react";
2832
2833
  import { jsx as jsx29, jsxs as jsxs17 } from "react/jsx-runtime";
2833
2834
  var TOGGLE_KEYS = new Set(["x", "X"]);
2834
2835
  function isMod(event) {
@@ -2837,7 +2838,7 @@ function isMod(event) {
2837
2838
  function isTextEntry(target) {
2838
2839
  return target instanceof HTMLElement && (target.isContentEditable || target.matches("input:not([type='checkbox']), textarea, select"));
2839
2840
  }
2840
- function ReviewList2({ label, rows, onIncludedChange }) {
2841
+ function ReviewList2({ label, rows, onIncludedChange, onExpandedChange }) {
2841
2842
  const [cursor, setCursor] = useState4({ row: 0, cell: 0 });
2842
2843
  const [anchorId, setAnchorId] = useState4();
2843
2844
  const cellsRef = useRef3(new Map);
@@ -2857,8 +2858,9 @@ function ReviewList2({ label, rows, onIncludedChange }) {
2857
2858
  setAnchorId(row.id);
2858
2859
  onIncludedChange([row.id], !row.isIncluded);
2859
2860
  };
2860
- const setRange = (row) => {
2861
- const anchorIndex = Math.max(0, rows.findIndex((candidate) => candidate.id === anchorId));
2861
+ const setRange = (row, fallbackAnchor = 0) => {
2862
+ const found = rows.findIndex((candidate) => candidate.id === anchorId);
2863
+ const anchorIndex = found >= 0 ? found : fallbackAnchor;
2862
2864
  const anchor = rows[anchorIndex];
2863
2865
  if (!anchor)
2864
2866
  return;
@@ -2872,7 +2874,13 @@ function ReviewList2({ label, rows, onIncludedChange }) {
2872
2874
  if (!current)
2873
2875
  return;
2874
2876
  let handled = true;
2875
- if (event.key === "ArrowDown")
2877
+ if ((event.key === "ArrowDown" || event.key === "ArrowUp") && event.shiftKey && !isMod(event)) {
2878
+ const next = event.key === "ArrowDown" ? Math.min(rows.length - 1, rowIndex + 1) : Math.max(0, rowIndex - 1);
2879
+ if (anchorId === undefined)
2880
+ setAnchorId(current.id);
2881
+ focusCell(next, cursor.cell);
2882
+ setRange(next, rowIndex);
2883
+ } else if (event.key === "ArrowDown")
2876
2884
  focusCell(Math.min(rows.length - 1, rowIndex + 1), cursor.cell);
2877
2885
  else if (event.key === "ArrowUp")
2878
2886
  focusCell(Math.max(0, rowIndex - 1), cursor.cell);
@@ -2886,6 +2894,8 @@ function ReviewList2({ label, rows, onIncludedChange }) {
2886
2894
  focusCell(rowIndex, cursor.cell - 1);
2887
2895
  else if (TOGGLE_KEYS.has(event.key) && !isMod(event) || event.key === " " && event.shiftKey)
2888
2896
  toggle(current);
2897
+ else if (event.key === "Enter" && current.isExpanded !== undefined && onExpandedChange && !isMod(event))
2898
+ onExpandedChange(current.id, !current.isExpanded);
2889
2899
  else if (event.key.toLowerCase() === "a" && isMod(event))
2890
2900
  onIncludedChange(rows.map((row) => row.id), true);
2891
2901
  else
@@ -2902,9 +2912,10 @@ function ReviewList2({ label, rows, onIncludedChange }) {
2902
2912
  setAnchorId(row.id);
2903
2913
  setCursor({ row: index, cell });
2904
2914
  };
2915
+ const isTree = rows.some((row) => row.level !== undefined);
2905
2916
  return /* @__PURE__ */ jsx29("div", {
2906
2917
  "data-slot": "review-list",
2907
- role: "grid",
2918
+ role: isTree ? "treegrid" : "grid",
2908
2919
  "aria-label": label,
2909
2920
  "aria-rowcount": rows.length,
2910
2921
  className: "flex min-w-0 flex-col gap-0.5",
@@ -2922,6 +2933,8 @@ function ReviewList2({ label, rows, onIncludedChange }) {
2922
2933
  return /* @__PURE__ */ jsxs17("div", {
2923
2934
  role: "row",
2924
2935
  "aria-rowindex": index + 1,
2936
+ "aria-level": isTree ? row.level ?? 1 : undefined,
2937
+ "aria-expanded": row.isExpanded,
2925
2938
  "data-included": row.isIncluded || undefined,
2926
2939
  className: cn2("flex min-w-0 items-start gap-2 rounded-sm px-1 py-0.5 focus-within:bg-accent/50", !row.isIncluded && "text-muted-foreground"),
2927
2940
  children: [
@@ -2934,6 +2947,7 @@ function ReviewList2({ label, rows, onIncludedChange }) {
2934
2947
  children: /* @__PURE__ */ jsx29(Checkbox2, {
2935
2948
  "aria-label": row.checkboxLabel,
2936
2949
  checked: row.isIncluded,
2950
+ indeterminate: row.isIndeterminate,
2937
2951
  tabIndex: -1,
2938
2952
  onCheckedChange: (_checked, details) => {
2939
2953
  const native = details.event;
@@ -2943,13 +2957,37 @@ function ReviewList2({ label, rows, onIncludedChange }) {
2943
2957
  }
2944
2958
  })
2945
2959
  }),
2946
- /* @__PURE__ */ jsx29("div", {
2960
+ /* @__PURE__ */ jsxs17("div", {
2947
2961
  ref: cellRef(1),
2948
2962
  role: "gridcell",
2949
2963
  tabIndex: tabIndex(1),
2950
- className: "min-w-0 flex-1 outline-none focus-visible:ring-1 focus-visible:ring-ring",
2964
+ className: "flex min-w-0 flex-1 items-start gap-1 outline-none focus-visible:ring-1 focus-visible:ring-ring",
2965
+ style: isTree ? { paddingInlineStart: `${((row.level ?? 1) - 1) * 1.25}rem` } : undefined,
2951
2966
  onClick: (event) => onRowClick(event, row, index, 1),
2952
- children: row.content
2967
+ children: [
2968
+ isTree && /* @__PURE__ */ jsx29("span", {
2969
+ className: "flex size-5 shrink-0 items-center justify-center",
2970
+ children: row.isExpanded !== undefined && /* @__PURE__ */ jsx29("button", {
2971
+ type: "button",
2972
+ tabIndex: -1,
2973
+ "aria-hidden": "true",
2974
+ "data-slot": "review-list-disclosure",
2975
+ className: "flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:bg-accent",
2976
+ onClick: (event) => {
2977
+ event.stopPropagation();
2978
+ setCursor({ row: index, cell: 1 });
2979
+ onExpandedChange?.(row.id, !row.isExpanded);
2980
+ },
2981
+ children: /* @__PURE__ */ jsx29(ChevronRightIcon3, {
2982
+ className: cn2("size-4 transition-transform", row.isExpanded && "rotate-90")
2983
+ })
2984
+ })
2985
+ }),
2986
+ /* @__PURE__ */ jsx29("div", {
2987
+ className: "min-w-0 flex-1",
2988
+ children: row.content
2989
+ })
2990
+ ]
2953
2991
  }),
2954
2992
  row.cells?.map((cell, offset) => /* @__PURE__ */ jsx29("div", {
2955
2993
  ref: cellRef(offset + 2),
@@ -9,18 +9,29 @@ export interface IReviewListRow {
9
9
  content: ReactNode;
10
10
  /** Further cells with their own controls, which ← and → reach; give those controls `tabIndex={-1}`. */
11
11
  cells?: readonly ReactNode[];
12
+ /** The row's depth in a tree review, from 1; any row with a level makes the list a tree grid. */
13
+ level?: number;
14
+ /** Whether a row with children shows them; leave unset on rows without children. Enter toggles it. */
15
+ isExpanded?: boolean;
16
+ /** Some but not all of the row's children are included; the checkbox shows the mixed state. */
17
+ isIndeterminate?: boolean;
12
18
  }
13
19
  interface IReviewListProps {
14
20
  label: string;
15
21
  rows: readonly IReviewListRow[];
16
22
  /** Sets the inclusion of these rows; a range or Mod+A changes several at once. */
17
23
  onIncludedChange: (ids: readonly string[], isIncluded: boolean) => void;
24
+ /** Shows or hides a row's children: Enter on the row or its disclosure. The consumer drops hidden rows. */
25
+ onExpandedChange?: (id: string, isExpanded: boolean) => void;
18
26
  }
19
27
  /**
20
28
  * A plan's review rows, where a tick means "include this change". It is one tab stop with a cursor: ↑/↓, Home and End
21
29
  * move between rows and ← and → between a row's cells. A click only moves the cursor, so a stray click never changes
22
30
  * what the plan includes; the checkbox, Mod+click, X and Shift+Space toggle a row, Shift+click sets the range from the
23
- * anchor row to the anchor's state, and Mod+A includes every row. Space is left to the page, such as a player.
31
+ * anchor row to the anchor's state, and Mod+A includes every row. Shift+↑ and Shift+↓ move the cursor and set the range
32
+ * from the anchor to it the same way. Space is left to the page, such as a player. Rows with a `level` form a tree:
33
+ * Enter or the disclosure shows or hides a row's children, and a row whose children are partly included shows a mixed
34
+ * checkbox.
24
35
  */
25
- export declare function ReviewList({ label, rows, onIncludedChange }: IReviewListProps): ReactElement;
36
+ export declare function ReviewList({ label, rows, onIncludedChange, onExpandedChange }: IReviewListProps): ReactElement;
26
37
  export {};
@@ -31,7 +31,7 @@ import {
31
31
  DrawerHeader2,
32
32
  DrawerTitle2,
33
33
  DrawerDescription2
34
- } from "../../chunk-8cxqbmh5.js";
34
+ } from "../../chunk-h2xvhydx.js";
35
35
  import {
36
36
  MenuPopup,
37
37
  MenuItem2,
package/dist/index.js CHANGED
@@ -175,7 +175,7 @@ import {
175
175
  StatusTracker2,
176
176
  DashboardLayout2,
177
177
  BillingUsage2
178
- } from "./chunk-8cxqbmh5.js";
178
+ } from "./chunk-h2xvhydx.js";
179
179
  import {
180
180
  Combobox2,
181
181
  ComboboxValue2,
package/dist/prototype.js CHANGED
@@ -2051,7 +2051,7 @@ var program = new Command;
2051
2051
  // package.json
2052
2052
  var package_default = {
2053
2053
  name: "@alexgorbatchev/shadcn",
2054
- version: "0.0.86",
2054
+ version: "0.0.87",
2055
2055
  description: "Sharp, monospace React components with compact and comfortable densities.",
2056
2056
  license: "MIT",
2057
2057
  repository: {
@@ -50,3 +50,11 @@ Storybook CSF excerpts. Default args and render apply unless overridden. Local h
50
50
  ```tsx
51
51
  {}
52
52
  ```
53
+
54
+ ### TreeGestures
55
+
56
+ ```tsx
57
+ {
58
+ render: () => <TreeReviewListExample />
59
+ }
60
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexgorbatchev/shadcn",
3
- "version": "0.0.86",
3
+ "version": "0.0.87",
4
4
  "description": "Sharp, monospace React components with compact and comfortable densities.",
5
5
  "license": "MIT",
6
6
  "repository": {