@threadlabs/looma 0.53.17 → 0.53.18

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/docs/catalog.json CHANGED
@@ -780,7 +780,7 @@
780
780
  ],
781
781
  "schemaVersion": 1,
782
782
  "package": "@threadlabs/looma",
783
- "version": "0.53.17",
783
+ "version": "0.53.18",
784
784
  "groups": [
785
785
  {
786
786
  "id": "layout",
@@ -19023,7 +19023,7 @@
19023
19023
  {
19024
19024
  "name": "invalid",
19025
19025
  "property": "invalid",
19026
- "description": "Marks the field's control invalid by setting aria-invalid on it. Only while invalid, the error slot appears and becomes part of the control's description.",
19026
+ "description": "Marks the field's control invalid by setting aria-invalid on it. Only while invalid, the error slot appears and becomes part of the control's description. Clearing the field error restores the control's own validation state.",
19027
19027
  "type": "boolean",
19028
19028
  "valueType": {
19029
19029
  "kind": "terminal",
@@ -19052,7 +19052,7 @@
19052
19052
  },
19053
19053
  {
19054
19054
  "name": "invalid",
19055
- "description": "Marks the field's control invalid by setting aria-invalid on it. Only while invalid, the error slot appears and becomes part of the control's description.",
19055
+ "description": "Marks the field's control invalid by setting aria-invalid on it. Only while invalid, the error slot appears and becomes part of the control's description. Clearing the field error restores the control's own validation state.",
19056
19056
  "type": "boolean",
19057
19057
  "default": false
19058
19058
  },
package/editor/index.js CHANGED
@@ -5258,8 +5258,41 @@ function connect$9(host) {
5258
5258
  const element = host.element;
5259
5259
  let activeInput = null;
5260
5260
  let owned = /* @__PURE__ */ new Set();
5261
+ let controlInvalid;
5261
5262
  let queued = false;
5262
5263
  const warned = /* @__PURE__ */ new Set();
5264
+ const readControlInvalid = (records) => {
5265
+ if (records.some((record) => record.attributeName === "aria-invalid")) controlInvalid = activeInput.getAttribute("aria-invalid") ?? "false";
5266
+ else if (records.some(({ attributeName }) => /^data-ui-[a-z-]+-prop-invalid$/.test(attributeName) && activeInput.getAttribute(attributeName) === "true")) controlInvalid = "true";
5267
+ };
5268
+ const setNativeInvalid = (value) => {
5269
+ if (activeInput.getAttribute("aria-invalid") === value) return;
5270
+ activeInput.setAttribute("aria-invalid", value);
5271
+ invalidObserver.takeRecords();
5272
+ };
5273
+ const invalidObserver = new MutationObserver((records) => {
5274
+ readControlInvalid(records);
5275
+ if (host.props.invalid.value) setNativeInvalid("true");
5276
+ });
5277
+ const releaseInvalid = () => {
5278
+ if (controlInvalid === void 0) return;
5279
+ readControlInvalid(invalidObserver.takeRecords());
5280
+ invalidObserver.disconnect();
5281
+ setNativeInvalid(controlInvalid);
5282
+ controlInvalid = void 0;
5283
+ };
5284
+ const updateInvalid = () => {
5285
+ if (!host.props.invalid.value) {
5286
+ releaseInvalid();
5287
+ return;
5288
+ }
5289
+ if (controlInvalid === void 0) {
5290
+ controlInvalid = activeInput.getAttribute("aria-invalid") ?? "false";
5291
+ invalidObserver.observe(activeInput, { attributes: true });
5292
+ }
5293
+ readControlInvalid(invalidObserver.takeRecords());
5294
+ setNativeInvalid("true");
5295
+ };
5263
5296
  const removeOwned = (input) => {
5264
5297
  if (!input || owned.size === 0) return;
5265
5298
  const remaining = descriptionIds(input).filter((value) => !owned.has(value));
@@ -5276,6 +5309,7 @@ function connect$9(host) {
5276
5309
  const errorRegion = element.querySelector(":scope > .error");
5277
5310
  const error = element.querySelector(":scope > .error > *, [slot=\"error\"], [role=\"alert\"]") ?? (errorRegion?.textContent.trim() ? errorRegion : null);
5278
5311
  if (input !== activeInput) {
5312
+ releaseInvalid();
5279
5313
  removeOwned(activeInput);
5280
5314
  activeInput = input;
5281
5315
  owned = /* @__PURE__ */ new Set();
@@ -5301,7 +5335,7 @@ function connect$9(host) {
5301
5335
  input.disabled = Boolean(host.props.disabled.value);
5302
5336
  if (input.matches("[data-ui-field-control]")) for (const value of element.querySelectorAll("[data-ui-field-value]")) value.disabled = input.disabled;
5303
5337
  input.required = Boolean(host.props.required.value);
5304
- input.setAttribute("aria-invalid", String(Boolean(host.props.invalid.value)));
5338
+ updateInvalid();
5305
5339
  };
5306
5340
  const schedule = () => {
5307
5341
  if (queued) return;
@@ -5334,6 +5368,7 @@ function connect$9(host) {
5334
5368
  return () => {
5335
5369
  stop();
5336
5370
  observer.disconnect();
5371
+ releaseInvalid();
5337
5372
  removeOwned(activeInput);
5338
5373
  };
5339
5374
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadlabs/looma",
3
- "version": "0.53.17",
3
+ "version": "0.53.18",
4
4
  "type": "module",
5
5
  "description": "HTML Next UI components, native DOM support and design tokens.",
6
6
  "license": "MIT",