bolt-table 0.1.35 → 0.1.37

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.d.mts CHANGED
@@ -22,6 +22,9 @@ interface BoltTableIcons {
22
22
  search?: React$1.ReactNode;
23
23
  columns?: React$1.ReactNode;
24
24
  close?: React$1.ReactNode;
25
+ sparkles?: React$1.ReactNode;
26
+ send?: React$1.ReactNode;
27
+ loader?: React$1.ReactNode;
25
28
  }
26
29
 
27
30
  /** `'asc'` | `'desc'` | `null` — the direction of a column sort. */
@@ -84,31 +87,52 @@ interface ColumnType<T = unknown> {
84
87
  interface CellContextMenuItem<T = unknown> {
85
88
  /** Unique identifier for this menu item, used as the React `key`. */
86
89
  key: string;
87
- /** The label shown in the menu. Can be a string or React node. */
88
- label: React.ReactNode;
89
- /** Optional icon shown to the left of the label. */
90
- icon?: React.ReactNode;
90
+ /**
91
+ * The label shown in the menu. Can be a string, React node, or a function
92
+ * `(columnKey, record, rowIndex) => ReactNode` that returns a custom node
93
+ * derived from the row being clicked.
94
+ */
95
+ label: React.ReactNode | ((columnKey: string, record: T, rowIndex: number) => React.ReactNode);
96
+ /**
97
+ * Optional icon shown to the left of the label. Can be a React node or a
98
+ * function `(columnKey, record, rowIndex) => ReactNode` for row-aware icons.
99
+ */
100
+ icon?: React.ReactNode | ((columnKey: string, record: T, rowIndex: number) => React.ReactNode);
91
101
  /** When `true`, the label renders in red to indicate a destructive action. */
92
102
  danger?: boolean;
93
103
  /** When `true`, the item is grayed out and click handler is not called. */
94
104
  disabled?: boolean;
95
- /** Called when the user clicks this menu item. Receives the column key, row record, and row index. */
96
- onClick: (columnKey: string, record: T, rowIndex: number) => void;
105
+ /**
106
+ * Called when the user clicks this menu item. Receives the column key, row
107
+ * record, and row index. Optional — omit if the item's label renders its
108
+ * own interactive content (e.g. a custom React node that handles clicks).
109
+ */
110
+ onClick?: (columnKey: string, record: T, rowIndex: number) => void;
97
111
  }
98
112
  /** A single item in the column header right-click context menu. */
99
113
  interface ColumnContextMenuItem {
100
114
  /** Unique identifier for this menu item, used as the React `key`. */
101
115
  key: string;
102
- /** The label shown in the menu. Can be a string or React node. */
103
- label: React.ReactNode;
104
- /** Optional icon shown to the left of the label. */
105
- icon?: React.ReactNode;
116
+ /**
117
+ * The label shown in the menu. Can be a string, React node, or a function
118
+ * `(columnKey) => ReactNode` that returns a custom node derived from the
119
+ * column being clicked.
120
+ */
121
+ label: React.ReactNode | ((columnKey: string) => React.ReactNode);
122
+ /**
123
+ * Optional icon shown to the left of the label. Can be a React node or a
124
+ * function `(columnKey) => ReactNode` for column-aware icons.
125
+ */
126
+ icon?: React.ReactNode | ((columnKey: string) => React.ReactNode);
106
127
  /** When `true`, the label renders in red to indicate a destructive action. */
107
128
  danger?: boolean;
108
129
  /** When `true`, the item is grayed out and click handler is not called. */
109
130
  disabled?: boolean;
110
- /** Called when the user clicks this menu item. Receives the column `key`. */
111
- onClick: (columnKey: string) => void;
131
+ /**
132
+ * Called when the user clicks this menu item. Receives the column `key`.
133
+ * Optional — omit if the item's label renders its own interactive content.
134
+ */
135
+ onClick?: (columnKey: string) => void;
112
136
  }
113
137
  /** How the row selection was triggered: `'all'`, `'single'`, or `'multiple'`. */
114
138
  type RowSelectMethod = "all" | "single" | "multiple";
@@ -187,6 +211,68 @@ interface ColumnPersistenceConfig {
187
211
  /** Persist column pinned state. Defaults to `true`. */
188
212
  persistPinned?: boolean;
189
213
  }
214
+ /** Supported comparison operators for AI-generated conditions. */
215
+ type AIOperator = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "contains" | "notContains" | "startsWith" | "endsWith" | "in" | "notIn";
216
+ /** A single condition produced by the AI. */
217
+ interface AICondition {
218
+ column: string;
219
+ op: AIOperator;
220
+ value: unknown;
221
+ }
222
+ /** Filter rows matching conditions. */
223
+ interface AIFilterOperation {
224
+ type: "filter";
225
+ conditions: AICondition[];
226
+ logic?: "and" | "or";
227
+ }
228
+ /** Apply inline styles to rows matching conditions. */
229
+ interface AIStyleOperation {
230
+ type: "rowStyle";
231
+ conditions: AICondition[];
232
+ logic?: "and" | "or";
233
+ style: Record<string, string>;
234
+ }
235
+ /** Apply inline styles to specific cells matching conditions. */
236
+ interface AICellStyleOperation {
237
+ type: "cellStyle";
238
+ column: string;
239
+ conditions: AICondition[];
240
+ logic?: "and" | "or";
241
+ style: Record<string, string>;
242
+ }
243
+ /** Sort data by a column. */
244
+ interface AISortOperation {
245
+ type: "sort";
246
+ column: string;
247
+ direction: "asc" | "desc";
248
+ }
249
+ /** Hide or show specific columns. */
250
+ interface AIColumnVisibilityOperation {
251
+ type: "hideColumns" | "showColumns";
252
+ columns: string[];
253
+ }
254
+ /** Union of all possible AI operations. */
255
+ type AIOperation = AIFilterOperation | AIStyleOperation | AICellStyleOperation | AISortOperation | AIColumnVisibilityOperation;
256
+ /** The structured response returned by the AI. */
257
+ interface AIResponse {
258
+ operations: AIOperation[];
259
+ message: string;
260
+ }
261
+ /** AI provider configuration. */
262
+ interface BoltTableAIConfig {
263
+ provider: "openai" | "anthropic" | "custom";
264
+ apiKey: string;
265
+ model?: string;
266
+ baseUrl?: string;
267
+ maxTokens?: number;
268
+ temperature?: number;
269
+ }
270
+ /** Top-level configuration for bolt-table.config.ts files. */
271
+ interface BoltTableConfig {
272
+ ai?: BoltTableAIConfig;
273
+ }
274
+ /** Helper for type-safe bolt-table.config.ts files. */
275
+ declare function defineConfig(config: BoltTableConfig): BoltTableConfig;
190
276
 
191
277
  interface BoltTableProps<T extends DataRecord = DataRecord> {
192
278
  /** Column definitions controlling what columns are shown, their order, width, pinning, sort/filter, and rendering. */
@@ -285,6 +371,21 @@ interface BoltTableProps<T extends DataRecord = DataRecord> {
285
371
  readonly toolbarContent?: React$1.ReactNode;
286
372
  /** Label for the column-settings button. Defaults to "Columns". */
287
373
  readonly columnSettingsLabel?: React$1.ReactNode;
374
+ /** Enable the AI assistant button in the toolbar. Requires `aiConfig` or `onAIQuery`. */
375
+ readonly aiMode?: boolean;
376
+ /** AI provider configuration (API key, model, etc.). Used by the built-in AI handler. */
377
+ readonly aiConfig?: BoltTableAIConfig;
378
+ /** Custom AI query handler. When provided, overrides the built-in AI call. Return an `AIResponse` with operations to apply. */
379
+ readonly onAIQuery?: (query: string, context: {
380
+ data: T[];
381
+ columns: ColumnType<T>[];
382
+ }) => Promise<AIResponse>;
383
+ /** Called after the AI applies operations. Receives the parsed response. */
384
+ readonly onAIResponse?: (response: AIResponse) => void;
385
+ /** Placeholder text for the AI search bar. */
386
+ readonly aiPlaceholder?: string;
387
+ /** Label for the AI button. Defaults to "Ask AI". */
388
+ readonly aiButtonLabel?: React$1.ReactNode;
288
389
  }
289
390
  interface ClassNamesTypes {
290
391
  /** Applied to all non-pinned column header cells. */
@@ -352,7 +453,7 @@ interface StylesTypes {
352
453
  /** Inline styles for the "X–Y of Z" info text. */
353
454
  paginationInfo?: CSSProperties;
354
455
  }
355
- declare function BoltTable<T extends DataRecord = DataRecord>({ columns: rawInitialColumns, data: rawData, rowHeight, expandedRowHeight, maxExpandedRowHeight, accentColor, className, classNames, styles, gripIcon, hideGripIcon, icons, pagination, onPaginationChange, onColumnResize, onColumnOrderChange, onColumnPin, onColumnHide, rowSelection, rowPinning, onRowPin, expandable, rowKey, onEndReached, onEndReachedThreshold, isLoading, onSortChange, onFilterChange, columnContextMenuItems, autoHeight, layoutLoading, emptyRenderer, rowClassName, rowStyle, disabledFilters, onCopy, keepPinnedRowsAcrossPages, onEdit, onRowClick, enableColumnVirtualization, enableDynamicRowHeight, columnPersistence, showColumnSettings, hideGlobalSearch, globalSearchValue, onGlobalSearchChange, toolbarContent, columnSettingsLabel, }: BoltTableProps<T>): react_jsx_runtime.JSX.Element;
456
+ declare function BoltTable<T extends DataRecord = DataRecord>({ columns: rawInitialColumns, data: rawData, rowHeight, expandedRowHeight, maxExpandedRowHeight, accentColor, className, classNames, styles, gripIcon, hideGripIcon, icons, pagination, onPaginationChange, onColumnResize, onColumnOrderChange, onColumnPin, onColumnHide, rowSelection, rowPinning, onRowPin, expandable, rowKey, onEndReached, onEndReachedThreshold, isLoading, onSortChange, onFilterChange, columnContextMenuItems, autoHeight, layoutLoading, emptyRenderer, rowClassName, rowStyle, disabledFilters, onCopy, keepPinnedRowsAcrossPages, onEdit, onRowClick, enableColumnVirtualization, enableDynamicRowHeight, columnPersistence, showColumnSettings, hideGlobalSearch, globalSearchValue, onGlobalSearchChange, toolbarContent, columnSettingsLabel, aiMode, aiConfig, onAIQuery, onAIResponse, aiPlaceholder, aiButtonLabel, }: BoltTableProps<T>): react_jsx_runtime.JSX.Element;
356
457
 
357
458
  interface DraggableHeaderProps {
358
459
  /** Column definition for this header cell. */
@@ -489,7 +590,9 @@ interface TableBodyProps {
489
590
  onRowHeightChange?: (index: number, height: number) => void;
490
591
  /** Maps column key → 1-based CSS grid column index in the full (non-virtualized) grid. Required for correct placement when column virtualization is enabled. */
491
592
  columnGridIndexMap?: Map<string, number>;
593
+ /** Optional AI cell style function. Returns extra styles for a specific cell. */
594
+ cellStyleFn?: (record: DataRecord, columnKey: string) => React$1.CSSProperties | undefined;
492
595
  }
493
596
  declare const TableBody: React$1.FC<TableBodyProps>;
494
597
 
495
- export { BoltTable, type BoltTableIcons, type CellContextMenuItem, type ClassNamesTypes, type ColumnContextMenuItem, type ColumnPersistenceConfig, type ColumnType, type DataRecord, DraggableHeader, type ExpandableConfig, type PaginationType, ResizeOverlay, type RowPinningConfig, type RowSelectionConfig, type SortDirection, type StylesTypes, TableBody };
598
+ export { type AICellStyleOperation, type AIColumnVisibilityOperation, type AICondition, type AIFilterOperation, type AIOperation, type AIOperator, type AIResponse, type AISortOperation, type AIStyleOperation, BoltTable, type BoltTableAIConfig, type BoltTableConfig, type BoltTableIcons, type CellContextMenuItem, type ClassNamesTypes, type ColumnContextMenuItem, type ColumnPersistenceConfig, type ColumnType, type DataRecord, DraggableHeader, type ExpandableConfig, type PaginationType, ResizeOverlay, type RowPinningConfig, type RowSelectionConfig, type SortDirection, type StylesTypes, TableBody, defineConfig };
package/dist/index.d.ts CHANGED
@@ -22,6 +22,9 @@ interface BoltTableIcons {
22
22
  search?: React$1.ReactNode;
23
23
  columns?: React$1.ReactNode;
24
24
  close?: React$1.ReactNode;
25
+ sparkles?: React$1.ReactNode;
26
+ send?: React$1.ReactNode;
27
+ loader?: React$1.ReactNode;
25
28
  }
26
29
 
27
30
  /** `'asc'` | `'desc'` | `null` — the direction of a column sort. */
@@ -84,31 +87,52 @@ interface ColumnType<T = unknown> {
84
87
  interface CellContextMenuItem<T = unknown> {
85
88
  /** Unique identifier for this menu item, used as the React `key`. */
86
89
  key: string;
87
- /** The label shown in the menu. Can be a string or React node. */
88
- label: React.ReactNode;
89
- /** Optional icon shown to the left of the label. */
90
- icon?: React.ReactNode;
90
+ /**
91
+ * The label shown in the menu. Can be a string, React node, or a function
92
+ * `(columnKey, record, rowIndex) => ReactNode` that returns a custom node
93
+ * derived from the row being clicked.
94
+ */
95
+ label: React.ReactNode | ((columnKey: string, record: T, rowIndex: number) => React.ReactNode);
96
+ /**
97
+ * Optional icon shown to the left of the label. Can be a React node or a
98
+ * function `(columnKey, record, rowIndex) => ReactNode` for row-aware icons.
99
+ */
100
+ icon?: React.ReactNode | ((columnKey: string, record: T, rowIndex: number) => React.ReactNode);
91
101
  /** When `true`, the label renders in red to indicate a destructive action. */
92
102
  danger?: boolean;
93
103
  /** When `true`, the item is grayed out and click handler is not called. */
94
104
  disabled?: boolean;
95
- /** Called when the user clicks this menu item. Receives the column key, row record, and row index. */
96
- onClick: (columnKey: string, record: T, rowIndex: number) => void;
105
+ /**
106
+ * Called when the user clicks this menu item. Receives the column key, row
107
+ * record, and row index. Optional — omit if the item's label renders its
108
+ * own interactive content (e.g. a custom React node that handles clicks).
109
+ */
110
+ onClick?: (columnKey: string, record: T, rowIndex: number) => void;
97
111
  }
98
112
  /** A single item in the column header right-click context menu. */
99
113
  interface ColumnContextMenuItem {
100
114
  /** Unique identifier for this menu item, used as the React `key`. */
101
115
  key: string;
102
- /** The label shown in the menu. Can be a string or React node. */
103
- label: React.ReactNode;
104
- /** Optional icon shown to the left of the label. */
105
- icon?: React.ReactNode;
116
+ /**
117
+ * The label shown in the menu. Can be a string, React node, or a function
118
+ * `(columnKey) => ReactNode` that returns a custom node derived from the
119
+ * column being clicked.
120
+ */
121
+ label: React.ReactNode | ((columnKey: string) => React.ReactNode);
122
+ /**
123
+ * Optional icon shown to the left of the label. Can be a React node or a
124
+ * function `(columnKey) => ReactNode` for column-aware icons.
125
+ */
126
+ icon?: React.ReactNode | ((columnKey: string) => React.ReactNode);
106
127
  /** When `true`, the label renders in red to indicate a destructive action. */
107
128
  danger?: boolean;
108
129
  /** When `true`, the item is grayed out and click handler is not called. */
109
130
  disabled?: boolean;
110
- /** Called when the user clicks this menu item. Receives the column `key`. */
111
- onClick: (columnKey: string) => void;
131
+ /**
132
+ * Called when the user clicks this menu item. Receives the column `key`.
133
+ * Optional — omit if the item's label renders its own interactive content.
134
+ */
135
+ onClick?: (columnKey: string) => void;
112
136
  }
113
137
  /** How the row selection was triggered: `'all'`, `'single'`, or `'multiple'`. */
114
138
  type RowSelectMethod = "all" | "single" | "multiple";
@@ -187,6 +211,68 @@ interface ColumnPersistenceConfig {
187
211
  /** Persist column pinned state. Defaults to `true`. */
188
212
  persistPinned?: boolean;
189
213
  }
214
+ /** Supported comparison operators for AI-generated conditions. */
215
+ type AIOperator = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "contains" | "notContains" | "startsWith" | "endsWith" | "in" | "notIn";
216
+ /** A single condition produced by the AI. */
217
+ interface AICondition {
218
+ column: string;
219
+ op: AIOperator;
220
+ value: unknown;
221
+ }
222
+ /** Filter rows matching conditions. */
223
+ interface AIFilterOperation {
224
+ type: "filter";
225
+ conditions: AICondition[];
226
+ logic?: "and" | "or";
227
+ }
228
+ /** Apply inline styles to rows matching conditions. */
229
+ interface AIStyleOperation {
230
+ type: "rowStyle";
231
+ conditions: AICondition[];
232
+ logic?: "and" | "or";
233
+ style: Record<string, string>;
234
+ }
235
+ /** Apply inline styles to specific cells matching conditions. */
236
+ interface AICellStyleOperation {
237
+ type: "cellStyle";
238
+ column: string;
239
+ conditions: AICondition[];
240
+ logic?: "and" | "or";
241
+ style: Record<string, string>;
242
+ }
243
+ /** Sort data by a column. */
244
+ interface AISortOperation {
245
+ type: "sort";
246
+ column: string;
247
+ direction: "asc" | "desc";
248
+ }
249
+ /** Hide or show specific columns. */
250
+ interface AIColumnVisibilityOperation {
251
+ type: "hideColumns" | "showColumns";
252
+ columns: string[];
253
+ }
254
+ /** Union of all possible AI operations. */
255
+ type AIOperation = AIFilterOperation | AIStyleOperation | AICellStyleOperation | AISortOperation | AIColumnVisibilityOperation;
256
+ /** The structured response returned by the AI. */
257
+ interface AIResponse {
258
+ operations: AIOperation[];
259
+ message: string;
260
+ }
261
+ /** AI provider configuration. */
262
+ interface BoltTableAIConfig {
263
+ provider: "openai" | "anthropic" | "custom";
264
+ apiKey: string;
265
+ model?: string;
266
+ baseUrl?: string;
267
+ maxTokens?: number;
268
+ temperature?: number;
269
+ }
270
+ /** Top-level configuration for bolt-table.config.ts files. */
271
+ interface BoltTableConfig {
272
+ ai?: BoltTableAIConfig;
273
+ }
274
+ /** Helper for type-safe bolt-table.config.ts files. */
275
+ declare function defineConfig(config: BoltTableConfig): BoltTableConfig;
190
276
 
191
277
  interface BoltTableProps<T extends DataRecord = DataRecord> {
192
278
  /** Column definitions controlling what columns are shown, their order, width, pinning, sort/filter, and rendering. */
@@ -285,6 +371,21 @@ interface BoltTableProps<T extends DataRecord = DataRecord> {
285
371
  readonly toolbarContent?: React$1.ReactNode;
286
372
  /** Label for the column-settings button. Defaults to "Columns". */
287
373
  readonly columnSettingsLabel?: React$1.ReactNode;
374
+ /** Enable the AI assistant button in the toolbar. Requires `aiConfig` or `onAIQuery`. */
375
+ readonly aiMode?: boolean;
376
+ /** AI provider configuration (API key, model, etc.). Used by the built-in AI handler. */
377
+ readonly aiConfig?: BoltTableAIConfig;
378
+ /** Custom AI query handler. When provided, overrides the built-in AI call. Return an `AIResponse` with operations to apply. */
379
+ readonly onAIQuery?: (query: string, context: {
380
+ data: T[];
381
+ columns: ColumnType<T>[];
382
+ }) => Promise<AIResponse>;
383
+ /** Called after the AI applies operations. Receives the parsed response. */
384
+ readonly onAIResponse?: (response: AIResponse) => void;
385
+ /** Placeholder text for the AI search bar. */
386
+ readonly aiPlaceholder?: string;
387
+ /** Label for the AI button. Defaults to "Ask AI". */
388
+ readonly aiButtonLabel?: React$1.ReactNode;
288
389
  }
289
390
  interface ClassNamesTypes {
290
391
  /** Applied to all non-pinned column header cells. */
@@ -352,7 +453,7 @@ interface StylesTypes {
352
453
  /** Inline styles for the "X–Y of Z" info text. */
353
454
  paginationInfo?: CSSProperties;
354
455
  }
355
- declare function BoltTable<T extends DataRecord = DataRecord>({ columns: rawInitialColumns, data: rawData, rowHeight, expandedRowHeight, maxExpandedRowHeight, accentColor, className, classNames, styles, gripIcon, hideGripIcon, icons, pagination, onPaginationChange, onColumnResize, onColumnOrderChange, onColumnPin, onColumnHide, rowSelection, rowPinning, onRowPin, expandable, rowKey, onEndReached, onEndReachedThreshold, isLoading, onSortChange, onFilterChange, columnContextMenuItems, autoHeight, layoutLoading, emptyRenderer, rowClassName, rowStyle, disabledFilters, onCopy, keepPinnedRowsAcrossPages, onEdit, onRowClick, enableColumnVirtualization, enableDynamicRowHeight, columnPersistence, showColumnSettings, hideGlobalSearch, globalSearchValue, onGlobalSearchChange, toolbarContent, columnSettingsLabel, }: BoltTableProps<T>): react_jsx_runtime.JSX.Element;
456
+ declare function BoltTable<T extends DataRecord = DataRecord>({ columns: rawInitialColumns, data: rawData, rowHeight, expandedRowHeight, maxExpandedRowHeight, accentColor, className, classNames, styles, gripIcon, hideGripIcon, icons, pagination, onPaginationChange, onColumnResize, onColumnOrderChange, onColumnPin, onColumnHide, rowSelection, rowPinning, onRowPin, expandable, rowKey, onEndReached, onEndReachedThreshold, isLoading, onSortChange, onFilterChange, columnContextMenuItems, autoHeight, layoutLoading, emptyRenderer, rowClassName, rowStyle, disabledFilters, onCopy, keepPinnedRowsAcrossPages, onEdit, onRowClick, enableColumnVirtualization, enableDynamicRowHeight, columnPersistence, showColumnSettings, hideGlobalSearch, globalSearchValue, onGlobalSearchChange, toolbarContent, columnSettingsLabel, aiMode, aiConfig, onAIQuery, onAIResponse, aiPlaceholder, aiButtonLabel, }: BoltTableProps<T>): react_jsx_runtime.JSX.Element;
356
457
 
357
458
  interface DraggableHeaderProps {
358
459
  /** Column definition for this header cell. */
@@ -489,7 +590,9 @@ interface TableBodyProps {
489
590
  onRowHeightChange?: (index: number, height: number) => void;
490
591
  /** Maps column key → 1-based CSS grid column index in the full (non-virtualized) grid. Required for correct placement when column virtualization is enabled. */
491
592
  columnGridIndexMap?: Map<string, number>;
593
+ /** Optional AI cell style function. Returns extra styles for a specific cell. */
594
+ cellStyleFn?: (record: DataRecord, columnKey: string) => React$1.CSSProperties | undefined;
492
595
  }
493
596
  declare const TableBody: React$1.FC<TableBodyProps>;
494
597
 
495
- export { BoltTable, type BoltTableIcons, type CellContextMenuItem, type ClassNamesTypes, type ColumnContextMenuItem, type ColumnPersistenceConfig, type ColumnType, type DataRecord, DraggableHeader, type ExpandableConfig, type PaginationType, ResizeOverlay, type RowPinningConfig, type RowSelectionConfig, type SortDirection, type StylesTypes, TableBody };
598
+ export { type AICellStyleOperation, type AIColumnVisibilityOperation, type AICondition, type AIFilterOperation, type AIOperation, type AIOperator, type AIResponse, type AISortOperation, type AIStyleOperation, BoltTable, type BoltTableAIConfig, type BoltTableConfig, type BoltTableIcons, type CellContextMenuItem, type ClassNamesTypes, type ColumnContextMenuItem, type ColumnPersistenceConfig, type ColumnType, type DataRecord, DraggableHeader, type ExpandableConfig, type PaginationType, ResizeOverlay, type RowPinningConfig, type RowSelectionConfig, type SortDirection, type StylesTypes, TableBody, defineConfig };