athena-ui-js 2.1.0 → 2.3.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.
Files changed (33) hide show
  1. package/README.md +81 -3
  2. package/docs/styling.md +21 -6
  3. package/package.json +9 -1
  4. package/src/athena-ui.js +4 -1
  5. package/src/libs/config/config.js +1 -1
  6. package/src/libs/core/gridLayout.js +102 -0
  7. package/src/libs/core/i18n.js +32 -0
  8. package/src/libs/core/motion.js +358 -0
  9. package/src/libs/core/theme.js +12 -0
  10. package/src/libs/hephaestus/chartGenerator/chartGenerator.js +9 -5
  11. package/src/libs/hephaestus/componentGenerator/componentGenerator.js +17 -0
  12. package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +2 -1
  13. package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +3 -1
  14. package/src/libs/hephaestus/router/router.js +18 -9
  15. package/src/libs/hephaestus/tableGenerator/tableGenerator.js +25 -0
  16. package/src/motion.js +6 -0
  17. package/src/res/themes/default/style.css +413 -10
  18. package/src/res/themes/tokens.css +25 -0
  19. package/src/widgets.js +7 -0
  20. package/types/athena-ui.d.ts +99 -96
  21. package/types/libs/config/config.d.ts +3 -3
  22. package/types/libs/core/gridLayout.d.ts +45 -0
  23. package/types/libs/core/motion.d.ts +123 -0
  24. package/types/libs/core/popover.d.ts +36 -36
  25. package/types/libs/core/theme.d.ts +2 -0
  26. package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +2 -0
  27. package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +238 -224
  28. package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +153 -153
  29. package/types/libs/hephaestus/router/router.d.ts +4 -0
  30. package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +3 -0
  31. package/types/libs/hephaestus/widgetGrid/widgetGrid.d.ts +117 -0
  32. package/types/motion.d.ts +1 -0
  33. package/types/widgets.d.ts +2 -0
