@rind-ui/testing 0.3.0 → 0.5.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.
@@ -15,8 +15,12 @@ interface ElementInfo {
15
15
  /** Not visible: see `isVisible`. */
16
16
  readonly hidden: boolean;
17
17
  readonly inAriaHidden: boolean;
18
+ /** Inside a hidden copy (`aria-hidden` + `data-copy`): a Marquee's repeated content. */
19
+ readonly inCopy: boolean;
18
20
  readonly inInert: boolean;
19
21
  readonly focusable: boolean;
22
+ /** A grid cell (the roving focus target itself) holding a focusable descendant. */
23
+ readonly focusableInside: boolean;
20
24
  /** Finite animations running (or held) on the element: exit animations presence waits for. */
21
25
  readonly animations: number;
22
26
  /** Its computed style animates (a transition or animation duration above zero). */
@@ -67,7 +67,7 @@ var UntilTimeout = class extends Error {
67
67
  };
68
68
  /** Mirrors horizontal arrows for right-to-left runs; everything else is unchanged. */
69
69
  const mirror = (key, direction) => direction === "ltr" ? key : key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
70
- const describeBy = (by) => "role" in by ? `role "${by.role}"${by.name === void 0 ? "" : ` named ${JSON.stringify(String(by.name))}`}` : "label" in by ? `control labelled ${JSON.stringify(String(by.label))}` : "part" in by ? `part "${by.part}"` : `text ${JSON.stringify(String(by.text))}`;
70
+ const describeBy = (by) => "role" in by ? `role "${[by.role].flat().join(" | ")}"${by.name === void 0 ? "" : ` named ${JSON.stringify(String(by.name))}`}` : "label" in by ? `control labelled ${JSON.stringify(String(by.label))}` : "part" in by ? `part "${by.part}"` : `text ${JSON.stringify(String(by.text))}`;
71
71
  //#endregion
72
72
  //#region src/adapters/compose.ts
73
73
  /**
@@ -1,4 +1,4 @@
1
- import { r as EnvFactory } from "./adapter-B05M46SW.mjs";
1
+ import { r as EnvFactory } from "./adapter-BcAjuBjR.mjs";
2
2
  //#region src/adapters/dom.d.ts
3
3
  /** The overlap of user-event's API and Vitest browser mode's `userEvent`. */
4
4
  interface UserLike {
@@ -31,7 +31,6 @@ interface DomAdapterOptions {
31
31
  */
32
32
  readonly timeout?: number;
33
33
  }
34
- /** The Testing Library adapter. */
35
34
  declare function domEnv(options?: DomAdapterOptions): EnvFactory;
36
35
  //#endregion
37
36
  export { UserLike as n, domEnv as r, DomAdapterOptions as t };
@@ -1,4 +1,4 @@
1
- import { c as renamedSnapshot, r as describeBy, s as poll, t as composeInPage } from "./compose-BpR_PG11.mjs";
1
+ import { c as renamedSnapshot, r as describeBy, s as poll, t as composeInPage } from "./compose-m76ER6GL.mjs";
2
2
  import { ANNOUNCEMENTS, KEY_DEBOUNCE_MS, PENDING_ANNOUNCEMENTS, isKeptVisible, tabbables } from "@rind-ui/core";
3
3
  import { computeAccessibleDescription, computeAccessibleName } from "dom-accessibility-api";
4
4
  //#region src/announcements.ts
@@ -166,7 +166,16 @@ function collectDom(arg) {
166
166
  const groupOf = (el) => {
167
167
  const parent = el.parentElement;
168
168
  if (!parents.has(parent)) parents.set(parent, parents.size);
169
- return `${parents.get(parent)}|${el.getAttribute("aria-level") ?? ""}`;
169
+ const level = el.getAttribute("aria-level");
170
+ let owner = "";
171
+ if (level !== null) for (let p = el.previousElementSibling; p; p = p.previousElementSibling) {
172
+ const l = p.getAttribute("aria-level");
173
+ if (l !== null && Number(l) < Number(level)) {
174
+ owner = p.id;
175
+ break;
176
+ }
177
+ }
178
+ return `${parents.get(parent)}|${level ?? ""}|${owner}`;
170
179
  };
171
180
  const own = (el) => el.getAttribute("data-instance") === arg.instance && el.getAttribute("data-scope") === arg.scope;
172
181
  const info = (el) => ({
@@ -190,8 +199,10 @@ function collectDom(arg) {
190
199
  attrs: attrsOf(el),
191
200
  hidden: !isVisible(el),
192
201
  inAriaHidden: el.closest("[aria-hidden=true]") !== null,
202
+ inCopy: el.closest("[aria-hidden=true][data-copy]") !== null,
193
203
  inInert: el.closest("[inert]") !== null,
194
204
  focusable: focusable(el),
205
+ focusableInside: roleOf(el) === "gridcell" && [...el.querySelectorAll("*")].some(focusable),
195
206
  animations: typeof el.getAnimations === "function" ? el.getAnimations().filter((a) => (a.playState === "running" || a.playState === "paused") && a.effect?.getComputedTiming().endTime !== Number.POSITIVE_INFINITY).length : 0,
196
207
  motion: hasMotion(el),
197
208
  group: groupOf(el),
@@ -247,6 +258,7 @@ function collectDom(arg) {
247
258
  if (partEls.length === 0 && doc.body) for (const el of Array.from(doc.body.querySelectorAll("*"))) record(el);
248
259
  const active = doc.activeElement;
249
260
  const activePart = active?.closest(selector);
261
+ const inControlled = active != null && elements.some((el) => (el.getAttribute("aria-controls") ?? "").split(/\s+/).filter(Boolean).some((id) => doc.getElementById(id)?.contains(active) === true));
250
262
  const fieldRoot = partEls[0]?.closest("[data-scope=\"field\"][data-part=\"root\"]") ?? null;
251
263
  const fieldPart = (part) => fieldRoot ? Array.from(doc.querySelectorAll(`[data-scope="field"][data-part="${part}"][data-instance="${fieldRoot.getAttribute("data-instance")}"]`)) : [];
252
264
  const fieldLabel = fieldPart("label")[0];
@@ -267,7 +279,7 @@ function collectDom(arg) {
267
279
  focus: {
268
280
  onBody: active === null || active === doc.body,
269
281
  part: activePart?.getAttribute("data-part") ?? null,
270
- inInstance: activePart != null,
282
+ inInstance: activePart != null || inControlled,
271
283
  element: active && active !== doc.body ? info(active) : null
272
284
  },
273
285
  html: attrsOf(doc.documentElement),
@@ -359,6 +371,16 @@ function opensElsewhere(a, e) {
359
371
  const target = a.getAttribute("target");
360
372
  return e.type === "auxclick" || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || a.hasAttribute("download") || target !== null && target !== "" && target !== "_self";
361
373
  }
374
+ /** `a` points at an element of the current document (only the hash differs, and it exists). */
375
+ function samePageFragment(win, a) {
376
+ const here = new URL(win.location.href);
377
+ const to = new URL(a.href, here);
378
+ here.hash = "";
379
+ const hash = to.hash;
380
+ to.hash = "";
381
+ if (hash === "" || to.href !== here.href) return false;
382
+ return win.document.getElementById(decodeURIComponent(hash.slice(1))) !== null;
383
+ }
362
384
  const intercepted = /* @__PURE__ */ new WeakSet();
363
385
  const handled = /* @__PURE__ */ new WeakSet();
364
386
  /**
@@ -375,11 +397,13 @@ function interceptNativeNavigation(win) {
375
397
  const a = anchorOf(e);
376
398
  if (!a || e.defaultPrevented || handled.has(e)) return;
377
399
  handled.add(e);
400
+ const newTab = opensElsewhere(a, e);
378
401
  navigationLog().push({
379
402
  href: a.href,
380
- newTab: opensElsewhere(a, e),
403
+ newTab,
381
404
  via: "browser"
382
405
  });
406
+ if (!newTab && samePageFragment(win, a)) return;
383
407
  e.preventDefault();
384
408
  };
385
409
  win.addEventListener("click", finish);
@@ -480,6 +504,9 @@ const KEY_NAMES = {
480
504
  ArrowRight: "{ArrowRight}",
481
505
  Backspace: "{Backspace}",
482
506
  Delete: "{Delete}",
507
+ "+": "+",
508
+ "-": "-",
509
+ "0": "0",
483
510
  F6: "{F6}",
484
511
  F10: "{F10}",
485
512
  ContextMenu: "{ContextMenu}",
@@ -525,6 +552,34 @@ function installErrorLog(win = globalThis.window ?? null) {
525
552
  }
526
553
  const isJsdom = () => (globalThis.navigator?.userAgent ?? "").includes("jsdom");
527
554
  /** The Testing Library adapter. */
555
+ /** A data transfer holding `files`: the real one where it exists, else a reader of the same shape. */
556
+ const transferOf = (win, files) => {
557
+ if (typeof win.DataTransfer === "function") {
558
+ const dt = new win.DataTransfer();
559
+ for (const f of files) dt.items.add(f);
560
+ return dt;
561
+ }
562
+ return {
563
+ types: files.length ? ["Files"] : [],
564
+ files,
565
+ items: files.map((f) => ({
566
+ kind: "file",
567
+ type: f.type,
568
+ getAsFile: () => f
569
+ })),
570
+ dropEffect: "none",
571
+ getData: () => ""
572
+ };
573
+ };
574
+ const fire = (el, type, data) => {
575
+ const e = new Event(type, {
576
+ bubbles: true,
577
+ cancelable: true,
578
+ composed: true
579
+ });
580
+ Object.defineProperty(e, type === "paste" ? "clipboardData" : "dataTransfer", { value: data });
581
+ el.dispatchEvent(e);
582
+ };
528
583
  function domEnv(options = {}) {
529
584
  const timeout = options.timeout ?? (isJsdom() ? 1e3 : 3e3);
530
585
  const doc = options.root?.ownerDocument ?? globalThis.document;
@@ -596,7 +651,7 @@ function createDomEnv({ scope, anchor, modality, platform, partName, anatomyName
596
651
  if ("role" in by) {
597
652
  const { queryAllByRole } = await loadTL();
598
653
  const name = by.name;
599
- return queryAllByRole(within, by.role, { ...name === void 0 ? {} : { name: typeof name === "string" ? (n) => normalize(n) === name : name } });
654
+ return [...new Set([by.role].flat().flatMap((role) => queryAllByRole(within, role, { ...name === void 0 ? {} : { name: typeof name === "string" ? (n) => normalize(n) === name : name } })))].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
600
655
  }
601
656
  if ("label" in by) {
602
657
  const { queryAllByLabelText } = await loadTL();
@@ -1047,6 +1102,93 @@ function createDomEnv({ scope, anchor, modality, platform, partName, anatomyName
1047
1102
  input.dispatchEvent(new InputEvent("input", init));
1048
1103
  });
1049
1104
  },
1105
+ async copySelection() {
1106
+ const el = await waitFor();
1107
+ await act(() => {
1108
+ const copy = typeof ClipboardEvent === "function" ? new ClipboardEvent("copy", {
1109
+ bubbles: true,
1110
+ cancelable: true,
1111
+ composed: true
1112
+ }) : new Event("copy", {
1113
+ bubbles: true,
1114
+ cancelable: true,
1115
+ composed: true
1116
+ });
1117
+ el.dispatchEvent(copy);
1118
+ });
1119
+ },
1120
+ async selectRange(start, end) {
1121
+ const el = await waitFor();
1122
+ await act(() => {
1123
+ el.setSelectionRange(start, end);
1124
+ el.dispatchEvent(new Event("select", { bubbles: true }));
1125
+ });
1126
+ },
1127
+ async dropFiles(specs) {
1128
+ const el = await waitFor();
1129
+ await act(async () => {
1130
+ const win = el.ownerDocument.defaultView;
1131
+ const files = specs.map((f) => new win.File([f.content], f.name, { type: f.type }));
1132
+ const data = transferOf(win, files);
1133
+ fire(el, "dragenter", data);
1134
+ fire(el, "dragover", data);
1135
+ fire(el, "drop", data);
1136
+ for (let i = 0; i < 20; i++) await Promise.resolve();
1137
+ });
1138
+ },
1139
+ async pasteFiles(specs) {
1140
+ const el = await waitFor();
1141
+ await act(async () => {
1142
+ const win = el.ownerDocument.defaultView;
1143
+ const files = specs.map((f) => new win.File([f.content], f.name, { type: f.type }));
1144
+ fire(el, "paste", transferOf(win, files));
1145
+ });
1146
+ },
1147
+ async wheel(deltaY) {
1148
+ const el = await waitFor();
1149
+ await act(async () => {
1150
+ const win = el.ownerDocument.defaultView;
1151
+ const e = new win.WheelEvent("wheel", {
1152
+ deltaY,
1153
+ bubbles: true,
1154
+ cancelable: true
1155
+ });
1156
+ el.dispatchEvent(e);
1157
+ if (!e.defaultPrevented) el.scrollTop += deltaY;
1158
+ await new Promise((r) => win.requestAnimationFrame(() => r()));
1159
+ });
1160
+ },
1161
+ async dragFiles(phase) {
1162
+ const el = await waitFor();
1163
+ await act(() => {
1164
+ const win = el.ownerDocument.defaultView;
1165
+ const data = transferOf(win, [new win.File(["x"], "drag.txt", { type: "text/plain" })]);
1166
+ if (phase === "enter") {
1167
+ fire(el, "dragenter", data);
1168
+ fire(el, "dragover", data);
1169
+ } else fire(el, "dragleave", data);
1170
+ });
1171
+ },
1172
+ async setFiles(specs) {
1173
+ const el = await waitFor();
1174
+ await act(() => {
1175
+ const input = el;
1176
+ const files = specs.map((f) => new File([f.content], f.name, { type: f.type }));
1177
+ if (typeof DataTransfer === "function") {
1178
+ const dt = new DataTransfer();
1179
+ for (const f of files) dt.items.add(f);
1180
+ input.files = dt.files;
1181
+ } else {
1182
+ const list = Object.assign([...files], { item: (i) => files[i] ?? null });
1183
+ Object.defineProperty(input, "files", {
1184
+ configurable: true,
1185
+ value: list
1186
+ });
1187
+ }
1188
+ input.dispatchEvent(new Event("input", { bubbles: true }));
1189
+ input.dispatchEvent(new Event("change", { bubbles: true }));
1190
+ });
1191
+ },
1050
1192
  waitForDetach: async () => {
1051
1193
  await until(async () => (await resolve()).length, (n) => n === 0);
1052
1194
  },
package/dist/dom.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as UserLike, r as domEnv, t as DomAdapterOptions } from "./dom-Ur_VPlTe.mjs";
1
+ import { n as UserLike, r as domEnv, t as DomAdapterOptions } from "./dom-BLTLsBAu.mjs";
2
2
  export { type DomAdapterOptions, type UserLike, domEnv };
package/dist/dom.mjs CHANGED
@@ -1 +1 @@
1
- export { t as domEnv } from "./dom-Bnnr_fg-.mjs";
1
+ export { t as domEnv } from "./dom-D9Da5Fku.mjs";