@dynostack/react-grid 0.4.0 → 0.5.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/dist/index.cjs CHANGED
@@ -2107,7 +2107,7 @@ function buildPreset(hue, chroma = 0.03) {
2107
2107
  border: `oklch(0.9 ${c * 0.8} ${hue})`,
2108
2108
  input: `oklch(0.9 ${c * 0.8} ${hue})`,
2109
2109
  ring: `oklch(0.55 0.2 ${hue} / 0.5)`,
2110
- radius: "0.625rem"
2110
+ radius: "0.375rem"
2111
2111
  },
2112
2112
  dark: {
2113
2113
  background: `oklch(0.16 ${c * 0.6} ${hue})`,
@@ -2129,7 +2129,7 @@ function buildPreset(hue, chroma = 0.03) {
2129
2129
  border: `oklch(0.27 ${c * 0.8} ${hue})`,
2130
2130
  input: `oklch(0.27 ${c * 0.8} ${hue})`,
2131
2131
  ring: `oklch(0.7 0.18 ${hue} / 0.5)`,
2132
- radius: "0.625rem"
2132
+ radius: "0.375rem"
2133
2133
  }
2134
2134
  };
2135
2135
  }
@@ -2169,7 +2169,7 @@ var neutral = {
2169
2169
  border: "oklch(0.922 0 0)",
2170
2170
  input: "oklch(0.922 0 0)",
2171
2171
  ring: "oklch(0.708 0 0)",
2172
- radius: "0.625rem"
2172
+ radius: "0.375rem"
2173
2173
  },
2174
2174
  dark: {
2175
2175
  background: "oklch(0.145 0 0)",
@@ -2191,11 +2191,38 @@ var neutral = {
2191
2191
  border: "oklch(0.269 0 0)",
2192
2192
  input: "oklch(0.269 0 0)",
2193
2193
  ring: "oklch(0.439 0 0)",
2194
- radius: "0.625rem"
2194
+ radius: "0.375rem"
2195
2195
  }
2196
2196
  };
2197
2197
  var themePresets = {
2198
2198
  neutral,
2199
+ graphite: {
2200
+ light: {
2201
+ ...neutral.light,
2202
+ background: "#fafafa",
2203
+ card: "#ffffff",
2204
+ border: "#e5e5e5",
2205
+ radius: "0.375rem",
2206
+ fontFamily: "'Geist', sans-serif"
2207
+ },
2208
+ dark: {
2209
+ ...neutral.dark,
2210
+ background: "#101112",
2211
+ card: "#101112",
2212
+ popover: "#17191b",
2213
+ border: "#292c2f",
2214
+ input: "#303438",
2215
+ muted: "#1b1e21",
2216
+ mutedForeground: "#9ba2aa",
2217
+ accent: "#24282d",
2218
+ primary: "#edf0f3",
2219
+ primaryForeground: "#101112",
2220
+ ring: "#84b8ff",
2221
+ destructive: "#fb7185",
2222
+ radius: "0.375rem",
2223
+ fontFamily: "'Geist', sans-serif"
2224
+ }
2225
+ },
2199
2226
  light: { light: neutral.light },
2200
2227
  dark: { light: neutral.dark },
2201
2228
  violet: buildPreset(285),
@@ -2559,9 +2586,7 @@ function getPinningStyles(column) {
2559
2586
  boxShadow: isLast ? "1px 0 0 0 var(--border)" : isFirst ? "-1px 0 0 0 var(--border)" : void 0
2560
2587
  };
2561
2588
  }