@@ -1,153 +1,153 @@
1
- /**
2
- * Generates tabs. Arrow keys, Home and End move between the tabs.
3
- *
4
- * @param {object} options
5
- * @param {string|Element} [options.parent]
6
- * @param {string} [options.id]
7
- * @param {{id: string, label: string, content: *, disabled?: boolean}[]} options.tabs content is text, a Node,
8
- * an array, or a function called once when the tab is first shown (lazy content)
9
- * @param {string} [options.active] id of the initially active tab (default: the first)
10
- * @param {(id: string) => void} [options.onChange]
11
- * @returns {{element: HTMLElement, select: (id: string) => void, getActive: () => string}}
12
- */
13
- export function generateTabs(options?: {
14
- parent?: string | Element;
15
- id?: string;
16
- tabs: {
17
- id: string;
18
- label: string;
19
- content: any;
20
- disabled?: boolean;
21
- }[];
22
- active?: string;
23
- onChange?: (id: string) => void;
24
- }): {
25
- element: HTMLElement;
26
- select: (id: string) => void;
27
- getActive: () => string;
28
- };
29
- /**
30
- * Generates breadcrumbs. The last item is the current page.
31
- *
32
- * @param {object} options
33
- * @param {string|Element} [options.parent]
34
- * @param {{label: string, href?: string, onclick?: Function}[]} options.items
35
- */
36
- export function generateBreadcrumbs(options?: {
37
- parent?: string | Element;
38
- items: {
39
- label: string;
40
- href?: string;
41
- onclick?: Function;
42
- }[];
43
- }): any;
44
- /**
45
- * Generates a page selector.
46
- *
47
- * @param {object} options
48
- * @param {string|Element} [options.parent]
49
- * @param {number} options.total number of items
50
- * @param {number} [options.pageSize=10]
51
- * @param {number} [options.page=1]
52
- * @param {number} [options.siblings=1] page buttons shown next to the current page
53
- * @param {(page: number) => void} [options.onChange]
54
- * @returns {{element: HTMLElement, setPage: Function, setTotal: Function, getPage: Function}}
55
- */
56
- export function generatePagination(options?: {
57
- parent?: string | Element;
58
- total: number;
59
- pageSize?: number;
60
- page?: number;
61
- siblings?: number;
62
- onChange?: (page: number) => void;
63
- }): {
64
- element: HTMLElement;
65
- setPage: Function;
66
- setTotal: Function;
67
- getPage: Function;
68
- };
69
- /**
70
- * Generates collapsible panels.
71
- *
72
- * @param {object} options
73
- * @param {string|Element} [options.parent]
74
- * @param {{id?: string, title: string, content: *, open?: boolean}[]} options.items
75
- * @param {boolean} [options.multiple=false] allow several panels to be open at once
76
- * @returns {{element: HTMLElement, toggle: (index: number, open?: boolean) => void}}
77
- */
78
- export function generateAccordion(options?: {
79
- parent?: string | Element;
80
- items: {
81
- id?: string;
82
- title: string;
83
- content: any;
84
- open?: boolean;
85
- }[];
86
- multiple?: boolean;
87
- }): {
88
- element: HTMLElement;
89
- toggle: (index: number, open?: boolean) => void;
90
- };
91
- /**
92
- * Generates a button that opens a menu. Arrow keys move through the items, Esc closes it, and so does a click outside.
93
- * The menu is a native popover (the `popover` attribute): it is drawn above everything, so no parent can cut it off, and the browser takes care of the
94
- * light dismiss and of the focus. It is placed next to the button, below it, or above it when there is no room below. Browsers without the popover API
95
- * get a plain menu that is shown and hidden with `hidden`.
96
- *
97
- * @param {object} options
98
- * @param {string|Element} [options.parent]
99
- * @param {string} [options.label] button text (leave it out for an icon-only button, and give `ariaLabel`)
100
- * @param {string|Node} [options.icon] shown before the label, text or a Node (e.g. an SVG); hidden from screen readers
101
- * @param {string} [options.ariaLabel] accessible name, needed when there is no label
102
- * @param {boolean} [options.caret=false] show a small arrow after the label
103
- * @param {string} [options.toggleClass] extra CSS class(es) of the toggle button
104
- * @param {{label?: string, onclick?: Function, href?: string, disabled?: boolean, divider?: boolean}[]} options.items
105
- * @param {"left"|"right"} [options.align="left"]
106
- * @returns {{element: HTMLElement, open: Function, close: Function}}
107
- */
108
- export function generateDropdown(options?: {
109
- parent?: string | Element;
110
- label?: string;
111
- icon?: string | Node;
112
- ariaLabel?: string;
113
- caret?: boolean;
114
- toggleClass?: string;
115
- items: {
116
- label?: string;
117
- onclick?: Function;
118
- href?: string;
119
- disabled?: boolean;
120
- divider?: boolean;
121
- }[];
122
- align?: "left" | "right";
123
- }): {
124
- element: HTMLElement;
125
- open: Function;
126
- close: Function;
127
- };
128
- /**
129
- * Generates a vertical navigation with nested items. On small screens it collapses behind a toggle button.
130
- *
131
- * @param {object} options
132
- * @param {string|Element} [options.parent]
133
- * @param {{id: string, label: string, icon?: string, href?: string, children?: object[]}[]} options.items
134
- * @param {(item: object) => void} [options.onSelect]
135
- * @param {string} [options.active] id of the initially selected item
136
- * @returns {{element: HTMLElement, select: (id: string) => void, toggle: Function}}
137
- */
138
- export function generateSidebar(options?: {
139
- parent?: string | Element;
140
- items: {
141
- id: string;
142
- label: string;
143
- icon?: string;
144
- href?: string;
145
- children?: object[];
146
- }[];
147
- onSelect?: (item: object) => void;
148
- active?: string;
149
- }): {
150
- element: HTMLElement;
151
- select: (id: string) => void;
152
- toggle: Function;
153
- };
1
+ /**
2
+ * Generates tabs. Arrow keys, Home and End move between the tabs.
3
+ *
4
+ * @param {object} options
5
+ * @param {string|Element} [options.parent]
6
+ * @param {string} [options.id]
7
+ * @param {{id: string, label: string, content: *, disabled?: boolean}[]} options.tabs content is text, a Node,
8
+ * an array, or a function called once when the tab is first shown (lazy content)
9
+ * @param {string} [options.active] id of the initially active tab (default: the first)
10
+ * @param {(id: string) => void} [options.onChange]
11
+ * @returns {{element: HTMLElement, select: (id: string) => void, getActive: () => string}}
12
+ */
13
+ export function generateTabs(options?: {
14
+ parent?: string | Element;
15
+ id?: string;
16
+ tabs: {
17
+ id: string;
18
+ label: string;
19
+ content: any;
20
+ disabled?: boolean;
21
+ }[];
22
+ active?: string;
23
+ onChange?: (id: string) => void;
24
+ }): {
25
+ element: HTMLElement;
26
+ select: (id: string) => void;
27
+ getActive: () => string;
28
+ };
29
+ /**
30
+ * Generates breadcrumbs. The last item is the current page.
31
+ *
32
+ * @param {object} options
33
+ * @param {string|Element} [options.parent]
34
+ * @param {{label: string, href?: string, onclick?: Function}[]} options.items
35
+ */
36
+ export function generateBreadcrumbs(options?: {
37
+ parent?: string | Element;
38
+ items: {
39
+ label: string;
40
+ href?: string;
41
+ onclick?: Function;
42
+ }[];
43
+ }): any;
44
+ /**
45
+ * Generates a page selector.
46
+ *
47
+ * @param {object} options
48
+ * @param {string|Element} [options.parent]
49
+ * @param {number} options.total number of items
50
+ * @param {number} [options.pageSize=10]
51
+ * @param {number} [options.page=1]
52
+ * @param {number} [options.siblings=1] page buttons shown next to the current page
53
+ * @param {(page: number) => void} [options.onChange]
54
+ * @returns {{element: HTMLElement, setPage: Function, setTotal: Function, getPage: Function}}
55
+ */
56
+ export function generatePagination(options?: {
57
+ parent?: string | Element;
58
+ total: number;
59
+ pageSize?: number;
60
+ page?: number;
61
+ siblings?: number;
62
+ onChange?: (page: number) => void;
63
+ }): {
64
+ element: HTMLElement;
65
+ setPage: Function;
66
+ setTotal: Function;
67
+ getPage: Function;
68
+ };
69
+ /**
70
+ * Generates collapsible panels.
71
+ *
72
+ * @param {object} options
73
+ * @param {string|Element} [options.parent]
74
+ * @param {{id?: string, title: string, content: *, open?: boolean}[]} options.items
75
+ * @param {boolean} [options.multiple=false] allow several panels to be open at once
76
+ * @returns {{element: HTMLElement, toggle: (index: number, open?: boolean) => void}}
77
+ */
78
+ export function generateAccordion(options?: {
79
+ parent?: string | Element;
80
+ items: {
81
+ id?: string;
82
+ title: string;
83
+ content: any;
84
+ open?: boolean;
85
+ }[];
86
+ multiple?: boolean;
87
+ }): {
88
+ element: HTMLElement;
89
+ toggle: (index: number, open?: boolean) => void;
90
+ };
91
+ /**
92
+ * Generates a button that opens a menu. Arrow keys move through the items, Esc closes it, and so does a click outside.
93
+ * The menu is a native popover (the `popover` attribute): it is drawn above everything, so no parent can cut it off, and the browser takes care of the
94
+ * light dismiss and of the focus. It is placed next to the button, below it, or above it when there is no room below. Browsers without the popover API
95
+ * get a plain menu that is shown and hidden with `hidden`.
96
+ *
97
+ * @param {object} options
98
+ * @param {string|Element} [options.parent]
99
+ * @param {string} [options.label] button text (leave it out for an icon-only button, and give `ariaLabel`)
100
+ * @param {string|Node} [options.icon] shown before the label, text or a Node (e.g. an SVG); hidden from screen readers
101
+ * @param {string} [options.ariaLabel] accessible name, needed when there is no label
102
+ * @param {boolean} [options.caret=false] show a small arrow after the label
103
+ * @param {string} [options.toggleClass] extra CSS class(es) of the toggle button
104
+ * @param {{label?: string, onclick?: Function, href?: string, disabled?: boolean, divider?: boolean}[]} options.items
105
+ * @param {"left"|"right"} [options.align="left"]
106
+ * @returns {{element: HTMLElement, open: Function, close: Function}}
107
+ */
108
+ export function generateDropdown(options?: {
109
+ parent?: string | Element;
110
+ label?: string;
111
+ icon?: string | Node;
112
+ ariaLabel?: string;
113
+ caret?: boolean;
114
+ toggleClass?: string;
115
+ items: {
116
+ label?: string;
117
+ onclick?: Function;
118
+ href?: string;
119
+ disabled?: boolean;
120
+ divider?: boolean;
121
+ }[];
122
+ align?: "left" | "right";
123
+ }): {
124
+ element: HTMLElement;
125
+ open: Function;
126
+ close: Function;
127
+ };
128
+ /**
129
+ * Generates a vertical navigation with nested items. On small screens it collapses behind a toggle button.
130
+ *
131
+ * @param {object} options
132
+ * @param {string|Element} [options.parent]
133
+ * @param {{id: string, label: string, icon?: string, href?: string, children?: object[]}[]} options.items
134
+ * @param {(item: object) => void} [options.onSelect]
135
+ * @param {string} [options.active] id of the initially selected item
136
+ * @returns {{element: HTMLElement, select: (id: string) => void, toggle: Function}}
137
+ */
138
+ export function generateSidebar(options?: {
139
+ parent?: string | Element;
140
+ items: {
141
+ id: string;
142
+ label: string;
143
+ icon?: string;
144
+ href?: string;
145
+ children?: object[];
146
+ }[];
147
+ onSelect?: (item: object) => void;
148
+ active?: string;
149
+ }): {
150
+ element: HTMLElement;
151
+ select: (id: string) => void;
152
+ toggle: Function;
153
+ };
@@ -17,6 +17,9 @@
17
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
18
  * screen reader starts reading the new page and the keyboard continues there
