@cloudscape-design/components 3.0.442 → 3.0.444
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/anchor-navigation/use-scroll-spy.js +1 -1
- package/anchor-navigation/use-scroll-spy.js.map +1 -1
- package/collection-preferences/interfaces.d.ts +5 -1
- package/collection-preferences/interfaces.d.ts.map +1 -1
- package/collection-preferences/interfaces.js.map +1 -1
- package/flashbar/flash.d.ts.map +1 -1
- package/flashbar/flash.js +7 -9
- package/flashbar/flash.js.map +1 -1
- package/internal/components/live-region/index.d.ts +20 -2
- package/internal/components/live-region/index.d.ts.map +1 -1
- package/internal/components/live-region/index.js +37 -5
- package/internal/components/live-region/index.js.map +1 -1
- package/internal/components/screenreader-only/index.d.ts +1 -1
- package/internal/components/screenreader-only/index.d.ts.map +1 -1
- package/internal/components/screenreader-only/index.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/manifest.json +1 -1
- package/package.json +1 -149
- package/table/column-widths-utils.d.ts +0 -1
- package/table/column-widths-utils.d.ts.map +1 -1
- package/table/column-widths-utils.js +0 -18
- package/table/column-widths-utils.js.map +1 -1
- package/table/header-cell/index.d.ts.map +1 -1
- package/table/header-cell/index.js +3 -3
- package/table/header-cell/index.js.map +1 -1
- package/table/header-cell/styles.css.js +24 -24
- package/table/header-cell/styles.scoped.css +38 -53
- package/table/header-cell/styles.selectors.js +24 -24
- package/table/header-cell/th-element.d.ts +1 -2
- package/table/header-cell/th-element.d.ts.map +1 -1
- package/table/header-cell/th-element.js +1 -2
- package/table/header-cell/th-element.js.map +1 -1
- package/table/interfaces.d.ts +3 -1
- package/table/interfaces.d.ts.map +1 -1
- package/table/interfaces.js.map +1 -1
- package/table/internal.d.ts.map +1 -1
- package/table/internal.js +4 -5
- package/table/internal.js.map +1 -1
- package/table/resizer/index.d.ts +3 -0
- package/table/resizer/index.d.ts.map +1 -1
- package/table/resizer/index.js +5 -2
- package/table/resizer/index.js.map +1 -1
- package/table/resizer/styles.css.js +8 -6
- package/table/resizer/styles.scoped.css +36 -28
- package/table/resizer/styles.selectors.js +8 -6
- package/table/sticky-columns/use-sticky-columns.js +1 -1
- package/table/sticky-columns/use-sticky-columns.js.map +1 -1
- package/table/thead.d.ts +1 -0
- package/table/thead.d.ts.map +1 -1
- package/table/thead.js +24 -6
- package/table/thead.js.map +1 -1
- package/table/use-column-widths.d.ts +3 -5
- package/table/use-column-widths.d.ts.map +1 -1
- package/table/use-column-widths.js +11 -57
- package/table/use-column-widths.js.map +1 -1
- package/table/use-sticky-header.d.ts.map +1 -1
- package/table/use-sticky-header.js +13 -0
- package/table/use-sticky-header.js.map +1 -1
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { useResizeObserver, useStableCallback } from '@cloudscape-design/component-toolkit/internal';
|
|
4
3
|
import React, { useEffect, useRef, useState, createContext, useContext } from 'react';
|
|
5
|
-
import { setElementWidths } from './column-widths-utils';
|
|
6
4
|
export const DEFAULT_COLUMN_WIDTH = 120;
|
|
7
5
|
function readWidths(getCell, visibleColumns) {
|
|
8
6
|
var _a;
|
|
@@ -31,72 +29,27 @@ function updateWidths(visibleColumns, oldWidths, newWidth, columnId) {
|
|
|
31
29
|
return Object.assign(Object.assign({}, oldWidths), { [columnId]: newWidth });
|
|
32
30
|
}
|
|
33
31
|
const WidthsContext = createContext({
|
|
34
|
-
|
|
32
|
+
totalWidth: 0,
|
|
35
33
|
columnWidths: {},
|
|
36
34
|
updateColumn: () => { },
|
|
37
35
|
setCell: () => { },
|
|
38
36
|
});
|
|
39
|
-
export function ColumnWidthsProvider({ visibleColumns, resizableColumns,
|
|
37
|
+
export function ColumnWidthsProvider({ visibleColumns, resizableColumns, children }) {
|
|
40
38
|
const visibleColumnsRef = useRef(null);
|
|
41
|
-
const
|
|
42
|
-
const [columnWidths, setColumnWidths] = useState(null);
|
|
39
|
+
const [columnWidths, setColumnWidths] = useState({});
|
|
43
40
|
const cellsRef = useRef({});
|
|
44
|
-
const stickyCellsRef = useRef({});
|
|
45
41
|
const getCell = (columnId) => { var _a; return (_a = cellsRef.current[columnId]) !== null && _a !== void 0 ? _a : null; };
|
|
46
|
-
const setCell = (
|
|
47
|
-
const ref = sticky ? stickyCellsRef : cellsRef;
|
|
42
|
+
const setCell = (columnId, node) => {
|
|
48
43
|
if (node) {
|
|
49
|
-
|
|
44
|
+
cellsRef.current[columnId] = node;
|
|
50
45
|
}
|
|
51
46
|
else {
|
|
52
|
-
delete
|
|
47
|
+
delete cellsRef.current[columnId];
|
|
53
48
|
}
|
|
54
49
|
};
|
|
55
|
-
const getColumnStyles = (sticky, columnId) => {
|
|
56
|
-
var _a, _b, _c;
|
|
57
|
-
const column = visibleColumns.find(column => column.id === columnId);
|
|
58
|
-
if (!column) {
|
|
59
|
-
return {};
|
|
60
|
-
}
|
|
61
|
-
if (sticky) {
|
|
62
|
-
return { width: ((_a = cellsRef.current[column.id]) === null || _a === void 0 ? void 0 : _a.offsetWidth) || ((_b = columnWidths === null || columnWidths === void 0 ? void 0 : columnWidths[column.id]) !== null && _b !== void 0 ? _b : column.width) };
|
|
63
|
-
}
|
|
64
|
-
if (resizableColumns && columnWidths) {
|
|
65
|
-
const isLastColumn = column.id === ((_c = visibleColumns[visibleColumns.length - 1]) === null || _c === void 0 ? void 0 : _c.id);
|
|
66
|
-
const totalWidth = visibleColumns.reduce((sum, { id }) => sum + (columnWidths[id] || DEFAULT_COLUMN_WIDTH), 0);
|
|
67
|
-
if (isLastColumn && containerWidthRef.current > totalWidth) {
|
|
68
|
-
return { width: 'auto', minWidth: column === null || column === void 0 ? void 0 : column.minWidth };
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
return { width: columnWidths[column.id], minWidth: column === null || column === void 0 ? void 0 : column.minWidth };
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
width: column.width,
|
|
76
|
-
minWidth: column.minWidth,
|
|
77
|
-
maxWidth: !resizableColumns ? column.maxWidth : undefined,
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
// Imperatively sets width style for a cell avoiding React state.
|
|
81
|
-
// This allows setting the style as soon container's size change is observed.
|
|
82
|
-
const updateColumnWidths = useStableCallback(() => {
|
|
83
|
-
for (const column of visibleColumns) {
|
|
84
|
-
setElementWidths(cellsRef.current[column.id], getColumnStyles(false, column.id));
|
|
85
|
-
}
|
|
86
|
-
// Sticky column widths must be synchronized once all real column widths are assigned.
|
|
87
|
-
for (const id of Object.keys(stickyCellsRef.current)) {
|
|
88
|
-
setElementWidths(stickyCellsRef.current[id], getColumnStyles(true, id));
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
// Observes container size and requests an update to the last cell width as it depends on the container's width.
|
|
92
|
-
useResizeObserver(containerRef, ({ contentBoxWidth: containerWidth }) => {
|
|
93
|
-
containerWidthRef.current = containerWidth;
|
|
94
|
-
updateColumnWidths();
|
|
95
|
-
});
|
|
96
50
|
// The widths of the dynamically added columns (after the first render) if not set explicitly
|
|
97
51
|
// will default to the DEFAULT_COLUMN_WIDTH.
|
|
98
52
|
useEffect(() => {
|
|
99
|
-
updateColumnWidths();
|
|
100
53
|
if (!resizableColumns) {
|
|
101
54
|
return;
|
|
102
55
|
}
|
|
@@ -105,7 +58,7 @@ export function ColumnWidthsProvider({ visibleColumns, resizableColumns, contain
|
|
|
105
58
|
if (lastVisible) {
|
|
106
59
|
for (let index = 0; index < visibleColumns.length; index++) {
|
|
107
60
|
const column = visibleColumns[index];
|
|
108
|
-
if (!
|
|
61
|
+
if (!columnWidths[column.id] && lastVisible.indexOf(column.id) === -1) {
|
|
109
62
|
updates[column.id] = column.width || DEFAULT_COLUMN_WIDTH;
|
|
110
63
|
}
|
|
111
64
|
}
|
|
@@ -114,7 +67,7 @@ export function ColumnWidthsProvider({ visibleColumns, resizableColumns, contain
|
|
|
114
67
|
}
|
|
115
68
|
}
|
|
116
69
|
visibleColumnsRef.current = visibleColumns.map(column => column.id);
|
|
117
|
-
}, [columnWidths, resizableColumns, visibleColumns
|
|
70
|
+
}, [columnWidths, resizableColumns, visibleColumns]);
|
|
118
71
|
// Read the actual column widths after the first render to employ the browser defaults for
|
|
119
72
|
// those columns without explicit width.
|
|
120
73
|
useEffect(() => {
|
|
@@ -126,9 +79,10 @@ export function ColumnWidthsProvider({ visibleColumns, resizableColumns, contain
|
|
|
126
79
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
127
80
|
}, []);
|
|
128
81
|
function updateColumn(columnId, newWidth) {
|
|
129
|
-
setColumnWidths(columnWidths => updateWidths(visibleColumns, columnWidths
|
|
82
|
+
setColumnWidths(columnWidths => updateWidths(visibleColumns, columnWidths, newWidth, columnId));
|
|
130
83
|
}
|
|
131
|
-
|
|
84
|
+
const totalWidth = visibleColumns.reduce((total, column) => total + (columnWidths[column.id] || DEFAULT_COLUMN_WIDTH), 0);
|
|
85
|
+
return (React.createElement(WidthsContext.Provider, { value: { columnWidths, totalWidth, updateColumn, setCell } }, children));
|
|
132
86
|
}
|
|
133
87
|
export function useColumnWidths() {
|
|
134
88
|
return useContext(WidthsContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-column-widths.js","sourceRoot":"lib/default/","sources":["table/use-column-widths.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACrG,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AASxC,SAAS,UAAU,CACjB,OAAsD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Y,EAAE,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,IACxG,QAAQ,CACc,CAC1B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,CAAC,aAAa,CAAC,CAAC;AACnC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useResizeObserver, useStableCallback } from '@cloudscape-design/component-toolkit/internal';\nimport React, { useEffect, useRef, useState, createContext, useContext } from 'react';\nimport { setElementWidths } from './column-widths-utils';\n\nexport const DEFAULT_COLUMN_WIDTH = 120;\n\nexport interface ColumnWidthDefinition {\n id: PropertyKey;\n minWidth?: string | number;\n maxWidth?: string | number;\n width?: string | number;\n}\n\nfunction readWidths(\n getCell: (columnId: PropertyKey) => null | HTMLElement,\n visibleColumns: readonly ColumnWidthDefinition[]\n) {\n const result: Record<PropertyKey, number> = {};\n for (let index = 0; index < visibleColumns.length; index++) {\n const column = visibleColumns[index];\n let width = (column.width as number) || 0;\n const minWidth = (column.minWidth as number) || width || DEFAULT_COLUMN_WIDTH;\n if (\n !width && // read width from the DOM if it is missing in the config\n index !== visibleColumns.length - 1 // skip reading for the last column, because it expands to fully fit the container\n ) {\n const colEl = getCell(column.id);\n width = colEl?.getBoundingClientRect().width ?? DEFAULT_COLUMN_WIDTH;\n }\n result[column.id] = Math.max(width, minWidth);\n }\n return result;\n}\n\nfunction updateWidths(\n visibleColumns: readonly ColumnWidthDefinition[],\n oldWidths: Record<PropertyKey, number>,\n newWidth: number,\n columnId: PropertyKey\n) {\n const column = visibleColumns.find(column => column.id === columnId);\n const minWidth = typeof column?.minWidth === 'number' ? column.minWidth : DEFAULT_COLUMN_WIDTH;\n newWidth = Math.max(newWidth, minWidth);\n if (oldWidths[columnId] === newWidth) {\n return oldWidths;\n }\n return { ...oldWidths, [columnId]: newWidth };\n}\n\ninterface WidthsContext {\n getColumnStyles(sticky: boolean, columnId: PropertyKey): React.CSSProperties;\n columnWidths: Record<PropertyKey, number>;\n updateColumn: (columnId: PropertyKey, newWidth: number) => void;\n setCell: (sticky: boolean, columnId: PropertyKey, node: null | HTMLElement) => void;\n}\n\nconst WidthsContext = createContext<WidthsContext>({\n getColumnStyles: () => ({}),\n columnWidths: {},\n updateColumn: () => {},\n setCell: () => {},\n});\n\ninterface WidthProviderProps {\n visibleColumns: readonly ColumnWidthDefinition[];\n resizableColumns: boolean | undefined;\n containerRef: React.RefObject<HTMLElement>;\n children: React.ReactNode;\n}\n\nexport function ColumnWidthsProvider({ visibleColumns, resizableColumns, containerRef, children }: WidthProviderProps) {\n const visibleColumnsRef = useRef<PropertyKey[] | null>(null);\n const containerWidthRef = useRef(0);\n const [columnWidths, setColumnWidths] = useState<null | Record<PropertyKey, number>>(null);\n\n const cellsRef = useRef<Record<PropertyKey, HTMLElement>>({});\n const stickyCellsRef = useRef<Record<PropertyKey, HTMLElement>>({});\n const getCell = (columnId: PropertyKey): null | HTMLElement => cellsRef.current[columnId] ?? null;\n const setCell = (sticky: boolean, columnId: PropertyKey, node: null | HTMLElement) => {\n const ref = sticky ? stickyCellsRef : cellsRef;\n if (node) {\n ref.current[columnId] = node;\n } else {\n delete ref.current[columnId];\n }\n };\n\n const getColumnStyles = (sticky: boolean, columnId: PropertyKey): React.CSSProperties => {\n const column = visibleColumns.find(column => column.id === columnId);\n if (!column) {\n return {};\n }\n\n if (sticky) {\n return { width: cellsRef.current[column.id]?.offsetWidth || (columnWidths?.[column.id] ?? column.width) };\n }\n\n if (resizableColumns && columnWidths) {\n const isLastColumn = column.id === visibleColumns[visibleColumns.length - 1]?.id;\n const totalWidth = visibleColumns.reduce((sum, { id }) => sum + (columnWidths[id] || DEFAULT_COLUMN_WIDTH), 0);\n if (isLastColumn && containerWidthRef.current > totalWidth) {\n return { width: 'auto', minWidth: column?.minWidth };\n } else {\n return { width: columnWidths[column.id], minWidth: column?.minWidth };\n }\n }\n return {\n width: column.width,\n minWidth: column.minWidth,\n maxWidth: !resizableColumns ? column.maxWidth : undefined,\n };\n };\n\n // Imperatively sets width style for a cell avoiding React state.\n // This allows setting the style as soon container's size change is observed.\n const updateColumnWidths = useStableCallback(() => {\n for (const column of visibleColumns) {\n setElementWidths(cellsRef.current[column.id], getColumnStyles(false, column.id));\n }\n // Sticky column widths must be synchronized once all real column widths are assigned.\n for (const id of Object.keys(stickyCellsRef.current)) {\n setElementWidths(stickyCellsRef.current[id], getColumnStyles(true, id));\n }\n });\n\n // Observes container size and requests an update to the last cell width as it depends on the container's width.\n useResizeObserver(containerRef, ({ contentBoxWidth: containerWidth }) => {\n containerWidthRef.current = containerWidth;\n updateColumnWidths();\n });\n\n // The widths of the dynamically added columns (after the first render) if not set explicitly\n // will default to the DEFAULT_COLUMN_WIDTH.\n useEffect(() => {\n updateColumnWidths();\n\n if (!resizableColumns) {\n return;\n }\n const updates: Record<PropertyKey, number> = {};\n const lastVisible = visibleColumnsRef.current;\n if (lastVisible) {\n for (let index = 0; index < visibleColumns.length; index++) {\n const column = visibleColumns[index];\n if (!columnWidths?.[column.id] && lastVisible.indexOf(column.id) === -1) {\n updates[column.id] = (column.width as number) || DEFAULT_COLUMN_WIDTH;\n }\n }\n if (Object.keys(updates).length > 0) {\n setColumnWidths(columnWidths => ({ ...columnWidths, ...updates }));\n }\n }\n visibleColumnsRef.current = visibleColumns.map(column => column.id);\n }, [columnWidths, resizableColumns, visibleColumns, updateColumnWidths]);\n\n // Read the actual column widths after the first render to employ the browser defaults for\n // those columns without explicit width.\n useEffect(() => {\n if (!resizableColumns) {\n return;\n }\n setColumnWidths(() => readWidths(getCell, visibleColumns));\n // This code is intended to run only at the first render and should not re-run when table props change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n function updateColumn(columnId: PropertyKey, newWidth: number) {\n setColumnWidths(columnWidths => updateWidths(visibleColumns, columnWidths ?? {}, newWidth, columnId));\n }\n\n return (\n <WidthsContext.Provider value={{ getColumnStyles, columnWidths: columnWidths ?? {}, updateColumn, setCell }}>\n {children}\n </WidthsContext.Provider>\n );\n}\n\nexport function useColumnWidths() {\n return useContext(WidthsContext);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-column-widths.js","sourceRoot":"lib/default/","sources":["table/use-column-widths.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEtF,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAQxC,SAAS,UAAU,CACjB,OAAsD,EACtD,cAAgD;;IAEhD,MAAM,MAAM,GAAgC,EAAE,CAAC;IAC/C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAC1D,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,KAAK,GAAI,MAAM,CAAC,KAAgB,IAAI,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAI,MAAM,CAAC,QAAmB,IAAI,KAAK,IAAI,oBAAoB,CAAC;QAC9E,IACE,CAAC,KAAK,IAAI,yDAAyD;YACnE,KAAK,KAAK,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,kFAAkF;UACtH;YACA,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACjC,KAAK,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,qBAAqB,GAAG,KAAK,mCAAI,oBAAoB,CAAC;SACtE;QACD,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;KAC/C;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CACnB,c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E;YACrB,OAAO;SACR;QACD,eAAe,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;QAC3D,sGAAsG;QACtG,uDAAuD;IACzD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,YAAY,CAAC,QAAqB,EAAE,QAAgB;QAC3D,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAClG,CAAC;IAED,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,CACtC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,oBAAoB,CAAC,EAC5E,CAAC,CACF,CAAC;IAEF,OAAO,CACL,oBAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,IAC/E,QAAQ,CACc,CAC1B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,CAAC,aAAa,CAAC,CAAC;AACnC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState, createContext, useContext } from 'react';\n\nexport const DEFAULT_COLUMN_WIDTH = 120;\n\nexport interface ColumnWidthDefinition {\n id: PropertyKey;\n minWidth?: string | number;\n width?: string | number;\n}\n\nfunction readWidths(\n getCell: (columnId: PropertyKey) => null | HTMLElement,\n visibleColumns: readonly ColumnWidthDefinition[]\n) {\n const result: Record<PropertyKey, number> = {};\n for (let index = 0; index < visibleColumns.length; index++) {\n const column = visibleColumns[index];\n let width = (column.width as number) || 0;\n const minWidth = (column.minWidth as number) || width || DEFAULT_COLUMN_WIDTH;\n if (\n !width && // read width from the DOM if it is missing in the config\n index !== visibleColumns.length - 1 // skip reading for the last column, because it expands to fully fit the container\n ) {\n const colEl = getCell(column.id);\n width = colEl?.getBoundingClientRect().width ?? DEFAULT_COLUMN_WIDTH;\n }\n result[column.id] = Math.max(width, minWidth);\n }\n return result;\n}\n\nfunction updateWidths(\n visibleColumns: readonly ColumnWidthDefinition[],\n oldWidths: Record<PropertyKey, number>,\n newWidth: number,\n columnId: PropertyKey\n) {\n const column = visibleColumns.find(column => column.id === columnId);\n const minWidth = typeof column?.minWidth === 'number' ? column.minWidth : DEFAULT_COLUMN_WIDTH;\n newWidth = Math.max(newWidth, minWidth);\n if (oldWidths[columnId] === newWidth) {\n return oldWidths;\n }\n return { ...oldWidths, [columnId]: newWidth };\n}\n\ninterface WidthsContext {\n totalWidth: number;\n columnWidths: Record<PropertyKey, number>;\n updateColumn: (columnId: PropertyKey, newWidth: number) => void;\n setCell: (columnId: PropertyKey, node: null | HTMLElement) => void;\n}\n\nconst WidthsContext = createContext<WidthsContext>({\n totalWidth: 0,\n columnWidths: {},\n updateColumn: () => {},\n setCell: () => {},\n});\n\ninterface WidthProviderProps {\n visibleColumns: readonly ColumnWidthDefinition[];\n resizableColumns: boolean | undefined;\n children: React.ReactNode;\n}\n\nexport function ColumnWidthsProvider({ visibleColumns, resizableColumns, children }: WidthProviderProps) {\n const visibleColumnsRef = useRef<(PropertyKey | undefined)[] | null>(null);\n const [columnWidths, setColumnWidths] = useState<Record<PropertyKey, number>>({});\n\n const cellsRef = useRef<Record<PropertyKey, HTMLElement>>({});\n const getCell = (columnId: PropertyKey): null | HTMLElement => cellsRef.current[columnId] ?? null;\n const setCell = (columnId: PropertyKey, node: null | HTMLElement) => {\n if (node) {\n cellsRef.current[columnId] = node;\n } else {\n delete cellsRef.current[columnId];\n }\n };\n\n // The widths of the dynamically added columns (after the first render) if not set explicitly\n // will default to the DEFAULT_COLUMN_WIDTH.\n useEffect(() => {\n if (!resizableColumns) {\n return;\n }\n const updates: Record<PropertyKey, number> = {};\n const lastVisible = visibleColumnsRef.current;\n if (lastVisible) {\n for (let index = 0; index < visibleColumns.length; index++) {\n const column = visibleColumns[index];\n if (!columnWidths[column.id] && lastVisible.indexOf(column.id) === -1) {\n updates[column.id] = (column.width as number) || DEFAULT_COLUMN_WIDTH;\n }\n }\n if (Object.keys(updates).length > 0) {\n setColumnWidths(columnWidths => ({ ...columnWidths, ...updates }));\n }\n }\n visibleColumnsRef.current = visibleColumns.map(column => column.id);\n }, [columnWidths, resizableColumns, visibleColumns]);\n\n // Read the actual column widths after the first render to employ the browser defaults for\n // those columns without explicit width.\n useEffect(() => {\n if (!resizableColumns) {\n return;\n }\n setColumnWidths(() => readWidths(getCell, visibleColumns));\n // This code is intended to run only at the first render and should not re-run when table props change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n function updateColumn(columnId: PropertyKey, newWidth: number) {\n setColumnWidths(columnWidths => updateWidths(visibleColumns, columnWidths, newWidth, columnId));\n }\n\n const totalWidth = visibleColumns.reduce(\n (total, column) => total + (columnWidths[column.id] || DEFAULT_COLUMN_WIDTH),\n 0\n );\n\n return (\n <WidthsContext.Provider value={{ columnWidths, totalWidth, updateColumn, setCell }}>\n {children}\n </WidthsContext.Provider>\n );\n}\n\nexport function useColumnWidths() {\n return useContext(WidthsContext);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-sticky-header.d.ts","sourceRoot":"lib/default/","sources":["table/use-sticky-header.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,SAAS,EAAe,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"use-sticky-header.d.ts","sourceRoot":"lib/default/","sources":["table/use-sticky-header.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,SAAS,EAAe,MAAM,OAAO,CAAC;AAkBhE,eAAO,MAAM,eAAe,aAChB,UAAU,WAAW,CAAC,YACtB,UAAU,WAAW,CAAC,qBACb,UAAU,WAAW,CAAC,qBACtB,UAAU,WAAW,CAAC,mBACxB,UAAU,WAAW,CAAC;4BAmCR,WAAW,GAAG,IAAI;;CAMlD,CAAC"}
|
|
@@ -4,6 +4,18 @@ import { useLayoutEffect, useCallback } from 'react';
|
|
|
4
4
|
import stickyScrolling, { calculateScrollingOffset, scrollUpBy } from './sticky-scrolling';
|
|
5
5
|
import { useMobile } from '../internal/hooks/use-mobile';
|
|
6
6
|
import { useResizeObserver } from '@cloudscape-design/component-toolkit/internal';
|
|
7
|
+
function syncSizes(from, to) {
|
|
8
|
+
const fromCells = Array.prototype.slice.apply(from.children);
|
|
9
|
+
const toCells = Array.prototype.slice.apply(to.children);
|
|
10
|
+
for (let i = 0; i < fromCells.length; i++) {
|
|
11
|
+
let width = fromCells[i].style.width;
|
|
12
|
+
// use auto if it is set by resizable columns or real size otherwise
|
|
13
|
+
if (width !== 'auto') {
|
|
14
|
+
width = `${fromCells[i].offsetWidth}px`;
|
|
15
|
+
}
|
|
16
|
+
toCells[i].style.width = width;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
7
19
|
export const useStickyHeader = (tableRef, theadRef, secondaryTheadRef, secondaryTableRef, tableWrapperRef) => {
|
|
8
20
|
const isMobile = useMobile();
|
|
9
21
|
// Sync the sizes of the column header copies in the sticky header with the originals
|
|
@@ -13,6 +25,7 @@ export const useStickyHeader = (tableRef, theadRef, secondaryTheadRef, secondary
|
|
|
13
25
|
secondaryTheadRef.current &&
|
|
14
26
|
secondaryTableRef.current &&
|
|
15
27
|
tableWrapperRef.current) {
|
|
28
|
+
syncSizes(theadRef.current, secondaryTheadRef.current);
|
|
16
29
|
// Using the tableRef offsetWidth instead of the theadRef because in VR
|
|
17
30
|
// the tableRef adds extra padding to the table and by default the theadRef will have a width
|
|
18
31
|
// without the padding and will make the sticky header width incorrect.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-sticky-header.js","sourceRoot":"lib/default/","sources":["table/use-sticky-header.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCA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e,CAAC,OAAO,EAAE;YACzF,MAAM,UAAU,GAAG,wBAAwB,CAAC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;YACzF,IAAI,UAAU,GAAG,CAAC,EAAE;gBAClB,UAAU,CAAC,UAAU,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;aACjD;SACF;IACH,CAAC,CAAC;IACF,MAAM,EAAE,YAAY,EAAE,GAAG,eAAe,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;IAC7E,MAAM,WAAW,GAAG,CAAC,QAA4B,EAAE,EAAE;QACnD,IAAI,CAAC,QAAQ,EAAE;YACb,YAAY,CAAC,QAAQ,CAAC,CAAC;SACxB;IACH,CAAC,CAAC;IACF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AACtC,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useLayoutEffect, RefObject, useCallback } from 'react';\nimport stickyScrolling, { calculateScrollingOffset, scrollUpBy } from './sticky-scrolling';\nimport { useMobile } from '../internal/hooks/use-mobile';\nimport { useResizeObserver } from '@cloudscape-design/component-toolkit/internal';\n\nexport const useStickyHeader = (\n tableRef: RefObject<HTMLElement>,\n theadRef: RefObject<HTMLElement>,\n secondaryTheadRef: RefObject<HTMLElement>,\n secondaryTableRef: RefObject<HTMLElement>,\n tableWrapperRef: RefObject<HTMLElement>\n) => {\n const isMobile = useMobile();\n // Sync the sizes of the column header copies in the sticky header with the originals\n const syncColumnHeaderWidths = useCallback(() => {\n if (\n tableRef.current &&\n theadRef.current &&\n secondaryTheadRef.current &&\n secondaryTableRef.current &&\n tableWrapperRef.current\n ) {\n // Using the tableRef offsetWidth instead of the theadRef because in VR\n // the tableRef adds extra padding to the table and by default the theadRef will have a width\n // without the padding and will make the sticky header width incorrect.\n secondaryTableRef.current.style.width = `${tableRef.current.offsetWidth}px`;\n\n tableWrapperRef.current.style.marginTop = `-${theadRef.current.offsetHeight}px`;\n }\n }, [theadRef, secondaryTheadRef, secondaryTableRef, tableWrapperRef, tableRef]);\n useLayoutEffect(() => {\n syncColumnHeaderWidths();\n });\n useResizeObserver(theadRef, syncColumnHeaderWidths);\n const scrollToTop = () => {\n if (!isMobile && theadRef.current && secondaryTheadRef.current && tableWrapperRef.current) {\n const scrollDist = calculateScrollingOffset(theadRef.current, secondaryTheadRef.current);\n if (scrollDist > 0) {\n scrollUpBy(scrollDist, tableWrapperRef.current);\n }\n }\n };\n const { scrollToItem } = stickyScrolling(tableWrapperRef, secondaryTheadRef);\n const scrollToRow = (itemNode: HTMLElement | null) => {\n if (!isMobile) {\n scrollToItem(itemNode);\n }\n };\n return { scrollToRow, scrollToTop };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"use-sticky-header.js","sourceRoot":"lib/default/","sources":["table/use-sticky-header.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,eAAe,EAAa,WAAW,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,eAAe,EAAE,EAAE,wBAAwB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAElF,SAAS,SAAS,CAAC,IAAiB,EAAE,EAAe;IACnD,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;IACzD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACzC,IAAI,KAAK,GAAG,SAAS,CAAC,CAA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vB,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,OAAO,IAAI,iBAAiB,CAAC,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE;YACzF,MAAM,UAAU,GAAG,wBAAwB,CAAC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;YACzF,IAAI,UAAU,GAAG,CAAC,EAAE;gBAClB,UAAU,CAAC,UAAU,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;aACjD;SACF;IACH,CAAC,CAAC;IACF,MAAM,EAAE,YAAY,EAAE,GAAG,eAAe,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;IAC7E,MAAM,WAAW,GAAG,CAAC,QAA4B,EAAE,EAAE;QACnD,IAAI,CAAC,QAAQ,EAAE;YACb,YAAY,CAAC,QAAQ,CAAC,CAAC;SACxB;IACH,CAAC,CAAC;IACF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AACtC,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useLayoutEffect, RefObject, useCallback } from 'react';\nimport stickyScrolling, { calculateScrollingOffset, scrollUpBy } from './sticky-scrolling';\nimport { useMobile } from '../internal/hooks/use-mobile';\nimport { useResizeObserver } from '@cloudscape-design/component-toolkit/internal';\n\nfunction syncSizes(from: HTMLElement, to: HTMLElement) {\n const fromCells = Array.prototype.slice.apply(from.children);\n const toCells = Array.prototype.slice.apply(to.children);\n for (let i = 0; i < fromCells.length; i++) {\n let width = fromCells[i].style.width;\n // use auto if it is set by resizable columns or real size otherwise\n if (width !== 'auto') {\n width = `${fromCells[i].offsetWidth}px`;\n }\n toCells[i].style.width = width;\n }\n}\n\nexport const useStickyHeader = (\n tableRef: RefObject<HTMLElement>,\n theadRef: RefObject<HTMLElement>,\n secondaryTheadRef: RefObject<HTMLElement>,\n secondaryTableRef: RefObject<HTMLElement>,\n tableWrapperRef: RefObject<HTMLElement>\n) => {\n const isMobile = useMobile();\n // Sync the sizes of the column header copies in the sticky header with the originals\n const syncColumnHeaderWidths = useCallback(() => {\n if (\n tableRef.current &&\n theadRef.current &&\n secondaryTheadRef.current &&\n secondaryTableRef.current &&\n tableWrapperRef.current\n ) {\n syncSizes(theadRef.current, secondaryTheadRef.current);\n\n // Using the tableRef offsetWidth instead of the theadRef because in VR\n // the tableRef adds extra padding to the table and by default the theadRef will have a width\n // without the padding and will make the sticky header width incorrect.\n secondaryTableRef.current.style.width = `${tableRef.current.offsetWidth}px`;\n\n tableWrapperRef.current.style.marginTop = `-${theadRef.current.offsetHeight}px`;\n }\n }, [theadRef, secondaryTheadRef, secondaryTableRef, tableWrapperRef, tableRef]);\n useLayoutEffect(() => {\n syncColumnHeaderWidths();\n });\n useResizeObserver(theadRef, syncColumnHeaderWidths);\n const scrollToTop = () => {\n if (!isMobile && theadRef.current && secondaryTheadRef.current && tableWrapperRef.current) {\n const scrollDist = calculateScrollingOffset(theadRef.current, secondaryTheadRef.current);\n if (scrollDist > 0) {\n scrollUpBy(scrollDist, tableWrapperRef.current);\n }\n }\n };\n const { scrollToItem } = stickyScrolling(tableWrapperRef, secondaryTheadRef);\n const scrollToRow = (itemNode: HTMLElement | null) => {\n if (!isMobile) {\n scrollToItem(itemNode);\n }\n };\n return { scrollToRow, scrollToTop };\n};\n"]}
|