athena-ui-js 1.1.0 → 1.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 (45) hide show
  1. package/README.md +273 -23
  2. package/package.json +11 -7
  3. package/src/athena-ui.js +33 -10
  4. package/src/libs/config/config.js +8 -1
  5. package/src/libs/core/combobox.js +1 -1
  6. package/src/libs/core/controls.js +153 -0
  7. package/src/libs/core/dateRange.js +121 -0
  8. package/src/libs/core/dom.js +88 -11
  9. package/src/libs/{hephaestus/HTMLElementGenerator/src/HTMLElementGenerator.js → core/elementGenerator.js} +23 -21
  10. package/src/libs/{hephaestus/HTMLElementGenerator/src → core}/errors.js +7 -5
  11. package/src/libs/core/format.js +51 -0
  12. package/src/libs/core/hungarianControls.js +41 -0
  13. package/src/libs/core/i18n.js +64 -0
  14. package/src/libs/core/theme.js +131 -0
  15. package/src/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.js +4 -6
  16. package/src/libs/hephaestus/LayoutGenerator/footerContentGenerator.js +2 -4
  17. package/src/libs/hephaestus/LayoutGenerator/headerContentGenerator.js +12 -5
  18. package/src/libs/hephaestus/MenuGenerator/basicMenuGenerator.js +3 -3
  19. package/src/libs/hephaestus/MenuGenerator/menuGenerator.js +253 -0
  20. package/src/libs/hephaestus/auth/authState.js +58 -0
  21. package/src/libs/hephaestus/chartGenerator/chartGenerator.js +530 -65
  22. package/src/libs/hephaestus/componentGenerator/componentGenerator.js +124 -6
  23. package/src/libs/hephaestus/componentGenerator/themePicker.js +73 -0
  24. package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +100 -13
  25. package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +23 -2
  26. package/src/libs/hephaestus/formGenerator/authForms.js +130 -0
  27. package/src/libs/hephaestus/formGenerator/formBuilder.js +5 -5
  28. package/src/libs/hephaestus/formGenerator/formUtils.js +10 -9
  29. package/src/libs/hephaestus/formGenerator/loginFormGenerator.js +9 -9
  30. package/src/libs/hephaestus/hephaestus.js +7 -2
  31. package/src/libs/hephaestus/inputGenerator/dropZoneGenerator.js +2 -2
  32. package/src/libs/hephaestus/inputGenerator/inputGenerator.js +37 -8
  33. package/src/libs/hephaestus/inputGenerator/richTextGenerator.js +2 -2
  34. package/src/libs/hephaestus/modalGenerator/modalGenerator.js +17 -11
  35. package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +20 -11
  36. package/src/libs/hephaestus/router/router.js +56 -6
  37. package/src/libs/hephaestus/tableGenerator/tableGenerator.js +368 -29
  38. package/src/libs/libs.js +3 -3
  39. package/src/res/themes/appearance.css +154 -0
  40. package/src/res/themes/default/style.css +649 -2
  41. package/src/testing.js +71 -0
  42. package/src/theme-boot.js +25 -0
  43. package/src/libs/hephaestus/HTMLControlGenerator/LICENSE +0 -21
  44. package/src/libs/hephaestus/HTMLControlGenerator/src/HTMLControlGenerator.min.js +0 -5
  45. package/src/libs/hephaestus/HTMLElementGenerator/LICENSE +0 -21
@@ -0,0 +1,58 @@
1
+ //authState for Athena UI
2
+ //Author: Csaba Tóth https://github.com/csabatibortoth/
3
+ //LICENCE: MIT
4
+ //Repository: https://github.com/csabatibortoth/athena-ui
5
+
6
+ /**
7
+ * Who is signed in, kept in memory only. Nothing is written to a cookie or to the storage, so a script (an injected one too) cannot read
8
+ * a credential from here: the real session is a cookie that only the server can read (HttpOnly). This object is the UI's copy of the
9
+ * answer to "who am I", for menus, route guards and the page. The server decides what a person may do.
10
+ *
11
+ * After a reload the state is empty until restore() has asked the server.
12
+ *
13
+ * @param {object} [options]
14
+ * @param {() => Promise<(object|null)>} [options.restore] asks the server who is signed in (for example GET /api/me with the cookie):
15
+ * resolves with the user object, or with null / throws when nobody is
16
+ * @returns {{signIn: (user: object) => void, signOut: () => void, restore: () => Promise<object|null>, isSignedIn: () => boolean,
17
+ * getUser: () => (object|null), hasRole: (role: string) => boolean, onChange: (listener: Function) => Function,
18
+ * routerRules: (paths?: object) => object}}
19
+ */
20
+ export function createAuthState(options = {}) {
21
+ let user = null;
22
+ const listeners = new Set();
23
+ const notify = () => listeners.forEach(listener => listener(user));
24
+ const set = next => {
25
+ const changed = (next === null) !== (user === null) || JSON.stringify(next) !== JSON.stringify(user);
26
+ user = next;
27
+ if (changed) notify();
28
+ };
29
+
30
+ const state = {
31
+ /** The server accepted the sign in: remember who it is (the user object comes from the server's answer). */
32
+ signIn(next) { set(next ?? {}); },
33
+ /** Forget the person. (End the session on the server too: this only clears the UI.) */
34
+ signOut() { set(null); },
35
+ /** Asks the server who is signed in. Resolves with the user, or null. Never throws. */
36
+ async restore() {
37
+ try {
38
+ const found = await options.restore?.();
39
+ set(found ?? null);
40
+ } catch {
41
+ set(null);
42
+ }
43
+ return user;
44
+ },
45
+ isSignedIn: () => user !== null,
46
+ getUser: () => user,
47
+ /** True when the user has the role (user.roles is a list, or user.role a single role). */
48
+ hasRole: role => Boolean(user && (user.roles?.includes?.(role) || user.role === role)),
49
+ /** Called with the user (or null) when somebody signs in or out. Returns a function that stops it. */
50
+ onChange(listener) {
51
+ listeners.add(listener);
52
+ return () => listeners.delete(listener);
53
+ },
54
+ /** The \`auth\` option of createRouter: createRouter({ auth: auth.routerRules({ loginPath: "/signin" }) }). */
55
+ routerRules: (paths = {}) => ({ isSignedIn: state.isSignedIn, hasRole: state.hasRole, ...paths })
56
+ };
57
+ return state;
58
+ }