@iyulab/components 2.19.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.20.0] - 2026-10-10
4
+
5
+ ### Changed
6
+
7
+ - `required` on `u-field` makes the control it labels required. It only drew the marker, so a field shown as required
8
+ submitted empty unless the control also carried `required`. A field wrapping several controls keeps the marker only;
9
+ turning `required` off on the field removes only the `required` the field set.
10
+ - Form controls show their error when a submit attempt or `form.reportValidity()` on the owning `<form>` blocks
11
+ submission. Submission was blocked but no control showed why. To check without showing errors, call the control's
12
+ `validate(false)` — a page-level `form.checkValidity()` fires the same `invalid` event and shows errors too.
13
+ - `u-form.validate()` moves focus to the first invalid control and takes `report` like a control's `validate()`:
14
+ `validate(false)` checks without touching the screen.
15
+
16
+ ### Fixed
17
+
18
+ - `u-form` saw only its direct children, so a control wrapped in `u-field` or a layout element was not validated, synced
19
+ from `model`, or reset — an empty required field reported the form valid. It now covers every control inside it, up
20
+ to a nested `u-form`, and validates all of them instead of stopping at the first invalid one.
21
+ - `validate()` judged the previous value when the value was set in the same tick (`el.value = x; el.validate()`, and
22
+ `form.model = …; form.validate()`), and left the error on. It now completes a pending render first.
23
+
24
+ ## [2.19.1] - 2026-10-09
25
+
26
+ ### Changed
27
+
28
+ - `Dialog` loads `u-input` only when `Dialog.prompt` is called. An app that imports `Dialog` from its own module for
29
+ `alert` and `confirm` no longer carries the input and the popover, option and field it brings (gzip 62.4 KB → 43.7 KB
30
+ in a minimal consumer); `prompt` loads it on first use and stays as before.
31
+
3
32
  ## [2.19.0] - 2026-10-09
4
33
 
5
34
  ### Added
