athena-ui-js 2.4.0 → 2.5.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.
- package/README.md +32 -2
- package/docs/styling.md +1 -1
- package/package.json +4 -1
- package/src/athena-ui.js +1 -1
- package/src/libs/config/config.js +1 -1
- package/src/libs/core/i18n.js +2 -0
- package/src/libs/hephaestus/chartGenerator/chartGenerator.js +70 -28
- package/src/libs/hephaestus/codeGenerator/codeEditor.js +1037 -0
- package/src/libs/hephaestus/codeGenerator/codeGenerator.js +286 -0
- package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +5 -2
- package/src/libs/hephaestus/formGenerator/formBuilder.js +86 -5
- package/src/libs/hephaestus/tableGenerator/tableGenerator.js +5 -1
- package/src/libs/hephaestus/widgetGrid/widgetGrid.js +870 -0
- package/src/res/themes/default/style.css +4 -0
- package/types/athena-ui.d.ts +103 -103
- package/types/code.d.ts +4 -4
- package/types/libs/config/config.d.ts +3 -3
- package/types/libs/core/codeDiff.d.ts +32 -32
- package/types/libs/core/codeLanguages.d.ts +58 -58
- package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +117 -95
- package/types/libs/hephaestus/codeGenerator/codeEditor.d.ts +60 -60
- package/types/libs/hephaestus/codeGenerator/codeGenerator.d.ts +99 -99
- package/types/libs/hephaestus/dialogGenerator/dialogGenerator.d.ts +122 -120
- package/types/libs/hephaestus/formGenerator/authForms.d.ts +130 -122
- package/types/libs/hephaestus/formGenerator/formBuilder.d.ts +128 -113
- package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +129 -123
|
@@ -1,113 +1,128 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a button.
|
|
3
|
-
*
|
|
4
|
-
* @param {object} options
|
|
5
|
-
* @param {string|Element} [options.parent] id or element, defaults to the body
|
|
6
|
-
* @param {string} [options.id]
|
|
7
|
-
* @param {string} [options.text]
|
|
8
|
-
* @param {"primary"|"secondary"|"danger"|"link"} [options.variant="primary"]
|
|
9
|
-
* @param {"button"|"submit"|"reset"} [options.type="button"]
|
|
10
|
-
* @param {"small"|"large"} [options.size]
|
|
11
|
-
* @param {boolean} [options.disabled]
|
|
12
|
-
* @param {boolean} [options.loading] shows a spinner and blocks clicks
|
|
13
|
-
* @param {(event: Event) => void} [options.onclick]
|
|
14
|
-
* @returns {{element: HTMLButtonElement, setLoading: Function, setDisabled: Function, setText: Function}}
|
|
15
|
-
*/
|
|
16
|
-
export function generateButton(options?: {
|
|
17
|
-
parent?: string | Element;
|
|
18
|
-
id?: string;
|
|
19
|
-
text?: string;
|
|
20
|
-
variant?: "primary" | "secondary" | "danger" | "link";
|
|
21
|
-
type?: "button" | "submit" | "reset";
|
|
22
|
-
size?: "small" | "large";
|
|
23
|
-
disabled?: boolean;
|
|
24
|
-
loading?: boolean;
|
|
25
|
-
onclick?: (event: Event) => void;
|
|
26
|
-
}): {
|
|
27
|
-
element: HTMLButtonElement;
|
|
28
|
-
setLoading: Function;
|
|
29
|
-
setDisabled: Function;
|
|
30
|
-
setText: Function;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Generates one labelled form field with help text and an error line.
|
|
34
|
-
*
|
|
35
|
-
* @param {object} options
|
|
36
|
-
* @param {string} options.name key of the field in the form values
|
|
37
|
-
* @param {"text"|"password"|"email"|"number"|"date"|"datetime-local"|"time"|"url"|"tel"|"search"|"color"|"range"|"file"|"hidden"|"textarea"|"select"|"checkbox"|"switch"|"radio"|"checkboxes"|"autocomplete"|"multiselect"|"daterange"|"richtext"|"wysiwyg"} [options.type="text"]
|
|
38
|
-
* @param {string} [options.label]
|
|
39
|
-
* @param {string} [options.help] help text under the control
|
|
40
|
-
* @param {*} [options.value] initial value (boolean for checkbox / switch, array for checkboxes / multiple select)
|
|
41
|
-
* @param {(string|{value: string, text?: string, disabled?: boolean})[]} [options.options] choices of select / radio / checkboxes
|
|
42
|
-
* @param {boolean} [options.multiple] select / file: allow several values
|
|
43
|
-
* @param {string} [options.placeholder]
|
|
44
|
-
* @param {number} [options.rows] textarea rows
|
|
45
|
-
* @param {object} [options.rules] validation rules, see validateValue. They can also be given directly
|
|
46
|
-
* (required, email, minLength, ...)
|
|
47
|
-
* @param {(value, field) => void} [options.onChange]
|
|
48
|
-
* @param {() => object} [options.getValues] all form values (set by generateForm, used by `match`)
|
|
49
|
-
* @returns {{element: HTMLElement, name: string, getValue: Function, setValue: Function, validate: Function,
|
|
50
|
-
* setError: Function, focus: Function}}
|
|
51
|
-
*/
|
|
52
|
-
export function generateField(options?: {
|
|
53
|
-
name: string;
|
|
54
|
-
type?: "text" | "password" | "email" | "number" | "date" | "datetime-local" | "time" | "url" | "tel" | "search" | "color" | "range" | "file" | "hidden" | "textarea" | "select" | "checkbox" | "switch" | "radio" | "checkboxes" | "autocomplete" | "multiselect" | "daterange" | "richtext" | "wysiwyg";
|
|
55
|
-
label?: string;
|
|
56
|
-
help?: string;
|
|
57
|
-
value?: any;
|
|
58
|
-
options?: (string | {
|
|
59
|
-
value: string;
|
|
60
|
-
text?: string;
|
|
61
|
-
disabled?: boolean;
|
|
62
|
-
})[];
|
|
63
|
-
multiple?: boolean;
|
|
64
|
-
placeholder?: string;
|
|
65
|
-
rows?: number;
|
|
66
|
-
rules?: object;
|
|
67
|
-
onChange?: (value: any, field: any) => void;
|
|
68
|
-
getValues?: () => object;
|
|
69
|
-
}): {
|
|
70
|
-
element: HTMLElement;
|
|
71
|
-
name: string;
|
|
72
|
-
getValue: Function;
|
|
73
|
-
setValue: Function;
|
|
74
|
-
validate: Function;
|
|
75
|
-
setError: Function;
|
|
76
|
-
focus: Function;
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* Generates a form from a list of field definitions.
|
|
80
|
-
*
|
|
81
|
-
* @param {object} options
|
|
82
|
-
* @param {string|Element} [options.parent]
|
|
83
|
-
* @param {string} [options.id]
|
|
84
|
-
* @param {object[]} options.fields field definitions, see generateField
|
|
85
|
-
* @param {string} [options.submitText]
|
|
86
|
-
* @param {string|false} [options.resetText] adds a reset button when set
|
|
87
|
-
* @param {(values: object, form: object) => (void|Promise)} [options.onSubmit] called with the values when every
|
|
88
|
-
* field is valid. A returned promise keeps the submit button busy; a rejection is shown as form message.
|
|
89
|
-
* @param {(values: object, field: object) => void} [options.onChange]
|
|
90
|
-
* @
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generates a button.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} options
|
|
5
|
+
* @param {string|Element} [options.parent] id or element, defaults to the body
|
|
6
|
+
* @param {string} [options.id]
|
|
7
|
+
* @param {string} [options.text]
|
|
8
|
+
* @param {"primary"|"secondary"|"danger"|"link"} [options.variant="primary"]
|
|
9
|
+
* @param {"button"|"submit"|"reset"} [options.type="button"]
|
|
10
|
+
* @param {"small"|"large"} [options.size]
|
|
11
|
+
* @param {boolean} [options.disabled]
|
|
12
|
+
* @param {boolean} [options.loading] shows a spinner and blocks clicks
|
|
13
|
+
* @param {(event: Event) => void} [options.onclick]
|
|
14
|
+
* @returns {{element: HTMLButtonElement, setLoading: Function, setDisabled: Function, setText: Function}}
|
|
15
|
+
*/
|
|
16
|
+
export function generateButton(options?: {
|
|
17
|
+
parent?: string | Element;
|
|
18
|
+
id?: string;
|
|
19
|
+
text?: string;
|
|
20
|
+
variant?: "primary" | "secondary" | "danger" | "link";
|
|
21
|
+
type?: "button" | "submit" | "reset";
|
|
22
|
+
size?: "small" | "large";
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
onclick?: (event: Event) => void;
|
|
26
|
+
}): {
|
|
27
|
+
element: HTMLButtonElement;
|
|
28
|
+
setLoading: Function;
|
|
29
|
+
setDisabled: Function;
|
|
30
|
+
setText: Function;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Generates one labelled form field with help text and an error line.
|
|
34
|
+
*
|
|
35
|
+
* @param {object} options
|
|
36
|
+
* @param {string} options.name key of the field in the form values
|
|
37
|
+
* @param {"text"|"password"|"email"|"number"|"date"|"datetime-local"|"time"|"url"|"tel"|"search"|"color"|"range"|"file"|"hidden"|"textarea"|"select"|"checkbox"|"switch"|"radio"|"checkboxes"|"autocomplete"|"multiselect"|"daterange"|"richtext"|"wysiwyg"} [options.type="text"]
|
|
38
|
+
* @param {string} [options.label]
|
|
39
|
+
* @param {string} [options.help] help text under the control
|
|
40
|
+
* @param {*} [options.value] initial value (boolean for checkbox / switch, array for checkboxes / multiple select)
|
|
41
|
+
* @param {(string|{value: string, text?: string, disabled?: boolean})[]} [options.options] choices of select / radio / checkboxes
|
|
42
|
+
* @param {boolean} [options.multiple] select / file: allow several values
|
|
43
|
+
* @param {string} [options.placeholder]
|
|
44
|
+
* @param {number} [options.rows] textarea rows
|
|
45
|
+
* @param {object} [options.rules] validation rules, see validateValue. They can also be given directly
|
|
46
|
+
* (required, email, minLength, ...)
|
|
47
|
+
* @param {(value, field) => void} [options.onChange]
|
|
48
|
+
* @param {() => object} [options.getValues] all form values (set by generateForm, used by `match`)
|
|
49
|
+
* @returns {{element: HTMLElement, name: string, getValue: Function, setValue: Function, validate: Function,
|
|
50
|
+
* setError: Function, focus: Function}}
|
|
51
|
+
*/
|
|
52
|
+
export function generateField(options?: {
|
|
53
|
+
name: string;
|
|
54
|
+
type?: "text" | "password" | "email" | "number" | "date" | "datetime-local" | "time" | "url" | "tel" | "search" | "color" | "range" | "file" | "hidden" | "textarea" | "select" | "checkbox" | "switch" | "radio" | "checkboxes" | "autocomplete" | "multiselect" | "daterange" | "richtext" | "wysiwyg";
|
|
55
|
+
label?: string;
|
|
56
|
+
help?: string;
|
|
57
|
+
value?: any;
|
|
58
|
+
options?: (string | {
|
|
59
|
+
value: string;
|
|
60
|
+
text?: string;
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
})[];
|
|
63
|
+
multiple?: boolean;
|
|
64
|
+
placeholder?: string;
|
|
65
|
+
rows?: number;
|
|
66
|
+
rules?: object;
|
|
67
|
+
onChange?: (value: any, field: any) => void;
|
|
68
|
+
getValues?: () => object;
|
|
69
|
+
}): {
|
|
70
|
+
element: HTMLElement;
|
|
71
|
+
name: string;
|
|
72
|
+
getValue: Function;
|
|
73
|
+
setValue: Function;
|
|
74
|
+
validate: Function;
|
|
75
|
+
setError: Function;
|
|
76
|
+
focus: Function;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Generates a form from a list of field definitions.
|
|
80
|
+
*
|
|
81
|
+
* @param {object} options
|
|
82
|
+
* @param {string|Element} [options.parent]
|
|
83
|
+
* @param {string} [options.id]
|
|
84
|
+
* @param {object[]} options.fields field definitions, see generateField
|
|
85
|
+
* @param {string} [options.submitText]
|
|
86
|
+
* @param {string|false} [options.resetText] adds a reset button when set
|
|
87
|
+
* @param {(values: object, form: object) => (void|Promise)} [options.onSubmit] called with the values when every
|
|
88
|
+
* field is valid. A returned promise keeps the submit button busy; a rejection is shown as form message.
|
|
89
|
+
* @param {(values: object, field: object) => void} [options.onChange]
|
|
90
|
+
* @param {boolean} [options.nested=false] a field called "soa.host" is the key `host` of the object `soa` in the values
|
|
91
|
+
*
|
|
92
|
+
* Field definitions can also have these, which only generateForm reads:
|
|
93
|
+
* - `show: (values) => boolean`: the field is shown while it returns true. A field that is not shown is not validated and not in the values.
|
|
94
|
+
* - `label: (values) => string`: a label that follows the other fields (`values` are the raw values of every field)
|
|
95
|
+
* - `send: false`: the field is validated but not in the values (the second field of "type the password again")
|
|
96
|
+
* - `trim: true`: a text value is trimmed
|
|
97
|
+
* - `empty: "omit"|"null"|"empty"`: what an empty value (an empty text, a number that is not a number) becomes: left out, null, or "".
|
|
98
|
+
* Without it the value stays as it is.
|
|
99
|
+
*
|
|
100
|
+
* A rejection of `onSubmit` with a `details` object ({ "soa.host": "Not a name" }) puts the messages at their fields; what has no field, and the message
|
|
101
|
+
* of the error when no field shows one, go to the message of the form.
|
|
102
|
+
* @returns {{element: HTMLFormElement, fields: Object<string, object>, getValues: Function, getRawValues: Function, setValues: Function,
|
|
103
|
+
* setErrors: Function, validate: Function, reset: Function, setMessage: Function, arrange: Function, submitButton: object}}
|
|
104
|
+
*/
|
|
105
|
+
export function generateForm(options?: {
|
|
106
|
+
parent?: string | Element;
|
|
107
|
+
id?: string;
|
|
108
|
+
fields: object[];
|
|
109
|
+
submitText?: string;
|
|
110
|
+
resetText?: string | false;
|
|
111
|
+
onSubmit?: (values: object, form: object) => (void | Promise<any>);
|
|
112
|
+
onChange?: (values: object, field: object) => void;
|
|
113
|
+
nested?: boolean;
|
|
114
|
+
}): {
|
|
115
|
+
element: HTMLFormElement;
|
|
116
|
+
fields: {
|
|
117
|
+
[x: string]: object;
|
|
118
|
+
};
|
|
119
|
+
getValues: Function;
|
|
120
|
+
getRawValues: Function;
|
|
121
|
+
setValues: Function;
|
|
122
|
+
setErrors: Function;
|
|
123
|
+
validate: Function;
|
|
124
|
+
reset: Function;
|
|
125
|
+
setMessage: Function;
|
|
126
|
+
arrange: Function;
|
|
127
|
+
submitButton: object;
|
|
128
|
+
};
|
|
@@ -1,123 +1,129 @@
|
|
|
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,
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {boolean} [options.
|
|
16
|
-
* @param {boolean} [options.
|
|
17
|
-
*
|
|
18
|
-
* @param {
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param {
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @param {(
|
|
26
|
-
* @param {string} [options.
|
|
27
|
-
*
|
|
28
|
-
* @param {(row: object) =>
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {(row: object) => string} [options.
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {boolean} [options.
|
|
33
|
-
* @param {(
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @param {number} [options.
|
|
45
|
-
* @param {
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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, align?: "left"|"center"|"right", title?: boolean,
|
|
11
|
+
* format?: (value, row) => string, render?: (row: object, value) => (string|Node)}[]} options.columns
|
|
12
|
+
* `format` writes the text of a cell; `render` builds its content instead (a badge, a link, buttons: an element, or text). Every cell carries its column
|
|
13
|
+
* label in `data-label`, so a stylesheet can show a row as a block on a narrow screen, with the label next to the value.
|
|
14
|
+
* @param {object[]} [options.rows] row objects, read by column key
|
|
15
|
+
* @param {boolean} [options.sortable=true] click on a header sorts by it
|
|
16
|
+
* @param {boolean} [options.filter=false] show a text filter above the table
|
|
17
|
+
* @param {number} [options.pageSize=0] rows per page, 0 disables pagination
|
|
18
|
+
* @param {boolean} [options.selectable=false] checkbox column; the header checkbox selects every filtered row
|
|
19
|
+
* @param {boolean} [options.resizableColumns=false] drag the edge of a header (or use the arrow keys on it) to resize;
|
|
20
|
+
* double click resets the width
|
|
21
|
+
* @param {{height?: number, rowHeight?: number, overscan?: number}|boolean} [options.virtual] render only the rows
|
|
22
|
+
* in view, for lists of thousands of rows. Rows have a fixed height (default 36 px) and the table scrolls
|
|
23
|
+
* inside `height` (default 400 px). Replaces pagination.
|
|
24
|
+
* @param {(key: string, width: number) => void} [options.onColumnResize]
|
|
25
|
+
* @param {(rows: object[]) => void} [options.onSelectionChange]
|
|
26
|
+
* @param {(row: object, key: string, value, oldValue) => (boolean|void)} [options.onEdit] called after an edit
|
|
27
|
+
* of an `editable` column (double click, or Enter / F2 on the focused cell). Return false to reject it.
|
|
28
|
+
* @param {(row: object) => void} [options.onRowClick]
|
|
29
|
+
* @param {string} [options.emptyText]
|
|
30
|
+
* @param {(row: object, column: object) => (string|string[]|null|undefined)} [options.cellClass] CSS class(es) for a cell
|
|
31
|
+
* @param {(row: object) => (string|string[]|null|undefined)} [options.rowClass] CSS class(es) for a row
|
|
32
|
+
* @param {boolean} [options.focusableRows=false] rows are reachable with Tab and, with `onRowClick`, opened with Enter and Space
|
|
33
|
+
* @param {(row: object) => string} [options.rowLabel] aria-label of a focusable row
|
|
34
|
+
* @param {"normal"|"compact"} [options.density="normal"]
|
|
35
|
+
* @param {boolean} [options.wrap] true lets long text wrap, false keeps one line with an ellipsis (default: wrap, except in virtual tables)
|
|
36
|
+
* @param {(query: {page: number, pageSize: number, cursor: *, sort: ({key: string, descending: boolean}|null), filter: string}) =>
|
|
37
|
+
* Promise<{rows: object[], total?: number, nextCursor?: *}>} [options.dataSource] load the rows from a server instead of
|
|
38
|
+
* keeping them all in the browser. Sorting, the filter box and the pager call it again. Answer with `total` for numbered pages
|
|
39
|
+
* (`page` is 0-based), or with `nextCursor` for a "Load more" button (`cursor` is what the last answer gave, undefined for the
|
|
40
|
+
* first request; the rows are appended). A failed request shows the error with a Retry button.
|
|
41
|
+
* Together with `virtual` the list scrolls like one of `total` rows (every answer must carry `total`): the rows in view are asked for
|
|
42
|
+
* in chunks of `chunkSize` (`page` is the chunk number), rows that have not arrived yet show a placeholder, and sorting or the filter
|
|
43
|
+
* start again from the top.
|
|
44
|
+
* @param {number} [options.chunkSize=50] rows per request of a data source with `virtual`
|
|
45
|
+
* @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
|
|
46
|
+
* (at most 60 rows are animated, none under reduced motion, none in a virtual table)
|
|
47
|
+
* @param {number} [options.filterDelay=300] ms to wait after typing before the data source is asked
|
|
48
|
+
* @param {{label: string, onclick: (row: object) => void, danger?: boolean, hidden?: (row: object) => boolean, ariaLabel?: (row: object) => string}[]} [options.rowActions]
|
|
49
|
+
* a column of buttons at the end of every row
|
|
50
|
+
* Column extras: `render(row, value)` returns text or a Node (built by the caller, so safe by construction), `align`
|
|
51
|
+
* ("left" | "center" | "right"), `title` (false switches the tooltip with the full text off).
|
|
52
|
+
* @returns {{element: HTMLElement, update: Function, destroy: Function, setRows: Function, getSelected: () => object[], clearSelection: Function,
|
|
53
|
+
* getColumnWidths: () => Object<string, number>, toCsv: () => string, exportCsv: (filename?: string) => void}}
|
|
54
|
+
*/
|
|
55
|
+
export function generateTable(options?: {
|
|
56
|
+
parent?: string | Element;
|
|
57
|
+
id?: string;
|
|
58
|
+
class?: string;
|
|
59
|
+
caption?: string;
|
|
60
|
+
columns: {
|
|
61
|
+
key: string;
|
|
62
|
+
label?: string;
|
|
63
|
+
width?: number;
|
|
64
|
+
sortable?: boolean;
|
|
65
|
+
editable?: boolean;
|
|
66
|
+
align?: "left" | "center" | "right";
|
|
67
|
+
title?: boolean;
|
|
68
|
+
format?: (value: any, row: any) => string;
|
|
69
|
+
render?: (row: object, value: any) => (string | Node);
|
|
70
|
+
}[];
|
|
71
|
+
rows?: object[];
|
|
72
|
+
sortable?: boolean;
|
|
73
|
+
filter?: boolean;
|
|
74
|
+
pageSize?: number;
|
|
75
|
+
selectable?: boolean;
|
|
76
|
+
resizableColumns?: boolean;
|
|
77
|
+
virtual?: {
|
|
78
|
+
height?: number;
|
|
79
|
+
rowHeight?: number;
|
|
80
|
+
overscan?: number;
|
|
81
|
+
} | boolean;
|
|
82
|
+
onColumnResize?: (key: string, width: number) => void;
|
|
83
|
+
onSelectionChange?: (rows: object[]) => void;
|
|
84
|
+
onEdit?: (row: object, key: string, value: any, oldValue: any) => (boolean | void);
|
|
85
|
+
onRowClick?: (row: object) => void;
|
|
86
|
+
emptyText?: string;
|
|
87
|
+
cellClass?: (row: object, column: object) => (string | string[] | null | undefined);
|
|
88
|
+
rowClass?: (row: object) => (string | string[] | null | undefined);
|
|
89
|
+
focusableRows?: boolean;
|
|
90
|
+
rowLabel?: (row: object) => string;
|
|
91
|
+
density?: "normal" | "compact";
|
|
92
|
+
wrap?: boolean;
|
|
93
|
+
dataSource?: (query: {
|
|
94
|
+
page: number;
|
|
95
|
+
pageSize: number;
|
|
96
|
+
cursor: any;
|
|
97
|
+
sort: ({
|
|
98
|
+
key: string;
|
|
99
|
+
descending: boolean;
|
|
100
|
+
} | null);
|
|
101
|
+
filter: string;
|
|
102
|
+
}) => Promise<{
|
|
103
|
+
rows: object[];
|
|
104
|
+
total?: number;
|
|
105
|
+
nextCursor?: any;
|
|
106
|
+
}>;
|
|
107
|
+
chunkSize?: number;
|
|
108
|
+
animateRows?: boolean;
|
|
109
|
+
filterDelay?: number;
|
|
110
|
+
rowActions?: {
|
|
111
|
+
label: string;
|
|
112
|
+
onclick: (row: object) => void;
|
|
113
|
+
danger?: boolean;
|
|
114
|
+
hidden?: (row: object) => boolean;
|
|
115
|
+
ariaLabel?: (row: object) => string;
|
|
116
|
+
}[];
|
|
117
|
+
}): {
|
|
118
|
+
element: HTMLElement;
|
|
119
|
+
update: Function;
|
|
120
|
+
destroy: Function;
|
|
121
|
+
setRows: Function;
|
|
122
|
+
getSelected: () => object[];
|
|
123
|
+
clearSelection: Function;
|
|
124
|
+
getColumnWidths: () => {
|
|
125
|
+
[x: string]: number;
|
|
126
|
+
};
|
|
127
|
+
toCsv: () => string;
|
|
128
|
+
exportCsv: (filename?: string) => void;
|
|
129
|
+
};
|