tyrell-components 1.0.0-RC16 → 1.0.0-RC18

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 (240) hide show
  1. package/README.md +1 -1
  2. package/css/tyrell-colors-static.css +1 -316
  3. package/css/tyrell-theme.css +1 -1471
  4. package/css/tyrell.css +1 -1385
  5. package/dist/tyrell-colors-static.css +1 -1
  6. package/dist/tyrell-theme.css +1 -1
  7. package/dist/tyrell.js +1 -1
  8. package/lib/base/ty-component.d.ts +28 -15
  9. package/lib/base/ty-component.js +81 -38
  10. package/lib/components/button.d.ts +14 -0
  11. package/lib/components/button.js +55 -7
  12. package/lib/components/calendar-month.d.ts +7 -1
  13. package/lib/components/calendar-month.js +35 -28
  14. package/lib/components/calendar-navigation.js +19 -6
  15. package/lib/components/calendar.d.ts +27 -3
  16. package/lib/components/calendar.js +107 -63
  17. package/lib/components/checkbox.d.ts +8 -1
  18. package/lib/components/checkbox.js +27 -6
  19. package/lib/components/copy.d.ts +2 -0
  20. package/lib/components/copy.js +15 -31
  21. package/lib/components/date-picker.d.ts +53 -18
  22. package/lib/components/date-picker.js +217 -146
  23. package/lib/components/file-upload.d.ts +4 -1
  24. package/lib/components/file-upload.js +23 -5
  25. package/lib/components/input.d.ts +73 -3
  26. package/lib/components/input.js +158 -22
  27. package/lib/components/modal.d.ts +2 -0
  28. package/lib/components/modal.js +97 -17
  29. package/lib/components/option.d.ts +19 -0
  30. package/lib/components/option.js +45 -31
  31. package/lib/components/popup.js +115 -15
  32. package/lib/components/radio.d.ts +10 -1
  33. package/lib/components/radio.js +22 -29
  34. package/lib/components/resize-observer.js +2 -0
  35. package/lib/components/scroll-container.js +2 -0
  36. package/lib/components/select.d.ts +150 -190
  37. package/lib/components/select.js +501 -796
  38. package/lib/components/selected-tags.d.ts +14 -4
  39. package/lib/components/selected-tags.js +35 -8
  40. package/lib/components/switch.d.ts +9 -1
  41. package/lib/components/switch.js +27 -6
  42. package/lib/components/tabs.js +1 -1
  43. package/lib/components/tag.d.ts +0 -9
  44. package/lib/components/tag.js +0 -11
  45. package/lib/components/textarea.d.ts +47 -2
  46. package/lib/components/textarea.js +81 -17
  47. package/lib/index.d.ts +1 -0
  48. package/lib/index.js +1 -0
  49. package/lib/styles/button.js +21 -19
  50. package/lib/styles/calendar-month.js +1 -1
  51. package/lib/styles/calendar.js +3 -0
  52. package/lib/styles/checkbox.js +11 -5
  53. package/lib/styles/date-picker.js +16 -4
  54. package/lib/styles/file-upload.d.ts +1 -1
  55. package/lib/styles/file-upload.js +3 -3
  56. package/lib/styles/icon.d.ts +1 -1
  57. package/lib/styles/icon.js +2 -2
  58. package/lib/styles/input.js +6 -10
  59. package/lib/styles/option.d.ts +1 -1
  60. package/lib/styles/option.js +6 -7
  61. package/lib/styles/popup.d.ts +1 -1
  62. package/lib/styles/popup.js +2 -0
  63. package/lib/styles/radio.js +12 -6
  64. package/lib/styles/select-base.js +22 -60
  65. package/lib/styles/select.d.ts +1 -1
  66. package/lib/styles/select.js +13 -2
  67. package/lib/styles/switch.js +10 -5
  68. package/lib/styles/tag.js +3 -5
  69. package/lib/styles/textarea.d.ts +1 -1
  70. package/lib/styles/textarea.js +7 -0
  71. package/lib/types/common.d.ts +3 -3
  72. package/lib/utils/calendar-utils.d.ts +49 -0
  73. package/lib/utils/calendar-utils.js +63 -6
  74. package/lib/utils/property-manager.d.ts +6 -5
  75. package/lib/utils/property-manager.js +14 -15
  76. package/lib/utils/scroll-lock.d.ts +10 -4
  77. package/lib/utils/scroll-lock.js +102 -2
  78. package/lib/utils/upgrade-properties.d.ts +21 -0
  79. package/lib/utils/upgrade-properties.js +47 -0
  80. package/lib/utils/validity.d.ts +98 -2
  81. package/lib/utils/validity.js +244 -8
  82. package/lib/version.d.ts +1 -1
  83. package/lib/version.js +1 -1
  84. package/package.json +8 -6
  85. package/lib/base/ty-component.d.ts.map +0 -1
  86. package/lib/base/ty-component.js.map +0 -1
  87. package/lib/components/button.d.ts.map +0 -1
  88. package/lib/components/button.js.map +0 -1
  89. package/lib/components/calendar-month.d.ts.map +0 -1
  90. package/lib/components/calendar-month.js.map +0 -1
  91. package/lib/components/calendar-navigation.d.ts.map +0 -1
  92. package/lib/components/calendar-navigation.js.map +0 -1
  93. package/lib/components/calendar.d.ts.map +0 -1
  94. package/lib/components/calendar.js.map +0 -1
  95. package/lib/components/checkbox.d.ts.map +0 -1
  96. package/lib/components/checkbox.js.map +0 -1
  97. package/lib/components/copy.d.ts.map +0 -1
  98. package/lib/components/copy.js.map +0 -1
  99. package/lib/components/date-picker.d.ts.map +0 -1
  100. package/lib/components/date-picker.js.map +0 -1
  101. package/lib/components/dropdown.d.ts +0 -403
  102. package/lib/components/dropdown.d.ts.map +0 -1
  103. package/lib/components/dropdown.js +0 -1315
  104. package/lib/components/dropdown.js.map +0 -1
  105. package/lib/components/icon.d.ts.map +0 -1
  106. package/lib/components/icon.js.map +0 -1
  107. package/lib/components/input.d.ts.map +0 -1
  108. package/lib/components/input.js.map +0 -1
  109. package/lib/components/modal.d.ts.map +0 -1
  110. package/lib/components/modal.js.map +0 -1
  111. package/lib/components/multiselect.d.ts +0 -389
  112. package/lib/components/multiselect.d.ts.map +0 -1
  113. package/lib/components/multiselect.js +0 -1301
  114. package/lib/components/multiselect.js.map +0 -1
  115. package/lib/components/option.d.ts.map +0 -1
  116. package/lib/components/option.js.map +0 -1
  117. package/lib/components/popup.d.ts.map +0 -1
  118. package/lib/components/popup.js.map +0 -1
  119. package/lib/components/resize-observer.d.ts.map +0 -1
  120. package/lib/components/resize-observer.js.map +0 -1
  121. package/lib/components/scroll-container.d.ts.map +0 -1
  122. package/lib/components/scroll-container.js.map +0 -1
  123. package/lib/components/step.d.ts.map +0 -1
  124. package/lib/components/step.js.map +0 -1
  125. package/lib/components/tab.d.ts.map +0 -1
  126. package/lib/components/tab.js.map +0 -1
  127. package/lib/components/tabs.d.ts.map +0 -1
  128. package/lib/components/tabs.js.map +0 -1
  129. package/lib/components/tag.d.ts.map +0 -1
  130. package/lib/components/tag.js.map +0 -1
  131. package/lib/components/textarea.d.ts.map +0 -1
  132. package/lib/components/textarea.js.map +0 -1
  133. package/lib/components/tooltip.d.ts.map +0 -1
  134. package/lib/components/tooltip.js.map +0 -1
  135. package/lib/components/wizard.d.ts.map +0 -1
  136. package/lib/components/wizard.js.map +0 -1
  137. package/lib/icons/fontawesome/brands.d.ts.map +0 -1
  138. package/lib/icons/fontawesome/brands.js.map +0 -1
  139. package/lib/icons/fontawesome/regular.d.ts.map +0 -1
  140. package/lib/icons/fontawesome/regular.js.map +0 -1
  141. package/lib/icons/fontawesome/solid.d.ts.map +0 -1
  142. package/lib/icons/fontawesome/solid.js.map +0 -1
  143. package/lib/icons/heroicons/micro.d.ts.map +0 -1
  144. package/lib/icons/heroicons/micro.js.map +0 -1
  145. package/lib/icons/heroicons/mini.d.ts.map +0 -1
  146. package/lib/icons/heroicons/mini.js.map +0 -1
  147. package/lib/icons/heroicons/outline.d.ts.map +0 -1
  148. package/lib/icons/heroicons/outline.js.map +0 -1
  149. package/lib/icons/heroicons/solid.d.ts.map +0 -1
  150. package/lib/icons/heroicons/solid.js.map +0 -1
  151. package/lib/icons/lucide.d.ts.map +0 -1
  152. package/lib/icons/lucide.js.map +0 -1
  153. package/lib/icons/material/filled.d.ts.map +0 -1
  154. package/lib/icons/material/filled.js.map +0 -1
  155. package/lib/icons/material/outlined.d.ts.map +0 -1
  156. package/lib/icons/material/outlined.js.map +0 -1
  157. package/lib/icons/material/round.d.ts.map +0 -1
  158. package/lib/icons/material/round.js.map +0 -1
  159. package/lib/icons/material/sharp.d.ts.map +0 -1
  160. package/lib/icons/material/sharp.js.map +0 -1
  161. package/lib/icons/material/two-tone.d.ts.map +0 -1
  162. package/lib/icons/material/two-tone.js.map +0 -1
  163. package/lib/index.d.ts.map +0 -1
  164. package/lib/index.js.map +0 -1
  165. package/lib/styles/button.d.ts.map +0 -1
  166. package/lib/styles/button.js.map +0 -1
  167. package/lib/styles/calendar-month.d.ts.map +0 -1
  168. package/lib/styles/calendar-month.js.map +0 -1
  169. package/lib/styles/calendar-navigation.d.ts.map +0 -1
  170. package/lib/styles/calendar-navigation.js.map +0 -1
  171. package/lib/styles/calendar.d.ts.map +0 -1
  172. package/lib/styles/calendar.js.map +0 -1
  173. package/lib/styles/copy.d.ts.map +0 -1
  174. package/lib/styles/copy.js.map +0 -1
  175. package/lib/styles/date-picker.d.ts.map +0 -1
  176. package/lib/styles/date-picker.js.map +0 -1
  177. package/lib/styles/dropdown.d.ts +0 -12
  178. package/lib/styles/dropdown.d.ts.map +0 -1
  179. package/lib/styles/dropdown.js +0 -725
  180. package/lib/styles/dropdown.js.map +0 -1
  181. package/lib/styles/icon.d.ts.map +0 -1
  182. package/lib/styles/icon.js.map +0 -1
  183. package/lib/styles/input.d.ts.map +0 -1
  184. package/lib/styles/input.js.map +0 -1
  185. package/lib/styles/modal.d.ts.map +0 -1
  186. package/lib/styles/modal.js.map +0 -1
  187. package/lib/styles/multiselect.d.ts +0 -6
  188. package/lib/styles/multiselect.d.ts.map +0 -1
  189. package/lib/styles/multiselect.js +0 -568
  190. package/lib/styles/multiselect.js.map +0 -1
  191. package/lib/styles/option.d.ts.map +0 -1
  192. package/lib/styles/option.js.map +0 -1
  193. package/lib/styles/popup.d.ts.map +0 -1
  194. package/lib/styles/popup.js.map +0 -1
  195. package/lib/styles/resize-observer.d.ts.map +0 -1
  196. package/lib/styles/resize-observer.js.map +0 -1
  197. package/lib/styles/scroll-container.d.ts.map +0 -1
  198. package/lib/styles/scroll-container.js.map +0 -1
  199. package/lib/styles/step.d.ts.map +0 -1
  200. package/lib/styles/step.js.map +0 -1
  201. package/lib/styles/tab.d.ts.map +0 -1
  202. package/lib/styles/tab.js.map +0 -1
  203. package/lib/styles/tabs.d.ts.map +0 -1
  204. package/lib/styles/tabs.js.map +0 -1
  205. package/lib/styles/tag.d.ts.map +0 -1
  206. package/lib/styles/tag.js.map +0 -1
  207. package/lib/styles/textarea.d.ts.map +0 -1
  208. package/lib/styles/textarea.js.map +0 -1
  209. package/lib/styles/tooltip.d.ts.map +0 -1
  210. package/lib/styles/tooltip.js.map +0 -1
  211. package/lib/styles/wizard.d.ts.map +0 -1
  212. package/lib/styles/wizard.js.map +0 -1
  213. package/lib/types/common.d.ts.map +0 -1
  214. package/lib/types/common.js.map +0 -1
  215. package/lib/utils/calendar-utils.d.ts.map +0 -1
  216. package/lib/utils/calendar-utils.js.map +0 -1
  217. package/lib/utils/icon-registry.d.ts.map +0 -1
  218. package/lib/utils/icon-registry.js.map +0 -1
  219. package/lib/utils/locale.d.ts.map +0 -1
  220. package/lib/utils/locale.js.map +0 -1
  221. package/lib/utils/number-format.d.ts.map +0 -1
  222. package/lib/utils/number-format.js.map +0 -1
  223. package/lib/utils/parse-boolean.d.ts +0 -39
  224. package/lib/utils/parse-boolean.d.ts.map +0 -1
  225. package/lib/utils/parse-boolean.js +0 -23
  226. package/lib/utils/parse-boolean.js.map +0 -1
  227. package/lib/utils/positioning.d.ts.map +0 -1
  228. package/lib/utils/positioning.js.map +0 -1
  229. package/lib/utils/property-capture.d.ts.map +0 -1
  230. package/lib/utils/property-capture.js.map +0 -1
  231. package/lib/utils/property-manager.d.ts.map +0 -1
  232. package/lib/utils/property-manager.js.map +0 -1
  233. package/lib/utils/resize-observer.d.ts.map +0 -1
  234. package/lib/utils/resize-observer.js.map +0 -1
  235. package/lib/utils/scroll-lock.d.ts.map +0 -1
  236. package/lib/utils/scroll-lock.js.map +0 -1
  237. package/lib/utils/styles.d.ts.map +0 -1
  238. package/lib/utils/styles.js.map +0 -1
  239. package/lib/version.d.ts.map +0 -1
  240. package/lib/version.js.map +0 -1