@@ -6,6 +6,15 @@ export declare class UElement extends LitElement {
6
6
  private detachedLocaleRevision?;
7
7
  connectedCallback(): void;
8
8
  disconnectedCallback(): void;
9
+ /** `performUpdate()` 안인가 — 렌더 도중에 같은 요소의 렌더를 다시 당기지 않으려고. */
10
+ private updating;
11
+ protected performUpdate(): void;
12
+ /**
13
+ * 대기 중인 렌더를 지금 끝낸다 — **렌더된 상태를 읽는 동기 판정**(검증이 안쪽 네이티브 요소의 `validity` 를
14
+ * 읽는 것 등)이 바로 앞의 속성 변경을 보게 한다. `el.value = x; el.validate()` 가 같은 틱에 바꾸기 전 값으로
15
+ * 판정하던 것을 막는다. 첫 렌더 전이거나 렌더 도중이면 아무것도 하지 않는다.
16
+ */
17
+ protected flushUpdate(): void;
9
18
  /**
10
19
  * 로케일이 바뀌었다(`Locale.set` · `Locale.register`) — 기본은 다시 그린다. 렌더 밖에서 로케일 문장을 담아 둔
11
20
  * 컴포넌트(속성·`ElementInternals`·필드에 적어 둔 이름)는 이것을 재정의해 그 값을 다시 적고 `super` 를 부른다.
@@ -27,6 +27,10 @@ function warnIfTokensMissing() {
27
27
  console.warn("[@iyulab/components] No design-token sheet found in the document — components render with their built-in fallbacks (baked from the light theme). Dark theme and theme variable overrides will not apply.\n Static CSS: import '@iyulab/components/styles/tokens.css'\n At runtime: Theme.init()\n (The @iyulab/modern-app shell calls Theme.init() for you. Screens rendered outside the shell — login, onboarding, embeds — need one of the two.)");
28
28
  }
29
29
  var UElement = class extends LitElement {
30
+ constructor(..._args) {
31
+ super(..._args);
32
+ this.updating = false;
33
+ }
30
34
  static {
31
35
  this.styles = styles;
32
36
  }
@@ -43,6 +47,22 @@ var UElement = class extends LitElement {
43
47
  this.detachedLocaleRevision = Locale.revision;
44
48
  super.disconnectedCallback();
45
49
  }
50
+ performUpdate() {
51
+ this.updating = true;
52
+ try {
53
+ super.performUpdate();
54
+ } finally {
55
+ this.updating = false;
56
+ }
57
+ }
58
+ /**
59
+ * 대기 중인 렌더를 지금 끝낸다 — **렌더된 상태를 읽는 동기 판정**(검증이 안쪽 네이티브 요소의 `validity` 를
60
+ * 읽는 것 등)이 바로 앞의 속성 변경을 보게 한다. `el.value = x; el.validate()` 가 같은 틱에 바꾸기 전 값으로
61
+ * 판정하던 것을 막는다. 첫 렌더 전이거나 렌더 도중이면 아무것도 하지 않는다.
62
+ */
63
+ flushUpdate() {
64
+ if (this.hasUpdated && this.isUpdatePending && !this.updating) this.performUpdate();
65
+ }
46
66
  /**
47
67
  * 로케일이 바뀌었다(`Locale.set` · `Locale.register`) — 기본은 다시 그린다. 렌더 밖에서 로케일 문장을 담아 둔
48
68
  * 컴포넌트(속성·`ElementInternals`·필드에 적어 둔 이름)는 이것을 재정의해 그 값을 다시 적고 `super` 를 부른다.
@@ -74,7 +74,20 @@ export declare abstract class UFormControlElement<T> extends UElement {
74
74
  protected commit(flags: ValidityStateFlags, message: string, anchor?: HTMLElement): void;
75
75
  /** form-associated 표준 콜백 — 조상 fieldset 의 비활성 상태가 바뀔 때 UA 가 부른다. */
76
76
  formDisabledCallback(disabled: boolean): void;
77
+ constructor();
77
78
  connectedCallback(): void;
79
+ /** 자기 `validate()` 가 `internals.checkValidity()` 를 부르는 동안 — 그때 오는 `invalid` 는 보고가 아니다. */
80
+ private quietCheck;
81
+ /**
82
+ * UA 가 보낸 `invalid` 에서 오류를 보인다 — 소속 `<form>` 의 제출 시도(`requestSubmit()`·제출 버튼)와
83
+ * `form.reportValidity()` 가 이 경로다. 그러지 않으면 제출은 막히는데 어느 칸이 틀렸는지 화면에 아무것도
84
+ * 없다. 해제는 종전대로 값이 바뀐 뒤의 `validate()` 가 한다.
85
+ *
86
+ * 자기 `validate()` 의 조용한 확인과 합성 이벤트는 무시한다. ⚠`invalid` 이벤트는 자기를 부른 메서드를
87
+ * 알려 주지 않아(`checkValidity()` 도 같은 이벤트를 낸다) 페이지가 직접 부른 `form.checkValidity()` 도
88
+ * 오류를 보인다 — 플랫폼 한계다. 조용히 확인하려면 컨트롤의 `validate(false)` 나 `u-form.validate(false)` 를 쓴다.
89
+ */
90
+ private handleInvalid;
78
91
  /**
79
92
  * 검증 메시지는 `setValidity()` 가 `internals` 에 적어 둔 문장이다 — 다시 그리기만 하면 옛 언어가 그대로 나온다.
80
93
  * 첫 렌더 뒤라면(검증이 참조하는 안쪽 컨트롤이 있을 때) 다시 계산하고 그린다.
@@ -9,21 +9,6 @@ import { property, state } from "lit/decorators.js";
9
9
  * 사용자 입력을 받는 모든 컴포넌트가 이 클래스를 확장합니다.
10
10
  */
11
11
  var UFormControlElement = class extends UElement {
12
- constructor(..._args) {
13
- super(..._args);
14
- this.disabled = false;
15
- this.formDisabled = false;
16
- this.readonly = false;
17
- this.required = false;
18
- this.invalid = false;
19
- this.novalidate = false;
20
- this.customMessage = "";
21
- this.hasSlottedLabel = false;
22
- this.handleLabelSlotChange = (e) => {
23
- const slot = e.target;
24
- this.hasSlottedLabel = slot.assignedNodes({ flatten: true }).some((n) => n.nodeType === Node.ELEMENT_NODE || !!n.textContent?.trim());
25
- };
26
- }
27
12
  static {
28
13
  this.styles = [super.styles, styles];
29
14
  }
@@ -83,6 +68,28 @@ var UFormControlElement = class extends UElement {
83
68
  this.formDisabled = disabled;
84
69
  this.updateComplete.then(() => this.requestUpdate("formDisabled", old));
85
70
  }
71
+ constructor() {
72
+ super();
73
+ this.disabled = false;
74
+ this.formDisabled = false;
75
+ this.readonly = false;
76
+ this.required = false;
77
+ this.invalid = false;
78
+ this.novalidate = false;
79
+ this.customMessage = "";
80
+ this.quietCheck = false;
81
+ this.handleInvalid = (e) => {
82
+ if (this.quietCheck || !e.isTrusted) return;
83
+ this.invalid = true;
84
+ this.requestUpdate();
85
+ };
86
+ this.hasSlottedLabel = false;
87
+ this.handleLabelSlotChange = (e) => {
88
+ const slot = e.target;
89
+ this.hasSlottedLabel = slot.assignedNodes({ flatten: true }).some((n) => n.nodeType === Node.ELEMENT_NODE || !!n.textContent?.trim());
90
+ };
91
+ this.addEventListener("invalid", this.handleInvalid);
92
+ }
86
93
  connectedCallback() {
87
94
  super.connectedCallback();
88
95
  if (!this.internals && "attachInternals" in this) this.internals = this.attachInternals();
@@ -165,9 +172,18 @@ var UFormControlElement = class extends UElement {
165
172
  * @returns 유효하면 `true`, 아니면 `false`
166
173
  */
167
174
  validate(report = true) {
175
+ this.flushUpdate();
168
176
  this.setValidity();
169
177
  this.requestUpdate();
170
- const valid = this.internals ? this.internals.checkValidity() : true;
178
+ let valid = true;
179
+ if (this.internals) {
180
+ this.quietCheck = true;
181
+ try {
182
+ valid = this.internals.checkValidity();
183
+ } finally {
184
+ this.quietCheck = false;
185
+ }
186
+ }
171
187
  if (report) this.invalid = !valid;
172
188
  return valid;
173
189
  }
@@ -90,6 +90,15 @@ export declare class UField extends UElement {
90
90
  private get hasControlInSubtree();
91
91
  protected firstUpdated(changed: PropertyValues): void;
92
92
  protected updated(changed: PropertyValues): void;
93
+ /** 이 필드가 `required` 를 켠 컨트롤 — 끌 때는 우리가 켠 것만 끈다(소비자가 단 `required` 는 그대로). */
94
+ private requiredApplied?;
95
+ /**
96
+ * 필드의 `required` 를 그 컨트롤의 **제약**으로 넘긴다. 종전에는 별표만 그리고 컨트롤은 선택 입력으로 남아,
97
+ * `<u-field label="이메일" required><u-input></u-input></u-field>` 가 빈 채로 제출됐다 — 문서 예제가 전부 그
98
+ * 형태였다. 라벨처럼 «이 필드가 가리키는 컨트롤 하나» 에만 넘긴다 — 컨트롤이 여럿인 묶음에서는 어느 것이 필수인지
99
+ * 필드가 알 수 없어 넘기지 않는다(별표만 그린다).
100
+ */
101
+ private syncRequired;
93
102
  /**
94
103
  * 🔴**이 컴포넌트의 존재 이유가 «라벨과 컨트롤을 한 칸으로 짝짓는 것»인데, 오랫동안
95
104
  * 라벨을 «그리기만» 하고 연결하지 않았다** — 섀도의 `label` 에 `for` 가 없고 슬롯된
@@ -153,11 +153,33 @@ var UField = class UField extends UElement {
153
153
  }
154
154
  firstUpdated(changed) {
155
155
  super.firstUpdated(changed);
156
- (this.shadowRoot?.querySelector("slot:not([name])"))?.addEventListener("slotchange", () => this.nameSlottedControl());
156
+ (this.shadowRoot?.querySelector("slot:not([name])"))?.addEventListener("slotchange", () => {
157
+ this.nameSlottedControl();
158
+ this.syncRequired();
159
+ });
157
160
  }
158
161
  updated(changed) {
159
162
  super.updated(changed);
160
163
  if (changed.has("label") || changed.has("description")) this.nameSlottedControl();
164
+ if (changed.has("required")) this.syncRequired();
165
+ }
166
+ /**
167
+ * 필드의 `required` 를 그 컨트롤의 **제약**으로 넘긴다. 종전에는 별표만 그리고 컨트롤은 선택 입력으로 남아,
168
+ * `<u-field label="이메일" required><u-input></u-input></u-field>` 가 빈 채로 제출됐다 — 문서 예제가 전부 그
169
+ * 형태였다. 라벨처럼 «이 필드가 가리키는 컨트롤 하나» 에만 넘긴다 — 컨트롤이 여럿인 묶음에서는 어느 것이 필수인지
170
+ * 필드가 알 수 없어 넘기지 않는다(별표만 그린다).
171
+ */
172
+ syncRequired() {
173
+ const control = this.labelsAGroup ? null : this.controlToName;
174
+ const target = control && "required" in control ? control : null;
175
+ if (this.requiredApplied && (this.requiredApplied !== target || !this.required)) {
176
+ this.requiredApplied.required = false;
177
+ this.requiredApplied = void 0;
178
+ }
179
+ if (this.required && target && !target.required) {
180
+ target.required = true;
181
+ this.requiredApplied = target;
182
+ }
161
183
  }
162
184
  /**
163
185
  * 🔴**이 컴포넌트의 존재 이유가 «라벨과 컨트롤을 한 칸으로 짝짓는 것»인데, 오랫동안
@@ -22,15 +22,23 @@ export declare class UForm extends UElement {
22
22
  protected updated(changedProperties: PropertyValues): void;
23
23
  render(): import('lit-html').TemplateResult<1>;
24
24
  /**
25
- * 폼 내의 모든 포함된 컨트롤을 검증합니다.
25
+ * 폼 안의 포함된 컨트롤을 **전부** 검증합니다 — 첫 오류에서 멈추지 않아 모든 무효 컨트롤이 오류를 보입니다.
26
+ * 컨트롤은 위치와 무관하게 대상입니다(`u-field`·배치용 요소 안의 것 포함 — 네이티브 `form.elements` 와 같다).
27
+ *
28
+ * @param report `true`(기본값)면 각 컨트롤의 오류 표시를 갱신하고 첫 무효 컨트롤로 포커스를 옮긴다
29
+ * (네이티브 `reportValidity()`). `false`면 화면에 영향 없이 유효 여부만 확인한다(`checkValidity()`).
26
30
  * @returns 모든 컨트롤이 유효하면 true, 아니면 false
27
31
  */
28
- validate(): boolean;
32
+ validate(report?: boolean): boolean;
29
33
  /**
30
34
  * 폼 내의 모든 포함된 컨트롤을 스냅샷 값으로 리셋합니다.
31
35
  */
32
36
  reset(): void;
33
37
  private sync;
38
+ /**
39
+ * 포함된 컨트롤을 문서 순서로 모은다 — 슬롯에 배정된 요소 **와 그 자손**이 대상이다. 감싸개(`u-field` 등) 안의
40
+ * 컨트롤도 이 폼의 것이다. 안쪽 `u-form` 의 컨트롤은 그 폼의 것이라 넘지 않는다.
41
+ */
34
42
  private getControls;
35
43
  private isIncluded;
36
44
  private handleSlotChange;
@@ -53,11 +53,19 @@ var UForm = class UForm extends UElement {
53
53
  return html`<slot @slotchange=${this.handleSlotChange}></slot>`;
54
54
  }
55
55
  /**
56
- * 폼 내의 모든 포함된 컨트롤을 검증합니다.
56
+ * 폼 안의 포함된 컨트롤을 **전부** 검증합니다 — 첫 오류에서 멈추지 않아 모든 무효 컨트롤이 오류를 보입니다.
57
+ * 컨트롤은 위치와 무관하게 대상입니다(`u-field`·배치용 요소 안의 것 포함 — 네이티브 `form.elements` 와 같다).
58
+ *
59
+ * @param report `true`(기본값)면 각 컨트롤의 오류 표시를 갱신하고 첫 무효 컨트롤로 포커스를 옮긴다
60
+ * (네이티브 `reportValidity()`). `false`면 화면에 영향 없이 유효 여부만 확인한다(`checkValidity()`).
57
61
  * @returns 모든 컨트롤이 유효하면 true, 아니면 false
58
62
  */
59
- validate() {
60
- return this.getControls().every((control) => control.validate());
63
+ validate(report = true) {
64
+ this.flushUpdate();
65
+ const controls = this.getControls();
66
+ const firstInvalid = controls[controls.map((control) => control.validate(report)).indexOf(false)];
67
+ if (report && firstInvalid) firstInvalid.focus();
68
+ return firstInvalid === void 0;
61
69
  }
62
70
  /**
63
71
  * 폼 내의 모든 포함된 컨트롤을 스냅샷 값으로 리셋합니다.
@@ -75,10 +83,14 @@ var UForm = class UForm extends UElement {
75
83
  if (!this.model) return;
76
84
  for (const control of this.getControls()) if (control.name && control.name in this.model) control.value = this.model[control.name];
77
85
  }
86
+ /**
87
+ * 포함된 컨트롤을 문서 순서로 모은다 — 슬롯에 배정된 요소 **와 그 자손**이 대상이다. 감싸개(`u-field` 등) 안의
88
+ * 컨트롤도 이 폼의 것이다. 안쪽 `u-form` 의 컨트롤은 그 폼의 것이라 넘지 않는다.
89
+ */
78
90
  getControls() {
79
91
  const slot = this.renderRoot.querySelector("slot");
80
92
  if (!slot) return [];
81
- return slot.assignedElements({ flatten: true }).filter((el) => el instanceof UFormControlElement).filter((el) => this.isIncluded(el));
93
+ return slot.assignedElements({ flatten: true }).flatMap((el) => [el, ...el.querySelectorAll("*")]).filter((el) => el instanceof UFormControlElement).filter((el) => el.parentElement?.closest("u-form") === this).filter((el) => this.isIncluded(el));
82
94
  }
83
95
  isIncluded(el) {
84
96
  const name = el.name;
@@ -2,7 +2,6 @@ import { Locale } from "./Locale.js";
2
2
  import { isImeComposing } from "./keyboard.js";
3
3
  import "../components/button/UButton.js";
4
4
  import { UDialog } from "../components/dialog/UDialog.js";
5
- import "../components/input/UInput.js";
6
5
  import { html, nothing, render } from "lit";
7
6
  import { ifDefined } from "lit/directives/if-defined.js";
8
7
  import { unsafeHTML } from "lit/directives/unsafe-html.js";
@@ -77,6 +76,7 @@ var Dialog = class {
77
76
  * @returns 입력값 또는 취소 시 null
78
77
  */
79
78
  static async prompt(message, options) {
79
+ await import("../components/input/UInput.js");
80
80
  let inputValue = options?.defaultValue || "";
81
81
  const messageId = nextMessageId();
82
82
  return await this.present({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iyulab/components",
3
3
  "description": "web-components library based on lit-element made by iyulab",
4
- "version": "2.19.0",
4
+ "version": "2.20.0",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",
@@ -85,7 +85,7 @@ because their name normally comes from their own content:
85
85
  | `label` | `string` | — | — | Label text |
86
86
  | `description` | `string` | — | — | Helper text shown below the control |
87
87
  | `validationMessage` | `string` | — | — | Error message shown when `invalid` |
88
- | `required` | `boolean` | `false` | ✓ | Show required marker |
88
+ | `required` | `boolean` | `false` | ✓ | Show the required marker and make the slotted control required (a single control — with several controls the field only shows the marker). Turning it off removes only the `required` the field set |
89
89
  | `invalid` | `boolean` | `false` | ✓ | Show validation error state |
90
90
  | `disabled` | `boolean` | `false` | ✓ | Disable state forwarding |
91
91
 
@@ -7,6 +7,8 @@ import '@iyulab/components/dist/components/form/UForm.js';
7
7
  **Tag:** `u-form`
8
8
 
9
9
  Form group with two-way model binding. Wraps `UFormControlElement`-based controls and observes value changes.
10
+ Controls belong to the form wherever they sit inside it — wrapped in `u-field` or a layout element counts; a nested
11
+ `u-form` keeps its own controls.
10
12
 
11
13
  ```html
12
14
  <u-form id="form">
@@ -29,7 +31,7 @@ form.addEventListener('change', () => {
29
31
  console.log(form.model); // { email: '...', role: '...' }
30
32
  });
31
33
 
32
- // Validate all controls
34
+ // Validate every control: each invalid one shows its error, focus moves to the first
33
35
  if (form.validate()) {
34
36
  submitData(form.model);
35
37
  }
@@ -64,5 +66,5 @@ form.reset();
64
66
 
65
67
  | Method | Returns | Description |
66
68
  |--------|---------|-------------|
67
- | `validate()` | `boolean` | Validate all child controls |
68
- | `reset()` | `void` | Reset all child controls |
69
+ | `validate(report?)` | `boolean` | Validate every control in the form. With `report` (default `true`) each invalid control shows its error and focus moves to the first one, like `form.reportValidity()`; `validate(false)` only checks, like `checkValidity()` |
70
+ | `reset()` | `void` | Restore every control in the form to the model snapshot |