@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
package/css/json.css ADDED
@@ -0,0 +1,44 @@
1
+ /* nilla-json: syntax-highlighted JSON. Styles adapted from pretty-print-json ~ MIT License. */
2
+ nilla-json {
3
+ display: block;
4
+ overflow-x: auto;
5
+ border: 1px solid var(--nilla-border);
6
+ border-radius: var(--nilla-radius);
7
+ background: var(--nilla-background);
8
+ font-family: var(--nilla-font-mono);
9
+
10
+ & .json-container {
11
+ margin: 0;
12
+ padding: var(--nilla-spacing);
13
+ border: none;
14
+ background: none;
15
+ color: var(--nilla-color);
16
+ font-family: inherit;
17
+ line-height: 1.5;
18
+ white-space: pre;
19
+ }
20
+
21
+ & .json-key {
22
+ color: var(--nilla-json-key, light-dark(#a52a2a, #e59a8c));
23
+ }
24
+
25
+ & .json-string {
26
+ color: var(--nilla-json-string, light-dark(#6b6b00, #c9c96a));
27
+ }
28
+
29
+ & .json-number {
30
+ color: var(--nilla-json-number, light-dark(#00008b, #8fb3ff));
31
+ }
32
+
33
+ & .json-boolean {
34
+ color: var(--nilla-json-boolean, light-dark(#007373, #5fd0d0));
35
+ }
36
+
37
+ & .json-null {
38
+ color: var(--nilla-muted);
39
+ }
40
+
41
+ & .json-mark {
42
+ color: var(--nilla-color);
43
+ }
44
+ }
package/css/list.css ADDED
@@ -0,0 +1,37 @@
1
+ /* nilla-list: add, remove, and reorder repeated items. */
2
+ nilla-list {
3
+ display: block;
4
+
5
+ & [data-list-item] {
6
+ display: flex;
7
+ gap: calc(var(--nilla-spacing) / 2);
8
+ align-items: center;
9
+ margin-block-end: calc(var(--nilla-spacing) / 2);
10
+
11
+ > :not(button) {
12
+ flex: 1;
13
+ margin-block-end: 0;
14
+ }
15
+
16
+ > button {
17
+ width: auto;
18
+ margin: 0;
19
+ }
20
+ }
21
+
22
+ & [data-list-drag-handle] {
23
+ cursor: grab;
24
+ touch-action: none;
25
+ }
26
+
27
+ & [data-list-empty-message] {
28
+ display: block;
29
+ margin-block-end: calc(var(--nilla-spacing) / 2);
30
+ color: var(--nilla-muted);
31
+ }
32
+
33
+ & .is-dragging {
34
+ opacity: .5;
35
+ outline: 2px dashed var(--nilla-primary);
36
+ }
37
+ }
@@ -0,0 +1,92 @@
1
+ /*
2
+ * nilla-nav-toggle: side nav that collapses to icons on wide screens, and is a drawer on narrow ones.
3
+ * The nav is a popover, which the browser opens as a drawer. On wide screens it's shown in the page without being open.
4
+ * Labels are any <span> that isn't an icon, meaning it has neither [aria-hidden="true"] nor .icon.
5
+ */
6
+ nilla-nav-toggle {
7
+ display: contents;
8
+
9
+ @media (width > 1024px) {
10
+ & [data-nav-toggle-drawer] {
11
+ display: none;
12
+ }
13
+
14
+ & nav {
15
+ transition: width var(--nilla-transition);
16
+
17
+ &[data-minimized] {
18
+ width: var(--nilla-nav-minimized-width, 4rem);
19
+ overflow: hidden;
20
+
21
+ /* out of sight, but still the links' names for screen readers */
22
+ & span:not(.icon, [aria-hidden="true"]) {
23
+ position: absolute;
24
+ width: 1px;
25
+ height: 1px;
26
+ overflow: hidden;
27
+ clip-path: inset(50%);
28
+ white-space: nowrap;
29
+ }
30
+ }
31
+ }
32
+ }
33
+
34
+ @media (width <= 1024px) {
35
+ & [data-nav-toggle-target] {
36
+ display: none;
37
+ }
38
+
39
+ & nav[popover] {
40
+ position: fixed;
41
+ inset-block: 0;
42
+ inset-inline: calc(var(--nilla-nav-width, 16rem) * -1) auto;
43
+ width: var(--nilla-nav-width, 16rem);
44
+ height: auto;
45
+ margin: 0;
46
+ padding: 0;
47
+ border: none;
48
+ overflow-y: auto;
49
+ background: var(--nilla-background);
50
+ color: var(--nilla-color);
51
+ transition: inset-inline-start var(--nilla-transition), display var(--nilla-transition) allow-discrete, overlay var(--nilla-transition) allow-discrete;
52
+
53
+ /* hidden even if the page sets a nav's display */
54
+ &:not(:popover-open) {
55
+ display: none;
56
+ }
57
+
58
+ &:popover-open {
59
+ inset-inline-start: 0;
60
+ box-shadow: var(--nilla-shadow);
61
+
62
+ @starting-style {
63
+ inset-inline-start: calc(var(--nilla-nav-width, 16rem) * -1);
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ @media (prefers-reduced-motion: reduce) {
70
+ & nav,
71
+ & nav[popover] {
72
+ transition: none;
73
+ }
74
+ }
75
+ }
76
+
77
+ /* undo the browser's popover styles, letting any style the page has for its nav win */
78
+ @media (width > 1024px) {
79
+ :where(nilla-nav-toggle nav[popover]) {
80
+ display: block;
81
+ position: static;
82
+ inset: auto;
83
+ width: auto;
84
+ height: auto;
85
+ margin: 0;
86
+ padding: 0;
87
+ border: none;
88
+ overflow: visible;
89
+ background: none;
90
+ color: inherit;
91
+ }
92
+ }
package/css/nilla.css ADDED
@@ -0,0 +1,16 @@
1
+ /*! @avlcodemonkey/nilla-components ~ MIT License ~ https://github.com/AvlCodeMonkey-Industries/NillaComponents */
2
+
3
+ /* Styles for every component. To include only what you use, import tokens.css plus the files you need. */
4
+ @import url("./tokens.css");
5
+ @import url("./alert.css");
6
+ @import url("./autocomplete.css");
7
+ @import url("./dialog.css");
8
+ @import url("./file-to-textarea.css");
9
+ @import url("./html-editor.css");
10
+ @import url("./json.css");
11
+ @import url("./list.css");
12
+ @import url("./nav-toggle.css");
13
+ @import url("./pjax.css");
14
+ @import url("./slider-input.css");
15
+ @import url("./table.css");
16
+ @import url("./unsaved-changes.css");
package/css/pjax.css ADDED
@@ -0,0 +1,58 @@
1
+ /*
2
+ * nilla-pjax: while a page loads, [data-pjax-loading-indicator] and [data-pjax-target] get aria-busy="true".
3
+ * Default indicator is a thin progress bar along the top of the window.
4
+ */
5
+ nilla-pjax {
6
+ display: block;
7
+
8
+ & [data-pjax-loading-indicator] {
9
+ position: fixed;
10
+ inset-block-start: 0;
11
+ inset-inline: 0;
12
+ z-index: 1000;
13
+ height: .2rem;
14
+ overflow: hidden;
15
+ visibility: hidden;
16
+ pointer-events: none;
17
+
18
+ &[aria-busy="true"] {
19
+ visibility: visible;
20
+ }
21
+
22
+ &::after {
23
+ content: "";
24
+ display: block;
25
+ width: 40%;
26
+ height: 100%;
27
+ background: var(--nilla-primary);
28
+ animation: nilla-pjax-progress 1.2s ease-in-out infinite;
29
+ }
30
+ }
31
+
32
+ /* target gets focus after loading; show the ring only to keyboard users */
33
+ & [data-pjax-target]:focus:not(:focus-visible) {
34
+ outline: none;
35
+ }
36
+
37
+ & [data-pjax-target][aria-busy="true"] {
38
+ opacity: .6;
39
+ transition: opacity var(--nilla-transition);
40
+ }
41
+ }
42
+
43
+ @keyframes nilla-pjax-progress {
44
+ from {
45
+ transform: translateX(-100%);
46
+ }
47
+
48
+ to {
49
+ transform: translateX(250%);
50
+ }
51
+ }
52
+
53
+ @media (prefers-reduced-motion: reduce) {
54
+ nilla-pjax [data-pjax-loading-indicator]::after {
55
+ width: 100%;
56
+ animation: none;
57
+ }
58
+ }
@@ -0,0 +1,16 @@
1
+ /* nilla-slider-input: keeps a range input and a number input in sync. */
2
+ nilla-slider-input {
3
+ display: flex;
4
+ gap: var(--nilla-spacing);
5
+ align-items: center;
6
+
7
+ & [data-slider-range] {
8
+ flex: 1;
9
+ margin: 0;
10
+ }
11
+
12
+ & [data-slider-text] {
13
+ width: 6em;
14
+ margin: 0;
15
+ }
16
+ }
package/css/table.css ADDED
@@ -0,0 +1,99 @@
1
+ /* nilla-table: client-side search, sort, and paging over JSON from data-src-url. */
2
+ nilla-table {
3
+ display: block;
4
+
5
+ & table {
6
+ width: 100%;
7
+ }
8
+
9
+ & th {
10
+ vertical-align: bottom;
11
+ user-select: none;
12
+
13
+ &[data-property] {
14
+ cursor: pointer;
15
+
16
+ &:hover {
17
+ color: var(--nilla-primary);
18
+ }
19
+ }
20
+
21
+ /* the sort arrow is a clipped box, not a character, so screen readers don't read it. aria-sort says the direction */
22
+ &[aria-sort] > button::after,
23
+ &[aria-sort]:not(:has(> button))::after {
24
+ content: '';
25
+ display: inline-block;
26
+ width: .6em;
27
+ height: .45em;
28
+ margin-inline-start: .35em;
29
+ vertical-align: middle;
30
+ background-color: currentcolor;
31
+ }
32
+
33
+ &[aria-sort='ascending'] > button::after,
34
+ &[aria-sort='ascending']:not(:has(> button))::after {
35
+ clip-path: polygon(50% 0, 100% 100%, 0 100%);
36
+ }
37
+
38
+ &[aria-sort='descending'] > button::after,
39
+ &[aria-sort='descending']:not(:has(> button))::after {
40
+ clip-path: polygon(0 0, 100% 0, 50% 100%);
41
+ }
42
+
43
+ /* looks like the header's text. the type selector keeps a page's button styles out */
44
+ & > button[data-table-sort-button][type='button'] {
45
+ all: unset;
46
+ display: block;
47
+ box-sizing: border-box;
48
+ width: 100%;
49
+ cursor: pointer;
50
+
51
+ &:focus-visible {
52
+ outline: 2px solid var(--nilla-primary);
53
+ outline-offset: 2px;
54
+ }
55
+ }
56
+ }
57
+
58
+ & [data-table-status] td {
59
+ color: var(--nilla-muted);
60
+ text-align: center;
61
+ }
62
+
63
+ & [data-table-error] {
64
+ color: var(--nilla-error);
65
+ }
66
+
67
+ /* optional layout hooks for the search box and the paging controls */
68
+ & [data-table-toolbar],
69
+ & [data-table-pager] {
70
+ display: flex;
71
+ flex-wrap: wrap;
72
+ gap: calc(var(--nilla-spacing) / 2);
73
+ align-items: center;
74
+ margin-block: calc(var(--nilla-spacing) / 2);
75
+
76
+ > * {
77
+ width: auto;
78
+ margin: 0;
79
+ }
80
+
81
+ > [data-table-search] {
82
+ flex: 1;
83
+ min-width: 12rem;
84
+ }
85
+ }
86
+
87
+ & [data-table-pager] {
88
+ justify-content: space-between;
89
+ }
90
+ }
91
+
92
+ /* forced colors would paint the arrow's box like the page behind it */
93
+ @media (forced-colors: active) {
94
+ nilla-table th[aria-sort] > button::after,
95
+ nilla-table th[aria-sort]:not(:has(> button))::after {
96
+ forced-color-adjust: none;
97
+ background-color: CanvasText;
98
+ }
99
+ }
package/css/tokens.css ADDED
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Theme tokens for nilla components.
3
+ * Defaults follow the light or dark color scheme. Override any token on :root, or on a single component, to theme it,
4
+ * or point the tokens at your CSS framework's variables, such as `--nilla-primary: var(--color-primary);` for chota.
5
+ * Light values are used unless the page opts into dark mode with `color-scheme: light dark` (follow the reader's
6
+ * setting) or `color-scheme: dark` on :root. This file doesn't set color-scheme, so it never changes the rest of the page.
7
+ */
8
+ :root {
9
+ --nilla-primary: light-dark(#386c9a, #6fa8dc);
10
+ --nilla-primary-hover: light-dark(#2b5478, #8cbbe6);
11
+ --nilla-primary-inverse: light-dark(#fff, #0f1720);
12
+ --nilla-highlight: light-dark(rgb(56 108 154 / 15%), rgb(111 168 220 / 20%));
13
+ --nilla-background: light-dark(#fff, #13171f);
14
+ --nilla-surface: light-dark(#f4f6f9, #1b212b);
15
+ --nilla-color: light-dark(#2b3038, #c9ced8);
16
+ --nilla-muted: light-dark(#5f6775, #8d96a7);
17
+ --nilla-border: light-dark(#dfe3ea, #2c3441);
18
+ --nilla-error: light-dark(#b42727, #e08a87);
19
+ --nilla-success: light-dark(#16775c, #62af9a);
20
+ --nilla-warning: light-dark(#8d5300, #e0a84a);
21
+ --nilla-radius: .375rem;
22
+ --nilla-spacing: 1rem;
23
+ --nilla-font-mono: ui-monospace, sfmono-regular, menlo, consolas, monospace;
24
+ --nilla-shadow: 0 .25rem 1rem light-dark(rgb(15 23 32 / 12%), rgb(0 0 0 / 45%));
25
+ --nilla-transition: .2s ease-in-out;
26
+ }
27
+
28
+ /*
29
+ * Components show and hide themselves and their parts with the `hidden` attribute. Any rule that sets `display`, from the
30
+ * page or from a component's own CSS, beats the browser's built-in `[hidden] { display: none }`, so this keeps hidden
31
+ * things hidden. It only applies to nilla components and their contents.
32
+ */
33
+ :is(
34
+ nilla-alert, nilla-autocomplete, nilla-confirm, nilla-copy-to-clipboard, nilla-date, nilla-datetime-input,
35
+ nilla-display-toggle, nilla-file-to-textarea, nilla-html-editor, nilla-info, nilla-json, nilla-list, nilla-nav-toggle,
36
+ nilla-pjax, nilla-share, nilla-slider-input, nilla-table, nilla-time-offset, nilla-unsaved-changes
37
+ )[hidden],
38
+ :is(
39
+ nilla-alert, nilla-autocomplete, nilla-confirm, nilla-copy-to-clipboard, nilla-date, nilla-datetime-input,
40
+ nilla-display-toggle, nilla-file-to-textarea, nilla-html-editor, nilla-info, nilla-json, nilla-list, nilla-nav-toggle,
41
+ nilla-pjax, nilla-share, nilla-slider-input, nilla-table, nilla-time-offset, nilla-unsaved-changes
42
+ ) [hidden] {
43
+ display: none !important;
44
+ }
@@ -0,0 +1,10 @@
1
+ /* nilla-unsaved-changes: shows [data-unsaved-indicator] while the form has changes. */
2
+ nilla-unsaved-changes {
3
+ display: block;
4
+
5
+ & [data-unsaved-indicator] {
6
+ margin-inline-start: calc(var(--nilla-spacing) / 2);
7
+ color: var(--nilla-warning);
8
+ font-size: .875em;
9
+ }
10
+ }