19
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.
20
23
  * @param {object} [options.auth] sign-in rules for routes, see the route options below
21
24
  * @param {() => boolean} [options.auth.isSignedIn]
22
25
  * @param {(role: string) => boolean} [options.auth.hasRole]
@@ -49,6 +52,7 @@ export function createRouter(options?: {
49
52
  onShown?: (context: any, route: any) => void;
50
53
  focusContent?: boolean;
51
54
  scrollTop?: boolean;
55
+ transition?: boolean;
52
56
  auth?: {
53
57
  isSignedIn?: () => boolean;
54
58
  hasRole?: (role: string) => boolean;
@@ -39,6 +39,8 @@
39
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
40
  * start again from the top.
41
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)
42
44
  * @param {number} [options.filterDelay=300] ms to wait after typing before the data source is asked
43
45
  * @param {{label: string, onclick: (row: object) => void, danger?: boolean, hidden?: (row: object) => boolean, ariaLabel?: (row: object) => string}[]} [options.rowActions]
44
46
  * a column of buttons at the end of every row
@@ -97,6 +99,7 @@ export function generateTable(options?: {
97
99
  nextCursor?: any;
98
100
  }>;
99
101
  chunkSize?: number;
102
+ animateRows?: boolean;
100
103
  filterDelay?: number;
101
104
  rowActions?: {
102
105
  label: string;
@@ -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
+ };
@@ -0,0 +1 @@
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";