@tipolox/litgrid-web 1.0.3 → 1.2.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,20 @@
1
+ export * from './components/DataGrid.js'
2
+ export type { GridQuery, GridQueryFilter, GridQueryReason, GridQueryChangeDetail, GridQuerySnapshot, GridExternalTotal, GridExternalState, SortDirection } from './types.js'
3
+ export type {
4
+ BestFitColumnWidth,
5
+ ColumnReorderDetail,
6
+ ColumnStateChangeDetail,
7
+ ColumnVisibilityChangeDetail,
8
+ DataGridElement,
9
+ GridFilter,
10
+ GridPaginationState,
11
+ GridSelection,
12
+ GridRowKey,
13
+ SelectedRowSnapshot,
14
+ SelectionChangeDetail,
15
+ SelectionIntent,
16
+ GridColumn,
17
+ GridTheme,
18
+ GridColumnState,
19
+ GridConfig
20
+ } 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,138 @@
1
+ import type {
2
+ GridConfig,
3
+ GridFilter,
4
+ GridPaginationState,
5
+ GridSelection,
6
+ GridRowKey,
7
+ SelectionChangeDetail,
8
+ GridExternalState,
9
+ GridQuerySnapshot,
10
+ GridQueryChangeDetail,
11
+ SortDirection,
12
+ SelectionIntent
13
+ } from '@tipolox/litgrid-core'
14
+ import type { ColumnStateChangeDetail, GridColumnState } from './columnState/columnState.js'
15
+
16
+ export type { ColumnStateChangeDetail, GridColumnState }
17
+ export type { GridQuery, GridQueryFilter, GridQueryReason, GridQueryChangeDetail, GridQuerySnapshot, GridExternalTotal, GridExternalState, SortDirection } from '@tipolox/litgrid-core'
18
+
19
+ export type {
20
+ GridRowKey,
21
+ SelectedRowSnapshot,
22
+ SelectionChangeDetail,
23
+ GridConfig,
24
+ GridFilter,
25
+ GridPaginationState,
26
+ GridSelection,
27
+ SelectionIntent
28
+ } from '@tipolox/litgrid-core'
29
+
30
+ export type GridTheme = 'light' | 'dark'
31
+
32
+ export type GridColumn = {
33
+ key: string
34
+ header?: string
35
+ width?: number | string
36
+ hidden?: boolean
37
+ /** Show local sorting actions in the header menu. Defaults to true; does not change query state or imperative APIs. */
38
+ sortable?: boolean
39
+ /** Show local column filtering controls. Defaults to true; does not affect quick search or imperative APIs. */
40
+ filterable?: boolean
41
+ accessor?: (row: unknown, rowIndex: number) => unknown
42
+ render?: (value: unknown, row: unknown, rowIndex: number) => unknown
43
+ }
44
+
45
+ export type BestFitColumnWidth = {
46
+ key: string
47
+ width: number | null
48
+ }
49
+
50
+ export type ColumnReorderDetail = {
51
+ columnKey: string
52
+ previousIndex: number
53
+ currentIndex: number
54
+ columnOrder: string[]
55
+ }
56
+
57
+ export type ColumnVisibilityChangeDetail = {
58
+ columnKey: string
59
+ visible: boolean
60
+ visibleColumnKeys: string[]
61
+ }
62
+
63
+ export type DataGridElement = HTMLElement & {
64
+ /** Additive external-query capabilities; production DataGrid implements them. */
65
+ externalState?: GridExternalState | null
66
+ setExternalState?: (state: GridExternalState) => boolean
67
+ getQuery?: () => GridQuerySnapshot
68
+ refreshQuery?: () => void
69
+ sortBy?: (columnKey: string, direction: SortDirection) => void
70
+ clearSort?: () => void
71
+ data: unknown[]
72
+ columns: GridColumn[]
73
+ config: GridConfig
74
+ theme: GridTheme
75
+ ariaLabel: string
76
+ ariaDescription: string
77
+ screenReaderAnnouncements: boolean
78
+ viewportHeight: number
79
+ virtualRowHeight: number
80
+ overscanCount: number
81
+ columnOverscanCount: number
82
+ bestFitSampleSize: number
83
+ quickSearchDebounceThreshold: number
84
+ quickSearchDebounceMs: number
85
+ columnStateStorageKey: string | null
86
+ /** Additive capability; production DataGrid always implements it. */
87
+ inferColumns?: boolean
88
+ /** Additive capability; older structural implementations may omit it. */
89
+ updateColumnSchema?: (columns: GridColumn[], applyOrder?: boolean, storageKey?: string | null) => void
90
+ getRowHeight: (rowIndex: number) => number
91
+ getColumnWidth: (column: GridColumn) => number
92
+ setRowHeight: (rowIndex: number, height: number) => void
93
+ resetRowHeight: (rowIndex: number) => void
94
+ resetAllRowHeights: () => void
95
+ setColumnWidth: (columnKey: string, width: number) => void
96
+ resetColumnWidth: (columnKey: string) => void
97
+ resetAllColumnWidths: () => void
98
+ moveColumn: (columnKey: string, targetIndex: number) => void
99
+ getColumnOrder: () => string[]
100
+ setColumnOrder: (columnKeys: string[]) => void
101
+ resetColumnOrder: () => void
102
+ setColumnVisible: (columnKey: string, visible: boolean) => void
103
+ isColumnVisible: (columnKey: string) => boolean
104
+ getVisibleColumnKeys: () => string[]
105
+ resetColumnVisibility: () => void
106
+ getColumnState: () => GridColumnState
107
+ setColumnState: (state: GridColumnState) => void
108
+ resetColumnState: () => void
109
+ bestFitColumn: (columnKey: string) => number | null
110
+ bestFitAllColumns: () => BestFitColumnWidth[]
111
+ copySelectedCells: () => Promise<boolean>
112
+ copySelectedRows: () => Promise<boolean>
113
+ setQuickSearch: (query: string) => void
114
+ clearQuickSearch: () => void
115
+ getQuickSearch: () => string
116
+ setFilter: (filter: GridFilter) => void
117
+ clearFilter: (columnKey?: string) => void
118
+ getFilters: () => GridFilter[]
119
+ setPage: (pageIndex: number) => void
120
+ setPageSize: (pageSize: number) => void
121
+ getPagination: () => GridPaginationState
122
+ getTotalRowCount: () => number
123
+ selectRow: (rowIndex: number, intent?: SelectionIntent) => void
124
+ selectAllRows: () => void
125
+ clearSelection: () => void
126
+ getSelection: () => GridSelection
127
+ getSelectionSnapshot: () => SelectionChangeDetail
128
+ selectRowByKey: (key: GridRowKey, intent?: SelectionIntent) => boolean
129
+ isRowSelected: (rowIndex: number) => boolean
130
+ isCellSelected: (rowIndex: number, columnKey: string) => boolean
131
+ }
132
+
133
+ declare global {
134
+ interface HTMLElementEventMap {
135
+ 'selection-change': CustomEvent<SelectionChangeDetail>
136
+ 'query-change': CustomEvent<GridQueryChangeDetail>
137
+ }
138
+ }