Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { assertI18nLabel, type DataTableModel, type DataTableVM } from "@toolctrl/view-models";
|
||||
import { renderDataTable } from "@toolctrl/ui-subframe";
|
||||
|
||||
import { defineAdapter } from "./defineAdapter.js";
|
||||
|
||||
const DEFAULT_EMPTY_LABEL_KEY = "ui.data-table.empty";
|
||||
|
||||
/**
|
||||
* Normalizes a domain {@link DataTableVM} into the {@link DataTableModel}
|
||||
* prop-model the UI implementation renders. Validates every i18n key
|
||||
* (columns + caption) and fills in defaults (column align, empty label,
|
||||
* row count) so render implementations stay dumb.
|
||||
*/
|
||||
export function toDataTableModel(vm: DataTableVM): DataTableModel {
|
||||
const columns = vm.columns.map((column) => {
|
||||
assertI18nLabel(column);
|
||||
return {
|
||||
key: column.key,
|
||||
labelKey: column.labelKey,
|
||||
align: column.align ?? "left",
|
||||
};
|
||||
});
|
||||
|
||||
const captionKey = vm.caption ? assertI18nLabel(vm.caption).labelKey : undefined;
|
||||
|
||||
return {
|
||||
captionKey,
|
||||
columns,
|
||||
rows: vm.rows,
|
||||
emptyLabelKey: vm.emptyLabelKey ?? DEFAULT_EMPTY_LABEL_KEY,
|
||||
rowCount: vm.rows.length,
|
||||
};
|
||||
}
|
||||
|
||||
export const dataTableAdapter = defineAdapter({
|
||||
name: "dataTable",
|
||||
toProps: toDataTableModel,
|
||||
defaultRenderer: renderDataTable,
|
||||
});
|
||||
Reference in new issue
Block a user