athena-ui-js 2.1.0 → 2.2.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,67 +1,71 @@
1
- /**
2
- * Creates a router that renders a page function into an outlet element.
3
- *
4
- * @param {object} options
5
- * @param {Object<string, Function|{handler: Function, title?: string}>} options.routes path pattern -> page
6
- * function. Patterns support `:param` segments and a trailing `*`. A page function is called with
7
- * `{ path, params, query }` after the outlet was emptied, and may return a promise.
8
- * @param {string} [options.outlet="wrapper"] id of the element the pages are rendered into
9
- * @param {"hash"|"history"} [options.mode="hash"] "history" needs the server to answer every path with the page
10
- * @param {(context) => void} [options.notFound] called when no route matches
11
- * @param {(context) => (boolean|string|void|Promise)} [options.beforeEach] guard: return false to cancel,
12
- * or a path to redirect to (login redirect)
13
- * @param {(context) => void} [options.afterEach] same as onShown
14
- * @param {(context, route) => void} [options.onRender] called after the outlet was emptied, before the page function runs
15
- * @param {(context, route) => void} [options.onShown] called after the page function finished (and it was not replaced by a newer
16
- * navigation): the place to set the title, move the focus to the content, scroll to the top
17
- * @param {boolean} [options.focusContent=false] after a page is shown the outlet gets the focus (it is made focusable for that), so a
18
- * screen reader starts reading the new page and the keyboard continues there
19
- * @param {boolean} [options.scrollTop=false] scroll to the top after a page is shown
20
- * @param {object} [options.auth] sign-in rules for routes, see the route options below
21
- * @param {() => boolean} [options.auth.isSignedIn]
22
- * @param {(role: string) => boolean} [options.auth.hasRole]
23
- * @param {string} [options.auth.loginPath="/login"] where `auth: true` routes send a visitor who is not signed in (with `?next=<path>`)
24
- * @param {string} [options.auth.homePath="/"] where `guestOnly` routes send a signed-in person
25
- * @param {string} [options.auth.forbiddenPath] where a person without the role goes (default: homePath)
26
- * @param {string} [options.titlePrefix] document title is `${titlePrefix}${route.title}`
27
- *
28
- * A route is a page function, or an object: `{ handler, title, auth: true, guestOnly: true, roles: ["admin"], guard(context) }`.
29
- * `auth`, `guestOnly` and `roles` are checked with options.auth; `guard` is a function that gets the same context and returns
30
- * false (stay where you are), a path (redirect) or anything else (go on); it runs after the rules.
31
- * @returns {{start: Function, stop: Function, navigate: Function, current: Function, href: Function,
32
- * onChange: (listener: (context) => void) => Function}}
33
- * `onChange(listener)` is called with the context after every page that is shown (menus and breadcrumbs follow the router
34
- * with it) and returns a function that stops it.
35
- */
36
- export function createRouter(options?: {
37
- routes: {
38
- [x: string]: Function | {
39
- handler: Function;
40
- title?: string;
41
- };
42
- };
43
- outlet?: string;
44
- mode?: "hash" | "history";
45
- notFound?: (context: any) => void;
46
- beforeEach?: (context: any) => (boolean | string | void | Promise<any>);
47
- afterEach?: (context: any) => void;
48
- onRender?: (context: any, route: any) => void;
49
- onShown?: (context: any, route: any) => void;
50
- focusContent?: boolean;
51
- scrollTop?: boolean;
52
- auth?: {
53
- isSignedIn?: () => boolean;
54
- hasRole?: (role: string) => boolean;
55
- loginPath?: string;
56
- homePath?: string;
57
- forbiddenPath?: string;
58
- };
59
- titlePrefix?: string;
60
- }): {
61
- start: Function;
62
- stop: Function;
63
- navigate: Function;
64
- current: Function;
65
- href: Function;
66
- onChange: (listener: (context: any) => void) => Function;
67
- };
1
+ /**
2
+ * Creates a router that renders a page function into an outlet element.
3
+ *
4
+ * @param {object} options
5
+ * @param {Object<string, Function|{handler: Function, title?: string}>} options.routes path pattern -> page
6
+ * function. Patterns support `:param` segments and a trailing `*`. A page function is called with
7
+ * `{ path, params, query }` after the outlet was emptied, and may return a promise.
8
+ * @param {string} [options.outlet="wrapper"] id of the element the pages are rendered into
9
+ * @param {"hash"|"history"} [options.mode="hash"] "history" needs the server to answer every path with the page
10
+ * @param {(context) => void} [options.notFound] called when no route matches
11
+ * @param {(context) => (boolean|string|void|Promise)} [options.beforeEach] guard: return false to cancel,
12
+ * or a path to redirect to (login redirect)
13
+ * @param {(context) => void} [options.afterEach] same as onShown
14
+ * @param {(context, route) => void} [options.onRender] called after the outlet was emptied, before the page function runs
15
+ * @param {(context, route) => void} [options.onShown] called after the page function finished (and it was not replaced by a newer
16
+ * navigation): the place to set the title, move the focus to the content, scroll to the top
17
+ * @param {boolean} [options.focusContent=false] after a page is shown the outlet gets the focus (it is made focusable for that), so a
18
+ * screen reader starts reading the new page and the keyboard continues there
19
+ * @param {boolean} [options.scrollTop=false] scroll to the top after a page is shown
20
+ * @param {boolean} [options.transition=false] a page change is a view transition (document.startViewTransition): the old page cross-fades into the new one,
21
+ * and elements with a `view-transition-name` move from one page to the next. Without the API, or under reduced motion, nothing changes. The old page
22
+ * stays on the screen until the page function of the new one is done, so pages that need long to build should draw something quickly.
23
+ * @param {object} [options.auth] sign-in rules for routes, see the route options below
24
+ * @param {() => boolean} [options.auth.isSignedIn]
25
+ * @param {(role: string) => boolean} [options.auth.hasRole]
26
+ * @param {string} [options.auth.loginPath="/login"] where `auth: true` routes send a visitor who is not signed in (with `?next=<path>`)
27
+ * @param {string} [options.auth.homePath="/"] where `guestOnly` routes send a signed-in person
28
+ * @param {string} [options.auth.forbiddenPath] where a person without the role goes (default: homePath)
29
+ * @param {string} [options.titlePrefix] document title is `${titlePrefix}${route.title}`
30
+ *
31
+ * A route is a page function, or an object: `{ handler, title, auth: true, guestOnly: true, roles: ["admin"], guard(context) }`.
32
+ * `auth`, `guestOnly` and `roles` are checked with options.auth; `guard` is a function that gets the same context and returns
33
+ * false (stay where you are), a path (redirect) or anything else (go on); it runs after the rules.
34
+ * @returns {{start: Function, stop: Function, navigate: Function, current: Function, href: Function,
35
+ * onChange: (listener: (context) => void) => Function}}
36
+ * `onChange(listener)` is called with the context after every page that is shown (menus and breadcrumbs follow the router
37
+ * with it) and returns a function that stops it.
38
+ */
39
+ export function createRouter(options?: {
40
+ routes: {
41
+ [x: string]: Function | {
42
+ handler: Function;
43
+ title?: string;
44
+ };
45
+ };
46
+ outlet?: string;
47
+ mode?: "hash" | "history";
48
+ notFound?: (context: any) => void;
49
+ beforeEach?: (context: any) => (boolean | string | void | Promise<any>);
50
+ afterEach?: (context: any) => void;
51
+ onRender?: (context: any, route: any) => void;
52
+ onShown?: (context: any, route: any) => void;
53
+ focusContent?: boolean;
54
+ scrollTop?: boolean;
55
+ transition?: boolean;
56
+ auth?: {
57
+ isSignedIn?: () => boolean;
58
+ hasRole?: (role: string) => boolean;
59
+ loginPath?: string;
60
+ homePath?: string;
61
+ forbiddenPath?: string;
62
+ };
63
+ titlePrefix?: string;
64
+ }): {
65
+ start: Function;
66
+ stop: Function;
67
+ navigate: Function;
68
+ current: Function;
69
+ href: Function;
70
+ onChange: (listener: (context: any) => void) => Function;
71
+ };
@@ -1,120 +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 {number} [options.filterDelay=300] ms to wait after typing before the data source is asked
43
- * @param {{label: string, onclick: (row: object) => void, danger?: boolean, hidden?: (row: object) => boolean, ariaLabel?: (row: object) => string}[]} [options.rowActions]
44
- * a column of buttons at the end of every row
45
- * Column extras: `render(row, value)` returns text or a Node (built by the caller, so safe by construction), `align`
46
- * ("left" | "center" | "right"), `title` (false switches the tooltip with the full text off).
47
- * @returns {{element: HTMLElement, update: Function, destroy: Function, setRows: Function, getSelected: () => object[], clearSelection: Function,
48
- * getColumnWidths: () => Object<string, number>, toCsv: () => string, exportCsv: (filename?: string) => void}}
49
- */
50
- export function generateTable(options?: {
51
- parent?: string | Element;
52
- id?: string;
53
- class?: string;
54
- caption?: string;
55
- columns: {
56
- key: string;
57
- label?: string;
58
- width?: number;
59
- sortable?: boolean;
60
- editable?: boolean;
61
- format?: (value: any, row: any) => string;
62
- }[];
63
- rows?: object[];
64
- sortable?: boolean;
65
- filter?: boolean;
66
- pageSize?: number;
67
- selectable?: boolean;
68
- resizableColumns?: boolean;
69
- virtual?: {
70
- height?: number;
71
- rowHeight?: number;
72
- overscan?: number;
73
- } | boolean;
74
- onColumnResize?: (key: string, width: number) => void;
75
- onSelectionChange?: (rows: object[]) => void;
76
- onEdit?: (row: object, key: string, value: any, oldValue: any) => (boolean | void);
77
- onRowClick?: (row: object) => void;
78
- emptyText?: string;
79
- cellClass?: (row: object, column: object) => (string | string[] | null | undefined);
80
- rowClass?: (row: object) => (string | string[] | null | undefined);
81
- focusableRows?: boolean;
82
- rowLabel?: (row: object) => string;
83
- density?: "normal" | "compact";
84
- wrap?: boolean;
85
- dataSource?: (query: {
86
- page: number;
87
- pageSize: number;
88
- cursor: any;
89
- sort: ({
90
- key: string;
91
- descending: boolean;
92
- } | null);
93
- filter: string;
94
- }) => Promise<{
95
- rows: object[];
96
- total?: number;
97
- nextCursor?: any;
98
- }>;
99
- chunkSize?: number;
100
- filterDelay?: number;
101
- rowActions?: {
102
- label: string;
103
- onclick: (row: object) => void;
104
- danger?: boolean;
105
- hidden?: (row: object) => boolean;
106
- ariaLabel?: (row: object) => string;
107
- }[];
108
- }): {
109
- element: HTMLElement;
110
- update: Function;
111
- destroy: Function;
112
- setRows: Function;
113
- getSelected: () => object[];
114
- clearSelection: Function;
115
- getColumnWidths: () => {
116
- [x: string]: number;
117
- };
118
- toCsv: () => string;
119
- exportCsv: (filename?: string) => void;
120
- };
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 @@
1
+ export * from "./libs/core/motion.js";