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.
Files changed (108) hide show
  1. package/README.md +44 -52
  2. package/css/tyrell-colors-static.css +14 -0
  3. package/css/tyrell-theme.css +13 -7
  4. package/css/tyrell.css +15 -22
  5. package/dist/tyrell-colors-static.css +1 -1
  6. package/dist/tyrell-theme.css +1 -1
  7. package/dist/tyrell.css +1 -1
  8. package/dist/tyrell.js +1 -1
  9. package/lib/base/ty-component.d.ts +37 -15
  10. package/lib/base/ty-component.js +90 -26
  11. package/lib/components/button.d.ts +14 -0
  12. package/lib/components/button.js +61 -7
  13. package/lib/components/calendar-month.d.ts +7 -1
  14. package/lib/components/calendar-month.js +38 -30
  15. package/lib/components/calendar-navigation.d.ts +11 -0
  16. package/lib/components/calendar-navigation.js +68 -44
  17. package/lib/components/calendar.d.ts +52 -3
  18. package/lib/components/calendar.js +274 -61
  19. package/lib/components/checkbox.d.ts +8 -1
  20. package/lib/components/checkbox.js +29 -8
  21. package/lib/components/copy.d.ts +2 -0
  22. package/lib/components/copy.js +24 -33
  23. package/lib/components/date-picker.d.ts +68 -34
  24. package/lib/components/date-picker.js +386 -389
  25. package/lib/components/file-upload.d.ts +7 -0
  26. package/lib/components/file-upload.js +36 -4
  27. package/lib/components/input.d.ts +73 -3
  28. package/lib/components/input.js +159 -24
  29. package/lib/components/modal.d.ts +4 -8
  30. package/lib/components/modal.js +103 -33
  31. package/lib/components/option.js +7 -5
  32. package/lib/components/popup.js +117 -14
  33. package/lib/components/radio.d.ts +24 -0
  34. package/lib/components/radio.js +55 -32
  35. package/lib/components/resize-observer.js +2 -0
  36. package/lib/components/scroll-container.d.ts +3 -2
  37. package/lib/components/scroll-container.js +7 -8
  38. package/lib/components/select.d.ts +68 -11
  39. package/lib/components/select.js +196 -44
  40. package/lib/components/selected-tags.d.ts +7 -1
  41. package/lib/components/selected-tags.js +10 -1
  42. package/lib/components/switch.d.ts +9 -1
  43. package/lib/components/switch.js +29 -8
  44. package/lib/components/tab.d.ts +49 -1
  45. package/lib/components/tab.js +151 -10
  46. package/lib/components/tabs.d.ts +14 -2
  47. package/lib/components/tabs.js +185 -136
  48. package/lib/components/tag.d.ts +4 -7
  49. package/lib/components/tag.js +6 -7
  50. package/lib/components/textarea.d.ts +51 -5
  51. package/lib/components/textarea.js +95 -30
  52. package/lib/components/tooltip.d.ts +4 -3
  53. package/lib/components/tooltip.js +34 -24
  54. package/lib/components/wizard.d.ts +5 -4
  55. package/lib/components/wizard.js +120 -156
  56. package/lib/index.d.ts +2 -1
  57. package/lib/index.js +1 -0
  58. package/lib/styles/button.js +21 -19
  59. package/lib/styles/calendar-month.d.ts +3 -0
  60. package/lib/styles/calendar-month.js +43 -27
  61. package/lib/styles/calendar-navigation.d.ts +1 -1
  62. package/lib/styles/calendar-navigation.js +55 -26
  63. package/lib/styles/calendar.d.ts +3 -2
  64. package/lib/styles/calendar.js +77 -0
  65. package/lib/styles/checkbox.js +31 -13
  66. package/lib/styles/copy.js +5 -1
  67. package/lib/styles/date-picker.js +68 -26
  68. package/lib/styles/file-upload.d.ts +1 -1
  69. package/lib/styles/file-upload.js +3 -3
  70. package/lib/styles/icon.d.ts +1 -1
  71. package/lib/styles/icon.js +2 -2
  72. package/lib/styles/input.js +6 -10
  73. package/lib/styles/option.d.ts +1 -1
  74. package/lib/styles/option.js +7 -3
  75. package/lib/styles/popup.d.ts +1 -1
  76. package/lib/styles/popup.js +10 -5
  77. package/lib/styles/radio.js +18 -6
  78. package/lib/styles/scroll-container.d.ts +1 -1
  79. package/lib/styles/scroll-container.js +1 -1
  80. package/lib/styles/select-base.js +24 -3
  81. package/lib/styles/select.d.ts +1 -1
  82. package/lib/styles/select.js +10 -0
  83. package/lib/styles/step.d.ts +1 -1
  84. package/lib/styles/step.js +1 -9
  85. package/lib/styles/switch.js +14 -6
  86. package/lib/styles/tab.d.ts +1 -1
  87. package/lib/styles/tab.js +67 -3
  88. package/lib/styles/tabs.d.ts +1 -1
  89. package/lib/styles/tabs.js +7 -3
  90. package/lib/styles/tag.js +3 -3
  91. package/lib/styles/textarea.d.ts +1 -1
  92. package/lib/styles/textarea.js +7 -0
  93. package/lib/styles/wizard.d.ts +9 -5
  94. package/lib/styles/wizard.js +211 -99
  95. package/lib/types/common.d.ts +2 -2
  96. package/lib/utils/calendar-utils.d.ts +49 -0
  97. package/lib/utils/calendar-utils.js +63 -6
  98. package/lib/utils/property-manager.d.ts +7 -1
  99. package/lib/utils/property-manager.js +16 -4
  100. package/lib/utils/scroll-lock.d.ts +10 -4
  101. package/lib/utils/scroll-lock.js +102 -2
  102. package/lib/utils/upgrade-properties.d.ts +21 -0
  103. package/lib/utils/upgrade-properties.js +47 -0
  104. package/lib/utils/validity.d.ts +122 -0
  105. package/lib/utils/validity.js +289 -0
  106. package/lib/version.d.ts +1 -1
  107. package/lib/version.js +1 -1
  108. package/package.json +27 -5
