@gridui/data-explorer 1.2.3 → 1.4.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.
Files changed (40) hide show
  1. package/README.md +75 -5
  2. package/dist/data-explorer/data-explorer.d.ts +1 -6
  3. package/dist/data-explorer-bulk-actions/data-explorer-bulk-actions.d.ts +4 -2
  4. package/dist/data-explorer-column-visibility/data-explorer-column-visibility.d.ts +5 -0
  5. package/dist/data-explorer-filter-control/data-explorer-filter-control.d.ts +5 -0
  6. package/dist/data-explorer-filters/data-explorer-filters.d.ts +5 -0
  7. package/dist/data-explorer-pagination/data-explorer-pagination.d.ts +4 -2
  8. package/dist/data-explorer-provider/data-explorer-provider.d.ts +7 -0
  9. package/dist/data-explorer-search/data-explorer-search.d.ts +5 -0
  10. package/dist/data-explorer-sort/data-explorer-sort.d.ts +5 -0
  11. package/dist/data-explorer-table/column-layout.d.ts +28 -0
  12. package/dist/data-explorer-table/data-explorer-table.d.ts +5 -2
  13. package/dist/data-explorer-toolbar/data-explorer-toolbar.d.ts +5 -9
  14. package/dist/data-explorer-view/data-explorer-view.d.ts +6 -0
  15. package/dist/index.d.ts +17 -0
  16. package/dist/index.js +388 -388
  17. package/dist/index.js.map +4 -4
  18. package/dist/shared/controller.d.ts +26 -0
  19. package/dist/shared/explorer-context.d.ts +129 -77
  20. package/dist/shared/explorer-options.d.ts +22 -18
  21. package/dist/shared/labels.d.ts +2 -0
  22. package/dist/styles.css +1 -0
  23. package/docs/catalog.json +106 -8
  24. package/docs/reference/README.md +7 -0
  25. package/docs/reference/data-explorer-bulk-actions.md +5 -1
  26. package/docs/reference/data-explorer-column-visibility.md +27 -0
  27. package/docs/reference/data-explorer-filter-control.md +27 -0
  28. package/docs/reference/data-explorer-filters.md +23 -0
  29. package/docs/reference/data-explorer-pagination.md +5 -1
  30. package/docs/reference/data-explorer-provider.md +97 -0
  31. package/docs/reference/data-explorer-search.md +27 -0
  32. package/docs/reference/data-explorer-sort.md +27 -0
  33. package/docs/reference/data-explorer-table.md +29 -1
  34. package/docs/reference/data-explorer-toolbar.md +7 -1
  35. package/docs/reference/data-explorer-view.md +59 -0
  36. package/docs/reference/data-explorer.md +3 -3
  37. package/package.json +13 -13
  38. /package/dist/{data-explorer-toolbar → data-explorer-filters}/filter-editor.d.ts +0 -0
  39. /package/dist/{data-explorer → data-explorer-view}/style.d.ts +0 -0
  40. /package/dist/{data-explorer-toolbar/style.d.ts → shared/label-style.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -114,58 +114,88 @@ var resolveExplorerWidth = (column, width = column.width ?? 200) => {
114
114
  return Math.max(min, Math.min(max, width));
115
115
  };
116
116
 
117
- // src/shared/explorer-context.ts
118
- import { createContext, useContext, useId } from "react";
119
- var useExplorerController = (options) => {
120
- const { rows, columns, state, onStateChange, filter, pageSize = 10, selectedIds = [], busy = false, columnSettings } = options;
121
- const tableId = useId();
117
+ // src/shared/controller.ts
118
+ var createExplorerController = (options) => {
119
+ const {
120
+ rows,
121
+ columns,
122
+ state,
123
+ onStateChange,
124
+ filter,
125
+ pageSize = 10,
126
+ selectedIds = [],
127
+ onSelectionChange,
128
+ busy = false,
129
+ columnSettings
130
+ } = options;
122
131
  const view = selectExplorerRows(rows, columns, state, pageSize, filter);
123
- const existingRowIds = new Set(rows.map((row) => {
124
- return row.id;
125
- }));
126
- const selectedRowIds = [...new Set(selectedIds)].filter((id) => {
127
- return existingRowIds.has(id);
128
- });
129
- const pageIds = view.rows.map((row) => {
130
- return row.id;
131
- });
132
- const selectedPageCount = pageIds.filter((id) => {
133
- return selectedRowIds.includes(id);
134
- }).length;
132
+ const existingRowIds = new Set(rows.map((row) => row.id));
133
+ const selectedRowIdSet = new Set(selectedIds.filter((id) => existingRowIds.has(id)));
134
+ const selectedRowIds = [...selectedRowIdSet];
135
+ const pageIds = view.rows.map((row) => row.id);
136
+ const selectedPageCount = pageIds.filter((id) => selectedRowIdSet.has(id)).length;
137
+ const visibleColumns = columns.filter((column) => !columnSettings?.hiddenKeys.includes(column.key));
138
+ if (columns.length > 0 && visibleColumns.length === 0) {
139
+ throw new RangeError("DataExplorer needs at least one visible column.");
140
+ }
135
141
  const updateState = (changes) => {
136
142
  if (!busy) {
137
- onStateChange({
138
- ...state,
139
- ...changes
140
- });
143
+ onStateChange({ ...state, ...changes });
144
+ }
145
+ };
146
+ const setQuery = (query) => void updateState({ query, page: 0 });
147
+ const setFilterValue = (filterValue) => void updateState({ filterValue, page: 0 });
148
+ const setSort = (sort) => void updateState({ sort, page: 0 });
149
+ const setFilters = (filters) => void updateState({ filters, page: 0 });
150
+ const updateSelection = (ids) => {
151
+ if (!busy) {
152
+ onSelectionChange?.([...new Set(ids.filter((id) => existingRowIds.has(id)))]);
141
153
  }
142
154
  };
143
- const visibleColumns = columns.filter((column) => {
144
- return !columnSettings?.hiddenKeys.includes(column.key);
145
- });
146
- if (columns.length > 0 && visibleColumns.length === 0) {
147
- throw new RangeError("DataExplorer needs at least one visible column.");
148
- }
149
155
  return {
150
- ...options,
151
156
  busy,
152
- tableId,
157
+ state,
158
+ columns,
159
+ visibleColumns,
153
160
  view,
154
161
  selectedRowIds,
162
+ selectedRowIdSet,
155
163
  pageIds,
156
164
  selectedPageCount,
157
165
  updateState,
158
- visibleColumns
166
+ setQuery,
167
+ setFilterValue,
168
+ setSort,
169
+ setFilters,
170
+ updateSelection
159
171
  };
160
172
  };
173
+
174
+ // src/shared/explorer-context.ts
175
+ import { createContext, useContext, useId } from "react";
176
+ var useExplorerController = (options) => {
177
+ const tableId = useId();
178
+ const controller = createExplorerController(options);
179
+ return { ...options, ...controller, tableId, controller };
180
+ };
161
181
  var explorerContext = createContext(null);
162
182
  var useExplorer = () => {
163
183
  const explorer = useContext(explorerContext);
164
184
  if (!explorer) {
165
- throw new Error("DataExplorer parts require a DataExplorer.");
185
+ throw new Error("DataExplorer parts require a DataExplorerProvider or DataExplorer.");
166
186
  }
167
187
  return explorer;
168
188
  };
189
+ var useDataExplorer = () => useExplorer().controller;
190
+
191
+ // src/shared/labels.ts
192
+ var explorerLabel = (labels, key) => {
193
+ const value = labels?.[key];
194
+ if (value === void 0) {
195
+ throw new Error(`DataExplorer requires the "${key}" label for this part.`);
196
+ }
197
+ return value;
198
+ };
169
199
 
170
200
  // src/data-explorer-bulk-actions/data-explorer-bulk-actions.tsx
171
201
  import { Button } from "@gridui/button";
@@ -173,7 +203,8 @@ import { Checkbox } from "@gridui/choice";
173
203
  import { cn } from "@gridui/style-utils";
174
204
  import { jsx, jsxs } from "react/jsx-runtime";
175
205
  var DataExplorerBulkActions = (props) => {
176
- const { actions = [], busy, labels, onSelectionChange, pageIds, selectedPageCount, selectedRowIds } = useExplorer();
206
+ const { actions = [], busy, labels: inheritedLabels, onSelectionChange, pageIds, selectedPageCount, selectedRowIds } = useExplorer();
207
+ const labels = { ...inheritedLabels, ...props.labels };
177
208
  if (!onSelectionChange) {
178
209
  return null;
179
210
  }
@@ -195,13 +226,13 @@ var DataExplorerBulkActions = (props) => {
195
226
  }
196
227
  ),
197
228
  " ",
198
- labels.selectPage
229
+ explorerLabel(labels, "selectPage")
199
230
  ] }),