2562
- var DataTableEditingContext = react.createContext(
2563
- null
2564
- );
2589
+ var DataTableEditingContext = react.createContext(null);
2565
2590
  function useEditingContext() {
2566
2591
  const ctx = react.useContext(DataTableEditingContext);
2567
2592
  if (!ctx) throw new Error("DataTable editing context missing");
@@ -2572,13 +2597,7 @@ function DefaultCellHost(ctx) {
2572
2597
  return value == null ? null : String(value);
2573
2598
  }
2574
2599
  function EditableCellHost(ctx) {
2575
- const {
2576
- editingCell,
2577
- editingRowId,
2578
- setEditingCell,
2579
- setRowDraft,
2580
- onCellEdit
2581
- } = useEditingContext();
2600
+ const { editingCell, editingRowId, setEditingCell, setRowDraft, onCellEdit } = useEditingContext();
2582
2601
  const colId = ctx.column.id;
2583
2602
  const rowId = ctx.row.id;
2584
2603
  const isCellEdit = editingCell?.rowId === rowId && editingCell.colId === colId;
@@ -2755,12 +2774,13 @@ function DataTable({
2755
2774
  () => `dyno-grid-${rawInstanceId.replace(/[^a-zA-Z0-9]/g, "")}`,
2756
2775
  [rawInstanceId]
2757
2776
  );
2758
- const { lightStyle, darkCss } = react.useMemo(() => {
2777
+ const { lightStyle, lightCss, darkCss } = react.useMemo(() => {
2759
2778
  const { light, dark } = splitTheme(theme);
2760
2779
  const lightTokens = isolate ? { ...ISOLATE_LIGHT_TOKENS, ...light ?? {} } : light;
2761
2780
  const darkTokens = isolate ? { ...ISOLATE_DARK_TOKENS, ...dark ?? light ?? {} } : dark;
2762
2781
  return {
2763
2782
  lightStyle: tokensToStyle(lightTokens),
2783
+ lightCss: tokensToCssBlock(lightTokens),
2764
2784
  darkCss: darkTokens ? tokensToCssBlock(darkTokens) : null
2765
2785
  };
2766
2786
  }, [theme, isolate]);
@@ -2810,19 +2830,17 @@ function DataTable({
2810
2830
  const [columnVisibility, setColumnVisibility] = react.useState(
2811
2831
  initialColumnVisibility ?? {}
2812
2832
  );
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 };
2833
+ const [columnPinning, setColumnPinning] = react.useState(() => {
2834
+ const base = initialColumnPinning ?? { left: [], right: [] };
2835
+ const left = [...base.left ?? []];
2836
+ const right = [...base.right ?? []];
2837
+ const hasExpandColumn = !!(renderSubRow || getSubRows);
2838
+ if (hasExpandColumn && left.includes("__select") && !left.includes("__expand")) {
2839
+ const idx = left.indexOf("__select");
2840
+ left.splice(idx + 1, 0, "__expand");
2824
2841
  }
2825
- );
2842
+ return { left, right };
2843
+ });
2826
2844
  const [columnSizing, setColumnSizing] = react.useState({});
2827
2845
  const [rowSelection, setRowSelection] = react.useState({});
2828
2846
  const [expanded, setExpanded] = react.useState({});
@@ -3008,7 +3026,9 @@ function DataTable({
3008
3026
  customRowActions?.length
3009
3027
  ]);
3010
3028
  const [columnOrder, setColumnOrder] = react.useState(
3011
- () => augmentedColumns.map((c) => c.id ?? c.accessorKey ?? "")
3029
+ () => augmentedColumns.map(
3030
+ (c) => c.id ?? c.accessorKey ?? ""
3031
+ )
3012
3032
  );
3013
3033
  react.useEffect(() => {
3014
3034
  const next = augmentedColumns.map(
@@ -3146,7 +3166,9 @@ function DataTable({
3146
3166
  const selectionCallback = react.useRef(onSelectionChange);
3147
3167
  selectionCallback.current = onSelectionChange;
3148
3168
  react.useEffect(() => {
3149
- selectionCallback.current?.(table.getSelectedRowModel().flatRows.map((row) => row.original));
3169
+ selectionCallback.current?.(
3170
+ table.getSelectedRowModel().flatRows.map((row) => row.original)
3171
+ );
3150
3172
  }, [rowSelection, mergedData, table]);
3151
3173
  const visibleLeafCount = table.getVisibleLeafColumns().length;
3152
3174
  const editingContextValue = react.useMemo(
@@ -3198,12 +3220,15 @@ function DataTable({
3198
3220
  DENSITY_CLASS[density],
3199
3221
  className
3200
3222
  ),
3201
- style: lightStyle,
3223
+ style: darkCss ? void 0 : lightStyle,
3202
3224
  children: [
3203
3225
  darkCss && /* @__PURE__ */ jsxRuntime.jsxs("style", { children: [
3226
+ `[data-dyno-grid="${instanceId}"]{${lightCss}}`,
3204
3227
  `@media (prefers-color-scheme: dark){[data-dyno-grid="${instanceId}"]{${darkCss}}}`,
3205
3228
  `.dark [data-dyno-grid="${instanceId}"]{${darkCss}}`,
3206
- `[data-dyno-grid="${instanceId}"].dark{${darkCss}}`
3229
+ `.light [data-dyno-grid="${instanceId}"]{${lightCss}}`,
3230
+ `[data-dyno-grid="${instanceId}"].dark{${darkCss}}`,
3231
+ `[data-dyno-grid="${instanceId}"].light{${lightCss}}`
3207
3232
  ] }),
3208
3233
  /* @__PURE__ */ jsxRuntime.jsx(
3209
3234
  DataTableToolbar,
@@ -3230,71 +3255,83 @@ function DataTable({
3230
3255
  "table",
3231
3256
  {
3232
3257
  "aria-label": ariaLabel,
3233
- className: cn("w-full caption-bottom text-sm", striped && "[&_tbody>tr:nth-child(even)]:bg-muted/25"),
3258
+ className: cn(
3259
+ "w-full caption-bottom text-sm",
3260
+ striped && "[&_tbody>tr:nth-child(even)]:bg-muted/25"
3261
+ ),
3234
3262
  style: {
3235
3263
  width: table.getCenterTotalSize() ? void 0 : "100%",
3236
3264
  minWidth: "100%"
3237
3265
  },
3238
3266
  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
- }
3267
+ /* @__PURE__ */ jsxRuntime.jsx(
3268
+ "thead",
3269
+ {
3270
+ className: cn("bg-card", stickyHeader && "sticky top-0 z-10"),
3271
+ children: table.getHeaderGroups().map((hg) => /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "border-b", children: hg.headers.map((header) => {
3272
+ const meta = header.column.columnDef.meta;
3273
+ const isUtility = header.column.id === "__select" || header.column.id === "__expand" || header.column.id === "__actions";
3274
+ const isPinned = !!header.column.getIsPinned();
3275
+ const canReorder = !isUtility && f.reordering;
3276
+ const isDropTarget = canReorder && dragOverColId === header.column.id;
3277
+ const isBeingDragged = canReorder && activeReorderId === header.column.id;
3278
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3279
+ "th",
3280
+ {
3281
+ colSpan: header.colSpan,
3282
+ "data-col-id": header.column.id,
3283
+ onPointerDown: canReorder ? onHeaderPointerDown(header.column.id) : void 0,
3284
+ onPointerMove: canReorder ? onHeaderPointerMove : void 0,
3285
+ onPointerUp: canReorder ? onHeaderPointerUp : void 0,
3286
+ onPointerCancel: canReorder ? onHeaderPointerUp : void 0,
3287
+ style: {
3288
+ width: header.getSize(),
3289
+ ...getPinningStyles(header.column),
3290
+ ...isPinned ? { zIndex: 2 } : {}
3291
+ },
3292
+ className: cn(
3293
+ "group/th relative h-9 px-2 text-left align-middle text-xs font-medium text-muted-foreground select-none",
3294
+ canReorder && "cursor-grab active:cursor-grabbing",
3295
+ isPinned && "bg-card",
3296
+ isBeingDragged && "opacity-50",
3297
+ isDropTarget && "bg-primary/10 ring-2 ring-primary/40 ring-inset",
3298
+ meta?.headerClassName
3276
3299
  ),
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"
3300
+ children: [
3301
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [
3302
+ canReorder && /* @__PURE__ */ jsxRuntime.jsx(
3303
+ lucideReact.GripVerticalIcon,
3304
+ {
3305
+ className: "-ml-1 size-3 shrink-0 text-muted-foreground/40 opacity-0 transition group-hover/th:opacity-100",
3306
+ "aria-hidden": "true"
3307
+ }
3308
+ ),
3309
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 flex-1", children: header.isPlaceholder ? null : reactTable.flexRender(
3310
+ header.column.columnDef.header,
3311
+ header.getContext()
3312
+ ) })
3313
+ ] }),
3314
+ header.column.getCanResize() && /* @__PURE__ */ jsxRuntime.jsx(
3315
+ "span",
3316
+ {
3317
+ "data-no-drag": true,
3318
+ onPointerDown: (e) => e.stopPropagation(),
3319
+ onMouseDown: header.getResizeHandler(),
3320
+ onTouchStart: header.getResizeHandler(),
3321
+ onDoubleClick: () => header.column.resetSize(),
3322
+ className: cn(
3323
+ "absolute top-0 right-0 h-full w-1 cursor-col-resize touch-none bg-transparent transition-colors select-none hover:bg-primary/40",
3324
+ header.column.getIsResizing() && "bg-primary"
3325
+ )
3326
+ }
3290
3327
  )
3291
- }
3292
- )
3293
- ]
3294
- },
3295
- header.id
3296
- );
3297
- }) }, hg.id)) }),
3328
+ ]
3329
+ },
3330
+ header.id
3331
+ );
3332
+ }) }, hg.id))
3333
+ }
3334
+ ),
3298
3335
  /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: effectiveIsLoading ? renderSkeleton(visibleLeafCount, pagination.pageSize) : sourceError && rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx(
3299
3336
  "td",
3300
3337
  {
@@ -3338,7 +3375,13 @@ function DataTable({
3338
3375
  labels.refreshing
3339
3376
  ] })
3340
3377
  ] }),
3341
- f.pagination && /* @__PURE__ */ jsxRuntime.jsx(DataTablePagination, { table, pageSizeOptions }),
3378
+ f.pagination && /* @__PURE__ */ jsxRuntime.jsx(
3379
+ DataTablePagination,
3380
+ {
3381
+ table,
3382
+ pageSizeOptions
3383
+ }
3384
+ ),
3342
3385
  /* @__PURE__ */ jsxRuntime.jsx(
3343
3386
  DataTableViewSheet,
3344
3387
  {