compostrap 0.0.0-stage → 1.0.1

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 (198) hide show
  1. package/dist/css/auth.css +166 -0
  2. package/dist/css/blog.css +512 -0
  3. package/dist/css/chart.css +99 -0
  4. package/dist/css/compostrap.css +5052 -0
  5. package/dist/css/dashboard.css +360 -0
  6. package/dist/css/datagrid.css +64 -0
  7. package/dist/css/datepicker.css +514 -0
  8. package/dist/css/dialogs.css +185 -0
  9. package/dist/css/dropzone.css +86 -0
  10. package/dist/css/elements.css +181 -0
  11. package/dist/css/empty.css +94 -0
  12. package/dist/css/gallery.css +122 -0
  13. package/dist/css/lightbox.css +144 -0
  14. package/dist/css/number-input.css +100 -0
  15. package/dist/css/otp-input.css +177 -0
  16. package/dist/css/password-toggle.css +52 -0
  17. package/dist/css/rating.css +95 -0
  18. package/dist/css/selection.css +59 -0
  19. package/dist/css/settings.css +85 -0
  20. package/dist/css/shop.css +1026 -0
  21. package/dist/css/sidebar-menu.css +439 -0
  22. package/dist/css/sidebar.css +95 -0
  23. package/dist/css/spinner.css +102 -0
  24. package/dist/css/strength.css +118 -0
  25. package/dist/css/theme-switcher.css +5 -0
  26. package/dist/css/theme.css +13034 -0
  27. package/dist/css/tooltip.css +158 -0
  28. package/dist/js/chart.js +257 -0
  29. package/dist/js/datepicker.js +82 -0
  30. package/dist/js/dialogs.js +7 -0
  31. package/dist/js/dropzone.js +15 -0
  32. package/dist/js/index.js +24 -0
  33. package/dist/js/lightbox.js +77 -0
  34. package/dist/js/number-input.js +44 -0
  35. package/dist/js/otp-input.js +182 -0
  36. package/dist/js/password-toggle.js +16 -0
  37. package/dist/js/selection.js +32 -0
  38. package/dist/js/sidebar-menu.js +76 -0
  39. package/dist/js/sidebar.js +120 -0
  40. package/dist/js/spinner.js +27 -0
  41. package/dist/js/strength.js +87 -0
  42. package/dist/js/theme-switcher.js +98 -0
  43. package/dist/js/tooltip.js +17 -0
  44. package/docs/auth.md +25 -0
  45. package/docs/blog.md +85 -0
  46. package/docs/chart.md +39 -0
  47. package/docs/datagrid.md +64 -0
  48. package/docs/datepicker.md +35 -0
  49. package/docs/dialogs.md +81 -0
  50. package/docs/dropzone.md +23 -0
  51. package/docs/elements.md +38 -0
  52. package/docs/empty.md +25 -0
  53. package/docs/gallery.md +23 -0
  54. package/docs/layout.md +143 -0
  55. package/docs/lightbox.md +18 -0
  56. package/docs/number-input.md +19 -0
  57. package/docs/otp-input.md +52 -0
  58. package/docs/password-toggle.md +21 -0
  59. package/docs/rating.md +15 -0
  60. package/docs/selection.md +52 -0
  61. package/docs/settings.md +25 -0
  62. package/docs/shop.md +140 -0
  63. package/docs/spinner.md +51 -0
  64. package/docs/strength.md +26 -0
  65. package/docs/theme-switcher.md +60 -0
  66. package/docs/theme.md +100 -0
  67. package/docs/tooltip.md +30 -0
  68. package/license +21 -0
  69. package/package.json +106 -6
  70. package/readme.md +198 -0
  71. package/src/illustrations/empty.svg +15 -0
  72. package/src/illustrations/forbidden.svg +16 -0
  73. package/src/illustrations/maintenance.svg +14 -0
  74. package/src/illustrations/not-found.svg +22 -0
  75. package/src/illustrations/server-error.svg +21 -0
  76. package/src/js/chart.js +359 -0
  77. package/src/js/datepicker.js +154 -0
  78. package/src/js/dialogs.js +25 -0
  79. package/src/js/dropzone.js +35 -0
  80. package/src/js/index.js +29 -0
  81. package/src/js/lightbox.js +165 -0
  82. package/src/js/number-input.js +87 -0
  83. package/src/js/otp-input.js +401 -0
  84. package/src/js/password-toggle.js +45 -0
  85. package/src/js/selection.js +114 -0
  86. package/src/js/sidebar-menu.js +178 -0
  87. package/src/js/sidebar.js +326 -0
  88. package/src/js/spinner.js +76 -0
  89. package/src/js/strength.js +115 -0
  90. package/src/js/theme-switcher.js +197 -0
  91. package/src/js/tooltip.js +46 -0
  92. package/src/scss/_bootstrap.scss +9 -0
  93. package/src/scss/_variables.scss +58 -0
  94. package/src/scss/auth/_index.scss +210 -0
  95. package/src/scss/auth.scss +5 -0
  96. package/src/scss/blog/_article.scss +181 -0
  97. package/src/scss/blog/_comments.scss +108 -0
  98. package/src/scss/blog/_index.scss +18 -0
  99. package/src/scss/blog/_list.scss +246 -0
  100. package/src/scss/blog/_page.scss +138 -0
  101. package/src/scss/blog.scss +5 -0
  102. package/src/scss/chart/_index.scss +114 -0
  103. package/src/scss/chart.scss +5 -0
  104. package/src/scss/compostrap.scss +29 -0
  105. package/src/scss/dashboard/_content.scss +25 -0
  106. package/src/scss/dashboard/_dropdown.scss +71 -0
  107. package/src/scss/dashboard/_index.scss +9 -0
  108. package/src/scss/dashboard/_nanobar.scss +34 -0
  109. package/src/scss/dashboard/_navbar.scss +314 -0
  110. package/src/scss/dashboard/_theme.scss +27 -0
  111. package/src/scss/dashboard.scss +5 -0
  112. package/src/scss/datagrid/_index.scss +111 -0
  113. package/src/scss/datagrid.scss +5 -0
  114. package/src/scss/datepicker/_index.scss +557 -0
  115. package/src/scss/datepicker.scss +5 -0
  116. package/src/scss/dialogs/_index.scss +8 -0
  117. package/src/scss/dialogs/_modal.scss +82 -0
  118. package/src/scss/dialogs/_offcanvas.scss +13 -0
  119. package/src/scss/dialogs/_search.scss +79 -0
  120. package/src/scss/dialogs/_toast.scss +61 -0
  121. package/src/scss/dialogs.scss +5 -0
  122. package/src/scss/dropzone/_index.scss +111 -0
  123. package/src/scss/dropzone.scss +5 -0
  124. package/src/scss/elements/_datagrid-filter.scss +21 -0
  125. package/src/scss/elements/_index.scss +9 -0
  126. package/src/scss/elements/_list-row.scss +40 -0
  127. package/src/scss/elements/_loading.scss +47 -0
  128. package/src/scss/elements/_stat.scss +73 -0
  129. package/src/scss/elements/_status-dot.scss +38 -0
  130. package/src/scss/elements.scss +5 -0
  131. package/src/scss/empty/_index.scss +117 -0
  132. package/src/scss/empty.scss +5 -0
  133. package/src/scss/gallery/_index.scss +162 -0
  134. package/src/scss/gallery.scss +5 -0
  135. package/src/scss/lightbox/_index.scss +171 -0
  136. package/src/scss/lightbox.scss +5 -0
  137. package/src/scss/number-input/_index.scss +143 -0
  138. package/src/scss/number-input.scss +5 -0
  139. package/src/scss/otp-input/_index.scss +214 -0
  140. package/src/scss/otp-input.scss +5 -0
  141. package/src/scss/password-toggle/_index.scss +82 -0
  142. package/src/scss/password-toggle.scss +5 -0
  143. package/src/scss/rating/_index.scss +121 -0
  144. package/src/scss/rating.scss +5 -0
  145. package/src/scss/selection/_index.scss +84 -0
  146. package/src/scss/selection.scss +5 -0
  147. package/src/scss/settings/_index.scss +6 -0
  148. package/src/scss/settings/_nav-list.scss +52 -0
  149. package/src/scss/settings/_setting-row.scss +50 -0
  150. package/src/scss/settings.scss +5 -0
  151. package/src/scss/shop/_bar.scss +64 -0
  152. package/src/scss/shop/_catalog.scss +308 -0
  153. package/src/scss/shop/_checkout.scss +204 -0
  154. package/src/scss/shop/_filters.scss +116 -0
  155. package/src/scss/shop/_hero.scss +130 -0
  156. package/src/scss/shop/_index.scss +22 -0
  157. package/src/scss/shop/_page.scss +154 -0
  158. package/src/scss/shop/_reviews.scss +165 -0
  159. package/src/scss/shop/_stepper.scss +159 -0
  160. package/src/scss/shop.scss +5 -0
  161. package/src/scss/sidebar/_body.scss +8 -0
  162. package/src/scss/sidebar/_index.scss +8 -0
  163. package/src/scss/sidebar/_sidebar.scss +89 -0
  164. package/src/scss/sidebar/_theme.scss +7 -0
  165. package/src/scss/sidebar/_wrapper.scss +17 -0
  166. package/src/scss/sidebar-menu/_compact.scss +174 -0
  167. package/src/scss/sidebar-menu/_index.scss +9 -0
  168. package/src/scss/sidebar-menu/_list.scss +131 -0
  169. package/src/scss/sidebar-menu/_pills.scss +82 -0
  170. package/src/scss/sidebar-menu/_scrollbar.scss +53 -0
  171. package/src/scss/sidebar-menu/_theme.scss +109 -0
  172. package/src/scss/sidebar-menu.scss +5 -0
  173. package/src/scss/sidebar.scss +5 -0
  174. package/src/scss/spinner/_index.scss +130 -0
  175. package/src/scss/spinner.scss +5 -0
  176. package/src/scss/strength/_index.scss +118 -0
  177. package/src/scss/strength.scss +5 -0
  178. package/src/scss/theme/_accordion.scss +20 -0
  179. package/src/scss/theme/_alerts.scss +24 -0
  180. package/src/scss/theme/_avatar.scss +37 -0
  181. package/src/scss/theme/_badges.scss +53 -0
  182. package/src/scss/theme/_base.scss +9 -0
  183. package/src/scss/theme/_breadcrumb.scss +64 -0
  184. package/src/scss/theme/_buttons.scss +200 -0
  185. package/src/scss/theme/_cards.scss +17 -0
  186. package/src/scss/theme/_colors.scss +139 -0
  187. package/src/scss/theme/_forms.scss +175 -0
  188. package/src/scss/theme/_index.scss +18 -0
  189. package/src/scss/theme/_navs.scss +15 -0
  190. package/src/scss/theme/_overlays.scss +128 -0
  191. package/src/scss/theme/_tables.scss +59 -0
  192. package/src/scss/theme/_variables.scss +194 -0
  193. package/src/scss/theme-switcher/_index.scss +9 -0
  194. package/src/scss/theme-switcher.scss +5 -0
  195. package/src/scss/theme.scss +9 -0
  196. package/src/scss/tooltip/_index.scss +177 -0
  197. package/src/scss/tooltip.scss +5 -0
  198. package/README.md +0 -3
