@ni/nimble-components 34.8.3 → 34.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/all-components-bundle.js +1 -1
- package/dist/all-components-bundle.js.map +1 -1
- package/dist/all-components-bundle.min.js +1 -1
- package/dist/all-components-bundle.min.js.map +1 -1
- package/dist/esm/table/models/expansion-manager.js +1 -1
- package/dist/esm/table/models/expansion-manager.js.map +1 -1
- package/package.json +1 -1
|
@@ -113,7 +113,7 @@ export class ExpansionManager {
|
|
|
113
113
|
return false;
|
|
114
114
|
}
|
|
115
115
|
return (this.hierarchyOptions.get(id)?.delayedHierarchyState
|
|
116
|
-
=== TableRecordDelayedHierarchyState.loadingChildren
|
|
116
|
+
=== TableRecordDelayedHierarchyState.loadingChildren);
|
|
117
117
|
}
|
|
118
118
|
canLoadDelayedChildren(id) {
|
|
119
119
|
if (!this.isHierarchyEnabled) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expansion-manager.js","sourceRoot":"","sources":["../../../../src/table/models/expansion-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAKH,gCAAgC,EACnC,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;GAUG;AACH,MAAM,OAAO,gBAAgB;IAMzB,YACqB,aAA8C;QAA9C,kBAAa,GAAb,aAAa,CAAiC;QAN3D,4BAAuB,GAAG,IAAI,GAAG,EAAmB,CAAC;QACrD,qBAAgB,GAAG,IAAI,GAAG,EAAuC,CAAC;QAClE,uBAAkB,GAAG,KAAK,CAAC;QAC3B,2BAAsB,GAAG,IAAI,GAAG,EAAU,CAAC;IAIhD,CAAC;IAEG,aAAa,CAAC,GAAkC;QACnD,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,MAAM,cAAc,GAAG,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,GAAG,CAA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AAgC,CAAC,eAAe,IAAI,KAAK,CACpE,CAAC;IACN,CAAC;IAEO,sBAAsB,CAAC,EAAU;QACrC,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,MAAM,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,qBAAqB,CAAC;QACnF,OAAO,qBAAqB,KAAK,gCAAgC,CAAC,IAAI,CAAC;IAC3E,CAAC;IAEO,wBAAwB,CAC5B,GAAkC;QAElC,0EAA0E;QAC1E,0EAA0E;QAC1E,wBAAwB;QACxB,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC;IACpC,CAAC;CACJ","sourcesContent":["import type {\n Row as TanStackRow,\n Table as TanStackTable\n} from '@tanstack/table-core';\nimport {\n type TableNode,\n type TableRecord,\n type TableSetRecordHierarchyOptions,\n type TableRecordHierarchyOptions,\n TableRecordDelayedHierarchyState\n} from '../types';\n\n/**\n * Manages the expanded/collapsed state of rows in the table.\n *\n * We must track the expansion state separately from TanStack because:\n * 1. TanStack does not support having a different initial expansion state per row unless explicitly\n * specified for each row by ID. This causes problems in the nimble-table because we could have\n * a different initial expansion state for group rows, parent rows, and parent rows with delay-loaded\n * children.\n * 2. TanStack does not remove entries from its expanded state when those rows are no longer present\n * in the data. This is not ideal because the object maintaining the expansion state can grow unbounded.\n */\nexport class ExpansionManager<TData extends TableRecord> {\n private explicitExpansionStates = new Map<string, boolean>();\n private hierarchyOptions = new Map<string, TableRecordHierarchyOptions>();\n private isHierarchyEnabled = false;\n private parentRowsWithChildren = new Set<string>();\n\n public constructor(\n private readonly tanStackTable: TanStackTable<TableNode<TData>>\n ) {}\n\n public isRowExpanded(row: TanStackRow<TableNode<TData>>): boolean {\n if (!this.isRowExpandable(row)) {\n return false;\n }\n\n const expansionState = this.explicitExpansionStates.get(row.id);\n return expansionState ?? this.getDefaultExpansionState(row);\n }\n\n public toggleRowExpansion(row: TanStackRow<TableNode<TData>>): void {\n if (!this.isRowExpandable(row)) {\n return;\n }\n\n const wasExpanded = this.isRowExpanded(row);\n this.explicitExpansionStates.set(row.id, !wasExpanded);\n\n row.toggleExpanded();\n }\n\n public collapseAll(): void {\n this.resetExpansionState();\n\n const rows = this.tanStackTable.getRowModel().flatRows;\n for (const row of rows) {\n if (this.isRowExpandable(row)) {\n this.explicitExpansionStates.set(row.id, false);\n }\n }\n this.tanStackTable.toggleAllRowsExpanded(false);\n }\n\n public resetExpansionState(): void {\n this.explicitExpansionStates.clear();\n }\n\n public resetHierarchyOptions(): void {\n this.hierarchyOptions.clear();\n }\n\n public processDataUpdate(rows: TanStackRow<TableNode<TData>>[]): void {\n if (\n this.explicitExpansionStates.size === 0\n && this.hierarchyOptions.size === 0\n ) {\n return;\n }\n\n const updatedExplicitExpansionStates = new Map<string, boolean>();\n const updatedHierarchyOptions = new Map<\n string,\n TableRecordHierarchyOptions\n >();\n const updatedParentRowsWithChildren = new Set<string>();\n for (const row of rows) {\n const rowId = row.id;\n const isGroupRow = row.getIsGrouped();\n const rowHierarchyOptions = this.hierarchyOptions.get(rowId);\n if (!isGroupRow && rowHierarchyOptions) {\n updatedHierarchyOptions.set(rowId, rowHierarchyOptions);\n }\n\n if (this.isRowExpandable(row)) {\n const expansionState = this.explicitExpansionStates.get(rowId);\n if (expansionState !== undefined) {\n updatedExplicitExpansionStates.set(rowId, expansionState);\n }\n\n if (!isGroupRow) {\n const hasChildRows = row.subRows.length !== 0;\n if (hasChildRows) {\n updatedParentRowsWithChildren.add(rowId);\n } else if (this.parentRowsWithChildren.has(rowId)) {\n // The row used to have children, but now it does not. Therefore,\n // collapse the row.\n updatedExplicitExpansionStates.set(rowId, false);\n }\n }\n }\n }\n\n this.explicitExpansionStates = updatedExplicitExpansionStates;\n this.hierarchyOptions = updatedHierarchyOptions;\n this.parentRowsWithChildren = updatedParentRowsWithChildren;\n }\n\n public setHierarchyOptions(\n hierarchyOptions: TableSetRecordHierarchyOptions[]\n ): void {\n const updatedHierarchyOptions = new Map<\n string,\n TableRecordHierarchyOptions\n >();\n for (const { recordId, options } of hierarchyOptions) {\n updatedHierarchyOptions.set(recordId, options);\n\n const oldState = this.hierarchyOptions.get(recordId)?.delayedHierarchyState;\n const newState = options.delayedHierarchyState;\n if (\n oldState === TableRecordDelayedHierarchyState.loadingChildren\n && newState === TableRecordDelayedHierarchyState.canLoadChildren\n && !this.parentRowsWithChildren.has(recordId)\n ) {\n // If a row without children transitions from loadingChildren to canLoadChildren,\n // put it back in its default state of collapsed.\n this.explicitExpansionStates.delete(recordId);\n }\n }\n this.hierarchyOptions = updatedHierarchyOptions;\n }\n\n public isRowExpandable(row: TanStackRow<TableNode<TData>>): boolean {\n return row.subRows.length > 0 || this.canLoadDelayedChildren(row.id);\n }\n\n public setHierarchyEnabled(isHierarchyEnabled: boolean): void {\n this.isHierarchyEnabled = isHierarchyEnabled;\n }\n\n public isLoadingChildren(id: string): boolean {\n if (!this.isHierarchyEnabled) {\n return false;\n }\n\n return (\n this.hierarchyOptions.get(id)?.delayedHierarchyState\n === TableRecordDelayedHierarchyState.loadingChildren ?? false\n );\n }\n\n private canLoadDelayedChildren(id: string): boolean {\n if (!this.isHierarchyEnabled) {\n return false;\n }\n\n const delayedHierarchyState = this.hierarchyOptions.get(id)?.delayedHierarchyState;\n return delayedHierarchyState !== TableRecordDelayedHierarchyState.none;\n }\n\n private getDefaultExpansionState(\n row: TanStackRow<TableNode<TData>>\n ): boolean {\n // Rows with children (group rows and parent rows with populated children)\n // default to expanded. Other rows (parent rows with lazy-loaded children)\n // default to collapsed.\n return row.subRows.length !== 0;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"expansion-manager.js","sourceRoot":"","sources":["../../../../src/table/models/expansion-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAKH,gCAAgC,EACnC,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;GAUG;AACH,MAAM,OAAO,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EM,eAAe,CAAC,GAAkC;QACrD,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzE,CAAC;IAEM,mBAAmB,CAAC,kBAA2B;QAClD,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IACjD,CAAC;IAEM,iBAAiB,CAAC,EAAU;QAC/B,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,OAAO,CACH,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,qBAAqB;gBAC5C,gCAAgC,CAAC,eAAe,CAC3D,CAAC;IACN,CAAC;IAEO,sBAAsB,CAAC,EAAU;QACrC,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,MAAM,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,qBAAqB,CAAC;QACnF,OAAO,qBAAqB,KAAK,gCAAgC,CAAC,IAAI,CAAC;IAC3E,CAAC;IAEO,wBAAwB,CAC5B,GAAkC;QAElC,0EAA0E;QAC1E,0EAA0E;QAC1E,wBAAwB;QACxB,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC;IACpC,CAAC;CACJ","sourcesContent":["import type {\n Row as TanStackRow,\n Table as TanStackTable\n} from '@tanstack/table-core';\nimport {\n type TableNode,\n type TableRecord,\n type TableSetRecordHierarchyOptions,\n type TableRecordHierarchyOptions,\n TableRecordDelayedHierarchyState\n} from '../types';\n\n/**\n * Manages the expanded/collapsed state of rows in the table.\n *\n * We must track the expansion state separately from TanStack because:\n * 1. TanStack does not support having a different initial expansion state per row unless explicitly\n * specified for each row by ID. This causes problems in the nimble-table because we could have\n * a different initial expansion state for group rows, parent rows, and parent rows with delay-loaded\n * children.\n * 2. TanStack does not remove entries from its expanded state when those rows are no longer present\n * in the data. This is not ideal because the object maintaining the expansion state can grow unbounded.\n */\nexport class ExpansionManager<TData extends TableRecord> {\n private explicitExpansionStates = new Map<string, boolean>();\n private hierarchyOptions = new Map<string, TableRecordHierarchyOptions>();\n private isHierarchyEnabled = false;\n private parentRowsWithChildren = new Set<string>();\n\n public constructor(\n private readonly tanStackTable: TanStackTable<TableNode<TData>>\n ) {}\n\n public isRowExpanded(row: TanStackRow<TableNode<TData>>): boolean {\n if (!this.isRowExpandable(row)) {\n return false;\n }\n\n const expansionState = this.explicitExpansionStates.get(row.id);\n return expansionState ?? this.getDefaultExpansionState(row);\n }\n\n public toggleRowExpansion(row: TanStackRow<TableNode<TData>>): void {\n if (!this.isRowExpandable(row)) {\n return;\n }\n\n const wasExpanded = this.isRowExpanded(row);\n this.explicitExpansionStates.set(row.id, !wasExpanded);\n\n row.toggleExpanded();\n }\n\n public collapseAll(): void {\n this.resetExpansionState();\n\n const rows = this.tanStackTable.getRowModel().flatRows;\n for (const row of rows) {\n if (this.isRowExpandable(row)) {\n this.explicitExpansionStates.set(row.id, false);\n }\n }\n this.tanStackTable.toggleAllRowsExpanded(false);\n }\n\n public resetExpansionState(): void {\n this.explicitExpansionStates.clear();\n }\n\n public resetHierarchyOptions(): void {\n this.hierarchyOptions.clear();\n }\n\n public processDataUpdate(rows: TanStackRow<TableNode<TData>>[]): void {\n if (\n this.explicitExpansionStates.size === 0\n && this.hierarchyOptions.size === 0\n ) {\n return;\n }\n\n const updatedExplicitExpansionStates = new Map<string, boolean>();\n const updatedHierarchyOptions = new Map<\n string,\n TableRecordHierarchyOptions\n >();\n const updatedParentRowsWithChildren = new Set<string>();\n for (const row of rows) {\n const rowId = row.id;\n const isGroupRow = row.getIsGrouped();\n const rowHierarchyOptions = this.hierarchyOptions.get(rowId);\n if (!isGroupRow && rowHierarchyOptions) {\n updatedHierarchyOptions.set(rowId, rowHierarchyOptions);\n }\n\n if (this.isRowExpandable(row)) {\n const expansionState = this.explicitExpansionStates.get(rowId);\n if (expansionState !== undefined) {\n updatedExplicitExpansionStates.set(rowId, expansionState);\n }\n\n if (!isGroupRow) {\n const hasChildRows = row.subRows.length !== 0;\n if (hasChildRows) {\n updatedParentRowsWithChildren.add(rowId);\n } else if (this.parentRowsWithChildren.has(rowId)) {\n // The row used to have children, but now it does not. Therefore,\n // collapse the row.\n updatedExplicitExpansionStates.set(rowId, false);\n }\n }\n }\n }\n\n this.explicitExpansionStates = updatedExplicitExpansionStates;\n this.hierarchyOptions = updatedHierarchyOptions;\n this.parentRowsWithChildren = updatedParentRowsWithChildren;\n }\n\n public setHierarchyOptions(\n hierarchyOptions: TableSetRecordHierarchyOptions[]\n ): void {\n const updatedHierarchyOptions = new Map<\n string,\n TableRecordHierarchyOptions\n >();\n for (const { recordId, options } of hierarchyOptions) {\n updatedHierarchyOptions.set(recordId, options);\n\n const oldState = this.hierarchyOptions.get(recordId)?.delayedHierarchyState;\n const newState = options.delayedHierarchyState;\n if (\n oldState === TableRecordDelayedHierarchyState.loadingChildren\n && newState === TableRecordDelayedHierarchyState.canLoadChildren\n && !this.parentRowsWithChildren.has(recordId)\n ) {\n // If a row without children transitions from loadingChildren to canLoadChildren,\n // put it back in its default state of collapsed.\n this.explicitExpansionStates.delete(recordId);\n }\n }\n this.hierarchyOptions = updatedHierarchyOptions;\n }\n\n public isRowExpandable(row: TanStackRow<TableNode<TData>>): boolean {\n return row.subRows.length > 0 || this.canLoadDelayedChildren(row.id);\n }\n\n public setHierarchyEnabled(isHierarchyEnabled: boolean): void {\n this.isHierarchyEnabled = isHierarchyEnabled;\n }\n\n public isLoadingChildren(id: string): boolean {\n if (!this.isHierarchyEnabled) {\n return false;\n }\n\n return (\n this.hierarchyOptions.get(id)?.delayedHierarchyState\n === TableRecordDelayedHierarchyState.loadingChildren\n );\n }\n\n private canLoadDelayedChildren(id: string): boolean {\n if (!this.isHierarchyEnabled) {\n return false;\n }\n\n const delayedHierarchyState = this.hierarchyOptions.get(id)?.delayedHierarchyState;\n return delayedHierarchyState !== TableRecordDelayedHierarchyState.none;\n }\n\n private getDefaultExpansionState(\n row: TanStackRow<TableNode<TData>>\n ): boolean {\n // Rows with children (group rows and parent rows with populated children)\n // default to expanded. Other rows (parent rows with lazy-loaded children)\n // default to collapsed.\n return row.subRows.length !== 0;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ni/nimble-components",
|
|
3
|
-
"version": "34.8.
|
|
3
|
+
"version": "34.8.4",
|
|
4
4
|
"description": "Styled web components for the NI Nimble Design System",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm run generate-icons && npm run generate-workers && npm run build-components && npm run bundle-components && npm run generate-scss",
|