@dynostack/react-grid 0.4.0 → 0.5.1

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/index.cjs CHANGED
@@ -1914,7 +1914,7 @@ function EditableCell({
1914
1914
  {
1915
1915
  className: cn(
1916
1916
  "flex h-7 items-center gap-1.5 rounded px-1.5 text-sm",
1917
- isEditable && "cursor-text outline-1 outline-transparent transition-colors hover:bg-muted/60 hover:outline-border",
1917
+ isEditable && "cursor-text transition-colors hover:bg-muted/60",
1918
1918
  align === "right" && "justify-end",
1919
1919
  align === "center" && "justify-center"
1920
1920
  ),
@@ -1937,6 +1937,7 @@ function EditableCell({
1937
1937
  return /* @__PURE__ */ jsxRuntime.jsx(
1938
1938
  "select",
1939
1939
  {
1940
+ "data-cell-editor": "",
1940
1941
  value: String(local ?? ""),
1941
1942
  onChange: (e) => {
1942
1943
  setLocal(e.target.value);
@@ -1958,7 +1959,15 @@ function EditableCell({
1958
1959
  value: String(local ?? ""),
1959
1960
  onValueChange: (v) => commit(v),
1960
1961
  children: [
1961
- /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { size: "sm", className: "h-7 w-full text-xs", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, {}) }),
1962
+ /* @__PURE__ */ jsxRuntime.jsx(
1963
+ SelectTrigger,
1964
+ {
1965
+ "data-cell-editor": "",
1966
+ size: "sm",
1967
+ className: "h-7 w-full text-xs focus-visible:ring-0",
1968
+ children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, {})
1969
+ }
1970
+ ),
1962
1971
  /* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: opts.map((o) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: o.value, children: o.label }, o.value)) })
1963
1972
  ]
1964
1973
  }
@@ -1968,6 +1977,8 @@ function EditableCell({
1968
1977
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-7 items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1969
1978
  Checkbox,
1970
1979
  {
1980
+ "data-cell-editor": "",
1981
+ className: "focus-visible:ring-0",
1971
1982
  checked: !!local,
1972
1983
  onCheckedChange: (c) => commit(!!c),
1973
1984
  autoFocus: true
@@ -1977,6 +1988,7 @@ function EditableCell({
1977
1988
  return /* @__PURE__ */ jsxRuntime.jsx(
1978
1989
  Input,
1979
1990
  {
1991
+ "data-cell-editor": "",
1980
1992
  ref: inputRef,
1981
1993
  type: editor === "number" || editor === "currency" ? "number" : editor === "date" ? "date" : "text",
1982
1994
  value: local == null ? "" : String(local),
@@ -1990,7 +2002,7 @@ function EditableCell({
1990
2002
  onBlur: () => commit(local),
1991
2003
  onKeyDown: handleKey,
1992
2004
  className: cn(
1993
- "h-7 px-1.5 text-sm",
2005
+ "h-7 px-1.5 text-sm focus-visible:ring-0",
1994
2006
  align === "right" && "text-right",
1995
2007
  align === "center" && "text-center"
1996
2008
  )
@@ -2107,7 +2119,7 @@ function buildPreset(hue, chroma = 0.03) {
2107
2119
  border: `oklch(0.9 ${c * 0.8} ${hue})`,
2108
2120
  input: `oklch(0.9 ${c * 0.8} ${hue})`,
2109
2121
  ring: `oklch(0.55 0.2 ${hue} / 0.5)`,
2110
- radius: "0.625rem"
2122
+ radius: "0.375rem"
2111
2123
  },
2112
2124
  dark: {
2113
2125
  background: `oklch(0.16 ${c * 0.6} ${hue})`,
@@ -2129,7 +2141,7 @@ function buildPreset(hue, chroma = 0.03) {
2129
2141
  border: `oklch(0.27 ${c * 0.8} ${hue})`,
2130
2142
  input: `oklch(0.27 ${c * 0.8} ${hue})`,
2131
2143
  ring: `oklch(0.7 0.18 ${hue} / 0.5)`,
2132
- radius: "0.625rem"
2144
+ radius: "0.375rem"
2133
2145
  }
2134
2146
  };
2135
2147
  }
@@ -2169,7 +2181,7 @@ var neutral = {
2169
2181
  border: "oklch(0.922 0 0)",
2170
2182
  input: "oklch(0.922 0 0)",
2171
2183
  ring: "oklch(0.708 0 0)",
2172
- radius: "0.625rem"
2184
+ radius: "0.375rem"
2173
2185
  },
2174
2186
  dark: {
2175
2187
  background: "oklch(0.145 0 0)",
@@ -2191,11 +2203,38 @@ var neutral = {
2191
2203
  border: "oklch(0.269 0 0)",
2192
2204
  input: "oklch(0.269 0 0)",
2193
2205
  ring: "oklch(0.439 0 0)",
2194
- radius: "0.625rem"
2206
+ radius: "0.375rem"
2195
2207
  }
2196
2208
  };
2197
2209
  var themePresets = {
2198
2210
  neutral,
2211
+ graphite: {
2212
+ light: {
2213
+ ...neutral.light,
2214
+ background: "#fafafa",
2215
+ card: "#ffffff",
2216
+ border: "#e5e5e5",
2217
+ radius: "0.375rem",
2218
+ fontFamily: "'Geist', sans-serif"
2219
+ },
2220
+ dark: {
2221
+ ...neutral.dark,
2222
+ background: "#101112",
2223
+ card: "#101112",
2224
+ popover: "#17191b",
2225
+ border: "#292c2f",
2226
+ input: "#303438",
2227
+ muted: "#1b1e21",
2228
+ mutedForeground: "#9ba2aa",
2229
+ accent: "#24282d",
2230
+ primary: "#edf0f3",
2231
+ primaryForeground: "#101112",
2232
+ ring: "#84b8ff",
2233
+ destructive: "#fb7185",
2234
+ radius: "0.375rem",
2235
+ fontFamily: "'Geist', sans-serif"
2236
+ }
2237
+ },
2199
2238
  light: { light: neutral.light },
2200
2239
  dark: { light: neutral.dark },
2201
2240
  violet: buildPreset(285),
@@ -2559,9 +2598,7 @@ function getPinningStyles(column) {
2559
2598
  boxShadow: isLast ? "1px 0 0 0 var(--border)" : isFirst ? "-1px 0 0 0 var(--border)" : void 0
2560
2599
  };
2561
2600
  }
2562
- var DataTableEditingContext = react.createContext(
2563
- null
2564
- );
2601
+ var DataTableEditingContext = react.createContext(null);
2565
2602
  function useEditingContext() {
2566
2603
  const ctx = react.useContext(DataTableEditingContext);
2567
2604
  if (!ctx) throw new Error("DataTable editing context missing");
@@ -2572,13 +2609,7 @@ function DefaultCellHost(ctx) {
2572
2609
  return value == null ? null : String(value);
2573
2610
  }
2574
2611
  function EditableCellHost(ctx) {
2575
- const {
2576
- editingCell,
2577
- editingRowId,
2578
- setEditingCell,
2579
- setRowDraft,
2580
- onCellEdit
2581
- } = useEditingContext();
2612
+ const { editingCell, editingRowId, setEditingCell, setRowDraft, onCellEdit } = useEditingContext();
2582
2613
  const colId = ctx.column.id;
2583
2614
  const rowId = ctx.row.id;
2584
2615
  const isCellEdit = editingCell?.rowId === rowId && editingCell.colId === colId;
@@ -2755,12 +2786,13 @@ function DataTable({
2755
2786
  () => `dyno-grid-${rawInstanceId.replace(/[^a-zA-Z0-9]/g, "")}`,
2756
2787
  [rawInstanceId]
2757
2788
  );
2758
- const { lightStyle, darkCss } = react.useMemo(() => {
2789
+ const { lightStyle, lightCss, darkCss } = react.useMemo(() => {
2759
2790
  const { light, dark } = splitTheme(theme);
2760
2791
  const lightTokens = isolate ? { ...ISOLATE_LIGHT_TOKENS, ...light ?? {} } : light;
2761
2792
  const darkTokens = isolate ? { ...ISOLATE_DARK_TOKENS, ...dark ?? light ?? {} } : dark;
2762
2793
  return {
2763
2794
  lightStyle: tokensToStyle(lightTokens),
2795
+ lightCss: tokensToCssBlock(lightTokens),
2764
2796
  darkCss: darkTokens ? tokensToCssBlock(darkTokens) : null
2765
2797
  };
2766
2798
  }, [theme, isolate]);
@@ -2810,19 +2842,17 @@ function DataTable({
2810
2842
  const [columnVisibility, setColumnVisibility] = react.useState(
2811
2843
  initialColumnVisibility ?? {}
2812
2844
  );
2813
- const [columnPinning, setColumnPinning] = react.useState(
2814
- () => {
2815
- const base = initialColumnPinning ?? { left: [], right: [] };
2816
- const left = [...base.left ?? []];
2817
- const right = [...base.right ?? []];
2818
- const hasExpandColumn = !!(renderSubRow || getSubRows);
2819
- if (hasExpandColumn && left.includes("__select") && !left.includes("__expand")) {
2820
- const idx = left.indexOf("__select");
2821
- left.splice(idx + 1, 0, "__expand");
2822
- }
2823
- return { left, right };
2845
+ const [columnPinning, setColumnPinning] = react.useState(() => {
2846
+ const base = initialColumnPinning ?? { left: [], right: [] };
2847
+ const left = [...base.left ?? []];
2848
+ const right = [...base.right ?? []];
2849
+ const hasExpandColumn = !!(renderSubRow || getSubRows);
2850
+ if (hasExpandColumn && left.includes("__select") && !left.includes("__expand")) {
2851
+ const idx = left.indexOf("__select");
2852
+ left.splice(idx + 1, 0, "__expand");
2824
2853
  }
2825
- );
2854
+ return { left, right };
2855
+ });
2826
2856
  const [columnSizing, setColumnSizing] = react.useState({});
2827
2857
  const [rowSelection, setRowSelection] = react.useState({});
2828
2858
  const [expanded, setExpanded] = react.useState({});
@@ -3008,7 +3038,9 @@ function DataTable({
3008
3038
  customRowActions?.length
3009
3039
  ]);
3010
3040
  const [columnOrder, setColumnOrder] = react.useState(
3011
- () => augmentedColumns.map((c) => c.id ?? c.accessorKey ?? "")
3041
+ () => augmentedColumns.map(
3042
+ (c) => c.id ?? c.accessorKey ?? ""
3043
+ )
3012
3044
  );
3013
3045
  react.useEffect(() => {
3014
3046
  const next = augmentedColumns.map(
@@ -3146,7 +3178,9 @@ function DataTable({
3146
3178
  const selectionCallback = react.useRef(onSelectionChange);
3147
3179
  selectionCallback.current = onSelectionChange;
3148
3180
  react.useEffect(() => {
3149
- selectionCallback.current?.(table.getSelectedRowModel().flatRows.map((row) => row.original));
3181
+ selectionCallback.current?.(
3182
+ table.getSelectedRowModel().flatRows.map((row) => row.original)
3183
+ );
3150
3184
  }, [rowSelection, mergedData, table]);
3151
3185
  const visibleLeafCount = table.getVisibleLeafColumns().length;
3152
3186
  const editingContextValue = react.useMemo(
@@ -3198,12 +3232,15 @@ function DataTable({
3198
3232
  DENSITY_CLASS[density],
3199
3233
  className
3200
3234
  ),
3201
- style: lightStyle,
3235
+ style: darkCss ? void 0 : lightStyle,
3202
3236
  children: [
3203
3237
  darkCss && /* @__PURE__ */ jsxRuntime.jsxs("style", { children: [
3238
+ `[data-dyno-grid="${instanceId}"]{${lightCss}}`,
3204
3239
  `@media (prefers-color-scheme: dark){[data-dyno-grid="${instanceId}"]{${darkCss}}}`,
3205
3240
  `.dark [data-dyno-grid="${instanceId}"]{${darkCss}}`,
3206
- `[data-dyno-grid="${instanceId}"].dark{${darkCss}}`
3241
+ `.light [data-dyno-grid="${instanceId}"]{${lightCss}}`,
3242
+ `[data-dyno-grid="${instanceId}"].dark{${darkCss}}`,
3243
+ `[data-dyno-grid="${instanceId}"].light{${lightCss}}`
3207
3244
  ] }),
3208
3245
  /* @__PURE__ */ jsxRuntime.jsx(
3209
3246
  DataTableToolbar,
@@ -3230,71 +3267,83 @@ function DataTable({
3230
3267
  "table",
3231
3268
  {
3232
3269
  "aria-label": ariaLabel,
3233
- className: cn("w-full caption-bottom text-sm", striped && "[&_tbody>tr:nth-child(even)]:bg-muted/25"),
3270
+ className: cn(
3271
+ "w-full caption-bottom text-sm",
3272
+ striped && "[&_tbody>tr:nth-child(even)]:bg-muted/25"
3273
+ ),
3234
3274
  style: {
3235
3275
  width: table.getCenterTotalSize() ? void 0 : "100%",
3236
3276
  minWidth: "100%"
3237
3277
  },
3238
3278
  children: [
3239
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: cn("bg-card", stickyHeader && "sticky top-0 z-10"), children: table.getHeaderGroups().map((hg) => /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "border-b", children: hg.headers.map((header) => {
3240
- const meta = header.column.columnDef.meta;
3241
- const isUtility = header.column.id === "__select" || header.column.id === "__expand" || header.column.id === "__actions";
3242
- const isPinned = !!header.column.getIsPinned();
3243
- const canReorder = !isUtility && f.reordering;
3244
- const isDropTarget = canReorder && dragOverColId === header.column.id;
3245
- const isBeingDragged = canReorder && activeReorderId === header.column.id;
3246
- return /* @__PURE__ */ jsxRuntime.jsxs(
3247
- "th",
3248
- {
3249
- colSpan: header.colSpan,
3250
- "data-col-id": header.column.id,
3251
- onPointerDown: canReorder ? onHeaderPointerDown(header.column.id) : void 0,
3252
- onPointerMove: canReorder ? onHeaderPointerMove : void 0,
3253
- onPointerUp: canReorder ? onHeaderPointerUp : void 0,
3254
- onPointerCancel: canReorder ? onHeaderPointerUp : void 0,
3255
- style: {
3256
- width: header.getSize(),
3257
- ...getPinningStyles(header.column),
3258
- ...isPinned ? { zIndex: 2 } : {}
3259
- },
3260
- className: cn(
3261
- "group/th relative h-9 px-2 text-left align-middle text-xs font-medium text-muted-foreground select-none",
3262
- canReorder && "cursor-grab active:cursor-grabbing",
3263
- isPinned && "bg-card",
3264
- isBeingDragged && "opacity-50",
3265
- isDropTarget && "bg-primary/10 ring-2 ring-inset ring-primary/40",
3266
- meta?.headerClassName
3267
- ),
3268
- children: [
3269
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [
3270
- canReorder && /* @__PURE__ */ jsxRuntime.jsx(
3271
- lucideReact.GripVerticalIcon,
3272
- {
3273
- className: "-ml-1 size-3 shrink-0 text-muted-foreground/40 opacity-0 transition group-hover/th:opacity-100",
3274
- "aria-hidden": "true"
3275
- }
3279
+ /* @__PURE__ */ jsxRuntime.jsx(
3280
+ "thead",
3281
+ {
3282
+ className: cn("bg-card", stickyHeader && "sticky top-0 z-10"),
3283
+ children: table.getHeaderGroups().map((hg) => /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "border-b", children: hg.headers.map((header) => {
3284
+ const meta = header.column.columnDef.meta;
3285
+ const isUtility = header.column.id === "__select" || header.column.id === "__expand" || header.column.id === "__actions";
3286
+ const isPinned = !!header.column.getIsPinned();
3287
+ const canReorder = !isUtility && f.reordering;
3288
+ const isDropTarget = canReorder && dragOverColId === header.column.id;
3289
+ const isBeingDragged = canReorder && activeReorderId === header.column.id;
3290
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3291
+ "th",
3292
+ {
3293
+ colSpan: header.colSpan,
3294
+ "data-col-id": header.column.id,
3295
+ onPointerDown: canReorder ? onHeaderPointerDown(header.column.id) : void 0,
3296
+ onPointerMove: canReorder ? onHeaderPointerMove : void 0,
3297
+ onPointerUp: canReorder ? onHeaderPointerUp : void 0,
3298
+ onPointerCancel: canReorder ? onHeaderPointerUp : void 0,
3299
+ style: {
3300
+ width: header.getSize(),
3301
+ ...getPinningStyles(header.column),
3302
+ ...isPinned ? { zIndex: 2 } : {}
3303
+ },
3304
+ className: cn(
3305
+ "group/th relative h-9 px-2 text-left align-middle text-xs font-medium text-muted-foreground select-none",
3306
+ canReorder && "cursor-grab active:cursor-grabbing",
3307
+ isPinned && "bg-card",
3308
+ isBeingDragged && "opacity-50",
3309
+ isDropTarget && "bg-primary/10 ring-2 ring-primary/40 ring-inset",
3310
+ meta?.headerClassName
3276
3311
  ),
3277
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 flex-1", children: header.isPlaceholder ? null : reactTable.flexRender(header.column.columnDef.header, header.getContext()) })
3278
- ] }),
3279
- header.column.getCanResize() && /* @__PURE__ */ jsxRuntime.jsx(
3280
- "span",
3281
- {
3282
- "data-no-drag": true,
3283
- onPointerDown: (e) => e.stopPropagation(),
3284
- onMouseDown: header.getResizeHandler(),
3285
- onTouchStart: header.getResizeHandler(),
3286
- onDoubleClick: () => header.column.resetSize(),
3287
- className: cn(
3288
- "absolute top-0 right-0 h-full w-1 cursor-col-resize touch-none select-none bg-transparent transition-colors hover:bg-primary/40",
3289
- header.column.getIsResizing() && "bg-primary"
3312
+ children: [
3313
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [
3314
+ canReorder && /* @__PURE__ */ jsxRuntime.jsx(
3315
+ lucideReact.GripVerticalIcon,
3316
+ {
3317
+ className: "-ml-1 size-3 shrink-0 text-muted-foreground/40 opacity-0 transition group-hover/th:opacity-100",
3318
+ "aria-hidden": "true"
3319
+ }
3320
+ ),
3321
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 flex-1", children: header.isPlaceholder ? null : reactTable.flexRender(
3322
+ header.column.columnDef.header,
3323
+ header.getContext()
3324
+ ) })
3325
+ ] }),
3326
+ header.column.getCanResize() && /* @__PURE__ */ jsxRuntime.jsx(
3327
+ "span",
3328
+ {
3329
+ "data-no-drag": true,
3330
+ onPointerDown: (e) => e.stopPropagation(),
3331
+ onMouseDown: header.getResizeHandler(),
3332
+ onTouchStart: header.getResizeHandler(),
3333
+ onDoubleClick: () => header.column.resetSize(),
3334
+ className: cn(
3335
+ "absolute top-0 right-0 h-full w-1 cursor-col-resize touch-none bg-transparent transition-colors select-none hover:bg-primary/40",
3336
+ header.column.getIsResizing() && "bg-primary"
3337
+ )
3338
+ }
3290
3339
  )
3291
- }
3292
- )
3293
- ]
3294
- },
3295
- header.id
3296
- );
3297
- }) }, hg.id)) }),
3340
+ ]
3341
+ },
3342
+ header.id
3343
+ );
3344
+ }) }, hg.id))
3345
+ }
3346
+ ),
3298
3347
  /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: effectiveIsLoading ? renderSkeleton(visibleLeafCount, pagination.pageSize) : sourceError && rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx(
3299
3348
  "td",
3300
3349
  {
@@ -3338,7 +3387,13 @@ function DataTable({
3338
3387
  labels.refreshing
3339
3388
  ] })
3340
3389
  ] }),
3341
- f.pagination && /* @__PURE__ */ jsxRuntime.jsx(DataTablePagination, { table, pageSizeOptions }),
3390
+ f.pagination && /* @__PURE__ */ jsxRuntime.jsx(
3391
+ DataTablePagination,
3392
+ {
3393
+ table,
3394
+ pageSizeOptions
3395
+ }
3396
+ ),
3342
3397
  /* @__PURE__ */ jsxRuntime.jsx(
3343
3398
  DataTableViewSheet,
3344
3399
  {