tyrell-components 1.0.0-RC15 → 1.0.0-RC17
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/README.md +44 -52
- package/css/tyrell-colors-static.css +14 -0
- package/css/tyrell-theme.css +13 -7
- package/css/tyrell.css +15 -22
- package/dist/tyrell-colors-static.css +1 -1
- package/dist/tyrell-theme.css +1 -1
- package/dist/tyrell.css +1 -1
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +37 -15
- package/lib/base/ty-component.js +90 -26
- package/lib/components/button.d.ts +14 -0
- package/lib/components/button.js +61 -7
- package/lib/components/calendar-month.d.ts +7 -1
- package/lib/components/calendar-month.js +38 -30
- package/lib/components/calendar-navigation.d.ts +11 -0
- package/lib/components/calendar-navigation.js +68 -44
- package/lib/components/calendar.d.ts +52 -3
- package/lib/components/calendar.js +274 -61
- package/lib/components/checkbox.d.ts +8 -1
- package/lib/components/checkbox.js +29 -8
- package/lib/components/copy.d.ts +2 -0
- package/lib/components/copy.js +24 -33
- package/lib/components/date-picker.d.ts +68 -34
- package/lib/components/date-picker.js +386 -389
- package/lib/components/file-upload.d.ts +7 -0
- package/lib/components/file-upload.js +36 -4
- package/lib/components/input.d.ts +73 -3
- package/lib/components/input.js +159 -24
- package/lib/components/modal.d.ts +4 -8
- package/lib/components/modal.js +103 -33
- package/lib/components/option.js +7 -5
- package/lib/components/popup.js +117 -14
- package/lib/components/radio.d.ts +24 -0
- package/lib/components/radio.js +55 -32
- package/lib/components/resize-observer.js +2 -0
- package/lib/components/scroll-container.d.ts +3 -2
- package/lib/components/scroll-container.js +7 -8
- package/lib/components/select.d.ts +68 -11
- package/lib/components/select.js +196 -44
- package/lib/components/selected-tags.d.ts +7 -1
- package/lib/components/selected-tags.js +10 -1
- package/lib/components/switch.d.ts +9 -1
- package/lib/components/switch.js +29 -8
- package/lib/components/tab.d.ts +49 -1
- package/lib/components/tab.js +151 -10
- package/lib/components/tabs.d.ts +14 -2
- package/lib/components/tabs.js +185 -136
- package/lib/components/tag.d.ts +4 -7
- package/lib/components/tag.js +6 -7
- package/lib/components/textarea.d.ts +51 -5
- package/lib/components/textarea.js +95 -30
- package/lib/components/tooltip.d.ts +4 -3
- package/lib/components/tooltip.js +34 -24
- package/lib/components/wizard.d.ts +5 -4
- package/lib/components/wizard.js +120 -156
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -0
- package/lib/styles/button.js +21 -19
- package/lib/styles/calendar-month.d.ts +3 -0
- package/lib/styles/calendar-month.js +43 -27
- package/lib/styles/calendar-navigation.d.ts +1 -1
- package/lib/styles/calendar-navigation.js +55 -26
- package/lib/styles/calendar.d.ts +3 -2
- package/lib/styles/calendar.js +77 -0
- package/lib/styles/checkbox.js +31 -13
- package/lib/styles/copy.js +5 -1
- package/lib/styles/date-picker.js +68 -26
- package/lib/styles/file-upload.d.ts +1 -1
- package/lib/styles/file-upload.js +3 -3
- package/lib/styles/icon.d.ts +1 -1
- package/lib/styles/icon.js +2 -2
- package/lib/styles/input.js +6 -10
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +7 -3
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.js +10 -5
- package/lib/styles/radio.js +18 -6
- package/lib/styles/scroll-container.d.ts +1 -1
- package/lib/styles/scroll-container.js +1 -1
- package/lib/styles/select-base.js +24 -3
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +10 -0
- package/lib/styles/step.d.ts +1 -1
- package/lib/styles/step.js +1 -9
- package/lib/styles/switch.js +14 -6
- package/lib/styles/tab.d.ts +1 -1
- package/lib/styles/tab.js +67 -3
- package/lib/styles/tabs.d.ts +1 -1
- package/lib/styles/tabs.js +7 -3
- package/lib/styles/tag.js +3 -3
- package/lib/styles/textarea.d.ts +1 -1
- package/lib/styles/textarea.js +7 -0
- package/lib/styles/wizard.d.ts +9 -5
- package/lib/styles/wizard.js +211 -99
- package/lib/types/common.d.ts +2 -2
- package/lib/utils/calendar-utils.d.ts +49 -0
- package/lib/utils/calendar-utils.js +63 -6
- package/lib/utils/property-manager.d.ts +7 -1
- package/lib/utils/property-manager.js +16 -4
- package/lib/utils/scroll-lock.d.ts +10 -4
- package/lib/utils/scroll-lock.js +102 -2
- package/lib/utils/upgrade-properties.d.ts +21 -0
- package/lib/utils/upgrade-properties.js +47 -0
- package/lib/utils/validity.d.ts +122 -0
- package/lib/utils/validity.js +289 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +27 -5
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
let submitAttempt = false;
|
|
2
|
+
let pointerPressed = false;
|
|
3
|
+
let touchRelease;
|
|
4
|
+
const pendingReveals = new Set();
|
|
5
|
+
let documentWatched = false;
|
|
6
|
+
function release() {
|
|
7
|
+
clearTimeout(touchRelease);
|
|
8
|
+
pointerPressed = false;
|
|
9
|
+
if (pendingReveals.size === 0)
|
|
10
|
+
return;
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
const waiting = [...pendingReveals];
|
|
13
|
+
pendingReveals.clear();
|
|
14
|
+
waiting.forEach((c) => c.reveal());
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function watchDocument() {
|
|
18
|
+
if (documentWatched)
|
|
19
|
+
return;
|
|
20
|
+
documentWatched = true;
|
|
21
|
+
const mark = () => {
|
|
22
|
+
submitAttempt = true;
|
|
23
|
+
setTimeout(() => { submitAttempt = false; });
|
|
24
|
+
};
|
|
25
|
+
document.addEventListener('click', (e) => {
|
|
26
|
+
const control = e.composedPath().find((n) => n instanceof HTMLButtonElement || n instanceof HTMLInputElement);
|
|
27
|
+
if (control?.form && (control.type === 'submit' || control.type === 'image'))
|
|
28
|
+
mark();
|
|
29
|
+
if (pointerPressed)
|
|
30
|
+
release();
|
|
31
|
+
}, true);
|
|
32
|
+
document.addEventListener('keydown', (e) => {
|
|
33
|
+
const target = e.composedPath()[0];
|
|
34
|
+
if (e.key === 'Enter' && !e.isComposing && target instanceof HTMLInputElement && target.form)
|
|
35
|
+
mark();
|
|
36
|
+
}, true);
|
|
37
|
+
document.addEventListener('pointerdown', () => {
|
|
38
|
+
clearTimeout(touchRelease);
|
|
39
|
+
pointerPressed = true;
|
|
40
|
+
}, true);
|
|
41
|
+
document.addEventListener('pointerup', (e) => {
|
|
42
|
+
if (e.pointerType === 'mouse')
|
|
43
|
+
release();
|
|
44
|
+
else
|
|
45
|
+
touchRelease = setTimeout(release, 1000);
|
|
46
|
+
}, true);
|
|
47
|
+
document.addEventListener('pointercancel', release, true);
|
|
48
|
+
watchRoot(document);
|
|
49
|
+
}
|
|
50
|
+
export function asSubmitAttempt(fn) {
|
|
51
|
+
const was = submitAttempt;
|
|
52
|
+
submitAttempt = true;
|
|
53
|
+
try {
|
|
54
|
+
return fn();
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
submitAttempt = was;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const formMethods = ['requestSubmit', 'reportValidity'];
|
|
61
|
+
const wrappedForms = new WeakMap();
|
|
62
|
+
function wrapForm(form) {
|
|
63
|
+
let entry = wrappedForms.get(form);
|
|
64
|
+
if (entry)
|
|
65
|
+
return entry;
|
|
66
|
+
entry = { fields: new Set(), ours: {} };
|
|
67
|
+
wrappedForms.set(form, entry);
|
|
68
|
+
for (const name of formMethods) {
|
|
69
|
+
if (typeof form[name] !== 'function')
|
|
70
|
+
continue;
|
|
71
|
+
const replaced = Object.getOwnPropertyDescriptor(form, name);
|
|
72
|
+
const previous = replaced ? form[name] : undefined;
|
|
73
|
+
const fn = function (...args) {
|
|
74
|
+
const next = previous ?? Object.getPrototypeOf(form)[name];
|
|
75
|
+
return asSubmitAttempt(() => next.apply(this, args));
|
|
76
|
+
};
|
|
77
|
+
Object.defineProperty(form, name, { value: fn, writable: true, configurable: true, enumerable: false });
|
|
78
|
+
entry.ours[name] = { fn, replaced };
|
|
79
|
+
}
|
|
80
|
+
return entry;
|
|
81
|
+
}
|
|
82
|
+
function unwrapForm(form, entry) {
|
|
83
|
+
wrappedForms.delete(form);
|
|
84
|
+
for (const name of formMethods) {
|
|
85
|
+
const own = entry.ours[name];
|
|
86
|
+
if (!own || Object.getOwnPropertyDescriptor(form, name)?.value !== own.fn)
|
|
87
|
+
continue;
|
|
88
|
+
if (own.replaced)
|
|
89
|
+
Object.defineProperty(form, name, own.replaced);
|
|
90
|
+
else
|
|
91
|
+
delete form[name];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const watchedRoots = new WeakSet();
|
|
95
|
+
function watchRoot(root) {
|
|
96
|
+
if (watchedRoots.has(root))
|
|
97
|
+
return;
|
|
98
|
+
watchedRoots.add(root);
|
|
99
|
+
root.addEventListener('invalid', (e) => {
|
|
100
|
+
if (!submitAttempt)
|
|
101
|
+
return;
|
|
102
|
+
const target = e.target;
|
|
103
|
+
const first = target.form ? firstInvalid(target.form) : undefined;
|
|
104
|
+
if (first && first !== target && hasErrorLine(first))
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
}, true);
|
|
107
|
+
}
|
|
108
|
+
function within(host, node) {
|
|
109
|
+
for (let n = node; n; n = n.getRootNode().host) {
|
|
110
|
+
if (host.contains(n))
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
function firstInvalid(form) {
|
|
116
|
+
return Array.from(form.elements).find((el) => {
|
|
117
|
+
const c = el;
|
|
118
|
+
return c.willValidate && c.validity && !c.validity.valid &&
|
|
119
|
+
c.checkVisibility?.({ visibilityProperty: true, checkVisibilityCSS: true }) !== false;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const hosts = new WeakSet();
|
|
123
|
+
function hasErrorLine(el) {
|
|
124
|
+
return hosts.has(el) && 'error' in el;
|
|
125
|
+
}
|
|
126
|
+
export class ValidityController {
|
|
127
|
+
constructor(host, internals) {
|
|
128
|
+
this.host = host;
|
|
129
|
+
this.internals = internals;
|
|
130
|
+
this.own = { flags: {} };
|
|
131
|
+
this.custom = '';
|
|
132
|
+
this.written = null;
|
|
133
|
+
this.shown = [];
|
|
134
|
+
this.form = null;
|
|
135
|
+
watchDocument();
|
|
136
|
+
hosts.add(host);
|
|
137
|
+
host.addEventListener('invalid', () => {
|
|
138
|
+
if (this.anchor && !this.shown.includes(this.anchor))
|
|
139
|
+
this.shown = [...this.shown.slice(-1), this.anchor];
|
|
140
|
+
});
|
|
141
|
+
host.addEventListener('invalid', (e) => {
|
|
142
|
+
if (!hasErrorLine(host))
|
|
143
|
+
return;
|
|
144
|
+
watchRoot(host.getRootNode());
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
this.showError();
|
|
147
|
+
if (!submitAttempt)
|
|
148
|
+
return;
|
|
149
|
+
const form = this.internals.form;
|
|
150
|
+
if (!form || firstInvalid(form) === host)
|
|
151
|
+
host.focus();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
track() {
|
|
155
|
+
const form = hasErrorLine(this.host) ? this.internals.form : null;
|
|
156
|
+
if (form === this.form)
|
|
157
|
+
return;
|
|
158
|
+
const old = this.form && wrappedForms.get(this.form);
|
|
159
|
+
if (old) {
|
|
160
|
+
old.fields.delete(this);
|
|
161
|
+
for (const c of old.fields)
|
|
162
|
+
if (c.internals.form !== this.form)
|
|
163
|
+
old.fields.delete(c);
|
|
164
|
+
if (old.fields.size === 0)
|
|
165
|
+
unwrapForm(this.form, old);
|
|
166
|
+
}
|
|
167
|
+
this.form = form;
|
|
168
|
+
if (form)
|
|
169
|
+
wrapForm(form).fields.add(this);
|
|
170
|
+
}
|
|
171
|
+
reveal() {
|
|
172
|
+
if (pointerPressed) {
|
|
173
|
+
pendingReveals.add(this);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if ('error' in this.host && !this.internals.validity.valid)
|
|
177
|
+
this.showError();
|
|
178
|
+
}
|
|
179
|
+
get errorFromReport() {
|
|
180
|
+
return this.written !== null && this.host.getAttribute('error') === this.written;
|
|
181
|
+
}
|
|
182
|
+
writeError(message) {
|
|
183
|
+
this.written = message;
|
|
184
|
+
if (message === null)
|
|
185
|
+
this.host.removeAttribute('error');
|
|
186
|
+
else
|
|
187
|
+
this.host.setAttribute('error', message);
|
|
188
|
+
}
|
|
189
|
+
showError() {
|
|
190
|
+
if (this.host.getAttribute('error') && !this.errorFromReport)
|
|
191
|
+
return;
|
|
192
|
+
this.writeError(this.internals.validationMessage);
|
|
193
|
+
}
|
|
194
|
+
reset() {
|
|
195
|
+
pendingReveals.delete(this);
|
|
196
|
+
if (this.errorFromReport)
|
|
197
|
+
this.writeError(null);
|
|
198
|
+
this.written = null;
|
|
199
|
+
}
|
|
200
|
+
set(flags, message, anchor) {
|
|
201
|
+
this.own = { flags, message, anchor };
|
|
202
|
+
this.sync();
|
|
203
|
+
}
|
|
204
|
+
setCustom(message) {
|
|
205
|
+
this.custom = message || '';
|
|
206
|
+
this.sync();
|
|
207
|
+
}
|
|
208
|
+
report() {
|
|
209
|
+
const valid = this.internals.checkValidity();
|
|
210
|
+
if (valid)
|
|
211
|
+
return true;
|
|
212
|
+
if ('error' in this.host) {
|
|
213
|
+
this.showError();
|
|
214
|
+
this.host.focus();
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
this.internals.reportValidity();
|
|
218
|
+
}
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
sync() {
|
|
222
|
+
const { flags, message } = this.own;
|
|
223
|
+
const anchor = this.own.anchor && within(this.host, this.own.anchor) ? this.own.anchor : undefined;
|
|
224
|
+
this.anchor = anchor;
|
|
225
|
+
const invalid = Object.values(flags).some(Boolean);
|
|
226
|
+
if (this.custom) {
|
|
227
|
+
this.internals.setValidity({ ...flags, customError: true }, this.custom, anchor);
|
|
228
|
+
}
|
|
229
|
+
else if (invalid) {
|
|
230
|
+
this.internals.setValidity(flags, message || 'Invalid value', anchor);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
this.internals.setValidity({});
|
|
234
|
+
}
|
|
235
|
+
if (!this.errorFromReport) {
|
|
236
|
+
this.written = null;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (this.internals.validity.valid) {
|
|
240
|
+
this.writeError(null);
|
|
241
|
+
}
|
|
242
|
+
else if (this.host.getAttribute('error') !== this.internals.validationMessage) {
|
|
243
|
+
this.showError();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const probes = {};
|
|
248
|
+
export function nativeMessage(tag, attrs, value = '') {
|
|
249
|
+
const probe = (probes[tag] ?? (probes[tag] = document.createElement(tag)));
|
|
250
|
+
for (const name of probe.getAttributeNames())
|
|
251
|
+
probe.removeAttribute(name);
|
|
252
|
+
for (const [name, v] of Object.entries(attrs)) {
|
|
253
|
+
if (v === true)
|
|
254
|
+
probe.setAttribute(name, '');
|
|
255
|
+
else if (v)
|
|
256
|
+
probe.setAttribute(name, v);
|
|
257
|
+
}
|
|
258
|
+
probe.value = value;
|
|
259
|
+
return probe.validationMessage;
|
|
260
|
+
}
|
|
261
|
+
export function nativeValidity(tag, attrs, value = '') {
|
|
262
|
+
const message = nativeMessage(tag, attrs, value);
|
|
263
|
+
return { validity: probes[tag].validity, message };
|
|
264
|
+
}
|
|
265
|
+
export function toLimit(v) {
|
|
266
|
+
if (v === null || v === undefined || String(v).trim() === '')
|
|
267
|
+
return null;
|
|
268
|
+
const n = Number(v);
|
|
269
|
+
return Number.isInteger(n) && n >= 0 ? n : null;
|
|
270
|
+
}
|
|
271
|
+
function fillMessage(template, vars) {
|
|
272
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => vars[key] != null ? String(vars[key]) : match);
|
|
273
|
+
}
|
|
274
|
+
export function lengthValidity(value, rules, control) {
|
|
275
|
+
const length = value.length;
|
|
276
|
+
const minLength = toLimit(rules.minlength);
|
|
277
|
+
const maxLength = toLimit(rules.maxlength);
|
|
278
|
+
const vars = { minlength: minLength, maxlength: maxLength, length };
|
|
279
|
+
const result = {};
|
|
280
|
+
if (minLength !== null && length < minLength) {
|
|
281
|
+
result.tooShort = !rules.tooShortMessage && control?.validity.tooShort
|
|
282
|
+
? control.validationMessage
|
|
283
|
+
: fillMessage(rules.tooShortMessage || 'Use at least {minlength} characters (now {length})', vars);
|
|
284
|
+
}
|
|
285
|
+
if (maxLength !== null && length > maxLength) {
|
|
286
|
+
result.tooLong = fillMessage(rules.tooLongMessage || 'Use at most {maxlength} characters (now {length})', vars);
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
}
|
package/lib/version.d.ts
CHANGED
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '1.0.0-
|
|
1
|
+
export const VERSION = '1.0.0-RC17';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tyrell-components",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-RC17",
|
|
4
4
|
"description": "Tyrell Components - Framework-agnostic web components with semantic design system",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -105,9 +105,30 @@
|
|
|
105
105
|
"types": "./lib/icons/lucide.d.ts",
|
|
106
106
|
"import": "./lib/icons/lucide.js"
|
|
107
107
|
},
|
|
108
|
-
"./icons/heroicons
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
"./icons/heroicons/*.js": {
|
|
109
|
+
"types": "./lib/icons/heroicons/*.d.ts",
|
|
110
|
+
"import": "./lib/icons/heroicons/*.js"
|
|
111
|
+
},
|
|
112
|
+
"./icons/heroicons/*": {
|
|
113
|
+
"types": "./lib/icons/heroicons/*.d.ts",
|
|
114
|
+
"import": "./lib/icons/heroicons/*.js"
|
|
115
|
+
},
|
|
116
|
+
"./icons/material/*.js": {
|
|
117
|
+
"types": "./lib/icons/material/*.d.ts",
|
|
118
|
+
"import": "./lib/icons/material/*.js"
|
|
119
|
+
},
|
|
120
|
+
"./icons/material/*": {
|
|
121
|
+
"types": "./lib/icons/material/*.d.ts",
|
|
122
|
+
"import": "./lib/icons/material/*.js"
|
|
123
|
+
},
|
|
124
|
+
"./icons/fontawesome/*.js": {
|
|
125
|
+
"types": "./lib/icons/fontawesome/*.d.ts",
|
|
126
|
+
"import": "./lib/icons/fontawesome/*.js"
|
|
127
|
+
},
|
|
128
|
+
"./icons/fontawesome/*": {
|
|
129
|
+
"types": "./lib/icons/fontawesome/*.d.ts",
|
|
130
|
+
"import": "./lib/icons/fontawesome/*.js"
|
|
131
|
+
},
|
|
111
132
|
"./cdn": "./dist/tyrell.js"
|
|
112
133
|
},
|
|
113
134
|
"files": [
|
|
@@ -154,6 +175,7 @@
|
|
|
154
175
|
"@web/dev-server-esbuild": "^1.0.5",
|
|
155
176
|
"@web/test-runner": "^0.20.2",
|
|
156
177
|
"@web/test-runner-chrome": "^0.18.1",
|
|
178
|
+
"@web/test-runner-commands": "^0.9.0",
|
|
157
179
|
"autoprefixer": "^10.4.27",
|
|
158
180
|
"axe-core": "^4.12.1",
|
|
159
181
|
"typescript": "^5.7.0",
|
|
@@ -162,7 +184,7 @@
|
|
|
162
184
|
},
|
|
163
185
|
"repository": {
|
|
164
186
|
"type": "git",
|
|
165
|
-
"url": "https://github.com/gersak/tyrell.git",
|
|
187
|
+
"url": "git+https://github.com/gersak/tyrell.git",
|
|
166
188
|
"directory": "packages/core"
|
|
167
189
|
},
|
|
168
190
|
"homepage": "https://gersak.github.io/tyrell/",
|