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
@@ -3,15 +3,63 @@ export interface TabAttributes {
3
3
  id: string | null;
4
4
  label: string | null;
5
5
  disabled: boolean;
6
+ lazy: boolean;
7
+ }
8
+ /**
9
+ * `ty-tab-load`: a lazy tab with no content was shown. Fired on the ty-tab
10
+ * and doesn't bubble, so a lazy tab nested in another doesn't trigger the
11
+ * outer one's listener. Listen on the tab, or on ty-tabs with capture.
12
+ */
13
+ export interface TabLoadDetail {
14
+ id: string;
15
+ index: number;
6
16
  }
7
17
  export declare class TyTab extends HTMLElement {
8
18
  private _scrollbar;
19
+ private _panelLabel;
20
+ private _shown;
21
+ private _load;
22
+ private _contentObserver;
23
+ private _contentChanged;
9
24
  static get observedAttributes(): string[];
10
25
  constructor();
11
26
  connectedCallback(): void;
27
+ /** Accessible name. Set by ty-tabs, which also knows rich `label-{id}` slots. */
28
+ setPanelLabel(label: string): void;
29
+ /** Set by ty-tabs: a panel that isn't shown is inert. */
30
+ setShown(shown: boolean): void;
12
31
  disconnectedCallback(): void;
13
- attributeChangedCallback(_name: string, _oldValue: string | null, _newValue: string | null): void;
32
+ /**
33
+ * Called by ty-tabs when this tab becomes the shown one — never for the
34
+ * tab shown first, whose content the page is expected to carry. A lazy
35
+ * tab with no content (or whose load failed) asks for it.
36
+ */
37
+ _requestLoad(index: number): void;
38
+ /**
39
+ * Report that loading this tab's content failed: shows `slot="error"`
40
+ * (default "Couldn't load.") with a Retry button. Retry, or showing the
41
+ * tab again, fires `ty-tab-load` once more. Content arriving clears it.
42
+ */
43
+ loadFailed(): void;
44
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
14
45
  private _render;
46
+ /** Lazy tabs track whether they have content; others don't watch. */
47
+ private _watchContent;
48
+ private _hasContent;
49
+ /**
50
+ * `mutated`: content changed under a connected tab. Content that goes away
51
+ * (a morph with the server's empty markup) loads again — right away when
52
+ * this tab is the one shown, otherwise the next time it's shown.
53
+ */
54
+ private _checkContent;
55
+ private _fireLoad;
56
+ /**
57
+ * Placeholder and error, built the first time a tab loads: tabs that never
58
+ * do carry no hidden "Couldn't load / Retry" text.
59
+ */
60
+ private _ensureStatus;
61
+ private _setLoad;
62
+ private _syncPanel;
15
63
  private _setupScrollbar;
16
64
  private _destroyScrollbar;
17
65
  resetScroll(): void;
@@ -1,44 +1,185 @@
1
1
  import { ensureStyles } from '../utils/styles.js';
2
2
  import { tabStyles } from '../styles/tab.js';
3
3
  import { CustomScrollbar, isCustomScrollbarEnabled } from '../utils/custom-scrollbar.js';
4
+ import { getLoaderSvg } from '../utils/loader-registry.js';
5
+ const STATUS_SLOTS = new Set(['loading', 'error']);
6
+ const INERT_ELEMENTS = new Set(['template', 'script', 'style']);
4
7
  export class TyTab extends HTMLElement {
5
8
  static get observedAttributes() {
6
- return ['id', 'label', 'disabled'];
9
+ return ['id', 'label', 'disabled', 'lazy'];
7
10
  }
8
11
  constructor() {
9
12
  super();
10
13
  this._scrollbar = null;
14
+ this._panelLabel = null;
15
+ this._shown = true;
16
+ this._load = 'idle';
17
+ this._contentObserver = null;
18
+ this._contentChanged = false;
11
19
  this.attachShadow({ mode: 'open' });
12
20
  }
13
21
  connectedCallback() {
14
22
  this._render();
23
+ if (!this._scrollbar)
24
+ this._setupScrollbar();
25
+ this._watchContent();
26
+ }
27
+ setPanelLabel(label) {
28
+ this._panelLabel = label;
29
+ this._syncPanel();
30
+ }
31
+ setShown(shown) {
32
+ this._shown = shown;
33
+ this._syncPanel();
15
34
  }
16
35
  disconnectedCallback() {
17
36
  this._destroyScrollbar();
37
+ this._contentChanged = !!this._contentObserver?.takeRecords().length;
38
+ this._contentObserver?.disconnect();
39
+ this._contentObserver = null;
40
+ }
41
+ _requestLoad(index) {
42
+ if (this._contentObserver?.takeRecords().length)
43
+ this._checkContent(false);
44
+ if (this._load === 'empty' || this._load === 'failed')
45
+ this._fireLoad(index);
46
+ }
47
+ loadFailed() {
48
+ if (this._load === 'loading' || this._load === 'empty')
49
+ this._setLoad('failed');
18
50
  }
19
- attributeChangedCallback(_name, _oldValue, _newValue) {
51
+ attributeChangedCallback(name, oldValue, newValue) {
20
52
  this._render();
53
+ if (name === 'lazy') {
54
+ if (this.isConnected)
55
+ this._watchContent();
56
+ return;
57
+ }
58
+ const tabs = this.parentElement;
59
+ if (oldValue !== newValue && this.isConnected && tabs?.localName === 'ty-tabs') {
60
+ tabs._queueUpdate?.(true);
61
+ }
21
62
  }
22
63
  _render() {
23
64
  const shadowRoot = this.shadowRoot;
24
65
  if (!shadowRoot)
25
66
  return;
26
- const id = this.getAttribute('id');
27
67
  if (!shadowRoot.querySelector('.tab-wrapper')) {
28
68
  ensureStyles(shadowRoot, { css: tabStyles, id: 'ty-tab' });
29
69
  shadowRoot.innerHTML = `
30
- <div class="tab-wrapper"
31
- role="tabpanel"
32
- ${id ? `id="panel-${id}"` : ''}
33
- ${id ? `aria-labelledby="tab-${id}"` : ''}
34
- >
35
- <div class="tab-panel">
70
+ <div class="tab-wrapper">
71
+ <div class="tab-panel" role="tabpanel" tabindex="0">
36
72
  <slot></slot>
37
73
  </div>
38
74
  </div>
39
75
  `;
40
- this._setupScrollbar();
41
76
  }
77
+ this._syncPanel();
78
+ }
79
+ _watchContent() {
80
+ const lazy = this.hasAttribute('lazy');
81
+ if (lazy && !this._contentObserver) {
82
+ this._contentObserver = new MutationObserver(() => this._checkContent(true));
83
+ this._contentObserver.observe(this, { childList: true, characterData: true, subtree: true });
84
+ }
85
+ else if (!lazy && this._contentObserver) {
86
+ this._contentObserver.disconnect();
87
+ this._contentObserver = null;
88
+ }
89
+ const changed = this._contentChanged;
90
+ this._contentChanged = false;
91
+ this._checkContent(changed);
92
+ }
93
+ _hasContent() {
94
+ for (const node of Array.from(this.childNodes)) {
95
+ if (node.nodeType === Node.TEXT_NODE && node.textContent.trim())
96
+ return true;
97
+ if (node.nodeType !== Node.ELEMENT_NODE)
98
+ continue;
99
+ const el = node;
100
+ if (!STATUS_SLOTS.has(el.getAttribute('slot') ?? '') && !INERT_ELEMENTS.has(el.localName))
101
+ return true;
102
+ }
103
+ return false;
104
+ }
105
+ _checkContent(mutated) {
106
+ if (!this.hasAttribute('lazy') || this._hasContent()) {
107
+ this._setLoad('idle');
108
+ return;
109
+ }
110
+ if (this._load !== 'idle')
111
+ return;
112
+ this._setLoad('empty');
113
+ if (!mutated)
114
+ return;
115
+ queueMicrotask(() => {
116
+ if (this._load === 'empty' && this._shown && this.parentElement?.localName === 'ty-tabs')
117
+ this._fireLoad();
118
+ });
119
+ }
120
+ _fireLoad(index) {
121
+ const tabs = this.parentElement;
122
+ if (index === undefined) {
123
+ index = tabs?.localName === 'ty-tabs'
124
+ ? Array.from(tabs.querySelectorAll(':scope > ty-tab')).indexOf(this)
125
+ : 0;
126
+ }
127
+ this._setLoad('loading');
128
+ this.dispatchEvent(new CustomEvent('ty-tab-load', { detail: { id: this.id, index } }));
129
+ }
130
+ _ensureStatus(panel) {
131
+ if (panel.querySelector('.tab-loading'))
132
+ return;
133
+ panel.insertAdjacentHTML('beforeend', `
134
+ <div class="tab-loading" part="loading">
135
+ <slot name="loading"><span class="tab-spinner" part="spinner" aria-hidden="true"></span></slot>
136
+ </div>
137
+ <div class="tab-error" part="error" role="alert">
138
+ <slot name="error">Couldn't load.</slot>
139
+ <button type="button" class="tab-retry" part="retry">Retry</button>
140
+ </div>
141
+ `);
142
+ panel.querySelector('.tab-retry').addEventListener('click', () => {
143
+ panel.focus({ preventScroll: true });
144
+ this._fireLoad();
145
+ });
146
+ }
147
+ _setLoad(state) {
148
+ if (state === this._load)
149
+ return;
150
+ this._load = state;
151
+ const panel = this.shadowRoot?.querySelector('.tab-panel');
152
+ if (!panel)
153
+ return;
154
+ if (state === 'loading' || state === 'failed') {
155
+ this._ensureStatus(panel);
156
+ panel.dataset.load = state;
157
+ }
158
+ else {
159
+ delete panel.dataset.load;
160
+ }
161
+ if (state === 'loading') {
162
+ panel.setAttribute('aria-busy', 'true');
163
+ panel.querySelector('.tab-spinner').innerHTML = getLoaderSvg();
164
+ }
165
+ else {
166
+ panel.removeAttribute('aria-busy');
167
+ }
168
+ }
169
+ _syncPanel() {
170
+ const panel = this.shadowRoot?.querySelector('.tab-panel');
171
+ if (!panel)
172
+ return;
173
+ const tabs = this.parentElement;
174
+ const rich = !this._panelLabel && this.id && tabs?.localName === 'ty-tabs'
175
+ ? tabs.querySelector(`:scope > [slot="label-${CSS.escape(this.id)}"]`)
176
+ : null;
177
+ const label = this._panelLabel || rich?.textContent?.trim() || this.getAttribute('label');
178
+ if (label)
179
+ panel.setAttribute('aria-label', label);
180
+ else
181
+ panel.removeAttribute('aria-label');
182
+ panel.parentElement.inert = !this._shown;
42
183
  }
43
184
  _setupScrollbar() {
44
185
  const panel = this.shadowRoot?.querySelector('.tab-panel');
@@ -14,7 +14,8 @@ export interface TabsAttributes {
14
14
  fixed: boolean;
15
15
  }
16
16
  /**
17
- * Tab change event detail
17
+ * Tab change event detail. Fired whenever the shown tab changes after the
18
+ * first one is shown — never for the initial tab.
18
19
  */
19
20
  export interface TabChangeDetail {
20
21
  activeId: string;
@@ -29,8 +30,19 @@ export declare class TyTabs extends HTMLElement {
29
30
  static get observedAttributes(): string[];
30
31
  constructor();
31
32
  private _childObserver;
32
- private _childRenderQueued;
33
+ private _updateQueued;
34
+ private _structureDirty;
35
+ /** ID of the tab currently shown (`active` may be stale or missing after a morph). */
36
+ get activeTab(): string | null;
33
37
  connectedCallback(): void;
34
38
  disconnectedCallback(): void;
39
+ /**
40
+ * External changes (`active` set by app or server, children added or
41
+ * removed, a ty-tab's id/label/disabled changed — ty-tab reports those)
42
+ * settle in one microtask: a morph sets attributes and swaps children in
43
+ * one go, and the shown tab must be decided once the whole batch has
44
+ * landed — `active` may name a tab that is appended after it.
45
+ */
46
+ _queueUpdate(structure: boolean): void;
35
47
  attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
36
48
  }