apex-grid 3.6.0 → 4.0.0-beta.2

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.
Files changed (151) hide show
  1. package/CHANGELOG.md +301 -0
  2. package/LICENSE.md +2 -1
  3. package/README.md +117 -18
  4. package/components/cell.d.ts +13 -1
  5. package/components/cell.js +28 -13
  6. package/components/cell.js.map +1 -1
  7. package/components/grid.d.ts +175 -28
  8. package/components/grid.js +183 -63
  9. package/components/grid.js.map +1 -1
  10. package/components/header-row.d.ts +0 -6
  11. package/components/header-row.js +1 -19
  12. package/components/header-row.js.map +1 -1
  13. package/components/header.js +39 -2
  14. package/components/header.js.map +1 -1
  15. package/components/paginator.d.ts +20 -5
  16. package/components/paginator.js +54 -17
  17. package/components/paginator.js.map +1 -1
  18. package/components/row.js +149 -40
  19. package/components/row.js.map +1 -1
  20. package/components/toolbar.d.ts +5 -1
  21. package/components/toolbar.js +4 -1
  22. package/components/toolbar.js.map +1 -1
  23. package/components/virtualize-rows.d.ts +38 -0
  24. package/components/virtualize-rows.js +286 -0
  25. package/components/virtualize-rows.js.map +1 -0
  26. package/components/virtualizer.d.ts +71 -1
  27. package/components/virtualizer.js +105 -29
  28. package/components/virtualizer.js.map +1 -1
  29. package/controllers/dom.d.ts +10 -3
  30. package/controllers/dom.js +5 -5
  31. package/controllers/dom.js.map +1 -1
  32. package/controllers/navigation.d.ts +63 -0
  33. package/controllers/navigation.js +295 -21
  34. package/controllers/navigation.js.map +1 -1
  35. package/controllers/pagination.d.ts +7 -6
  36. package/controllers/pagination.js +27 -28
  37. package/controllers/pagination.js.map +1 -1
  38. package/controllers/row-pin.d.ts +6 -0
  39. package/controllers/row-pin.js +8 -2
  40. package/controllers/row-pin.js.map +1 -1
  41. package/controllers/row-reorder.d.ts +12 -4
  42. package/controllers/row-reorder.js +20 -6
  43. package/controllers/row-reorder.js.map +1 -1
  44. package/controllers/selection.d.ts +32 -10
  45. package/controllers/selection.js +33 -10
  46. package/controllers/selection.js.map +1 -1
  47. package/controllers/sort.js +2 -3
  48. package/controllers/sort.js.map +1 -1
  49. package/controllers/state.d.ts +18 -5
  50. package/controllers/state.js +53 -46
  51. package/controllers/state.js.map +1 -1
  52. package/custom-elements.json +1762 -339
  53. package/docs/assets/hierarchy.js +1 -1
  54. package/docs/assets/search.js +1 -1
  55. package/docs/classes/ApexGrid.html +166 -66
  56. package/docs/classes/ApexGridPaginator.html +39 -8
  57. package/docs/classes/ApexGridToolbar.html +9 -5
  58. package/docs/functions/localize.html +2 -2
  59. package/docs/hierarchy.html +1 -1
  60. package/docs/index.html +123 -20
  61. package/docs/interfaces/ApexPageChangedEvent.html +3 -1
  62. package/docs/interfaces/BaseApexCellContext.html +18 -5
  63. package/docs/interfaces/BaseApexEditorContext.html +20 -5
  64. package/docs/interfaces/BaseFilterExpression.html +1 -1
  65. package/docs/interfaces/CSVExportOptions.html +1 -1
  66. package/docs/interfaces/DataPipelineConfiguration.html +4 -9
  67. package/docs/interfaces/ExportOptions.html +1 -1
  68. package/docs/interfaces/GridSelectionConfiguration.html +19 -4
  69. package/docs/interfaces/PaginationConfiguration.html +11 -4
  70. package/docs/interfaces/PaginationState.html +4 -2
  71. package/docs/media/_token-values.scss +42 -16
  72. package/docs/media/package.json +12 -4
  73. package/docs/types/DataPipelineParams.html +2 -2
  74. package/docs/types/PaginationMode.html +5 -4
  75. package/docs/variables/EN_LOCALE.html +2 -2
  76. package/i18n/en.d.ts +2 -0
  77. package/i18n/en.js +2 -0
  78. package/i18n/en.js.map +1 -1
  79. package/i18n/es.js +2 -0
  80. package/i18n/es.js.map +1 -1
  81. package/ignite-ui.d.ts +1 -0
  82. package/ignite-ui.js +4 -0
  83. package/ignite-ui.js.map +1 -0
  84. package/internal/column-types.d.ts +11 -1
  85. package/internal/column-types.js +8 -6
  86. package/internal/column-types.js.map +1 -1
  87. package/internal/design-system.d.ts +32 -0
  88. package/internal/design-system.js +66 -0
  89. package/internal/design-system.js.map +1 -0
  90. package/internal/export.d.ts +6 -0
  91. package/internal/export.js +4 -0
  92. package/internal/export.js.map +1 -1
  93. package/internal/feature-module.d.ts +7 -0
  94. package/internal/feature-module.js.map +1 -1
  95. package/internal/flip.d.ts +28 -16
  96. package/internal/flip.js +42 -10
  97. package/internal/flip.js.map +1 -1
  98. package/internal/icons.d.ts +2 -16
  99. package/internal/icons.js +0 -8
  100. package/internal/icons.js.map +1 -1
  101. package/internal/ignite-ui.d.ts +10 -0
  102. package/internal/ignite-ui.js +118 -0
  103. package/internal/ignite-ui.js.map +1 -0
  104. package/internal/index.d.ts +4 -2
  105. package/internal/index.js +3 -2
  106. package/internal/index.js.map +1 -1
  107. package/internal/types.d.ts +75 -19
  108. package/internal/types.js.map +1 -1
  109. package/operations/filter/types.d.ts +1 -1
  110. package/operations/filter/types.js.map +1 -1
  111. package/package.json +7 -2
  112. package/styles/_token-blocks.css.d.ts +1 -0
  113. package/styles/_token-blocks.css.js +3 -0
  114. package/styles/_token-blocks.css.js.map +1 -0
  115. package/styles/_tokens.css.js +1 -1
  116. package/styles/_tokens.css.js.map +1 -1
  117. package/styles/body-cell/body-cell.css.js +1 -1
  118. package/styles/body-cell/body-cell.css.js.map +1 -1
  119. package/styles/body-cell/cell-renderers.css.js +1 -1
  120. package/styles/body-cell/cell-renderers.css.js.map +1 -1
  121. package/styles/body-row/body-row.css.js +1 -1
  122. package/styles/body-row/body-row.css.js.map +1 -1
  123. package/styles/document-tokens.css.js +1 -1
  124. package/styles/document-tokens.css.js.map +1 -1
  125. package/styles/grid/_grid.base.css.js +1 -1
  126. package/styles/grid/_grid.base.css.js.map +1 -1
  127. package/styles/grid/grid.css.js +1 -1
  128. package/styles/grid/grid.css.js.map +1 -1
  129. package/styles/group-header-row/group-header-row.css.js +1 -1
  130. package/styles/group-header-row/group-header-row.css.js.map +1 -1
  131. package/styles/header-cell/header-cell.css.js +1 -1
  132. package/styles/header-cell/header-cell.css.js.map +1 -1
  133. package/styles/header-row/header-row.base.css.js +1 -1
  134. package/styles/header-row/header-row.base.css.js.map +1 -1
  135. package/styles/ignite-ui/ignite-ui-dark.css.d.ts +1 -0
  136. package/styles/ignite-ui/ignite-ui-dark.css.js +3 -0
  137. package/styles/ignite-ui/ignite-ui-dark.css.js.map +1 -0
  138. package/styles/ignite-ui/ignite-ui-document.css.d.ts +1 -0
  139. package/styles/ignite-ui/ignite-ui-document.css.js +3 -0
  140. package/styles/ignite-ui/ignite-ui-document.css.js.map +1 -0
  141. package/styles/ignite-ui/ignite-ui.css.d.ts +1 -0
  142. package/styles/ignite-ui/ignite-ui.css.js +3 -0
  143. package/styles/ignite-ui/ignite-ui.css.js.map +1 -0
  144. package/styles/paginator/paginator.css.js +1 -1
  145. package/styles/paginator/paginator.css.js.map +1 -1
  146. package/styles/toolbar/toolbar.css.js +1 -1
  147. package/styles/toolbar/toolbar.css.js.map +1 -1
  148. package/tokens.css +14 -15
  149. package/operations/pagination.d.ts +0 -19
  150. package/operations/pagination.js +0 -12
  151. package/operations/pagination.js.map +0 -1
