athena-ui-js 1.2.0 → 2.0.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 (148) hide show
  1. package/README.md +312 -60
  2. package/docs/migration-2.0.md +83 -0
  3. package/docs/styling.md +86 -0
  4. package/package.json +109 -24
  5. package/src/athena-ui.js +61 -81
  6. package/src/chart.js +6 -0
  7. package/src/classic.js +11 -0
  8. package/src/components.js +6 -0
  9. package/src/controls.js +8 -0
  10. package/src/csv.js +6 -0
  11. package/src/dialog.js +7 -0
  12. package/src/dom.js +6 -0
  13. package/src/feedback.js +6 -0
  14. package/src/format.js +6 -0
  15. package/src/forms.js +7 -0
  16. package/src/i18n.js +6 -0
  17. package/src/inputs.js +9 -0
  18. package/src/libs/config/config.js +1 -2
  19. package/src/libs/core/controls.js +145 -0
  20. package/src/libs/core/cookies.js +55 -0
  21. package/src/libs/core/dateRange.js +121 -0
  22. package/src/libs/core/dom.js +58 -8
  23. package/src/libs/{hephaestus/HTMLElementGenerator/src/HTMLElementGenerator.js → core/elementGenerator.js} +23 -21
  24. package/src/libs/{hephaestus/HTMLElementGenerator/src → core}/errors.js +7 -5
  25. package/src/libs/core/format.js +51 -0
  26. package/src/libs/core/hungarianControls.js +41 -0
  27. package/src/libs/core/i18n.js +104 -6
  28. package/src/libs/core/theme.js +131 -0
  29. package/src/libs/core/validation.js +2 -2
  30. package/src/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.js +13 -7
  31. package/src/libs/hephaestus/LayoutGenerator/footerContentGenerator.js +2 -4
  32. package/src/libs/hephaestus/LayoutGenerator/headerContentGenerator.js +12 -5
  33. package/src/libs/hephaestus/MenuGenerator/basicMenuGenerator.js +3 -3
  34. package/src/libs/hephaestus/MenuGenerator/menuGenerator.js +265 -0
  35. package/src/libs/hephaestus/auth/authState.js +58 -0
  36. package/src/libs/hephaestus/auth/session.js +1 -1
  37. package/src/libs/hephaestus/chartGenerator/chartGenerator.js +519 -87
  38. package/src/libs/hephaestus/componentGenerator/componentGenerator.js +121 -4
  39. package/src/libs/hephaestus/componentGenerator/themePicker.js +73 -0
  40. package/src/libs/hephaestus/dialogGenerator/dialogGenerator.js +113 -25
  41. package/src/libs/hephaestus/feedbackGenerator/feedbackGenerator.js +21 -0
  42. package/src/libs/hephaestus/formGenerator/authForms.js +130 -0
  43. package/src/libs/hephaestus/formGenerator/changePasswordFormGenerator.js +4 -4
  44. package/src/libs/hephaestus/formGenerator/formUtils.js +10 -13
  45. package/src/libs/hephaestus/formGenerator/loginFormGenerator.js +10 -11
  46. package/src/libs/hephaestus/formGenerator/registrationFormGenerator.js +3 -3
  47. package/src/libs/hephaestus/hephaestus.js +0 -5
  48. package/src/libs/hephaestus/inputGenerator/dropZoneGenerator.js +1 -1
  49. package/src/libs/hephaestus/inputGenerator/inputGenerator.js +30 -1
  50. package/src/libs/hephaestus/modalGenerator/modalGenerator.js +25 -12
  51. package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +20 -24
  52. package/src/libs/hephaestus/router/router.js +54 -5
  53. package/src/libs/hephaestus/tableGenerator/tableGenerator.js +290 -16
  54. package/src/menu.js +6 -0
  55. package/src/navigation.js +6 -0
  56. package/src/res/themes/appearance.css +154 -0
  57. package/src/res/themes/default/style.css +688 -82
  58. package/src/res/themes/tokens.css +96 -0
  59. package/src/router.js +6 -0
  60. package/src/sanitize.js +6 -0
  61. package/src/session.js +8 -0
  62. package/src/table.js +6 -0
  63. package/src/testing.js +11 -1
  64. package/src/theme-boot.js +25 -0
  65. package/src/theme.js +7 -0
  66. package/src/validation.js +6 -0
  67. package/types/athena-ui.d.ts +96 -0
  68. package/types/chart.d.ts +1 -0
  69. package/types/classic.d.ts +1 -0
  70. package/types/components.d.ts +1 -0
  71. package/types/controls.d.ts +3 -0
  72. package/types/csv.d.ts +1 -0
  73. package/types/dialog.d.ts +2 -0
  74. package/types/dom.d.ts +1 -0
  75. package/types/feedback.d.ts +1 -0
  76. package/types/format.d.ts +1 -0
  77. package/types/forms.d.ts +2 -0
  78. package/types/i18n.d.ts +1 -0
  79. package/types/inputs.d.ts +4 -0
  80. package/types/libs/config/config.d.ts +96 -0
  81. package/types/libs/config/hooks.d.ts +8 -0
  82. package/types/libs/core/combobox.d.ts +10 -0
  83. package/types/libs/core/controls.d.ts +28 -0
  84. package/types/libs/core/cookies.d.ts +27 -0
  85. package/types/libs/core/csv.d.ts +12 -0
  86. package/types/libs/core/dateRange.d.ts +72 -0
  87. package/types/libs/core/dom.d.ts +65 -0
  88. package/types/libs/core/elementGenerator.d.ts +30 -0
  89. package/types/libs/core/errors.d.ts +29 -0
  90. package/types/libs/core/focus.d.ts +6 -0
  91. package/types/libs/core/format.d.ts +21 -0
  92. package/types/libs/core/hungarianControls.d.ts +2 -0
  93. package/types/libs/core/i18n.d.ts +17 -0
  94. package/types/libs/core/pagination.d.ts +5 -0
  95. package/types/libs/core/sanitize.d.ts +6 -0
  96. package/types/libs/core/tableMath.d.ts +26 -0
  97. package/types/libs/core/theme.d.ts +39 -0
  98. package/types/libs/core/validation.d.ts +56 -0
  99. package/types/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.d.ts +10 -0
  100. package/types/libs/hephaestus/LayoutGenerator/footerContentGenerator.d.ts +4 -0
  101. package/types/libs/hephaestus/LayoutGenerator/headerContentGenerator.d.ts +20 -0
  102. package/types/libs/hephaestus/LayoutGenerator/wrapperContentGenerator.d.ts +1 -0
  103. package/types/libs/hephaestus/MenuGenerator/basicMenuGenerator.d.ts +14 -0
  104. package/types/libs/hephaestus/MenuGenerator/menuGenerator.d.ts +65 -0
  105. package/types/libs/hephaestus/auth/authState.d.ts +26 -0
  106. package/types/libs/hephaestus/auth/session.d.ts +26 -0
  107. package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +91 -0
  108. package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +222 -0
  109. package/types/libs/hephaestus/componentGenerator/themePicker.d.ts +24 -0
  110. package/types/libs/hephaestus/dialogGenerator/dialogGenerator.d.ts +120 -0
  111. package/types/libs/hephaestus/feedbackGenerator/feedbackGenerator.d.ts +86 -0
  112. package/types/libs/hephaestus/formGenerator/authForms.d.ts +122 -0
  113. package/types/libs/hephaestus/formGenerator/changePasswordFormGenerator.d.ts +6 -0
  114. package/types/libs/hephaestus/formGenerator/formBuilder.d.ts +113 -0
  115. package/types/libs/hephaestus/formGenerator/formUtils.d.ts +8 -0
  116. package/types/libs/hephaestus/formGenerator/loginFormGenerator.d.ts +11 -0
  117. package/types/libs/hephaestus/formGenerator/lostPasswordFormGenerator.d.ts +4 -0
  118. package/types/libs/hephaestus/formGenerator/registrationFormGenerator.d.ts +7 -0
  119. package/types/libs/hephaestus/hephaestus.d.ts +3 -0
  120. package/types/libs/hephaestus/inputGenerator/dropZoneGenerator.d.ts +48 -0
  121. package/types/libs/hephaestus/inputGenerator/inputGenerator.d.ts +185 -0
  122. package/types/libs/hephaestus/inputGenerator/richTextGenerator.d.ts +49 -0
  123. package/types/libs/hephaestus/modalGenerator/modalGenerator.d.ts +2 -0
  124. package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +150 -0
  125. package/types/libs/hephaestus/router/matchRoute.d.ts +12 -0
  126. package/types/libs/hephaestus/router/router.d.ts +67 -0
  127. package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +120 -0
  128. package/types/menu.d.ts +1 -0
  129. package/types/navigation.d.ts +1 -0
  130. package/types/res/themes/themes.d.ts +7 -0
  131. package/types/router.d.ts +1 -0
  132. package/types/sanitize.d.ts +1 -0
  133. package/types/session.d.ts +3 -0
  134. package/types/table.d.ts +1 -0
  135. package/types/testing.d.ts +27 -0
  136. package/types/theme-boot.d.ts +0 -0
  137. package/types/theme.d.ts +2 -0
  138. package/types/validation.d.ts +1 -0
  139. package/src/libs/crypto-js/LICENSE +0 -24
  140. package/src/libs/crypto-js/crypto-js.js +0 -6657
  141. package/src/libs/hephaestus/HTMLControlGenerator/LICENSE +0 -21
  142. package/src/libs/hephaestus/HTMLControlGenerator/src/HTMLControlGenerator.min.js +0 -5
  143. package/src/libs/hephaestus/HTMLElementGenerator/LICENSE +0 -21
  144. package/src/libs/js-cookie/LICENSE +0 -21
  145. package/src/libs/js-cookie/src/api.mjs +0 -103
  146. package/src/libs/js-cookie/src/assign.mjs +0 -10
  147. package/src/libs/js-cookie/src/converter.mjs +0 -14
  148. package/src/libs/libs.js +0 -13