@@ -8,6 +8,12 @@ const COPY_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height
8
8
  const CHECK_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>`;
9
9
  const ERROR_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`;
10
10
  import { REQUIRED_ICON_SVG } from '../utils/icons.js';
11
+ function escapeText(text) {
12
+ return text
13
+ .replace(/&/g, '&amp;')
14
+ .replace(/</g, '&lt;')
15
+ .replace(/>/g, '&gt;');
16
+ }
11
17
  export class TyCopy extends TyComponent {
12
18
  constructor() {
13
19
  super();
@@ -26,7 +32,7 @@ this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFla
26
32
  onDisconnect() {
27
33
  if (this._copyTimeout !== null) {
28
34
  clearTimeout(this._copyTimeout);
29
- this._copyTimeout = null;
35
+ this.resetCopyButton();
30
36
  }
31
37
  }
32
38
  onPropertiesChanged(changes) {
@@ -55,15 +61,15 @@ composed: true
55
61
  }));
56
62
  }
57
63
  catch (err) {
58
- try {
64
+ const focused = this.shadowRoot.activeElement;
59
65
  const textarea = document.createElement('textarea');
66
+ try {
60
67
  textarea.value = value;
61
68
  textarea.style.position = 'fixed';
62
69
  textarea.style.opacity = '0';
63
70
  document.body.appendChild(textarea);
64
71
  textarea.select();
65
72
  document.execCommand('copy');
66
- document.body.removeChild(textarea);
67
73
  this.dispatchEvent(new CustomEvent('copy-success', {
68
74
  detail: { value },
69
75
  bubbles: true,
@@ -80,6 +86,10 @@ composed: true
80
86
  this.showCopyError();
81
87
  return;
82
88
  }
89
+ finally {
90
+ textarea.remove();
91
+ focused?.focus();
92
+ }
83
93
  }
84
94
  this.showCopySuccess();
85
95
  }
@@ -94,16 +104,17 @@ copyButton.classList.add('success');
94
104
  copyButton.innerHTML = CHECK_ICON_SVG;
95
105
  copyButton.setAttribute('aria-label', 'Copied!');
96
106
  }
97
- this._copyTimeout = window.setTimeout(() => {
107
+ this._copyTimeout = window.setTimeout(() => this.resetCopyButton(), 2000);
108
+ }
109
+ resetCopyButton() {
98
110
  this._showingSuccess = false;
99
111
  const btn = this.shadowRoot.querySelector('.copy-button');
100
112
  if (btn) {
101
- btn.classList.remove('success');
113
+ btn.classList.remove('success', 'error');
102
114
  btn.innerHTML = COPY_ICON_SVG;
103
115
  btn.setAttribute('aria-label', 'Copy to clipboard');
104
116
  }
105
117
  this._copyTimeout = null;
106
- }, 2000);
107
118
  }
108
119
  showCopyError() {
109
120
  if (this._copyTimeout !== null) {
@@ -116,34 +127,13 @@ copyButton.classList.add('error');
116
127
  copyButton.innerHTML = ERROR_ICON_SVG;
117
128
  copyButton.setAttribute('aria-label', 'Copy failed');
118
129
  }
119
- this._copyTimeout = window.setTimeout(() => {
120
- const btn = this.shadowRoot.querySelector('.copy-button');
121
- if (btn) {
122
- btn.classList.remove('error');
123
- btn.innerHTML = COPY_ICON_SVG;
124
- btn.setAttribute('aria-label', 'Copy to clipboard');
125
- }
126
- this._copyTimeout = null;
127
- }, 2000);
130
+ this._copyTimeout = window.setTimeout(() => this.resetCopyButton(), 2000);
128
131
  }
129
132
  setupEventListeners() {
130
- const shadow = this.shadowRoot;
131
- const inputWrapper = shadow.querySelector('.input-wrapper');
132
- const copyButton = shadow.querySelector('.copy-button');
133
+ const inputWrapper = this.shadowRoot.querySelector('.input-wrapper');
133
134
  if (inputWrapper && !this.disabled) {
134
- const wrapperEl = inputWrapper;
135
- wrapperEl.addEventListener('click', (e) => {
136
- if (e.target === copyButton || e.target.closest('.copy-button')) {
137
- return;
138
- }
139
- this.copyToClipboard();
140
- });
141
- wrapperEl.style.cursor = 'pointer';
142
- }
143
- if (copyButton) {
144
- copyButton.addEventListener('click', () => {
145
- this.copyToClipboard();
146
- });
135
+ inputWrapper.addEventListener('click', () => this.copyToClipboard());
136
+ inputWrapper.style.cursor = 'pointer';
147
137
  }
148
138
  }
149
139
  render() {
@@ -154,9 +144,10 @@ const valueClass = [
154
144
  this.multiline ? 'multiline' : '',
155
145
  this.horizontalScroll ? 'horizontal-scroll' : '',
156
146
  ].filter(Boolean).join(' ');
147
+ const shown = escapeText(this.value || '');
157
148
  const displayElement = this.format === 'code'
158
- ? `<code class="${valueClass}">${this.value || ''}</code>`
159
- : `<div class="${valueClass}">${this.value || ''}</div>`;
149
+ ? `<code class="${valueClass}">${shown}</code>`
150
+ : `<div class="${valueClass}">${shown}</div>`;
160
151
  const labelHtml = this.label ? `
161
152
  <label class="ty-field-label">
162
153
  ${this.label}
@@ -1,26 +1,18 @@
1
1
  /**
2
2
  * TyDatePicker Web Component — read-only input stub + calendar dropdown
3
3
  * (modal <dialog>), optional time input, form participation via
4
- * ElementInternals. Value is UTC; display is local.
4
+ * ElementInternals. Value is a UTC instant (wall-clock with `native`);
5
+ * display is local.
5
6
  */
6
7
  import { type Placement } from '../utils/positioning.js';
7
8
  import { TyComponent } from '../base/ty-component.js';
8
9
  import type { Flavor } from '../types/common.js';
9
10
  import type { PropertyChange } from '../utils/property-manager.js';
10
- /**
11
- * Date components (internal representation in local timezone)
12
- */
13
- interface DateComponents {
14
- year?: number;
15
- month?: number;
16
- day?: number;
17
- hour?: number;
18
- minute?: number;
19
- }
11
+ import { type DateTimeParts } from '../utils/calendar-utils.js';
20
12
  /**
21
13
  * Internal date picker state
22
14
  */
23
- interface DatePickerState extends DateComponents {
15
+ interface DatePickerState extends DateTimeParts {
24
16
  withTime: boolean;
25
17
  open: boolean;
26
18
  }
@@ -94,13 +86,15 @@ export declare class TyDatePicker extends TyComponent<DatePickerState> {
94
86
  visual: boolean;
95
87
  default: boolean;
96
88
  };
97
- clearable: {
89
+ noClear: {
98
90
  type: "boolean";
99
91
  visual: boolean;
100
92
  default: boolean;
101
- aliases: {
102
- 'not-clearable': boolean;
103
- };
93
+ };
94
+ error: {
95
+ type: "string";
96
+ visual: boolean;
97
+ default: string;
104
98
  };
105
99
  format: {
106
100
  type: "string";
@@ -126,12 +120,19 @@ export declare class TyDatePicker extends TyComponent<DatePickerState> {
126
120
  visual: boolean;
127
121
  default: boolean;
128
122
  };
123
+ native: {
124
+ type: "boolean";
125
+ visual: boolean;
126
+ default: boolean;
127
+ };
129
128
  };
130
129
  private _state;
131
130
  private _clickListener?;
132
131
  private _keydownListener?;
133
132
  private _dialogClickListener?;
134
133
  private _closeTimestamp;
134
+ private _initialized;
135
+ private _syncing;
135
136
  private _timeInput?;
136
137
  private _localeObserver?;
137
138
  private _customFlavorSheet;
@@ -145,10 +146,23 @@ export declare class TyDatePicker extends TyComponent<DatePickerState> {
145
146
  /** Handle state updates BEFORE render. */
146
147
  protected onPropertiesChanged(changes: PropertyChange[]): void;
147
148
  /**
148
- * Get form value - returns UTC string from current state
149
- * TyComponent calls this automatically when value property changes
149
+ * Get form value - the submitted string from current state (see
150
+ * componentsToOutputValue). TyComponent calls this automatically when the
151
+ * value property changes.
150
152
  */
151
153
  protected getFormValue(): FormDataEntryValue | null;
154
+ private outputValue;
155
+ protected updateFormValue(): void;
156
+ /** The field's focusable element: the stub, or the native input on touch devices. */
157
+ private focusTarget;
158
+ /** Focus the field: the host itself isn't focusable. Disabled: nothing, like a native input. */
159
+ focus(options?: FocusOptions): void;
160
+ /**
161
+ * `required` used to be cosmetic: nothing reported valueMissing, so an empty
162
+ * required picker never blocked its form. Disabled pickers don't validate.
163
+ * The message is a native date (datetime-local with time) input's.
164
+ */
165
+ private updateValidity;
152
166
  private getComponents;
153
167
  /**
154
168
  * Whether internal state has a complete date
@@ -169,16 +183,11 @@ export declare class TyDatePicker extends TyComponent<DatePickerState> {
169
183
  */
170
184
  private syncFormValue;
171
185
  /**
172
- * Reflect constraint validation to the owning <form> via ElementInternals.
173
- * Without this `required` is only cosmetic — unlike ty-input/ty-select/
174
- * ty-calendar, which all call setValidity, an empty required date-picker
175
- * never blocks form submission.
176
- */
177
- private updateValidity;
178
- /**
179
- * Handle time input changes from TimeInput class
186
+ * Handle time changes from the footer's hour/minute fields
180
187
  */
181
188
  handleTimeInputChange(hour: number, minute: number): void;
189
+ /** Footer summary under the time fields: "Wed, Sep 23 · 14:30" + local ISO. */
190
+ private updateTimeSummary;
182
191
  private emitChangeEvent;
183
192
  get size(): DatePickerSize;
184
193
  set size(v: DatePickerSize);
@@ -200,46 +209,71 @@ export declare class TyDatePicker extends TyComponent<DatePickerState> {
200
209
  set required(v: boolean);
201
210
  get disabled(): boolean;
202
211
  set disabled(v: boolean);
203
- get clearable(): boolean;
204
- set clearable(v: boolean);
212
+ get noClear(): boolean;
213
+ set noClear(v: boolean);
205
214
  get min(): string;
206
215
  set min(v: string);
207
216
  get max(): string;
208
217
  set max(v: string);
209
218
  get withTime(): boolean;
210
219
  set withTime(v: boolean);
220
+ get native(): boolean;
221
+ set native(v: boolean);
222
+ get error(): string;
223
+ set error(v: string);
211
224
  /**
212
- * Get current value (UTC ISO string)
225
+ * Get current value — the string the form submits: a UTC ISO instant, or
226
+ * wall-clock ('YYYY-MM-DD' / 'YYYY-MM-DDTHH:mm') with `native`. null when
227
+ * empty (the form then submits name=, like a native date input).
213
228
  */
214
229
  get value(): string | null;
215
230
  /**
216
- * Set value (UTC ISO string, Date object, or null)
231
+ * Set value: any format parseDateTime() reads, a Date, epoch milliseconds,
232
+ * or null. It's normalized to the submitted form.
217
233
  *
218
234
  * When set to null/undefined/empty string, the attribute is removed.
219
- * When set to a valid date, the attribute is set to ISO UTC string.
220
235
  */
221
- set value(val: string | Date | null);
236
+ set value(val: string | number | Date | null);
222
237
  /**
223
238
  * Clear the date value programmatically WITH a change event (source:
224
- * 'clear'). Works regardless of the `clearable` attribute — lets any
239
+ * 'clear'). Works regardless of `no-clear` — lets any
225
240
  * external trigger (e.g. a button elsewhere in the page) clear the value
226
241
  * without needing the built-in clear button. Mirrors ty-select's clear().
227
242
  */
228
243
  clear(): void;
229
244
  private buildStubClasses;
230
245
  private renderStub;
231
- private createTimeInputElement;
246
+ private createTimeField;
247
+ /** Footer: clock + "Time" on the left, HH : MM on the right, summary below. */
232
248
  private renderTimeSection;
233
249
  private renderCalendarDropdown;
250
+ /**
251
+ * Match the popup calendar to the stub's look: danger while an error
252
+ * shows, as on the stub (styles: errorLook), else the user's flavor.
253
+ * 'default' is the stub's own unstyled state, not a real flavor: the
254
+ * calendar stays on its own default.
255
+ */
256
+ private calendarFlavor;
234
257
  /**
235
258
  * Render native date input for mobile touch devices.
236
259
  * Uses <input type="date"> or <input type="datetime-local"> when with-time.
237
260
  * Reuses .date-picker-stub styling and existing event/state infrastructure.
238
261
  */
239
262
  private renderNativeInput;
263
+ /**
264
+ * The touch devices' native input follows the picker: type (date, or
265
+ * datetime-local with time), disabled, required, min/max (datetime-local
266
+ * wants a time suffix) and value — also when they change at runtime.
267
+ */
268
+ private syncNativeInput;
240
269
  private calculateCalendarPosition;
241
270
  private renderContainer;
242
271
  protected render(): void;
272
+ /**
273
+ * The `error` line under the field — same markup as ty-input's; the field
274
+ * (stub, or the native input on touch devices) is described by it.
275
+ */
276
+ private syncErrorLine;
243
277
  /**
244
278
  * Update display without destroying DOM (for open dialog)
245
279
  */