Update sigpro-ui.js

This commit is contained in:
Natxo
2026-03-28 19:08:59 +01:00
committed by GitHub
parent 5a502a7461
commit 2123ef2a0d

View File

@@ -624,55 +624,43 @@ export const Grid = (props) => {
const { data, options, class: className } = props; const { data, options, class: className } = props;
let gridApi = null; let gridApi = null;
const container = $html("div", { return $html("div", {
style: "height: 100%; width: 100%;", style: "height: 100%; width: 100%;",
class: className, class: className,
}); ref: async (container) => {
const { createGrid } = await import("./grid/grid.js");
const observer = new MutationObserver(() => { const initialData = typeof data === "function" ? data() : data;
if (gridApi) gridApi.setGridOption("theme", getTheme(isDark())); const gridOptions = {
}); ...(typeof options === "function" ? options() : options),
theme: getTheme(isDark()),
rowData: initialData || [],
};
observer.observe(document.documentElement, { gridApi = createGrid(container, gridOptions);
attributes: true,
attributeFilter: ["data-theme"],
});
container._cleanups.add(() => observer.disconnect()); const stopData = $watch(() => {
const rowData = typeof data === "function" ? data() : data;
const stopGrid = $watch(() => { if (gridApi && Array.isArray(rowData)) {
const dark = isDark(); gridApi.setGridOption("rowData", rowData);
const agTheme = getTheme(dark); }
const rowData = val(data) || []; });
if (!gridApi) { const stopTheme = $watch(() => {
gridApi = createGrid(container, { const dark = isDark();
...(val(options) || {}), if (gridApi) gridApi.setGridOption("theme", getTheme(dark));
theme: agTheme, });
rowData: rowData,
container._cleanups.add(stopData);
container._cleanups.add(stopTheme);
container._cleanups.add(() => {
if (gridApi) {
gridApi.destroy();
gridApi = null;
}
}); });
} else {
gridApi.setGridOption("theme", agTheme);
} }
}); });
container._cleanups.add(stopGrid);
const stopData = $watch(() => {
const rowData = val(data);
if (gridApi && Array.isArray(rowData)) {
gridApi.setGridOption("rowData", rowData);
}
});
container._cleanups.add(stopData);
container._cleanups.add(() => {
if (gridApi) {
gridApi.destroy();
gridApi = null;
}
});
return container;
}; };
/** DROPDOWN */ /** DROPDOWN */