@@ -9,17 +9,30 @@
9
9
  * - Property change events via 'prop:change' (separate from user 'change' events)
10
10
  */
11
11
  import { PropertyManager, PropertyConfig, PropertyChange } from '../utils/property-manager.js';
12
+ import { upgradeProperties } from '../utils/upgrade-properties.js';
13
+ export { upgradeProperties };
12
14
  /**
13
15
  * Base class for all Ty components with unified property lifecycle
14
16
  */
15
17
  export declare abstract class TyComponent<T = any> extends HTMLElement {
16
18
  static formAssociated: boolean;
17
19
  protected static properties: Record<string, PropertyConfig>;
20
+ /** attachShadow delegatesFocus: the host itself counts as focusable when
21
+ * its focusable role element lives in the shadow (checkbox/switch) —
22
+ * Firefox checks the host, not the validation anchor, on a blocked submit. */
23
+ protected static delegatesFocus: boolean;
24
+ /** 'manual': the component assigns its children to slots itself (ty-select). */
25
+ protected static slotAssignment: SlotAssignmentMode;
26
+ /** A wrapping <label> delegates clicks to the host (see watchLabelForwards). */
27
+ protected static labelClicks: boolean;
18
28
  protected props: PropertyManager<T>;
19
29
  protected _internals: ElementInternals;
20
30
  private _validity;
21
31
  protected _connected: boolean;
22
32
  protected _rendered: boolean;
33
+ /** The user edited the field since it was created or its form reset:
34
+ * blur then shows its validation message (like native :user-invalid). */
35
+ protected _userEdited: boolean;
23
36
  constructor();
24
37
  /**
25
38
  * Define which attributes to observe
@@ -41,6 +54,9 @@ export declare abstract class TyComponent<T = any> extends HTMLElement {
41
54
  * Sync property value to HTML attribute
42
55
  */
43
56
  private _syncPropertyToAttribute;
57
+ /** Our own write of a property to its attribute is under way. */
58
+ private _reflecting;
59
+ private _writeAttribute;
44
60
  private _toKebabCase;
45
61
  private _toCamelCase;
46
62
  /**
@@ -55,11 +71,14 @@ export declare abstract class TyComponent<T = any> extends HTMLElement {
55
71
  * Disconnected callback
56
72
  */
57
73
  disconnectedCallback(): void;
74
+ /** The form owner changed (moved, `form` attribute): see ValidityController.track(). */
75
+ formAssociatedCallback(): void;
58
76
  /**
59
- * Capture properties that were set before connectedCallback
60
- * (React, Vue, Reagent set properties before element is connected)
77
+ * upgradeProperties(), plus declared properties without an accessor of
78
+ * their own name (e.g. ty-input's `minlength`): those go straight to
79
+ * setProperty().
61
80
  */
62
- private _capturePreSetProperties;
81
+ private _upgradeProperties;
63
82
  /**
64
83
  * THE CORE LIFECYCLE METHOD
65
84
  * All property changes flow through here
@@ -119,6 +138,9 @@ export declare abstract class TyComponent<T = any> extends HTMLElement {
119
138
  /** Subclasses report their own validity here, not via _internals directly,
120
139
  * so a user's setCustomValidity() survives re-validation. */
121
140
  protected applyValidity(flags: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;
141
+ /** Show the field's current validation message in its error display, if
142
+ * it's invalid. Called on blur after the user edited the field. */
143
+ protected revealValidity(): void;
122
144
  get validity(): ValidityState | undefined;
123
145
  get validationMessage(): string;
124
146
  get willValidate(): boolean;
@@ -134,18 +156,6 @@ export declare abstract class TyComponent<T = any> extends HTMLElement {
134
156
  * the role element as aria-label, giving it an accessible name.
135
157
  */
136
158
  protected applyLabelName(roleEl: HTMLElement): void;
137
- private _handlingActivationClick;
138
- /**
139
- * Guard for click-driven toggle handlers (checkbox/switch) on components
140
- * whose whole host is the click target AND that expect a wrapping
141
- * <label> to delegate to them. Some browsers still forward a label's own
142
- * synthetic click to the associated control even when the original click
143
- * already targeted that control directly, firing 'click' twice for one
144
- * user gesture. Both arrive synchronously in the same task, so a flag
145
- * cleared on the next microtask catches only the spurious duplicate —
146
- * two genuinely separate clicks are always in different tasks.
147
- */
148
- protected isDuplicateActivationClick(): boolean;
149
159
  private _resetDefaults;
150
160
  /**
151
161
  * Form reset callback - called when form.reset() is invoked.
@@ -154,6 +164,9 @@ export declare abstract class TyComponent<T = any> extends HTMLElement {
154
164
  * semantics). Non-form state (e.g. a checkbox's submission `value`, a
155
165
  * ty-radio's option `value`) is deliberately left alone — the old
156
166
  * blanket 'value' reset corrupted radio groups by wiping child values.
167
+ * Like a native control the field also looks untouched again: the
168
+ * validation message it showed is gone (an `error` the author set stays)
169
+ * and a blur shows nothing until the user edits it.
157
170
  */
158
171
  formResetCallback(): void;
159
172
  /**
@@ -1,29 +1,54 @@
1
1
  import { PropertyManager } from '../utils/property-manager.js';
2
2
  import { ValidityController } from '../utils/validity.js';
3
+ import { upgradeProperties } from '../utils/upgrade-properties.js';
4
+ export { upgradeProperties };
5
+ const labelClickHosts = new WeakSet();
6
+ const directClicks = new WeakMap();
7
+ let labelForwardsWatched = false;
8
+ function watchLabelForwards() {
9
+ if (labelForwardsWatched)
10
+ return;
11
+ labelForwardsWatched = true;
12
+ window.addEventListener('click', (e) => {
13
+ const path = e.composedPath();
14
+ const host = path.find((n) => labelClickHosts.has(n));
15
+ if (!host)
16
+ return;
17
+ const at = `${e.clientX},${e.clientY}`;
18
+ if (path[0] !== host) {
19
+ directClicks.set(host, at);
20
+ setTimeout(() => { if (directClicks.get(host) === at)
21
+ directClicks.delete(host); });
22
+ }
23
+ else if (directClicks.get(host) === at) {
24
+ e.stopImmediatePropagation();
25
+ }
26
+ }, true);
27
+ }
3
28
  export class TyComponent extends HTMLElement {
4
29
  constructor() {
5
30
  super();
6
31
  this._connected = false;
7
32
  this._rendered = false;
8
- this._handlingActivationClick = false;
33
+ this._userEdited = false;
34
+ this._reflecting = false;
9
35
  this._resetDefaults = null;
10
36
  const ctor = this.constructor;
11
37
  this.props = new PropertyManager(ctor.properties);
12
38
  this._internals = this.attachInternals();
13
39
  this._validity = new ValidityController(this, this._internals);
14
40
  if (!this.shadowRoot) {
15
- this.attachShadow({ mode: 'open' });
41
+ this.attachShadow({ mode: 'open', delegatesFocus: ctor.delegatesFocus, slotAssignment: ctor.slotAssignment });
42
+ }
43
+ if (ctor.labelClicks) {
44
+ labelClickHosts.add(this);
45
+ watchLabelForwards();
16
46
  }
17
47
  }
18
48
  static get observedAttributes() {
19
49
  const attrs = [];
20
- for (const [name, config] of Object.entries(this.properties)) {
50
+ for (const name of Object.keys(this.properties)) {
21
51
  attrs.push(name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase());
22
- if (config.aliases) {
23
- for (const alias of Object.keys(config.aliases)) {
24
- attrs.push(alias);
25
- }
26
- }
27
52
  }
28
53
  return attrs;
29
54
  }
@@ -43,7 +68,16 @@ const config = this.props.getConfig(name);
43
68
  if (!config)
44
69
  return;
45
70
  const attrName = this._toKebabCase(name);
46
- if (config.type === 'boolean') {
71
+ this._reflecting = true;
72
+ try {
73
+ this._writeAttribute(attrName, config.type, newValue);
74
+ }
75
+ finally {
76
+ this._reflecting = false;
77
+ }
78
+ }
79
+ _writeAttribute(attrName, type, newValue) {
80
+ if (type === 'boolean') {
47
81
  if (newValue) {
48
82
  this.setAttribute(attrName, '');
49
83
  }
@@ -70,18 +104,17 @@ return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
70
104
  attributeChangedCallback(name, oldValue, newValue) {
71
105
  if (oldValue === newValue)
72
106
  return;
73
- let change = this.props.handleAlias(name, newValue);
74
- if (!change) {
75
- const camelName = this._toCamelCase(name);
76
- const propName = this.props.hasConfig(name) ? name : camelName;
77
- change = this.props.updateProperty(propName, newValue, 'attribute');
107
+ const propName = this.props.hasConfig(name) ? name : this._toCamelCase(name);
108
+ if (!this._reflecting && this._resetDefaults?.has(propName)) {
109
+ const config = this.props.getConfig(propName);
110
+ this._resetDefaults.set(propName, newValue ?? (typeof config.default === 'function' ? config.default() : config.default) ?? null);
78
111
  }
112
+ const change = this.props.updateProperty(propName, newValue, 'attribute');
79
113
  if (change) {
80
114
  this._handlePropertyChanges([change]);
81
115
  }
82
116
  }
83
117
  connectedCallback() {
84
- this._connected = true;
85
118
  if (!this._resetDefaults) {
86
119
  this._resetDefaults = new Map();
87
120
  const ctor = this.constructor;
@@ -89,13 +122,13 @@ for (const [name, config] of Object.entries(ctor.properties)) {
89
122
  if (!config.formValue)
90
123
  continue;
91
124
  const attr = this.getAttribute(this._toKebabCase(name));
92
- this._resetDefaults.set(name, attr ?? config.default ?? null);
93
- }
125
+ this._resetDefaults.set(name, attr ?? (typeof config.default === 'function' ? config.default() : config.default) ?? null);
94
126
  }
95
- const preSetProps = this._capturePreSetProperties();
96
- if (preSetProps.length > 0) {
97
- this._handlePropertyChanges(preSetProps);
98
127
  }
128
+ this._upgradeProperties();
129
+ this._connected = true;
130
+ if (this._validates)
131
+ this._validity.track();
99
132
  this.onConnect();
100
133
  if (!this._rendered) {
101
134
  this.render();
@@ -104,21 +137,28 @@ this._rendered = true;
104
137
  }
105
138
  disconnectedCallback() {
106
139
  this._connected = false;
140
+ if (this._validates)
141
+ this._validity.track();
107
142
  this.onDisconnect();
108
143
  }
109
- _capturePreSetProperties() {
110
- const changes = [];
111
- const ctor = this.constructor;
112
- for (const propName of Object.keys(ctor.properties)) {
113
- const descriptor = Object.getOwnPropertyDescriptor(this, propName);
114
- if (descriptor && descriptor.value !== undefined) {
115
- const change = this.props.updateProperty(propName, descriptor.value, 'property');
116
- if (change) {
117
- changes.push(change);
118
- }
144
+ formAssociatedCallback() {
145
+ if (this._validates)
146
+ this._validity.track();
119
147
  }
148
+ _upgradeProperties() {
149
+ for (const name of Object.keys(this.constructor.properties)) {
150
+ if (!Object.prototype.hasOwnProperty.call(this, name))
151
+ continue;
152
+ const value = this[name];
153
+ delete this[name];
154
+ if (value === undefined)
155
+ continue;
156
+ if (name in this)
157
+ this[name] = value;
158
+ else
159
+ this.setProperty(name, value);
120
160
  }
121
- return changes;
161
+ upgradeProperties(this);
122
162
  }
123
163
  _handlePropertyChanges(changes) {
124
164
  if (changes.length === 0)
@@ -171,6 +211,10 @@ return this.constructor.formAssociated === true;
171
211
  applyValidity(flags, message, anchor) {
172
212
  this._validity.set(flags, message, anchor);
173
213
  }
214
+ revealValidity() {
215
+ if (this._validates)
216
+ this._validity.reveal();
217
+ }
174
218
  get validity() {
175
219
  return this._validates ? this._internals.validity : undefined;
176
220
  }
@@ -208,14 +252,10 @@ roleEl.setAttribute('aria-label', text);
208
252
  else
209
253
  roleEl.removeAttribute('aria-label');
210
254
  }
211
- isDuplicateActivationClick() {
212
- if (this._handlingActivationClick)
213
- return true;
214
- this._handlingActivationClick = true;
215
- queueMicrotask(() => { this._handlingActivationClick = false; });
216
- return false;
217
- }
218
255
  formResetCallback() {
256
+ this._userEdited = false;
257
+ if (this._validates)
258
+ this._validity.reset();
219
259
  for (const [name, def] of this._resetDefaults ?? []) {
220
260
  this.setProperty(name, def);
221
261
  }
@@ -226,3 +266,6 @@ onFormReset() {
226
266
  }
227
267
  TyComponent.formAssociated = true;
228
268
  TyComponent.properties = {};
269
+ TyComponent.delegatesFocus = false;
270
+ TyComponent.slotAssignment = 'named';
271
+ TyComponent.labelClicks = false;
@@ -89,11 +89,25 @@ export declare class TyButton extends TyComponent<ButtonState> implements TyButt
89
89
  };
90
90
  };
91
91
  private _structureInitialized;
92
+ private _formDisabled;
92
93
  private _customFlavorSheet;
94
+ private _ownClick;
93
95
  constructor();
96
+ /**
97
+ * A real press inside the host's content box that missed the button: the
98
+ * empty host below a wide button that a min-height made taller, or around
99
+ * one a page's display: flex stretched. Nothing there looks like the
100
+ * button, so it's no press. Host padding and border are outside the
101
+ * content box.
102
+ */
103
+ private _pressOffButton;
94
104
  protected onConnect(): void;
95
105
  protected onDisconnect(): void;
96
106
  protected onPropertiesChanged(changes: PropertyChange[]): void;
107
+ formDisabledCallback(disabled: boolean): void;
108
+ private get _isDisabled();
109
+ /** Focus the inner <button>. The host itself isn't focusable. */
110
+ focus(options?: FocusOptions): void;
97
111
  /**
98
112
  * Custom flavors: adopt generated per-flavor rules pointed at the user's
99
113
  * design tokens (--ty-solid-X / --ty-color-X / --ty-bg-X), falling back to
@@ -4,12 +4,37 @@ import { ensureStyles, buildClassList } from "../utils/styles.js";
4
4
  import { buttonStyles, buttonCustomFlavorCss } from "../styles/button.js";
5
5
  import { syncCustomFlavorSheet } from "../utils/flavor-sheet.js";
6
6
  import { getLoaderSvg } from "../utils/loader-registry.js";
7
+ import { asSubmitAttempt } from "../utils/validity.js";
7
8
  export class TyButton extends TyComponent {
8
9
  constructor() {
9
10
  super();
10
11
  this._structureInitialized = false;
12
+ this._formDisabled = false;
11
13
  this._customFlavorSheet = null;
14
+ this._ownClick = null;
12
15
  ensureStyles(this.shadowRoot, { css: buttonStyles, id: "ty-button" });
16
+ this.addEventListener("click", (e) => {
17
+ const button = this.shadowRoot.querySelector("button");
18
+ if (!button || e === this._ownClick)
19
+ return;
20
+ if (e.composedPath().includes(button))
21
+ return;
22
+ e.stopImmediatePropagation();
23
+ if (!this._pressOffButton(e))
24
+ button.click();
25
+ }, true);
26
+ }
27
+ _pressOffButton(e) {
28
+ if (!e.isTrusted || !(e instanceof MouseEvent))
29
+ return false;
30
+ const r = this.getBoundingClientRect();
31
+ const s = getComputedStyle(this);
32
+ const px = (p) => parseFloat(s.getPropertyValue(p)) || 0;
33
+ const left = r.left + px("border-left-width") + px("padding-left");
34
+ const right = r.right - px("border-right-width") - px("padding-right");
35
+ const top = r.top + px("border-top-width") + px("padding-top");
36
+ const bottom = r.bottom - px("border-bottom-width") - px("padding-bottom");
37
+ return e.clientX >= left && e.clientX < right && e.clientY >= top && e.clientY < bottom;
13
38
  }
14
39
  onConnect() {
15
40
  this._syncCustomFlavor();
@@ -20,6 +45,21 @@ if (changes.some((c) => c.name === "flavor")) {
20
45
  this._syncCustomFlavor();
21
46
  }
22
47
  }
48
+ formDisabledCallback(disabled) {
49
+ this._formDisabled = disabled;
50
+ if (this._structureInitialized)
51
+ this.render();
52
+ }
53
+ get _isDisabled() {
54
+ return this.disabled || this._formDisabled;
55
+ }
56
+ focus(options) {
57
+ const button = this.shadowRoot?.querySelector("button");
58
+ if (button)
59
+ button.focus(options);
60
+ else
61
+ super.focus(options);
62
+ }
23
63
  _syncCustomFlavor() {
24
64
  const { base } = this.parseFlavor();
25
65
  this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, base, () => buttonCustomFlavorCss(base));
@@ -118,7 +158,7 @@ if (this.name && this.value) {
118
158
  this._internals.setFormValue(this.value);
119
159
  }
120
160
  try {
121
- form.requestSubmit();
161
+ asSubmitAttempt(() => form.requestSubmit());
122
162
  }
123
163
  finally {
124
164
  if (this.name && this.value)
@@ -136,7 +176,7 @@ initializeButtonStructure() {
136
176
  const shadow = this.shadowRoot;
137
177
  const classes = this.buildClasses();
138
178
  const button = document.createElement("button");
139
- button.disabled = this.disabled;
179
+ button.disabled = this._isDisabled;
140
180
  button.className = classes;
141
181
  button.setAttribute("part", "button");
142
182
  const loader = document.createElement("span");
@@ -155,15 +195,21 @@ button.appendChild(startSlot);
155
195
  button.appendChild(defaultSlot);
156
196
  button.appendChild(endSlot);
157
197
  button.addEventListener("click", (e) => {
158
- if (this.disabled || this.loading)
198
+ const path = e.composedPath();
199
+ if (path.slice(0, path.indexOf(button)).some((n) => n instanceof Element && n.localName === "ty-popup"))
159
200
  return;
160
201
  e.stopPropagation();
161
- this.handleFormAction();
162
- this.dispatchEvent(new CustomEvent("click", {
202
+ if (this._isDisabled || this.loading)
203
+ return;
204
+ const click = new CustomEvent("click", {
163
205
  bubbles: true,
164
206
  composed: true,
207
+ cancelable: true,
165
208
  detail: { originalEvent: e },
166
- }));
209
+ });
210
+ this._ownClick = click;
211
+ if (this.dispatchEvent(click))
212
+ this.handleFormAction();
167
213
  });
168
214
  this.applyLoadingState(button);
169
215
  shadow.appendChild(button);
@@ -174,12 +220,14 @@ const isLoading = this.loading;
174
220
  button.classList.toggle("loading", isLoading);
175
221
  if (isLoading) {
176
222
  button.setAttribute("aria-busy", "true");
223
+ button.setAttribute("aria-disabled", "true");
177
224
  const loader = button.querySelector(".loader-icon");
178
225
  if (loader)
179
226
  loader.innerHTML = getLoaderSvg();
180
227
  }
181
228
  else {
182
229
  button.removeAttribute("aria-busy");
230
+ button.removeAttribute("aria-disabled");
183
231
  }
184
232
  }
185
233
  render() {
@@ -191,7 +239,7 @@ return;
191
239
  const classes = this.buildClasses();
192
240
  const button = shadow.querySelector("button");
193
241
  if (button) {
194
- button.disabled = this.disabled;
242
+ button.disabled = this._isDisabled;
195
243
  button.className = classes;
196
244
  this.applyLoadingState(button);
197
245
  }
@@ -32,7 +32,7 @@ export interface DayClickDetail {
32
32
  export declare class TyCalendarMonth extends HTMLElement {
33
33
  private _displayYear;
34
34
  private _displayMonth;
35
- private _locale;
35
+ private _locale?;
36
36
  private _size;
37
37
  private _width?;
38
38
  private _minWidth?;
@@ -97,6 +97,12 @@ export declare class TyCalendarMonth extends HTMLElement {
97
97
  * Useful when external data changes (e.g., async event loading)
98
98
  */
99
99
  refresh(): void;
100
+ /**
101
+ * A day was picked (click, Enter, Space): it becomes the grid's tab stop and
102
+ * takes the focus, which render() keeps on it when the pick re-renders the
103
+ * grid. Then the events go out.
104
+ */
105
+ private pickDay;
100
106
  private dispatchDayClick;
101
107
  /**
102
108
  * WAI-ARIA grid pattern: gridcell + roving tabindex (exactly one cell in
@@ -1,7 +1,8 @@
1
1
  import { ensureStyles } from '../utils/styles.js';
2
+ import { liftProperties, upgradeProperties } from '../utils/upgrade-properties.js';
2
3
  import { syncCustomFlavorSheet } from '../utils/flavor-sheet.js';
3
4
  import { calendarMonthStyles, calendarMonthCustomFlavorCss } from '../styles/calendar-month.js';
4
- import { getCalendarMonthDays, getLocalizedWeekdays, parseISODate } from '../utils/calendar-utils.js';
5
+ import { getCalendarMonthDays, getLocalizedWeekdays, localMidnight, parseDateDay, utcMidnight } from '../utils/calendar-utils.js';
5
6
  import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
6
7
  function defaultDayContent(dayContext) {
7
8
  return dayContext.dayInMonth.toString();
@@ -24,10 +25,10 @@ return value instanceof HTMLElement;
24
25
  function isoToUTCTimestamp(iso) {
25
26
  if (!iso)
26
27
  return null;
27
- const parsed = parseISODate(iso);
28
+ const parsed = parseDateDay(iso);
28
29
  if (!parsed)
29
30
  return null;
30
- return Date.UTC(parsed.year, parsed.month - 1, parsed.day);
31
+ return utcMidnight(parsed.year, parsed.month, parsed.day);
31
32
  }
32
33
  function normalizeSizeValue(value) {
33
34
  if (!value || value === '')
@@ -44,7 +45,6 @@ return ['display-year', 'display-month', 'locale', 'size', 'min', 'max', 'flavor
44
45
  }
45
46
  constructor() {
46
47
  super();
47
- this._locale = 'en-US';
48
48
  this._size = 'md';
49
49
  this._customFlavorSheet = null;
50
50
  this._focusedIndex = null;
@@ -53,6 +53,7 @@ const today = new Date();
53
53
  this._displayYear = today.getFullYear();
54
54
  this._displayMonth = today.getMonth() + 1;
55
55
  this.attachShadow({ mode: 'open' });
56
+ liftProperties(this);
56
57
  }
57
58
  connectedCallback() {
58
59
  if (!this._displayMonth) {
@@ -62,23 +63,15 @@ if (!this._displayYear) {
62
63
  this._displayYear = new Date().getFullYear();
63
64
  }
64
65
  if (!this._locale) {
65
- this._locale = this.getAttribute('locale') || 'en-US';
66
+ this._locale = this.getAttribute('locale') || undefined;
66
67
  }
67
68
  const sizeAttr = this.getAttribute('size');
68
69
  if (sizeAttr && (sizeAttr === 'sm' || sizeAttr === 'md' || sizeAttr === 'lg')) {
69
70
  this._size = sizeAttr;
70
71
  }
71
- const plainDayContentFn = this.dayContentFn;
72
- if (plainDayContentFn && !this._dayContentFn) {
73
- this._dayContentFn = plainDayContentFn;
74
- delete this.dayContentFn;
75
- }
76
- const plainCustomCSS = this.customCSS;
77
- if (plainCustomCSS && !this._customCSS) {
78
- this._customCSS = plainCustomCSS;
79
- delete this.customCSS;
80
- }
72
+ upgradeProperties(this);
81
73
  this._localeObserver = observeLocaleChanges(this, () => {
74
+ if (!this._locale)
82
75
  this.render();
83
76
  });
84
77
  this._syncCustomFlavor();
@@ -102,7 +95,7 @@ this.displayMonth = n;
102
95
  }
103
96
  }
104
97
  else if (name === 'locale') {
105
- this._locale = newValue || 'en-US';
98
+ this._locale = newValue || undefined;
106
99
  this.render();
107
100
  }
108
101
  else if (name === 'size') {
@@ -143,11 +136,11 @@ this.render();
143
136
  }
144
137
  }
145
138
  get locale() {
146
- return getEffectiveLocale(this, this.getAttribute('locale'));
139
+ return getEffectiveLocale(this, this._locale);
147
140
  }
148
141
  set locale(value) {
149
142
  if (this._locale !== value) {
150
- this._locale = value;
143
+ this._locale = value || undefined;
151
144
  this.render();
152
145
  }
153
146
  }
@@ -239,6 +232,7 @@ set value(timestamp) {
239
232
  const newValue = timestamp ?? undefined;
240
233
  if (this._value !== newValue) {
241
234
  this._value = newValue;
235
+ this._focusedIndex = null;
242
236
  this.render();
243
237
  }
244
238
  }
@@ -276,6 +270,15 @@ this.shadowRoot.adoptedStyleSheets = [...existing, this._customCSS];
276
270
  refresh() {
277
271
  this.render();
278
272
  }
273
+ pickDay(cell, dayContext, domEvent) {
274
+ const index = this._cellElements.indexOf(cell);
275
+ if (index !== -1) {
276
+ this._cellElements.forEach((c) => c.setAttribute('tabindex', c === cell ? '0' : '-1'));
277
+ this._focusedIndex = index;
278
+ cell.focus({ preventScroll: true });
279
+ }
280
+ this.dispatchDayClick(dayContext, domEvent);
281
+ }
279
282
  dispatchDayClick(dayContext, _domEvent) {
280
283
  const detail = {
281
284
  dayContext,
@@ -297,7 +300,7 @@ cancelable: true,
297
300
  this.dispatchEvent(event);
298
301
  }
299
302
  }
300
- renderDayCell(dayContext, disabled, isRoving) {
303
+ renderDayCell(dayContext, disabled, isRoving, label) {
301
304
  const dayElement = document.createElement('div');
302
305
  const content = this._dayContentFn
303
306
  ? this._dayContentFn(dayContext)
@@ -319,8 +322,7 @@ else if (isDOMElement(content)) {
319
322
  dayElement.appendChild(content);
320
323
  }
321
324
  dayElement.setAttribute('role', 'gridcell');
322
- dayElement.setAttribute('aria-label', new Intl.DateTimeFormat(this._locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
323
- .format(new Date(dayContext.localValue)));
325
+ dayElement.setAttribute('aria-label', label.format(new Date(dayContext.localValue)));
324
326
  dayElement.setAttribute('aria-selected', String(!!dayContext.isSelected));
325
327
  if (dayContext.today)
326
328
  dayElement.setAttribute('aria-current', 'date');
@@ -331,13 +333,13 @@ dayElement.setAttribute('tabindex', '-1');
331
333
  else {
332
334
  dayElement.setAttribute('tabindex', isRoving ? '0' : '-1');
333
335
  dayElement.addEventListener('click', (event) => {
334
- this.dispatchDayClick(dayContext, event);
336
+ this.pickDay(dayElement, dayContext, event);
335
337
  });
336
338
  dayElement.addEventListener('keydown', (event) => {
337
339
  const ke = event;
338
340
  if (ke.key === 'Enter' || ke.key === ' ') {
339
341
  ke.preventDefault();
340
- this.dispatchDayClick(dayContext, event);
342
+ this.pickDay(dayElement, dayContext, event);
341
343
  }
342
344
  });
343
345
  }
@@ -351,7 +353,7 @@ ensureStyles(root, { css: calendarMonthStyles, id: 'ty-calendar-month' });
351
353
  this.applyCustomCSS();
352
354
  this.applyWidthProperties();
353
355
  let selection;
354
- if (this._value) {
356
+ if (this._value !== undefined) {
355
357
  const date = new Date(this._value);
356
358
  selection = {
357
359
  year: date.getFullYear(),
@@ -360,13 +362,16 @@ day: date.getDate()
360
362
  };
361
363
  }
362
364
  const days = getCalendarMonthDays(this._displayYear, this._displayMonth, selection);
363
- const weekdays = getLocalizedWeekdays(this._locale, 'short');
365
+ const locale = this.locale;
366
+ const weekdays = getLocalizedWeekdays(locale, 'short');
367
+ const dayLabel = new Intl.DateTimeFormat(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
368
+ const hadFocus = !!root.activeElement;
364
369
  root.innerHTML = '';
365
370
  const calendarContainer = document.createElement('div');
366
371
  calendarContainer.className = `calendar-flex-container calendar-size-${this._size}`;
367
372
  calendarContainer.setAttribute('role', 'grid');
368
- calendarContainer.setAttribute('aria-label', new Intl.DateTimeFormat(this._locale, { month: 'long', year: 'numeric' })
369
- .format(new Date(this._displayYear, this._displayMonth - 1, 1)));
373
+ calendarContainer.setAttribute('aria-label', new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' })
374
+ .format(localMidnight(this._displayYear, this._displayMonth, 1)));
370
375
  const headerRow = document.createElement('div');
371
376
  headerRow.className = 'calendar-row calendar-header-row';
372
377
  headerRow.setAttribute('role', 'row');
@@ -421,7 +426,7 @@ dayRow.setAttribute('role', 'row');
421
426
  week.forEach(dayContext => {
422
427
  const disabled = (minTs !== null && dayContext.value < minTs) ||
423
428
  (maxTs !== null && dayContext.value > maxTs);
424
- const dayCell = this.renderDayCell(dayContext, disabled, flatIndex === effectiveFocusedIndex);
429
+ const dayCell = this.renderDayCell(dayContext, disabled, flatIndex === effectiveFocusedIndex, dayLabel);
425
430
  dayCell.className = `${dayCell.className} calendar-cell calendar-day-cell`;
426
431
  dayRow.appendChild(dayCell);
427
432
  this._cellElements[flatIndex] = dayCell;
@@ -452,6 +457,8 @@ nextCell.focus();
452
457
  }
453
458
  });
454
459
  root.appendChild(calendarContainer);
460
+ if (hadFocus)
461
+ this._cellElements[effectiveFocusedIndex]?.focus({ preventScroll: true });
455
462
  }
456
463
  }
457
464
  if (!customElements.get('ty-calendar-month')) {