apex-grid 3.5.0 → 4.0.0-beta.1

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 (215) hide show
  1. package/CHANGELOG.md +573 -0
  2. package/LICENSE.md +125 -0
  3. package/README.md +143 -23
  4. package/components/cell.d.ts +43 -5
  5. package/components/cell.js +225 -64
  6. package/components/cell.js.map +1 -1
  7. package/components/filter-row.d.ts +2 -0
  8. package/components/filter-row.js +82 -28
  9. package/components/filter-row.js.map +1 -1
  10. package/components/grid.d.ts +281 -49
  11. package/components/grid.js +600 -159
  12. package/components/grid.js.map +1 -1
  13. package/components/group-header-row.js +28 -25
  14. package/components/group-header-row.js.map +1 -1
  15. package/components/header-row.d.ts +6 -10
  16. package/components/header-row.js +12 -28
  17. package/components/header-row.js.map +1 -1
  18. package/components/header.js +71 -22
  19. package/components/header.js.map +1 -1
  20. package/components/paginator.d.ts +20 -5
  21. package/components/paginator.js +54 -17
  22. package/components/paginator.js.map +1 -1
  23. package/components/row.d.ts +19 -3
  24. package/components/row.js +211 -56
  25. package/components/row.js.map +1 -1
  26. package/components/toolbar.d.ts +5 -1
  27. package/components/toolbar.js +6 -2
  28. package/components/toolbar.js.map +1 -1
  29. package/components/virtualize-rows.d.ts +38 -0
  30. package/components/virtualize-rows.js +286 -0
  31. package/components/virtualize-rows.js.map +1 -0
  32. package/components/virtualizer.d.ts +111 -1
  33. package/components/virtualizer.js +192 -5
  34. package/components/virtualizer.js.map +1 -1
  35. package/controllers/dom.d.ts +14 -7
  36. package/controllers/dom.js +45 -27
  37. package/controllers/dom.js.map +1 -1
  38. package/controllers/editing.d.ts +104 -37
  39. package/controllers/editing.js +230 -78
  40. package/controllers/editing.js.map +1 -1
  41. package/controllers/expansion.d.ts +14 -5
  42. package/controllers/expansion.js +24 -1
  43. package/controllers/expansion.js.map +1 -1
  44. package/controllers/filter.d.ts +10 -2
  45. package/controllers/filter.js +62 -17
  46. package/controllers/filter.js.map +1 -1
  47. package/controllers/history.d.ts +45 -8
  48. package/controllers/history.js +58 -20
  49. package/controllers/history.js.map +1 -1
  50. package/controllers/navigation.d.ts +130 -13
  51. package/controllers/navigation.js +474 -60
  52. package/controllers/navigation.js.map +1 -1
  53. package/controllers/pagination.d.ts +13 -6
  54. package/controllers/pagination.js +29 -22
  55. package/controllers/pagination.js.map +1 -1
  56. package/controllers/reorder.js +38 -22
  57. package/controllers/reorder.js.map +1 -1
  58. package/controllers/resize.d.ts +17 -2
  59. package/controllers/resize.js +16 -6
  60. package/controllers/resize.js.map +1 -1
  61. package/controllers/row-pin.d.ts +26 -2
  62. package/controllers/row-pin.js +24 -11
  63. package/controllers/row-pin.js.map +1 -1
  64. package/controllers/row-reorder.d.ts +40 -12
  65. package/controllers/row-reorder.js +137 -43
  66. package/controllers/row-reorder.js.map +1 -1
  67. package/controllers/selection.d.ts +33 -4
  68. package/controllers/selection.js +49 -11
  69. package/controllers/selection.js.map +1 -1
  70. package/controllers/sort.d.ts +22 -2
  71. package/controllers/sort.js +30 -25
  72. package/controllers/sort.js.map +1 -1
  73. package/controllers/state.d.ts +74 -7
  74. package/controllers/state.js +117 -36
  75. package/controllers/state.js.map +1 -1
  76. package/controllers/tree.d.ts +15 -10
  77. package/controllers/tree.js +0 -0
  78. package/controllers/tree.js.map +1 -1
  79. package/custom-elements.json +5091 -1023
  80. package/docs/assets/hierarchy.js +1 -1
  81. package/docs/assets/highlight.css +15 -8
  82. package/docs/assets/navigation.js +1 -1
  83. package/docs/assets/search.js +1 -1
  84. package/docs/classes/ApexGrid.html +233 -87
  85. package/docs/classes/ApexGridPaginator.html +39 -8
  86. package/docs/classes/ApexGridToolbar.html +11 -7
  87. package/docs/functions/localize.html +2 -2
  88. package/docs/hierarchy.html +1 -1
  89. package/docs/index.html +159 -26
  90. package/docs/interfaces/ApexCellValidationFailedEvent.html +3 -2
  91. package/docs/interfaces/ApexCellValueChangedEvent.html +4 -2
  92. package/docs/interfaces/ApexCellValueChangingEvent.html +3 -2
  93. package/docs/interfaces/ApexGridEventMap.html +5 -2
  94. package/docs/interfaces/ApexPageChangedEvent.html +3 -1
  95. package/docs/interfaces/ApexRowEditEndedEvent.html +2 -1
  96. package/docs/interfaces/ApexRowEditStartedEvent.html +2 -1
  97. package/docs/interfaces/ApexRowMovingEvent.html +9 -3
  98. package/docs/interfaces/ApexRowPinningEvent.html +1 -1
  99. package/docs/interfaces/ApexTreeRowExpandedEvent.html +4 -1
  100. package/docs/interfaces/ApexTreeRowExpandingEvent.html +4 -1
  101. package/docs/interfaces/BaseApexCellContext.html +18 -5
  102. package/docs/interfaces/BaseApexEditorContext.html +20 -5
  103. package/docs/interfaces/BaseFilterExpression.html +3 -3
  104. package/docs/interfaces/CSVExportOptions.html +12 -4
  105. package/docs/interfaces/DataPipelineConfiguration.html +4 -9
  106. package/docs/interfaces/ExportOptions.html +5 -3
  107. package/docs/interfaces/GridExpansionConfiguration.html +6 -2
  108. package/docs/interfaces/GridRowReorderingConfiguration.html +1 -1
  109. package/docs/interfaces/GridSelectionConfiguration.html +19 -4
  110. package/docs/interfaces/PaginationConfiguration.html +11 -4
  111. package/docs/interfaces/PaginationState.html +4 -2
  112. package/docs/interfaces/SetStateResult.html +3 -2
  113. package/docs/interfaces/ValidatorContext.html +7 -2
  114. package/docs/media/_token-values.scss +118 -0
  115. package/docs/media/package.json +9 -5
  116. package/docs/modules.html +1 -1
  117. package/docs/types/DataPipelineParams.html +2 -2
  118. package/docs/types/ExportSource.html +6 -4
  119. package/docs/types/OperandKeys.html +9 -0
  120. package/docs/types/PaginationMode.html +5 -4
  121. package/docs/variables/EN_LOCALE.html +2 -2
  122. package/i18n/en.d.ts +7 -0
  123. package/i18n/en.js +7 -0
  124. package/i18n/en.js.map +1 -1
  125. package/i18n/es.js +7 -0
  126. package/i18n/es.js.map +1 -1
  127. package/internal/column-types.d.ts +38 -2
  128. package/internal/column-types.js +83 -55
  129. package/internal/column-types.js.map +1 -1
  130. package/internal/constants.d.ts +1 -2
  131. package/internal/constants.js +0 -4
  132. package/internal/constants.js.map +1 -1
  133. package/internal/document-styles.d.ts +30 -0
  134. package/internal/document-styles.js +48 -0
  135. package/internal/document-styles.js.map +1 -0
  136. package/internal/export.d.ts +45 -7
  137. package/internal/export.js +39 -34
  138. package/internal/export.js.map +1 -1
  139. package/internal/feature-module.d.ts +67 -3
  140. package/internal/feature-module.js +6 -0
  141. package/internal/feature-module.js.map +1 -1
  142. package/internal/flip.d.ts +28 -16
  143. package/internal/flip.js +42 -10
  144. package/internal/flip.js.map +1 -1
  145. package/internal/index.d.ts +7 -5
  146. package/internal/index.js +6 -4
  147. package/internal/index.js.map +1 -1
  148. package/internal/normalize-case.d.ts +8 -1
  149. package/internal/normalize-case.js +3 -2
  150. package/internal/normalize-case.js.map +1 -1
  151. package/internal/state-snapshot.d.ts +60 -8
  152. package/internal/state-snapshot.js +87 -19
  153. package/internal/state-snapshot.js.map +1 -1
  154. package/internal/types.d.ts +92 -21
  155. package/internal/types.js.map +1 -1
  156. package/internal/utils.d.ts +34 -6
  157. package/internal/utils.js +30 -21
  158. package/internal/utils.js.map +1 -1
  159. package/internal/validators.js +1 -0
  160. package/internal/validators.js.map +1 -1
  161. package/operations/filter/operands/number.js +9 -6
  162. package/operations/filter/operands/number.js.map +1 -1
  163. package/operations/filter/operands/string.js +2 -3
  164. package/operations/filter/operands/string.js.map +1 -1
  165. package/operations/filter/types.d.ts +14 -2
  166. package/operations/filter/types.js.map +1 -1
  167. package/operations/filter.d.ts +6 -0
  168. package/operations/filter.js +23 -7
  169. package/operations/filter.js.map +1 -1
  170. package/operations/quick-filter.js +2 -5
  171. package/operations/quick-filter.js.map +1 -1
  172. package/operations/sort.d.ts +21 -2
  173. package/operations/sort.js +41 -14
  174. package/operations/sort.js.map +1 -1
  175. package/package.json +9 -4
  176. package/setup.d.ts +11 -0
  177. package/setup.js +9 -19
  178. package/setup.js.map +1 -1
  179. package/styles/_token-values.css.d.ts +1 -0
  180. package/styles/_token-values.css.js +3 -0
  181. package/styles/_token-values.css.js.map +1 -0
  182. package/styles/_tokens.css.js +1 -1
  183. package/styles/_tokens.css.js.map +1 -1
  184. package/styles/body-cell/body-cell.css.js +1 -1
  185. package/styles/body-cell/body-cell.css.js.map +1 -1
  186. package/styles/body-cell/cell-renderers.css.js +1 -1
  187. package/styles/body-cell/cell-renderers.css.js.map +1 -1
  188. package/styles/body-row/body-row.css.js +1 -1
  189. package/styles/body-row/body-row.css.js.map +1 -1
  190. package/styles/document-tokens.css.d.ts +1 -0
  191. package/styles/document-tokens.css.js +3 -0
  192. package/styles/document-tokens.css.js.map +1 -0
  193. package/styles/filter-row/filter-row.css.js +1 -1
  194. package/styles/filter-row/filter-row.css.js.map +1 -1
  195. package/styles/grid/_grid.base.css.js +1 -1
  196. package/styles/grid/_grid.base.css.js.map +1 -1
  197. package/styles/grid/grid.css.js +1 -1
  198. package/styles/grid/grid.css.js.map +1 -1
  199. package/styles/group-header-row/group-header-row.css.js +1 -1
  200. package/styles/group-header-row/group-header-row.css.js.map +1 -1
  201. package/styles/header-cell/header-cell.css.js +1 -1
  202. package/styles/header-cell/header-cell.css.js.map +1 -1
  203. package/styles/header-row/header-row.base.css.js +1 -1
  204. package/styles/header-row/header-row.base.css.js.map +1 -1
  205. package/styles/paginator/paginator.css.js +1 -1
  206. package/styles/paginator/paginator.css.js.map +1 -1
  207. package/styles/toolbar/toolbar.css.js +1 -1
  208. package/styles/toolbar/toolbar.css.js.map +1 -1
  209. package/tokens.css +78 -0
  210. package/LICENSE +0 -80
  211. package/docs/media/LICENSE +0 -80
  212. package/docs/media/_tokens.scss +0 -214
  213. package/operations/pagination.d.ts +0 -19
  214. package/operations/pagination.js +0 -12
  215. package/operations/pagination.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/controllers/history.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAIpD,MAAM,kBAAkB,GAAG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AAG,IAAI,CAAC,SAAS,EAAE,CAAC;YAC1C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,YAAY,CAAC,OAAoB,EAAE,IAAqB;QACtD,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAClC,MAAM,KAAK,GAAG,OAAO,YAAY,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9E,MAAM,GAAG,GACP,IAAI,KAAK,MAAM;YACb,CAAC,CAAC,KAAK,KAAK,CAAC;gBACX,CAAC,CAAC,kBAAkB;gBACpB,CAAC,CAAC,mBAAmB;YACvB,CAAC,CAAC,KAAK,KAAK,CAAC;gBACX,CAAC,CAAC,kBAAkB;gBACpB,CAAC,CAAC,mBAAmB,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QACvD,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,YAAY;QACV,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE;YACpC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;SACzD,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { ReactiveController } from 'lit';\nimport { PIPELINE } from '../internal/constants.js';\nimport type { GridHost, Keys } from '../internal/types.js';\n\n/** Default number of commands retained on the undo stack. */\nconst DEFAULT_STACK_SIZE = 100;\n\n/**\n * A single recorded cell mutation: the record reference, its column, and the\n * before / after values. `rowIndex` is the view-relative index at record time\n * and is used only for the replayed `cellValueChanged` event (the live record\n * reference is authoritative).\n */\nexport interface CellChange<T extends object> {\n record: T;\n key: Keys<T>;\n rowIndex: number;\n oldValue: unknown;\n newValue: unknown;\n}\n\n/**\n * A reversible unit of work on the history stacks.\n *\n * @remarks\n * `apply` re-performs the change (redo); `revert` undoes it. Cell-data edits use\n * {@link CellEditCommand}; the interface is deliberately open so later command\n * kinds (e.g. view-state) can join the same stacks.\n */\nexport interface EditCommand {\n apply(): void;\n revert(): void;\n}\n\n/**\n * One or more cell mutations that undo / redo as a single step. A single-cell\n * edit holds one change; a row-mode commit or a bulk paste / fill holds many so\n * one Ctrl+Z reverts the whole batch.\n */\nexport class CellEditCommand<T extends object> implements EditCommand {\n constructor(\n private host: GridHost<T>,\n public readonly changes: ReadonlyArray<CellChange<T>>\n ) {}\n\n public apply(): void {\n for (const change of this.changes) {\n this.#write(change, change.newValue);\n }\n }\n\n public revert(): void {\n // Revert in reverse so overlapping writes to the same cell unwind cleanly.\n for (let i = this.changes.length - 1; i >= 0; i -= 1) {\n this.#write(this.changes[i], this.changes[i].oldValue);\n }\n }\n\n #write(change: CellChange<T>, value: unknown): void {\n (change.record as Record<string, unknown>)[change.key as string] = value;\n // Re-emit `cellValueChanged` (never the cancellable `cellValueChanging`) so\n // data-bound consumers stay in sync. Validation and history recording are\n // intentionally skipped on replay. Prefer the record's current view index\n // when it is on the page; fall back to the recorded one.\n const liveIndex = this.host.pageItems.indexOf(change.record);\n this.host.emitEvent('cellValueChanged', {\n detail: {\n key: change.key,\n rowIndex: liveIndex >= 0 ? liveIndex : change.rowIndex,\n data: change.record,\n value,\n },\n });\n }\n}\n\n/**\n * Reactive controller owning the undo / redo stacks for cell-data edits.\n *\n * @remarks\n * Recording is driven from the {@link EditingController.applyCellEdit} choke\n * point: every successful write calls {@link record}. Single edits push one\n * command; {@link beginBatch} / {@link endBatch} coalesce a row-mode commit or a\n * bulk paste / fill into one command. Disabled unless\n * `editing.history.enabled` is set, so the community grid pays nothing.\n */\nexport class HistoryController<T extends object> implements ReactiveController {\n #undo: EditCommand[] = [];\n #redo: EditCommand[] = [];\n #batch: CellChange<T>[] | null = null;\n\n constructor(protected host: GridHost<T>) {\n this.host.addController(this);\n }\n\n public hostConnected(): void {}\n\n /** Whether undo / redo tracking is enabled. */\n public get enabled(): boolean {\n return Boolean(this.host.editing?.history?.enabled);\n }\n\n /** Maximum number of commands retained on the undo stack. */\n public get stackSize(): number {\n const size = this.host.editing?.history?.stackSize;\n return typeof size === 'number' && size > 0 ? size : DEFAULT_STACK_SIZE;\n }\n\n /** Whether there is at least one command to undo. */\n public get canUndo(): boolean {\n return this.#undo.length > 0;\n }\n\n /** Whether there is at least one command to redo. */\n public get canRedo(): boolean {\n return this.#redo.length > 0;\n }\n\n /**\n * Records a single cell mutation. Routed to the open batch when one is active,\n * otherwise pushed immediately as a standalone command. No-op when history is\n * disabled.\n */\n public record(change: CellChange<T>): void {\n if (!this.enabled) return;\n if (this.#batch) {\n this.#batch.push(change);\n return;\n }\n this.#push(new CellEditCommand(this.host, [change]));\n }\n\n /**\n * Opens a batch so subsequent {@link record} calls coalesce into one command.\n * Nestable calls are flattened (the outermost {@link endBatch} commits).\n */\n public beginBatch(): void {\n if (!this.enabled) return;\n this.#batch ??= [];\n }\n\n /**\n * Closes the open batch, pushing it as a single command when it captured any\n * changes.\n */\n public endBatch(): void {\n const batch = this.#batch;\n this.#batch = null;\n if (batch && batch.length > 0) {\n this.#push(new CellEditCommand(this.host, batch));\n }\n }\n\n /** Reverts the most recent command. No-op when the undo stack is empty. */\n public undo(): void {\n const command = this.#undo.pop();\n if (!command) return;\n command.revert();\n this.#redo.push(command);\n this.#afterReplay(command, 'undo');\n }\n\n /** Re-applies the most recently undone command. No-op when nothing to redo. */\n public redo(): void {\n const command = this.#redo.pop();\n if (!command) return;\n command.apply();\n this.#undo.push(command);\n this.#afterReplay(command, 'redo');\n }\n\n /** Clears both stacks (e.g. after a data reset). */\n public clear(): void {\n if (this.#undo.length === 0 && this.#redo.length === 0) return;\n this.#undo = [];\n this.#redo = [];\n this.#batch = null;\n this.#emitChanged();\n }\n\n #push(command: EditCommand): void {\n this.#undo.push(command);\n // A fresh edit invalidates the redo branch.\n this.#redo = [];\n // Evict the oldest commands once the stack exceeds its cap.\n while (this.#undo.length > this.stackSize) {\n this.#undo.shift();\n }\n this.#emitChanged();\n }\n\n #afterReplay(command: EditCommand, kind: 'undo' | 'redo'): void {\n this.host.requestUpdate(PIPELINE);\n const count = command instanceof CellEditCommand ? command.changes.length : 1;\n const key =\n kind === 'undo'\n ? count === 1\n ? 'announce.undoOne'\n : 'announce.undoMany'\n : count === 1\n ? 'announce.redoOne'\n : 'announce.redoMany';\n this.host.announce(this.host.localize(key, { count }));\n this.#emitChanged();\n }\n\n #emitChanged(): void {\n this.host.emitEvent('historyChanged', {\n detail: { canUndo: this.canUndo, canRedo: this.canRedo },\n });\n }\n}\n"]}
1
+ {"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/controllers/history.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAIpD,MAAM,kBAAkB,GAAG,GAAG,CAAC;AA6C/B,MAAM,OAAO,eAAe;IAC1B,YACU,IAAiB,EACT,OAAqC,EACrC,WAAuC,EAAE;QAFjD,SAAI,GAAJ,IAAI,CAAa;QACT,YAAO,GAAP,OAAO,CAA8B;QACrC,aAAQ,GAAR,QAAQ,CAAiC;IACxD,CAAC;IAEG,KAAK;QACV,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACtE,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC;QACD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,CAAC,KAAK,EAAE,CAAC;IACvD,CAAC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C,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QACvD,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,YAAY;QACV,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE;YACpC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;SACzD,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { ReactiveController } from 'lit';\nimport { PIPELINE } from '../internal/constants.js';\nimport type { GridHost, Keys } from '../internal/types.js';\n\n/** Default number of commands retained on the undo stack. */\nconst DEFAULT_STACK_SIZE = 100;\n\n/**\n * A single recorded cell mutation: the record reference, its column, and the\n * before / after values. `rowIndex` is the view-relative index at record time;\n * replay reports the record's index at replay time instead (the live record\n * reference is authoritative).\n */\nexport interface CellChange<T extends object> {\n record: T;\n key: Keys<T>;\n rowIndex: number;\n oldValue: unknown;\n newValue: unknown;\n}\n\n/**\n * A reversible unit of work on the history stacks.\n *\n * @remarks\n * `apply` re-performs the change (redo); `revert` undoes it. Cell-data edits use\n * {@link CellEditCommand}; the interface is deliberately open so later command\n * kinds (e.g. view-state) can join the same stacks.\n */\nexport interface EditCommand {\n apply(): void;\n revert(): void;\n /** The record the command acts on: history is cleared once a reload drops it. */\n readonly record?: object;\n /**\n * For a command staged with a row edit: the value to stage for its cell,\n * re-read from the row's staged values just before the row commits, so\n * validation judges what the command will leave there.\n */\n stagedValue?(staged: ReadonlyMap<PropertyKey, unknown>): unknown;\n}\n\n/**\n * One or more cell mutations that undo / redo as a single step. A single-cell\n * edit holds one change; a row-mode commit or a bulk paste / fill holds many so\n * one Ctrl+Z reverts the whole batch. `commands` are other commands pushed in\n * the same batch (a feature's state riding with the edit, such as a formula):\n * they replay after the cell values in both directions, so a value write can\n * never undo the state they restore.\n */\nexport class CellEditCommand<T extends object> implements EditCommand {\n constructor(\n private host: GridHost<T>,\n public readonly changes: ReadonlyArray<CellChange<T>>,\n public readonly commands: ReadonlyArray<EditCommand> = []\n ) {}\n\n public apply(): void {\n const indexOf = viewIndexer(this.host.pageItems, this.changes.length);\n for (const change of this.changes) {\n this.#write(change, change.newValue, indexOf);\n }\n for (const command of this.commands) command.apply();\n }\n\n public revert(): void {\n const indexOf = viewIndexer(this.host.pageItems, this.changes.length);\n // Revert in reverse so overlapping writes to the same cell unwind cleanly.\n for (let i = this.changes.length - 1; i >= 0; i -= 1) {\n this.#write(this.changes[i], this.changes[i].oldValue, indexOf);\n }\n for (let i = this.commands.length - 1; i >= 0; i -= 1) this.commands[i].revert();\n }\n\n #write(change: CellChange<T>, value: unknown, indexOf: (record: T) => number): void {\n (change.record as Record<string, unknown>)[change.key as string] = value;\n // Re-emit `cellValueChanged` (never the cancellable `cellValueChanging`) so\n // data-bound consumers stay in sync. Validation and history recording are\n // intentionally skipped on replay. The index is where the record is now:\n // -1 when it is pinned or on another page.\n this.host.emitEvent('cellValueChanged', {\n detail: { key: change.key, rowIndex: indexOf(change.record), data: change.record, value },\n });\n }\n}\n\n/**\n * Returns a lookup of a record's index in `items` (by reference, `-1` when\n * absent). For more than one lookup it indexes `items` once, so a large batch\n * costs one pass instead of one scan per record.\n */\nexport function viewIndexer<T>(items: ReadonlyArray<T>, lookups: number): (record: T) => number {\n if (lookups < 2) return (record) => items.indexOf(record);\n let index: Map<T, number> | undefined;\n return (record) => {\n if (!index) {\n index = new Map();\n // Backwards, so a record listed twice resolves to its first index.\n for (let i = items.length - 1; i >= 0; i -= 1) index.set(items[i], i);\n }\n return index.get(record) ?? -1;\n };\n}\n\n/**\n * Reactive controller owning the undo / redo stacks for cell-data edits.\n *\n * @remarks\n * Recording is driven from the {@link EditingController.applyCellEdit} choke\n * point: every successful write calls {@link record}. Single edits push one\n * command; {@link beginBatch} / {@link endBatch} coalesce a row-mode commit or a\n * bulk paste / fill into one command. Disabled unless\n * `editing.history.enabled` is set, so the community grid pays nothing.\n */\nexport class HistoryController<T extends object> implements ReactiveController {\n #undo: EditCommand[] = [];\n #redo: EditCommand[] = [];\n /** Changes recorded by the open batch, pushed as one command when it closes. */\n #batch: CellChange<T>[] = [];\n /** Commands {@link push}ed while the batch is open, replayed after its changes. */\n #commands: EditCommand[] = [];\n /** Open {@link beginBatch} calls; only the outermost {@link endBatch} commits. */\n #depth = 0;\n\n constructor(protected host: GridHost<T>) {\n this.host.addController(this);\n }\n\n public hostConnected(): void {}\n\n /** Whether undo / redo tracking is enabled. */\n public get enabled(): boolean {\n return Boolean(this.host.editing?.history?.enabled);\n }\n\n /** Maximum number of commands retained on the undo stack. */\n public get stackSize(): number {\n const size = this.host.editing?.history?.stackSize;\n return typeof size === 'number' && size > 0 ? size : DEFAULT_STACK_SIZE;\n }\n\n /** Whether there is at least one command to undo. */\n public get canUndo(): boolean {\n return this.#undo.length > 0;\n }\n\n /** Whether there is at least one command to redo. */\n public get canRedo(): boolean {\n return this.#redo.length > 0;\n }\n\n /**\n * Records a single cell mutation. Routed to the open batch when one is active,\n * otherwise pushed immediately as a standalone command. No-op when history is\n * disabled.\n */\n public record(change: CellChange<T>): void {\n if (!this.enabled) return;\n if (this.#depth > 0) {\n this.#batch.push(change);\n return;\n }\n this.#push(new CellEditCommand(this.host, [change]));\n }\n\n /**\n * Records a command that is not a plain cell write (its first `apply` has\n * already run). Joins the open batch, replaying after the batch's cell\n * changes, otherwise pushed as its own step. No-op when history is disabled.\n */\n public push(command: EditCommand): void {\n if (!this.enabled) return;\n if (this.#depth > 0) this.#commands.push(command);\n else this.#push(command);\n }\n\n /**\n * Opens a batch so subsequent {@link record} calls coalesce into one command.\n * Nested calls are flattened: a batch opened while another is open (a\n * `cellValueChanged` listener that calls `applyEdits`, say) joins it, and\n * only the outermost {@link endBatch} commits. Counted even while history\n * is disabled, so every begin pairs with its end.\n */\n public beginBatch(): void {\n this.#depth += 1;\n }\n\n /**\n * Closes the innermost open batch. Closing the outermost pushes everything\n * it captured as a single command.\n */\n public endBatch(): void {\n if (this.#depth === 0 || --this.#depth > 0) return;\n const batch = this.#batch;\n const commands = this.#commands;\n this.#batch = [];\n this.#commands = [];\n if (batch.length > 0 || commands.length > 0) {\n this.#push(new CellEditCommand(this.host, batch, commands));\n }\n }\n\n /** Reverts the most recent command. No-op when the undo stack is empty. */\n public undo(): void {\n const command = this.#undo.pop();\n if (!command) return;\n command.revert();\n this.#redo.push(command);\n this.#afterReplay(command, 'undo');\n }\n\n /** Re-applies the most recently undone command. No-op when nothing to redo. */\n public redo(): void {\n const command = this.#redo.pop();\n if (!command) return;\n command.apply();\n this.#undo.push(command);\n this.#afterReplay(command, 'redo');\n }\n\n /** Clears both stacks, and the changes an open batch has captured so far. */\n public clear(): void {\n this.#batch = [];\n this.#commands = [];\n if (this.#undo.length === 0 && this.#redo.length === 0) return;\n this.#undo = [];\n this.#redo = [];\n this.#emitChanged();\n }\n\n /**\n * Clears both stacks when the grid's data was replaced and a recorded change\n * (or a command's {@link EditCommand.record}) names a record that `records`\n * no longer yields (a reload with new objects).\n * Replaying onto such a detached record would change nothing on screen while\n * still reporting the edit. New data that keeps the edited records (an\n * append, a re-sorted copy) keeps its history. `records` is read only while\n * a stack has entries, so the caller may pass an expensive source.\n */\n public reconcile(records: () => Iterable<T>): void {\n if (this.#undo.length === 0 && this.#redo.length === 0) return;\n const live = new Set(records());\n const stale = (command: EditCommand): boolean =>\n (command.record !== undefined && !live.has(command.record as T)) ||\n (command instanceof CellEditCommand &&\n (command.changes.some((change: CellChange<T>) => !live.has(change.record)) ||\n command.commands.some(stale)));\n if (this.#undo.some(stale) || this.#redo.some(stale)) this.clear();\n }\n\n #push(command: EditCommand): void {\n this.#undo.push(command);\n // A fresh edit invalidates the redo branch.\n this.#redo = [];\n // Evict the oldest commands once the stack exceeds its cap.\n while (this.#undo.length > this.stackSize) {\n this.#undo.shift();\n }\n this.#emitChanged();\n }\n\n #afterReplay(command: EditCommand, kind: 'undo' | 'redo'): void {\n this.host.requestUpdate(PIPELINE);\n const count = command instanceof CellEditCommand ? command.changes.length || 1 : 1;\n const key =\n kind === 'undo'\n ? count === 1\n ? 'announce.undoOne'\n : 'announce.undoMany'\n : count === 1\n ? 'announce.redoOne'\n : 'announce.redoMany';\n this.host.announce(this.host.localize(key, { count }));\n this.#emitChanged();\n }\n\n #emitChanged(): void {\n this.host.emitEvent('historyChanged', {\n detail: { canUndo: this.canUndo, canRedo: this.canRedo },\n });\n }\n}\n"]}
@@ -1,16 +1,18 @@
1
1
  import type { ReactiveController } from 'lit';
2
+ import type ApexGridRow from '../components/row.js';
3
+ import { type ScrollInsets } from '../components/virtualizer.js';
2
4
  import type { ActiveNode, ColumnConfiguration, GridHost, Keys } from '../internal/types.js';
3
5
  export declare class NavigationController<T extends object> implements ReactiveController {
4
6
  #private;
5
7
  protected host: GridHost<T>;
6
8
  protected handlers: Map<string, (() => void) | (() => void) | (() => void) | (() => void) | (() => void) | (() => void) | (() => void) | (() => void) | (() => void)>;
7
9
  protected get virtualizer(): import("../components/virtualizer.js").default;
8
- protected state: Map<import("../internal/types.js").NavigationState, ActiveNode<any>>;
9
- protected _active: Readonly<ActiveNode<any>>;
10
- protected get nextNode(): {
11
- column: keyof T;
12
- row: number;
13
- };
10
+ /**
11
+ * The active cell of this grid. Instance state on purpose: every grid on a
12
+ * page, including one nested in another grid's detail panel, keeps its own.
13
+ */
14
+ protected _active: ActiveNode<T>;
15
+ protected get nextNode(): ActiveNode<T>;
14
16
  protected get columns(): Array<{
15
17
  key: Keys<T>;
16
18
  hidden?: boolean;
@@ -20,21 +22,129 @@ export declare class NavigationController<T extends object> implements ReactiveC
20
22
  hidden?: boolean;
21
23
  }[];
22
24
  protected get firstColumn(): Keys<T>;
25
+ /** Whether there is any cell to move to: a body row and a visible column. */
26
+ protected get navigable(): boolean;
23
27
  protected getPreviousColumn(key: Keys<T>): Keys<T>;
24
28
  protected getNextColumn(key: Keys<T>): Keys<T>;
29
+ /** The rendered body row at `index`, when the virtualizer has it in the DOM. */
30
+ protected findRow(index: number): ApexGridRow<T> | undefined;
31
+ /**
32
+ * The element that stands for `node` in the DOM: the cell, or for a row a
33
+ * feature module renders full width (a group header, a total row) the
34
+ * row's single focus target, whatever the column.
35
+ */
36
+ protected findCell(node: ActiveNode<T>): HTMLElement | undefined;
25
37
  protected scrollToCell(node: ActiveNode<T>): void;
26
- protected findActiveCell(): import("../components/cell.js").default<T> | undefined;
38
+ /** Scrolls body row `index` into view, rendered or not. */
39
+ protected scrollToRow(index: number): void;
40
+ /**
41
+ * Scrolls the cell at `node` into view clear of the sticky chrome without
42
+ * moving the active cell: the cell itself when it is rendered, else its row
43
+ * first and the cell once the virtualizer has rendered it. For a feature
44
+ * that moves something other than the active cell with the keyboard (range
45
+ * extension), so it scrolls the way arrow navigation does.
46
+ */
47
+ revealCell(node: ActiveNode<T>): void;
48
+ /**
49
+ * Whether ArrowLeft or ArrowRight steps towards the end of the column
50
+ * order: ArrowRight in a left-to-right grid, ArrowLeft in a right-to-left
51
+ * one. The rule every inline arrow key on this grid follows.
52
+ */
53
+ towardsInlineEnd(key: string): boolean;
54
+ /**
55
+ * How much of the scroll container's scrollport the sticky chrome covers
56
+ * (toolbar, headers and the pinned-top band above, the pinned-bottom band
57
+ * and the paginator below, pinned columns on either side). Keyboard scrolls
58
+ * use it as scroll-padding, so a row or cell the keyboard moves to is never
59
+ * parked underneath that chrome. Measured right before each keyboard scroll
60
+ * because any of those bands can change size between key presses. Public
61
+ * so a feature scrolling the body itself (drag auto-scroll) measures the
62
+ * same chrome.
63
+ */
64
+ scrollInsets(): ScrollInsets;
27
65
  /**
28
66
  * Moves real DOM focus to the active cell (the grid body's roving tab stop),
29
67
  * so screen readers track keyboard navigation. Waits for the host render to
30
- * commit the cell's `active` state, then retries once on the next frame to
31
- * cover virtualizer re-materialization after a long jump. No-op while no
32
- * cell is active (the scroll container keeps focus as the entry point).
68
+ * commit the cell's `active` state and, when the cell is not in the DOM yet
69
+ * (a long jump), for the virtualizer to finish laying out the new range.
70
+ * No-op while no cell is active (the scroll container keeps focus as the
71
+ * entry point).
72
+ *
73
+ * @param reveal - also scroll the cell into view once it exists, for jumps
74
+ * whose target row was not rendered when the scroll started.
33
75
  */
34
- focusActiveCell(): void;
76
+ focusActiveCell(reveal?: boolean): void;
35
77
  get active(): ActiveNode<T>;
36
78
  set active(node: ActiveNode<T>);
37
79
  constructor(host: GridHost<T>);
80
+ /**
81
+ * Whether this grid's body holds focus: the body itself, one of its cells
82
+ * or an editor in one, not a grid nested in a detail panel. Tracked from
83
+ * the body's focus events ({@link focusEntered}, {@link focusLeft}). A
84
+ * focus loss a re-bind caused (it removed the focused editor while a
85
+ * reconcile is running) keeps it until that reconcile has run, so it can
86
+ * put focus back under row recycling. Any other loss clears it: a click
87
+ * elsewhere, the window losing focus, a template removing its own focused
88
+ * element, the grid leaving the document. Focus is never taken back once
89
+ * it left the grid.
90
+ */
91
+ get ownsFocus(): boolean;
92
+ /**
93
+ * Whether focus arriving on the body itself should move on to the active
94
+ * cell (the roving tab stop). Not while a page change holds focus in the
95
+ * body, or while this controller puts it there.
96
+ */
97
+ get forwardsBodyFocus(): boolean;
98
+ /**
99
+ * Focus arrived in the body. `owned` is whether the event is this grid's
100
+ * rather than a nested grid's (the grid's `ownsEvent`).
101
+ */
102
+ focusEntered(event: FocusEvent, owned: boolean): void;
103
+ /**
104
+ * Focus left something in the body. Focus moving to another element is
105
+ * followed by its `focusin`, which sets {@link ownsFocus} again when that
106
+ * element is this body's. Focus going nowhere is a blur when the element
107
+ * is still in the document a microtask later, and a removal otherwise. A
108
+ * removal keeps {@link ownsFocus} only while a reconcile is running, which
109
+ * then decides; with none, nothing would repair it, so a later reconcile
110
+ * must not either.
111
+ */
112
+ focusLeft(event: FocusEvent, owned: boolean): void;
113
+ /**
114
+ * Row recycling: after the rows re-render, puts focus back in the body when
115
+ * the render took it away. A re-bind keeps every row element in place, so
116
+ * focus usually stays where it was, on the cell at the active position; it
117
+ * is lost only when the focused element left the document (an editor whose
118
+ * slot now shows another record) or stands on a row that now shows another
119
+ * record without being active. Then focus goes to the edited record's
120
+ * editor when it is rendered, else the active cell when its row is, else
121
+ * the body. Acts only while the body owns focus, so it never takes focus
122
+ * back from outside the grid or off a nested grid. A loss it leaves
123
+ * unrepaired clears {@link ownsFocus}.
124
+ */
125
+ reconcileFocus(): void;
126
+ /**
127
+ * Row recycling: a page change re-binds every row to the new page's
128
+ * records, so a focused cell would stay focused on another record. Holds
129
+ * focus in the body across the change: the body does not forward focus to
130
+ * the active cell, and the post-render reconcile waits. Returns what to
131
+ * call once the change has run its pipeline: focus then moves to the body
132
+ * unless it rests on an editor or on a cell still showing the record it
133
+ * showed before. Returns `null`, holding nothing, without row recycling or
134
+ * while the body does not own focus.
135
+ */
136
+ parkFocus(): (() => Promise<void>) | null;
137
+ /**
138
+ * Keeps the active cell pointing at something that exists. Runs before
139
+ * every grid render, so after a data swap, sort, filter, page change or a
140
+ * column hide or reorder the active node is clamped to the last row and the
141
+ * nearest visible column, or cleared when there is nothing left to point
142
+ * at (no rows, no visible columns). Without it a stale node names a cell
143
+ * that is never rendered, which leaves the body with no tab stop.
144
+ */
145
+ hostUpdate(): void;
146
+ /** The active row is one a feature module renders full width (no cells). */
147
+ protected isPresentedRow(index: number): boolean;
38
148
  /** Home moves to the first cell in the row (ARIA grid pattern). */
39
149
  protected home(): void;
40
150
  /** End moves to the last cell in the row (ARIA grid pattern). */
@@ -44,8 +154,9 @@ export declare class NavigationController<T extends object> implements ReactiveC
44
154
  /** Ctrl/Cmd+End moves to the last cell of the grid. */
45
155
  protected ctrlEnd(): void;
46
156
  /**
47
- * Rows per Page Up/Down step, derived from the host viewport and the height
48
- * of a rendered row (fallback: 10 rows when nothing is measurable yet).
157
+ * Rows per Page Up/Down step: the rows that fit in the part of the
158
+ * scrollport the sticky chrome leaves visible, minus one so the row the
159
+ * user was on stays in view. Falls back to 10 when nothing is measurable.
49
160
  */
50
161
  protected pageStep(): number;
51
162
  protected pageUp(): void;
@@ -58,6 +169,11 @@ export declare class NavigationController<T extends object> implements ReactiveC
58
169
  hostConnected(): void;
59
170
  hostDisconnected(): void;
60
171
  protected get editing(): {
172
+ activeCell: {
173
+ data: T;
174
+ columnKey: Keys<T>;
175
+ rowIndex: number;
176
+ } | null;
61
177
  enabled: boolean;
62
178
  isEditable(column: ColumnConfiguration<T>): boolean;
63
179
  editCell(rowIndex: number, columnKey: Keys<T>): Promise<boolean>;
@@ -70,6 +186,7 @@ export declare class NavigationController<T extends object> implements ReactiveC
70
186
  protected get rowReorder(): {
71
187
  enabled: boolean;
72
188
  isGrabbing: boolean;
189
+ grabbed: T | null;
73
190
  grab(rowIndex: number): boolean;
74
191
  moveGrabbed(direction: -1 | 1): number;
75
192
  drop(): void;