200
231
  /* @__PURE__ */ jsx(
201
232
  "span",
202
233
  {
203
234
  role: "status",
204
- children: labels.selected(selectedRowIds.length)
235
+ children: explorerLabel(labels, "selected")(selectedRowIds.length)
205
236
  }
206
237
  ),
207
238
  actions.map((action) => {
@@ -230,7 +261,8 @@ import { cva as cva2 } from "class-variance-authority";
230
261
  import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
231
262
  var explorerFooterStyles = cva2("gridui-u-data-explorer--flex gridui-u-data-explorer--flex-wrap gridui-u-data-explorer--items-center gridui-u-data-explorer--justify-between gridui-u-data-explorer--gap-gridui-8 gridui-u-data-explorer--p-gridui-16");
232
263
  var DataExplorerPagination = (props) => {
233
- const { busy, labels, updateState, view } = useExplorer();
264
+ const { busy, labels: inheritedLabels, updateState, view } = useExplorer();
265
+ const labels = { ...inheritedLabels, ...props.labels };
234
266
  return /* @__PURE__ */ jsxs2(
235
267
  "div",
236
268
  {
@@ -244,14 +276,14 @@ var DataExplorerPagination = (props) => {
244
276
  onClick: () => {
245
277
  updateState({ page: view.page - 1 });
246
278
  },
247
- children: labels.previous
279
+ children: explorerLabel(labels, "previous")
248
280
  }
249
281
  ),
250
282
  /* @__PURE__ */ jsx2(
251
283
  "span",
252
284
  {
253
285
  role: "status",
254
- children: labels.page(view.page + 1, view.pageCount, view.total)
286
+ children: explorerLabel(labels, "page")(view.page + 1, view.pageCount, view.total)
255
287
  }
256
288
  ),
257
289
  /* @__PURE__ */ jsx2(
@@ -262,7 +294,7 @@ var DataExplorerPagination = (props) => {
262
294
  onClick: () => {
263
295
  updateState({ page: view.page + 1 });
264
296
  },
265
- children: labels.next
297
+ children: explorerLabel(labels, "next")
266
298
  }
267
299
  )
268
300
  ]
@@ -270,54 +302,83 @@ var DataExplorerPagination = (props) => {
270
302
  );
271
303
  };
272
304
 
273
- // src/data-explorer-table/column-resize-handle.tsx
274
- import { isComposingKeyEvent, listenForDragCancellation } from "@gridui/interaction";
275
- import { useEffect, useLayoutEffect, useRef } from "react";
305
+ // src/data-explorer-provider/data-explorer-provider.tsx
276
306
  import { jsx as jsx3 } from "react/jsx-runtime";
307
+ function DataExplorerProvider({ children, ...options }) {
308
+ const explorer = useExplorerController(options);
309
+ return /* @__PURE__ */ jsx3(explorerContext.Provider, { value: explorer, children });
310
+ }
311
+
312
+ // src/data-explorer-table/column-layout.ts
313
+ var calculateStickyOffset = (columns, index) => {
314
+ const side = columns[index].column.sticky;
315
+ if (side === void 0) {
316
+ return 0;
317
+ }
318
+ return columns.reduce((offset, current, currentIndex) => {
319
+ if (current.column.sticky !== side) {
320
+ return offset;
321
+ }
322
+ const contributes = side === "start" ? currentIndex < index : currentIndex > index;
323
+ if (contributes) {
324
+ return offset + current.width;
325
+ }
326
+ return offset;
327
+ }, 0);
328
+ };
329
+ var calculateColumnLayout = (options) => {
330
+ const { columns, columnWidths, hasSelection, hasDetails } = options;
331
+ const fixedWidths = columnWidths !== void 0 || columns.some((column) => {
332
+ return column.width !== void 0 || column.sticky !== void 0;
333
+ });
334
+ const sizedColumns = columns.map((column) => {
335
+ return {
336
+ column,
337
+ width: resolveExplorerWidth(column, columnWidths?.[column.key] ?? column.width)
338
+ };
339
+ });
340
+ const selectionWidth = hasSelection ? 56 : 0;
341
+ const detailsWidth = hasDetails ? 96 : 0;
342
+ const dataWidth = sizedColumns.reduce((total, column) => {
343
+ return total + column.width;
344
+ }, 0);
345
+ return {
346
+ columns: sizedColumns.map((column, index) => {
347
+ return {
348
+ ...column,
349
+ stickyOffset: calculateStickyOffset(sizedColumns, index)
350
+ };
351
+ }),
352
+ fixedWidths,
353
+ selectionWidth,
354
+ detailsWidth,
355
+ tableWidth: dataWidth + selectionWidth + detailsWidth
356
+ };
357
+ };
358
+
359
+ // src/data-explorer-table/column-resize-handle.tsx
360
+ import { isComposingKeyEvent } from "@gridui/interaction";
361
+ import { usePointerDrag } from "@gridui/react-utils";
362
+ import { useEffect } from "react";
363
+ import { jsx as jsx4 } from "react/jsx-runtime";
277
364
  var ColumnResizeHandle = (props) => {
278
365
  const { column, width, label, disabled, onChange } = props;
279
- const handle = useRef(null);
280
- const drag = useRef(null);
281
366
  const min = column.minWidth ?? 80;
282
367
  const max = column.maxWidth ?? 1200;
283
368
  const change = (next) => {
284
369
  onChange(resolveExplorerWidth(column, Math.max(min, Math.min(max, next))));
285
370
  };
286
- const cancelDrag = () => {
287
- const current = drag.current;
288
- drag.current = null;
289
- if (current) {
290
- current.cleanup();
291
- change(current.width);
292
- if (handle.current?.hasPointerCapture(current.pointer)) {
293
- handle.current.releasePointerCapture(current.pointer);
294
- }
295
- }
296
- };
297
- const cancelLatest = useRef(cancelDrag);
298
- useLayoutEffect(() => {
299
- cancelLatest.current = cancelDrag;
300
- });
371
+ const drag = usePointerDrag((current) => {
372
+ change(current.width);
373
+ }, { onUnmount: "finish" });
301
374
  useEffect(() => {
302
375
  if (disabled) {
303
- cancelLatest.current();
376
+ drag.cancel();
304
377
  }
305
- }, [disabled]);
306
- useEffect(() => {
307
- const element = handle.current;
308
- return () => {
309
- const current = drag.current;
310
- drag.current = null;
311
- current?.cleanup();
312
- if (current && element?.hasPointerCapture(current.pointer)) {
313
- element.releasePointerCapture(current.pointer);
314
- }
315
- };
316
- }, []);
317
- return /* @__PURE__ */ jsx3(
378
+ }, [disabled, drag]);
379
+ return /* @__PURE__ */ jsx4(
318
380
  "div",
319
381
  {
320
- ref: handle,
321
382
  role: "separator",
322
383
  tabIndex: disabled ? -1 : 0,
323
384
  "aria-orientation": "vertical",
@@ -328,47 +389,30 @@ var ColumnResizeHandle = (props) => {
328
389
  "aria-disabled": disabled || void 0,
329
390
  className: "gridui-explorer-resize gridui-u-data-explorer--min-h-11 gridui-u-data-explorer--w-gridui-16 gridui-u-data-explorer--shrink-0 gridui-u-data-explorer--cursor-col-resize gridui-u-data-explorer--touch-none gridui-u-data-explorer--border-s gridui-u-data-explorer--border-solid gridui-u-data-explorer--border-border",
330
391
  onPointerDown: (event) => {
331
- if (disabled || event.button !== 0 || !event.isPrimary || drag.current) {
392
+ if (disabled || !drag.start(event, {
393
+ x: event.clientX,
394
+ width,
395
+ direction: getComputedStyle(event.currentTarget).direction === "rtl" ? -1 : 1
396
+ })) {
332
397
  return;
333
398
  }
334
399
  event.preventDefault();
335
400
  event.currentTarget.focus();
336
- drag.current = {
337
- pointer: event.pointerId,
338
- x: event.clientX,
339
- width,
340
- direction: getComputedStyle(event.currentTarget).direction === "rtl" ? -1 : 1,
341
- cleanup: listenForDragCancellation(event.currentTarget, () => {
342
- cancelLatest.current();
343
- })
344
- };
345
- event.currentTarget.setPointerCapture(event.pointerId);
346
401
  },
347
402
  onPointerMove: (event) => {
348
- const current = drag.current;
349
- if (!disabled && current?.pointer === event.pointerId) {
403
+ const current = drag.get(event.pointerId);
404
+ if (!disabled && current) {
350
405
  change(current.width + (event.clientX - current.x) * current.direction);
351
406
  }
352
407
  },
353
408
  onPointerUp: (event) => {
354
- if (drag.current?.pointer === event.pointerId) {
355
- const current = drag.current;
356
- drag.current = null;
357
- current.cleanup();
358
- if (event.currentTarget.hasPointerCapture(event.pointerId)) {
359
- event.currentTarget.releasePointerCapture(event.pointerId);
360
- }
361
- }
409
+ drag.finish(event.pointerId);
362
410
  },
363
411
  onPointerCancel: (event) => {
364
- if (drag.current?.pointer === event.pointerId) {
365
- cancelDrag();
366
- }
412
+ drag.cancel(event.pointerId);
367
413
  },
368
414
  onLostPointerCapture: (event) => {
369
- if (drag.current?.pointer === event.pointerId) {
370
- cancelDrag();
371
- }
415
+ drag.cancel(event.pointerId);
372
416
  },
373
417
  onKeyDown: (event) => {
374
418
  if (disabled || isComposingKeyEvent(event.nativeEvent) || ![
@@ -402,23 +446,34 @@ import { Split } from "@gridui/grid";
402
446
  import { cn as cn3 } from "@gridui/style-utils";
403
447
  import { DataTable } from "@gridui/table";
404
448
  import { Children } from "react";
405
- import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
449
+ import { Fragment, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
406
450
  var DataExplorerTable = (props) => {
407
- const { busy, columnSizing, details, labels, notice, onSelectionChange, renderCell, selectedRowIds, tableId, view, visibleColumns } = useExplorer();
451
+ const { className, labels: ownLabels, ...presentation } = props;
452
+ const {
453
+ busy,
454
+ columnSizing,
455
+ details,
456
+ labels: inheritedLabels,
457
+ notice,
458
+ onSelectionChange,
459
+ renderCell,
460
+ selectedRowIds,
461
+ selectedRowIdSet,
462
+ tableId,
463
+ view,
464
+ visibleColumns
465
+ } = useExplorer();
466
+ const labels = { ...inheritedLabels, ...ownLabels };
408
467
  const hasNotice = Children.toArray(notice).some((child) => {
409
468
  return child !== "";
410
469
  });
411
- const fixedWidths = columnSizing !== void 0 || visibleColumns.some((column) => {
412
- return column.width !== void 0 || column.sticky !== void 0;
413
- });
414
- const widths = visibleColumns.map((column) => {
415
- return resolveExplorerWidth(column, columnSizing?.widths[column.key] ?? column.width);
470
+ const { columns, fixedWidths, selectionWidth, detailsWidth, tableWidth } = calculateColumnLayout({
471
+ columns: visibleColumns,
472
+ columnWidths: columnSizing?.widths,
473
+ hasSelection: onSelectionChange !== void 0,
474
+ hasDetails: details !== void 0
416
475
  });
417
- const tableColumns = visibleColumns.map((column, index) => {
418
- const width = widths[index];
419
- const stickyOffset = visibleColumns.reduce((offset, current, currentIndex) => {
420
- return current.sticky === column.sticky && (column.sticky === "start" ? currentIndex < index : currentIndex > index) ? offset + widths[currentIndex] : offset;
421
- }, 0);
476
+ const tableColumns = columns.map(({ column, width, stickyOffset }) => {
422
477
  return {
423
478
  key: `column:${column.key}`,
424
479
  label: column.label,
@@ -440,8 +495,8 @@ var DataExplorerTable = (props) => {
440
495
  {
441
496
  className: "gridui-u-data-explorer--flex gridui-u-data-explorer--min-w-0 gridui-u-data-explorer--items-center gridui-u-data-explorer--justify-between gridui-u-data-explorer--gap-gridui-8",
442
497
  children: [
443
- /* @__PURE__ */ jsx4("span", { children: column.label }),
444
- /* @__PURE__ */ jsx4(
498
+ /* @__PURE__ */ jsx5("span", { children: column.label }),
499
+ /* @__PURE__ */ jsx5(
445
500
  ColumnResizeHandle,
446
501
  {
447
502
  column,
@@ -465,20 +520,17 @@ var DataExplorerTable = (props) => {
465
520
  if (onSelectionChange) {
466
521
  tableColumns.unshift({
467
522
  key: "control:selection",
468
- label: labels.selection,
469
- ...fixedWidths ? { sizing: { width: 56 } } : {}
523
+ label: explorerLabel(labels, "selection"),
524
+ ...fixedWidths ? { sizing: { width: selectionWidth } } : {}
470
525
  });
471
526
  }
472
527
  if (details) {
473
528
  tableColumns.unshift({
474
529
  key: "control:details",
475
530
  label: details.columnLabel,
476
- ...fixedWidths ? { sizing: { width: 96 } } : {}
531
+ ...fixedWidths ? { sizing: { width: detailsWidth } } : {}
477
532
  });
478
533
  }
479
- const tableWidth = widths.reduce((total, width) => {
480
- return total + width;
481
- }, 0) + (onSelectionChange ? 56 : 0) + (details ? 96 : 0);
482
534
  const detailId = (row) => {
483
535
  return `${tableId}-details-${encodeURIComponent(row.id)}`;
484
536
  };
@@ -491,11 +543,11 @@ var DataExplorerTable = (props) => {
491
543
  return value ?? "";
492
544
  });
493
545
  if (onSelectionChange) {
494
- cells.unshift(/* @__PURE__ */ jsx4(
546
+ cells.unshift(/* @__PURE__ */ jsx5(
495
547
  Checkbox2,
496
548
  {
497
- "aria-label": labels.selectRow(row),
498
- checked: selectedRowIds.includes(row.id),
549
+ "aria-label": explorerLabel(labels, "selectRow")(row),
550
+ checked: selectedRowIdSet.has(row.id),
499
551
  disabled: busy,
500
552
  onCheckedChange: (checked) => {
501
553
  const nextSelection = selectExplorerPage(selectedRowIds, [row.id], checked);
@@ -507,7 +559,7 @@ var DataExplorerTable = (props) => {
507
559
  }
508
560
  if (details) {
509
561
  const expanded = details.expandedIds.includes(row.id);
510
- cells.unshift(/* @__PURE__ */ jsx4(
562
+ cells.unshift(/* @__PURE__ */ jsx5(
511
563
  Button3,
512
564
  {
513
565
  variant: "quiet",
@@ -535,23 +587,25 @@ var DataExplorerTable = (props) => {
535
587
  } : void 0;
536
588
  return {
537
589
  key: row.id,
590
+ selected: selectedRowIdSet.has(row.id),
538
591
  cells,
539
592
  ...detail ? { detail } : {}
540
593
  };
541
594
  });
542
595
  return /* @__PURE__ */ jsxs3(Fragment, { children: [
543
- hasNotice && /* @__PURE__ */ jsx4("div", { children: notice }),
596
+ hasNotice && /* @__PURE__ */ jsx5("div", { children: notice }),
544
597
  /* @__PURE__ */ jsxs3(
545
598
  Split,
546
599
  {
547
600
  direction: "column",
548
601
  "aria-busy": busy,
549
- className: cn3(props.className),
602
+ className: cn3(className),
550
603
  children: [
551
- /* @__PURE__ */ jsx4("div", { children: /* @__PURE__ */ jsx4(
604
+ /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5(
552
605
  DataTable,
553
606
  {
554
- label: labels.table,
607
+ ...presentation,
608
+ label: explorerLabel(labels, "table"),
555
609
  variant: "structured",
556
610
  blockEdges: "none",
557
611
  inlineEdges: "none",
@@ -566,11 +620,11 @@ var DataExplorerTable = (props) => {
566
620
  } : {}
567
621
  }
568
622
  ) }),
569
- view.rows.length === 0 && !busy && /* @__PURE__ */ jsx4("div", { children: /* @__PURE__ */ jsx4(
623
+ view.rows.length === 0 && !busy && /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5(
570
624
  "p",
571
625
  {
572
626
  className: "gridui-u-data-explorer--m-0 gridui-u-data-explorer--p-gridui-16",
573
- children: labels.empty
627
+ children: explorerLabel(labels, "empty")
574
628
  }
575
629
  ) })
576
630
  ]
@@ -579,21 +633,73 @@ var DataExplorerTable = (props) => {
579
633
  ] });
580
634
  };
581
635
 
582
- // src/data-explorer-toolbar/style.ts
636
+ // src/data-explorer-column-visibility/data-explorer-column-visibility.tsx
637
+ import { Checkbox as Checkbox3 } from "@gridui/choice";
638
+ import { cn as cn4 } from "@gridui/style-utils";
639
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
640
+ function DataExplorerColumnVisibility({ label, className }) {
641
+ const { busy, columnSettings, columns, visibleColumns } = useExplorer();
642
+ if (!columnSettings) {
643
+ return null;
644
+ }
645
+ return /* @__PURE__ */ jsxs4("details", { className: cn4("gridui-u-data-explorer--p-gridui-16", className), children: [
646
+ /* @__PURE__ */ jsx6("summary", { className: "gridui-u-data-explorer--cursor-pointer gridui-u-data-explorer--type-caption", children: label ?? columnSettings.label }),
647
+ /* @__PURE__ */ jsx6("div", { className: "gridui-u-data-explorer--flex gridui-u-data-explorer--flex-wrap gridui-u-data-explorer--gap-gridui-16 gridui-u-data-explorer--pt-gridui-16", children: columns.map((column) => {
648
+ const visible = !columnSettings.hiddenKeys.includes(column.key);
649
+ return /* @__PURE__ */ jsxs4("label", { className: "gridui-u-data-explorer--flex gridui-u-data-explorer--min-h-11 gridui-u-data-explorer--items-center gridui-u-data-explorer--gap-gridui-8", children: [
650
+ /* @__PURE__ */ jsx6(
651
+ Checkbox3,
652
+ {
653
+ checked: visible,
654
+ disabled: busy || visible && visibleColumns.length === 1,
655
+ onCheckedChange: (checked) => void columnSettings.onHiddenKeysChange(checked ? columnSettings.hiddenKeys.filter((key) => key !== column.key) : [.../* @__PURE__ */ new Set([...columnSettings.hiddenKeys, column.key])])
656
+ }
657
+ ),
658
+ column.label
659
+ ] }, column.key);
660
+ }) })
661
+ ] });
662
+ }
663
+
664
+ // src/shared/label-style.ts
583
665
  import { cva as cva3 } from "class-variance-authority";
584
666
  var explorerLabelStyles = cva3("gridui-u-data-explorer--flex gridui-u-data-explorer--min-w-0 gridui-u-data-explorer--flex-[1_1_10rem] gridui-u-data-explorer--flex-col gridui-u-data-explorer--gap-gridui-4 gridui-u-data-explorer--text-muted gridui-u-data-explorer--type-caption");
585
667
 
586
- // src/data-explorer-toolbar/filter-editor.tsx
668
+ // src/data-explorer-filter-control/data-explorer-filter-control.tsx
669
+ import { Select } from "@gridui/select";
670
+ import { cn as cn5 } from "@gridui/style-utils";
671
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
672
+ function DataExplorerFilterControl({ allLabel, className }) {
673
+ const { busy, filter, state, setFilterValue } = useExplorer();
674
+ if (!filter) {
675
+ return null;
676
+ }
677
+ return /* @__PURE__ */ jsxs5("label", { className: cn5(explorerLabelStyles(), className), children: [
678
+ filter.label,
679
+ /* @__PURE__ */ jsx7(
680
+ Select,
681
+ {
682
+ "aria-label": filter.label,
683
+ value: state.filterValue,
684
+ disabled: busy,
685
+ options: [{ value: "", label: allLabel }, ...filter.options],
686
+ onValueChange: setFilterValue
687
+ }
688
+ )
689
+ ] });
690
+ }
691
+
692
+ // src/data-explorer-filters/filter-editor.tsx
587
693
  import { Button as Button4 } from "@gridui/button";
588
694
  import { Input } from "@gridui/input";
589
- import { Select } from "@gridui/select";
590
- import { useId as useId2, useRef as useRef2 } from "react";
591
- import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
695
+ import { Select as Select2 } from "@gridui/select";
696
+ import { useId as useId2, useRef } from "react";
697
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
592
698
  var FilterEditor = (props) => {
593
699
  const { filtering, conditions, disabled, onChange } = props;
594
700
  const id = useId2();
595
- const sequence = useRef2(0);
596
- const addButton = useRef2(null);
701
+ const sequence = useRef(0);
702
+ const addButton = useRef(null);
597
703
  const { definitions, labels } = filtering;
598
704
  const first = definitions[0];
599
705
  const change = (index, condition) => {
@@ -601,7 +707,7 @@ var FilterEditor = (props) => {
601
707
  return currentIndex === index ? condition : current;
602
708
  }));
603
709
  };
604
- return /* @__PURE__ */ jsxs4("div", { children: [
710
+ return /* @__PURE__ */ jsxs6("div", { children: [
605
711
  conditions.map((condition, index) => {
606
712
  const definition = definitions.find((entry) => {
607
713
  return entry.key === condition.key;
@@ -628,19 +734,19 @@ var FilterEditor = (props) => {
628
734
  "empty"
629
735
  ];
630
736
  }
631
- return /* @__PURE__ */ jsxs4(
737
+ return /* @__PURE__ */ jsxs6(
632
738
  "div",
633
739
  {
634
740
  className: explorerControlRowStyles(),
635
741
  children: [
636
- /* @__PURE__ */ jsxs4(
742
+ /* @__PURE__ */ jsxs6(
637
743
  "label",
638
744
  {
639
745
  className: explorerLabelStyles(),
640
746
  children: [
641
747
  labels.field,
642
- /* @__PURE__ */ jsx5(
643
- Select,
748
+ /* @__PURE__ */ jsx8(
749
+ Select2,
644
750
  {
645
751
  "aria-label": labels.field,
646
752
  disabled,
@@ -667,14 +773,14 @@ var FilterEditor = (props) => {
667
773
  ]
668
774
  }
669
775
  ),
670
- /* @__PURE__ */ jsxs4(
776
+ /* @__PURE__ */ jsxs6(
671
777
  "label",
672
778
  {
673
779
  className: explorerLabelStyles(),
674
780
  children: [
675
781
  labels.operator,
676
- /* @__PURE__ */ jsx5(
677
- Select,
782
+ /* @__PURE__ */ jsx8(
783
+ Select2,
678
784
  {
679
785
  "aria-label": labels.operator,
680
786
  disabled,
@@ -701,14 +807,14 @@ var FilterEditor = (props) => {
701
807
  ]
702
808
  }
703
809
  ),
704
- condition.operator !== "empty" && /* @__PURE__ */ jsxs4(
810
+ condition.operator !== "empty" && /* @__PURE__ */ jsxs6(
705
811
  "label",
706
812
  {
707
813
  className: explorerLabelStyles(),
708
814
  children: [
709
815
  labels.value,
710
- definition?.type === "enum" ? /* @__PURE__ */ jsx5(
711
- Select,
816
+ definition?.type === "enum" ? /* @__PURE__ */ jsx8(
817
+ Select2,
712
818
  {
713
819
  "aria-label": labels.value,
714
820
  disabled,
@@ -722,7 +828,7 @@ var FilterEditor = (props) => {
722
828
  });
723
829
  }
724
830
  }
725
- ) : /* @__PURE__ */ jsx5(
831
+ ) : /* @__PURE__ */ jsx8(
726
832
  Input,
727
833
  {
728
834
  "aria-label": labels.value,
@@ -741,7 +847,7 @@ var FilterEditor = (props) => {
741
847
  ]
742
848
  }
743
849
  ),
744
- /* @__PURE__ */ jsx5(
850
+ /* @__PURE__ */ jsx8(
745
851
  Button4,
746
852
  {
747
853
  variant: "quiet",
@@ -760,11 +866,11 @@ var FilterEditor = (props) => {
760
866
  condition.id
761
867
  );
762
868
  }),
763
- /* @__PURE__ */ jsx5(
869
+ /* @__PURE__ */ jsx8(
764
870
  "div",
765
871
  {
766
872
  className: explorerControlRowStyles(),
767
- children: /* @__PURE__ */ jsx5(
873
+ children: /* @__PURE__ */ jsx8(
768
874
  Button4,
769
875
  {
770
876
  ref: addButton,
@@ -793,210 +899,111 @@ var FilterEditor = (props) => {
793
899
  ] });
794
900
  };
795
901
 
796
- // src/data-explorer-toolbar/data-explorer-toolbar.tsx
797
- import { Button as Button5 } from "@gridui/button";
798
- import { Checkbox as Checkbox3 } from "@gridui/choice";
902
+ // src/data-explorer-filters/data-explorer-filters.tsx
903
+ import { jsx as jsx9 } from "react/jsx-runtime";
904
+ function DataExplorerFilters({ labels }) {
905
+ const { busy, filtering, state, setFilters } = useExplorer();
906
+ if (!filtering) {
907
+ return null;
908
+ }
909
+ return /* @__PURE__ */ jsx9(
910
+ FilterEditor,
911
+ {
912
+ filtering: labels ? { ...filtering, labels } : filtering,
913
+ conditions: state.filters ?? [],
914
+ disabled: busy,
915
+ onChange: setFilters
916
+ }
917
+ );
918
+ }
919
+
920
+ // src/data-explorer-search/data-explorer-search.tsx
799
921
  import { Input as Input2 } from "@gridui/input";
800
- import { Select as Select2 } from "@gridui/select";
801
- import { cn as cn4 } from "@gridui/style-utils";
802
- import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
803
- var DataExplorerToolbar = (props) => {
804
- const { busy, columnSettings, columns, filter, filtering, labels, state, updateState, visibleColumns } = useExplorer();
805
- return /* @__PURE__ */ jsxs5(Fragment2, { children: [
806
- /* @__PURE__ */ jsxs5(
807
- "div",
808
- {
809
- className: cn4(explorerControlRowStyles(), props.className),
810
- children: [
811
- /* @__PURE__ */ jsxs5(
812
- "label",
813
- {
814
- className: explorerLabelStyles(),
815
- children: [
816
- labels.search,
817
- /* @__PURE__ */ jsx6(
818
- Input2,
819
- {
820
- type: "search",
821
- value: state.query,
822
- disabled: busy,
823
- onValueChange: (query) => {
824
- updateState({
825
- query,
826
- page: 0
827
- });
828
- }
829
- }
830
- )
831
- ]
832
- }
833
- ),
834
- filter && /* @__PURE__ */ jsxs5(
835
- "label",
836
- {
837
- className: explorerLabelStyles(),
838
- children: [
839
- filter.label,
840
- /* @__PURE__ */ jsx6(
841
- Select2,
842
- {
843
- "aria-label": filter.label,
844
- value: state.filterValue,
845
- disabled: busy,
846
- options: [
847
- {
848
- value: "",
849
- label: labels.all
850
- },
851
- ...filter.options
852
- ],
853
- onValueChange: (filterValue) => {
854
- updateState({
855
- filterValue,
856
- page: 0
857
- });
858
- }
859
- }
860
- )
861
- ]
862
- }
863
- ),
864
- /* @__PURE__ */ jsxs5(
865
- "label",
866
- {
867
- className: explorerLabelStyles(),
868
- children: [
869
- labels.sort,
870
- /* @__PURE__ */ jsx6(
871
- Select2,
872
- {
873
- "aria-label": labels.sort,
874
- value: state.sort?.key ?? "",
875
- disabled: busy,
876
- options: [
877
- {
878
- value: "",
879
- label: labels.unsorted
880
- },
881
- ...columns.map((column) => {
882
- return {
883
- value: column.key,
884
- label: column.label
885
- };
886
- })
887
- ],
888
- onValueChange: (key) => {
889
- updateState({
890
- sort: key ? {
891
- key,
892
- direction: "ascending"
893
- } : null,
894
- page: 0
895
- });
896
- }
897
- }
898
- )
899
- ]
900
- }
901
- ),
902
- /* @__PURE__ */ jsx6(
903
- Button5,
904
- {
905
- variant: "secondary",
906
- disabled: busy || !state.sort,
907
- onClick: () => {
908
- if (state.sort) {
909
- updateState({
910
- sort: {
911
- ...state.sort,
912
- direction: state.sort.direction === "ascending" ? "descending" : "ascending"
913
- },
914
- page: 0
915
- });
916
- }
917
- },
918
- children: state.sort?.direction === "descending" ? labels.descending : labels.ascending
919
- }
920
- )
921
- ]
922
- }
923
- ),
924
- columnSettings && /* @__PURE__ */ jsxs5(
925
- "details",
922
+ import { cn as cn6 } from "@gridui/style-utils";
923
+ import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
924
+ function DataExplorerSearch({ label, className }) {
925
+ const { busy, state, setQuery } = useExplorer();
926
+ return /* @__PURE__ */ jsxs7("label", { className: cn6(explorerLabelStyles(), className), children: [
927
+ label,
928
+ /* @__PURE__ */ jsx10(
929
+ Input2,
926
930
  {
927
- className: "gridui-u-data-explorer--p-gridui-16",
928
- children: [
929
- /* @__PURE__ */ jsx6(
930
- "summary",
931
- {
932
- className: "gridui-u-data-explorer--cursor-pointer gridui-u-data-explorer--type-caption",
933
- children: columnSettings.label
934
- }
935
- ),
936
- /* @__PURE__ */ jsx6(
937
- "div",
938
- {
939
- className: "gridui-u-data-explorer--flex gridui-u-data-explorer--flex-wrap gridui-u-data-explorer--gap-gridui-16 gridui-u-data-explorer--pt-gridui-16",
940
- children: columns.map((column) => {
941
- const visible = !columnSettings.hiddenKeys.includes(column.key);
942
- return /* @__PURE__ */ jsxs5(
943
- "label",
944
- {
945
- className: "gridui-u-data-explorer--flex gridui-u-data-explorer--min-h-11 gridui-u-data-explorer--items-center gridui-u-data-explorer--gap-gridui-8",
946
- children: [
947
- /* @__PURE__ */ jsx6(
948
- Checkbox3,
949
- {
950
- checked: visible,
951
- disabled: busy || visible && visibleColumns.length === 1,
952
- onCheckedChange: (checked) => {
953
- columnSettings.onHiddenKeysChange(checked ? columnSettings.hiddenKeys.filter((key) => {
954
- return key !== column.key;
955
- }) : [
956
- .../* @__PURE__ */ new Set([
957
- ...columnSettings.hiddenKeys,
958
- column.key
959
- ])
960
- ]);
961
- }
962
- }
963
- ),
964
- column.label
965
- ]
966
- },
967
- column.key
968
- );
969
- })
970
- }
971
- )
972
- ]
973
- }
974
- ),
975
- filtering && /* @__PURE__ */ jsx6(
976
- FilterEditor,
977
- {
978
- filtering,
979
- conditions: state.filters ?? [],
931
+ type: "search",
932
+ value: state.query,
980
933
  disabled: busy,
981
- onChange: (filters) => {
982
- updateState({
983
- filters,
984
- page: 0
985
- });
986
- }
934
+ onValueChange: setQuery
987
935
  }
988
936
  )
989
937
  ] });
990
- };
938
+ }
991
939
 
992
- // src/data-explorer/style.ts
940
+ // src/data-explorer-sort/data-explorer-sort.tsx
941
+ import { Button as Button5 } from "@gridui/button";
942
+ import { Select as Select3 } from "@gridui/select";
943
+ import { cn as cn7 } from "@gridui/style-utils";
944
+ import { Fragment as Fragment2, jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
945
+ function DataExplorerSort({ labels, className }) {
946
+ const { busy, columns, state, setSort } = useExplorer();
947
+ return /* @__PURE__ */ jsxs8(Fragment2, { children: [
948
+ /* @__PURE__ */ jsxs8("label", { className: cn7(explorerLabelStyles(), className), children: [
949
+ labels.sort,
950
+ /* @__PURE__ */ jsx11(
951
+ Select3,
952
+ {
953
+ "aria-label": labels.sort,
954
+ value: state.sort?.key ?? "",
955
+ disabled: busy,
956
+ options: [{ value: "", label: labels.unsorted }, ...columns.map((column) => ({ value: column.key, label: column.label }))],
957
+ onValueChange: (key) => void setSort(key ? { key, direction: "ascending" } : null)
958
+ }
959
+ )
960
+ ] }),
961
+ /* @__PURE__ */ jsx11(Button5, { variant: "secondary", disabled: busy || !state.sort, onClick: () => {
962
+ if (state.sort) {
963
+ setSort({ ...state.sort, direction: state.sort.direction === "ascending" ? "descending" : "ascending" });
964
+ }
965
+ }, children: state.sort?.direction === "descending" ? labels.descending : labels.ascending })
966
+ ] });
967
+ }
968
+
969
+ // src/data-explorer-toolbar/data-explorer-toolbar.tsx
970
+ import { cn as cn8 } from "@gridui/style-utils";
971
+ import { Fragment as Fragment3, jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
972
+ function DataExplorerToolbar({ className, children }) {
973
+ const { labels, filter } = useExplorer();
974
+ if (children !== void 0) {
975
+ return /* @__PURE__ */ jsx12("div", { className: cn8(explorerControlRowStyles(), className), children });
976
+ }
977
+ return /* @__PURE__ */ jsxs9(Fragment3, { children: [
978
+ /* @__PURE__ */ jsxs9("div", { className: cn8(explorerControlRowStyles(), className), children: [
979
+ /* @__PURE__ */ jsx12(DataExplorerSearch, { label: explorerLabel(labels, "search") }),
980
+ filter && /* @__PURE__ */ jsx12(DataExplorerFilterControl, { allLabel: explorerLabel(labels, "all") }),
981
+ /* @__PURE__ */ jsx12(DataExplorerSort, { labels: {
982
+ sort: explorerLabel(labels, "sort"),
983
+ unsorted: explorerLabel(labels, "unsorted"),
984
+ ascending: explorerLabel(labels, "ascending"),
985
+ descending: explorerLabel(labels, "descending")
986
+ } })
987
+ ] }),
988
+ /* @__PURE__ */ jsx12(DataExplorerColumnVisibility, {}),
989
+ /* @__PURE__ */ jsx12(DataExplorerFilters, {})
990
+ ] });
991
+ }
992
+
993
+ // src/data-explorer-view/style.ts
993
994
  import { cva as cva4 } from "class-variance-authority";
994
995
  var explorerStyles = cva4("gridui-u-data-explorer--min-w-0 gridui-u-data-explorer--border gridui-u-data-explorer--border-border gridui-u-data-explorer--bg-background gridui-u-data-explorer--text-foreground");
995
996
 
996
- // src/data-explorer/data-explorer.tsx
997
+ // src/data-explorer-view/data-explorer-view.tsx
997
998
  import { Split as Split2 } from "@gridui/grid";
998
- import { cn as cn5 } from "@gridui/style-utils";
999
- import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
999
+ import { cn as cn9 } from "@gridui/style-utils";
1000
+ import { jsx as jsx13 } from "react/jsx-runtime";
1001
+ function DataExplorerView({ label, className, children, ...rest }) {
1002
+ return /* @__PURE__ */ jsx13("section", { ...rest, "aria-label": label, className: cn9(explorerStyles(), className), children: /* @__PURE__ */ jsx13(Split2, { direction: "column", children }) });
1003
+ }
1004
+
1005
+ // src/data-explorer/data-explorer.tsx
1006
+ import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
1000
1007
  var DataExplorer = (props) => {
1001
1008
  const {
1002
1009
  rows,
@@ -1020,57 +1027,50 @@ var DataExplorer = (props) => {
1020
1027
  children,
1021
1028
  ...restProps
1022
1029
  } = props;
1023
- const explorer = useExplorerController({
1024
- rows,
1025
- columns,
1026
- state,
1027
- onStateChange,
1028
- filter,
1029
- columnSettings,
1030
- columnSizing,
1031
- details,
1032
- filtering,
1033
- pageSize,
1034
- selectedIds,
1035
- onSelectionChange,
1036
- actions,
1037
- renderCell,
1038
- busy,
1039
- notice,
1040
- labels
1041
- });
1042
- return /* @__PURE__ */ jsx7(
1043
- explorerContext.Provider,
1030
+ return /* @__PURE__ */ jsx14(
1031
+ DataExplorerProvider,
1044
1032
  {
1045
- value: explorer,
1046
- children: /* @__PURE__ */ jsx7(
1047
- "section",
1048
- {
1049
- ...restProps,
1050
- "aria-label": labels.table,
1051
- className: cn5(explorerStyles(), className),
1052
- children: /* @__PURE__ */ jsx7(
1053
- Split2,
1054
- {
1055
- direction: "column",
1056
- children: children ?? /* @__PURE__ */ jsxs6(Fragment3, { children: [
1057
- /* @__PURE__ */ jsx7(DataExplorerToolbar, {}),
1058
- /* @__PURE__ */ jsx7(DataExplorerBulkActions, {}),
1059
- /* @__PURE__ */ jsx7(DataExplorerTable, {}),
1060
- /* @__PURE__ */ jsx7(DataExplorerPagination, {})
1061
- ] })
1062
- }
1063
- )
1064
- }
1065
- )
1033
+ ...{
1034
+ rows,
1035
+ columns,
1036
+ state,
1037
+ onStateChange,
1038
+ filter,
1039
+ columnSettings,
1040
+ columnSizing,
1041
+ details,
1042
+ filtering,
1043
+ pageSize,
1044
+ selectedIds,
1045
+ onSelectionChange,
1046
+ actions,
1047
+ renderCell,
1048
+ busy,
1049
+ notice,
1050
+ labels
1051
+ },
1052
+ children: /* @__PURE__ */ jsx14(DataExplorerView, { ...restProps, label: labels.table, className, children: children ?? /* @__PURE__ */ jsxs10(Fragment4, { children: [
1053
+ /* @__PURE__ */ jsx14(DataExplorerToolbar, {}),
1054
+ /* @__PURE__ */ jsx14(DataExplorerBulkActions, {}),
1055
+ /* @__PURE__ */ jsx14(DataExplorerTable, {}),
1056
+ /* @__PURE__ */ jsx14(DataExplorerPagination, {})
1057
+ ] }) })
1066
1058
  }
1067
1059
  );
1068
1060
  };
1069
1061
  export {
1070
1062
  DataExplorer,
1071
1063
  DataExplorerBulkActions,
1064
+ DataExplorerColumnVisibility,
1065
+ DataExplorerFilterControl,
1066
+ DataExplorerFilters,
1072
1067
  DataExplorerPagination,
1068
+ DataExplorerProvider,
1069
+ DataExplorerSearch,
1070
+ DataExplorerSort,
1073
1071
  DataExplorerTable,
1074
- DataExplorerToolbar
1072
+ DataExplorerToolbar,
1073
+ DataExplorerView,
1074
+ useDataExplorer
1075
1075
  };
1076
1076
  //# sourceMappingURL=index.js.map