@avlcodemonkey/nilla-components 0.0.0-stage → 0.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 (94) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +219 -3
  4. package/THIRD_PARTY_NOTICES.md +48 -0
  5. package/css/alert.css +48 -0
  6. package/css/autocomplete.css +38 -0
  7. package/css/dialog.css +61 -0
  8. package/css/file-to-textarea.css +8 -0
  9. package/css/html-editor.css +172 -0
  10. package/css/json.css +44 -0
  11. package/css/list.css +37 -0
  12. package/css/nav-toggle.css +92 -0
  13. package/css/nilla.css +16 -0
  14. package/css/pjax.css +58 -0
  15. package/css/slider-input.css +16 -0
  16. package/css/table.css +99 -0
  17. package/css/tokens.css +44 -0
  18. package/css/unsaved-changes.css +10 -0
  19. package/css/vendor/wysi.css +406 -0
  20. package/docs/llms.txt +319 -0
  21. package/package.json +121 -5
  22. package/src/components/Alert.js +24 -0
  23. package/src/components/Autocomplete.js +127 -0
  24. package/src/components/BaseComponent.js +78 -0
  25. package/src/components/BaseDialog.js +151 -0
  26. package/src/components/ConfirmDialog.js +34 -0
  27. package/src/components/CopyToClipboard.js +66 -0
  28. package/src/components/DateFormatter.js +51 -0
  29. package/src/components/DateTimeInput.js +63 -0
  30. package/src/components/DisplayToggle.js +53 -0
  31. package/src/components/FileToTextarea.js +81 -0
  32. package/src/components/HtmlEditor.js +309 -0
  33. package/src/components/InfoDialog.js +38 -0
  34. package/src/components/JsonFormatter.js +23 -0
  35. package/src/components/List.js +237 -0
  36. package/src/components/ListSortable.js +8 -0
  37. package/src/components/NavToggle.js +119 -0
  38. package/src/components/PJax.js +888 -0
  39. package/src/components/Share.js +41 -0
  40. package/src/components/SliderInput.js +26 -0
  41. package/src/components/Table.js +758 -0
  42. package/src/components/TimeOffsetSelect.js +29 -0
  43. package/src/components/UnsavedChanges.js +187 -0
  44. package/src/constants/Fetch.js +7 -0
  45. package/src/constants/HttpHeaders.js +19 -0
  46. package/src/constants/HttpMethods.js +14 -0
  47. package/src/constants/SortDirection.js +11 -0
  48. package/src/constants/TableElements.js +25 -0
  49. package/src/constants/TableSettings.js +14 -0
  50. package/src/errors/FetchError.js +7 -0
  51. package/src/events/ListReorderEvent.js +19 -0
  52. package/src/events/PJaxErrorEvent.js +38 -0
  53. package/src/events/PJaxNavigatingEvent.js +46 -0
  54. package/src/index.js +26 -0
  55. package/src/locales/en.json +55 -0
  56. package/src/locales/es.js +9 -0
  57. package/src/locales/es.json +55 -0
  58. package/src/models/TableSort.js +20 -0
  59. package/src/utils/ajaxHeaders.js +10 -0
  60. package/src/utils/announce.js +40 -0
  61. package/src/utils/defineElement.js +13 -0
  62. package/src/utils/editor/blockTools.js +256 -0
  63. package/src/utils/editor/elements.js +18 -0
  64. package/src/utils/editor/input.js +350 -0
  65. package/src/utils/editor/selection.js +125 -0
  66. package/src/utils/editor/tableTools.js +497 -0
  67. package/src/utils/escape.js +20 -0
  68. package/src/utils/fetchJsonArray.js +29 -0
  69. package/src/utils/filterArray.js +18 -0
  70. package/src/utils/formActionUrl.js +10 -0
  71. package/src/utils/formData.js +118 -0
  72. package/src/utils/index.js +18 -0
  73. package/src/utils/indexedCompare.js +18 -0
  74. package/src/utils/isSameOrigin.js +12 -0
  75. package/src/utils/locale.js +36 -0
  76. package/src/utils/notifyChange.js +10 -0
  77. package/src/utils/numberSetting.js +14 -0
  78. package/src/utils/pageLanguage.js +13 -0
  79. package/src/utils/parseUtcDate.js +22 -0
  80. package/src/utils/randomId.js +17 -0
  81. package/src/utils/registerTabTrap.js +60 -0
  82. package/src/utils/renderTemplate.js +44 -0
  83. package/src/utils/requestTimeout.js +12 -0
  84. package/src/utils/response.js +28 -0
  85. package/src/utils/sortedCompare.js +67 -0
  86. package/src/utils/storage.js +40 -0
  87. package/src/vendor/autocomplete.js +515 -0
  88. package/src/vendor/formatDate.js +236 -0
  89. package/src/vendor/licenses/autocomplete.LICENSE.md +21 -0
  90. package/src/vendor/licenses/fecha.LICENSE.md +21 -0
  91. package/src/vendor/licenses/pretty-print-json.LICENSE.md +21 -0
  92. package/src/vendor/licenses/wysi.LICENSE.md +21 -0
  93. package/src/vendor/prettyPrintJson.js +108 -0
  94. package/src/vendor/wyzi.js +2024 -0
