@rind-ui/testing 0.4.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,6 +15,8 @@ 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;
20
22
  /** A grid cell (the roving focus target itself) holding a focusable descendant. */
@@ -1,4 +1,4 @@
1
- import { r as EnvFactory } from "./adapter-C3LQTPFi.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 };
@@ -199,6 +199,7 @@ function collectDom(arg) {
199
199
  attrs: attrsOf(el),
200
200
  hidden: !isVisible(el),
201
201
  inAriaHidden: el.closest("[aria-hidden=true]") !== null,
202
+ inCopy: el.closest("[aria-hidden=true][data-copy]") !== null,
202
203
  inInert: el.closest("[inert]") !== null,
203
204
  focusable: focusable(el),
204
205
  focusableInside: roleOf(el) === "gridcell" && [...el.querySelectorAll("*")].some(focusable),
@@ -370,6 +371,16 @@ function opensElsewhere(a, e) {
370
371
  const target = a.getAttribute("target");
371
372
  return e.type === "auxclick" || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || a.hasAttribute("download") || target !== null && target !== "" && target !== "_self";
372
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
+ }
373
384
  const intercepted = /* @__PURE__ */ new WeakSet();
374
385
  const handled = /* @__PURE__ */ new WeakSet();
375
386
  /**
@@ -386,11 +397,13 @@ function interceptNativeNavigation(win) {
386
397
  const a = anchorOf(e);
387
398
  if (!a || e.defaultPrevented || handled.has(e)) return;
388
399
  handled.add(e);
400
+ const newTab = opensElsewhere(a, e);
389
401
  navigationLog().push({
390
402
  href: a.href,
391
- newTab: opensElsewhere(a, e),
403
+ newTab,
392
404
  via: "browser"
393
405
  });
406
+ if (!newTab && samePageFragment(win, a)) return;
394
407
  e.preventDefault();
395
408
  };
396
409
  win.addEventListener("click", finish);
@@ -491,6 +504,9 @@ const KEY_NAMES = {
491
504
  ArrowRight: "{ArrowRight}",
492
505
  Backspace: "{Backspace}",
493
506
  Delete: "{Delete}",
507
+ "+": "+",
508
+ "-": "-",
509
+ "0": "0",
494
510
  F6: "{F6}",
495
511
  F10: "{F10}",
496
512
  ContextMenu: "{ContextMenu}",
@@ -536,6 +552,34 @@ function installErrorLog(win = globalThis.window ?? null) {
536
552
  }
537
553
  const isJsdom = () => (globalThis.navigator?.userAgent ?? "").includes("jsdom");
538
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
+ };
539
583
  function domEnv(options = {}) {
540
584
  const timeout = options.timeout ?? (isJsdom() ? 1e3 : 3e3);
541
585
  const doc = options.root?.ownerDocument ?? globalThis.document;
@@ -1058,6 +1102,73 @@ function createDomEnv({ scope, anchor, modality, platform, partName, anatomyName
1058
1102
  input.dispatchEvent(new InputEvent("input", init));
1059
1103
  });
1060
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
+ },
1061
1172
  async setFiles(specs) {
1062
1173
  const el = await waitFor();
1063
1174
  await act(() => {
package/dist/dom.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as UserLike, r as domEnv, t as DomAdapterOptions } from "./dom-BH8CVBb2.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-DjurZVd0.mjs";
1
+ export { t as domEnv } from "./dom-D9Da5Fku.mjs";