@testing-library/user-event 14.0.0-beta.11 → 14.0.0-beta.12

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/dist/index.cjs CHANGED
@@ -1352,6 +1352,7 @@ var eventMap = __spreadProps(__spreadValues({}, import_event_map.eventMap), {
1352
1352
  defaultInit: { bubbles: true, cancelable: true, composed: true }
1353
1353
  }
1354
1354
  });
1355
+ var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
1355
1356
 
1356
1357
  // src/event/eventTypes.ts
1357
1358
  var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
@@ -1369,8 +1370,7 @@ function isKeyboardEvent(type3) {
1369
1370
 
1370
1371
  // src/event/createEvent.ts
1371
1372
  function createEvent(type3, target, init) {
1372
- const eventKey = Object.keys(eventMap).find((k) => k.toLowerCase() === type3);
1373
- const event = (0, import_dom2.createEvent)(type3, target, init, eventMap[eventKey]);
1373
+ const event = (0, import_dom2.createEvent)(type3, target, init, eventMap[eventMapKeys[type3]]);
1374
1374
  if (isMouseEvent(type3) && init) {
1375
1375
  assignPositionInit(event, init);
1376
1376
  assignPointerInit(event, init);
@@ -1439,6 +1439,15 @@ behavior.click = (event, target, config) => {
1439
1439
  }
1440
1440
  };
1441
1441
 
1442
+ // src/event/behavior/cut.ts
1443
+ behavior.cut = (event, target, config) => {
1444
+ return () => {
1445
+ if (isEditable(target)) {
1446
+ input(config, target, "", "deleteByCut");
1447
+ }
1448
+ };
1449
+ };
1450
+
1442
1451
  // src/event/behavior/keydown.ts
1443
1452
  behavior.keydown = (event, target, config) => {
1444
1453
  var _a, _b;
@@ -1568,6 +1577,19 @@ var keyupBehavior = {
1568
1577
  }
1569
1578
  };
1570
1579
 
1580
+ // src/event/behavior/paste.ts
1581
+ behavior.paste = (event, target, config) => {
1582
+ if (isEditable(target)) {
1583
+ return () => {
1584
+ var _a;
1585
+ const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
1586
+ if (insertData) {
1587
+ input(config, target, insertData, "insertFromPaste");
1588
+ }
1589
+ };
1590
+ }
1591
+ };
1592
+
1571
1593
  // src/event/wrapEvent.ts
1572
1594
  var import_dom3 = require("@testing-library/dom");
1573
1595
  function wrapEvent(cb, _element) {
@@ -2502,10 +2524,9 @@ async function copy() {
2502
2524
  if (clipboardData.items.length === 0) {
2503
2525
  return;
2504
2526
  }
2505
- this.dispatchUIEvent(target, "copy", {
2527
+ if (this.dispatchUIEvent(target, "copy", {
2506
2528
  clipboardData
2507
- });
2508
- if (this[Config].writeToClipboard) {
2529
+ }) && this[Config].writeToClipboard) {
2509
2530
  await writeDataTransferToClipboard(doc, clipboardData);
2510
2531
  }
2511
2532
  return clipboardData;
@@ -2520,14 +2541,10 @@ async function cut() {
2520
2541
  if (clipboardData.items.length === 0) {
2521
2542
  return;
2522
2543
  }
2523
- this.dispatchUIEvent(target, "cut", {
2544
+ if (this.dispatchUIEvent(target, "cut", {
2524
2545
  clipboardData
2525
- });
2526
- if (isEditable(target)) {
2527
- input(this[Config], target, "", "deleteByCut");
2528
- }
2529
- if (this[Config].writeToClipboard) {
2530
- await writeDataTransferToClipboard(doc, clipboardData);
2546
+ }) && this[Config].writeToClipboard) {
2547
+ await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
2531
2548
  }
2532
2549
  return clipboardData;
2533
2550
  }
@@ -2543,9 +2560,6 @@ async function paste(clipboardData) {
2543
2560
  this.dispatchUIEvent(target, "paste", {
2544
2561
  clipboardData: dataTransfer
2545
2562
  });
2546
- if (isEditable(target)) {
2547
- input(this[Config], target, dataTransfer.getData("text"), "insertFromPaste");
2548
- }
2549
2563
  }
2550
2564
  function getClipboardDataFromString(text) {
2551
2565
  const dt = createDataTransfer();
package/dist/index.mjs CHANGED
@@ -1364,6 +1364,7 @@ var eventMap = __spreadProps(__spreadValues({}, baseEventMap), {
1364
1364
  defaultInit: { bubbles: true, cancelable: true, composed: true }
1365
1365
  }
1366
1366
  });
1367
+ var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
1367
1368
 
1368
1369
  // src/event/eventTypes.ts
1369
1370
  import { eventMap as eventMap2 } from "@testing-library/dom/dist/event-map.js";
@@ -1381,8 +1382,7 @@ function isKeyboardEvent(type3) {
1381
1382
 
1382
1383
  // src/event/createEvent.ts
1383
1384
  function createEvent(type3, target, init) {
1384
- const eventKey = Object.keys(eventMap).find((k) => k.toLowerCase() === type3);
1385
- const event = createEventBase(type3, target, init, eventMap[eventKey]);
1385
+ const event = createEventBase(type3, target, init, eventMap[eventMapKeys[type3]]);
1386
1386
  if (isMouseEvent(type3) && init) {
1387
1387
  assignPositionInit(event, init);
1388
1388
  assignPointerInit(event, init);
@@ -1451,6 +1451,15 @@ behavior.click = (event, target, config) => {
1451
1451
  }
1452
1452
  };
1453
1453
 
1454
+ // src/event/behavior/cut.ts
1455
+ behavior.cut = (event, target, config) => {
1456
+ return () => {
1457
+ if (isEditable(target)) {
1458
+ input(config, target, "", "deleteByCut");
1459
+ }
1460
+ };
1461
+ };
1462
+
1454
1463
  // src/event/behavior/keydown.ts
1455
1464
  behavior.keydown = (event, target, config) => {
1456
1465
  var _a, _b;
@@ -1580,6 +1589,19 @@ var keyupBehavior = {
1580
1589
  }
1581
1590
  };
1582
1591
 
1592
+ // src/event/behavior/paste.ts
1593
+ behavior.paste = (event, target, config) => {
1594
+ if (isEditable(target)) {
1595
+ return () => {
1596
+ var _a;
1597
+ const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
1598
+ if (insertData) {
1599
+ input(config, target, insertData, "insertFromPaste");
1600
+ }
1601
+ };
1602
+ }
1603
+ };
1604
+
1583
1605
  // src/event/wrapEvent.ts
1584
1606
  import { getConfig as getConfig2 } from "@testing-library/dom";
1585
1607
  function wrapEvent(cb, _element) {
@@ -2549,10 +2571,9 @@ function copy() {
2549
2571
  if (clipboardData.items.length === 0) {
2550
2572
  return;
2551
2573
  }
2552
- this.dispatchUIEvent(target, "copy", {
2574
+ if (this.dispatchUIEvent(target, "copy", {
2553
2575
  clipboardData
2554
- });
2555
- if (this[Config].writeToClipboard) {
2576
+ }) && this[Config].writeToClipboard) {
2556
2577
  yield writeDataTransferToClipboard(doc, clipboardData);
2557
2578
  }
2558
2579
  return clipboardData;
@@ -2569,14 +2590,10 @@ function cut() {
2569
2590
  if (clipboardData.items.length === 0) {
2570
2591
  return;
2571
2592
  }
2572
- this.dispatchUIEvent(target, "cut", {
2593
+ if (this.dispatchUIEvent(target, "cut", {
2573
2594
  clipboardData
2574
- });
2575
- if (isEditable(target)) {
2576
- input(this[Config], target, "", "deleteByCut");
2577
- }
2578
- if (this[Config].writeToClipboard) {
2579
- yield writeDataTransferToClipboard(doc, clipboardData);
2595
+ }) && this[Config].writeToClipboard) {
2596
+ yield writeDataTransferToClipboard(target.ownerDocument, clipboardData);
2580
2597
  }
2581
2598
  return clipboardData;
2582
2599
  });
@@ -2594,9 +2611,6 @@ function paste(clipboardData) {
2594
2611
  this.dispatchUIEvent(target, "paste", {
2595
2612
  clipboardData: dataTransfer
2596
2613
  });
2597
- if (isEditable(target)) {
2598
- input(this[Config], target, dataTransfer.getData("text"), "insertFromPaste");
2599
- }
2600
2614
  });
2601
2615
  }
2602
2616
  function getClipboardDataFromString(text) {
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,8 @@
1
1
  import './click';
2
+ import './cut';
2
3
  import './keydown';
3
4
  import './keypress';
4
5
  import './keyup';
6
+ import './paste';
5
7
  export { behavior } from './registry';
6
8
  export type { BehaviorPlugin } from './registry';
@@ -0,0 +1 @@
1
+ export {};
@@ -340,3 +340,6 @@ export declare const eventMap: {
340
340
  defaultInit: EventInit;
341
341
  };
342
342
  };
343
+ export declare const eventMapKeys: {
344
+ [k in keyof DocumentEventMap]?: keyof typeof eventMap;
345
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.0.0-beta.11",
3
+ "version": "14.0.0-beta.12",
4
4
  "description": "Fire events the same way the user does",
5
5
  "keywords": [
6
6
  "react-testing-library",