@@ -0,0 +1,119 @@
1
+ import BaseComponent from './BaseComponent.js';
2
+ import defineElement from '../utils/defineElement.js';
3
+ import { readStorage, writeStorage } from '../utils/storage.js';
4
+
5
+ /**
6
+ * Attribute of a nav that's collapsed to icons.
7
+ * @type {string}
8
+ */
9
+ const Minimized = 'data-minimized';
10
+
11
+ /**
12
+ * Start of the storage key for a nav's collapsed state, which is saved so it stays collapsed across pages.
13
+ * @type {string}
14
+ */
15
+ const KeyPrefix = 'navToggle_minimized_';
16
+
17
+ /**
18
+ * Matches wide screens, where the nav is part of the page. Same as in nav-toggle.css.
19
+ * @type {string}
20
+ */
21
+ const WideQuery = '(width > 1024px)';
22
+
23
+ /**
24
+ * Side nav that collapses to icons on wide screens, and is a drawer on narrow ones.
25
+ * The drawer is a `<nav popover>` that buttons open and close with `popovertarget`, without this component. It closes the
26
+ * drawer when a link in it is followed, or the screen becomes wide. Each `[data-nav-toggle-target]` button collapses the nav
27
+ * whose ID it names, which gets `data-minimized`, and the button's `aria-expanded` says whether it's showing in full.
28
+ */
29
+ class NavToggle extends BaseComponent {
30
+ /**
31
+ * Whether the screen is wide.
32
+ * @type {MediaQueryList}
33
+ */
34
+ #wide = window.matchMedia(WideQuery);
35
+
36
+ /**
37
+ * Closes the drawer when the screen becomes wide, where the nav is part of the page.
38
+ */
39
+ #wideListener = () => {
40
+ this.querySelectorAll('nav:popover-open').forEach(x => /** @type {HTMLElement} */ (x).hidePopover());
41
+ };
42
+
43
+ /**
44
+ * Restore the collapsed state.
45
+ */
46
+ constructor() {
47
+ super('nav-toggle');
48
+
49
+ this.addEventListener('click', this);
50
+ for (const toggle of this.getElements('target')) {
51
+ const nav = NavToggle.#navFor(toggle);
52
+ if (nav) {
53
+ this.#setMinimized(nav, readStorage('localStorage', KeyPrefix + nav.id) === 'true');
54
+ }
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Watch the screen's width while the element is in the page.
60
+ */
61
+ connectedCallback() {
62
+ this.#wide.addEventListener('change', this.#wideListener);
63
+ }
64
+
65
+ /**
66
+ * Stop watching the screen's width.
67
+ */
68
+ disconnectedCallback() {
69
+ this.#wide.removeEventListener('change', this.#wideListener);
70
+ super.disconnectedCallback();
71
+ }
72
+
73
+ /**
74
+ * Collapses or expands a nav when its button is clicked, and closes the drawer when a link in it is followed.
75
+ * @param {Event} event Click event.
76
+ */
77
+ handleEvent(event) {
78
+ const target = /** @type {Element} */ (event.target);
79
+ const toggle = this.getElements('target').find(x => x.contains(target));
80
+ if (!toggle) {
81
+ if (target.closest('a:not([href="#"])')) {
82
+ /** @type {HTMLElement|null} */ (target.closest('nav:popover-open'))?.hidePopover();
83
+ }
84
+ return;
85
+ }
86
+
87
+ const nav = NavToggle.#navFor(toggle);
88
+ if (nav) {
89
+ const minimized = !nav.hasAttribute(Minimized);
90
+ writeStorage('localStorage', KeyPrefix + nav.id, minimized ? 'true' : null);
91
+ this.#setMinimized(nav, minimized);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Collapses or expands a nav, and tells its buttons.
97
+ * @param {HTMLElement} nav Nav.
98
+ * @param {boolean} minimized Whether to collapse it.
99
+ */
100
+ #setMinimized(nav, minimized) {
101
+ nav.toggleAttribute(Minimized, minimized);
102
+ this.getElements('target').filter(x => NavToggle.#navFor(x) === nav)
103
+ .forEach(x => x.setAttribute('aria-expanded', `${!minimized}`));
104
+ }
105
+
106
+ /**
107
+ * Gets the nav a button collapses.
108
+ * @param {HTMLElement} toggle Button.
109
+ * @returns {HTMLElement|null} Nav, or null if the ID doesn't match an element.
110
+ */
111
+ static #navFor(toggle) {
112
+ const id = toggle.dataset.navToggleTarget;
113
+ return id ? document.getElementById(id) : null;
114
+ }
115
+ }
116
+
117
+ defineElement('nilla-nav-toggle', NavToggle);
118
+
119
+ export default NavToggle;