@tipolox/litgrid-web 1.0.3 → 1.1.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/src/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ export * from './components/DataGrid.js'
2
+ export type {
3
+ BestFitColumnWidth,
4
+ ColumnReorderDetail,
5
+ ColumnStateChangeDetail,
6
+ ColumnVisibilityChangeDetail,
7
+ DataGridElement,
8
+ GridFilter,
9
+ GridPaginationState,
10
+ GridSelection,
11
+ SelectionIntent,
12
+ GridColumn,
13
+ GridTheme,
14
+ GridColumnState,
15
+ GridConfig
16
+ } from './types.js'
@@ -0,0 +1,25 @@
1
+ import type { GridColumn } from '../types.js'
2
+ import { DEFAULT_COLUMN_WIDTH, MIN_COLUMN_WIDTH } from './constants.js'
3
+
4
+ export function normalizeColumnWidth(width: number) {
5
+ return Math.max(MIN_COLUMN_WIDTH, width)
6
+ }
7
+
8
+ export function resolveColumnWidth(
9
+ column: GridColumn,
10
+ resizedWidth: number | undefined
11
+ ) {
12
+ if (resizedWidth) {
13
+ return resizedWidth
14
+ }
15
+
16
+ if (typeof column.width === 'number') {
17
+ return column.width
18
+ }
19
+
20
+ if (typeof column.width === 'string' && /^\d+px$/.test(column.width)) {
21
+ return Number.parseInt(column.width, 10)
22
+ }
23
+
24
+ return DEFAULT_COLUMN_WIDTH
25
+ }
@@ -0,0 +1,3 @@
1
+ export const DEFAULT_COLUMN_WIDTH = 160
2
+ export const MIN_COLUMN_WIDTH = 64
3
+ export const MIN_ROW_HEIGHT = 28
@@ -0,0 +1,5 @@
1
+ import { MIN_ROW_HEIGHT } from './constants.js'
2
+
3
+ export function normalizeRowHeight(height: number) {
4
+ return Math.max(MIN_ROW_HEIGHT, height)
5
+ }
@@ -0,0 +1,34 @@
1
+ import { css } from 'lit'
2
+
3
+ /**
4
+ * Dark semantic color tokens for the Community Edition grid.
5
+ * Consumers can override these custom properties on `yc-grid`.
6
+ */
7
+ export const darkThemeStyles = css`
8
+ :host([theme='dark']) {
9
+ --litgrid-color-text: #e2e8f0;
10
+ --litgrid-color-text-strong: #f8fafc;
11
+ --litgrid-color-text-muted: #cbd5e1;
12
+ --litgrid-color-text-subtle: #94a3b8;
13
+ --litgrid-color-text-header: #e2e8f0;
14
+ --litgrid-color-surface: #0f172a;
15
+ --litgrid-color-surface-subtle: #1e293b;
16
+ --litgrid-color-surface-hover: #334155;
17
+ --litgrid-color-row-start: rgba(30, 41, 59, 0.9);
18
+ --litgrid-color-row-end: rgba(15, 23, 42, 0.95);
19
+ --litgrid-color-border: #475569;
20
+ --litgrid-color-border-strong: #64748b;
21
+ --litgrid-color-border-subtle: #334155;
22
+ --litgrid-color-cell-border: #1e293b;
23
+ --litgrid-color-row-border: #334155;
24
+ --litgrid-color-accent: #60a5fa;
25
+ --litgrid-color-accent-soft: #1e3a5f;
26
+ --litgrid-color-accent-selected: #1d4ed8;
27
+ --litgrid-color-accent-text: #dbeafe;
28
+ --litgrid-color-resize-indicator: #94a3b8;
29
+ --litgrid-color-control-hover: rgba(148, 163, 184, 0.2);
30
+ --litgrid-shadow-shell: 0 12px 32px rgba(0, 0, 0, 0.35);
31
+ --litgrid-shadow-menu: 0 12px 24px rgba(0, 0, 0, 0.45);
32
+ --litgrid-shadow-dialog: 0 8px 20px rgba(0, 0, 0, 0.5);
33
+ }
34
+ `
@@ -0,0 +1,35 @@
1
+ import { css } from 'lit'
2
+
3
+ /**
4
+ * Default semantic color tokens for the Community Edition grid.
5
+ * Consumers can override these custom properties on `yc-grid`.
6
+ */
7
+ export const lightThemeStyles = css`
8
+ :host,
9
+ :host([theme='light']) {
10
+ --litgrid-color-text: #111827;
11
+ --litgrid-color-text-strong: #0f172a;
12
+ --litgrid-color-text-muted: #475569;
13
+ --litgrid-color-text-subtle: #64748b;
14
+ --litgrid-color-text-header: #334155;
15
+ --litgrid-color-surface: #ffffff;
16
+ --litgrid-color-surface-subtle: #f8fafc;
17
+ --litgrid-color-surface-hover: #f1f5f9;
18
+ --litgrid-color-row-start: rgba(249, 250, 251, 0.9);
19
+ --litgrid-color-row-end: rgba(255, 255, 255, 0.95);
20
+ --litgrid-color-border: #cbd5e1;
21
+ --litgrid-color-border-strong: #d1d5db;
22
+ --litgrid-color-border-subtle: #e2e8f0;
23
+ --litgrid-color-cell-border: #eef2f7;
24
+ --litgrid-color-row-border: #e5e7eb;
25
+ --litgrid-color-accent: #2563eb;
26
+ --litgrid-color-accent-soft: #dbeafe;
27
+ --litgrid-color-accent-selected: #bfdbfe;
28
+ --litgrid-color-accent-text: #1e3a8a;
29
+ --litgrid-color-resize-indicator: #94a3b8;
30
+ --litgrid-color-control-hover: rgba(148, 163, 184, 0.15);
31
+ --litgrid-shadow-shell: 0 12px 32px rgba(15, 23, 42, 0.08);
32
+ --litgrid-shadow-menu: 0 12px 24px rgba(15, 23, 42, 0.12);
33
+ --litgrid-shadow-dialog: 0 8px 20px rgba(15, 23, 42, 0.15);
34
+ }
35
+ `
package/src/types.ts ADDED
@@ -0,0 +1,108 @@
1
+ import type {
2
+ GridConfig,
3
+ GridFilter,
4
+ GridPaginationState,
5
+ GridSelection,
6
+ SelectionIntent
7
+ } from '@tipolox/litgrid-core'
8
+ import type { ColumnStateChangeDetail, GridColumnState } from './columnState/columnState.js'
9
+
10
+ export type { ColumnStateChangeDetail, GridColumnState }
11
+
12
+ export type {
13
+ GridConfig,
14
+ GridFilter,
15
+ GridPaginationState,
16
+ GridSelection,
17
+ SelectionIntent
18
+ } from '@tipolox/litgrid-core'
19
+
20
+ export type GridTheme = 'light' | 'dark'
21
+
22
+ export type GridColumn = {
23
+ key: string
24
+ header?: string
25
+ width?: number | string
26
+ hidden?: boolean
27
+ accessor?: (row: unknown, rowIndex: number) => unknown
28
+ render?: (value: unknown, row: unknown, rowIndex: number) => unknown
29
+ }
30
+
31
+ export type BestFitColumnWidth = {
32
+ key: string
33
+ width: number | null
34
+ }
35
+
36
+ export type ColumnReorderDetail = {
37
+ columnKey: string
38
+ previousIndex: number
39
+ currentIndex: number
40
+ columnOrder: string[]
41
+ }
42
+
43
+ export type ColumnVisibilityChangeDetail = {
44
+ columnKey: string
45
+ visible: boolean
46
+ visibleColumnKeys: string[]
47
+ }
48
+
49
+ export type DataGridElement = HTMLElement & {
50
+ data: unknown[]
51
+ columns: GridColumn[]
52
+ config: GridConfig
53
+ theme: GridTheme
54
+ ariaLabel: string
55
+ ariaDescription: string
56
+ screenReaderAnnouncements: boolean
57
+ viewportHeight: number
58
+ virtualRowHeight: number
59
+ overscanCount: number
60
+ columnOverscanCount: number
61
+ bestFitSampleSize: number
62
+ quickSearchDebounceThreshold: number
63
+ quickSearchDebounceMs: number
64
+ columnStateStorageKey: string | null
65
+ /** Additive capability; production DataGrid always implements it. */
66
+ inferColumns?: boolean
67
+ /** Additive capability; older structural implementations may omit it. */
68
+ updateColumnSchema?: (columns: GridColumn[], applyOrder?: boolean, storageKey?: string | null) => void
69
+ getRowHeight: (rowIndex: number) => number
70
+ getColumnWidth: (column: GridColumn) => number
71
+ setRowHeight: (rowIndex: number, height: number) => void
72
+ resetRowHeight: (rowIndex: number) => void
73
+ resetAllRowHeights: () => void
74
+ setColumnWidth: (columnKey: string, width: number) => void
75
+ resetColumnWidth: (columnKey: string) => void
76
+ resetAllColumnWidths: () => void
77
+ moveColumn: (columnKey: string, targetIndex: number) => void
78
+ getColumnOrder: () => string[]
79
+ setColumnOrder: (columnKeys: string[]) => void
80
+ resetColumnOrder: () => void
81
+ setColumnVisible: (columnKey: string, visible: boolean) => void
82
+ isColumnVisible: (columnKey: string) => boolean
83
+ getVisibleColumnKeys: () => string[]
84
+ resetColumnVisibility: () => void
85
+ getColumnState: () => GridColumnState
86
+ setColumnState: (state: GridColumnState) => void
87
+ resetColumnState: () => void
88
+ bestFitColumn: (columnKey: string) => number | null
89
+ bestFitAllColumns: () => BestFitColumnWidth[]
90
+ copySelectedCells: () => Promise<boolean>
91
+ copySelectedRows: () => Promise<boolean>
92
+ setQuickSearch: (query: string) => void
93
+ clearQuickSearch: () => void
94
+ getQuickSearch: () => string
95
+ setFilter: (filter: GridFilter) => void
96
+ clearFilter: (columnKey?: string) => void
97
+ getFilters: () => GridFilter[]
98
+ setPage: (pageIndex: number) => void
99
+ setPageSize: (pageSize: number) => void
100
+ getPagination: () => GridPaginationState
101
+ getTotalRowCount: () => number
102
+ selectRow: (rowIndex: number, intent?: SelectionIntent) => void
103
+ selectAllRows: () => void
104
+ clearSelection: () => void
105
+ getSelection: () => GridSelection
106
+ isRowSelected: (rowIndex: number) => boolean
107
+ isCellSelected: (rowIndex: number, columnKey: string) => boolean
108
+ }