frontile 0.18.0-beta.5 → 0.18.1
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/declarations/components/buttons/chip.d.ts +1 -1
- package/declarations/components/buttons/chip.d.ts.map +1 -1
- package/declarations/components/collections/dropdown/menu-context.d.ts +10 -0
- package/declarations/components/collections/dropdown/menu-context.d.ts.map +1 -1
- package/declarations/components/collections/dropdown/sub.d.ts +34 -0
- package/declarations/components/collections/dropdown/sub.d.ts.map +1 -1
- package/declarations/components/forms/autocomplete.d.ts +12 -12
- package/declarations/components/forms/date-input/clipboard.d.ts +34 -0
- package/declarations/components/forms/date-input/clipboard.d.ts.map +1 -0
- package/declarations/components/forms/date-input/date-input.d.ts +91 -0
- package/declarations/components/forms/date-input/date-input.d.ts.map +1 -0
- package/declarations/components/forms/date-input/segment-group.d.ts +130 -0
- package/declarations/components/forms/date-input/segment-group.d.ts.map +1 -0
- package/declarations/components/forms/date-input/segments.d.ts +137 -0
- package/declarations/components/forms/date-input/segments.d.ts.map +1 -0
- package/declarations/components/forms/date-input/types.d.ts +134 -0
- package/declarations/components/forms/date-input/types.d.ts.map +1 -0
- package/declarations/components/forms/date-input.d.ts +6 -0
- package/declarations/components/forms/date-input.d.ts.map +1 -0
- package/declarations/components/forms/date-picker/date-picker.d.ts +248 -15
- package/declarations/components/forms/date-picker/date-picker.d.ts.map +1 -1
- package/declarations/components/forms/date-picker/end-content.d.ts +33 -3
- package/declarations/components/forms/date-picker/end-content.d.ts.map +1 -1
- package/declarations/components/forms/date-picker/types.d.ts +30 -1
- package/declarations/components/forms/date-picker/types.d.ts.map +1 -1
- package/declarations/components/forms/field.d.ts +3 -0
- package/declarations/components/forms/field.d.ts.map +1 -1
- package/declarations/components/forms/index.d.ts +1 -0
- package/declarations/components/forms/index.d.ts.map +1 -1
- package/declarations/components/forms/input.d.ts +11 -11
- package/declarations/components/forms/native-select.d.ts +8 -8
- package/declarations/components/forms/select/select.d.ts +16 -16
- package/declarations/components/forms/textarea.d.ts +7 -7
- package/declarations/components/utilities/avatar.d.ts +35 -2
- package/declarations/components/utilities/avatar.d.ts.map +1 -1
- package/declarations/test-support.d.ts +30 -0
- package/declarations/test-support.d.ts.map +1 -1
- package/dist/components/buttons/chip.js.map +1 -1
- package/dist/components/collections/dropdown/menu-context.js.map +1 -1
- package/dist/components/collections/dropdown/sub.js +76 -11
- package/dist/components/collections/dropdown/sub.js.map +1 -1
- package/dist/components/forms/date-input/clipboard.js +162 -0
- package/dist/components/forms/date-input/clipboard.js.map +1 -0
- package/dist/components/forms/date-input/date-input.js +194 -0
- package/dist/components/forms/date-input/date-input.js.map +1 -0
- package/dist/components/forms/date-input/segment-group.js +271 -0
- package/dist/components/forms/date-input/segment-group.js.map +1 -0
- package/dist/components/forms/date-input/segments.js +379 -0
- package/dist/components/forms/date-input/segments.js.map +1 -0
- package/dist/components/forms/date-input/types.js +2 -0
- package/dist/components/forms/date-input/types.js.map +1 -0
- package/dist/components/forms/date-input.js +4 -0
- package/dist/components/forms/date-input.js.map +1 -0
- package/dist/components/forms/date-picker/date-picker.js +301 -14
- package/dist/components/forms/date-picker/date-picker.js.map +1 -1
- package/dist/components/forms/date-picker/end-content.js +17 -4
- package/dist/components/forms/date-picker/end-content.js.map +1 -1
- package/dist/components/forms/field.js +4 -1
- package/dist/components/forms/field.js.map +1 -1
- package/dist/components/forms/index.js +3 -0
- package/dist/components/forms/index.js.map +1 -1
- package/dist/components/utilities/avatar.js +30 -5
- package/dist/components/utilities/avatar.js.map +1 -1
- package/dist/forms.js +3 -0
- package/dist/forms.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/test-support.js +480 -1
- package/dist/test-support.js.map +1 -1
- package/package.json +3 -3
package/dist/test-support.js
CHANGED
|
@@ -14,6 +14,7 @@ import '@ember/-internals/views';
|
|
|
14
14
|
import '@glimmer/manager';
|
|
15
15
|
import { precompileTemplate } from '@ember/template-compilation';
|
|
16
16
|
import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';
|
|
17
|
+
import { parseDate } from './components/forms/date-picker/value.js';
|
|
17
18
|
export { setPrefersReducedMotion } from './utils/prefers-reduced-motion.js';
|
|
18
19
|
|
|
19
20
|
// @ts-ignore
|
|
@@ -83,6 +84,11 @@ function isDocument(target) {
|
|
|
83
84
|
return target !== null && typeof target === 'object' && Reflect.get(target, 'nodeType') === Node.DOCUMENT_NODE;
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
// eslint-disable-next-line require-jsdoc
|
|
88
|
+
function isContentEditable(element) {
|
|
89
|
+
return 'isContentEditable' in element && element.isContentEditable;
|
|
90
|
+
}
|
|
91
|
+
|
|
86
92
|
const FORM_CONTROL_TAGS = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'];
|
|
87
93
|
/**
|
|
88
94
|
@private
|
|
@@ -95,6 +101,17 @@ function isFormControl(element) {
|
|
|
95
101
|
|
|
96
102
|
const futureTick = setTimeout;
|
|
97
103
|
|
|
104
|
+
/**
|
|
105
|
+
Returns whether the passed in string consists only of numeric characters.
|
|
106
|
+
|
|
107
|
+
@private
|
|
108
|
+
@param {string} n input string
|
|
109
|
+
@returns {boolean} whether the input string consists only of numeric characters
|
|
110
|
+
*/
|
|
111
|
+
function isNumeric(n) {
|
|
112
|
+
return !isNaN(parseFloat(n)) && isFinite(Number(n));
|
|
113
|
+
}
|
|
114
|
+
|
|
98
115
|
const TIMEOUTS = [0, 1, 2, 5, 7];
|
|
99
116
|
const MAX_TIMEOUT = 10;
|
|
100
117
|
/**
|
|
@@ -1160,6 +1177,35 @@ function buildFileEvent(type, element, options = {}) {
|
|
|
1160
1177
|
return event;
|
|
1161
1178
|
}
|
|
1162
1179
|
|
|
1180
|
+
// For reference:
|
|
1181
|
+
// https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
|
1182
|
+
const FOCUSABLE_TAGS = ['A', 'SUMMARY'];
|
|
1183
|
+
// eslint-disable-next-line require-jsdoc
|
|
1184
|
+
function isFocusableElement(element) {
|
|
1185
|
+
return FOCUSABLE_TAGS.indexOf(element.tagName) > -1;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
@private
|
|
1190
|
+
@param {Element} element the element to check
|
|
1191
|
+
@returns {boolean} `true` when the element is focusable, `false` otherwise
|
|
1192
|
+
*/
|
|
1193
|
+
function isFocusable(element) {
|
|
1194
|
+
if (isWindow(element)) {
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1197
|
+
if (isDocument(element)) {
|
|
1198
|
+
return false;
|
|
1199
|
+
}
|
|
1200
|
+
if (isFormControl(element)) {
|
|
1201
|
+
return !element.disabled;
|
|
1202
|
+
}
|
|
1203
|
+
if (isContentEditable(element) || isFocusableElement(element)) {
|
|
1204
|
+
return true;
|
|
1205
|
+
}
|
|
1206
|
+
return element.hasAttribute('tabindex');
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1163
1209
|
/**
|
|
1164
1210
|
Used internally by the DOM interaction helpers to get a description of a
|
|
1165
1211
|
target for debug/error messaging.
|
|
@@ -1181,9 +1227,153 @@ registerHook('blur', 'start', target => {
|
|
|
1181
1227
|
log('blur', target);
|
|
1182
1228
|
});
|
|
1183
1229
|
|
|
1230
|
+
/**
|
|
1231
|
+
@private
|
|
1232
|
+
@param {Element} element the element to trigger events on
|
|
1233
|
+
@param {Element} relatedTarget the element that is focused after blur
|
|
1234
|
+
@return {Promise<Event | void>} resolves when settled
|
|
1235
|
+
*/
|
|
1236
|
+
function __blur__(element, relatedTarget = null) {
|
|
1237
|
+
if (!isFocusable(element)) {
|
|
1238
|
+
throw new Error(`${element} is not focusable`);
|
|
1239
|
+
}
|
|
1240
|
+
const browserIsNotFocused = document.hasFocus && !document.hasFocus();
|
|
1241
|
+
const needsCustomEventOptions = relatedTarget !== null;
|
|
1242
|
+
if (!needsCustomEventOptions) {
|
|
1243
|
+
// makes `document.activeElement` be `body`.
|
|
1244
|
+
// If the browser is focused, it also fires a blur event
|
|
1245
|
+
element.blur();
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
// Chrome/Firefox does not trigger the `blur` event if the window
|
|
1249
|
+
// does not have focus. If the document does not have focus then
|
|
1250
|
+
// fire `blur` event via native event.
|
|
1251
|
+
const options = {
|
|
1252
|
+
relatedTarget
|
|
1253
|
+
};
|
|
1254
|
+
return browserIsNotFocused || needsCustomEventOptions ? Promise.resolve().then(() => fireEvent(element, 'blur', {
|
|
1255
|
+
bubbles: false,
|
|
1256
|
+
...options
|
|
1257
|
+
})).then(() => fireEvent(element, 'focusout', options)) : Promise.resolve();
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1184
1260
|
registerHook('focus', 'start', target => {
|
|
1185
1261
|
log('focus', target);
|
|
1186
1262
|
});
|
|
1263
|
+
/**
|
|
1264
|
+
Get the closest focusable ancestor of a given element (or the element itself
|
|
1265
|
+
if it's focusable)
|
|
1266
|
+
|
|
1267
|
+
@private
|
|
1268
|
+
@param {Element} element the element to trigger events on
|
|
1269
|
+
@returns {HTMLElement|SVGElement|null} the focusable element/ancestor or null
|
|
1270
|
+
if there is none
|
|
1271
|
+
*/
|
|
1272
|
+
function getClosestFocusable(element) {
|
|
1273
|
+
if (isDocument(element)) {
|
|
1274
|
+
return null;
|
|
1275
|
+
}
|
|
1276
|
+
let maybeFocusable = element;
|
|
1277
|
+
while (maybeFocusable && !isFocusable(maybeFocusable)) {
|
|
1278
|
+
maybeFocusable = maybeFocusable.parentElement;
|
|
1279
|
+
}
|
|
1280
|
+
return maybeFocusable;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
@private
|
|
1285
|
+
@param {Element} element the element to trigger events on
|
|
1286
|
+
@return {Promise<FocusRecord | Event | void>} resolves when settled
|
|
1287
|
+
*/
|
|
1288
|
+
function __focus__(element) {
|
|
1289
|
+
return Promise.resolve().then(() => {
|
|
1290
|
+
const focusTarget = getClosestFocusable(element);
|
|
1291
|
+
const previousFocusedElement = document.activeElement && document.activeElement !== focusTarget && isFocusable(document.activeElement) ? document.activeElement : null;
|
|
1292
|
+
|
|
1293
|
+
// fire __blur__ manually with the null relatedTarget when the target is not focusable
|
|
1294
|
+
// and there was a previously focused element
|
|
1295
|
+
return !focusTarget && previousFocusedElement ? __blur__(previousFocusedElement, null).then(() => Promise.resolve({
|
|
1296
|
+
focusTarget,
|
|
1297
|
+
previousFocusedElement
|
|
1298
|
+
})) : Promise.resolve({
|
|
1299
|
+
focusTarget,
|
|
1300
|
+
previousFocusedElement
|
|
1301
|
+
});
|
|
1302
|
+
}).then(({
|
|
1303
|
+
focusTarget,
|
|
1304
|
+
previousFocusedElement
|
|
1305
|
+
}) => {
|
|
1306
|
+
if (!focusTarget) {
|
|
1307
|
+
throw new Error('There was a previously focused element');
|
|
1308
|
+
}
|
|
1309
|
+
const browserIsNotFocused = !document?.hasFocus();
|
|
1310
|
+
|
|
1311
|
+
// fire __blur__ manually with the correct relatedTarget when the browser is not
|
|
1312
|
+
// already in focus and there was a previously focused element
|
|
1313
|
+
return previousFocusedElement && browserIsNotFocused ? __blur__(previousFocusedElement, focusTarget).then(() => Promise.resolve({
|
|
1314
|
+
focusTarget
|
|
1315
|
+
})) : Promise.resolve({
|
|
1316
|
+
focusTarget
|
|
1317
|
+
});
|
|
1318
|
+
}).then(({
|
|
1319
|
+
focusTarget
|
|
1320
|
+
}) => {
|
|
1321
|
+
// makes `document.activeElement` be `element`. If the browser is focused, it also fires a focus event
|
|
1322
|
+
focusTarget.focus();
|
|
1323
|
+
|
|
1324
|
+
// Firefox does not trigger the `focusin` event if the window
|
|
1325
|
+
// does not have focus. If the document does not have focus then
|
|
1326
|
+
// fire `focusin` event as well.
|
|
1327
|
+
const browserIsFocused = document?.hasFocus();
|
|
1328
|
+
return browserIsFocused ? Promise.resolve() :
|
|
1329
|
+
// if the browser is not focused the previous `el.focus()` didn't fire an event, so we simulate it
|
|
1330
|
+
Promise.resolve().then(() => fireEvent(focusTarget, 'focus', {
|
|
1331
|
+
bubbles: false
|
|
1332
|
+
})).then(() => fireEvent(focusTarget, 'focusin')).then(() => settled());
|
|
1333
|
+
}).catch(() => {});
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
/**
|
|
1337
|
+
Focus the specified target.
|
|
1338
|
+
|
|
1339
|
+
Sends a number of events intending to simulate a "real" user focusing an
|
|
1340
|
+
element.
|
|
1341
|
+
|
|
1342
|
+
The following events are triggered (in order):
|
|
1343
|
+
|
|
1344
|
+
- `focus`
|
|
1345
|
+
- `focusin`
|
|
1346
|
+
|
|
1347
|
+
The exact listing of events that are triggered may change over time as needed
|
|
1348
|
+
to continue to emulate how actual browsers handle focusing a given element.
|
|
1349
|
+
|
|
1350
|
+
@public
|
|
1351
|
+
@param {string|Element|IDOMElementDescriptor} target the element, selector, or descriptor to focus
|
|
1352
|
+
@return {Promise<void>} resolves when the application is settled
|
|
1353
|
+
|
|
1354
|
+
@example
|
|
1355
|
+
<caption>
|
|
1356
|
+
Emulating focusing an input using `focus`
|
|
1357
|
+
</caption>
|
|
1358
|
+
|
|
1359
|
+
focus('input');
|
|
1360
|
+
*/
|
|
1361
|
+
function focus(target) {
|
|
1362
|
+
return Promise.resolve().then(() => runHooks('focus', 'start', target)).then(() => {
|
|
1363
|
+
if (!target) {
|
|
1364
|
+
throw new Error('Must pass an element, selector, or descriptor to `focus`.');
|
|
1365
|
+
}
|
|
1366
|
+
const element = getElement(target);
|
|
1367
|
+
if (!element) {
|
|
1368
|
+
const description = getDescription(target);
|
|
1369
|
+
throw new Error(`Element not found when calling \`focus('${description}')\`.`);
|
|
1370
|
+
}
|
|
1371
|
+
if (!isFocusable(element)) {
|
|
1372
|
+
throw new Error(`${element} is not focusable`);
|
|
1373
|
+
}
|
|
1374
|
+
return __focus__(element).then(settled);
|
|
1375
|
+
}).then(() => runHooks('focus', 'end', target));
|
|
1376
|
+
}
|
|
1187
1377
|
|
|
1188
1378
|
registerHook('click', 'start', target => {
|
|
1189
1379
|
log('click', target);
|
|
@@ -1273,6 +1463,216 @@ function triggerEvent(target, eventType, options, force = false) {
|
|
|
1273
1463
|
registerHook('triggerKeyEvent', 'start', (target, eventType, key) => {
|
|
1274
1464
|
log('triggerKeyEvent', target, eventType, key);
|
|
1275
1465
|
});
|
|
1466
|
+
const DEFAULT_MODIFIERS = Object.freeze({
|
|
1467
|
+
ctrlKey: false,
|
|
1468
|
+
altKey: false,
|
|
1469
|
+
shiftKey: false,
|
|
1470
|
+
metaKey: false
|
|
1471
|
+
});
|
|
1472
|
+
|
|
1473
|
+
// This is not a comprehensive list, but it is better than nothing.
|
|
1474
|
+
const keyFromKeyCode = {
|
|
1475
|
+
8: 'Backspace',
|
|
1476
|
+
9: 'Tab',
|
|
1477
|
+
13: 'Enter',
|
|
1478
|
+
16: 'Shift',
|
|
1479
|
+
17: 'Control',
|
|
1480
|
+
18: 'Alt',
|
|
1481
|
+
20: 'CapsLock',
|
|
1482
|
+
27: 'Escape',
|
|
1483
|
+
32: ' ',
|
|
1484
|
+
37: 'ArrowLeft',
|
|
1485
|
+
38: 'ArrowUp',
|
|
1486
|
+
39: 'ArrowRight',
|
|
1487
|
+
40: 'ArrowDown',
|
|
1488
|
+
48: '0',
|
|
1489
|
+
49: '1',
|
|
1490
|
+
50: '2',
|
|
1491
|
+
51: '3',
|
|
1492
|
+
52: '4',
|
|
1493
|
+
53: '5',
|
|
1494
|
+
54: '6',
|
|
1495
|
+
55: '7',
|
|
1496
|
+
56: '8',
|
|
1497
|
+
57: '9',
|
|
1498
|
+
65: 'a',
|
|
1499
|
+
66: 'b',
|
|
1500
|
+
67: 'c',
|
|
1501
|
+
68: 'd',
|
|
1502
|
+
69: 'e',
|
|
1503
|
+
70: 'f',
|
|
1504
|
+
71: 'g',
|
|
1505
|
+
72: 'h',
|
|
1506
|
+
73: 'i',
|
|
1507
|
+
74: 'j',
|
|
1508
|
+
75: 'k',
|
|
1509
|
+
76: 'l',
|
|
1510
|
+
77: 'm',
|
|
1511
|
+
78: 'n',
|
|
1512
|
+
79: 'o',
|
|
1513
|
+
80: 'p',
|
|
1514
|
+
81: 'q',
|
|
1515
|
+
82: 'r',
|
|
1516
|
+
83: 's',
|
|
1517
|
+
84: 't',
|
|
1518
|
+
85: 'u',
|
|
1519
|
+
86: 'v',
|
|
1520
|
+
87: 'w',
|
|
1521
|
+
88: 'x',
|
|
1522
|
+
89: 'y',
|
|
1523
|
+
90: 'z',
|
|
1524
|
+
91: 'Meta',
|
|
1525
|
+
93: 'Meta',
|
|
1526
|
+
// There is two keys that map to meta,
|
|
1527
|
+
186: ';',
|
|
1528
|
+
187: '=',
|
|
1529
|
+
188: ',',
|
|
1530
|
+
189: '-',
|
|
1531
|
+
190: '.',
|
|
1532
|
+
191: '/',
|
|
1533
|
+
219: '[',
|
|
1534
|
+
220: '\\',
|
|
1535
|
+
221: ']',
|
|
1536
|
+
222: "'"
|
|
1537
|
+
};
|
|
1538
|
+
const keyFromKeyCodeWithShift = {
|
|
1539
|
+
48: ')',
|
|
1540
|
+
49: '!',
|
|
1541
|
+
50: '@',
|
|
1542
|
+
51: '#',
|
|
1543
|
+
52: '$',
|
|
1544
|
+
53: '%',
|
|
1545
|
+
54: '^',
|
|
1546
|
+
55: '&',
|
|
1547
|
+
56: '*',
|
|
1548
|
+
57: '(',
|
|
1549
|
+
186: ':',
|
|
1550
|
+
187: '+',
|
|
1551
|
+
188: '<',
|
|
1552
|
+
189: '_',
|
|
1553
|
+
190: '>',
|
|
1554
|
+
191: '?',
|
|
1555
|
+
219: '{',
|
|
1556
|
+
220: '|',
|
|
1557
|
+
221: '}',
|
|
1558
|
+
222: '"'
|
|
1559
|
+
};
|
|
1560
|
+
|
|
1561
|
+
/**
|
|
1562
|
+
Calculates the value of KeyboardEvent#key given a keycode and the modifiers.
|
|
1563
|
+
Note that this works if the key is pressed in combination with the shift key, but it cannot
|
|
1564
|
+
detect if caps lock is enabled.
|
|
1565
|
+
@param {number} keycode The keycode of the event.
|
|
1566
|
+
@param {object} modifiers The modifiers of the event.
|
|
1567
|
+
@returns {string} The key string for the event.
|
|
1568
|
+
*/
|
|
1569
|
+
function keyFromKeyCodeAndModifiers(keycode, modifiers) {
|
|
1570
|
+
if (keycode > 64 && keycode < 91) {
|
|
1571
|
+
if (modifiers.shiftKey) {
|
|
1572
|
+
return String.fromCharCode(keycode);
|
|
1573
|
+
} else {
|
|
1574
|
+
return String.fromCharCode(keycode).toLocaleLowerCase();
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
return modifiers.shiftKey && keyFromKeyCodeWithShift[keycode] || keyFromKeyCode[keycode];
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
/**
|
|
1581
|
+
* Infers the keycode from the given key
|
|
1582
|
+
* @param {string} key The KeyboardEvent#key string
|
|
1583
|
+
* @returns {number} The keycode for the given key
|
|
1584
|
+
*/
|
|
1585
|
+
function keyCodeFromKey(key) {
|
|
1586
|
+
const keys = Object.keys(keyFromKeyCode);
|
|
1587
|
+
const keyCode = keys.find(keyCode => keyFromKeyCode[Number(keyCode)] === key) || keys.find(keyCode => keyFromKeyCode[Number(keyCode)] === key.toLowerCase());
|
|
1588
|
+
return keyCode !== undefined ? parseInt(keyCode) : undefined;
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
/**
|
|
1592
|
+
@private
|
|
1593
|
+
@param {Element | Document} element the element to trigger the key event on
|
|
1594
|
+
@param {'keydown' | 'keyup' | 'keypress'} eventType the type of event to trigger
|
|
1595
|
+
@param {number|string} key the `keyCode`(number) or `key`(string) of the event being triggered
|
|
1596
|
+
@param {Object} [modifiers] the state of various modifier keys
|
|
1597
|
+
@return {Promise<Event>} resolves when settled
|
|
1598
|
+
*/
|
|
1599
|
+
function __triggerKeyEvent__(element, eventType, key, modifiers = DEFAULT_MODIFIERS) {
|
|
1600
|
+
return Promise.resolve().then(() => {
|
|
1601
|
+
let props;
|
|
1602
|
+
if (typeof key === 'number') {
|
|
1603
|
+
props = {
|
|
1604
|
+
keyCode: key,
|
|
1605
|
+
which: key,
|
|
1606
|
+
key: keyFromKeyCodeAndModifiers(key, modifiers),
|
|
1607
|
+
...modifiers
|
|
1608
|
+
};
|
|
1609
|
+
} else if (typeof key === 'string' && key.length !== 0) {
|
|
1610
|
+
const firstCharacter = key[0];
|
|
1611
|
+
if (!firstCharacter || firstCharacter !== firstCharacter.toUpperCase()) {
|
|
1612
|
+
throw new Error(`Must provide a \`key\` to \`triggerKeyEvent\` that starts with an uppercase character but you passed \`${key}\`.`);
|
|
1613
|
+
}
|
|
1614
|
+
if (isNumeric(key) && key.length > 1) {
|
|
1615
|
+
throw new Error(`Must provide a numeric \`keyCode\` to \`triggerKeyEvent\` but you passed \`${key}\` as a string.`);
|
|
1616
|
+
}
|
|
1617
|
+
const keyCode = keyCodeFromKey(key);
|
|
1618
|
+
props = {
|
|
1619
|
+
keyCode,
|
|
1620
|
+
which: keyCode,
|
|
1621
|
+
key,
|
|
1622
|
+
...modifiers
|
|
1623
|
+
};
|
|
1624
|
+
} else {
|
|
1625
|
+
throw new Error(`Must provide a \`key\` or \`keyCode\` to \`triggerKeyEvent\``);
|
|
1626
|
+
}
|
|
1627
|
+
return fireEvent(element, eventType, props);
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
Triggers a keyboard event of given type in the target element.
|
|
1633
|
+
It also requires the developer to provide either a string with the [`key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
|
|
1634
|
+
or the numeric [`keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) of the pressed key.
|
|
1635
|
+
Optionally the user can also provide a POJO with extra modifiers for the event.
|
|
1636
|
+
|
|
1637
|
+
@public
|
|
1638
|
+
@param {string|Element|IDOMElementDescriptor} target the element, selector, or descriptor to trigger the event on
|
|
1639
|
+
@param {'keydown' | 'keyup' | 'keypress'} eventType the type of event to trigger
|
|
1640
|
+
@param {number|string} key the `keyCode`(number) or `key`(string) of the event being triggered
|
|
1641
|
+
@param {Object} [modifiers] the state of various modifier keys
|
|
1642
|
+
@param {boolean} [modifiers.ctrlKey=false] if true the generated event will indicate the control key was pressed during the key event
|
|
1643
|
+
@param {boolean} [modifiers.altKey=false] if true the generated event will indicate the alt key was pressed during the key event
|
|
1644
|
+
@param {boolean} [modifiers.shiftKey=false] if true the generated event will indicate the shift key was pressed during the key event
|
|
1645
|
+
@param {boolean} [modifiers.metaKey=false] if true the generated event will indicate the meta key was pressed during the key event
|
|
1646
|
+
@return {Promise<void>} resolves when the application is settled unless awaitSettled is false
|
|
1647
|
+
|
|
1648
|
+
@example
|
|
1649
|
+
<caption>
|
|
1650
|
+
Emulating pressing the `ENTER` key on a button using `triggerKeyEvent`
|
|
1651
|
+
</caption>
|
|
1652
|
+
triggerKeyEvent('button', 'keydown', 'Enter');
|
|
1653
|
+
*/
|
|
1654
|
+
function triggerKeyEvent(target, eventType, key, modifiers = DEFAULT_MODIFIERS) {
|
|
1655
|
+
return Promise.resolve().then(() => {
|
|
1656
|
+
return runHooks('triggerKeyEvent', 'start', target, eventType, key);
|
|
1657
|
+
}).then(() => {
|
|
1658
|
+
if (!target) {
|
|
1659
|
+
throw new Error('Must pass an element, selector, or descriptor to `triggerKeyEvent`.');
|
|
1660
|
+
}
|
|
1661
|
+
const element = getElement(target);
|
|
1662
|
+
if (!element) {
|
|
1663
|
+
const description = getDescription(target);
|
|
1664
|
+
throw new Error(`Element not found when calling \`triggerKeyEvent('${description}')\`.`);
|
|
1665
|
+
}
|
|
1666
|
+
if (!isKeyboardEventType(eventType)) {
|
|
1667
|
+
const validEventTypes = KEYBOARD_EVENT_TYPES.join(', ');
|
|
1668
|
+
throw new Error(`Must provide an \`eventType\` of ${validEventTypes} to \`triggerKeyEvent\` but you passed \`${eventType}\`.`);
|
|
1669
|
+
}
|
|
1670
|
+
if (isFormControl(element) && element.disabled) {
|
|
1671
|
+
throw new Error(`Can not \`triggerKeyEvent\` on disabled ${element}`);
|
|
1672
|
+
}
|
|
1673
|
+
return __triggerKeyEvent__(element, eventType, key, modifiers).then(settled);
|
|
1674
|
+
}).then(() => runHooks('triggerKeyEvent', 'end', target, eventType, key));
|
|
1675
|
+
}
|
|
1276
1676
|
|
|
1277
1677
|
registerHook('fillIn', 'start', (target, text) => {
|
|
1278
1678
|
log('fillIn', target, text);
|
|
@@ -1350,5 +1750,84 @@ function ownParts(root, part) {
|
|
|
1350
1750
|
});
|
|
1351
1751
|
}
|
|
1352
1752
|
|
|
1353
|
-
|
|
1753
|
+
/**
|
|
1754
|
+
* Types a date into a segmented `DateInput` or `DatePicker`.
|
|
1755
|
+
*
|
|
1756
|
+
* `fillIn` cannot do this and, worse, does not fail when you try. The segments
|
|
1757
|
+
* are `contenteditable`, so `fillIn` writes their text and fires `input`
|
|
1758
|
+
* without complaint -- but the component renders from its own segments and
|
|
1759
|
+
* listens only to `beforeinput`/`keydown`, so nothing reaches the value. The
|
|
1760
|
+
* result is a test that reads green, whose `assert.dom(...).hasText('01')`
|
|
1761
|
+
* even passes, while the component's value stayed `null` and the form would
|
|
1762
|
+
* submit empty.
|
|
1763
|
+
*
|
|
1764
|
+
* This types the digits segment by segment the way a person does, so the value
|
|
1765
|
+
* composes through the same commit path as real input.
|
|
1766
|
+
*
|
|
1767
|
+
* ```js
|
|
1768
|
+
* await fillDate('[data-test-due]', '2026-01-20');
|
|
1769
|
+
* await fillDate('[data-test-due]', new Date(2026, 0, 20));
|
|
1770
|
+
* ```
|
|
1771
|
+
*
|
|
1772
|
+
* For `@mode="range"` use {@link fillDateRange}.
|
|
1773
|
+
*/
|
|
1774
|
+
function fillDate(selector, value) {
|
|
1775
|
+
return fillGroup('fillDate', selector, value, 0);
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
/**
|
|
1779
|
+
* Types both ends of a range into a segmented `DatePicker @mode="range"`.
|
|
1780
|
+
*
|
|
1781
|
+
* ```js
|
|
1782
|
+
* await fillDateRange('[data-test-trip]', '2026-01-20', '2026-01-25');
|
|
1783
|
+
* ```
|
|
1784
|
+
*/
|
|
1785
|
+
async function fillDateRange(selector, start, end) {
|
|
1786
|
+
await fillGroup('fillDateRange', selector, start, 0);
|
|
1787
|
+
await fillGroup('fillDateRange', selector, end, 1);
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
/**
|
|
1791
|
+
* Reuses the component's own parser rather than restating the wire format, so
|
|
1792
|
+
* the helper cannot drift from what `@value` actually accepts -- but turns a
|
|
1793
|
+
* refusal into a thrown error, since a test helper handed a bad date should
|
|
1794
|
+
* say so rather than quietly fill nothing.
|
|
1795
|
+
*/
|
|
1796
|
+
function asDate(functionName, value) {
|
|
1797
|
+
const parsed = parseDate(value);
|
|
1798
|
+
if (!parsed) {
|
|
1799
|
+
throw new Error(`You called "${functionName}" with "${String(value)}", which is neither a Date nor a yyyy-MM-dd string.`);
|
|
1800
|
+
}
|
|
1801
|
+
return parsed;
|
|
1802
|
+
}
|
|
1803
|
+
async function fillGroup(functionName, selector, value, which) {
|
|
1804
|
+
const container = document.querySelector(selector);
|
|
1805
|
+
if (!container) {
|
|
1806
|
+
throw new Error(`You called "${functionName}('${selector}', ...)" but no element was found using selector "${selector}".`);
|
|
1807
|
+
}
|
|
1808
|
+
const group = container.querySelectorAll('[data-part="group"]')[which];
|
|
1809
|
+
if (!group) {
|
|
1810
|
+
// Far and away the likeliest cause: the field is on the button-trigger
|
|
1811
|
+
// path, where there is nothing to type into at all.
|
|
1812
|
+
const hasButtonTrigger = container.querySelector('[data-part="input"]');
|
|
1813
|
+
throw new Error(hasButtonTrigger ? `You called "${functionName}('${selector}', ...)" on a date field rendering its button trigger, which cannot be typed into. Drop @isEditable={{false}}, or click the trigger and pick from the calendar.` : `You called "${functionName}('${selector}', ...)" but found no date segments inside "${selector}".`);
|
|
1814
|
+
}
|
|
1815
|
+
const date = asDate(functionName, value);
|
|
1816
|
+
const digits = {
|
|
1817
|
+
year: String(date.getFullYear()).padStart(4, '0'),
|
|
1818
|
+
month: String(date.getMonth() + 1).padStart(2, '0'),
|
|
1819
|
+
day: String(date.getDate()).padStart(2, '0')
|
|
1820
|
+
};
|
|
1821
|
+
for (const segment of group.querySelectorAll('[data-part="segment"]')) {
|
|
1822
|
+
const element = segment;
|
|
1823
|
+
const run = element.dataset['type'] ? digits[element.dataset['type']] : undefined;
|
|
1824
|
+
if (!run) continue;
|
|
1825
|
+
await focus(element);
|
|
1826
|
+
for (const digit of run) {
|
|
1827
|
+
await triggerKeyEvent(element, 'keydown', digit);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
export { fillDate, fillDateRange, ownParts, selectOptionByKey, toggleOptionByKey };
|
|
1354
1833
|
//# sourceMappingURL=test-support.js.map
|