@@ -0,0 +1,114 @@
1
+ /**
2
+ * RowSelection: rows of a table chosen by checkboxes and a bar with the actions for them (the bulk actions of
3
+ * a datagrid). Inside a [data-selection] wrapper the checkbox [data-selection-all] checks all [data-selection-item]
4
+ * checkboxes (and shows a dash when only some are checked), a chosen row gets the class table-active, the bar
5
+ * [data-selection-bar] is shown while a row is chosen, [data-selection-count] holds their number and
6
+ * [data-selection-clear] unchecks them. The checkboxes are found on every change, so a table drawn again
7
+ * (an AJAX snippet) needs no new init(); call RowSelection.update(wrapper) after such a redraw to bring the bar
8
+ * in line with the new rows.
9
+ *
10
+ * Optional parts: a button of the bar with [data-selection-single] is for one row only and is disabled while
11
+ * more rows are chosen; with [data-selection-rows] on the wrapper a click anywhere on a row chooses it like its
12
+ * checkbox (not a click on a link, a button, a field or a label, not a click in a cell with a
13
+ * button, and not the end of selecting a text).
14
+ *
15
+ * <div data-selection>
16
+ * <table>
17
+ * <thead><tr><th><input type="checkbox" data-selection-all></th>…</tr></thead>
18
+ * <tbody><tr><td><input type="checkbox" data-selection-item name="ids[]" value="1"></td>…</tr></tbody>
19
+ * </table>
20
+ * <div class="selection-bar" data-selection-bar hidden>
21
+ * <strong data-selection-count>0</strong> selected … <button type="button" data-selection-clear></button>
22
+ * </div>
23
+ * </div>
24
+ */
25
+ export class RowSelection {
26
+ static _initialized = false;
27
+
28
+ static init() {
29
+ if (this._initialized) {
30
+ return;
31
+ }
32
+
33
+ this._initialized = true;
34
+
35
+ document.addEventListener('change', (event) => {
36
+ const input = event.target.closest?.('[data-selection-all], [data-selection-item]');
37
+ const wrapper = input?.closest('[data-selection]');
38
+ if (!wrapper) {
39
+ return;
40
+ }
41
+
42
+ if (input.matches('[data-selection-all]')) {
43
+ this.items(wrapper).forEach((item) => item.checked = input.checked);
44
+ }
45
+
46
+ this.update(wrapper);
47
+ });
48
+
49
+ document.addEventListener('click', (event) => {
50
+ const wrapper = event.target.closest('[data-selection-clear]')?.closest('[data-selection]');
51
+ if (wrapper) {
52
+ this.clear(wrapper);
53
+ return;
54
+ }
55
+
56
+ this._clickRow(event);
57
+ });
58
+
59
+ // checkboxes kept checked by the browser after a reload
60
+ document.querySelectorAll('[data-selection]').forEach((wrapper) => this.update(wrapper));
61
+ }
62
+
63
+ /** A click on a row of a [data-selection-rows] wrapper chooses the row like its checkbox. */
64
+ static _clickRow(event) {
65
+ const row = event.target.closest('tbody tr');
66
+ const wrapper = row?.closest('[data-selection-rows]');
67
+ if (!wrapper || event.target.closest('a, button, input, select, textarea, label, [data-bs-toggle]')) {
68
+ return;
69
+ }
70
+
71
+ // a cell with a button or a menu of the row: a click next to it was meant for it
72
+ if (event.target.closest('td')?.querySelector('button, .btn')) {
73
+ return;
74
+ }
75
+
76
+ // dragging over a text to copy it ends with a click too
77
+ if (!window.getSelection()?.isCollapsed) {
78
+ return;
79
+ }
80
+
81
+ const item = row.querySelector('[data-selection-item]:not(:disabled)');
82
+ if (item) {
83
+ item.checked = !item.checked;
84
+ item.dispatchEvent(new Event('change', { bubbles: true }));
85
+ }
86
+ }
87
+
88
+ /** The checkboxes of the rows that can be chosen. */
89
+ static items(wrapper) {
90
+ return [...wrapper.querySelectorAll('[data-selection-item]:not(:disabled)')];
91
+ }
92
+
93
+ /** Unchecks all rows. */
94
+ static clear(wrapper) {
95
+ this.items(wrapper).forEach((item) => item.checked = false);
96
+ this.update(wrapper);
97
+ }
98
+
99
+ /** Brings the "select all" checkbox, the rows, the count and the bar in line with the checked rows. */
100
+ static update(wrapper) {
101
+ const items = this.items(wrapper);
102
+ const count = items.filter((item) => item.checked).length;
103
+
104
+ items.forEach((item) => item.closest('tr')?.classList.toggle('table-active', item.checked));
105
+
106
+ wrapper.querySelectorAll('[data-selection-all]').forEach((all) => {
107
+ all.checked = count > 0 && count === items.length;
108
+ all.indeterminate = count > 0 && count < items.length;
109
+ });
110
+ wrapper.querySelectorAll('[data-selection-count]').forEach((element) => element.textContent = String(count));
111
+ wrapper.querySelectorAll('[data-selection-single]').forEach((button) => button.disabled = count !== 1);
112
+ wrapper.querySelectorAll('[data-selection-bar]').forEach((bar) => bar.hidden = count === 0);
113
+ }
114
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ ** Multi-level sidebar menu
3
+ ** Built on Bootstrap 5
4
+ **/
5
+ export class SidebarMenu {
6
+ // a submenu opens at once; a duration in ms (e.g. 200) slides it open instead
7
+ static slideDuration = 0;
8
+ static _slideStates = new WeakMap();
9
+ static _submenuId = 0;
10
+
11
+ static init() {
12
+ const elements = document.querySelectorAll('.list-item');
13
+ const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
14
+ const duration = reduceMotion ? 0 : this.slideDuration;
15
+
16
+ elements.forEach((el) => {
17
+ const links = el.querySelectorAll('a.link-arrow');
18
+
19
+ links.forEach((link) => {
20
+ const submenu = link.nextElementSibling;
21
+ if (!submenu) return;
22
+ if (link.dataset.sidebarMenuInitialized === 'true') return;
23
+
24
+ link.dataset.sidebarMenuInitialized = 'true';
25
+ link.classList.add('up');
26
+ if (!submenu.id) {
27
+ submenu.id = `sidebar-submenu-${++this._submenuId}`;
28
+ }
29
+ link.setAttribute('aria-controls', submenu.id);
30
+
31
+ if (link.classList.contains('link-current')) {
32
+ link.classList.add('active', 'down');
33
+ submenu.style.display = 'block';
34
+ }
35
+ link.setAttribute('aria-expanded', String(submenu.style.display === 'block'));
36
+
37
+ // a link that only opens its submenu has no address (the browser shows none in its status bar), so it
38
+ // becomes a button for the keyboard and screen readers
39
+ if (!link.hasAttribute('href')) {
40
+ link.setAttribute('role', 'button');
41
+ link.tabIndex = 0;
42
+ link.addEventListener('keydown', (event) => {
43
+ if (event.key === 'Enter' || event.key === ' ') {
44
+ event.preventDefault();
45
+ link.click();
46
+ }
47
+ });
48
+ }
49
+
50
+ link.addEventListener('click', (event) => {
51
+ // the compact sidebar (Sidebar) shows the links of a group in a menu next to its icon; the submenu
52
+ // keeps its state for the wide sidebar
53
+ if (this._isCompact()) {
54
+ return;
55
+ }
56
+
57
+ event.preventDefault();
58
+ const expanded = this._slideToggle(submenu, duration);
59
+ link.setAttribute('aria-expanded', String(expanded));
60
+
61
+ if (link.classList.contains('down')) {
62
+ link.classList.toggle('rotate-revert');
63
+ }
64
+
65
+ link.classList.add('transition');
66
+ link.classList.toggle('active');
67
+ link.classList.toggle('rotate');
68
+ });
69
+ });
70
+ });
71
+
72
+ document.querySelectorAll('.list-link.link-current:not(.link-arrow)').forEach((link) => {
73
+ link.setAttribute('aria-current', 'page');
74
+ });
75
+ }
76
+
77
+ // the compact sidebar with the icons only (html.sidebar-compact, from md up), the same test as Sidebar.isCompact()
78
+ static _isCompact() {
79
+ return document.documentElement.classList.contains('sidebar-compact') && window.matchMedia('(min-width: 768px)').matches;
80
+ }
81
+
82
+ static _slideToggle(target, duration) {
83
+ const state = this._slideStates.get(target);
84
+ const isOpen = state
85
+ ? state.open
86
+ : window.getComputedStyle(target).display !== 'none';
87
+
88
+ if (!isOpen) {
89
+ this._slideDown(target, duration);
90
+ } else {
91
+ this._slideUp(target, duration);
92
+ }
93
+
94
+ return !isOpen;
95
+ }
96
+
97
+ static _slideUp(target, duration) {
98
+ this._animate(target, false, duration);
99
+ }
100
+
101
+ static _slideDown(target, duration) {
102
+ this._animate(target, true, duration);
103
+ }
104
+
105
+ static _animate(target, open, duration) {
106
+ const previousState = this._slideStates.get(target);
107
+ const currentHeight = target.getBoundingClientRect().height;
108
+ if (previousState?.timer) {
109
+ clearTimeout(previousState.timer);
110
+ }
111
+
112
+ if (open) {
113
+ target.style.display = 'block';
114
+ }
115
+
116
+ [
117
+ 'height',
118
+ 'padding-top',
119
+ 'padding-bottom',
120
+ 'margin-top',
121
+ 'margin-bottom',
122
+ 'overflow',
123
+ 'box-sizing',
124
+ 'transition-duration',
125
+ 'transition-property'
126
+ ].forEach((prop) => target.style.removeProperty(prop));
127
+
128
+ const naturalHeight = target.offsetHeight;
129
+ target.style.overflow = 'hidden';
130
+ target.style.boxSizing = 'border-box';
131
+ target.style.height = currentHeight + 'px';
132
+ target.style.paddingTop = open ? '0' : '';
133
+ target.style.paddingBottom = open ? '0' : '';
134
+ target.style.marginTop = open ? '0' : '';
135
+ target.style.marginBottom = open ? '0' : '';
136
+ target.offsetHeight;
137
+
138
+ target.style.transitionProperty = 'height, margin, padding';
139
+ target.style.transitionDuration = duration + 'ms';
140
+ target.style.height = open ? naturalHeight + 'px' : '0';
141
+ if (open) {
142
+ target.style.removeProperty('padding-top');
143
+ target.style.removeProperty('padding-bottom');
144
+ target.style.removeProperty('margin-top');
145
+ target.style.removeProperty('margin-bottom');
146
+ } else {
147
+ target.style.paddingTop = '0';
148
+ target.style.paddingBottom = '0';
149
+ target.style.marginTop = '0';
150
+ target.style.marginBottom = '0';
151
+ }
152
+
153
+ const state = { open, timer: null };
154
+ this._slideStates.set(target, state);
155
+ const finish = () => {
156
+ if (this._slideStates.get(target) !== state) return;
157
+ if (!open) target.style.display = 'none';
158
+ [
159
+ 'height',
160
+ 'padding-top',
161
+ 'padding-bottom',
162
+ 'margin-top',
163
+ 'margin-bottom',
164
+ 'overflow',
165
+ 'box-sizing',
166
+ 'transition-duration',
167
+ 'transition-property'
168
+ ].forEach((prop) => target.style.removeProperty(prop));
169
+ this._slideStates.set(target, { open, timer: null });
170
+ };
171
+
172
+ if (duration === 0) {
173
+ finish();
174
+ } else {
175
+ state.timer = setTimeout(finish, duration);
176
+ }
177
+ }
178
+ }
@@ -0,0 +1,326 @@
1
+ /*!
2
+ ** Sidebar for Bootstrap
3
+ ** Copyright Zdeněk Papučík
4
+ ** MIT License
5
+ **/
6
+ export class Sidebar {
7
+ // the key of the remembered compact sidebar in localStorage
8
+ static compactStorageKey = 'sidebar-compact';
9
+ static _compactInitialized = false;
10
+ // the name of a hovered link and the menu of a group next to the compact sidebar (one of each, made on first use)
11
+ static _label = null;
12
+ static _flyout = null;
13
+ static _flyoutGroup = null;
14
+
15
+ static init() {
16
+ this._initCompact();
17
+
18
+ const sidebar = document.getElementById('sidebar');
19
+ const navigation = document.getElementById('navigation');
20
+
21
+ if (!sidebar || !navigation || navigation.dataset.sidebarInitialized === 'true') {
22
+ return;
23
+ }
24
+
25
+ navigation.dataset.sidebarInitialized = 'true';
26
+ sidebar.setAttribute('aria-controls', navigation.id);
27
+
28
+ const backdrop = document.createElement('div');
29
+ backdrop.className = 'sidebar-backdrop';
30
+ navigation.after(backdrop);
31
+
32
+ const setExpanded = (expanded) => {
33
+ sidebar.setAttribute('aria-expanded', String(expanded));
34
+ };
35
+
36
+ const media = window.matchMedia('(min-width: 768px)');
37
+ const isOpen = () => navigation.classList.contains('sidebar-toggle');
38
+ // below md the closed sidebar stands outside the window: it is inert there, so Tab does not walk through
39
+ // links nobody sees and a screen reader does not read them
40
+ const syncInert = () => {
41
+ navigation.inert = !media.matches && !isOpen() && !navigation.classList.contains('sidebar-toggle-visible');
42
+ };
43
+ setExpanded(isOpen());
44
+ backdrop.classList.toggle('show', isOpen());
45
+ syncInert();
46
+
47
+ const close = () => {
48
+ navigation.classList.remove('sidebar-toggle');
49
+ backdrop.classList.remove('show');
50
+ setExpanded(false);
51
+ syncInert();
52
+ };
53
+
54
+ sidebar.addEventListener('click', () => {
55
+ const expanded = !isOpen();
56
+ navigation.classList.toggle('sidebar-toggle', expanded);
57
+ backdrop.classList.toggle('show', expanded);
58
+ setExpanded(expanded);
59
+ syncInert();
60
+ // the opened sidebar of a phone takes the focus, so the keyboard and a screen reader go on in it
61
+ if (expanded && !media.matches) {
62
+ navigation.querySelector('a[href], button, [tabindex="0"]')?.focus({ preventScroll: true });
63
+ }
64
+ });
65
+ // the focus that leaves the open sidebar of a phone (Tab after its last link) closes it, like a dropdown:
66
+ // the page under the backdrop is not walked through with the sidebar over it
67
+ document.addEventListener('focusin', (event) => {
68
+ if (!media.matches && isOpen() && event.target !== sidebar && !navigation.contains(event.target)) {
69
+ close();
70
+ }
71
+ });
72
+
73
+ backdrop.addEventListener('click', () => {
74
+ close();
75
+ sidebar.focus();
76
+ });
77
+ document.addEventListener('keydown', (event) => {
78
+ if (event.key === 'Escape' && isOpen()) {
79
+ close();
80
+ sidebar.focus();
81
+ }
82
+ });
83
+ media.addEventListener('change', (event) => {
84
+ if (event.matches) {
85
+ close();
86
+ }
87
+ syncInert();
88
+ });
89
+ }
90
+
91
+ /**
92
+ * The compact sidebar with the icons only (from md up): a button [data-sidebar-compact] switches the class
93
+ * sidebar-compact of <html> and remembers it; the head of a page can set the class before it is drawn:
94
+ * <script>try { if (localStorage.getItem('sidebar-compact') === '1') document.documentElement.classList.add('sidebar-compact'); } catch (e) { }</script>
95
+ */
96
+ static setCompact(compact) {
97
+ document.documentElement.classList.toggle('sidebar-compact', compact);
98
+ document.querySelectorAll('[data-sidebar-compact]').forEach((button) => button.setAttribute('aria-pressed', String(compact)));
99
+ try {
100
+ localStorage.setItem(this.compactStorageKey, compact ? '1' : '0');
101
+ } catch (e) { }
102
+ this._hideLabel();
103
+ this._closeFlyout();
104
+ // a scrollbar of the menu (Perfect scrollbar) measures its box again on a resize
105
+ window.dispatchEvent(new Event('resize'));
106
+ }
107
+
108
+ /** Whether the compact sidebar is shown (it is only from md up). */
109
+ static isCompact() {
110
+ return document.documentElement.classList.contains('sidebar-compact') && window.matchMedia('(min-width: 768px)').matches;
111
+ }
112
+
113
+ static _initCompact() {
114
+ if (this._compactInitialized) {
115
+ return;
116
+ }
117
+
118
+ this._compactInitialized = true;
119
+
120
+ let stored = null;
121
+ try {
122
+ stored = localStorage.getItem(this.compactStorageKey);
123
+ } catch (e) { }
124
+ if (stored !== null) {
125
+ document.documentElement.classList.toggle('sidebar-compact', stored === '1');
126
+ }
127
+ const compact = document.documentElement.classList.contains('sidebar-compact');
128
+ document.querySelectorAll('[data-sidebar-compact]').forEach((button) => button.setAttribute('aria-pressed', String(compact)));
129
+
130
+ // the button, a link with a submenu (its links in a menu next to the icon; SidebarMenu leaves the click alone in
131
+ // the compact sidebar) and a click outside an open menu
132
+ document.addEventListener('click', (event) => {
133
+ if (event.target.closest('[data-sidebar-compact]')) {
134
+ this.setCompact(!document.documentElement.classList.contains('sidebar-compact'));
135
+ return;
136
+ }
137
+
138
+ const group = event.target.closest('.sidebar .list-link.link-arrow');
139
+ if (group && this.isCompact()) {
140
+ event.preventDefault();
141
+ if (this._flyoutGroup === group) {
142
+ this._closeFlyout();
143
+ } else {
144
+ // a click of the mouse leaves the focus on the icon, Enter or Space moves it into the menu
145
+ this._openFlyout(group, event.detail === 0);
146
+ }
147
+ } else if (this._flyout && !this._flyout.contains(event.target)) {
148
+ this._closeFlyout();
149
+ }
150
+ });
151
+
152
+ // the keys of a dropdown: Esc closes the menu (the focus back on its icon), the arrows move between its links;
153
+ // the menu stands at the end of the page, so Tab leaves it as if it stood after its icon
154
+ document.addEventListener('keydown', (event) => {
155
+ if (!this._flyout) {
156
+ return;
157
+ }
158
+
159
+ const items = [...this._flyout.querySelectorAll('.sidebar-compact-menu-item')];
160
+ const index = items.indexOf(event.target);
161
+ if (event.key === 'Escape') {
162
+ this._closeFlyout(true);
163
+ } else if ((event.key === 'ArrowDown' || event.key === 'ArrowUp') && (index !== -1 || event.target === this._flyoutGroup)) {
164
+ event.preventDefault();
165
+ items[Math.min(Math.max(index + (event.key === 'ArrowDown' ? 1 : -1), 0), items.length - 1)].focus();
166
+ } else if (event.key === 'Tab' && event.shiftKey && index === 0) {
167
+ // before the first link: back on the icon
168
+ event.preventDefault();
169
+ this._closeFlyout(true);
170
+ } else if (event.key === 'Tab' && !event.shiftKey && index === items.length - 1) {
171
+ // after the last link: the focus on the icon, then the browser moves on to the next one
172
+ this._closeFlyout(true);
173
+ }
174
+ });
175
+
176
+ // the focus moving anywhere else (a click into a field, a dialog taking the focus) closes the menu
177
+ document.addEventListener('focusin', (event) => {
178
+ if (this._flyout && !this._flyout.contains(event.target) && event.target !== this._flyoutGroup) {
179
+ this._closeFlyout();
180
+ }
181
+ });
182
+ window.addEventListener('resize', () => this._closeFlyout());
183
+ document.addEventListener('scroll', (event) => {
184
+ this._hideLabel();
185
+ if (!this._flyout?.contains(event.target)) {
186
+ this._closeFlyout();
187
+ }
188
+ }, true);
189
+
190
+ // the name of a hovered or focused link next to the compact sidebar
191
+ const show = (event) => {
192
+ const link = event.target.closest?.('.sidebar .list-link');
193
+ if (link && link !== this._flyoutGroup && this.isCompact()) {
194
+ this._showLabel(link);
195
+ }
196
+ };
197
+ const hide = (event) => {
198
+ if (event.target.closest?.('.sidebar .list-link')) {
199
+ this._hideLabel();
200
+ }
201
+ };
202
+ document.addEventListener('mouseover', show);
203
+ document.addEventListener('focusin', show);
204
+ document.addEventListener('mouseout', hide);
205
+ document.addEventListener('focusout', hide);
206
+ }
207
+
208
+ // the text of a link of the menu without its icon and badge
209
+ static _linkText(link) {
210
+ return (link.querySelector('.float-start') || link).textContent.trim();
211
+ }
212
+
213
+ // a box next to the compact sidebar at the end of the page: the scrolling menu would cut off a box inside it
214
+ static _place(box, link, top) {
215
+ const rect = link.getBoundingClientRect();
216
+ box.style.left = `${rect.right + 8}px`;
217
+ box.style.top = `${top ?? rect.top + rect.height / 2}px`;
218
+ }
219
+
220
+ static _showLabel(link) {
221
+ if (!this._label) {
222
+ this._label = document.createElement('div');
223
+ this._label.className = 'sidebar-compact-label';
224
+ this._label.setAttribute('aria-hidden', 'true');
225
+ document.body.append(this._label);
226
+ }
227
+
228
+ this._label.textContent = this._linkText(link);
229
+ this._place(this._label, link);
230
+ this._label.hidden = false;
231
+ }
232
+
233
+ static _hideLabel() {
234
+ if (this._label) {
235
+ this._label.hidden = true;
236
+ }
237
+ }
238
+
239
+ /** The links of a group in a menu next to its icon in the compact sidebar; deeper levels under their name. */
240
+ static _openFlyout(group, focus = false) {
241
+ this._closeFlyout();
242
+
243
+ const submenu = group.nextElementSibling;
244
+ if (!submenu) {
245
+ return;
246
+ }
247
+
248
+ const menu = document.createElement('ul');
249
+ menu.className = 'sidebar-compact-menu';
250
+ menu.id = 'sidebar-compact-menu';
251
+
252
+ const add = (link, depth) => {
253
+ const item = document.createElement('li');
254
+ const header = link === group || link.classList.contains('link-arrow');
255
+ const element = document.createElement(header ? 'h6' : 'a');
256
+ element.className = header ? 'sidebar-compact-menu-header' : 'sidebar-compact-menu-item';
257
+ element.textContent = this._linkText(link);
258
+ if (depth) {
259
+ element.style.paddingLeft = `${1 + depth}rem`;
260
+ }
261
+ if (!header) {
262
+ element.href = link.getAttribute('href') || '#';
263
+ if (link.classList.contains('link-current')) {
264
+ element.classList.add('active');
265
+ element.setAttribute('aria-current', 'page');
266
+ }
267
+ }
268
+ item.append(element);
269
+ menu.append(item);
270
+ };
271
+
272
+ add(group, 0);
273
+ submenu.querySelectorAll('.list-link').forEach((link) => add(link, this._depth(link, submenu)));
274
+ document.body.append(menu);
275
+
276
+ // its top in line with the icon, inside the window
277
+ const top = Math.max(8, Math.min(group.getBoundingClientRect().top - 8, window.innerHeight - menu.offsetHeight - 8));
278
+ this._place(menu, group, top);
279
+
280
+ this._flyout = menu;
281
+ this._flyoutGroup = group;
282
+ group.setAttribute('aria-controls', menu.id);
283
+ group.setAttribute('aria-expanded', 'true');
284
+ group.classList.add('sidebar-compact-open');
285
+ this._hideLabel();
286
+ if (focus) {
287
+ menu.querySelector('.sidebar-compact-menu-item')?.focus({ preventScroll: true });
288
+ }
289
+ }
290
+
291
+ /** Closes the menu of a group; `focusGroup` moves the focus back on its icon. */
292
+ static _closeFlyout(focusGroup = false) {
293
+ const group = this._flyoutGroup;
294
+ if (!group) {
295
+ return;
296
+ }
297
+
298
+ // also when the menu closes by itself (a scroll, a resize) with the focus inside: it would be lost with the menu
299
+ if (focusGroup || this._flyout.contains(document.activeElement)) {
300
+ group.focus({ preventScroll: true });
301
+ }
302
+
303
+ // the group tells again the state of its submenu in the wide sidebar (opened by SidebarMenu by its own style)
304
+ const submenu = group.nextElementSibling;
305
+ group.classList.remove('sidebar-compact-open');
306
+ group.setAttribute('aria-expanded', String(submenu?.style.display === 'block'));
307
+ if (submenu?.id) {
308
+ group.setAttribute('aria-controls', submenu.id);
309
+ } else {
310
+ group.removeAttribute('aria-controls');
311
+ }
312
+
313
+ this._flyout.remove();
314
+ this._flyout = null;
315
+ this._flyoutGroup = null;
316
+ }
317
+
318
+ // how many submenus a link is nested in below the submenu of its group
319
+ static _depth(link, submenu) {
320
+ let depth = 0;
321
+ for (let element = link.parentElement; element && element !== submenu; element = element.parentElement) {
322
+ depth += element.classList.contains('list-hidden') ? 1 : 0;
323
+ }
324
+ return depth;
325
+ }
326
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Spinner: shows that a request runs. show() puts the spinner at the end of <body>, hide() removes it; the calls are
3
+ * counted, so with more requests at once the spinner stays until the last one ends.
4
+ *
5
+ * const spinner = new Spinner(); // a line at the top of the window (.spinner), the page stays in use
6
+ * const spinner = new Spinner({ overlay: true }); // the window darkens (.spinner-overlay), nothing can be clicked
7
+ *
8
+ * spinner.show();
9
+ * fetch(url).finally(() => spinner.hide());
10
+ *
11
+ * The overlay also stops the keyboard (Tab, Enter, Space), so a focused button cannot send the form once more, and
12
+ * gives the focus back when it ends.
13
+ */
14
+ export class Spinner {
15
+ _count = 0;
16
+ _focused = null;
17
+
18
+ constructor({ overlay = false, label = 'Loading', parent = document.body } = {}) {
19
+ this.overlay = overlay;
20
+ this.parent = parent;
21
+ this.element = document.createElement('div');
22
+ this.element.className = overlay ? 'spinner-overlay' : 'spinner';
23
+ this.element.setAttribute('role', 'status');
24
+ // the text for a screen reader: written a moment after the element is in the page, because a status is
25
+ // announced when its content changes, not when it appears with its text (or with an aria-label only)
26
+ this.label = label;
27
+ this._label = document.createElement('span');
28
+ this._label.className = 'spinner-label';
29
+ this.element.append(this._label);
30
+ }
31
+
32
+ /** Whether a request runs. */
33
+ get active() {
34
+ return this._count > 0;
35
+ }
36
+
37
+ show() {
38
+ if (this._count++ > 0) {
39
+ return;
40
+ }
41
+
42
+ this.parent.appendChild(this.element);
43
+ this._timer = setTimeout(() => {
44
+ this._label.textContent = this.label;
45
+ }, 100);
46
+ if (this.overlay) {
47
+ this._focused = document.activeElement;
48
+ this._focused?.blur?.();
49
+ document.addEventListener('keydown', this._stopKeys, true);
50
+ }
51
+ }
52
+
53
+ hide() {
54
+ if (this._count === 0 || --this._count > 0) {
55
+ return;
56
+ }
57
+
58
+ clearTimeout(this._timer);
59
+ this._label.textContent = '';
60
+ this.element.remove();
61
+ if (this.overlay) {
62
+ document.removeEventListener('keydown', this._stopKeys, true);
63
+ if (this._focused?.isConnected) {
64
+ this._focused.focus({ preventScroll: true });
65
+ }
66
+ this._focused = null;
67
+ }
68
+ }
69
+
70
+ _stopKeys = (event) => {
71
+ if (['Tab', 'Enter', ' '].includes(event.key)) {
72
+ event.preventDefault();
73
+ event.stopPropagation();
74
+ }
75
+ };
76
+ }