@@ -15,8 +15,8 @@ export declare const DEFAULT_PAGINATION: Readonly<{
15
15
  * @remarks
16
16
  * Exposes a state machine for the current `page` and `pageSize`, derives `pageCount`
17
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`.
18
+ * events on the grid host. The page slice itself is read from
19
+ * {@link ApexGrid.pageItems}, so the controller never mutates `dataView`.
20
20
  */
21
21
  export declare class PaginationController<T extends object> implements ReactiveController {
22
22
  #private;
@@ -36,11 +36,12 @@ export declare class PaginationController<T extends object> implements ReactiveC
36
36
  */
37
37
  get enabled(): boolean;
38
38
  /**
39
- * The total number of records before pagination is applied.
39
+ * The number of rows paged through (see {@link ApexGrid.totalItems}).
40
40
  *
41
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`.
42
+ * For `'local'` mode this is the post-filter, post-sort row count; with pagination
43
+ * enabled it leaves out the pinned rows, so it counts the rows {@link ApexGrid.pageItems}
44
+ * slices. For `'remote'` mode the consumer supplies the value via `pagination.totalItems`.
44
45
  */
45
46
  get totalItems(): number;
46
47
  /**
@@ -70,7 +71,7 @@ export declare class PaginationController<T extends object> implements ReactiveC
70
71
  reclamp(): void;
71
72
  /**
72
73
  * Navigates to `page`, emitting the cancellable `pageChanging` event first and
73
- * the `pageChanged` event after the pipeline has applied.
74
+ * the `pageChanged` event after the change rendered.
74
75
  *
75
76
  * @param page - The target zero-based page index. Out-of-range values are clamped.
76
77
  * @returns `true` if the change was applied, `false` if it was cancelled or a no-op.
@@ -21,20 +21,18 @@ export class PaginationController {
21
21
  if (cfg?.mode === 'remote') {
22
22
  return Math.max(0, cfg?.totalItems ?? 0);
23
23
  }
24
- return this.host.dataState?.length ?? 0;
24
+ return (this.enabled ? this.host.bodyRows : this.host.dataState)?.length ?? 0;
25
25
  }
26
26
  get pageCount() {
27
- if (!this.pageSize)
28
- return 1;
29
- return Math.max(1, Math.ceil(this.totalItems / this.pageSize));
27
+ return this.state.pageCount;
30
28
  }
31
29
  get state() {
32
- return {
33
- page: this.page,
34
- pageSize: this.pageSize,
35
- pageCount: this.pageCount,
36
- totalItems: this.totalItems,
37
- };
30
+ return this.#stateFor(this.page, this.pageSize);
31
+ }
32
+ #stateFor(page, pageSize) {
33
+ const totalItems = this.totalItems;
34
+ const pageCount = pageSize ? Math.max(1, Math.ceil(totalItems / pageSize)) : 1;
35
+ return { page, pageSize, pageCount, totalItems };
38
36
  }
39
37
  clamp(page) {
40
38
  if (!Number.isFinite(page))
@@ -59,9 +57,21 @@ export class PaginationController {
59
57
  cancelable: true,
60
58
  });
61
59
  }
62
- #emitChanged() {
63
- this.host.announce(this.host.localize('announce.page', { page: this.page + 1, total: this.pageCount }));
64
- return this.host.emitEvent('pageChanged', { detail: this.state });
60
+ async #apply(page, pageSize) {
61
+ this.page = page;
62
+ this.pageSize = pageSize;
63
+ const parked = this.host.stateController.navigation.parkFocus();
64
+ this.host.requestUpdate(this.host.pagination?.mode === 'remote' ? PIPELINE : undefined);
65
+ try {
66
+ await this.host.pipelineSettled();
67
+ }
68
+ finally {
69
+ if (parked)
70
+ void parked();
71
+ }
72
+ const detail = this.#stateFor(page, pageSize);
73
+ this.host.announce(this.host.localize('announce.page', { page: page + 1, total: detail.pageCount }));
74
+ this.host.emitEvent('pageChanged', { detail });
65
75
  }
66
76
  async gotoPage(page) {
67
77
  const next = this.clamp(page);
@@ -70,19 +80,12 @@ export class PaginationController {
70
80
  if (!this.#emitChanging(next, this.pageSize)) {
71
81
  return false;
72
82
  }
73
- this.page = next;
74
- this.host.requestUpdate(PIPELINE);
75
- await this.host.pipelineSettled();
76
- this.#emitChanged();
83
+ await this.#apply(next, this.pageSize);
77
84
  return true;
78
85
  }
79
86
  async resetPage() {
80
- if (this.page === 0)
81
- return;
82
- this.page = 0;
83
- this.host.requestUpdate(PIPELINE);
84
- await this.host.pipelineSettled();
85
- this.#emitChanged();
87
+ if (this.page !== 0)
88
+ await this.#apply(0, this.pageSize);
86
89
  }
87
90
  async setPageSize(size) {
88
91
  const next = Math.max(1, Math.trunc(size));
@@ -91,11 +94,7 @@ export class PaginationController {
91
94
  if (!this.#emitChanging(0, next)) {
92
95
  return false;
93
96
  }
94
- this.pageSize = next;
95
- this.page = 0;
96
- this.host.requestUpdate(PIPELINE);
97
- await this.host.pipelineSettled();
98
- this.#emitChanged();
97
+ await this.#apply(0, next);
99
98
  return true;
100
99
  }
101
100
  nextPage() {
@@ -1 +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;IAC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AI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAElC,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;QAClC,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(\n this.host.localize('announce.page', { page: this.page + 1, total: this.pageCount })\n );\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 // @ts-expect-error - protected member access\n await this.host.pipelineSettled();\n this.#emitChanged();\n return true;\n }\n\n /**\n * Moves to the first page as part of a change already confirmed (a new\n * quick filter), so without `pageChanging`; fires `pageChanged` once the\n * pipeline settled when the page actually moved.\n */\n public async resetPage(): Promise<void> {\n if (this.page === 0) return;\n this.page = 0;\n this.host.requestUpdate(PIPELINE);\n // @ts-expect-error - protected member access\n await this.host.pipelineSettled();\n this.#emitChanged();\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 // @ts-expect-error - protected member access\n await this.host.pipelineSettled();\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"]}
1
+ {"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src/controllers/pagination.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAMpD,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AE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAOM,KAAK,CAAC,SAAS;QACpB,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC;YAAE,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;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,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QAC3B,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. The page slice itself is read from\n * {@link ApexGrid.pageItems}, so the controller never mutates `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 number of rows paged through (see {@link ApexGrid.totalItems}).\n *\n * @remarks\n * For `'local'` mode this is the post-filter, post-sort row count; with pagination\n * enabled it leaves out the pinned rows, so it counts the rows {@link ApexGrid.pageItems}\n * slices. For `'remote'` mode the consumer supplies 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.enabled ? this.host.bodyRows : 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 return this.state.pageCount;\n }\n\n /**\n * Returns the resolved {@link PaginationState} for the current host.\n */\n public get state(): PaginationState {\n return this.#stateFor(this.page, this.pageSize);\n }\n\n /** The state for `page` and `pageSize` over the rows the grid holds now. */\n #stateFor(page: number, pageSize: number): PaginationState {\n const totalItems = this.totalItems;\n const pageCount = pageSize ? Math.max(1, Math.ceil(totalItems / pageSize)) : 1;\n return { page, pageSize, pageCount, totalItems };\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 /**\n * Applies `page` and `pageSize`, then fires `pageChanged` for that change\n * once it rendered. The detail is this change, not whatever page a later\n * call moved to meanwhile, so two unawaited calls report two pages. In\n * local mode the body slice is read from {@link ApexGrid.pageItems} on\n * render, so the data pipeline does not rerun; in remote mode it does, so\n * a pipeline hook that fetches the page by `grid.page` sees the new page.\n */\n async #apply(page: number, pageSize: number): Promise<void> {\n this.page = page;\n this.pageSize = pageSize;\n // Row recycling re-binds the focused row to the new page's record, so\n // focus moves to the body rather than stay on the same slot.\n // @ts-expect-error - protected member access\n const parked = this.host.stateController.navigation.parkFocus() as (() => Promise<void>) | null;\n this.host.requestUpdate(this.host.pagination?.mode === 'remote' ? PIPELINE : undefined);\n try {\n // @ts-expect-error - protected member access\n await this.host.pipelineSettled();\n } finally {\n if (parked) void parked();\n }\n const detail = this.#stateFor(page, pageSize);\n this.host.announce(\n this.host.localize('announce.page', { page: page + 1, total: detail.pageCount })\n );\n this.host.emitEvent('pageChanged', { detail });\n }\n\n /**\n * Navigates to `page`, emitting the cancellable `pageChanging` event first and\n * the `pageChanged` event after the change rendered.\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 await this.#apply(next, this.pageSize);\n return true;\n }\n\n /**\n * Moves to the first page as part of a change already confirmed (a new\n * quick filter), so without `pageChanging`; fires `pageChanged` once the\n * pipeline settled when the page actually moved.\n */\n public async resetPage(): Promise<void> {\n if (this.page !== 0) await this.#apply(0, this.pageSize);\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 await this.#apply(0, next);\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"]}
@@ -28,6 +28,12 @@ export declare class RowPinController<T extends object> implements ReactiveContr
28
28
  hostConnected(): void;
29
29
  /** Whether row pinning is enabled at the grid level. */
30
30
  get enabled(): boolean;
31
+ /**
32
+ * Bumped whenever either band's contents change, so a view derived from the
33
+ * pins (the body's {@link ApexGrid.pageItems}) knows when to recompute.
34
+ * Read only.
35
+ */
36
+ version: number;
31
37
  /** Whether any row is currently pinned (none while pinning is disabled). */
32
38
  get hasPinnedRows(): boolean;
33
39
  /** The band `row` is pinned to, or `null` when it is not pinned. */
@@ -1,8 +1,11 @@
1
1
  export class RowPinController {
2
- #top = new Set();
3
- #bottom = new Set();
2
+ #top;
3
+ #bottom;
4
4
  constructor(host) {
5
5
  this.host = host;
6
+ this.#top = new Set();
7
+ this.#bottom = new Set();
8
+ this.version = 0;
6
9
  this.host.addController(this);
7
10
  }
8
11
  hostConnected() { }
@@ -55,11 +58,13 @@ export class RowPinController {
55
58
  return;
56
59
  this.#top.clear();
57
60
  this.#bottom.clear();
61
+ this.version++;
58
62
  this.host.requestUpdate();
59
63
  }
60
64
  restore(top, bottom) {
61
65
  this.#top = new Set(top);
62
66
  this.#bottom = new Set(bottom);
67
+ this.version++;
63
68
  this.host.requestUpdate();
64
69
  }
65
70
  resetForDataChange(carry) {
@@ -74,6 +79,7 @@ export class RowPinController {
74
79
  });
75
80
  }
76
81
  #commit(row, position, message) {
82
+ this.version++;
77
83
  this.host.requestUpdate();
78
84
  this.host.announce(message);
79
85
  this.host.emitEvent('rowPinned', { detail: { row, position } });
@@ -1 +1 @@
1
- {"version":3,"file":"row-pin.js","sourceRoot":"","sources":["../../src/controllers/row-pin.ts"],"names":[],"mappings":"AAyBA,MAAM,OAAO,gBAAgB;IAC3B,IAAI,GAAW,IAAI,GAAG,EAAE,CAAC;IACzB,OAAO,GAAW,IAAI,GAAG,EAAE,CAAC;IAE5B,YAAsB,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;QACrC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAEM,aAAa,KAAI,CAAC;IAGzB,IAAW,OAAO;QAChB,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAGD,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IACvE,CAAC;IAGM,cAAc,CAAC,GAAM;QAC1B,OAAO,IAAI,CAAC,OAAO,CAA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,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC;IAMM,kBAAkB,CAAC,KAAyB;QACjD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACxC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAED,YAAY,CAAC,GAAM,EAAE,QAA+B;QAClD,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE;YACvC,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE;YACzB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,GAAM,EAAE,QAA+B,EAAE,OAAe;QAC9D,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;IAClE,CAAC;CACF","sourcesContent":["import type { ReactiveController } from 'lit';\nimport type { GridHost } from '../internal/types.js';\n\n/** Where a row is pinned, or `null` when it scrolls with the body. */\nexport type RowPinPosition = 'top' | 'bottom';\n\n/**\n * Reactive controller backing row pinning.\n *\n * @remarks\n * Pinned rows are lifted out of the scrollable body and rendered in sticky\n * bands above (`'top'`) or below (`'bottom'`) the virtualized rows. State is\n * reference-based: the controller holds a `Set` of row data references per band,\n * so pins survive sort / filter / pagination as long as those preserve row\n * identity (the default in-place pipeline does). Replacing {@link ApexGrid.data}\n * carries the pins onto the new array: by `rowId` when set, else a pin whose\n * row left the data is dropped.\n *\n * While `rowPinning.enabled` is false every query reports no pins and the\n * rows stay in the body; the pins are kept (and `getState` still saves them),\n * and re-enabling brings them back.\n *\n * Mutations go through the cancellable `rowPinning` event and emit a follow-up\n * `rowPinned` event, mirroring selection / expansion.\n */\nexport class RowPinController<T extends object> implements ReactiveController {\n #top: Set<T> = new Set();\n #bottom: Set<T> = new Set();\n\n constructor(protected host: GridHost<T>) {\n this.host.addController(this);\n }\n\n public hostConnected() {}\n\n /** Whether row pinning is enabled at the grid level. */\n public get enabled(): boolean {\n return Boolean(this.host.rowPinning?.enabled);\n }\n\n /** Whether any row is currently pinned (none while pinning is disabled). */\n public get hasPinnedRows(): boolean {\n return this.enabled && (this.#top.size > 0 || this.#bottom.size > 0);\n }\n\n /** The band `row` is pinned to, or `null` when it is not pinned. */\n public pinnedPosition(row: T): RowPinPosition | null {\n return this.enabled ? this.#band(row) : null;\n }\n\n /** Whether `row` is pinned to either band. */\n public isPinned(row: T): boolean {\n return this.pinnedPosition(row) !== null;\n }\n\n /** Pinned rows per band, in the order they were pinned. */\n public get pinnedRows(): { top: T[]; bottom: T[] } {\n return this.enabled ? this.pins : { top: [], bottom: [] };\n }\n\n /**\n * Every pin per band, kept while pinning is disabled too, so a `getState`\n * snapshot taken then still carries them.\n */\n public get pins(): { top: T[]; bottom: T[] } {\n return { top: [...this.#top], bottom: [...this.#bottom] };\n }\n\n /** The band holding `row`, whether or not pinning is enabled. */\n #band(row: T): RowPinPosition | null {\n return this.#top.has(row) ? 'top' : this.#bottom.has(row) ? 'bottom' : null;\n }\n\n /**\n * Pins `row` to the given band. Moves it between bands when already pinned\n * elsewhere. No-op (returns `true`) when it is already pinned there.\n *\n * @returns `true` when applied, `false` when disabled or cancelled.\n */\n public pinRow(row: T, position: RowPinPosition): boolean {\n if (!this.enabled) return false;\n if (this.pinnedPosition(row) === position) return true;\n if (!this.#emitPinning(row, position)) return false;\n\n this.#top.delete(row);\n this.#bottom.delete(row);\n (position === 'top' ? this.#top : this.#bottom).add(row);\n this.#commit(\n row,\n position,\n this.host.localize(position === 'top' ? 'announce.rowPinnedTop' : 'announce.rowPinnedBottom')\n );\n return true;\n }\n\n /**\n * Unpins `row` from whichever band holds it. No-op (returns `true`) when it is\n * not pinned.\n *\n * @returns `true` when applied, `false` when cancelled.\n */\n public unpinRow(row: T): boolean {\n if (!this.#band(row)) return true;\n if (!this.#emitPinning(row, null)) return false;\n\n this.#top.delete(row);\n this.#bottom.delete(row);\n this.#commit(row, null, this.host.localize('announce.rowUnpinned'));\n return true;\n }\n\n /** Clears every pin in both bands. */\n public clear(): void {\n if (!this.#top.size && !this.#bottom.size) return;\n this.#top.clear();\n this.#bottom.clear();\n this.host.requestUpdate();\n }\n\n /**\n * Restores pinned rows from explicit per-band reference lists (state restore),\n * replacing any current pins. Silent: emits no `rowPinning` / `rowPinned` and\n * preserves the given order within each band.\n */\n public restore(top: ReadonlyArray<T>, bottom: ReadonlyArray<T>): void {\n this.#top = new Set(top);\n this.#bottom = new Set(bottom);\n this.host.requestUpdate();\n }\n\n /**\n * Carries the pins onto a new `data` array through `carry` (by `rowId` when\n * set, else the rows still present), so the bands never show a stale object.\n */\n public resetForDataChange(carry: (rows: T[]) => T[]): void {\n if (this.#top.size || this.#bottom.size) {\n this.restore(carry([...this.#top]), carry([...this.#bottom]));\n }\n }\n\n #emitPinning(row: T, position: RowPinPosition | null): boolean {\n return this.host.emitEvent('rowPinning', {\n detail: { row, position },\n cancelable: true,\n });\n }\n\n #commit(row: T, position: RowPinPosition | null, message: string): void {\n this.host.requestUpdate();\n this.host.announce(message);\n this.host.emitEvent('rowPinned', { detail: { row, position } });\n }\n}\n"]}
1
+ {"version":3,"file":"row-pin.js","sourceRoot":"","sources":["../../src/controllers/row-pin.ts"],"names":[],"mappings":"AAyBA,MAAM,OAAO,gBAAgB;IAC3B,IAAI,CAAqB;IACzB,OAAO,CAAqB;IAE5B,YAAsB,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;QAHvC,SAAI,GAAW,IAAI,G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IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;IAClE,CAAC;CACF","sourcesContent":["import type { ReactiveController } from 'lit';\nimport type { GridHost } from '../internal/types.js';\n\n/** Where a row is pinned, or `null` when it scrolls with the body. */\nexport type RowPinPosition = 'top' | 'bottom';\n\n/**\n * Reactive controller backing row pinning.\n *\n * @remarks\n * Pinned rows are lifted out of the scrollable body and rendered in sticky\n * bands above (`'top'`) or below (`'bottom'`) the virtualized rows. State is\n * reference-based: the controller holds a `Set` of row data references per band,\n * so pins survive sort / filter / pagination as long as those preserve row\n * identity (the default in-place pipeline does). Replacing {@link ApexGrid.data}\n * carries the pins onto the new array: by `rowId` when set, else a pin whose\n * row left the data is dropped.\n *\n * While `rowPinning.enabled` is false every query reports no pins and the\n * rows stay in the body; the pins are kept (and `getState` still saves them),\n * and re-enabling brings them back.\n *\n * Mutations go through the cancellable `rowPinning` event and emit a follow-up\n * `rowPinned` event, mirroring selection / expansion.\n */\nexport class RowPinController<T extends object> implements ReactiveController {\n #top: Set<T> = new Set();\n #bottom: Set<T> = new Set();\n\n constructor(protected host: GridHost<T>) {\n this.host.addController(this);\n }\n\n public hostConnected() {}\n\n /** Whether row pinning is enabled at the grid level. */\n public get enabled(): boolean {\n return Boolean(this.host.rowPinning?.enabled);\n }\n\n /**\n * Bumped whenever either band's contents change, so a view derived from the\n * pins (the body's {@link ApexGrid.pageItems}) knows when to recompute.\n * Read only.\n */\n public version = 0;\n\n /** Whether any row is currently pinned (none while pinning is disabled). */\n public get hasPinnedRows(): boolean {\n return this.enabled && (this.#top.size > 0 || this.#bottom.size > 0);\n }\n\n /** The band `row` is pinned to, or `null` when it is not pinned. */\n public pinnedPosition(row: T): RowPinPosition | null {\n return this.enabled ? this.#band(row) : null;\n }\n\n /** Whether `row` is pinned to either band. */\n public isPinned(row: T): boolean {\n return this.pinnedPosition(row) !== null;\n }\n\n /** Pinned rows per band, in the order they were pinned. */\n public get pinnedRows(): { top: T[]; bottom: T[] } {\n return this.enabled ? this.pins : { top: [], bottom: [] };\n }\n\n /**\n * Every pin per band, kept while pinning is disabled too, so a `getState`\n * snapshot taken then still carries them.\n */\n public get pins(): { top: T[]; bottom: T[] } {\n return { top: [...this.#top], bottom: [...this.#bottom] };\n }\n\n /** The band holding `row`, whether or not pinning is enabled. */\n #band(row: T): RowPinPosition | null {\n return this.#top.has(row) ? 'top' : this.#bottom.has(row) ? 'bottom' : null;\n }\n\n /**\n * Pins `row` to the given band. Moves it between bands when already pinned\n * elsewhere. No-op (returns `true`) when it is already pinned there.\n *\n * @returns `true` when applied, `false` when disabled or cancelled.\n */\n public pinRow(row: T, position: RowPinPosition): boolean {\n if (!this.enabled) return false;\n if (this.pinnedPosition(row) === position) return true;\n if (!this.#emitPinning(row, position)) return false;\n\n this.#top.delete(row);\n this.#bottom.delete(row);\n (position === 'top' ? this.#top : this.#bottom).add(row);\n this.#commit(\n row,\n position,\n this.host.localize(position === 'top' ? 'announce.rowPinnedTop' : 'announce.rowPinnedBottom')\n );\n return true;\n }\n\n /**\n * Unpins `row` from whichever band holds it. No-op (returns `true`) when it is\n * not pinned.\n *\n * @returns `true` when applied, `false` when cancelled.\n */\n public unpinRow(row: T): boolean {\n if (!this.#band(row)) return true;\n if (!this.#emitPinning(row, null)) return false;\n\n this.#top.delete(row);\n this.#bottom.delete(row);\n this.#commit(row, null, this.host.localize('announce.rowUnpinned'));\n return true;\n }\n\n /** Clears every pin in both bands. */\n public clear(): void {\n if (!this.#top.size && !this.#bottom.size) return;\n this.#top.clear();\n this.#bottom.clear();\n this.version++;\n this.host.requestUpdate();\n }\n\n /**\n * Restores pinned rows from explicit per-band reference lists (state restore),\n * replacing any current pins. Silent: emits no `rowPinning` / `rowPinned` and\n * preserves the given order within each band.\n */\n public restore(top: ReadonlyArray<T>, bottom: ReadonlyArray<T>): void {\n this.#top = new Set(top);\n this.#bottom = new Set(bottom);\n this.version++;\n this.host.requestUpdate();\n }\n\n /**\n * Carries the pins onto a new `data` array through `carry` (by `rowId` when\n * set, else the rows still present), so the bands never show a stale object.\n */\n public resetForDataChange(carry: (rows: T[]) => T[]): void {\n if (this.#top.size || this.#bottom.size) {\n this.restore(carry([...this.#top]), carry([...this.#bottom]));\n }\n }\n\n #emitPinning(row: T, position: RowPinPosition | null): boolean {\n return this.host.emitEvent('rowPinning', {\n detail: { row, position },\n cancelable: true,\n });\n }\n\n #commit(row: T, position: RowPinPosition | null, message: string): void {\n this.version++;\n this.host.requestUpdate();\n this.host.announce(message);\n this.host.emitEvent('rowPinned', { detail: { row, position } });\n }\n}\n"]}
@@ -21,6 +21,12 @@ export interface RowGhostInit {
21
21
  /** Per-cell snapshot of the row's visible content. */
22
22
  cells: RowGhostCell[];
23
23
  }
24
+ /**
25
+ * Snapshots a row element for the floating ghost: its bounding rect and each
26
+ * cell's rendered text, width and alignment. A cell renders into its own
27
+ * shadow root, so the text is read from there.
28
+ */
29
+ export declare function captureRowGhost(row: Element, cells: ReadonlyArray<Element>, clientX: number, clientY: number): RowGhostInit;
24
30
  /**
25
31
  * Live state for the floating "ghost" row that trails the cursor during a
26
32
  * pointer drag. Mirrors {@link ReorderController}'s column ghost: the source
@@ -157,11 +163,13 @@ export declare class RowReorderController<T extends object> implements ReactiveC
157
163
  * listener is bound to the **grid host**, so the gesture is immune to the
158
164
  * source row's DOM being recycled by a live-swap; the up / cancel listeners
159
165
  * are bound to the document, so a release outside the grid ends it too, as
160
- * does a move with the primary button no longer held. `getGhost` is a thunk
161
- * the controller invokes once, the instant the drag engages, to snapshot the
162
- * row's cells (the row is still in place then).
166
+ * does a move with the primary button no longer held. The ghost is
167
+ * snapshotted once, the instant the drag engages, from the row element that
168
+ * renders `data` then; `getGhost` is the pressed row's own snapshot, used
169
+ * when no rendered row shows `data`, and returns `null` once that row shows
170
+ * another record.
163
171
  */
164
- armPointerDrag(data: T, getGhost: () => RowGhostInit, event: PointerEvent): void;
172
+ armPointerDrag(data: T, getGhost: () => RowGhostInit | null, event: PointerEvent): void;
165
173
  /** Grabs the row at view index `rowIndex` for keyboard reorder. */
166
174
  grab(rowIndex: number): boolean;
167
175
  /**
@@ -1,7 +1,16 @@
1
1
  import { PIPELINE } from '../internal/constants.js';
2
- import { awaitChildUpdates, playKeyedFlip } from '../internal/flip.js';
2
+ import { playKeyedFlip, settleRowsForFlip } from '../internal/flip.js';
3
3
  import SortDataOperation from '../operations/sort.js';
4
4
  const DRAG_THRESHOLD_PX = 4;
5
+ export function captureRowGhost(row, cells, clientX, clientY) {
6
+ const rect = row.getBoundingClientRect();
7
+ const snapshot = cells.map((cell) => ({
8
+ text: ((cell.shadowRoot ?? cell).textContent ?? '').replace(/\s+/g, ' ').trim(),
9
+ width: cell.getBoundingClientRect().width,
10
+ align: getComputedStyle(cell).textAlign,
11
+ }));
12
+ return { rect, clientX, clientY, cells: snapshot };
13
+ }
5
14
  export class RowReorderController {
6
15
  #order;
7
16
  #preGrab;
@@ -34,7 +43,7 @@ export class RowReorderController {
34
43
  }
35
44
  catch {
36
45
  }
37
- this.startDrag(pending.data, pending.getGhost());
46
+ this.startDrag(pending.data, this.#ghostAtEngage(pending) ?? undefined);
38
47
  }
39
48
  this.moveGhost(event.clientX, event.clientY);
40
49
  this.dragOver(event.clientY);
@@ -210,6 +219,13 @@ export class RowReorderController {
210
219
  host.ownerDocument.addEventListener('pointercancel', this.#onPointerUp, true);
211
220
  }
212
221
  #onHostPointerMove;
222
+ #ghostAtEngage(pending) {
223
+ const row = this.host.rows.find((candidate) => candidate.data === pending.data);
224
+ if (!row)
225
+ return pending.getGhost();
226
+ const cells = row.cells;
227
+ return captureRowGhost(row, cells, pending.startX, pending.startY);
228
+ }
213
229
  #onPointerUp;
214
230
  #endPointer() {
215
231
  const pending = this.#pending;
@@ -236,8 +252,7 @@ export class RowReorderController {
236
252
  try {
237
253
  const before = this.#captureRowRects();
238
254
  if (this.#commit(this.dragging, target, position)) {
239
- await this.host.updateComplete;
240
- await awaitChildUpdates(this.host.rows);
255
+ await settleRowsForFlip(this.host);
241
256
  this.#playRowFlip(before);
242
257
  }
243
258
  }
@@ -397,8 +412,7 @@ export class RowReorderController {
397
412
  return entries;
398
413
  }
399
414
  async #flipAfterUpdate(before) {
400
- await this.host.updateComplete;
401
- await awaitChildUpdates(this.host.rows);
415
+ await settleRowsForFlip(this.host);
402
416
  this.#playRowFlip(before);
403
417
  }
404
418
  #playRowFlip(before) {
@@ -1 +1 @@
1
- {"version":3,"file":"row-reorder.js","sourceRoot":"","sources":["../../src/controllers/row-reorder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAuB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAG5F,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AAMtD,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAkE5B,MAAM,OAAO,oBAAoB;IAE/B,MAAM,CAAoB;IAO1B,QAAQ,CAKQ;IAgBhB,SAAS,CAAS;IAOlB,QAAQ,CAMQ;IAEhB,YAAsB,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;QA3CvC,WAAM,GAAe,IAAI,CAAC;QAO1B,aAAQ,GAKG,IAAI,CAAC;QAGT,aAAQ,GAAa,IAAI,CAAC;QAO1B,UAAK,GAAyB,IAAI,CAAC;QAGnC,YAAO,GAAa,IAAI,CAAC;QAGhC,cAAS,GAAG,KAAK,CAAC;QAOlB,aAAQ,GAMG,IAAI,CAAC;QAkPhB,uBAAkB,GAAG,CAAC,KAAmB,EAAQ,EAAE;YACjD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;YAC9B,IAAI,CAAC,OAAO,IAAI,KAAK,C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IAAI,CAAC,MAAM;gBAAE,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC;QACvF,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gBAAgB;QACd,MAAM,OAAO,GAAwB,EAAE,CAAC;QACxC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACjC,MAAM,EAAE,GAAG,GAA6B,CAAC;YACzC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,MAAwC;QAC7D,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;QAC/B,MAAM,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,YAAY,CAAC,MAAwC;QACnD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;QACzC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACjC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAA6B,CAAC,CAAC;QACtD,CAAC;QACD,aAAa,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;IACjE,CAAC;CACF","sourcesContent":["import type { ReactiveController } from 'lit';\nimport { PIPELINE } from '../internal/constants.js';\nimport { awaitChildUpdates, type KeyedFlipEntry, playKeyedFlip } from '../internal/flip.js';\nimport type { GridHost } from '../internal/types.js';\nimport type { SortExpression } from '../operations/sort/types.js';\nimport SortDataOperation from '../operations/sort.js';\n\n/** Where a moved row lands relative to its target. */\nexport type RowDropPosition = 'before' | 'after';\n\n/** Pixels the pointer must travel before a row drag engages. */\nconst DRAG_THRESHOLD_PX = 4;\n\n/** A single cell snapshot used to paint the floating row ghost. */\nexport interface RowGhostCell {\n /** The cell's rendered text at grab time. */\n text: string;\n /** The cell's rendered width (px), so the ghost matches the column layout. */\n width: number;\n /** The cell's computed `text-align`, so numbers stay right-aligned in the ghost. */\n align: string;\n}\n\n/** Everything the row hands the controller to seed the floating ghost. */\nexport interface RowGhostInit {\n /** The source row's bounding rect at grab time. */\n rect: DOMRect;\n /** Pointer position at grab time (to keep the grab point under the cursor). */\n clientX: number;\n clientY: number;\n /** Per-cell snapshot of the row's visible content. */\n cells: RowGhostCell[];\n}\n\n/**\n * Live state for the floating \"ghost\" row that trails the cursor during a\n * pointer drag. Mirrors {@link ReorderController}'s column ghost: the source\n * row stays in the grid (and live-swaps), the ghost is a purely visual proxy.\n */\nexport interface RowGhostState {\n /** Ghost position (viewport-relative top-left, in CSS pixels). */\n x: number;\n y: number;\n /** Ghost size, fixed at the source row's initial bounding rect. */\n width: number;\n height: number;\n /** Cursor offset within the ghost so the grab point stays under the cursor. */\n pointerOffsetX: number;\n pointerOffsetY: number;\n /** Snapshot of the row's visible cells. */\n cells: ReadonlyArray<RowGhostCell>;\n}\n\n/**\n * Reactive controller backing row drag-reorder and a manual row order.\n *\n * @remarks\n * Row order is normally derived (filter → sort). This controller adds a\n * **manual order**: an explicit sequence of row references applied as a\n * pipeline step after sort. A manual order and a sort are mutually exclusive:\n * applying a sort clears the manual order, and a move clears the sort. The\n * order spans every row, hidden by a filter or not, so a move made under a\n * filter leaves the hidden rows in place. State is reference-based, so it\n * survives the in-place pipeline, and it is carried onto a new `data` array\n * (by `rowId` when set, else by identity).\n *\n * Reordering happens through {@link moveRow} (pointer live-swap during a drag,\n * the keyboard grab/move flow, or the public API). Each move goes through the\n * cancellable `rowMoving` event and emits a follow-up `rowMoved`, then animates\n * with a Y-axis FLIP. Pinned rows (F4) are never the drag source and reorder\n * only within the unpinned body set.\n *\n * Persistence: by default the order lives in this controller and the app\n * persists via `rowMoved`. With `rowReordering.applyToData` the move also\n * splices {@link ApexGrid.data} in place (and clears the manual order, since the\n * data array then carries the order).\n */\nexport class RowReorderController<T extends object> implements ReactiveController {\n /** Manual order of row references, or `null` for the natural (sorted) order. */\n #order: T[] | null = null;\n\n /**\n * What a keyboard grab may change, captured when it starts, for\n * Escape-to-cancel: the manual order, the data order (with `applyToData`),\n * the sort and the grabbed row's view index.\n */\n #preGrab: {\n order: T[] | null;\n data: T[] | null;\n sort: SortExpression<T>[];\n index: number;\n } | null = null;\n\n /** The row currently being pointer-dragged, or `null`. */\n public dragging: T | null = null;\n\n /**\n * Live floating-ghost state during a pointer drag, or `null`. Surfaced to the\n * grid, which renders the ghost at the top of its shadow tree (outside the\n * virtualizer) so `position: fixed` tracks the viewport cleanly.\n */\n public ghost: RowGhostState | null = null;\n\n /** The row currently grabbed for keyboard reorder, or `null`. */\n public grabbed: T | null = null;\n\n /** Re-entrancy guard so a slow swap can't trigger a second mid-drag. */\n #swapping = false;\n\n /**\n * In-flight pointer-drag gesture. The move/up listeners live on the **grid\n * host** (a stable element), not the row, so a live-swap that recycles the\n * source row's DOM can't tear the drag down mid-gesture.\n */\n #pending: {\n data: T;\n getGhost: () => RowGhostInit;\n startX: number;\n startY: number;\n pointerId: number;\n } | null = null;\n\n constructor(protected host: GridHost<T>) {\n this.host.addController(this);\n }\n\n /** The grid host as a DOM event target (it is always an `HTMLElement`). */\n get #hostElement(): HTMLElement {\n return this.host as unknown as HTMLElement;\n }\n\n public hostConnected() {}\n\n /** A grid detached mid-drag ends the gesture, so no frozen ghost stays behind. */\n public hostDisconnected() {\n this.#endPointer();\n }\n\n /** Whether row reordering is enabled at the grid level. */\n public get enabled(): boolean {\n return Boolean(this.host.rowReordering?.enabled);\n }\n\n /**\n * Whether a pointer drag must start from the dedicated grip handle (the\n * default), rather than from anywhere on the row. Driven by\n * `rowReordering.handle` (defaults to `true`).\n */\n public get handleMode(): boolean {\n return this.enabled && this.host.rowReordering?.handle !== false;\n }\n\n /**\n * Whether the leading grip-handle column is rendered. Only in handle mode, and\n * only while reordering is enabled.\n */\n public get showHandleColumn(): boolean {\n return this.handleMode;\n }\n\n /** Whether moves also splice {@link ApexGrid.data} in place. */\n public get applyToData(): boolean {\n return Boolean(this.host.rowReordering?.applyToData);\n }\n\n /** Whether a manual order is currently active. */\n public get hasManualOrder(): boolean {\n return this.#order !== null;\n }\n\n /** Whether a row is currently grabbed for keyboard reorder. */\n public get isGrabbing(): boolean {\n return this.grabbed !== null;\n }\n\n /**\n * Pipeline step: reorders the (post-filter, post-sort) rows by the manual\n * order. Rows absent from the manual order (e.g. newly added) keep their\n * incoming relative order at the end. Identity pass-through when inactive.\n */\n public apply(rows: T[]): T[] {\n if (!this.#order) return rows;\n const rank = new Map<T, number>();\n this.#order.forEach((row, i) => {\n rank.set(row, i);\n });\n return [...rows].sort((a, b) => {\n const ra = rank.has(a) ? (rank.get(a) as number) : Number.POSITIVE_INFINITY;\n const rb = rank.has(b) ? (rank.get(b) as number) : Number.POSITIVE_INFINITY;\n return ra - rb;\n });\n }\n\n /**\n * The current manual order as a copy of its row references, or `null` for the\n * derived order. Consumed by `ApexGrid.getState`.\n */\n public getManualOrder(): T[] | null {\n return this.#order ? [...this.#order] : null;\n }\n\n /**\n * Restores a manual order from a list of row references (state restore). Pass\n * `null` (or an empty list) to clear it. Silent: emits no `rowMoving` /\n * `rowMoved` and does not animate; re-runs the pipeline.\n */\n public restoreManualOrder(order: T[] | null): void {\n this.#order = order?.length ? [...order] : null;\n this.host.requestUpdate(PIPELINE);\n }\n\n /**\n * Clears the manual order (e.g. when a sort is applied). Re-runs the pipeline.\n */\n public clearManualOrder(announce = false): void {\n if (!this.#order) return;\n this.#order = null;\n this.host.requestUpdate(PIPELINE);\n if (announce) this.host.announce(this.host.localize('announce.manualOrderCleared'));\n }\n\n /**\n * Carries the manual order onto a new `data` array through `carry` (by\n * `rowId` when set, else the rows still present), clearing it when no row\n * survives. A grab or drag follows its row onto the new data, so an app\n * that re-sets `data` on `rowMoved` keeps the gesture; it ends only when\n * the row is gone.\n */\n public resetForDataChange(carry: (rows: T[]) => T[]): void {\n const pre = this.#preGrab;\n if (this.grabbed) {\n this.grabbed = carry([this.grabbed])[0] ?? null;\n if (!this.grabbed) this.#preGrab = null;\n else if (pre) {\n pre.order = pre.order && carry(pre.order);\n pre.data = pre.data && carry(pre.data);\n }\n }\n const pending = this.#pending;\n const held = pending?.data ?? this.dragging;\n if (held) {\n const row = carry([held])[0];\n if (!row) this.#endPointer();\n else {\n if (pending) pending.data = row;\n if (this.dragging) this.dragging = row;\n }\n }\n if (this.#order) this.restoreManualOrder(carry(this.#order));\n }\n\n /**\n * Moves the row at view index `from` relative to the row at view index `to`.\n * Indices are into {@link ApexGrid.pageItems}.\n *\n * @returns `true` when applied, `false` when disabled, out of range, a\n * no-op (the row would land where it is), or cancelled via `rowMoving`.\n */\n public moveRow(from: number, to: number, position: RowDropPosition = 'before'): boolean {\n const view = this.host.pageItems;\n const before = this.#captureRowRects();\n const ok = this.#commit(view[from] as T, view[to] as T, position);\n if (ok) void this.#flipAfterUpdate(before);\n return ok;\n }\n\n // --- pointer drag -------------------------------------------------------\n\n /**\n * Begins a pointer drag from `source`. When `ghost` is supplied (the pointer\n * path always does), seeds the floating ghost from the source row's rect and\n * the grab point so it stays anchored under the cursor.\n */\n public startDrag(source: T, ghost?: RowGhostInit): void {\n if (!this.enabled) return;\n this.dragging = source;\n this.ghost = ghost\n ? {\n x: ghost.rect.left,\n y: ghost.rect.top,\n width: ghost.rect.width,\n height: ghost.rect.height,\n pointerOffsetX: ghost.clientX - ghost.rect.left,\n pointerOffsetY: ghost.clientY - ghost.rect.top,\n cells: ghost.cells,\n }\n : null;\n this.host.requestUpdate();\n }\n\n /** Moves the floating ghost to track the cursor. No-op without an active ghost. */\n public moveGhost(clientX: number, clientY: number): void {\n if (!this.ghost) return;\n this.ghost = {\n ...this.ghost,\n x: clientX - this.ghost.pointerOffsetX,\n y: clientY - this.ghost.pointerOffsetY,\n };\n this.host.requestUpdate();\n }\n\n /**\n * Called on pointer-move during a drag: live-swaps the dragged row past the\n * body row currently under `clientY` once the cursor crosses its midpoint.\n */\n public dragOver(clientY: number): void {\n if (!this.dragging || this.#swapping) return;\n const target = this.#bodyRowAt(clientY);\n if (!target || target.data === this.dragging) return;\n\n const view = this.host.pageItems;\n const sourceIdx = view.indexOf(this.dragging);\n const targetIdx = view.indexOf(target.data);\n if (sourceIdx === -1 || targetIdx === -1) return;\n\n const rect = target.element.getBoundingClientRect();\n const midpoint = rect.top + rect.height / 2;\n let position: RowDropPosition;\n if (sourceIdx < targetIdx) {\n if (clientY < midpoint) return; // dragging down — wait for the midpoint\n position = 'after';\n } else {\n if (clientY > midpoint) return; // dragging up\n position = 'before';\n }\n void this.#dragSwap(target.data, position);\n }\n\n /** Ends the pointer drag. The order is already final (live-swapped). */\n public endDrag(): void {\n if (!this.dragging) return;\n this.dragging = null;\n this.ghost = null;\n this.host.requestUpdate();\n }\n\n /**\n * Arms a pointer drag from a row press. Called by the row on `pointerdown`\n * (from the grip in handle mode, or anywhere in whole-row mode). The move\n * listener is bound to the **grid host**, so the gesture is immune to the\n * source row's DOM being recycled by a live-swap; the up / cancel listeners\n * are bound to the document, so a release outside the grid ends it too, as\n * does a move with the primary button no longer held. `getGhost` is a thunk\n * the controller invokes once, the instant the drag engages, to snapshot the\n * row's cells (the row is still in place then).\n */\n public armPointerDrag(data: T, getGhost: () => RowGhostInit, event: PointerEvent): void {\n const pinned = this.host.pinnedRows;\n if (!this.enabled || pinned.top.includes(data) || pinned.bottom.includes(data)) return;\n this.#pending = {\n data,\n getGhost,\n startX: event.clientX,\n startY: event.clientY,\n pointerId: event.pointerId,\n };\n const host = this.#hostElement;\n host.addEventListener('pointermove', this.#onHostPointerMove);\n host.ownerDocument.addEventListener('pointerup', this.#onPointerUp, true);\n host.ownerDocument.addEventListener('pointercancel', this.#onPointerUp, true);\n }\n\n #onHostPointerMove = (event: PointerEvent): void => {\n const pending = this.#pending;\n if (!pending || event.pointerId !== pending.pointerId) return;\n // The release was missed (e.g. outside the window): a hover is not a drag.\n if (!(event.buttons & 1)) {\n this.#endPointer();\n return;\n }\n if (!this.dragging) {\n const dx = event.clientX - pending.startX;\n const dy = event.clientY - pending.startY;\n if (Math.hypot(dx, dy) < DRAG_THRESHOLD_PX) return;\n // Capture on the stable host so moves keep arriving even when the cursor\n // leaves the grid, and so the source row reflowing can't drop the pointer.\n try {\n this.#hostElement.setPointerCapture(pending.pointerId);\n } catch {\n /* a synthetic pointer id may not be capturable; hit-testing still works */\n }\n this.startDrag(pending.data, pending.getGhost());\n }\n this.moveGhost(event.clientX, event.clientY);\n this.dragOver(event.clientY);\n };\n\n #onPointerUp = (event: PointerEvent): void => {\n if (event.pointerId === this.#pending?.pointerId) this.#endPointer();\n };\n\n /** Tears down an armed or engaged pointer gesture. */\n #endPointer(): void {\n const pending = this.#pending;\n if (pending) {\n const host = this.#hostElement;\n host.removeEventListener('pointermove', this.#onHostPointerMove);\n host.ownerDocument.removeEventListener('pointerup', this.#onPointerUp, true);\n host.ownerDocument.removeEventListener('pointercancel', this.#onPointerUp, true);\n try {\n if (host.hasPointerCapture(pending.pointerId)) {\n host.releasePointerCapture(pending.pointerId);\n }\n } catch {\n /* capture was never taken or already released */\n }\n this.#pending = null;\n }\n this.endDrag();\n }\n\n async #dragSwap(target: T, position: RowDropPosition): Promise<void> {\n if (this.#swapping) return;\n this.#swapping = true;\n try {\n const before = this.#captureRowRects();\n if (this.#commit(this.dragging as T, target, position)) {\n await this.host.updateComplete;\n await awaitChildUpdates(this.host.rows);\n this.#playRowFlip(before);\n }\n } finally {\n this.#swapping = false;\n }\n }\n\n // --- keyboard grab ------------------------------------------------------\n\n /** Grabs the row at view index `rowIndex` for keyboard reorder. */\n public grab(rowIndex: number): boolean {\n if (!this.enabled) return false;\n const row = this.host.pageItems[rowIndex] as T | undefined;\n if (!row) return false;\n this.grabbed = row;\n this.#preGrab = {\n order: this.#order,\n data: this.applyToData ? [...this.host.data] : null,\n sort: this.host.sortExpressions,\n index: rowIndex,\n };\n this.host.requestUpdate();\n this.host.announce(this.host.localize('announce.rowGrabbed'));\n return true;\n }\n\n /**\n * Moves the grabbed row one position in `direction`. Returns the grabbed\n * row's new view index, or `-1` when it can't move (no grab / at the edge).\n */\n public moveGrabbed(direction: -1 | 1): number {\n if (!this.grabbed) return -1;\n const view = this.host.pageItems;\n const current = view.indexOf(this.grabbed);\n const target = current + direction;\n if (current === -1 || target < 0 || target >= view.length) return -1;\n const before = this.#captureRowRects();\n const ok = this.#commit(this.grabbed, view[target] as T, direction > 0 ? 'after' : 'before', {\n silent: true,\n });\n if (!ok) return -1;\n void this.#flipAfterUpdate(before);\n this.host.announce(this.host.localize('announce.rowMovedTo', { position: target + 1 }));\n return target;\n }\n\n /** Drops the grabbed row, keeping its moves. */\n public drop(): void {\n if (!this.grabbed) return;\n this.grabbed = null;\n this.#preGrab = null;\n this.host.requestUpdate();\n this.host.announce(this.host.localize('announce.rowDropped'));\n }\n\n /**\n * Cancels the grab, reverting the order, the data order (with\n * `applyToData`) and the sort to what they were when the row was grabbed.\n * Emits `rowMoved` for the way back when the row had moved, so an app\n * persisting each step sees the revert too.\n */\n public cancelGrab(): void {\n const row = this.grabbed;\n const pre = this.#preGrab;\n if (!row || !pre) return;\n const from = this.host.pageItems.indexOf(row);\n this.grabbed = this.#preGrab = null;\n this.#order = pre.order;\n if (pre.data) this.#spliceData(pre.data);\n if (pre.sort.length) this.host.sortExpressions = pre.sort;\n this.host.requestUpdate(PIPELINE);\n this.host.announce(this.host.localize('announce.reorderCancelled'));\n const to = pre.index;\n if (from !== to) {\n const position: RowDropPosition = from > to ? 'before' : 'after';\n this.host.emitEvent('rowMoved', { detail: { from, to, position, toIndex: to, data: row } });\n }\n }\n\n // --- internals ----------------------------------------------------------\n\n /**\n * The order every row is in, hidden by a filter or not: the manual order,\n * else `data` under the active sort, with rows it lacks following in data\n * order. The rows the view shows are laid into their own slots in view order,\n * so the move applies to exactly what the user sees and hidden rows stay put.\n */\n #fullOrder(): T[] {\n const data = this.host.data;\n const sort = this.host.sortExpressions;\n let base: T[];\n if (this.#order) {\n const rest = new Set(data);\n base = this.#order.filter((row) => rest.delete(row));\n base.push(...rest);\n } else if (sort.length && !this.host.dataPipelineConfiguration?.sort) {\n const state = new Map(sort.map((expr) => [expr.key, expr] as const));\n base = new SortDataOperation<T>().apply([...data], state);\n } else {\n base = [...data];\n }\n const listed = new Set(base);\n const shown = this.host.dataView.filter((row) => listed.has(row));\n const inView = new Set(shown);\n let k = 0;\n return base.map((row) => (inView.has(row) ? shown[k++] : row));\n }\n\n /**\n * The core order mutation: validates, emits `rowMoving` (cancellable),\n * updates the manual order (or splices data when `applyToData`), clears any\n * sort (a move establishes a manual order, which a sort would undo), re-runs\n * the pipeline, and emits `rowMoved`. Does not animate.\n */\n #commit(\n source: T | undefined,\n target: T | undefined,\n position: RowDropPosition,\n options: { silent?: boolean } = {}\n ): boolean {\n if (!this.enabled || !source || !target || source === target) return false;\n const view = this.host.pageItems;\n const from = view.indexOf(source);\n const to = view.indexOf(target);\n // Where the row lands in the view; a move that leaves it in place is no move.\n const toIndex = position === 'after' ? (from < to ? to : to + 1) : from < to ? to - 1 : to;\n if (from === -1 || to === -1 || toIndex === from) return false;\n\n // A row outside the order (a tree child, a module's row) cannot move.\n const next = this.#fullOrder();\n const at = next.indexOf(source);\n if (at === -1 || !next.includes(target)) return false;\n next.splice(at, 1);\n next.splice(next.indexOf(target) + (position === 'after' ? 1 : 0), 0, source);\n // Rows outside the order (group rows) can make a view move a no-op too.\n if (next.indexOf(source) === at) return false;\n\n const detail = { from, to, position, toIndex, data: source };\n if (!this.host.emitEvent('rowMoving', { detail, cancelable: true })) return false;\n\n if (this.host.sortExpressions.length) this.host.sortExpressions = [];\n\n if (this.applyToData) {\n this.#spliceData(next);\n this.#order = null; // the data array now carries the order\n } else {\n this.#order = next;\n }\n\n this.host.requestUpdate(PIPELINE);\n if (!options.silent) this.host.announce(this.host.localize('announce.rowMoved'));\n this.host.emitEvent('rowMoved', { detail });\n return true;\n }\n\n /** Reorders {@link ApexGrid.data} in place to match `order`. */\n #spliceData(order: ReadonlyArray<T>): void {\n const rank = new Map<T, number>();\n order.forEach((row, i) => {\n rank.set(row, i);\n });\n (this.host.data as T[]).sort((a, b) => {\n const ra = rank.has(a) ? (rank.get(a) as number) : Number.POSITIVE_INFINITY;\n const rb = rank.has(b) ? (rank.get(b) as number) : Number.POSITIVE_INFINITY;\n return ra - rb;\n });\n }\n\n /** The rendered body row (non-pinned) whose box contains `clientY`. */\n #bodyRowAt(clientY: number): { data: T; element: HTMLElement } | null {\n const pinned = this.host.pinnedRows;\n for (const row of this.host.rows) {\n if (pinned.top.includes(row.data) || pinned.bottom.includes(row.data)) continue;\n const element = row as unknown as HTMLElement;\n const rect = element.getBoundingClientRect();\n if (clientY >= rect.top && clientY < rect.bottom) return { data: row.data, element };\n }\n return null;\n }\n\n #captureRowRects(): KeyedFlipEntry<T>[] {\n const entries: KeyedFlipEntry<T>[] = [];\n for (const row of this.host.rows) {\n const el = row as unknown as HTMLElement;\n entries.push({ key: row.data, rect: el.getBoundingClientRect() });\n }\n return entries;\n }\n\n async #flipAfterUpdate(before: ReadonlyArray<KeyedFlipEntry<T>>): Promise<void> {\n await this.host.updateComplete;\n await awaitChildUpdates(this.host.rows);\n this.#playRowFlip(before);\n }\n\n #playRowFlip(before: ReadonlyArray<KeyedFlipEntry<T>>): void {\n const byData = new Map<T, HTMLElement>();\n for (const row of this.host.rows) {\n byData.set(row.data, row as unknown as HTMLElement);\n }\n playKeyedFlip(before, (data) => byData.get(data) ?? null, 'y');\n }\n}\n"]}
1
+ {"version":3,"file":"row-reorder.js","sourceRoot":"","sources":["../../src/controllers/row-reorder.ts"],"names":[],"mappings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AAC,IAAI,EAAE,CAAC;YACjC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAA6B,CAAC,CAAC;QACtD,CAAC;QACD,aAAa,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;IACjE,CAAC;CACF","sourcesContent":["import type { ReactiveController } from 'lit';\nimport { PIPELINE } from '../internal/constants.js';\nimport { type KeyedFlipEntry, playKeyedFlip, settleRowsForFlip } from '../internal/flip.js';\nimport type { GridHost } from '../internal/types.js';\nimport type { SortExpression } from '../operations/sort/types.js';\nimport SortDataOperation from '../operations/sort.js';\n\n/** Where a moved row lands relative to its target. */\nexport type RowDropPosition = 'before' | 'after';\n\n/** Pixels the pointer must travel before a row drag engages. */\nconst DRAG_THRESHOLD_PX = 4;\n\n/** A single cell snapshot used to paint the floating row ghost. */\nexport interface RowGhostCell {\n /** The cell's rendered text at grab time. */\n text: string;\n /** The cell's rendered width (px), so the ghost matches the column layout. */\n width: number;\n /** The cell's computed `text-align`, so numbers stay right-aligned in the ghost. */\n align: string;\n}\n\n/** Everything the row hands the controller to seed the floating ghost. */\nexport interface RowGhostInit {\n /** The source row's bounding rect at grab time. */\n rect: DOMRect;\n /** Pointer position at grab time (to keep the grab point under the cursor). */\n clientX: number;\n clientY: number;\n /** Per-cell snapshot of the row's visible content. */\n cells: RowGhostCell[];\n}\n\n/**\n * Snapshots a row element for the floating ghost: its bounding rect and each\n * cell's rendered text, width and alignment. A cell renders into its own\n * shadow root, so the text is read from there.\n */\nexport function captureRowGhost(\n row: Element,\n cells: ReadonlyArray<Element>,\n clientX: number,\n clientY: number\n): RowGhostInit {\n const rect = row.getBoundingClientRect();\n const snapshot = cells.map((cell) => ({\n text: ((cell.shadowRoot ?? cell).textContent ?? '').replace(/\\s+/g, ' ').trim(),\n width: cell.getBoundingClientRect().width,\n align: getComputedStyle(cell).textAlign,\n }));\n return { rect, clientX, clientY, cells: snapshot };\n}\n\n/**\n * Live state for the floating \"ghost\" row that trails the cursor during a\n * pointer drag. Mirrors {@link ReorderController}'s column ghost: the source\n * row stays in the grid (and live-swaps), the ghost is a purely visual proxy.\n */\nexport interface RowGhostState {\n /** Ghost position (viewport-relative top-left, in CSS pixels). */\n x: number;\n y: number;\n /** Ghost size, fixed at the source row's initial bounding rect. */\n width: number;\n height: number;\n /** Cursor offset within the ghost so the grab point stays under the cursor. */\n pointerOffsetX: number;\n pointerOffsetY: number;\n /** Snapshot of the row's visible cells. */\n cells: ReadonlyArray<RowGhostCell>;\n}\n\n/**\n * Reactive controller backing row drag-reorder and a manual row order.\n *\n * @remarks\n * Row order is normally derived (filter → sort). This controller adds a\n * **manual order**: an explicit sequence of row references applied as a\n * pipeline step after sort. A manual order and a sort are mutually exclusive:\n * applying a sort clears the manual order, and a move clears the sort. The\n * order spans every row, hidden by a filter or not, so a move made under a\n * filter leaves the hidden rows in place. State is reference-based, so it\n * survives the in-place pipeline, and it is carried onto a new `data` array\n * (by `rowId` when set, else by identity).\n *\n * Reordering happens through {@link moveRow} (pointer live-swap during a drag,\n * the keyboard grab/move flow, or the public API). Each move goes through the\n * cancellable `rowMoving` event and emits a follow-up `rowMoved`, then animates\n * with a Y-axis FLIP. Pinned rows (F4) are never the drag source and reorder\n * only within the unpinned body set.\n *\n * Persistence: by default the order lives in this controller and the app\n * persists via `rowMoved`. With `rowReordering.applyToData` the move also\n * splices {@link ApexGrid.data} in place (and clears the manual order, since the\n * data array then carries the order).\n */\nexport class RowReorderController<T extends object> implements ReactiveController {\n /** Manual order of row references, or `null` for the natural (sorted) order. */\n #order: T[] | null = null;\n\n /**\n * What a keyboard grab may change, captured when it starts, for\n * Escape-to-cancel: the manual order, the data order (with `applyToData`),\n * the sort and the grabbed row's view index.\n */\n #preGrab: {\n order: T[] | null;\n data: T[] | null;\n sort: SortExpression<T>[];\n index: number;\n } | null = null;\n\n /** The row currently being pointer-dragged, or `null`. */\n public dragging: T | null = null;\n\n /**\n * Live floating-ghost state during a pointer drag, or `null`. Surfaced to the\n * grid, which renders the ghost at the top of its shadow tree (outside the\n * virtualizer) so `position: fixed` tracks the viewport cleanly.\n */\n public ghost: RowGhostState | null = null;\n\n /** The row currently grabbed for keyboard reorder, or `null`. */\n public grabbed: T | null = null;\n\n /** Re-entrancy guard so a slow swap can't trigger a second mid-drag. */\n #swapping = false;\n\n /**\n * In-flight pointer-drag gesture. The move/up listeners live on the **grid\n * host** (a stable element), not the row, so a live-swap that recycles the\n * source row's DOM can't tear the drag down mid-gesture.\n */\n #pending: {\n data: T;\n getGhost: () => RowGhostInit | null;\n startX: number;\n startY: number;\n pointerId: number;\n } | null = null;\n\n constructor(protected host: GridHost<T>) {\n this.host.addController(this);\n }\n\n /** The grid host as a DOM event target (it is always an `HTMLElement`). */\n get #hostElement(): HTMLElement {\n return this.host as unknown as HTMLElement;\n }\n\n public hostConnected() {}\n\n /** A grid detached mid-drag ends the gesture, so no frozen ghost stays behind. */\n public hostDisconnected() {\n this.#endPointer();\n }\n\n /** Whether row reordering is enabled at the grid level. */\n public get enabled(): boolean {\n return Boolean(this.host.rowReordering?.enabled);\n }\n\n /**\n * Whether a pointer drag must start from the dedicated grip handle (the\n * default), rather than from anywhere on the row. Driven by\n * `rowReordering.handle` (defaults to `true`).\n */\n public get handleMode(): boolean {\n return this.enabled && this.host.rowReordering?.handle !== false;\n }\n\n /**\n * Whether the leading grip-handle column is rendered. Only in handle mode, and\n * only while reordering is enabled.\n */\n public get showHandleColumn(): boolean {\n return this.handleMode;\n }\n\n /** Whether moves also splice {@link ApexGrid.data} in place. */\n public get applyToData(): boolean {\n return Boolean(this.host.rowReordering?.applyToData);\n }\n\n /** Whether a manual order is currently active. */\n public get hasManualOrder(): boolean {\n return this.#order !== null;\n }\n\n /** Whether a row is currently grabbed for keyboard reorder. */\n public get isGrabbing(): boolean {\n return this.grabbed !== null;\n }\n\n /**\n * Pipeline step: reorders the (post-filter, post-sort) rows by the manual\n * order. Rows absent from the manual order (e.g. newly added) keep their\n * incoming relative order at the end. Identity pass-through when inactive.\n */\n public apply(rows: T[]): T[] {\n if (!this.#order) return rows;\n const rank = new Map<T, number>();\n this.#order.forEach((row, i) => {\n rank.set(row, i);\n });\n return [...rows].sort((a, b) => {\n const ra = rank.has(a) ? (rank.get(a) as number) : Number.POSITIVE_INFINITY;\n const rb = rank.has(b) ? (rank.get(b) as number) : Number.POSITIVE_INFINITY;\n return ra - rb;\n });\n }\n\n /**\n * The current manual order as a copy of its row references, or `null` for the\n * derived order. Consumed by `ApexGrid.getState`.\n */\n public getManualOrder(): T[] | null {\n return this.#order ? [...this.#order] : null;\n }\n\n /**\n * Restores a manual order from a list of row references (state restore). Pass\n * `null` (or an empty list) to clear it. Silent: emits no `rowMoving` /\n * `rowMoved` and does not animate; re-runs the pipeline.\n */\n public restoreManualOrder(order: T[] | null): void {\n this.#order = order?.length ? [...order] : null;\n this.host.requestUpdate(PIPELINE);\n }\n\n /**\n * Clears the manual order (e.g. when a sort is applied). Re-runs the pipeline.\n */\n public clearManualOrder(announce = false): void {\n if (!this.#order) return;\n this.#order = null;\n this.host.requestUpdate(PIPELINE);\n if (announce) this.host.announce(this.host.localize('announce.manualOrderCleared'));\n }\n\n /**\n * Carries the manual order onto a new `data` array through `carry` (by\n * `rowId` when set, else the rows still present), clearing it when no row\n * survives. A grab or drag follows its row onto the new data, so an app\n * that re-sets `data` on `rowMoved` keeps the gesture; it ends only when\n * the row is gone.\n */\n public resetForDataChange(carry: (rows: T[]) => T[]): void {\n const pre = this.#preGrab;\n if (this.grabbed) {\n this.grabbed = carry([this.grabbed])[0] ?? null;\n if (!this.grabbed) this.#preGrab = null;\n else if (pre) {\n pre.order = pre.order && carry(pre.order);\n pre.data = pre.data && carry(pre.data);\n }\n }\n const pending = this.#pending;\n const held = pending?.data ?? this.dragging;\n if (held) {\n const row = carry([held])[0];\n if (!row) this.#endPointer();\n else {\n if (pending) pending.data = row;\n if (this.dragging) this.dragging = row;\n }\n }\n if (this.#order) this.restoreManualOrder(carry(this.#order));\n }\n\n /**\n * Moves the row at view index `from` relative to the row at view index `to`.\n * Indices are into {@link ApexGrid.pageItems}.\n *\n * @returns `true` when applied, `false` when disabled, out of range, a\n * no-op (the row would land where it is), or cancelled via `rowMoving`.\n */\n public moveRow(from: number, to: number, position: RowDropPosition = 'before'): boolean {\n const view = this.host.pageItems;\n const before = this.#captureRowRects();\n const ok = this.#commit(view[from] as T, view[to] as T, position);\n if (ok) void this.#flipAfterUpdate(before);\n return ok;\n }\n\n // --- pointer drag -------------------------------------------------------\n\n /**\n * Begins a pointer drag from `source`. When `ghost` is supplied (the pointer\n * path always does), seeds the floating ghost from the source row's rect and\n * the grab point so it stays anchored under the cursor.\n */\n public startDrag(source: T, ghost?: RowGhostInit): void {\n if (!this.enabled) return;\n this.dragging = source;\n this.ghost = ghost\n ? {\n x: ghost.rect.left,\n y: ghost.rect.top,\n width: ghost.rect.width,\n height: ghost.rect.height,\n pointerOffsetX: ghost.clientX - ghost.rect.left,\n pointerOffsetY: ghost.clientY - ghost.rect.top,\n cells: ghost.cells,\n }\n : null;\n this.host.requestUpdate();\n }\n\n /** Moves the floating ghost to track the cursor. No-op without an active ghost. */\n public moveGhost(clientX: number, clientY: number): void {\n if (!this.ghost) return;\n this.ghost = {\n ...this.ghost,\n x: clientX - this.ghost.pointerOffsetX,\n y: clientY - this.ghost.pointerOffsetY,\n };\n this.host.requestUpdate();\n }\n\n /**\n * Called on pointer-move during a drag: live-swaps the dragged row past the\n * body row currently under `clientY` once the cursor crosses its midpoint.\n */\n public dragOver(clientY: number): void {\n if (!this.dragging || this.#swapping) return;\n const target = this.#bodyRowAt(clientY);\n if (!target || target.data === this.dragging) return;\n\n const view = this.host.pageItems;\n const sourceIdx = view.indexOf(this.dragging);\n const targetIdx = view.indexOf(target.data);\n if (sourceIdx === -1 || targetIdx === -1) return;\n\n const rect = target.element.getBoundingClientRect();\n const midpoint = rect.top + rect.height / 2;\n let position: RowDropPosition;\n if (sourceIdx < targetIdx) {\n if (clientY < midpoint) return; // dragging down — wait for the midpoint\n position = 'after';\n } else {\n if (clientY > midpoint) return; // dragging up\n position = 'before';\n }\n void this.#dragSwap(target.data, position);\n }\n\n /** Ends the pointer drag. The order is already final (live-swapped). */\n public endDrag(): void {\n if (!this.dragging) return;\n this.dragging = null;\n this.ghost = null;\n this.host.requestUpdate();\n }\n\n /**\n * Arms a pointer drag from a row press. Called by the row on `pointerdown`\n * (from the grip in handle mode, or anywhere in whole-row mode). The move\n * listener is bound to the **grid host**, so the gesture is immune to the\n * source row's DOM being recycled by a live-swap; the up / cancel listeners\n * are bound to the document, so a release outside the grid ends it too, as\n * does a move with the primary button no longer held. The ghost is\n * snapshotted once, the instant the drag engages, from the row element that\n * renders `data` then; `getGhost` is the pressed row's own snapshot, used\n * when no rendered row shows `data`, and returns `null` once that row shows\n * another record.\n */\n public armPointerDrag(data: T, getGhost: () => RowGhostInit | null, event: PointerEvent): void {\n const pinned = this.host.pinnedRows;\n if (!this.enabled || pinned.top.includes(data) || pinned.bottom.includes(data)) return;\n this.#pending = {\n data,\n getGhost,\n startX: event.clientX,\n startY: event.clientY,\n pointerId: event.pointerId,\n };\n const host = this.#hostElement;\n host.addEventListener('pointermove', this.#onHostPointerMove);\n host.ownerDocument.addEventListener('pointerup', this.#onPointerUp, true);\n host.ownerDocument.addEventListener('pointercancel', this.#onPointerUp, true);\n }\n\n #onHostPointerMove = (event: PointerEvent): void => {\n const pending = this.#pending;\n if (!pending || event.pointerId !== pending.pointerId) return;\n // The release was missed (e.g. outside the window): a hover is not a drag.\n if (!(event.buttons & 1)) {\n this.#endPointer();\n return;\n }\n if (!this.dragging) {\n const dx = event.clientX - pending.startX;\n const dy = event.clientY - pending.startY;\n if (Math.hypot(dx, dy) < DRAG_THRESHOLD_PX) return;\n // Capture on the stable host so moves keep arriving even when the cursor\n // leaves the grid, and so the source row reflowing can't drop the pointer.\n try {\n this.#hostElement.setPointerCapture(pending.pointerId);\n } catch {\n /* a synthetic pointer id may not be capturable; hit-testing still works */\n }\n this.startDrag(pending.data, this.#ghostAtEngage(pending) ?? undefined);\n }\n this.moveGhost(event.clientX, event.clientY);\n this.dragOver(event.clientY);\n };\n\n /**\n * The ghost snapshot for an engaging drag, taken from the row element that\n * renders the pressed record now. A re-bind between the press and the\n * engage (a sort, a data change) can leave another record in the pressed\n * element, so the element is found by record, not kept from the press.\n */\n #ghostAtEngage(pending: {\n data: T;\n getGhost: () => RowGhostInit | null;\n startX: number;\n startY: number;\n }): RowGhostInit | null {\n const row = this.host.rows.find((candidate) => candidate.data === pending.data);\n if (!row) return pending.getGhost();\n const cells = row.cells as unknown as Element[];\n return captureRowGhost(row as unknown as Element, cells, pending.startX, pending.startY);\n }\n\n #onPointerUp = (event: PointerEvent): void => {\n if (event.pointerId === this.#pending?.pointerId) this.#endPointer();\n };\n\n /** Tears down an armed or engaged pointer gesture. */\n #endPointer(): void {\n const pending = this.#pending;\n if (pending) {\n const host = this.#hostElement;\n host.removeEventListener('pointermove', this.#onHostPointerMove);\n host.ownerDocument.removeEventListener('pointerup', this.#onPointerUp, true);\n host.ownerDocument.removeEventListener('pointercancel', this.#onPointerUp, true);\n try {\n if (host.hasPointerCapture(pending.pointerId)) {\n host.releasePointerCapture(pending.pointerId);\n }\n } catch {\n /* capture was never taken or already released */\n }\n this.#pending = null;\n }\n this.endDrag();\n }\n\n async #dragSwap(target: T, position: RowDropPosition): Promise<void> {\n if (this.#swapping) return;\n this.#swapping = true;\n try {\n const before = this.#captureRowRects();\n if (this.#commit(this.dragging as T, target, position)) {\n await settleRowsForFlip(this.host);\n this.#playRowFlip(before);\n }\n } finally {\n this.#swapping = false;\n }\n }\n\n // --- keyboard grab ------------------------------------------------------\n\n /** Grabs the row at view index `rowIndex` for keyboard reorder. */\n public grab(rowIndex: number): boolean {\n if (!this.enabled) return false;\n const row = this.host.pageItems[rowIndex] as T | undefined;\n if (!row) return false;\n this.grabbed = row;\n this.#preGrab = {\n order: this.#order,\n data: this.applyToData ? [...this.host.data] : null,\n sort: this.host.sortExpressions,\n index: rowIndex,\n };\n this.host.requestUpdate();\n this.host.announce(this.host.localize('announce.rowGrabbed'));\n return true;\n }\n\n /**\n * Moves the grabbed row one position in `direction`. Returns the grabbed\n * row's new view index, or `-1` when it can't move (no grab / at the edge).\n */\n public moveGrabbed(direction: -1 | 1): number {\n if (!this.grabbed) return -1;\n const view = this.host.pageItems;\n const current = view.indexOf(this.grabbed);\n const target = current + direction;\n if (current === -1 || target < 0 || target >= view.length) return -1;\n const before = this.#captureRowRects();\n const ok = this.#commit(this.grabbed, view[target] as T, direction > 0 ? 'after' : 'before', {\n silent: true,\n });\n if (!ok) return -1;\n void this.#flipAfterUpdate(before);\n this.host.announce(this.host.localize('announce.rowMovedTo', { position: target + 1 }));\n return target;\n }\n\n /** Drops the grabbed row, keeping its moves. */\n public drop(): void {\n if (!this.grabbed) return;\n this.grabbed = null;\n this.#preGrab = null;\n this.host.requestUpdate();\n this.host.announce(this.host.localize('announce.rowDropped'));\n }\n\n /**\n * Cancels the grab, reverting the order, the data order (with\n * `applyToData`) and the sort to what they were when the row was grabbed.\n * Emits `rowMoved` for the way back when the row had moved, so an app\n * persisting each step sees the revert too.\n */\n public cancelGrab(): void {\n const row = this.grabbed;\n const pre = this.#preGrab;\n if (!row || !pre) return;\n const from = this.host.pageItems.indexOf(row);\n this.grabbed = this.#preGrab = null;\n this.#order = pre.order;\n if (pre.data) this.#spliceData(pre.data);\n if (pre.sort.length) this.host.sortExpressions = pre.sort;\n this.host.requestUpdate(PIPELINE);\n this.host.announce(this.host.localize('announce.reorderCancelled'));\n const to = pre.index;\n if (from !== to) {\n const position: RowDropPosition = from > to ? 'before' : 'after';\n this.host.emitEvent('rowMoved', { detail: { from, to, position, toIndex: to, data: row } });\n }\n }\n\n // --- internals ----------------------------------------------------------\n\n /**\n * The order every row is in, hidden by a filter or not: the manual order,\n * else `data` under the active sort, with rows it lacks following in data\n * order. The rows the view shows are laid into their own slots in view order,\n * so the move applies to exactly what the user sees and hidden rows stay put.\n */\n #fullOrder(): T[] {\n const data = this.host.data;\n const sort = this.host.sortExpressions;\n let base: T[];\n if (this.#order) {\n const rest = new Set(data);\n base = this.#order.filter((row) => rest.delete(row));\n base.push(...rest);\n } else if (sort.length && !this.host.dataPipelineConfiguration?.sort) {\n const state = new Map(sort.map((expr) => [expr.key, expr] as const));\n base = new SortDataOperation<T>().apply([...data], state);\n } else {\n base = [...data];\n }\n const listed = new Set(base);\n const shown = this.host.dataView.filter((row) => listed.has(row));\n const inView = new Set(shown);\n let k = 0;\n return base.map((row) => (inView.has(row) ? shown[k++] : row));\n }\n\n /**\n * The core order mutation: validates, emits `rowMoving` (cancellable),\n * updates the manual order (or splices data when `applyToData`), clears any\n * sort (a move establishes a manual order, which a sort would undo), re-runs\n * the pipeline, and emits `rowMoved`. Does not animate.\n */\n #commit(\n source: T | undefined,\n target: T | undefined,\n position: RowDropPosition,\n options: { silent?: boolean } = {}\n ): boolean {\n if (!this.enabled || !source || !target || source === target) return false;\n const view = this.host.pageItems;\n const from = view.indexOf(source);\n const to = view.indexOf(target);\n // Where the row lands in the view; a move that leaves it in place is no move.\n const toIndex = position === 'after' ? (from < to ? to : to + 1) : from < to ? to - 1 : to;\n if (from === -1 || to === -1 || toIndex === from) return false;\n\n // A row outside the order (a tree child, a module's row) cannot move.\n const next = this.#fullOrder();\n const at = next.indexOf(source);\n if (at === -1 || !next.includes(target)) return false;\n next.splice(at, 1);\n next.splice(next.indexOf(target) + (position === 'after' ? 1 : 0), 0, source);\n // Rows outside the order (group rows) can make a view move a no-op too.\n if (next.indexOf(source) === at) return false;\n\n const detail = { from, to, position, toIndex, data: source };\n if (!this.host.emitEvent('rowMoving', { detail, cancelable: true })) return false;\n\n if (this.host.sortExpressions.length) this.host.sortExpressions = [];\n\n if (this.applyToData) {\n this.#spliceData(next);\n this.#order = null; // the data array now carries the order\n } else {\n this.#order = next;\n }\n\n this.host.requestUpdate(PIPELINE);\n if (!options.silent) this.host.announce(this.host.localize('announce.rowMoved'));\n this.host.emitEvent('rowMoved', { detail });\n return true;\n }\n\n /** Reorders {@link ApexGrid.data} in place to match `order`. */\n #spliceData(order: ReadonlyArray<T>): void {\n const rank = new Map<T, number>();\n order.forEach((row, i) => {\n rank.set(row, i);\n });\n (this.host.data as T[]).sort((a, b) => {\n const ra = rank.has(a) ? (rank.get(a) as number) : Number.POSITIVE_INFINITY;\n const rb = rank.has(b) ? (rank.get(b) as number) : Number.POSITIVE_INFINITY;\n return ra - rb;\n });\n }\n\n /** The rendered body row (non-pinned) whose box contains `clientY`. */\n #bodyRowAt(clientY: number): { data: T; element: HTMLElement } | null {\n const pinned = this.host.pinnedRows;\n for (const row of this.host.rows) {\n if (pinned.top.includes(row.data) || pinned.bottom.includes(row.data)) continue;\n const element = row as unknown as HTMLElement;\n const rect = element.getBoundingClientRect();\n if (clientY >= rect.top && clientY < rect.bottom) return { data: row.data, element };\n }\n return null;\n }\n\n #captureRowRects(): KeyedFlipEntry<T>[] {\n const entries: KeyedFlipEntry<T>[] = [];\n for (const row of this.host.rows) {\n const el = row as unknown as HTMLElement;\n entries.push({ key: row.data, rect: el.getBoundingClientRect() });\n }\n return entries;\n }\n\n async #flipAfterUpdate(before: ReadonlyArray<KeyedFlipEntry<T>>): Promise<void> {\n await settleRowsForFlip(this.host);\n this.#playRowFlip(before);\n }\n\n #playRowFlip(before: ReadonlyArray<KeyedFlipEntry<T>>): void {\n const byData = new Map<T, HTMLElement>();\n for (const row of this.host.rows) {\n byData.set(row.data, row as unknown as HTMLElement);\n }\n playKeyedFlip(before, (data) => byData.get(data) ?? null, 'y');\n }\n}\n"]}