@@ -0,0 +1,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
+ * @returns {{element: HTMLFormElement, fields: Object<string, object>, getValues: Function, setValues: Function,
91
+ * setErrors: Function, validate: Function, reset: Function, setMessage: Function, submitButton: object}}
92
+ */
93
+ export function generateForm(options?: {
94
+ parent?: string | Element;
95
+ id?: string;
96
+ fields: object[];
97
+ submitText?: string;
98
+ resetText?: string | false;
99
+ onSubmit?: (values: object, form: object) => (void | Promise<any>);
100
+ onChange?: (values: object, field: object) => void;
101
+ }): {
102
+ element: HTMLFormElement;
103
+ fields: {
104
+ [x: string]: object;
105
+ };
106
+ getValues: Function;
107
+ setValues: Function;
108
+ setErrors: Function;
109
+ validate: Function;
110
+ reset: Function;
111
+ setMessage: Function;
112
+ submitButton: object;
113
+ };
@@ -0,0 +1,8 @@
1
+ export function generateFormDiv(formId: any, className: any, parent?: string): HTMLElement;
2
+ export function generateRow(formId: any, name: any): string;
3
+ export function generateField(formId: any, name: any, label: any, inputType: any): void;
4
+ export function generateButton(formId: any, name: any, text: any, onclick: any): void;
5
+ export function generateMessage(formId: any): void;
6
+ export function showMessage(formId: any, text: any, isError?: boolean): void;
7
+ export function readControl(formId: any, name: any): any;
8
+ export { EMAIL_PATTERN } from "../../core/validation.js";
@@ -0,0 +1,11 @@
1
+ export function getLoginFormData(): {
2
+ username: any;
3
+ password: any;
4
+ };
5
+ export function generateLoginForm(): void;
6
+ export function generateFormDiv(): void;
7
+ export function generateFormElements(): void;
8
+ export function generateUsernameElements(): void;
9
+ export function generatePasswordElements(): void;
10
+ export function generateRememberElement(): void;
11
+ export function generateSubmitElement(): void;
@@ -0,0 +1,4 @@
1
+ export function getLostPasswordFormData(): {
2
+ email: any;
3
+ };
4
+ export function generateLostPasswordForm(parent?: string): void;
@@ -0,0 +1,7 @@
1
+ export function getRegistrationFormData(): {
2
+ username: any;
3
+ email: any;
4
+ password: any;
5
+ };
6
+ export function validateRegistrationForm(): string;
7
+ export function generateRegistrationForm(parent?: string): void;
@@ -0,0 +1,3 @@
1
+ export function loadScript(src: any): any;
2
+ export function resolveTheme(selected: any): any;
3
+ export function loadTheme(selected: any): Promise<any>;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Generates a drag-and-drop area. Files dropped on it (or picked with the browser dialog after a click / Enter / Space)
3
+ * are checked against `accept`, `maxSize` and `maxFiles`; the valid ones are passed to `onDrop`, the rest to `onReject`.
4
+ * Nothing is read or sent: what to do with the files is up to the caller (generateFileUpload builds on this).
5
+ *
6
+ * @param {object} options
7
+ * @param {string|Element} [options.parent]
8
+ * @param {string} [options.id]
9
+ * @param {string} [options.class]
10
+ * @param {*} [options.content] text, Node, array or function; the default is the localized "Drop files here" text
11
+ * @param {string} [options.accept] like ".png,image/*"
12
+ * @param {boolean} [options.multiple=true]
13
+ * @param {number} [options.maxSize] bytes per file
14
+ * @param {number} [options.maxFiles] files accepted per drop
15
+ * @param {boolean} [options.clickable=true] click / Enter / Space opens the file dialog
16
+ * @param {boolean} [options.disabled=false]
17
+ * @param {(files: File[]) => void} [options.onDrop] valid files
18
+ * @param {(rejected: {file: File, reason: string}[]) => void} [options.onReject]
19
+ * @param {(over: boolean) => void} [options.onDragChange] a drag entered / left the area
20
+ * @returns {{element: HTMLElement, input: HTMLInputElement, handleFiles: (files: Iterable<File>) => void,
21
+ * setDisabled: (disabled: boolean) => void, open: () => void}}
22
+ */
23
+ export function createDropZone(options?: {
24
+ parent?: string | Element;
25
+ id?: string;
26
+ class?: string;
27
+ content?: any;
28
+ accept?: string;
29
+ multiple?: boolean;
30
+ maxSize?: number;
31
+ maxFiles?: number;
32
+ clickable?: boolean;
33
+ disabled?: boolean;
34
+ onDrop?: (files: File[]) => void;
35
+ onReject?: (rejected: {
36
+ file: File;
37
+ reason: string;
38
+ }[]) => void;
39
+ onDragChange?: (over: boolean) => void;
40
+ }): {
41
+ element: HTMLElement;
42
+ input: HTMLInputElement;
43
+ handleFiles: (files: Iterable<File>) => void;
44
+ setDisabled: (disabled: boolean) => void;
45
+ open: () => void;
46
+ };
47
+ /** Generates a drag-and-drop area into `parent`, see createDropZone. */
48
+ export function generateDropZone(options?: {}): any;
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Generates an input with suggestions. `options` is an array of strings / { value, text }, or a function
3
+ * (query) => options | Promise<options> for remote data.
4
+ *
5
+ * @param {object} options
6
+ * @param {string|Element} [options.parent]
7
+ * @param {string} [options.label]
8
+ * @param {Array|Function} options.options
9
+ * @param {number} [options.minChars=1] characters needed before suggestions show
10
+ * @param {boolean} [options.strict=false] only a value chosen from the list is accepted
11
+ * @param {(item: {value, text}) => void} [options.onSelect]
12
+ * @param {(value) => void} [options.onChange]
13
+ * @returns {{element: HTMLElement, input: HTMLInputElement, getValue: Function, setValue: Function}}
14
+ */
15
+ export function generateAutocomplete(options?: {
16
+ parent?: string | Element;
17
+ label?: string;
18
+ options: any[] | Function;
19
+ minChars?: number;
20
+ strict?: boolean;
21
+ onSelect?: (item: {
22
+ value: any;
23
+ text: any;
24
+ }) => void;
25
+ onChange?: (value: any) => void;
26
+ }): {
27
+ element: HTMLElement;
28
+ input: HTMLInputElement;
29
+ getValue: Function;
30
+ setValue: Function;
31
+ };
32
+ /**
33
+ * Generates a multiple selection with chips. Same options as generateAutocomplete; getValue returns an array.
34
+ */
35
+ export function generateMultiSelect(options?: {}): any;
36
+ /**
37
+ * Generates a from / to date picker (the native pickers of the browser). The end date cannot be picked before
38
+ * the start date, and validate() reports a reversed range typed by hand.
39
+ *
40
+ * @param {object} options
41
+ * @param {string|Element} [options.parent]
42
+ * @param {string} [options.label]
43
+ * @param {string} [options.from] initial start, "2026-01-31"
44
+ * @param {string} [options.to] initial end
45
+ * @param {string} [options.min] earliest date
46
+ * @param {string} [options.max] latest date
47
+ * @param {(value: {from: string, to: string}) => void} [options.onChange]
48
+ * @returns {{element: HTMLElement, getValue: () => {from: string, to: string}, setValue: Function, validate: () => string}}
49
+ */
50
+ export function generateDateRange(options?: {
51
+ parent?: string | Element;
52
+ label?: string;
53
+ from?: string;
54
+ to?: string;
55
+ min?: string;
56
+ max?: string;
57
+ onChange?: (value: {
58
+ from: string;
59
+ to: string;
60
+ }) => void;
61
+ }): {
62
+ element: HTMLElement;
63
+ getValue: () => {
64
+ from: string;
65
+ to: string;
66
+ };
67
+ setValue: Function;
68
+ validate: () => string;
69
+ };
70
+ /**
71
+ * Generates a from / to range with date AND time (datetime-local inputs), and a list of presets: last 15 minutes, hour,
72
+ * 24 hours, 7 days, 30 days, or "Custom". For log filters, charts and reports that need times, not whole days.
73
+ * A preset moves with the clock: getRange() measures it from now when it is called.
74
+ *
75
+ * @param {object} options
76
+ * @param {string|Element} [options.parent]
77
+ * @param {string} [options.label]
78
+ * @param {string} [options.from] initial start, "2026-01-31T08:00"
79
+ * @param {string} [options.to] initial end
80
+ * @param {string} [options.preset] id of the preset to start with ("15m", "1h", "24h", "7d", "30d")
81
+ * @param {{id: string, label?: string, labelKey?: string, minutes: number}[]} [options.presets] your own list
82
+ * @param {boolean} [options.seconds=false]
83
+ * @param {string} [options.min]
84
+ * @param {string} [options.max]
85
+ * @param {(value: {from: string, to: string, preset: string}) => void} [options.onChange]
86
+ * @returns {{element: HTMLElement, getValue: Function, getRange: () => ({from: Date|null, to: Date|null}), setValue: Function, validate: () => string}}
87
+ */
88
+ export function generateDateTimeRange(options?: {
89
+ parent?: string | Element;
90
+ label?: string;
91
+ from?: string;
92
+ to?: string;
93
+ preset?: string;
94
+ presets?: {
95
+ id: string;
96
+ label?: string;
97
+ labelKey?: string;
98
+ minutes: number;
99
+ }[];
100
+ seconds?: boolean;
101
+ min?: string;
102
+ max?: string;
103
+ onChange?: (value: {
104
+ from: string;
105
+ to: string;
106
+ preset: string;
107
+ }) => void;
108
+ }): {
109
+ element: HTMLElement;
110
+ getValue: Function;
111
+ getRange: () => ({
112
+ from: Date | null;
113
+ to: Date | null;
114
+ });
115
+ setValue: Function;
116
+ validate: () => string;
117
+ };
118
+ /**
119
+ * Generates a drop zone with a file list and upload progress.
120
+ *
121
+ * @param {object} options
122
+ * @param {string|Element} [options.parent]
123
+ * @param {string} [options.accept] ".png,image/*"
124
+ * @param {boolean} [options.multiple=true]
125
+ * @param {number} [options.maxSize] bytes per file
126
+ * @param {string} [options.url] upload endpoint (multipart POST). Without it the files are only collected.
127
+ * @param {string} [options.fieldName="file"] name of the form field the file is sent as
128
+ * @param {Object<string,string>} [options.headers]
129
+ * @param {boolean} [options.autoUpload=true] upload as soon as files are added
130
+ * @param {(files: File[]) => void} [options.onSelect]
131
+ * @param {(file: File, percent: number) => void} [options.onProgress]
132
+ * @param {(file: File, response: string) => void} [options.onComplete]
133
+ * @param {(file: File, error: Error) => void} [options.onError]
134
+ * @returns {{element: HTMLElement, getFiles: () => File[], upload: () => Promise<void>, clear: Function}}
135
+ */
136
+ export function generateFileUpload(options?: {
137
+ parent?: string | Element;
138
+ accept?: string;
139
+ multiple?: boolean;
140
+ maxSize?: number;
141
+ url?: string;
142
+ fieldName?: string;
143
+ headers?: {
144
+ [x: string]: string;
145
+ };
146
+ autoUpload?: boolean;
147
+ onSelect?: (files: File[]) => void;
148
+ onProgress?: (file: File, percent: number) => void;
149
+ onComplete?: (file: File, response: string) => void;
150
+ onError?: (file: File, error: Error) => void;
151
+ }): {
152
+ element: HTMLElement;
153
+ getFiles: () => File[];
154
+ upload: () => Promise<void>;
155
+ clear: Function;
156
+ };
157
+ /**
158
+ * Generates a multi step form (wizard).
159
+ *
160
+ * @param {object} options
161
+ * @param {string|Element} [options.parent]
162
+ * @param {{id?: string, title: string, content: *, validate?: () => (boolean|string|Promise<boolean|string>)}[]} options.steps
163
+ * content is text, a Node, an array, or a function called once when the step is first shown.
164
+ * `validate` runs before leaving the step forwards: false or an error text blocks it.
165
+ * @param {() => void} [options.onFinish] called when Finish is pressed on the last step
166
+ * @param {(index: number) => void} [options.onChange]
167
+ * @returns {{element: HTMLElement, next: Function, back: Function, goTo: Function, getCurrent: Function}}
168
+ */
169
+ export function generateStepper(options?: {
170
+ parent?: string | Element;
171
+ steps: {
172
+ id?: string;
173
+ title: string;
174
+ content: any;
175
+ validate?: () => (boolean | string | Promise<boolean | string>);
176
+ }[];
177
+ onFinish?: () => void;
178
+ onChange?: (index: number) => void;
179
+ }): {
180
+ element: HTMLElement;
181
+ next: Function;
182
+ back: Function;
183
+ goTo: Function;
184
+ getCurrent: Function;
185
+ };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Generates a rich text editor. The content is HTML restricted to a safe set of tags (paragraphs, headings,
3
+ * bold / italic / underline / strike, lists, quotes, code, links); everything else, including scripts, styles,
4
+ * event attributes and `javascript:` links, is removed when the content is set, pasted and read.
5
+ *
6
+ * @param {object} options
7
+ * @param {string|Element} [options.parent]
8
+ * @param {string} [options.id]
9
+ * @param {string} [options.label]
10
+ * @param {string} [options.value] initial HTML
11
+ * @param {string} [options.placeholder]
12
+ * @param {string[]} [options.toolbar] button names (bold, italic, underline, strike, h2, h3, quote, ul, ol, link,
13
+ * unlink, clear, undo, redo, source) and "|" separators. `source` switches between the visual editor and
14
+ * the sanitized HTML source.
15
+ * @param {number} [options.minHeight=140] px
16
+ * @param {boolean} [options.disabled]
17
+ * @param {(html: string) => void} [options.onChange]
18
+ * @returns {{element: HTMLElement, editor: HTMLElement, getValue: () => string, setValue: (html: string) => void,
19
+ * getText: () => string, focus: Function}}
20
+ */
21
+ export function createRichText(options?: {
22
+ parent?: string | Element;
23
+ id?: string;
24
+ label?: string;
25
+ value?: string;
26
+ placeholder?: string;
27
+ toolbar?: string[];
28
+ minHeight?: number;
29
+ disabled?: boolean;
30
+ onChange?: (html: string) => void;
31
+ }): {
32
+ element: HTMLElement;
33
+ editor: HTMLElement;
34
+ getValue: () => string;
35
+ setValue: (html: string) => void;
36
+ getText: () => string;
37
+ focus: Function;
38
+ };
39
+ /** Generates a labelled rich text editor, see createRichText. */
40
+ export function generateRichText(options?: {}): any;
41
+ export function createWysiwyg(options?: {}): {
42
+ element: HTMLElement;
43
+ editor: HTMLElement;
44
+ getValue: () => string;
45
+ setValue: (html: string) => void;
46
+ getText: () => string;
47
+ focus: Function;
48
+ };
49
+ export function generateWysiwyg(options?: {}): any;
@@ -0,0 +1,2 @@
1
+ export function openModal(id?: string): void;
2
+ export function closeModal(id?: string): void;
@@ -0,0 +1,150 @@
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.
93
+ *
94
+ * @param {object} options
95
+ * @param {string|Element} [options.parent]
96
+ * @param {string} [options.label] button text (leave it out for an icon-only button, and give `ariaLabel`)
97
+ * @param {string|Node} [options.icon] shown before the label, text or a Node (e.g. an SVG); hidden from screen readers
98
+ * @param {string} [options.ariaLabel] accessible name, needed when there is no label
99
+ * @param {boolean} [options.caret=false] show a small arrow after the label
100
+ * @param {string} [options.toggleClass] extra CSS class(es) of the toggle button
101
+ * @param {{label?: string, onclick?: Function, href?: string, disabled?: boolean, divider?: boolean}[]} options.items
102
+ * @param {"left"|"right"} [options.align="left"]
103
+ * @returns {{element: HTMLElement, open: Function, close: Function}}
104
+ */
105
+ export function generateDropdown(options?: {
106
+ parent?: string | Element;
107
+ label?: string;
108
+ icon?: string | Node;
109
+ ariaLabel?: string;
110
+ caret?: boolean;
111
+ toggleClass?: string;
112
+ items: {
113
+ label?: string;
114
+ onclick?: Function;
115
+ href?: string;
116
+ disabled?: boolean;
117
+ divider?: boolean;
118
+ }[];
119
+ align?: "left" | "right";
120
+ }): {
121
+ element: HTMLElement;
122
+ open: Function;
123
+ close: Function;
124
+ };
125
+ /**
126
+ * Generates a vertical navigation with nested items. On small screens it collapses behind a toggle button.
127
+ *
128
+ * @param {object} options
129
+ * @param {string|Element} [options.parent]
130
+ * @param {{id: string, label: string, icon?: string, href?: string, children?: object[]}[]} options.items
131
+ * @param {(item: object) => void} [options.onSelect]
132
+ * @param {string} [options.active] id of the initially selected item
133
+ * @returns {{element: HTMLElement, select: (id: string) => void, toggle: Function}}
134
+ */
135
+ export function generateSidebar(options?: {
136
+ parent?: string | Element;
137
+ items: {
138
+ id: string;
139
+ label: string;
140
+ icon?: string;
141
+ href?: string;
142
+ children?: object[];
143
+ }[];
144
+ onSelect?: (item: object) => void;
145
+ active?: string;
146
+ }): {
147
+ element: HTMLElement;
148
+ select: (id: string) => void;
149
+ toggle: Function;
150
+ };
@@ -0,0 +1,12 @@
1
+ export function normalizePath(path: any): string;
2
+ export function parseQuery(search: any): {
3
+ [k: string]: string;
4
+ };
5
+ /**
6
+ * Matches a path against a pattern. `:name` segments capture a value, a trailing `*` matches the rest.
7
+ *
8
+ * @returns {Object<string, string>|null} the captured params, or null when the path does not match
9
+ */
10
+ export function matchRoute(pattern: any, path: any): {
11
+ [x: string]: string;
12
+ } | null;
@@ -0,0 +1,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 {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
+ };