apex-grid 1.1.0 → 3.0.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/LICENSE +76 -5
- package/README.md +523 -10
- package/components/cell.d.ts +39 -0
- package/components/cell.js +334 -5
- package/components/cell.js.map +1 -1
- package/components/filter-row.d.ts +7 -5
- package/components/filter-row.js +151 -68
- package/components/filter-row.js.map +1 -1
- package/components/grid.d.ts +955 -4
- package/components/grid.js +412 -40
- package/components/grid.js.map +1 -1
- package/components/header-row.d.ts +21 -1
- package/components/header-row.js +140 -7
- package/components/header-row.js.map +1 -1
- package/components/header.d.ts +7 -0
- package/components/header.js +151 -31
- package/components/header.js.map +1 -1
- package/components/paginator.d.ts +56 -0
- package/components/paginator.js +148 -0
- package/components/paginator.js.map +1 -0
- package/components/row.d.ts +21 -2
- package/components/row.js +185 -10
- package/components/row.js.map +1 -1
- package/components/toolbar.d.ts +60 -0
- package/components/toolbar.js +259 -0
- package/components/toolbar.js.map +1 -0
- package/components/virtualizer.js +1 -1
- package/components/virtualizer.js.map +1 -1
- package/controllers/data-operation.d.ts +14 -0
- package/controllers/data-operation.js +19 -2
- package/controllers/data-operation.js.map +1 -1
- package/controllers/dom.d.ts +37 -1
- package/controllers/dom.js +176 -9
- package/controllers/dom.js.map +1 -1
- package/controllers/editing.d.ts +130 -0
- package/controllers/editing.js +197 -0
- package/controllers/editing.js.map +1 -0
- package/controllers/expansion.d.ts +68 -0
- package/controllers/expansion.js +126 -0
- package/controllers/expansion.js.map +1 -0
- package/controllers/navigation.d.ts +17 -6
- package/controllers/navigation.js +24 -8
- package/controllers/navigation.js.map +1 -1
- package/controllers/pagination.d.ts +102 -0
- package/controllers/pagination.js +106 -0
- package/controllers/pagination.js.map +1 -0
- package/controllers/reorder.d.ts +78 -0
- package/controllers/reorder.js +124 -0
- package/controllers/reorder.js.map +1 -0
- package/controllers/selection.d.ts +109 -0
- package/controllers/selection.js +168 -0
- package/controllers/selection.js.map +1 -0
- package/controllers/sort.js +28 -0
- package/controllers/sort.js.map +1 -1
- package/controllers/state.d.ts +47 -1
- package/controllers/state.js +48 -1
- package/controllers/state.js.map +1 -1
- package/controllers/tree.d.ts +87 -0
- package/controllers/tree.js +0 -0
- package/controllers/tree.js.map +1 -0
- package/custom-elements.json +6491 -1355
- package/define.js.map +1 -1
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/highlight.css +77 -14
- package/docs/assets/icons.js +1 -1
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/main.js +4 -4
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +3 -3
- package/docs/classes/ApexGrid.html +320 -24
- package/docs/functions/setup.html +16 -0
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +543 -9
- package/docs/interfaces/ApexCellValueChangedEvent.html +11 -0
- package/docs/interfaces/ApexCellValueChangingEvent.html +13 -0
- package/docs/interfaces/ApexColumnMovedEvent.html +8 -0
- package/docs/interfaces/ApexColumnMovingEvent.html +11 -0
- package/docs/interfaces/ApexColumnPinnedEvent.html +6 -0
- package/docs/interfaces/ApexColumnPinningEvent.html +8 -0
- package/docs/interfaces/ApexDetailContext.html +8 -0
- package/docs/interfaces/ApexFilteredEvent.html +4 -4
- package/docs/interfaces/ApexFilteringEvent.html +4 -4
- package/docs/interfaces/ApexGridEventMap.html +60 -9
- package/docs/interfaces/ApexHeaderContext.html +4 -4
- package/docs/interfaces/ApexPageChangedEvent.html +10 -0
- package/docs/interfaces/ApexPageChangingEvent.html +10 -0
- package/docs/interfaces/ApexQuickFilterChangedEvent.html +4 -0
- package/docs/interfaces/ApexQuickFilterChangingEvent.html +6 -0
- package/docs/interfaces/ApexRowEditEndedEvent.html +6 -0
- package/docs/interfaces/ApexRowEditStartedEvent.html +4 -0
- package/docs/interfaces/ApexRowExpandedEvent.html +8 -0
- package/docs/interfaces/ApexRowExpandingEvent.html +11 -0
- package/docs/interfaces/ApexRowSelectedEvent.html +8 -0
- package/docs/interfaces/ApexRowSelectingEvent.html +11 -0
- package/docs/interfaces/ApexTreeRowExpandedEvent.html +8 -0
- package/docs/interfaces/ApexTreeRowExpandingEvent.html +10 -0
- package/docs/interfaces/BaseApexCellContext.html +12 -6
- package/docs/interfaces/BaseApexEditorContext.html +19 -0
- package/docs/interfaces/BaseColumnConfiguration.html +88 -14
- package/docs/interfaces/BaseColumnSortConfiguration.html +4 -4
- package/docs/interfaces/BaseFilterExpression.html +5 -5
- package/docs/interfaces/BaseSortExpression.html +4 -4
- package/docs/interfaces/CSVExportOptions.html +22 -0
- package/docs/interfaces/ColumnFilterConfiguration.html +3 -3
- package/docs/interfaces/DataPipelineConfiguration.html +13 -4
- package/docs/interfaces/ExportFormat.html +10 -0
- package/docs/interfaces/ExportOptions.html +15 -0
- package/docs/interfaces/GridEditingConfiguration.html +10 -0
- package/docs/interfaces/GridExpansionConfiguration.html +15 -0
- package/docs/interfaces/GridSelectionConfiguration.html +11 -0
- package/docs/interfaces/GridSortConfiguration.html +4 -4
- package/docs/interfaces/GridTreeConfiguration.html +33 -0
- package/docs/interfaces/PaginationConfiguration.html +18 -0
- package/docs/interfaces/PaginationState.html +10 -0
- package/docs/media/LICENSE +80 -0
- package/docs/media/_tokens.scss +106 -0
- package/docs/media/package.json +85 -0
- package/docs/modules.html +1 -1
- package/docs/types/ApexCellContext.html +2 -2
- package/docs/types/ApexEditorContext.html +2 -0
- package/docs/types/BasePropertyType.html +2 -2
- package/docs/types/BaseSortComparer.html +2 -2
- package/docs/types/ColumnConfiguration.html +2 -2
- package/docs/types/ColumnDropPosition.html +2 -0
- package/docs/types/ColumnSortConfiguration.html +2 -2
- package/docs/types/DataPipelineHook.html +2 -2
- package/docs/types/DataPipelineParams.html +5 -5
- package/docs/types/DataType.html +47 -2
- package/docs/types/EditMode.html +6 -0
- package/docs/types/EditTrigger.html +4 -0
- package/docs/types/ExportCellValue.html +5 -0
- package/docs/types/ExportSource.html +8 -0
- package/docs/types/FilterCriteria.html +2 -2
- package/docs/types/FilterExpression.html +2 -2
- package/docs/types/Keys.html +2 -2
- package/docs/types/PaginationMode.html +6 -0
- package/docs/types/PinPosition.html +5 -0
- package/docs/types/PropertyType.html +2 -2
- package/docs/types/SelectionMode.html +7 -0
- package/docs/types/SortComparer.html +2 -2
- package/docs/types/SortExpression.html +2 -2
- package/docs/types/SortState.html +2 -2
- package/docs/types/SortingDirection.html +1 -1
- package/index.d.ts +5 -2
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/internal/column-types.d.ts +94 -0
- package/internal/column-types.js +428 -0
- package/internal/column-types.js.map +1 -0
- package/internal/export.d.ts +114 -0
- package/internal/export.js +122 -0
- package/internal/export.js.map +1 -0
- package/internal/feature-module.d.ts +27 -0
- package/internal/feature-module.js +2 -0
- package/internal/feature-module.js.map +1 -0
- package/internal/flip.d.ts +80 -0
- package/internal/flip.js +52 -0
- package/internal/flip.js.map +1 -0
- package/internal/icons.d.ts +31 -0
- package/internal/icons.js +145 -0
- package/internal/icons.js.map +1 -0
- package/internal/index.d.ts +20 -0
- package/internal/index.js +6 -0
- package/internal/index.js.map +1 -0
- package/internal/tags.d.ts +2 -0
- package/internal/tags.js +2 -0
- package/internal/tags.js.map +1 -1
- package/internal/types.d.ts +473 -3
- package/internal/types.js.map +1 -1
- package/internal/utils.d.ts +24 -1
- package/internal/utils.js +48 -7
- package/internal/utils.js.map +1 -1
- package/operations/filter/tree.d.ts +1 -1
- package/operations/filter/types.js.map +1 -1
- package/operations/pagination.d.ts +19 -0
- package/operations/pagination.js +12 -0
- package/operations/pagination.js.map +1 -0
- package/operations/quick-filter.d.ts +21 -0
- package/operations/quick-filter.js +26 -0
- package/operations/quick-filter.js.map +1 -0
- package/operations/sort/types.js.map +1 -1
- package/package.json +10 -5
- package/setup.d.ts +51 -0
- package/setup.js +31 -0
- package/setup.js.map +1 -0
- package/styles/_checkbox.css.js +3 -0
- package/styles/_checkbox.css.js.map +1 -0
- package/styles/_tokens.css.js +3 -0
- package/styles/_tokens.css.js.map +1 -0
- package/styles/body-cell/body-cell.css.js +1 -1
- package/styles/body-cell/body-cell.css.js.map +1 -1
- package/styles/body-cell/cell-renderers.css.js +3 -0
- package/styles/body-cell/cell-renderers.css.js.map +1 -0
- package/styles/body-row/body-row.css.js +1 -1
- package/styles/body-row/body-row.css.js.map +1 -1
- package/styles/filter-row/filter-row.css.js +1 -1
- package/styles/filter-row/filter-row.css.js.map +1 -1
- package/styles/grid/_grid.base.css.js +1 -1
- package/styles/grid/_grid.base.css.js.map +1 -1
- package/styles/grid/grid.css.js +3 -0
- package/styles/grid/grid.css.js.map +1 -0
- package/styles/header-cell/header-cell.css.js +1 -1
- package/styles/header-cell/header-cell.css.js.map +1 -1
- package/styles/header-row/header-row.base.css.js +1 -1
- package/styles/header-row/header-row.base.css.js.map +1 -1
- package/styles/paginator/paginator.css.d.ts +1 -0
- package/styles/paginator/paginator.css.js +3 -0
- package/styles/paginator/paginator.css.js.map +1 -0
- package/styles/toolbar/toolbar.css.d.ts +1 -0
- package/styles/toolbar/toolbar.css.js +3 -0
- package/styles/toolbar/toolbar.css.js.map +1 -0
- package/styles.css +17 -0
- package/internal/icon-registry.d.ts +0 -1
- package/internal/icon-registry.js +0 -29
- package/internal/icon-registry.js.map +0 -1
- package/internal/theming.d.ts +0 -34
- package/internal/theming.js +0 -123
- package/internal/theming.js.map +0 -1
- package/styles/grid/themes/light/grid.bootstrap.css.js +0 -3
- package/styles/grid/themes/light/grid.bootstrap.css.js.map +0 -1
- package/styles/grid/themes/light/grid.fluent.css.js +0 -3
- package/styles/grid/themes/light/grid.fluent.css.js.map +0 -1
- package/styles/grid/themes/light/grid.indigo.css.js +0 -3
- package/styles/grid/themes/light/grid.indigo.css.js.map +0 -1
- package/styles/grid/themes/light/grid.material.css.js +0 -3
- package/styles/grid/themes/light/grid.material.css.js.map +0 -1
- /package/styles/{grid/themes/light/grid.bootstrap.css.d.ts → _checkbox.css.d.ts} +0 -0
- /package/styles/{grid/themes/light/grid.fluent.css.d.ts → _tokens.css.d.ts} +0 -0
- /package/styles/{grid/themes/light/grid.indigo.css.d.ts → body-cell/cell-renderers.css.d.ts} +0 -0
- /package/styles/grid/{themes/light/grid.material.css.d.ts → grid.css.d.ts} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { ReactiveController } from 'lit';
|
|
2
|
+
import type { GridHost, PaginationState } from '../internal/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Default pagination state used when no `pagination` configuration is provided.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_PAGINATION: Readonly<{
|
|
7
|
+
mode: "local";
|
|
8
|
+
page: 0;
|
|
9
|
+
pageSize: 25;
|
|
10
|
+
pageSizeOptions: readonly number[];
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Reactive controller that owns the grid's pagination state.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Exposes a state machine for the current `page` and `pageSize`, derives `pageCount`
|
|
17
|
+
* from the host's data, and emits the cancellable `pageChanging` + `pageChanged`
|
|
18
|
+
* events on the grid host. Page slicing itself is performed by
|
|
19
|
+
* {@link PaginationDataOperation} so the controller does not mutate `dataView`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class PaginationController<T extends object> implements ReactiveController {
|
|
22
|
+
#private;
|
|
23
|
+
protected host: GridHost<T>;
|
|
24
|
+
/**
|
|
25
|
+
* The current zero-based page index.
|
|
26
|
+
*/
|
|
27
|
+
page: number;
|
|
28
|
+
/**
|
|
29
|
+
* The current page size.
|
|
30
|
+
*/
|
|
31
|
+
pageSize: number;
|
|
32
|
+
constructor(host: GridHost<T>);
|
|
33
|
+
hostConnected(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Whether pagination is enabled on the host grid.
|
|
36
|
+
*/
|
|
37
|
+
get enabled(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The total number of records before pagination is applied.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* For `'local'` mode this is the post-filter, post-sort dataset length. For `'remote'`
|
|
43
|
+
* mode the consumer must supply the value via `pagination.totalItems`.
|
|
44
|
+
*/
|
|
45
|
+
get totalItems(): number;
|
|
46
|
+
/**
|
|
47
|
+
* The total number of pages for the current data view and `pageSize`.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* Always at least `1` so a paginator can render a sensible "1 / 1" label for empty data.
|
|
51
|
+
*/
|
|
52
|
+
get pageCount(): number;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the resolved {@link PaginationState} for the current host.
|
|
55
|
+
*/
|
|
56
|
+
get state(): PaginationState;
|
|
57
|
+
/**
|
|
58
|
+
* Clamps a candidate `page` index into the valid `[0, pageCount - 1]` range.
|
|
59
|
+
*
|
|
60
|
+
* @param page - The candidate page index.
|
|
61
|
+
*/
|
|
62
|
+
clamp(page: number): number;
|
|
63
|
+
/**
|
|
64
|
+
* Re-clamps the current page after the dataset size (or `pageSize`) changes.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Called from the grid pipeline so paging never points past the last valid page.
|
|
68
|
+
* Mutates `page` in place and requests a re-render when the value changes.
|
|
69
|
+
*/
|
|
70
|
+
reclamp(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Navigates to `page`, emitting the cancellable `pageChanging` event first and
|
|
73
|
+
* the `pageChanged` event after the pipeline has applied.
|
|
74
|
+
*
|
|
75
|
+
* @param page - The target zero-based page index. Out-of-range values are clamped.
|
|
76
|
+
* @returns `true` if the change was applied, `false` if it was cancelled or a no-op.
|
|
77
|
+
*/
|
|
78
|
+
gotoPage(page: number): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* Sets the current page size and resets to the first page.
|
|
81
|
+
*
|
|
82
|
+
* @param size - The new page size. Must be a positive integer.
|
|
83
|
+
* @returns `true` if the change was applied, `false` if it was cancelled or a no-op.
|
|
84
|
+
*/
|
|
85
|
+
setPageSize(size: number): Promise<boolean>;
|
|
86
|
+
/**
|
|
87
|
+
* Navigates to the next page if not already on the last one.
|
|
88
|
+
*/
|
|
89
|
+
nextPage(): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Navigates to the previous page if not already on the first one.
|
|
92
|
+
*/
|
|
93
|
+
previousPage(): Promise<boolean>;
|
|
94
|
+
/**
|
|
95
|
+
* Navigates to the first page.
|
|
96
|
+
*/
|
|
97
|
+
firstPage(): Promise<boolean>;
|
|
98
|
+
/**
|
|
99
|
+
* Navigates to the last page.
|
|
100
|
+
*/
|
|
101
|
+
lastPage(): Promise<boolean>;
|
|
102
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { PIPELINE } from '../internal/constants.js';
|
|
2
|
+
export const DEFAULT_PAGINATION = Object.freeze({
|
|
3
|
+
mode: 'local',
|
|
4
|
+
page: 0,
|
|
5
|
+
pageSize: 25,
|
|
6
|
+
pageSizeOptions: Object.freeze([10, 25, 50, 100]),
|
|
7
|
+
});
|
|
8
|
+
export class PaginationController {
|
|
9
|
+
constructor(host) {
|
|
10
|
+
this.host = host;
|
|
11
|
+
this.page = DEFAULT_PAGINATION.page;
|
|
12
|
+
this.pageSize = DEFAULT_PAGINATION.pageSize;
|
|
13
|
+
this.host.addController(this);
|
|
14
|
+
}
|
|
15
|
+
hostConnected() { }
|
|
16
|
+
get enabled() {
|
|
17
|
+
return Boolean(this.host.pagination?.enabled);
|
|
18
|
+
}
|
|
19
|
+
get totalItems() {
|
|
20
|
+
const cfg = this.host.pagination;
|
|
21
|
+
if (cfg?.mode === 'remote') {
|
|
22
|
+
return Math.max(0, cfg?.totalItems ?? 0);
|
|
23
|
+
}
|
|
24
|
+
return this.host.dataState?.length ?? 0;
|
|
25
|
+
}
|
|
26
|
+
get pageCount() {
|
|
27
|
+
if (!this.pageSize)
|
|
28
|
+
return 1;
|
|
29
|
+
return Math.max(1, Math.ceil(this.totalItems / this.pageSize));
|
|
30
|
+
}
|
|
31
|
+
get state() {
|
|
32
|
+
return {
|
|
33
|
+
page: this.page,
|
|
34
|
+
pageSize: this.pageSize,
|
|
35
|
+
pageCount: this.pageCount,
|
|
36
|
+
totalItems: this.totalItems,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
clamp(page) {
|
|
40
|
+
if (!Number.isFinite(page))
|
|
41
|
+
return 0;
|
|
42
|
+
return Math.min(Math.max(0, Math.trunc(page)), Math.max(0, this.pageCount - 1));
|
|
43
|
+
}
|
|
44
|
+
reclamp() {
|
|
45
|
+
const next = this.clamp(this.page);
|
|
46
|
+
if (next !== this.page) {
|
|
47
|
+
this.page = next;
|
|
48
|
+
this.host.requestUpdate();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
#emitChanging(nextPage, nextPageSize) {
|
|
52
|
+
return this.host.emitEvent('pageChanging', {
|
|
53
|
+
detail: {
|
|
54
|
+
page: this.page,
|
|
55
|
+
pageSize: this.pageSize,
|
|
56
|
+
nextPage,
|
|
57
|
+
nextPageSize,
|
|
58
|
+
},
|
|
59
|
+
cancelable: true,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
#emitChanged() {
|
|
63
|
+
this.host.announce(`Page ${this.page + 1} of ${this.pageCount}`);
|
|
64
|
+
return this.host.emitEvent('pageChanged', { detail: this.state });
|
|
65
|
+
}
|
|
66
|
+
async gotoPage(page) {
|
|
67
|
+
const next = this.clamp(page);
|
|
68
|
+
if (next === this.page)
|
|
69
|
+
return false;
|
|
70
|
+
if (!this.#emitChanging(next, this.pageSize)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
this.page = next;
|
|
74
|
+
this.host.requestUpdate(PIPELINE);
|
|
75
|
+
await this.host.updateComplete;
|
|
76
|
+
this.#emitChanged();
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
async setPageSize(size) {
|
|
80
|
+
const next = Math.max(1, Math.trunc(size));
|
|
81
|
+
if (next === this.pageSize)
|
|
82
|
+
return false;
|
|
83
|
+
if (!this.#emitChanging(0, next)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
this.pageSize = next;
|
|
87
|
+
this.page = 0;
|
|
88
|
+
this.host.requestUpdate(PIPELINE);
|
|
89
|
+
await this.host.updateComplete;
|
|
90
|
+
this.#emitChanged();
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
nextPage() {
|
|
94
|
+
return this.gotoPage(this.page + 1);
|
|
95
|
+
}
|
|
96
|
+
previousPage() {
|
|
97
|
+
return this.gotoPage(this.page - 1);
|
|
98
|
+
}
|
|
99
|
+
firstPage() {
|
|
100
|
+
return this.gotoPage(0);
|
|
101
|
+
}
|
|
102
|
+
lastPage() {
|
|
103
|
+
return this.gotoPage(this.pageCount - 1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src/controllers/pagination.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAMpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,OAAgB;IACtB,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,EAAE;IACZ,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,CAAsB;CACvE,CAAC,CAAC;AAWH,MAAM,OAAO,oBAAoB;IAW/B,YAAsB,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;QAPhC,SAAI,GAAW,kBAAkB,CAAC,IAAI,CAAC;QAKvC,aAAQ,GAAW,kBAAkB,CAAC,QAAQ,CAAC;QAGpD,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAEM,aAAa,KAAI,CAAC;IAKzB,IAAW,OAAO;Q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IAQM,KAAK,CAAC,WAAW,CAAC,IAAY;QACnC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3C,IAAI,IAAI,KAAK,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAEzC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAClC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;QAC/B,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAKM,QAAQ;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC;IAKM,YAAY;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC;IAKM,SAAS;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAKM,QAAQ;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import type { ReactiveController } from 'lit';\nimport { PIPELINE } from '../internal/constants.js';\nimport type { GridHost, PaginationState } from '../internal/types.js';\n\n/**\n * Default pagination state used when no `pagination` configuration is provided.\n */\nexport const DEFAULT_PAGINATION = Object.freeze({\n mode: 'local' as const,\n page: 0,\n pageSize: 25,\n pageSizeOptions: Object.freeze([10, 25, 50, 100]) as readonly number[],\n});\n\n/**\n * Reactive controller that owns the grid's pagination state.\n *\n * @remarks\n * Exposes a state machine for the current `page` and `pageSize`, derives `pageCount`\n * from the host's data, and emits the cancellable `pageChanging` + `pageChanged`\n * events on the grid host. Page slicing itself is performed by\n * {@link PaginationDataOperation} so the controller does not mutate `dataView`.\n */\nexport class PaginationController<T extends object> implements ReactiveController {\n /**\n * The current zero-based page index.\n */\n public page: number = DEFAULT_PAGINATION.page;\n\n /**\n * The current page size.\n */\n public pageSize: number = DEFAULT_PAGINATION.pageSize;\n\n constructor(protected host: GridHost<T>) {\n this.host.addController(this);\n }\n\n public hostConnected() {}\n\n /**\n * Whether pagination is enabled on the host grid.\n */\n public get enabled(): boolean {\n return Boolean(this.host.pagination?.enabled);\n }\n\n /**\n * The total number of records before pagination is applied.\n *\n * @remarks\n * For `'local'` mode this is the post-filter, post-sort dataset length. For `'remote'`\n * mode the consumer must supply the value via `pagination.totalItems`.\n */\n public get totalItems(): number {\n const cfg = this.host.pagination;\n if (cfg?.mode === 'remote') {\n return Math.max(0, cfg?.totalItems ?? 0);\n }\n // @ts-expect-error - protected member access\n return this.host.dataState?.length ?? 0;\n }\n\n /**\n * The total number of pages for the current data view and `pageSize`.\n *\n * @remarks\n * Always at least `1` so a paginator can render a sensible \"1 / 1\" label for empty data.\n */\n public get pageCount(): number {\n if (!this.pageSize) return 1;\n return Math.max(1, Math.ceil(this.totalItems / this.pageSize));\n }\n\n /**\n * Returns the resolved {@link PaginationState} for the current host.\n */\n public get state(): PaginationState {\n return {\n page: this.page,\n pageSize: this.pageSize,\n pageCount: this.pageCount,\n totalItems: this.totalItems,\n };\n }\n\n /**\n * Clamps a candidate `page` index into the valid `[0, pageCount - 1]` range.\n *\n * @param page - The candidate page index.\n */\n public clamp(page: number): number {\n if (!Number.isFinite(page)) return 0;\n return Math.min(Math.max(0, Math.trunc(page)), Math.max(0, this.pageCount - 1));\n }\n\n /**\n * Re-clamps the current page after the dataset size (or `pageSize`) changes.\n *\n * @remarks\n * Called from the grid pipeline so paging never points past the last valid page.\n * Mutates `page` in place and requests a re-render when the value changes.\n */\n public reclamp(): void {\n const next = this.clamp(this.page);\n if (next !== this.page) {\n this.page = next;\n this.host.requestUpdate();\n }\n }\n\n #emitChanging(nextPage: number, nextPageSize: number) {\n return this.host.emitEvent('pageChanging', {\n detail: {\n page: this.page,\n pageSize: this.pageSize,\n nextPage,\n nextPageSize,\n },\n cancelable: true,\n });\n }\n\n #emitChanged() {\n this.host.announce(`Page ${this.page + 1} of ${this.pageCount}`);\n return this.host.emitEvent('pageChanged', { detail: this.state });\n }\n\n /**\n * Navigates to `page`, emitting the cancellable `pageChanging` event first and\n * the `pageChanged` event after the pipeline has applied.\n *\n * @param page - The target zero-based page index. Out-of-range values are clamped.\n * @returns `true` if the change was applied, `false` if it was cancelled or a no-op.\n */\n public async gotoPage(page: number): Promise<boolean> {\n const next = this.clamp(page);\n if (next === this.page) return false;\n\n if (!this.#emitChanging(next, this.pageSize)) {\n return false;\n }\n\n this.page = next;\n this.host.requestUpdate(PIPELINE);\n await this.host.updateComplete;\n this.#emitChanged();\n return true;\n }\n\n /**\n * Sets the current page size and resets to the first page.\n *\n * @param size - The new page size. Must be a positive integer.\n * @returns `true` if the change was applied, `false` if it was cancelled or a no-op.\n */\n public async setPageSize(size: number): Promise<boolean> {\n const next = Math.max(1, Math.trunc(size));\n if (next === this.pageSize) return false;\n\n if (!this.#emitChanging(0, next)) {\n return false;\n }\n\n this.pageSize = next;\n this.page = 0;\n this.host.requestUpdate(PIPELINE);\n await this.host.updateComplete;\n this.#emitChanged();\n return true;\n }\n\n /**\n * Navigates to the next page if not already on the last one.\n */\n public nextPage() {\n return this.gotoPage(this.page + 1);\n }\n\n /**\n * Navigates to the previous page if not already on the first one.\n */\n public previousPage() {\n return this.gotoPage(this.page - 1);\n }\n\n /**\n * Navigates to the first page.\n */\n public firstPage() {\n return this.gotoPage(0);\n }\n\n /**\n * Navigates to the last page.\n */\n public lastPage() {\n return this.gotoPage(this.pageCount - 1);\n }\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ReactiveController } from 'lit';
|
|
2
|
+
import type { ColumnConfiguration, GridHost, Keys } from '../internal/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Live drag state surfaced to the header row so it can render the floating
|
|
5
|
+
* "ghost" element that follows the cursor.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The dragged column itself stays in the columns array — we live-swap it
|
|
9
|
+
* with neighbours as the cursor crosses their midpoints, so the rendered
|
|
10
|
+
* order updates while the user is still dragging. The ghost is purely a
|
|
11
|
+
* visual indicator of what the user is grabbing.
|
|
12
|
+
*/
|
|
13
|
+
interface ReorderState<T> {
|
|
14
|
+
/** The column currently being dragged. */
|
|
15
|
+
sourceKey: Keys<T>;
|
|
16
|
+
/** Ghost position (viewport-relative top-left, in CSS pixels). */
|
|
17
|
+
ghostX: number;
|
|
18
|
+
ghostY: number;
|
|
19
|
+
/** Ghost size — fixed at the source header's initial bounding rect. */
|
|
20
|
+
ghostWidth: number;
|
|
21
|
+
ghostHeight: number;
|
|
22
|
+
/** Cursor offset within the ghost so the grab point stays under the cursor. */
|
|
23
|
+
pointerOffsetX: number;
|
|
24
|
+
pointerOffsetY: number;
|
|
25
|
+
/** Display label for the ghost (header text or column key). */
|
|
26
|
+
label: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reactive controller backing pointer-driven column reordering with a
|
|
30
|
+
* floating ghost and live mid-drag swaps.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Headers feed `pointerdown` / `pointermove` / `pointerup` events into the
|
|
34
|
+
* controller. While dragging, the controller updates the ghost position and
|
|
35
|
+
* decides whether the cursor has crossed an adjacent column's midpoint —
|
|
36
|
+
* if so it calls {@link ApexGrid.moveColumn} immediately, so the swap
|
|
37
|
+
* happens during the drag instead of waiting for drop. The same cancellable
|
|
38
|
+
* `columnMoving` / follow-up `columnMoved` event pipeline applies for
|
|
39
|
+
* every swap.
|
|
40
|
+
*/
|
|
41
|
+
export declare class ReorderController<T extends object> implements ReactiveController {
|
|
42
|
+
#private;
|
|
43
|
+
protected host: GridHost<T>;
|
|
44
|
+
state: ReorderState<T> | null;
|
|
45
|
+
constructor(host: GridHost<T>);
|
|
46
|
+
hostConnected(): void;
|
|
47
|
+
protected get headerRow(): (HTMLElement & {
|
|
48
|
+
headers?: Array<HTMLElement & {
|
|
49
|
+
column: ColumnConfiguration<T>;
|
|
50
|
+
}>;
|
|
51
|
+
}) | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Whether reordering is enabled for the given column.
|
|
54
|
+
*/
|
|
55
|
+
isDraggable(column: ColumnConfiguration<T>): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Whether `source` may be dropped onto `target`. Cross-pinning-group moves
|
|
58
|
+
* are blocked so the drag can't escape its pin region.
|
|
59
|
+
*/
|
|
60
|
+
canDrop(source: ColumnConfiguration<T>, target: ColumnConfiguration<T>): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Begins a drag from `sourceKey`. Captures the source's bounding rect and
|
|
63
|
+
* the cursor offset within it so the ghost stays anchored to the grab
|
|
64
|
+
* point as the cursor moves.
|
|
65
|
+
*/
|
|
66
|
+
start(sourceKey: Keys<T>, sourceRect: DOMRect, initialClientX: number, initialClientY: number, label: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Updates the ghost position and decides whether to swap with an adjacent
|
|
69
|
+
* column.
|
|
70
|
+
*/
|
|
71
|
+
move(clientX: number, clientY: number): void;
|
|
72
|
+
/**
|
|
73
|
+
* Ends the drag session. The columns are already in their final order
|
|
74
|
+
* because we live-swapped during the drag, so there's nothing to commit.
|
|
75
|
+
*/
|
|
76
|
+
end(): void;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { awaitChildUpdates, captureRect, playFlip } from '../internal/flip.js';
|
|
2
|
+
export class ReorderController {
|
|
3
|
+
#swapping;
|
|
4
|
+
constructor(host) {
|
|
5
|
+
this.host = host;
|
|
6
|
+
this.state = null;
|
|
7
|
+
this.#swapping = false;
|
|
8
|
+
this.host.addController(this);
|
|
9
|
+
}
|
|
10
|
+
hostConnected() { }
|
|
11
|
+
get headerRow() {
|
|
12
|
+
return this.host.headerRow;
|
|
13
|
+
}
|
|
14
|
+
isDraggable(column) {
|
|
15
|
+
if (!this.host.columnReordering)
|
|
16
|
+
return false;
|
|
17
|
+
if (column.hidden)
|
|
18
|
+
return false;
|
|
19
|
+
return column.reorderable !== false;
|
|
20
|
+
}
|
|
21
|
+
canDrop(source, target) {
|
|
22
|
+
if (source.key === target.key)
|
|
23
|
+
return false;
|
|
24
|
+
if (!this.isDraggable(source) || !this.isDraggable(target))
|
|
25
|
+
return false;
|
|
26
|
+
return (source.pinned ?? null) === (target.pinned ?? null);
|
|
27
|
+
}
|
|
28
|
+
start(sourceKey, sourceRect, initialClientX, initialClientY, label) {
|
|
29
|
+
this.state = {
|
|
30
|
+
sourceKey,
|
|
31
|
+
ghostX: sourceRect.left,
|
|
32
|
+
ghostY: sourceRect.top,
|
|
33
|
+
ghostWidth: sourceRect.width,
|
|
34
|
+
ghostHeight: sourceRect.height,
|
|
35
|
+
pointerOffsetX: initialClientX - sourceRect.left,
|
|
36
|
+
pointerOffsetY: initialClientY - sourceRect.top,
|
|
37
|
+
label,
|
|
38
|
+
};
|
|
39
|
+
this.host.requestUpdate();
|
|
40
|
+
}
|
|
41
|
+
move(clientX, clientY) {
|
|
42
|
+
if (!this.state)
|
|
43
|
+
return;
|
|
44
|
+
this.state = {
|
|
45
|
+
...this.state,
|
|
46
|
+
ghostX: clientX - this.state.pointerOffsetX,
|
|
47
|
+
ghostY: clientY - this.state.pointerOffsetY,
|
|
48
|
+
};
|
|
49
|
+
this.host.requestUpdate();
|
|
50
|
+
void this.#checkSwap(clientX);
|
|
51
|
+
}
|
|
52
|
+
end() {
|
|
53
|
+
if (!this.state)
|
|
54
|
+
return;
|
|
55
|
+
this.state = null;
|
|
56
|
+
this.host.requestUpdate();
|
|
57
|
+
}
|
|
58
|
+
async #checkSwap(clientX) {
|
|
59
|
+
if (!this.state || this.#swapping)
|
|
60
|
+
return;
|
|
61
|
+
const source = this.host.getColumn(this.state.sourceKey);
|
|
62
|
+
if (!source)
|
|
63
|
+
return;
|
|
64
|
+
const headerRow = this.headerRow;
|
|
65
|
+
if (!headerRow?.headers)
|
|
66
|
+
return;
|
|
67
|
+
const target = headerRow.headers.find((h) => {
|
|
68
|
+
const rect = h.getBoundingClientRect();
|
|
69
|
+
return clientX >= rect.left && clientX < rect.right;
|
|
70
|
+
});
|
|
71
|
+
if (!target || target.column.key === source.key)
|
|
72
|
+
return;
|
|
73
|
+
if (!this.canDrop(source, target.column))
|
|
74
|
+
return;
|
|
75
|
+
const rect = target.getBoundingClientRect();
|
|
76
|
+
const midpoint = rect.left + rect.width / 2;
|
|
77
|
+
const visibleColumns = this.host.columns.filter((c) => !c.hidden);
|
|
78
|
+
const sourceIdx = visibleColumns.findIndex((c) => c.key === source.key);
|
|
79
|
+
const targetIdx = visibleColumns.findIndex((c) => c.key === target.column.key);
|
|
80
|
+
if (sourceIdx === -1 || targetIdx === -1)
|
|
81
|
+
return;
|
|
82
|
+
let position;
|
|
83
|
+
if (sourceIdx < targetIdx) {
|
|
84
|
+
if (clientX < midpoint)
|
|
85
|
+
return;
|
|
86
|
+
position = 'after';
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (clientX > midpoint)
|
|
90
|
+
return;
|
|
91
|
+
position = 'before';
|
|
92
|
+
}
|
|
93
|
+
this.#swapping = true;
|
|
94
|
+
try {
|
|
95
|
+
const before = this.#captureCellRects();
|
|
96
|
+
await this.host.moveColumn(source.key, target.column.key, position);
|
|
97
|
+
await this.host.updateComplete;
|
|
98
|
+
await awaitChildUpdates([
|
|
99
|
+
this.headerRow,
|
|
100
|
+
...this.host.rows,
|
|
101
|
+
]);
|
|
102
|
+
playFlip(before, 'x');
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
this.#swapping = false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
#captureCellRects() {
|
|
109
|
+
const entries = [];
|
|
110
|
+
const headerRow = this.headerRow;
|
|
111
|
+
if (headerRow?.headers) {
|
|
112
|
+
for (const header of headerRow.headers) {
|
|
113
|
+
entries.push(captureRect(header));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (const row of this.host.rows) {
|
|
117
|
+
for (const cell of row.cells) {
|
|
118
|
+
entries.push(captureRect(cell));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return entries;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=reorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reorder.js","sourceRoot":"","sources":["../../src/controllers/reorder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAkB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AA0C/F,MAAM,OAAO,iBAAiB;IAI5B,SAAS,CAAS;IAElB,YAAsB,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;QALhC,UAAK,GAA2B,IAAI,CAAC;QAG5C,cAAS,GAAG,KAAK,CAAC;QAGhB,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAEM,aAAa,KAAI,CAAC;IAEzB,IAAc,SAAS;QAErB,OAAO,IAAI,CAAC,IAAI,CAAC,SAEJ,CAAC;IAChB,CAAC;IAKM,WAAW,CAAC,MAA8B;QAC/C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,OAAO,KAAK,CAAC;QAC9C,IAAI,MAAM,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAChC,OAAO,MAAM,CAAC,WAAW,KAAK,KAAK,CAAC;IACtC,CAAC;IAMM,OAAO,C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AE,OAAO,EAAE,CAAC;YACvB,KAAK,MAAM,MAAM,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;gBACvC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;QACD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACjC,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;gBAC7B,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,IAA8B,CAAC,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import type { ReactiveController } from 'lit';\nimport { awaitChildUpdates, captureRect, type FlipEntry, playFlip } from '../internal/flip.js';\nimport type { ColumnConfiguration, GridHost, Keys } from '../internal/types.js';\n\n/**\n * Live drag state surfaced to the header row so it can render the floating\n * \"ghost\" element that follows the cursor.\n *\n * @remarks\n * The dragged column itself stays in the columns array — we live-swap it\n * with neighbours as the cursor crosses their midpoints, so the rendered\n * order updates while the user is still dragging. The ghost is purely a\n * visual indicator of what the user is grabbing.\n */\ninterface ReorderState<T> {\n /** The column currently being dragged. */\n sourceKey: Keys<T>;\n /** Ghost position (viewport-relative top-left, in CSS pixels). */\n ghostX: number;\n ghostY: number;\n /** Ghost size — fixed at the source header's initial bounding rect. */\n ghostWidth: number;\n ghostHeight: number;\n /** Cursor offset within the ghost so the grab point stays under the cursor. */\n pointerOffsetX: number;\n pointerOffsetY: number;\n /** Display label for the ghost (header text or column key). */\n label: string;\n}\n\n/**\n * Reactive controller backing pointer-driven column reordering with a\n * floating ghost and live mid-drag swaps.\n *\n * @remarks\n * Headers feed `pointerdown` / `pointermove` / `pointerup` events into the\n * controller. While dragging, the controller updates the ghost position and\n * decides whether the cursor has crossed an adjacent column's midpoint —\n * if so it calls {@link ApexGrid.moveColumn} immediately, so the swap\n * happens during the drag instead of waiting for drop. The same cancellable\n * `columnMoving` / follow-up `columnMoved` event pipeline applies for\n * every swap.\n */\nexport class ReorderController<T extends object> implements ReactiveController {\n public state: ReorderState<T> | null = null;\n\n /** Re-entrancy guard so a slow `moveColumn` can't trigger a second swap. */\n #swapping = false;\n\n constructor(protected host: GridHost<T>) {\n this.host.addController(this);\n }\n\n public hostConnected() {}\n\n protected get headerRow() {\n // @ts-expect-error - protected member access\n return this.host.headerRow as\n | (HTMLElement & { headers?: Array<HTMLElement & { column: ColumnConfiguration<T> }> })\n | undefined;\n }\n\n /**\n * Whether reordering is enabled for the given column.\n */\n public isDraggable(column: ColumnConfiguration<T>): boolean {\n if (!this.host.columnReordering) return false;\n if (column.hidden) return false;\n return column.reorderable !== false;\n }\n\n /**\n * Whether `source` may be dropped onto `target`. Cross-pinning-group moves\n * are blocked so the drag can't escape its pin region.\n */\n public canDrop(source: ColumnConfiguration<T>, target: ColumnConfiguration<T>): boolean {\n if (source.key === target.key) return false;\n if (!this.isDraggable(source) || !this.isDraggable(target)) return false;\n return (source.pinned ?? null) === (target.pinned ?? null);\n }\n\n /**\n * Begins a drag from `sourceKey`. Captures the source's bounding rect and\n * the cursor offset within it so the ghost stays anchored to the grab\n * point as the cursor moves.\n */\n public start(\n sourceKey: Keys<T>,\n sourceRect: DOMRect,\n initialClientX: number,\n initialClientY: number,\n label: string\n ): void {\n this.state = {\n sourceKey,\n ghostX: sourceRect.left,\n ghostY: sourceRect.top,\n ghostWidth: sourceRect.width,\n ghostHeight: sourceRect.height,\n pointerOffsetX: initialClientX - sourceRect.left,\n pointerOffsetY: initialClientY - sourceRect.top,\n label,\n };\n this.host.requestUpdate();\n }\n\n /**\n * Updates the ghost position and decides whether to swap with an adjacent\n * column.\n */\n public move(clientX: number, clientY: number): void {\n if (!this.state) return;\n this.state = {\n ...this.state,\n ghostX: clientX - this.state.pointerOffsetX,\n ghostY: clientY - this.state.pointerOffsetY,\n };\n this.host.requestUpdate();\n void this.#checkSwap(clientX);\n }\n\n /**\n * Ends the drag session. The columns are already in their final order\n * because we live-swapped during the drag, so there's nothing to commit.\n */\n public end(): void {\n if (!this.state) return;\n this.state = null;\n this.host.requestUpdate();\n }\n\n async #checkSwap(clientX: number): Promise<void> {\n if (!this.state || this.#swapping) return;\n const source = this.host.getColumn(this.state.sourceKey);\n if (!source) return;\n const headerRow = this.headerRow;\n if (!headerRow?.headers) return;\n\n // Find the visible header whose box currently contains the cursor X.\n const target = headerRow.headers.find((h) => {\n const rect = h.getBoundingClientRect();\n return clientX >= rect.left && clientX < rect.right;\n });\n if (!target || target.column.key === source.key) return;\n if (!this.canDrop(source, target.column)) return;\n\n // Only swap once the cursor crosses the target's midpoint, so we don't\n // bounce back and forth as soon as the ghost touches the edge.\n const rect = target.getBoundingClientRect();\n const midpoint = rect.left + rect.width / 2;\n const visibleColumns = this.host.columns.filter((c) => !c.hidden);\n const sourceIdx = visibleColumns.findIndex((c) => c.key === source.key);\n const targetIdx = visibleColumns.findIndex((c) => c.key === target.column.key);\n if (sourceIdx === -1 || targetIdx === -1) return;\n\n let position: 'before' | 'after';\n if (sourceIdx < targetIdx) {\n // Dragging right — swap when the cursor crosses past the target's centre.\n if (clientX < midpoint) return;\n position = 'after';\n } else {\n // Dragging left — swap when the cursor crosses before the target's centre.\n if (clientX > midpoint) return;\n position = 'before';\n }\n\n this.#swapping = true;\n try {\n const before = this.#captureCellRects();\n await this.host.moveColumn(source.key, target.column.key, position);\n await this.host.updateComplete;\n // Child rows + header row schedule their own updates one microtask\n // after the grid — wait for them so the cells have actually moved\n // before measuring the \"Last\" rect.\n await awaitChildUpdates([\n this.headerRow as unknown as { updateComplete: Promise<unknown> } | undefined,\n ...this.host.rows,\n ]);\n playFlip(before, 'x');\n } finally {\n this.#swapping = false;\n }\n }\n\n /**\n * Snapshots the bounding rect of every header + body cell before a\n * swap. Used as the \"First\" step of a FLIP — after `moveColumn` resolves,\n * `playFlip` computes the delta against the new rect and animates each\n * element from its old position back to identity.\n */\n #captureCellRects(): FlipEntry[] {\n const entries: FlipEntry[] = [];\n const headerRow = this.headerRow;\n if (headerRow?.headers) {\n for (const header of headerRow.headers) {\n entries.push(captureRect(header));\n }\n }\n for (const row of this.host.rows) {\n for (const cell of row.cells) {\n entries.push(captureRect(cell as unknown as HTMLElement));\n }\n }\n return entries;\n }\n}\n"]}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { ReactiveController } from 'lit';
|
|
2
|
+
import type { GridHost, SelectionMode } from '../internal/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The default selection configuration used when the grid has none set.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_SELECTION_CONFIG: Readonly<{
|
|
7
|
+
enabled: false;
|
|
8
|
+
mode: SelectionMode;
|
|
9
|
+
showCheckboxColumn: false;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Reactive controller backing row selection.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Selection state is reference-based — the controller holds a `Set` of row
|
|
16
|
+
* data references so the selection survives sort / filter / pagination as
|
|
17
|
+
* long as those operations preserve identities (the default in-place
|
|
18
|
+
* pipeline does). Replacing {@link ApexGrid.data} wholesale will invalidate
|
|
19
|
+
* any selected rows that are no longer present in the new array; consumers
|
|
20
|
+
* should call {@link clear} or re-apply selection after such a change.
|
|
21
|
+
*
|
|
22
|
+
* Mutations go through the cancellable `rowSelecting` event and emit a
|
|
23
|
+
* follow-up `rowSelected` event, mirroring the pattern used by editing.
|
|
24
|
+
*/
|
|
25
|
+
export declare class SelectionController<T extends object> implements ReactiveController {
|
|
26
|
+
#private;
|
|
27
|
+
protected host: GridHost<T>;
|
|
28
|
+
/** Set of currently selected row data references. */
|
|
29
|
+
selected: Set<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Anchor row for Shift+click range selection. Set whenever a single row
|
|
32
|
+
* is toggled / picked so a follow-up Shift+click knows where to start.
|
|
33
|
+
*/
|
|
34
|
+
anchor: T | null;
|
|
35
|
+
constructor(host: GridHost<T>);
|
|
36
|
+
hostConnected(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Whether selection is enabled at the grid level.
|
|
39
|
+
*/
|
|
40
|
+
get enabled(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The resolved selection mode (`'multiple'` if unset).
|
|
43
|
+
*/
|
|
44
|
+
get mode(): SelectionMode;
|
|
45
|
+
/**
|
|
46
|
+
* Whether to render the built-in checkbox column.
|
|
47
|
+
*/
|
|
48
|
+
get showCheckboxColumn(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the given row is currently selected.
|
|
51
|
+
*/
|
|
52
|
+
isSelected(row: T): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the currently selected rows in insertion order.
|
|
55
|
+
*/
|
|
56
|
+
selectedRows(): T[];
|
|
57
|
+
/**
|
|
58
|
+
* Whether every row in the current view ({@link ApexGrid.dataView}) is
|
|
59
|
+
* selected. Used by the header checkbox to render its "all" state.
|
|
60
|
+
*/
|
|
61
|
+
allSelected(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Whether some — but not all — rows in the current view are selected.
|
|
64
|
+
* Used to render the header checkbox in its indeterminate state.
|
|
65
|
+
*/
|
|
66
|
+
someSelected(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Toggles selection of `row`. In `'single'` mode this either selects the
|
|
69
|
+
* row (replacing any previous selection) or deselects it if it was the
|
|
70
|
+
* only selected row.
|
|
71
|
+
*/
|
|
72
|
+
toggleRow(row: T): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Adds `row` to the selection. In `'single'` mode the existing selection
|
|
75
|
+
* is cleared first.
|
|
76
|
+
*/
|
|
77
|
+
selectRow(row: T): Promise<boolean>;
|
|
78
|
+
/**
|
|
79
|
+
* Removes `row` from the selection.
|
|
80
|
+
*/
|
|
81
|
+
deselectRow(row: T): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Adds `row` to the selection without affecting other selected rows
|
|
84
|
+
* (`'multiple'` mode only). In `'single'` mode this behaves like
|
|
85
|
+
* {@link selectRow}.
|
|
86
|
+
*/
|
|
87
|
+
additiveToggle(row: T): Promise<boolean>;
|
|
88
|
+
/**
|
|
89
|
+
* Selects every row between {@link anchor} and `row` (inclusive) in the
|
|
90
|
+
* current page view. No-op in `'single'` mode or when no anchor is set —
|
|
91
|
+
* in those cases the call falls back to a plain {@link selectRow}.
|
|
92
|
+
*/
|
|
93
|
+
rangeToggle(row: T): Promise<boolean>;
|
|
94
|
+
/**
|
|
95
|
+
* Selects every row currently in view ({@link ApexGrid.dataView}). No-op
|
|
96
|
+
* in `'single'` mode.
|
|
97
|
+
*/
|
|
98
|
+
selectAll(): Promise<boolean>;
|
|
99
|
+
/**
|
|
100
|
+
* Clears the selection.
|
|
101
|
+
*/
|
|
102
|
+
clear(): Promise<boolean>;
|
|
103
|
+
/**
|
|
104
|
+
* Replaces the current selection with `rows`. Used by the public
|
|
105
|
+
* {@link ApexGrid.selectedRows} setter so callers can drive selection
|
|
106
|
+
* programmatically. Single-mode keeps at most one row.
|
|
107
|
+
*/
|
|
108
|
+
replaceSelection(rows: ReadonlyArray<T>): Promise<boolean>;
|
|
109
|
+
}
|