@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.
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +219 -3
- package/THIRD_PARTY_NOTICES.md +48 -0
- package/css/alert.css +48 -0
- package/css/autocomplete.css +38 -0
- package/css/dialog.css +61 -0
- package/css/file-to-textarea.css +8 -0
- package/css/html-editor.css +172 -0
- package/css/json.css +44 -0
- package/css/list.css +37 -0
- package/css/nav-toggle.css +92 -0
- package/css/nilla.css +16 -0
- package/css/pjax.css +58 -0
- package/css/slider-input.css +16 -0
- package/css/table.css +99 -0
- package/css/tokens.css +44 -0
- package/css/unsaved-changes.css +10 -0
- package/css/vendor/wysi.css +406 -0
- package/docs/llms.txt +319 -0
- package/package.json +121 -5
- package/src/components/Alert.js +24 -0
- package/src/components/Autocomplete.js +127 -0
- package/src/components/BaseComponent.js +78 -0
- package/src/components/BaseDialog.js +151 -0
- package/src/components/ConfirmDialog.js +34 -0
- package/src/components/CopyToClipboard.js +66 -0
- package/src/components/DateFormatter.js +51 -0
- package/src/components/DateTimeInput.js +63 -0
- package/src/components/DisplayToggle.js +53 -0
- package/src/components/FileToTextarea.js +81 -0
- package/src/components/HtmlEditor.js +309 -0
- package/src/components/InfoDialog.js +38 -0
- package/src/components/JsonFormatter.js +23 -0
- package/src/components/List.js +237 -0
- package/src/components/ListSortable.js +8 -0
- package/src/components/NavToggle.js +119 -0
- package/src/components/PJax.js +888 -0
- package/src/components/Share.js +41 -0
- package/src/components/SliderInput.js +26 -0
- package/src/components/Table.js +758 -0
- package/src/components/TimeOffsetSelect.js +29 -0
- package/src/components/UnsavedChanges.js +187 -0
- package/src/constants/Fetch.js +7 -0
- package/src/constants/HttpHeaders.js +19 -0
- package/src/constants/HttpMethods.js +14 -0
- package/src/constants/SortDirection.js +11 -0
- package/src/constants/TableElements.js +25 -0
- package/src/constants/TableSettings.js +14 -0
- package/src/errors/FetchError.js +7 -0
- package/src/events/ListReorderEvent.js +19 -0
- package/src/events/PJaxErrorEvent.js +38 -0
- package/src/events/PJaxNavigatingEvent.js +46 -0
- package/src/index.js +26 -0
- package/src/locales/en.json +55 -0
- package/src/locales/es.js +9 -0
- package/src/locales/es.json +55 -0
- package/src/models/TableSort.js +20 -0
- package/src/utils/ajaxHeaders.js +10 -0
- package/src/utils/announce.js +40 -0
- package/src/utils/defineElement.js +13 -0
- package/src/utils/editor/blockTools.js +256 -0
- package/src/utils/editor/elements.js +18 -0
- package/src/utils/editor/input.js +350 -0
- package/src/utils/editor/selection.js +125 -0
- package/src/utils/editor/tableTools.js +497 -0
- package/src/utils/escape.js +20 -0
- package/src/utils/fetchJsonArray.js +29 -0
- package/src/utils/filterArray.js +18 -0
- package/src/utils/formActionUrl.js +10 -0
- package/src/utils/formData.js +118 -0
- package/src/utils/index.js +18 -0
- package/src/utils/indexedCompare.js +18 -0
- package/src/utils/isSameOrigin.js +12 -0
- package/src/utils/locale.js +36 -0
- package/src/utils/notifyChange.js +10 -0
- package/src/utils/numberSetting.js +14 -0
- package/src/utils/pageLanguage.js +13 -0
- package/src/utils/parseUtcDate.js +22 -0
- package/src/utils/randomId.js +17 -0
- package/src/utils/registerTabTrap.js +60 -0
- package/src/utils/renderTemplate.js +44 -0
- package/src/utils/requestTimeout.js +12 -0
- package/src/utils/response.js +28 -0
- package/src/utils/sortedCompare.js +67 -0
- package/src/utils/storage.js +40 -0
- package/src/vendor/autocomplete.js +515 -0
- package/src/vendor/formatDate.js +236 -0
- package/src/vendor/licenses/autocomplete.LICENSE.md +21 -0
- package/src/vendor/licenses/fecha.LICENSE.md +21 -0
- package/src/vendor/licenses/pretty-print-json.LICENSE.md +21 -0
- package/src/vendor/licenses/wysi.LICENSE.md +21 -0
- package/src/vendor/prettyPrintJson.js +108 -0
- package/src/vendor/wyzi.js +2024 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import defineElement from '../utils/defineElement.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Web component that pre-selects the browser's UTC offset in a select, for a new time window filter.
|
|
5
|
+
*
|
|
6
|
+
* Set `data-browser-default="true"` on the component to select the offset. For any other value, including the empty string Razor
|
|
7
|
+
* renders for a null `data-` attribute, the select is left as it was rendered.
|
|
8
|
+
*/
|
|
9
|
+
class TimeOffsetSelect extends HTMLElement {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
|
|
13
|
+
const select = this.querySelector('select');
|
|
14
|
+
if (!select || this.dataset.browserDefault !== 'true') {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// getTimezoneOffset is minutes west of UTC, and may be -0
|
|
19
|
+
const offset = -new Date().getTimezoneOffset() || 0;
|
|
20
|
+
const option = [...select.options].find(x => Number(x.value) === offset);
|
|
21
|
+
if (option) {
|
|
22
|
+
select.value = option.value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
defineElement('nilla-time-offset', TimeOffsetSelect);
|
|
28
|
+
|
|
29
|
+
export default TimeOffsetSelect;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import PJaxErrorEvent from '../events/PJaxErrorEvent.js';
|
|
2
|
+
import PJaxNavigatingEvent from '../events/PJaxNavigatingEvent.js';
|
|
3
|
+
import BaseDialog from './BaseDialog.js';
|
|
4
|
+
import defineElement from '../utils/defineElement.js';
|
|
5
|
+
import { getText } from '../utils/locale.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Web component that warns the user before they leave a form that has unsaved changes.
|
|
9
|
+
* Navigation within the site is handled with a dialog, since PJax changes pages without unloading the document.
|
|
10
|
+
* Anything else that unloads the page, like reloading or following an external link, uses the browser's own prompt.
|
|
11
|
+
* Changes are found by comparing the form's values to what they were when the page loaded.
|
|
12
|
+
* Setting `data-unsaved="true"` marks the values the page loaded with as unsaved too, such as after saving fails.
|
|
13
|
+
*/
|
|
14
|
+
class UnsavedChanges extends BaseDialog {
|
|
15
|
+
/** @type {HTMLFormElement} */
|
|
16
|
+
#form;
|
|
17
|
+
|
|
18
|
+
/** @type {HTMLElement|null} */
|
|
19
|
+
#indicator;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Serialized form values from when the page loaded, or empty until that has been captured.
|
|
23
|
+
* @type {string}
|
|
24
|
+
*/
|
|
25
|
+
#initialState = '';
|
|
26
|
+
|
|
27
|
+
/** @type {((event: BeforeUnloadEvent) => void)|undefined} */
|
|
28
|
+
#beforeUnloadListener;
|
|
29
|
+
|
|
30
|
+
/** @type {((event: PJaxNavigatingEvent) => void)|undefined} */
|
|
31
|
+
#navigatingListener;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Latest navigation waiting for the user's answer.
|
|
35
|
+
* @type {PJaxNavigatingEvent|undefined}
|
|
36
|
+
*/
|
|
37
|
+
#pendingNavigation;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether the form was submitted since its last change. Submitting saves the changes, so leaving shouldn't warn, unless
|
|
41
|
+
* PJax reports that it failed.
|
|
42
|
+
* @type {boolean}
|
|
43
|
+
*/
|
|
44
|
+
#submitted = false;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Start watching the form.
|
|
48
|
+
*/
|
|
49
|
+
constructor() {
|
|
50
|
+
super();
|
|
51
|
+
|
|
52
|
+
this.#form = this.querySelector('form');
|
|
53
|
+
if (!this.#form) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.#indicator = this.getElement('unsaved-indicator');
|
|
58
|
+
|
|
59
|
+
this.#beforeUnloadListener = event => this.#onBeforeUnload(event);
|
|
60
|
+
this.#navigatingListener = event => this.#onNavigating(event);
|
|
61
|
+
|
|
62
|
+
this.#form.addEventListener('input', () => this.#onChange());
|
|
63
|
+
this.#form.addEventListener('change', () => this.#onChange());
|
|
64
|
+
this.#form.addEventListener('submit', () => {
|
|
65
|
+
this.#submitted = true;
|
|
66
|
+
});
|
|
67
|
+
// the changes weren't saved after all
|
|
68
|
+
this.#form.addEventListener(PJaxErrorEvent.Name, () => {
|
|
69
|
+
this.#submitted = false;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// let other components finish setting up their fields, since that can change values, before capturing them
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
this.#initialState = this.#serialize();
|
|
75
|
+
this.#update();
|
|
76
|
+
}, 0);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Start watching for navigation each time the component is added to the page, so moving it keeps it working.
|
|
81
|
+
*/
|
|
82
|
+
connectedCallback() {
|
|
83
|
+
if (this.#beforeUnloadListener) {
|
|
84
|
+
window.addEventListener('beforeunload', this.#beforeUnloadListener);
|
|
85
|
+
}
|
|
86
|
+
if (this.#navigatingListener) {
|
|
87
|
+
document.addEventListener(PJaxNavigatingEvent.Name, this.#navigatingListener);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Clean up when removing component. Listeners are kept, so they can be added again if the component returns.
|
|
93
|
+
*/
|
|
94
|
+
disconnectedCallback() {
|
|
95
|
+
if (this.#beforeUnloadListener) {
|
|
96
|
+
window.removeEventListener('beforeunload', this.#beforeUnloadListener);
|
|
97
|
+
}
|
|
98
|
+
if (this.#navigatingListener) {
|
|
99
|
+
document.removeEventListener(PJaxNavigatingEvent.Name, this.#navigatingListener);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
super.disconnectedCallback();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Gets whether the form's values differ from when the page loaded.
|
|
107
|
+
* @returns {boolean} True if there are unsaved changes.
|
|
108
|
+
*/
|
|
109
|
+
get #isDirty() {
|
|
110
|
+
return this.dataset.unsaved === 'true' || (this.#initialState !== '' && this.#serialize() !== this.#initialState);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Gets whether leaving should warn: there are unsaved changes, and the form hasn't been submitted since they were made.
|
|
115
|
+
* @returns {boolean} True if leaving should ask first.
|
|
116
|
+
*/
|
|
117
|
+
get #shouldWarn() {
|
|
118
|
+
return !this.#submitted && this.#isDirty;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Handles a change to the form: new changes need saving again, so leaving warns again.
|
|
123
|
+
*/
|
|
124
|
+
#onChange() {
|
|
125
|
+
this.#submitted = false;
|
|
126
|
+
this.#update();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Turn the form's values into a string that can be compared.
|
|
131
|
+
* @returns {string} The serialized values.
|
|
132
|
+
*/
|
|
133
|
+
#serialize() {
|
|
134
|
+
// files can't be compared by value, so use their metadata
|
|
135
|
+
const entries = [...new FormData(this.#form)]
|
|
136
|
+
// editor drops white space between tags, which doesn't count as a change
|
|
137
|
+
.map(([name, value]) => (typeof value === 'string' ? [name, value.replace(/>\s+(?=<|$)/g, '>')] : [name, value.name, value.size]));
|
|
138
|
+
return JSON.stringify(entries);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Show the indicator only when there are unsaved changes.
|
|
143
|
+
*/
|
|
144
|
+
#update() {
|
|
145
|
+
if (this.#indicator) {
|
|
146
|
+
this.#indicator.hidden = !this.#isDirty;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Ask the browser to show its own prompt when the page unloads with unsaved changes.
|
|
152
|
+
* @param {BeforeUnloadEvent} event Event for the page unloading.
|
|
153
|
+
*/
|
|
154
|
+
#onBeforeUnload(event) {
|
|
155
|
+
if (this.#shouldWarn) {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Ask the user to confirm before PJax navigates to another page, whether from a link or the back and forward buttons.
|
|
162
|
+
* @param {PJaxNavigatingEvent} event Event raised before PJax navigates.
|
|
163
|
+
*/
|
|
164
|
+
#onNavigating(event) {
|
|
165
|
+
if (!this.#shouldWarn) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
// pressing back again while the dialog is open changes which navigation is being asked about
|
|
171
|
+
this.#pendingNavigation = event;
|
|
172
|
+
|
|
173
|
+
const { message, ok, cancel } = this.dataset;
|
|
174
|
+
const text = [message || getText('unsaved', this), ok || getText('leave', this), cancel || getText('stay', this)];
|
|
175
|
+
this.showDialog(...text, (returnValue) => {
|
|
176
|
+
if (returnValue === 'ok') {
|
|
177
|
+
this.#pendingNavigation.proceed();
|
|
178
|
+
} else {
|
|
179
|
+
this.#pendingNavigation.cancel();
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
defineElement('nilla-unsaved-changes', UnsavedChanges);
|
|
186
|
+
|
|
187
|
+
export default UnsavedChanges;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum for custom http request/response headers.
|
|
3
|
+
* @readonly
|
|
4
|
+
* @enum {string}
|
|
5
|
+
*/
|
|
6
|
+
const HttpHeaders = Object.freeze({
|
|
7
|
+
PJax: 'x-pjax',
|
|
8
|
+
PJaxTitle: 'x-pjax-title',
|
|
9
|
+
PJaxDescription: 'x-pjax-description',
|
|
10
|
+
PJaxCanonical: 'x-pjax-canonical',
|
|
11
|
+
PJaxOgType: 'x-pjax-og-type',
|
|
12
|
+
PJaxPushUrl: 'x-pjax-push-url',
|
|
13
|
+
PJaxRefresh: 'x-pjax-refresh',
|
|
14
|
+
PJaxVersion: 'x-pjax-version',
|
|
15
|
+
RequestedWith: 'x-requested-with',
|
|
16
|
+
ContentType: 'Content-Type',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default HttpHeaders;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum for identifiers to query DOM elements for the table component.
|
|
3
|
+
* @readonly
|
|
4
|
+
* @enum {string}
|
|
5
|
+
*/
|
|
6
|
+
const TableElements = Object.freeze({
|
|
7
|
+
Search: 'search',
|
|
8
|
+
FirstPage: 'first-page',
|
|
9
|
+
PreviousPage: 'previous-page',
|
|
10
|
+
NextPage: 'next-page',
|
|
11
|
+
LastPage: 'last-page',
|
|
12
|
+
PerPage: 'per-page',
|
|
13
|
+
Retry: 'retry',
|
|
14
|
+
StartRow: 'start-row',
|
|
15
|
+
EndRow: 'end-row',
|
|
16
|
+
FilteredRows: 'filtered-rows',
|
|
17
|
+
Loading: 'loading',
|
|
18
|
+
Error: 'error',
|
|
19
|
+
Empty: 'empty',
|
|
20
|
+
SortButton: 'sort-button',
|
|
21
|
+
Status: 'status',
|
|
22
|
+
MaxResults: 'max-results',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export default TableElements;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum for table setting keys.
|
|
3
|
+
* @readonly
|
|
4
|
+
* @enum {string}
|
|
5
|
+
*/
|
|
6
|
+
const TableSettings = Object.freeze({
|
|
7
|
+
CurrentPage: 'currentPage',
|
|
8
|
+
PerPage: 'perPage',
|
|
9
|
+
Search: 'search',
|
|
10
|
+
Sort: 'sort',
|
|
11
|
+
FormData: 'formData',
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export default TableSettings;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event dispatched by nilla-list after the user drags an item to a new position. It bubbles, so a form can listen for it.
|
|
3
|
+
*/
|
|
4
|
+
class ListReorderEvent extends Event {
|
|
5
|
+
/**
|
|
6
|
+
* Name of the event.
|
|
7
|
+
* @type {string}
|
|
8
|
+
*/
|
|
9
|
+
static Name = 'nilla:list-reorder';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create the event.
|
|
13
|
+
*/
|
|
14
|
+
constructor() {
|
|
15
|
+
super(ListReorderEvent.Name, { bubbles: true });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default ListReorderEvent;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event dispatched when a PJax request fails, before the error dialog opens. It comes from the form that was sent, or else
|
|
3
|
+
* from the PJax element, and bubbles. A form also gets one, without a dialog, when something else stops its request.
|
|
4
|
+
*/
|
|
5
|
+
class PJaxErrorEvent extends Event {
|
|
6
|
+
/**
|
|
7
|
+
* Name of the event.
|
|
8
|
+
* @type {string}
|
|
9
|
+
*/
|
|
10
|
+
static Name = 'nilla:pjax-error';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Url that was requested.
|
|
14
|
+
* @type {URL}
|
|
15
|
+
*/
|
|
16
|
+
url;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether the request was stopped by another, rather than failing.
|
|
20
|
+
* @type {boolean}
|
|
21
|
+
*/
|
|
22
|
+
aborted;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create the event.
|
|
26
|
+
* @param {URL} url Url that was requested.
|
|
27
|
+
* @param {object} [options] Options for the event.
|
|
28
|
+
* @param {boolean} [options.aborted] Whether the request was stopped by another.
|
|
29
|
+
*/
|
|
30
|
+
constructor(url, { aborted = false } = {}) {
|
|
31
|
+
super(PJaxErrorEvent.Name, { bubbles: true });
|
|
32
|
+
|
|
33
|
+
this.url = url;
|
|
34
|
+
this.aborted = aborted;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default PJaxErrorEvent;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event raised on the document before PJax navigates to another page.
|
|
3
|
+
* Listeners can cancel it to stop the navigation, for example to ask the user about unsaved changes.
|
|
4
|
+
* Listeners that cancel must later call either `proceed` or `cancel`.
|
|
5
|
+
*/
|
|
6
|
+
class PJaxNavigatingEvent extends Event {
|
|
7
|
+
/**
|
|
8
|
+
* Name of the event.
|
|
9
|
+
* @type {string}
|
|
10
|
+
*/
|
|
11
|
+
static Name = 'nilla:pjax-navigating';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Url that will be loaded.
|
|
15
|
+
* @type {URL}
|
|
16
|
+
*/
|
|
17
|
+
url;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Continue with the navigation that was canceled.
|
|
21
|
+
* @type {() => Promise<void>}
|
|
22
|
+
*/
|
|
23
|
+
proceed;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Stay on the current page after canceling the navigation.
|
|
27
|
+
* @type {() => void}
|
|
28
|
+
*/
|
|
29
|
+
cancel;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Create the event.
|
|
33
|
+
* @param {URL} url Url that will be loaded.
|
|
34
|
+
* @param {() => Promise<void>} proceed Continues with the navigation.
|
|
35
|
+
* @param {() => void} cancel Stays on the current page.
|
|
36
|
+
*/
|
|
37
|
+
constructor(url, proceed, cancel) {
|
|
38
|
+
super(PJaxNavigatingEvent.Name, { cancelable: true });
|
|
39
|
+
|
|
40
|
+
this.url = url;
|
|
41
|
+
this.proceed = proceed;
|
|
42
|
+
this.cancel = cancel;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default PJaxNavigatingEvent;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers every nilla component. Import individual components instead to keep bundles small,
|
|
3
|
+
* such as `import '@avlcodemonkey/nilla-components/table'`.
|
|
4
|
+
* List reordering needs SortableJS: import `@avlcodemonkey/nilla-components/list-sortable` as well.
|
|
5
|
+
*/
|
|
6
|
+
export { default as Alert } from './components/Alert.js';
|
|
7
|
+
export { default as Autocomplete } from './components/Autocomplete.js';
|
|
8
|
+
export { default as BaseComponent } from './components/BaseComponent.js';
|
|
9
|
+
export { default as BaseDialog } from './components/BaseDialog.js';
|
|
10
|
+
export { default as ConfirmDialog } from './components/ConfirmDialog.js';
|
|
11
|
+
export { default as CopyToClipboard } from './components/CopyToClipboard.js';
|
|
12
|
+
export { default as DateFormatter } from './components/DateFormatter.js';
|
|
13
|
+
export { default as DateTimeInput } from './components/DateTimeInput.js';
|
|
14
|
+
export { default as DisplayToggle } from './components/DisplayToggle.js';
|
|
15
|
+
export { default as FileToTextarea } from './components/FileToTextarea.js';
|
|
16
|
+
export { default as HtmlEditor } from './components/HtmlEditor.js';
|
|
17
|
+
export { default as InfoDialog } from './components/InfoDialog.js';
|
|
18
|
+
export { default as JsonFormatter } from './components/JsonFormatter.js';
|
|
19
|
+
export { default as List } from './components/List.js';
|
|
20
|
+
export { default as NavToggle } from './components/NavToggle.js';
|
|
21
|
+
export { default as PJax } from './components/PJax.js';
|
|
22
|
+
export { default as Share } from './components/Share.js';
|
|
23
|
+
export { default as SliderInput } from './components/SliderInput.js';
|
|
24
|
+
export { default as Table } from './components/Table.js';
|
|
25
|
+
export { default as TimeOffsetSelect } from './components/TimeOffsetSelect.js';
|
|
26
|
+
export { default as UnsavedChanges } from './components/UnsavedChanges.js';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ok": "OK",
|
|
3
|
+
"cancel": "Cancel",
|
|
4
|
+
"save": "Save",
|
|
5
|
+
"delete": "Delete",
|
|
6
|
+
"leave": "Leave",
|
|
7
|
+
"stay": "Stay",
|
|
8
|
+
"unsaved": "Leave without saving?",
|
|
9
|
+
"fileTooLarge": "File is too large.",
|
|
10
|
+
"list.moved": "Position {{position}} of {{count}}",
|
|
11
|
+
"editor.deleteTableConfirm": "Delete this table?",
|
|
12
|
+
"editor.format": "Text style",
|
|
13
|
+
"editor.paragraph": "Paragraph",
|
|
14
|
+
"editor.heading": "Heading",
|
|
15
|
+
"editor.bold": "Bold",
|
|
16
|
+
"editor.italic": "Italic",
|
|
17
|
+
"editor.strike": "Strikethrough",
|
|
18
|
+
"editor.code": "Code",
|
|
19
|
+
"editor.codeBlock": "Code block (Ctrl+Enter to exit)",
|
|
20
|
+
"editor.quote": "Quote",
|
|
21
|
+
"editor.hr": "Line",
|
|
22
|
+
"editor.ul": "Bulleted list",
|
|
23
|
+
"editor.ol": "Numbered list",
|
|
24
|
+
"editor.indent": "Indent",
|
|
25
|
+
"editor.outdent": "Outdent",
|
|
26
|
+
"editor.link": "Link",
|
|
27
|
+
"editor.removeLink": "Remove link",
|
|
28
|
+
"editor.url": "URL",
|
|
29
|
+
"editor.openIn": "Open in",
|
|
30
|
+
"editor.currentTab": "This tab",
|
|
31
|
+
"editor.newTab": "New tab",
|
|
32
|
+
"editor.image": "Image",
|
|
33
|
+
"editor.alt": "Alt text",
|
|
34
|
+
"editor.size": "Size",
|
|
35
|
+
"editor.sizeNone": "None",
|
|
36
|
+
"editor.position": "Position",
|
|
37
|
+
"editor.positionNone": "None",
|
|
38
|
+
"editor.left": "Left",
|
|
39
|
+
"editor.center": "Center",
|
|
40
|
+
"editor.right": "Right",
|
|
41
|
+
"editor.table": "Table",
|
|
42
|
+
"editor.rows": "Rows",
|
|
43
|
+
"editor.columns": "Columns",
|
|
44
|
+
"editor.insertTable": "Insert table",
|
|
45
|
+
"editor.rowAbove": "Add row above",
|
|
46
|
+
"editor.rowBelow": "Add row below",
|
|
47
|
+
"editor.columnLeft": "Add column left",
|
|
48
|
+
"editor.columnRight": "Add column right",
|
|
49
|
+
"editor.alignLeft": "Align column left",
|
|
50
|
+
"editor.alignCenter": "Center column",
|
|
51
|
+
"editor.alignRight": "Align column right",
|
|
52
|
+
"editor.deleteRow": "Delete row",
|
|
53
|
+
"editor.deleteColumn": "Delete column",
|
|
54
|
+
"editor.deleteTable": "Delete table"
|
|
55
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spanish text for the components. Importing it is all that's needed: it's used wherever the page's language is Spanish.
|
|
3
|
+
*/
|
|
4
|
+
import { setLocale } from '../utils/locale.js';
|
|
5
|
+
import es from './es.json' with { type: 'json' };
|
|
6
|
+
|
|
7
|
+
setLocale('es', es);
|
|
8
|
+
|
|
9
|
+
export default es;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ok": "Aceptar",
|
|
3
|
+
"cancel": "Cancelar",
|
|
4
|
+
"save": "Guardar",
|
|
5
|
+
"delete": "Eliminar",
|
|
6
|
+
"leave": "Salir",
|
|
7
|
+
"stay": "Quedarse",
|
|
8
|
+
"unsaved": "¿Salir sin guardar?",
|
|
9
|
+
"fileTooLarge": "El archivo es demasiado grande.",
|
|
10
|
+
"list.moved": "Posición {{position}} de {{count}}",
|
|
11
|
+
"editor.deleteTableConfirm": "¿Eliminar esta tabla?",
|
|
12
|
+
"editor.format": "Estilo de texto",
|
|
13
|
+
"editor.paragraph": "Párrafo",
|
|
14
|
+
"editor.heading": "Título",
|
|
15
|
+
"editor.bold": "Negrita",
|
|
16
|
+
"editor.italic": "Cursiva",
|
|
17
|
+
"editor.strike": "Tachado",
|
|
18
|
+
"editor.code": "Código",
|
|
19
|
+
"editor.codeBlock": "Bloque de código (Ctrl+Enter para salir)",
|
|
20
|
+
"editor.quote": "Cita",
|
|
21
|
+
"editor.hr": "Línea",
|
|
22
|
+
"editor.ul": "Lista con viñetas",
|
|
23
|
+
"editor.ol": "Lista numerada",
|
|
24
|
+
"editor.indent": "Aumentar sangría",
|
|
25
|
+
"editor.outdent": "Reducir sangría",
|
|
26
|
+
"editor.link": "Enlace",
|
|
27
|
+
"editor.removeLink": "Quitar enlace",
|
|
28
|
+
"editor.url": "URL",
|
|
29
|
+
"editor.openIn": "Abrir en",
|
|
30
|
+
"editor.currentTab": "Esta pestaña",
|
|
31
|
+
"editor.newTab": "Pestaña nueva",
|
|
32
|
+
"editor.image": "Imagen",
|
|
33
|
+
"editor.alt": "Texto alternativo",
|
|
34
|
+
"editor.size": "Tamaño",
|
|
35
|
+
"editor.sizeNone": "Ninguno",
|
|
36
|
+
"editor.position": "Posición",
|
|
37
|
+
"editor.positionNone": "Ninguna",
|
|
38
|
+
"editor.left": "Izquierda",
|
|
39
|
+
"editor.center": "Centro",
|
|
40
|
+
"editor.right": "Derecha",
|
|
41
|
+
"editor.table": "Tabla",
|
|
42
|
+
"editor.rows": "Filas",
|
|
43
|
+
"editor.columns": "Columnas",
|
|
44
|
+
"editor.insertTable": "Insertar tabla",
|
|
45
|
+
"editor.rowAbove": "Añadir fila arriba",
|
|
46
|
+
"editor.rowBelow": "Añadir fila abajo",
|
|
47
|
+
"editor.columnLeft": "Añadir columna a la izquierda",
|
|
48
|
+
"editor.columnRight": "Añadir columna a la derecha",
|
|
49
|
+
"editor.alignLeft": "Alinear columna a la izquierda",
|
|
50
|
+
"editor.alignCenter": "Centrar columna",
|
|
51
|
+
"editor.alignRight": "Alinear columna a la derecha",
|
|
52
|
+
"editor.deleteRow": "Eliminar fila",
|
|
53
|
+
"editor.deleteColumn": "Eliminar columna",
|
|
54
|
+
"editor.deleteTable": "Eliminar tabla"
|
|
55
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import SortDirection from '../constants/SortDirection.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Table sort settings.
|
|
5
|
+
*/
|
|
6
|
+
class TableSort {
|
|
7
|
+
/**
|
|
8
|
+
* Name of property to sort on.
|
|
9
|
+
* @type {string}
|
|
10
|
+
*/
|
|
11
|
+
property = '';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Direction to sort this property.
|
|
15
|
+
* @type {SortDirection}
|
|
16
|
+
*/
|
|
17
|
+
direction = undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default TableSort;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import HttpHeaders from '../constants/HttpHeaders.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Build request headers that mark a fetch as an ajax request, so the server returns json or partial content.
|
|
5
|
+
* @param {Record<string, string|boolean>} [extraHeaders] Additional headers to include.
|
|
6
|
+
* @returns {Record<string, string|boolean>} Headers for fetch.
|
|
7
|
+
*/
|
|
8
|
+
export default function ajaxHeaders(extraHeaders = {}) {
|
|
9
|
+
return { [HttpHeaders.RequestedWith]: 'XMLHttpRequest', ...extraHeaders };
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Element screen readers watch for messages.
|
|
3
|
+
* @type {HTMLElement|undefined}
|
|
4
|
+
*/
|
|
5
|
+
let region;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Time between adding or clearing the element and filling it, in milliseconds. Screen readers miss changes made at once.
|
|
9
|
+
* @type {number}
|
|
10
|
+
*/
|
|
11
|
+
const Delay = 100;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tells screen reader users about a change they can't see, such as how many rows a search found.
|
|
15
|
+
* @param {string|undefined} text Message. Nothing is said without one.
|
|
16
|
+
*/
|
|
17
|
+
export default function announce(text) {
|
|
18
|
+
const message = text?.replace(/\s+/g, ' ').trim();
|
|
19
|
+
if (!message) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// the rest of the page is inert while a modal dialog is open
|
|
24
|
+
const parent = document.querySelector('dialog[open]') ?? document.body;
|
|
25
|
+
if (region?.parentNode !== parent) {
|
|
26
|
+
region?.remove();
|
|
27
|
+
region = document.createElement('div');
|
|
28
|
+
region.setAttribute('role', 'status');
|
|
29
|
+
// out of sight, but not hidden from screen readers
|
|
30
|
+
Object.assign(region.style, { position: 'absolute', width: '1px', height: '1px', overflow: 'hidden', clipPath: 'inset(50%)', whiteSpace: 'nowrap' });
|
|
31
|
+
parent.append(region);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// clear it first, so the same message is said again
|
|
35
|
+
const current = region;
|
|
36
|
+
current.textContent = '';
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
current.textContent = message;
|
|
39
|
+
}, Delay);
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a custom element unless it's already defined, such as when two bundles include the same component.
|
|
3
|
+
* Also does nothing when custom elements aren't available. Component modules still need a DOM to load, since their
|
|
4
|
+
* classes extend `HTMLElement`.
|
|
5
|
+
* @param {string} name Tag name for the element.
|
|
6
|
+
* @param {typeof HTMLElement} constructor Class for the element.
|
|
7
|
+
*/
|
|
8
|
+
export default function defineElement(name, constructor) {
|
|
9
|
+
if (typeof window === 'undefined' || !('customElements' in window) || customElements.get(name)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
customElements.define(name, constructor);
|
|
13
|
+
}
|