@coreui/data-grid 0.1.0-rc.0 → 0.3.0-rc.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/README.md +9 -6
- package/dist/css/data-grid.css +156 -38
- package/dist/css/data-grid.css.map +1 -1
- package/dist/css/data-grid.min.css +2 -2
- package/dist/css/data-grid.min.css.map +1 -1
- package/dist/css/data-grid.standalone.css +1066 -0
- package/dist/css/data-grid.standalone.css.map +1 -0
- package/dist/css/data-grid.standalone.min.css +5 -0
- package/dist/css/data-grid.standalone.min.css.map +1 -0
- package/dist/js/clipboard.cjs +56 -0
- package/dist/js/clipboard.cjs.map +1 -0
- package/dist/js/clipboard.mjs +54 -0
- package/dist/js/clipboard.mjs.map +1 -0
- package/dist/js/csv.cjs +36 -59
- package/dist/js/csv.cjs.map +1 -1
- package/dist/js/csv.mjs +35 -55
- package/dist/js/csv.mjs.map +1 -1
- package/dist/js/data-grid.esm.js +14108 -9331
- package/dist/js/data-grid.esm.js.map +1 -1
- package/dist/js/data-grid.esm.min.js +6 -6
- package/dist/js/data-grid.esm.min.js.map +1 -1
- package/dist/js/data-grid.js +14408 -9634
- package/dist/js/data-grid.js.map +1 -1
- package/dist/js/data-grid.lite.esm.js +10507 -0
- package/dist/js/data-grid.lite.esm.js.map +1 -0
- package/dist/js/data-grid.lite.esm.min.js +8 -0
- package/dist/js/data-grid.lite.esm.min.js.map +1 -0
- package/dist/js/data-grid.lite.js +10520 -0
- package/dist/js/data-grid.lite.js.map +1 -0
- package/dist/js/data-grid.lite.min.js +8 -0
- package/dist/js/data-grid.lite.min.js.map +1 -0
- package/dist/js/data-grid.lite.mjs +10507 -0
- package/dist/js/data-grid.lite.mjs.map +1 -0
- package/dist/js/data-grid.min.js +6 -6
- package/dist/js/data-grid.min.js.map +1 -1
- package/dist/js/data-grid.mjs +14108 -9331
- package/dist/js/data-grid.mjs.map +1 -1
- package/dist/js/direction.cjs +26 -0
- package/dist/js/direction.cjs.map +1 -0
- package/dist/js/direction.mjs +24 -0
- package/dist/js/direction.mjs.map +1 -0
- package/dist/js/drag.cjs +467 -0
- package/dist/js/drag.cjs.map +1 -0
- package/dist/js/drag.mjs +464 -0
- package/dist/js/drag.mjs.map +1 -0
- package/dist/js/export-table-BdabEbJG.mjs +26 -0
- package/dist/js/export-table-BdabEbJG.mjs.map +1 -0
- package/dist/js/export-table-D762wrZ1.cjs +55 -0
- package/dist/js/export-table-D762wrZ1.cjs.map +1 -0
- package/dist/js/filters.cjs +89 -132
- package/dist/js/filters.cjs.map +1 -1
- package/dist/js/filters.mjs +88 -128
- package/dist/js/filters.mjs.map +1 -1
- package/dist/js/labels.cjs +65 -70
- package/dist/js/labels.cjs.map +1 -1
- package/dist/js/labels.mjs +64 -66
- package/dist/js/labels.mjs.map +1 -1
- package/dist/js/print.cjs +66 -0
- package/dist/js/print.cjs.map +1 -0
- package/dist/js/print.mjs +64 -0
- package/dist/js/print.mjs.map +1 -0
- package/dist/js/validate.cjs +43 -0
- package/dist/js/validate.cjs.map +1 -0
- package/dist/js/validate.mjs +42 -0
- package/dist/js/validate.mjs.map +1 -0
- package/dist/js/xlsx.cjs +240 -0
- package/dist/js/xlsx.cjs.map +1 -0
- package/dist/js/xlsx.mjs +238 -0
- package/dist/js/xlsx.mjs.map +1 -0
- package/dist/types/base-component.d.ts +28 -18
- package/dist/types/data-grid.d.ts +26 -13
- package/dist/types/dom/data.d.ts +15 -0
- package/dist/types/dom/event-handler.d.ts +21 -10
- package/dist/types/dom/manipulator.d.ts +15 -8
- package/dist/types/engine/active-cell.d.ts +1 -0
- package/dist/types/engine/data-source.d.ts +1 -1
- package/dist/types/engine/features-lite.d.ts +25 -0
- package/dist/types/engine/features.d.ts +35 -0
- package/dist/types/engine/table.d.ts +3 -3
- package/dist/types/engine/validate.d.mts +1 -0
- package/dist/types/engine/validate.d.ts +20 -0
- package/dist/types/engine/virtualizer.d.ts +2 -0
- package/dist/types/icons.d.ts +6 -4
- package/dist/types/index-lite.d.mts +1 -0
- package/dist/types/index-lite.d.ts +19 -0
- package/dist/types/index.d.ts +11 -2
- package/dist/types/types.d.ts +53 -31
- package/dist/types/ui/body.d.ts +6 -3
- package/dist/types/ui/header.d.ts +3 -2
- package/dist/types/ui/loading.d.ts +1 -1
- package/dist/types/ui/pinning.d.ts +1 -1
- package/dist/types/ui/toolbar.d.ts +10 -2
- package/dist/types/util/clipboard.d.mts +1 -0
- package/dist/types/util/clipboard.d.ts +29 -0
- package/dist/types/util/config.d.ts +27 -10
- package/dist/types/util/csv.d.ts +5 -5
- package/dist/types/util/direction.d.mts +1 -0
- package/dist/types/util/direction.d.ts +17 -0
- package/dist/types/util/drag.d.mts +1 -0
- package/dist/types/util/drag.d.ts +48 -0
- package/dist/types/util/export-table.d.ts +47 -0
- package/dist/types/util/index.d.ts +66 -10
- package/dist/types/util/print.d.mts +1 -0
- package/dist/types/util/print.d.ts +32 -0
- package/dist/types/util/sanitizer.d.ts +15 -11
- package/dist/types/util/xlsx.d.mts +1 -0
- package/dist/types/util/xlsx.d.ts +17 -0
- package/dist/types/util/zip.d.ts +11 -0
- package/package.json +101 -10
- package/scss/_base.scss +13 -0
- package/scss/_config.scss +14 -0
- package/scss/_functions.scss +1 -0
- package/scss/_mixins.scss +1 -0
- package/scss/base/_buttons.scss +113 -0
- package/scss/base/_forms.scss +157 -0
- package/scss/base/_helpers.scss +24 -0
- package/scss/base/_pagination.scss +100 -0
- package/scss/base/_reboot.scss +93 -0
- package/scss/base/_root.scss +85 -0
- package/scss/base/_spinner.scss +45 -0
- package/scss/base/_table.scss +78 -0
- package/scss/components/_data-grid.scss +807 -0
- package/scss/data-grid.scss +7 -555
- package/scss/data-grid.standalone.scss +16 -0
- package/scss/functions/_defaults.scss +25 -0
- package/scss/mixins/_tokens.scss +12 -0
- package/src/{base-component.js → base-component.ts} +21 -17
- package/src/data-grid.ts +523 -201
- package/src/dom/{data.js → data.ts} +13 -10
- package/src/dom/event-handler.ts +380 -0
- package/src/dom/{manipulator.js → manipulator.ts} +11 -11
- package/src/engine/active-cell.ts +10 -3
- package/src/engine/data-source.ts +7 -3
- package/src/engine/features-lite.ts +47 -0
- package/src/engine/features.ts +68 -0
- package/src/engine/table.ts +86 -45
- package/src/engine/validate.ts +64 -0
- package/src/engine/virtualizer.ts +17 -1
- package/src/icons.ts +11 -5
- package/src/index-lite.ts +85 -0
- package/src/index.ts +30 -2
- package/src/labels.ts +6 -4
- package/src/types.ts +87 -32
- package/src/ui/body.ts +73 -17
- package/src/ui/header.ts +51 -26
- package/src/ui/loading.ts +2 -2
- package/src/ui/pinning.ts +16 -16
- package/src/ui/toolbar.ts +27 -3
- package/src/util/clipboard.ts +112 -0
- package/src/util/{config.js → config.ts} +25 -11
- package/src/util/csv.ts +11 -30
- package/src/util/direction.ts +37 -0
- package/src/util/drag.ts +832 -0
- package/src/util/export-table.ts +86 -0
- package/src/util/{index.js → index.ts} +55 -35
- package/src/util/print.ts +125 -0
- package/src/util/{sanitizer.js → sanitizer.ts} +17 -13
- package/src/util/xlsx.ts +183 -0
- package/src/util/zip.ts +170 -0
- package/src/base-component.d.ts +0 -19
- package/src/dom/event-handler.d.ts +0 -11
- package/src/dom/event-handler.js +0 -331
- package/src/dom/manipulator.d.ts +0 -9
- package/src/util/config.d.ts +0 -11
- package/src/util/index.d.ts +0 -10
- package/src/util/sanitizer.d.ts +0 -11
package/src/engine/table.ts
CHANGED
|
@@ -5,26 +5,20 @@
|
|
|
5
5
|
* --------------------------------------------------------------------------
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
createTable,
|
|
10
|
-
getCoreRowModel,
|
|
11
|
-
getFacetedRowModel,
|
|
12
|
-
getFacetedUniqueValues,
|
|
13
|
-
getFilteredRowModel,
|
|
14
|
-
getPaginationRowModel,
|
|
15
|
-
getSortedRowModel,
|
|
16
|
-
type FilterFn,
|
|
17
|
-
type Table,
|
|
18
|
-
type TableState,
|
|
19
|
-
type Updater
|
|
20
|
-
} from '@tanstack/table-core'
|
|
8
|
+
import { constructTable, type FilterFn } from '@tanstack/table-core'
|
|
21
9
|
import { evaluateColumnFilter } from '../filters'
|
|
10
|
+
import { isElementRTL } from '../util/direction'
|
|
22
11
|
import type {
|
|
23
|
-
DataGridColumn, DataGridColumnFilterValue, DataGridItem, DataGridOptions
|
|
12
|
+
DataGridColumn, DataGridColumnFilterValue, DataGridFeatures, DataGridItem, DataGridOptions,
|
|
13
|
+
DataGridTable, DataGridTableState
|
|
24
14
|
} from '../types'
|
|
25
15
|
import { isGlobalFilterEnabled } from '../ui/toolbar'
|
|
16
|
+
import { assertFeatureCoverage } from './validate'
|
|
26
17
|
|
|
27
|
-
const
|
|
18
|
+
const UNPAGINATED_PAGE_SIZE = Number.MAX_SAFE_INTEGER
|
|
19
|
+
const INFINITE_SCROLL_PAGE_SIZE = 50
|
|
20
|
+
|
|
21
|
+
const toTanStackFilterFn = (column: DataGridColumn): FilterFn<DataGridFeatures, DataGridItem> => {
|
|
28
22
|
const { filterFn } = column
|
|
29
23
|
if (filterFn) {
|
|
30
24
|
return (row, columnId, filterValue) => filterFn(row.getValue(columnId), filterValue, row.original)
|
|
@@ -36,8 +30,8 @@ const toTanStackFilterFn = (column: DataGridColumn): FilterFn<DataGridItem> => {
|
|
|
36
30
|
|
|
37
31
|
export const createGridTable = (
|
|
38
32
|
options: DataGridOptions,
|
|
39
|
-
|
|
40
|
-
):
|
|
33
|
+
getElement?: () => Element | null
|
|
34
|
+
): DataGridTable => {
|
|
41
35
|
const sortingOptions = typeof options.sorting === 'object' ? options.sorting : {}
|
|
42
36
|
const sizingOptions = typeof options.columnSizing === 'object' ? options.columnSizing : {}
|
|
43
37
|
const paginationOptions = typeof options.pagination === 'object' ? options.pagination : {}
|
|
@@ -49,17 +43,64 @@ export const createGridTable = (
|
|
|
49
43
|
// seed and apply explicit widths.
|
|
50
44
|
const widthsEnabled = sizingEnabled || pinningEnabled
|
|
51
45
|
const paginated = Boolean(options.pagination) || serverSide
|
|
46
|
+
const infiniteOptions = typeof options.infiniteScroll === 'object' ? options.infiniteScroll : {}
|
|
47
|
+
|
|
48
|
+
if (options.infiniteScroll) {
|
|
49
|
+
if (!serverSide) {
|
|
50
|
+
throw new TypeError('DATA-GRID: Option "infiniteScroll" requires "dataProvider".')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options.pagination) {
|
|
54
|
+
throw new TypeError('DATA-GRID: Option "infiniteScroll" cannot be combined with "pagination".')
|
|
55
|
+
}
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
if (!options.virtualization) {
|
|
58
|
+
throw new TypeError('DATA-GRID: Option "infiniteScroll" requires "virtualization".')
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The default set comes from the ENTRY's DataGrid subclass, never from a
|
|
63
|
+
// static import here - that split is what keeps the full preset out of the
|
|
64
|
+
// lite bundle. A custom set is typed as the full DataGridFeatures; internals
|
|
65
|
+
// stay on the full alias and capability-guard every optional-feature call.
|
|
66
|
+
const { features } = options
|
|
67
|
+
if (!features) {
|
|
68
|
+
throw new TypeError('DATA-GRID: Option "features" is required.')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
assertFeatureCoverage('data-grid', features, {
|
|
72
|
+
cellSelection: options.cellSelection,
|
|
73
|
+
columnFilters: options.columnFilters,
|
|
74
|
+
columnOrder: Boolean(options.columnOrder),
|
|
75
|
+
columnPinning: pinningEnabled,
|
|
76
|
+
columnSizing: sizingEnabled,
|
|
77
|
+
columnVisibility: Boolean(options.columnVisibility),
|
|
78
|
+
globalFilter: isGlobalFilterEnabled(options),
|
|
79
|
+
pagination: paginated,
|
|
80
|
+
rowSelection: Boolean(options.rowSelection),
|
|
81
|
+
selectFilters: options.columnFilters && options.columns.some(column => column.filterType === 'select'),
|
|
82
|
+
sorting: Boolean(options.sorting)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const initialState: Partial<DataGridTableState> = {
|
|
86
|
+
// An unpaginated grid is one page holding every row - but only when the
|
|
87
|
+
// pagination feature is registered at all.
|
|
88
|
+
...('rowPaginationFeature' in features && {
|
|
89
|
+
pagination: {
|
|
90
|
+
pageIndex: 0,
|
|
91
|
+
pageSize: options.infiniteScroll ?
|
|
92
|
+
infiniteOptions.pageSize ?? INFINITE_SCROLL_PAGE_SIZE :
|
|
93
|
+
(paginated ? paginationOptions.pageSize ?? 10 : UNPAGINATED_PAGE_SIZE)
|
|
94
|
+
}
|
|
95
|
+
}),
|
|
96
|
+
...(typeof options.columnPinning === 'object' && {
|
|
97
|
+
columnPinning: { start: [], end: [], ...options.columnPinning }
|
|
56
98
|
}),
|
|
57
|
-
...(typeof options.columnPinning === 'object' && { columnPinning: options.columnPinning }),
|
|
58
99
|
...(Array.isArray(options.columnOrder) && { columnOrder: options.columnOrder }),
|
|
59
100
|
...(typeof options.columnVisibility === 'object' && { columnVisibility: options.columnVisibility })
|
|
60
101
|
}
|
|
61
102
|
|
|
62
|
-
|
|
103
|
+
return constructTable<DataGridFeatures, DataGridItem>({
|
|
63
104
|
columns: options.columns.map(column => {
|
|
64
105
|
const size = column.width ?? null
|
|
65
106
|
return {
|
|
@@ -70,12 +111,17 @@ export const createGridTable = (
|
|
|
70
111
|
enableSorting: column.sortable !== false,
|
|
71
112
|
filterFn: toTanStackFilterFn(column),
|
|
72
113
|
id: column.key,
|
|
73
|
-
meta: { label: column.label, formatter: column.formatter },
|
|
114
|
+
meta: { label: column.label, formatter: column.formatter, width: column.width },
|
|
74
115
|
...(widthsEnabled && size !== null && { size })
|
|
75
116
|
}
|
|
76
117
|
}),
|
|
77
118
|
columnResizeMode: sizingOptions.mode ?? 'onChange',
|
|
119
|
+
// Construction-time only — table-core copies the options object, so a
|
|
120
|
+
// getter here would never be re-read. A direction flipped later is picked
|
|
121
|
+
// up by refreshing this through setOptions when a resize starts.
|
|
122
|
+
columnResizeDirection: isElementRTL(getElement?.()) ? 'rtl' : 'ltr',
|
|
78
123
|
data: serverSide ? [] : options.items,
|
|
124
|
+
enableCellSelection: Boolean(options.cellSelection),
|
|
79
125
|
enableColumnFilters: Boolean(options.columnFilters),
|
|
80
126
|
enableColumnPinning: pinningEnabled,
|
|
81
127
|
enableColumnResizing: sizingEnabled,
|
|
@@ -85,12 +131,7 @@ export const createGridTable = (
|
|
|
85
131
|
enableRowSelection: Boolean(options.rowSelection),
|
|
86
132
|
enableSorting: Boolean(options.sorting),
|
|
87
133
|
enableSortingRemoval: Boolean(sortingOptions.resetable),
|
|
88
|
-
|
|
89
|
-
// Faceting powers custom filter UIs (column.getFacetedUniqueValues()).
|
|
90
|
-
getFacetedRowModel: getFacetedRowModel(),
|
|
91
|
-
getFacetedUniqueValues: getFacetedUniqueValues(),
|
|
92
|
-
getFilteredRowModel: getFilteredRowModel(),
|
|
93
|
-
getSortedRowModel: getSortedRowModel(),
|
|
134
|
+
features,
|
|
94
135
|
globalFilterFn: 'includesString',
|
|
95
136
|
...(serverSide && {
|
|
96
137
|
manualFiltering: true,
|
|
@@ -98,25 +139,25 @@ export const createGridTable = (
|
|
|
98
139
|
manualSorting: true,
|
|
99
140
|
rowCount: 0
|
|
100
141
|
}),
|
|
101
|
-
...(paginated && { getPaginationRowModel: getPaginationRowModel() }),
|
|
102
142
|
...(options.itemKey && { getRowId: options.itemKey }),
|
|
103
143
|
initialState,
|
|
104
|
-
|
|
105
|
-
renderFallbackValue: null,
|
|
106
|
-
state: {}
|
|
144
|
+
renderFallbackValue: null
|
|
107
145
|
})
|
|
146
|
+
}
|
|
108
147
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
148
|
+
// table.store emits the new snapshot only (and only when a slice identity
|
|
149
|
+
// changed - it compares shallowly), so the previous one is kept here for the
|
|
150
|
+
// slice-by-slice diffing the grid does on every state change.
|
|
151
|
+
export const subscribeToTableState = (
|
|
152
|
+
table: DataGridTable,
|
|
153
|
+
listener: (previous: DataGridTableState, next: DataGridTableState) => void
|
|
154
|
+
): (() => void) => {
|
|
155
|
+
let previous = table.store.state
|
|
156
|
+
const subscription = table.store.subscribe(next => {
|
|
157
|
+
const from = previous
|
|
158
|
+
previous = next
|
|
159
|
+
listener(from, next)
|
|
160
|
+
})
|
|
120
161
|
|
|
121
|
-
return
|
|
162
|
+
return () => subscription.unsubscribe()
|
|
122
163
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* CoreUI PRO data-grid engine/validate.ts
|
|
4
|
+
* License (https://coreui.io/pro/license/)
|
|
5
|
+
* --------------------------------------------------------------------------
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// v9 exposes an API only when its feature is registered - a config flag whose
|
|
9
|
+
// feature is missing from a custom `features` set would otherwise surface as
|
|
10
|
+
// an undefined-method crash deep in a render. This maps each flag to the
|
|
11
|
+
// registration keys its code paths reach and fails fast at construction with
|
|
12
|
+
// the flag/feature pair spelled out.
|
|
13
|
+
export interface FeatureCoverageFlags {
|
|
14
|
+
cellSelection: boolean
|
|
15
|
+
columnFilters: boolean
|
|
16
|
+
columnOrder: boolean
|
|
17
|
+
columnPinning: boolean
|
|
18
|
+
columnSizing: boolean
|
|
19
|
+
columnVisibility: boolean
|
|
20
|
+
globalFilter: boolean
|
|
21
|
+
pagination: boolean
|
|
22
|
+
rowSelection: boolean
|
|
23
|
+
// columnFilters with a filterType: 'select' column - the value list comes
|
|
24
|
+
// from faceting.
|
|
25
|
+
selectFilters: boolean
|
|
26
|
+
sorting: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const FLAG_FEATURES: ReadonlyArray<[keyof FeatureCoverageFlags, readonly string[]]> = [
|
|
30
|
+
['cellSelection', ['cellSelectionFeature']],
|
|
31
|
+
['columnFilters', ['columnFilteringFeature', 'filteredRowModel']],
|
|
32
|
+
['columnOrder', ['columnOrderingFeature']],
|
|
33
|
+
// Pinning offsets come from column.getSize() and the edge classes from
|
|
34
|
+
// getIsVisible(), so pinning drags sizing + visibility in with it.
|
|
35
|
+
['columnPinning', ['columnPinningFeature', 'columnSizingFeature', 'columnVisibilityFeature']],
|
|
36
|
+
['columnSizing', ['columnResizingFeature', 'columnSizingFeature']],
|
|
37
|
+
['columnVisibility', ['columnVisibilityFeature']],
|
|
38
|
+
['globalFilter', ['filteredRowModel', 'filterFns', 'globalFilteringFeature']],
|
|
39
|
+
['pagination', ['paginatedRowModel', 'rowPaginationFeature']],
|
|
40
|
+
['rowSelection', ['rowSelectionFeature']],
|
|
41
|
+
['selectFilters', ['columnFacetingFeature', 'facetedRowModel', 'facetedUniqueValues']],
|
|
42
|
+
['sorting', ['rowSortingFeature', 'sortedRowModel']]
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
export const assertFeatureCoverage = (
|
|
46
|
+
componentName: string,
|
|
47
|
+
features: object,
|
|
48
|
+
flags: FeatureCoverageFlags
|
|
49
|
+
): void => {
|
|
50
|
+
for (const [flag, requiredKeys] of FLAG_FEATURES) {
|
|
51
|
+
if (!flags[flag]) {
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const label = flag === 'selectFilters' ? 'columnFilters (filterType "select")' : flag
|
|
56
|
+
for (const key of requiredKeys) {
|
|
57
|
+
if (!(key in features)) {
|
|
58
|
+
throw new TypeError(
|
|
59
|
+
`${componentName.toUpperCase()}: Option "${label}" requires feature "${key}" in "features".`
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
elementScroll,
|
|
10
|
+
measureElement,
|
|
10
11
|
observeElementOffset,
|
|
11
12
|
observeElementRect,
|
|
12
13
|
Virtualizer
|
|
@@ -17,10 +18,19 @@ export type GridVirtualizerInstance = Virtualizer<HTMLDivElement, Element>
|
|
|
17
18
|
export interface GridVirtualizer {
|
|
18
19
|
instance: GridVirtualizerInstance
|
|
19
20
|
setCount: (count: number) => void
|
|
21
|
+
// Discards cached row measurements. Rows are measured by INDEX, so any
|
|
22
|
+
// transition that puts different data at the same index (sorting,
|
|
23
|
+
// filtering, paging, a data swap) leaves the cache describing rows that are
|
|
24
|
+
// no longer there.
|
|
25
|
+
remeasure: () => void
|
|
20
26
|
destroy: () => void
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
export interface GridVirtualizerOptions {
|
|
30
|
+
// Measure each rendered row instead of trusting rowHeight. rowHeight stays
|
|
31
|
+
// the estimate for rows that have not been rendered yet, so it still sizes
|
|
32
|
+
// the scrollbar.
|
|
33
|
+
autoRowHeight: boolean
|
|
24
34
|
count: number
|
|
25
35
|
getScrollElement: () => HTMLDivElement
|
|
26
36
|
onChange: () => void
|
|
@@ -37,7 +47,8 @@ export const createGridVirtualizer = (options: GridVirtualizerOptions): GridVirt
|
|
|
37
47
|
observeElementRect,
|
|
38
48
|
onChange: options.onChange,
|
|
39
49
|
overscan: options.overscan,
|
|
40
|
-
scrollToFn: elementScroll
|
|
50
|
+
scrollToFn: elementScroll,
|
|
51
|
+
...(options.autoRowHeight && { measureElement })
|
|
41
52
|
})
|
|
42
53
|
|
|
43
54
|
const unmount = instance._didMount()
|
|
@@ -50,6 +61,11 @@ export const createGridVirtualizer = (options: GridVirtualizerOptions): GridVirt
|
|
|
50
61
|
instance.setOptions({ ...instance.options, count })
|
|
51
62
|
}
|
|
52
63
|
},
|
|
64
|
+
remeasure() {
|
|
65
|
+
if (options.autoRowHeight) {
|
|
66
|
+
instance.measure()
|
|
67
|
+
}
|
|
68
|
+
},
|
|
53
69
|
destroy() {
|
|
54
70
|
unmount()
|
|
55
71
|
}
|
package/src/icons.ts
CHANGED
|
@@ -15,6 +15,9 @@ export const DEFAULT_COLUMN_MENU_ICON =
|
|
|
15
15
|
export const DEFAULT_FILTER_ICON =
|
|
16
16
|
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="M96 197.333h320v32H96zm72 101.334h176v32H168zM216 400h80v32h-80zM48 96h416v32H48z"/></svg>'
|
|
17
17
|
|
|
18
|
+
export const DEFAULT_ROW_HANDLE_ICON =
|
|
19
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="M160 96h64v64h-64zm0 128h64v64h-64zm0 128h64v64h-64zM288 96h64v64h-64zm0 128h64v64h-64zm0 128h64v64h-64z"/></svg>'
|
|
20
|
+
|
|
18
21
|
export const DEFAULT_TOOLBAR_COLUMNS_ICON =
|
|
19
22
|
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="M16 64v384h480V64Zm304 32v320H192V96ZM48 96h112v320H48Zm416 320H352V96h112Z"/></svg>'
|
|
20
23
|
|
|
@@ -24,6 +27,9 @@ export const DEFAULT_TOOLBAR_EXPORT_ICON =
|
|
|
24
27
|
export const DEFAULT_TOOLBAR_UNDO_ICON =
|
|
25
28
|
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="M495.473 197.262c0-73.061-43.651-136.118-106.242-164.462q-2-.9-4.021-1.762-4.046-1.715-8.19-3.235-2.071-.761-4.167-1.47-4.19-1.422-8.468-2.64a180.95 180.95 0 0 0-98.675 0q-4.278 1.218-8.469 2.64-2.094.71-4.166 1.47-4.143 1.519-8.19 3.235-2.023.857-4.021 1.762c-62.592 28.344-106.242 91.4-106.242 164.462v237.483L38.627 338.75 16 361.377 150.623 496l134.623-134.623-22.627-22.627-96 96V197.263c0-72.891 52.814-133.678 122.186-146.1a149.4 149.4 0 0 1 52.479 0c69.371 12.426 122.186 73.213 122.186 146.1h32Z"/></svg>'
|
|
26
29
|
|
|
30
|
+
export const DEFAULT_TOOLBAR_PRINT_ICON =
|
|
31
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="M400 144V16H112v128H16v256h96v96h288v-96h96V144ZM144 48h224v96H144Zm224 416H144V304h224Zm96-96h-64V272H112v96H48V176h416Z"/><path fill="currentColor" d="M384 208h32v32h-32z"/></svg>'
|
|
32
|
+
|
|
27
33
|
export const DEFAULT_TOOLBAR_REDO_ICON =
|
|
28
34
|
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="M361.376 495.163 226.753 360.54l22.627-22.627 111.996 111.996 111.997-111.996L496 360.54z"/><path fill="currentColor" d="M377.377 472.52h-32V196.426C345.377 114.584 278.794 48 196.952 48c-83.229 0-148.426 63.106-148.426 143.667h-32c0-48.024 18.85-92.569 53.079-125.429C103.35 33.842 148.576 16 196.952 16c99.487 0 180.425 80.938 180.425 180.426Z"/></svg>'
|
|
29
35
|
|
|
@@ -39,22 +45,22 @@ export const DEFAULT_SORT_NEUTRAL_ICON =
|
|
|
39
45
|
// Column-menu item icons. Sort actions in the menu reuse the sort header icons.
|
|
40
46
|
|
|
41
47
|
// Pin (pushpin): the needle points to the lower-left, so the unmirrored glyph is
|
|
42
|
-
// "pin
|
|
48
|
+
// "pin to start"; a horizontal mirror (scale(-1 1) about the 512 viewBox) is "pin to end".
|
|
43
49
|
const PIN_PATH =
|
|
44
50
|
'm477.8 140.2-106-106a62.132 62.132 0 0 0-93.617 81.24l-4.913 5.533-97.654 42.9-42.611-23.026a24.04 24.04 0 0 0-28.86 4.638L62.6 189.487a23.88 23.88 0 0 0 .479 33.449l101.68 101.679L16 473.373V496h22.627l148.758-148.758L288.6 448.457a23.93 23.93 0 0 0 33.275.642l44.425-41.128a23.98 23.98 0 0 0 4.773-29.092l-23.344-42.858 42.131-90.515 8.6-10.318A62.134 62.134 0 0 0 477.8 140.2m-22.628 65.231a30.125 30.125 0 0 1-42.6 0l-16.885-16.886-33.08 39.678-50.7 108.933 28.087 51.566-34.209 31.669L91.2 205.806l32-33.89 50.969 27.543 118.386-52.008 29.177-32.863-15.158-15.161a30.126 30.126 0 0 1 42.6-42.6l106 106a30.126 30.126 0 0 1 0 42.6Z'
|
|
45
51
|
|
|
46
52
|
const SVG_512 =
|
|
47
53
|
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false">'
|
|
48
54
|
|
|
49
|
-
export const
|
|
55
|
+
export const DEFAULT_PIN_START_ICON =
|
|
50
56
|
`${SVG_512}<path fill="currentColor" d="${PIN_PATH}"/></svg>`
|
|
51
|
-
export const
|
|
57
|
+
export const DEFAULT_PIN_END_ICON =
|
|
52
58
|
`${SVG_512}<g transform="translate(512 0) scale(-1 1)"><path fill="currentColor" d="${PIN_PATH}"/></g></svg>`
|
|
53
59
|
export const DEFAULT_UNPIN_ICON =
|
|
54
60
|
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="m427.314 107.313-22.628-22.626L256 233.373 107.314 84.687l-22.628 22.626L233.373 256 84.686 404.687l22.628 22.626L256 278.627l148.686 148.686 22.628-22.626L278.627 256z"/></svg>'
|
|
55
|
-
export const
|
|
61
|
+
export const DEFAULT_MOVE_START_ICON =
|
|
56
62
|
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="M254.625 56h-38.632L16 256.2 216 456h38.623V336h144V176h-144Zm112 152v96h-144v113.384l-161.37-161.21 161.37-161.535V208Zm96-152h32v400h-32z"/></svg>'
|
|
57
|
-
export const
|
|
63
|
+
export const DEFAULT_MOVE_END_ICON =
|
|
58
64
|
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="M296.007 56h-38.632v120h-144v160h144v120H296l200-199.8Zm-6.632 361.384V304h-144v-96h144V94.639l161.37 161.535ZM17.375 56h32v400h-32z"/></svg>'
|
|
59
65
|
export const DEFAULT_HIDE_COLUMN_ICON =
|
|
60
66
|
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><path fill="currentColor" d="m397.222 131.1-.218-.223c-63.173-63.17-158.534-75.015-233.776-35.531l23.938 23.939c61.571-27.691 136.573-16.327 187.105 34.115L464 246.683v3.107l-71.744 74.585 22.63 22.63L496 262.683V233.79Z"/><path fill="currentColor" d="M352.8 284.33a103.307 103.307 0 0 0-132.893-132.892L246.1 177.63a71.228 71.228 0 0 1 80.507 80.508Zm17.1 62.938-33.831-33.831c.088-.108.179-.212.266-.32l-22.805-22.806q-.126.168-.253.334l-99.681-99.681.334-.253-22.81-22.805c-.108.087-.213.179-.321.266L38.627 16H16v22.627l95.689 95.689L16 233.79v28.893l98.778 102.689.218.222A199.73 199.73 0 0 0 367.372 390l106 106H496v-22.627L392.537 369.911Zm-177.157-131.9 96.128 96.132a71.28 71.28 0 0 1-96.133-96.133Zm-55.014 127.705L48 249.79v-3.107l86.319-89.737 35.065 35.064a103.248 103.248 0 0 0 142.842 142.843l32.007 32.007c-64.51 40.015-150.522 32.095-206.504-23.787"/></svg>'
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* CoreUI PRO data-grid index-lite.ts
|
|
4
|
+
* License (https://coreui.io/pro/license/)
|
|
5
|
+
* --------------------------------------------------------------------------
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import DataGridBase from './data-grid'
|
|
9
|
+
import type { DataGridFeatures } from './engine/features'
|
|
10
|
+
import { dataGridLiteFeatures, type DataGridLiteFeatures } from './engine/features-lite'
|
|
11
|
+
import type { DataGridOptions, TableFeatures } from './types'
|
|
12
|
+
import { defineJQueryPlugin } from './util/index.js'
|
|
13
|
+
|
|
14
|
+
// The lite entry: the same DataGrid paired with dataGridLiteFeatures (core +
|
|
15
|
+
// sorting + filtering incl. the toolbar search + pagination) as its default
|
|
16
|
+
// set, and no reference to the full preset anywhere in the module graph -
|
|
17
|
+
// that absence is the whole point of the second bundle.
|
|
18
|
+
class DataGrid<TFeatures extends TableFeatures = DataGridLiteFeatures> extends DataGridBase<TFeatures> {
|
|
19
|
+
static get Default(): DataGridOptions {
|
|
20
|
+
// The lite preset is deliberately narrower than the options' invariant
|
|
21
|
+
// features type - the coverage assertion, not the type, polices a config
|
|
22
|
+
// the set cannot serve.
|
|
23
|
+
return { ...DataGridBase.Default, features: dataGridLiteFeatures as unknown as DataGridFeatures }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
defineJQueryPlugin(DataGrid)
|
|
28
|
+
|
|
29
|
+
export { DataGrid }
|
|
30
|
+
export { dataGridLiteFeatures } from './engine/features-lite'
|
|
31
|
+
export { DEFAULT_LABELS, interpolate } from './labels'
|
|
32
|
+
export { evaluateColumnFilter, FILTER_OPERATORS, VALUELESS_OPERATORS } from './filters'
|
|
33
|
+
export { downloadCsv, exportCsv } from './util/csv'
|
|
34
|
+
export type { CsvDownloadOptions, CsvOptions } from './util/csv'
|
|
35
|
+
export type {
|
|
36
|
+
Column,
|
|
37
|
+
ColumnFiltersState,
|
|
38
|
+
ColumnOrderState,
|
|
39
|
+
ColumnPinningState,
|
|
40
|
+
ColumnSizingState,
|
|
41
|
+
DataGridColumn,
|
|
42
|
+
DataGridColumnFilterContext,
|
|
43
|
+
DataGridColumnFilterFactory,
|
|
44
|
+
DataGridColumnFilterValue,
|
|
45
|
+
DataGridColumnMenuBuilder,
|
|
46
|
+
DataGridColumnMenuContext,
|
|
47
|
+
DataGridColumnSizingOptions,
|
|
48
|
+
DataGridDataRequest,
|
|
49
|
+
DataGridDataResponse,
|
|
50
|
+
DataGridEditableOptions,
|
|
51
|
+
DataGridEditCommitEvent,
|
|
52
|
+
DataGridEditor,
|
|
53
|
+
DataGridEditorContext,
|
|
54
|
+
DataGridEditorFactory,
|
|
55
|
+
DataGridEditorType,
|
|
56
|
+
DataGridFilterCondition,
|
|
57
|
+
DataGridFilterOperator,
|
|
58
|
+
DataGridFilterType,
|
|
59
|
+
DataGridInfiniteScrollOptions,
|
|
60
|
+
DataGridItem,
|
|
61
|
+
DataGridLabels,
|
|
62
|
+
DataGridLiteFeatures,
|
|
63
|
+
DataGridMenuAction,
|
|
64
|
+
DataGridOptions,
|
|
65
|
+
DataGridPaginationInfoState,
|
|
66
|
+
DataGridPaginationOptions,
|
|
67
|
+
DataGridRowSelectionOptions,
|
|
68
|
+
DataGridSlot,
|
|
69
|
+
DataGridSlotContext,
|
|
70
|
+
DataGridSlotFactory,
|
|
71
|
+
DataGridSlots,
|
|
72
|
+
DataGridSortingOptions,
|
|
73
|
+
DataGridState,
|
|
74
|
+
DataGridToolbarOptions,
|
|
75
|
+
PaginationState,
|
|
76
|
+
RowSelectionState,
|
|
77
|
+
SortingState,
|
|
78
|
+
ColumnVisibilityState,
|
|
79
|
+
DataGridColumnPinning,
|
|
80
|
+
DataGridRow,
|
|
81
|
+
DataGridTable,
|
|
82
|
+
DataGridTableState,
|
|
83
|
+
Table,
|
|
84
|
+
TableFeatures
|
|
85
|
+
} from './types'
|
package/src/index.ts
CHANGED
|
@@ -5,11 +5,31 @@
|
|
|
5
5
|
* --------------------------------------------------------------------------
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import DataGridBase from './data-grid'
|
|
9
|
+
import { dataGridFeatures, type DataGridFeatures } from './engine/features'
|
|
10
|
+
import type { DataGridOptions, TableFeatures } from './types'
|
|
11
|
+
import { defineJQueryPlugin } from './util/index.js'
|
|
12
|
+
|
|
13
|
+
// The ENTRY, not the class, owns the default feature set: this one pairs the
|
|
14
|
+
// grid with the full dataGridFeatures, ./lite pairs the same class with
|
|
15
|
+
// dataGridLiteFeatures. Keeping the preset import out of data-grid.ts is what
|
|
16
|
+
// keeps the full set out of the lite bundle.
|
|
17
|
+
class DataGrid<TFeatures extends TableFeatures = DataGridFeatures> extends DataGridBase<TFeatures> {
|
|
18
|
+
static get Default(): DataGridOptions {
|
|
19
|
+
return { ...DataGridBase.Default, features: dataGridFeatures }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
defineJQueryPlugin(DataGrid)
|
|
24
|
+
|
|
25
|
+
export { DataGrid }
|
|
26
|
+
export { dataGridFeatures } from './engine/features'
|
|
27
|
+
export { dataGridLiteFeatures } from './engine/features-lite'
|
|
9
28
|
export { DEFAULT_LABELS, interpolate } from './labels'
|
|
10
29
|
export { evaluateColumnFilter, FILTER_OPERATORS, VALUELESS_OPERATORS } from './filters'
|
|
11
30
|
export { downloadCsv, exportCsv } from './util/csv'
|
|
12
31
|
export type { CsvDownloadOptions, CsvOptions } from './util/csv'
|
|
32
|
+
export type { DataGridExporter, DataGridExportOptions } from './ui/toolbar'
|
|
13
33
|
export type {
|
|
14
34
|
Column,
|
|
15
35
|
ColumnFiltersState,
|
|
@@ -31,11 +51,14 @@ export type {
|
|
|
31
51
|
DataGridEditorContext,
|
|
32
52
|
DataGridEditorFactory,
|
|
33
53
|
DataGridEditorType,
|
|
54
|
+
DataGridFeatures,
|
|
34
55
|
DataGridFilterCondition,
|
|
35
56
|
DataGridFilterOperator,
|
|
36
57
|
DataGridFilterType,
|
|
58
|
+
DataGridInfiniteScrollOptions,
|
|
37
59
|
DataGridItem,
|
|
38
60
|
DataGridLabels,
|
|
61
|
+
DataGridLiteFeatures,
|
|
39
62
|
DataGridMenuAction,
|
|
40
63
|
DataGridOptions,
|
|
41
64
|
DataGridPaginationInfoState,
|
|
@@ -51,6 +74,11 @@ export type {
|
|
|
51
74
|
PaginationState,
|
|
52
75
|
RowSelectionState,
|
|
53
76
|
SortingState,
|
|
77
|
+
ColumnVisibilityState,
|
|
78
|
+
DataGridColumnPinning,
|
|
79
|
+
DataGridRow,
|
|
80
|
+
DataGridTable,
|
|
81
|
+
DataGridTableState,
|
|
54
82
|
Table,
|
|
55
|
-
|
|
83
|
+
TableFeatures
|
|
56
84
|
} from './types'
|
package/src/labels.ts
CHANGED
|
@@ -25,8 +25,8 @@ export const DEFAULT_LABELS: DataGridLabels = {
|
|
|
25
25
|
lastPage: 'Last page',
|
|
26
26
|
loadError: 'Failed to load data',
|
|
27
27
|
loading: 'Loading…',
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
moveEnd: 'Move to end',
|
|
29
|
+
moveStart: 'Move to start',
|
|
30
30
|
nextPage: 'Next page',
|
|
31
31
|
operatorBetween: 'Between',
|
|
32
32
|
operatorBlank: 'Blank',
|
|
@@ -43,10 +43,11 @@ export const DEFAULT_LABELS: DataGridLabels = {
|
|
|
43
43
|
operatorStartsWith: 'Starts with',
|
|
44
44
|
pageSizeLabel: 'Rows per page',
|
|
45
45
|
paginationLabel: 'Pagination',
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
pinEnd: 'Pin to end',
|
|
47
|
+
pinStart: 'Pin to start',
|
|
48
48
|
previousPage: 'Previous page',
|
|
49
49
|
redoneAnnouncement: 'Change redone',
|
|
50
|
+
reorderRow: 'Reorder row',
|
|
50
51
|
resetColumns: 'Reset',
|
|
51
52
|
resultsAnnouncement: '{count} results',
|
|
52
53
|
searchValues: 'Search values',
|
|
@@ -58,6 +59,7 @@ export const DEFAULT_LABELS: DataGridLabels = {
|
|
|
58
59
|
sortDescending: 'Sort descending',
|
|
59
60
|
toolbarColumns: 'Columns',
|
|
60
61
|
toolbarExport: 'Export',
|
|
62
|
+
toolbarPrint: 'Print',
|
|
61
63
|
toolbarRedo: 'Redo',
|
|
62
64
|
toolbarUndo: 'Undo',
|
|
63
65
|
undoneAnnouncement: 'Change undone',
|