athena-ui-js 2.2.0 → 2.4.0

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.
@@ -1,123 +1,123 @@
1
- /**
2
- * Generates a table (optional filter box, sortable headers, pagination, row selection, inline
3
- * editing, resizable columns, virtual scrolling, CSV export) and appends it to its parent.
4
- *
5
- * @param {object} options
6
- * @param {string|Element} [options.parent] id or element, defaults to "wrapper"
7
- * @param {string} [options.id] id of the table wrapper (default: "table")
8
- * @param {string} [options.class] extra CSS class of the table
9
- * @param {string} [options.caption]
10
- * @param {{key: string, label?: string, width?: number, sortable?: boolean, editable?: boolean, format?: (value, row) => string}[]} options.columns
11
- * @param {object[]} [options.rows] row objects, read by column key
12
- * @param {boolean} [options.sortable=true] click on a header sorts by it
13
- * @param {boolean} [options.filter=false] show a text filter above the table
14
- * @param {number} [options.pageSize=0] rows per page, 0 disables pagination
15
- * @param {boolean} [options.selectable=false] checkbox column; the header checkbox selects every filtered row
16
- * @param {boolean} [options.resizableColumns=false] drag the edge of a header (or use the arrow keys on it) to resize;
17
- * double click resets the width
18
- * @param {{height?: number, rowHeight?: number, overscan?: number}|boolean} [options.virtual] render only the rows
19
- * in view, for lists of thousands of rows. Rows have a fixed height (default 36 px) and the table scrolls
20
- * inside `height` (default 400 px). Replaces pagination.
21
- * @param {(key: string, width: number) => void} [options.onColumnResize]
22
- * @param {(rows: object[]) => void} [options.onSelectionChange]
23
- * @param {(row: object, key: string, value, oldValue) => (boolean|void)} [options.onEdit] called after an edit
24
- * of an `editable` column (double click, or Enter / F2 on the focused cell). Return false to reject it.
25
- * @param {(row: object) => void} [options.onRowClick]
26
- * @param {string} [options.emptyText]
27
- * @param {(row: object, column: object) => (string|string[]|null|undefined)} [options.cellClass] CSS class(es) for a cell
28
- * @param {(row: object) => (string|string[]|null|undefined)} [options.rowClass] CSS class(es) for a row
29
- * @param {boolean} [options.focusableRows=false] rows are reachable with Tab and, with `onRowClick`, opened with Enter and Space
30
- * @param {(row: object) => string} [options.rowLabel] aria-label of a focusable row
31
- * @param {"normal"|"compact"} [options.density="normal"]
32
- * @param {boolean} [options.wrap] true lets long text wrap, false keeps one line with an ellipsis (default: wrap, except in virtual tables)
33
- * @param {(query: {page: number, pageSize: number, cursor: *, sort: ({key: string, descending: boolean}|null), filter: string}) =>
34
- * Promise<{rows: object[], total?: number, nextCursor?: *}>} [options.dataSource] load the rows from a server instead of
35
- * keeping them all in the browser. Sorting, the filter box and the pager call it again. Answer with `total` for numbered pages
36
- * (`page` is 0-based), or with `nextCursor` for a "Load more" button (`cursor` is what the last answer gave, undefined for the
37
- * first request; the rows are appended). A failed request shows the error with a Retry button.
38
- * Together with `virtual` the list scrolls like one of `total` rows (every answer must carry `total`): the rows in view are asked for
39
- * in chunks of `chunkSize` (`page` is the chunk number), rows that have not arrived yet show a placeholder, and sorting or the filter
40
- * start again from the top.
41
- * @param {number} [options.chunkSize=50] rows per request of a data source with `virtual`
42
- * @param {boolean} [options.animateRows=false] rows slide to their new place when the table is sorted, filtered or changes page, and new rows fade in
43
- * (at most 60 rows are animated, none under reduced motion, none in a virtual table)
44
- * @param {number} [options.filterDelay=300] ms to wait after typing before the data source is asked
45
- * @param {{label: string, onclick: (row: object) => void, danger?: boolean, hidden?: (row: object) => boolean, ariaLabel?: (row: object) => string}[]} [options.rowActions]
46
- * a column of buttons at the end of every row
47
- * Column extras: `render(row, value)` returns text or a Node (built by the caller, so safe by construction), `align`
48
- * ("left" | "center" | "right"), `title` (false switches the tooltip with the full text off).
49
- * @returns {{element: HTMLElement, update: Function, destroy: Function, setRows: Function, getSelected: () => object[], clearSelection: Function,
50
- * getColumnWidths: () => Object<string, number>, toCsv: () => string, exportCsv: (filename?: string) => void}}
51
- */
52
- export function generateTable(options?: {
53
- parent?: string | Element;
54
- id?: string;
55
- class?: string;
56
- caption?: string;
57
- columns: {
58
- key: string;
59
- label?: string;
60
- width?: number;
61
- sortable?: boolean;
62
- editable?: boolean;
63
- format?: (value: any, row: any) => string;
64
- }[];
65
- rows?: object[];
66
- sortable?: boolean;
67
- filter?: boolean;
68
- pageSize?: number;
69
- selectable?: boolean;
70
- resizableColumns?: boolean;
71
- virtual?: {
72
- height?: number;
73
- rowHeight?: number;
74
- overscan?: number;
75
- } | boolean;
76
- onColumnResize?: (key: string, width: number) => void;
77
- onSelectionChange?: (rows: object[]) => void;
78
- onEdit?: (row: object, key: string, value: any, oldValue: any) => (boolean | void);
79
- onRowClick?: (row: object) => void;
80
- emptyText?: string;
81
- cellClass?: (row: object, column: object) => (string | string[] | null | undefined);
82
- rowClass?: (row: object) => (string | string[] | null | undefined);
83
- focusableRows?: boolean;
84
- rowLabel?: (row: object) => string;
85
- density?: "normal" | "compact";
86
- wrap?: boolean;
87
- dataSource?: (query: {
88
- page: number;
89
- pageSize: number;
90
- cursor: any;
91
- sort: ({
92
- key: string;
93
- descending: boolean;
94
- } | null);
95
- filter: string;
96
- }) => Promise<{
97
- rows: object[];
98
- total?: number;
99
- nextCursor?: any;
100
- }>;
101
- chunkSize?: number;
102
- animateRows?: boolean;
103
- filterDelay?: number;
104
- rowActions?: {
105
- label: string;
106
- onclick: (row: object) => void;
107
- danger?: boolean;
108
- hidden?: (row: object) => boolean;
109
- ariaLabel?: (row: object) => string;
110
- }[];
111
- }): {
112
- element: HTMLElement;
113
- update: Function;
114
- destroy: Function;
115
- setRows: Function;
116
- getSelected: () => object[];
117
- clearSelection: Function;
118
- getColumnWidths: () => {
119
- [x: string]: number;
120
- };
121
- toCsv: () => string;
122
- exportCsv: (filename?: string) => void;
123
- };
1
+ /**
2
+ * Generates a table (optional filter box, sortable headers, pagination, row selection, inline
3
+ * editing, resizable columns, virtual scrolling, CSV export) and appends it to its parent.
4
+ *
5
+ * @param {object} options
6
+ * @param {string|Element} [options.parent] id or element, defaults to "wrapper"
7
+ * @param {string} [options.id] id of the table wrapper (default: "table")
8
+ * @param {string} [options.class] extra CSS class of the table
9
+ * @param {string} [options.caption]
10
+ * @param {{key: string, label?: string, width?: number, sortable?: boolean, editable?: boolean, format?: (value, row) => string}[]} options.columns
11
+ * @param {object[]} [options.rows] row objects, read by column key
12
+ * @param {boolean} [options.sortable=true] click on a header sorts by it
13
+ * @param {boolean} [options.filter=false] show a text filter above the table
14
+ * @param {number} [options.pageSize=0] rows per page, 0 disables pagination
15
+ * @param {boolean} [options.selectable=false] checkbox column; the header checkbox selects every filtered row
16
+ * @param {boolean} [options.resizableColumns=false] drag the edge of a header (or use the arrow keys on it) to resize;
17
+ * double click resets the width
18
+ * @param {{height?: number, rowHeight?: number, overscan?: number}|boolean} [options.virtual] render only the rows
19
+ * in view, for lists of thousands of rows. Rows have a fixed height (default 36 px) and the table scrolls
20
+ * inside `height` (default 400 px). Replaces pagination.
21
+ * @param {(key: string, width: number) => void} [options.onColumnResize]
22
+ * @param {(rows: object[]) => void} [options.onSelectionChange]
23
+ * @param {(row: object, key: string, value, oldValue) => (boolean|void)} [options.onEdit] called after an edit
24
+ * of an `editable` column (double click, or Enter / F2 on the focused cell). Return false to reject it.
25
+ * @param {(row: object) => void} [options.onRowClick]
26
+ * @param {string} [options.emptyText]
27
+ * @param {(row: object, column: object) => (string|string[]|null|undefined)} [options.cellClass] CSS class(es) for a cell
28
+ * @param {(row: object) => (string|string[]|null|undefined)} [options.rowClass] CSS class(es) for a row
29
+ * @param {boolean} [options.focusableRows=false] rows are reachable with Tab and, with `onRowClick`, opened with Enter and Space
30
+ * @param {(row: object) => string} [options.rowLabel] aria-label of a focusable row
31
+ * @param {"normal"|"compact"} [options.density="normal"]
32
+ * @param {boolean} [options.wrap] true lets long text wrap, false keeps one line with an ellipsis (default: wrap, except in virtual tables)
33
+ * @param {(query: {page: number, pageSize: number, cursor: *, sort: ({key: string, descending: boolean}|null), filter: string}) =>
34
+ * Promise<{rows: object[], total?: number, nextCursor?: *}>} [options.dataSource] load the rows from a server instead of
35
+ * keeping them all in the browser. Sorting, the filter box and the pager call it again. Answer with `total` for numbered pages
36
+ * (`page` is 0-based), or with `nextCursor` for a "Load more" button (`cursor` is what the last answer gave, undefined for the
37
+ * first request; the rows are appended). A failed request shows the error with a Retry button.
38
+ * Together with `virtual` the list scrolls like one of `total` rows (every answer must carry `total`): the rows in view are asked for
39
+ * in chunks of `chunkSize` (`page` is the chunk number), rows that have not arrived yet show a placeholder, and sorting or the filter
40
+ * start again from the top.
41
+ * @param {number} [options.chunkSize=50] rows per request of a data source with `virtual`
42
+ * @param {boolean} [options.animateRows=false] rows slide to their new place when the table is sorted, filtered or changes page, and new rows fade in
43
+ * (at most 60 rows are animated, none under reduced motion, none in a virtual table)
44
+ * @param {number} [options.filterDelay=300] ms to wait after typing before the data source is asked
45
+ * @param {{label: string, onclick: (row: object) => void, danger?: boolean, hidden?: (row: object) => boolean, ariaLabel?: (row: object) => string}[]} [options.rowActions]
46
+ * a column of buttons at the end of every row
47
+ * Column extras: `render(row, value)` returns text or a Node (built by the caller, so safe by construction), `align`
48
+ * ("left" | "center" | "right"), `title` (false switches the tooltip with the full text off).
49
+ * @returns {{element: HTMLElement, update: Function, destroy: Function, setRows: Function, getSelected: () => object[], clearSelection: Function,
50
+ * getColumnWidths: () => Object<string, number>, toCsv: () => string, exportCsv: (filename?: string) => void}}
51
+ */
52
+ export function generateTable(options?: {
53
+ parent?: string | Element;
54
+ id?: string;
55
+ class?: string;
56
+ caption?: string;
57
+ columns: {
58
+ key: string;
59
+ label?: string;
60
+ width?: number;
61
+ sortable?: boolean;
62
+ editable?: boolean;
63
+ format?: (value: any, row: any) => string;
64
+ }[];
65
+ rows?: object[];
66
+ sortable?: boolean;
67
+ filter?: boolean;
68
+ pageSize?: number;
69
+ selectable?: boolean;
70
+ resizableColumns?: boolean;
71
+ virtual?: {
72
+ height?: number;
73
+ rowHeight?: number;
74
+ overscan?: number;
75
+ } | boolean;
76
+ onColumnResize?: (key: string, width: number) => void;
77
+ onSelectionChange?: (rows: object[]) => void;
78
+ onEdit?: (row: object, key: string, value: any, oldValue: any) => (boolean | void);
79
+ onRowClick?: (row: object) => void;
80
+ emptyText?: string;
81
+ cellClass?: (row: object, column: object) => (string | string[] | null | undefined);
82
+ rowClass?: (row: object) => (string | string[] | null | undefined);
83
+ focusableRows?: boolean;
84
+ rowLabel?: (row: object) => string;
85
+ density?: "normal" | "compact";
86
+ wrap?: boolean;
87
+ dataSource?: (query: {
88
+ page: number;
89
+ pageSize: number;
90
+ cursor: any;
91
+ sort: ({
92
+ key: string;
93
+ descending: boolean;
94
+ } | null);
95
+ filter: string;
96
+ }) => Promise<{
97
+ rows: object[];
98
+ total?: number;
99
+ nextCursor?: any;
100
+ }>;
101
+ chunkSize?: number;
102
+ animateRows?: boolean;
103
+ filterDelay?: number;
104
+ rowActions?: {
105
+ label: string;
106
+ onclick: (row: object) => void;
107
+ danger?: boolean;
108
+ hidden?: (row: object) => boolean;
109
+ ariaLabel?: (row: object) => string;
110
+ }[];
111
+ }): {
112
+ element: HTMLElement;
113
+ update: Function;
114
+ destroy: Function;
115
+ setRows: Function;
116
+ getSelected: () => object[];
117
+ clearSelection: Function;
118
+ getColumnWidths: () => {
119
+ [x: string]: number;
120
+ };
121
+ toCsv: () => string;
122
+ exportCsv: (filename?: string) => void;
123
+ };
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Registers a type of widget, so grids can create it, load it from a saved layout and show its settings.
3
+ *
4
+ * @param {string} type name of the type, for example "stat" (it is saved in layouts)
5
+ * @param {object} definition
6
+ * @param {(context: WidgetContext) => (void|Function|{update?: Function, destroy?: Function})} definition.render builds the widget into `context.element`;
7
+ * it may return a function (called when the widget goes away) or an object with `update(context)` and `destroy(context)`
8
+ * @param {(context: WidgetContext) => void} [definition.update] called (throttled) when the config or the title changed; without it the widget is rendered again
9
+ * @param {(context: WidgetContext, size: {width: number, height: number}) => void} [definition.resize] called (throttled) when the body changes its size
10
+ * @param {(context: WidgetContext) => void} [definition.destroy] called when the widget is removed or the grid is destroyed
11
+ * @param {object[]|((widget: object) => object[])} [definition.configForm] field definitions (see generateField) of the settings dialog; the field `name` is the key in the config
12
+ * @param {object} [definition.defaultConfig] config of a new widget
13
+ * @param {string} [definition.title] title of a new widget
14
+ * @param {{w: number, h: number}} [definition.defaultSize={w: 3, h: 2}] size in grid cells
15
+ * @param {{w?: number, h?: number}} [definition.minSize]
16
+ * @param {{w?: number, h?: number}} [definition.maxSize]
17
+ *
18
+ * @typedef {object} WidgetContext
19
+ * @property {string} id
20
+ * @property {string} type
21
+ * @property {HTMLElement} element the body of the widget: build into it
22
+ * @property {object} config the current config (read it again in update())
23
+ * @property {string} title
24
+ * @property {{width: number, height: number}} size
25
+ * @property {(title: string) => void} setTitle
26
+ */
27
+ export function registerWidget(type: string, definition: {
28
+ render: (context: WidgetContext) => (void | Function | {
29
+ update?: Function;
30
+ destroy?: Function;
31
+ });
32
+ update?: (context: WidgetContext) => void;
33
+ resize?: (context: WidgetContext, size: {
34
+ width: number;
35
+ height: number;
36
+ }) => void;
37
+ destroy?: (context: WidgetContext) => void;
38
+ configForm?: object[] | ((widget: object) => object[]);
39
+ defaultConfig?: object;
40
+ title?: string;
41
+ defaultSize?: {
42
+ w: number;
43
+ h: number;
44
+ };
45
+ minSize?: {
46
+ w?: number;
47
+ h?: number;
48
+ };
49
+ maxSize?: {
50
+ w?: number;
51
+ h?: number;
52
+ };
53
+ }): void;
54
+ /** Forgets a widget type. Widgets of it that are in grids stay and are shown as unknown. */
55
+ export function unregisterWidget(type: any): boolean;
56
+ /** The names of the registered widget types. */
57
+ export function getWidgetTypes(): any[];
58
+ /**
59
+ * A grid of widgets.
60
+ *
61
+ * @param {object} options
62
+ * @param {string|HTMLElement} options.element the container
63
+ * @param {number} [options.columns=12] columns when there are no breakpoints
64
+ * @param {number} [options.rowHeight=80] height of a row in px
65
+ * @param {number} [options.gap=12] gap between widgets in px
66
+ * @param {Record<string, {minWidth?: number, columns: number}>} [options.breakpoints] layouts by the width of the container, for example
67
+ * `{ large: { minWidth: 900, columns: 12 }, small: { minWidth: 0, columns: 4 } }`. A breakpoint without a layout of its own is derived from the widest one.
68
+ * @param {object[]} [options.widgets] first widgets: `{ type, title?, config?, x?, y?, w?, h?, locked?, id? }`
69
+ * @param {object} [options.layout] a saved layout (getLayout()), used instead of `widgets`
70
+ * @param {boolean} [options.editable=false] edit mode: move, resize, settings, duplicate, remove
71
+ * @param {boolean} [options.compact=true] widgets fall upwards when there is room (false: they stay where they are put)
72
+ * @param {boolean} [options.animate=true] widgets slide to their new places (never under reduced motion)
73
+ * @param {string} [options.label] accessible name of the dashboard
74
+ * @param {number} [options.maxWidgets=200]
75
+ * @param {(layout: object, reason: string) => void} [options.onChange] called after a change made by the person or by add/remove/...: "move", "resize", "add", "remove", "duplicate", "settings", "lock", "undo", "redo"
76
+ * @returns the handle: { element, addWidget, removeWidget, duplicateWidget, configureWidget, updateWidget, getWidget, getWidgets, lockWidget, setEditable, isEditable,
77
+ * getLayout, setLayout, undo, redo, canUndo, canRedo, getBreakpoint, destroy }
78
+ */
79
+ export function createWidgetGrid(options?: {
80
+ element: string | HTMLElement;
81
+ columns?: number;
82
+ rowHeight?: number;
83
+ gap?: number;
84
+ breakpoints?: Record<string, {
85
+ minWidth?: number;
86
+ columns: number;
87
+ }>;
88
+ widgets?: object[];
89
+ layout?: object;
90
+ editable?: boolean;
91
+ compact?: boolean;
92
+ animate?: boolean;
93
+ label?: string;
94
+ maxWidgets?: number;
95
+ onChange?: (layout: object, reason: string) => void;
96
+ }): any;
97
+ /**
98
+ * Registers a type of widget, so grids can create it, load it from a saved layout and show its settings.
99
+ */
100
+ export type WidgetContext = {
101
+ id: string;
102
+ type: string;
103
+ /**
104
+ * the body of the widget: build into it
105
+ */
106
+ element: HTMLElement;
107
+ /**
108
+ * the current config (read it again in update())
109
+ */
110
+ config: object;
111
+ title: string;
112
+ size: {
113
+ width: number;
114
+ height: number;
115
+ };
116
+ setTitle: (title: string) => void;
117
+ };
package/types/motion.d.ts CHANGED
@@ -1 +1 @@
1
- export * from "./libs/core/motion.js";
1
+ export * from "./libs/core/motion.js";
@@ -0,0 +1,2 @@
1
+ export * from "./libs/hephaestus/widgetGrid/widgetGrid.js";
2
+ export * from "./libs/core/gridLayout.js";