Version 1.0.2 mit node_modules Verzeichnis

This commit is contained in:
ISA
2024-10-02 07:58:24 +02:00
parent f353a06b1b
commit 62b6e55a0a
68228 changed files with 4548477 additions and 651 deletions

View File

@@ -0,0 +1,35 @@
import '../event/behavior/click.js';
import '../event/behavior/cut.js';
import '../event/behavior/keydown.js';
import '../event/behavior/keypress.js';
import '../event/behavior/keyup.js';
import '../event/behavior/paste.js';
import '@testing-library/dom';
import '../utils/click/isClickableInput.js';
import '../utils/dataTransfer/Clipboard.js';
import { isEditable } from '../utils/edit/isEditable.js';
import '../utils/edit/maxLength.js';
import { isDisabled } from '../utils/misc/isDisabled.js';
import '../utils/keyDef/readNextDescriptor.js';
import '../utils/misc/level.js';
import '../options.js';
import { focusElement } from '../event/focus.js';
import { input } from '../event/input.js';
import { selectAll, isAllSelected } from '../event/selection/selectAll.js';
async function clear(element) {
if (!isEditable(element) || isDisabled(element)) {
throw new Error('clear()` is only supported on editable elements.');
}
focusElement(element);
if (element.ownerDocument.activeElement !== element) {
throw new Error('The element to be cleared could not be focused.');
}
selectAll(element);
if (!isAllSelected(element)) {
throw new Error('The element content to be cleared could not be selected.');
}
input(this, element, '', 'deleteContentBackward');
}
export { clear };

View File

@@ -0,0 +1,4 @@
export { clear } from './clear.js';
export { deselectOptions, selectOptions } from './selectOptions.js';
export { type } from './type.js';
export { upload } from './upload.js';

View File

@@ -0,0 +1,116 @@
import { getConfig } from '@testing-library/dom';
import '../utils/click/isClickableInput.js';
import '../utils/dataTransfer/Clipboard.js';
import '../utils/edit/isEditable.js';
import '../utils/edit/maxLength.js';
import { isElementType } from '../utils/misc/isElementType.js';
import { isDisabled } from '../utils/misc/isDisabled.js';
import '../utils/keyDef/readNextDescriptor.js';
import '../utils/misc/level.js';
import { wait } from '../utils/misc/wait.js';
import { hasPointerEvents } from '../utils/pointer/cssPointerEvents.js';
import '../event/behavior/click.js';
import '../event/behavior/cut.js';
import '../event/behavior/keydown.js';
import '../event/behavior/keypress.js';
import '../event/behavior/keyup.js';
import '../event/behavior/paste.js';
import { focusElement } from '../event/focus.js';
async function selectOptions(select, values) {
return selectOptionsBase.call(this, true, select, values);
}
async function deselectOptions(select, values) {
return selectOptionsBase.call(this, false, select, values);
}
async function selectOptionsBase(newValue, select, values) {
if (!newValue && !select.multiple) {
throw getConfig().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
}
const valArray = Array.isArray(values) ? values : [
values
];
const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
const selectedOptions = valArray.map((val)=>{
if (typeof val !== 'string' && allOptions.includes(val)) {
return val;
} else {
const matchingOption = allOptions.find((o)=>o.value === val || o.innerHTML === val);
if (matchingOption) {
return matchingOption;
} else {
throw getConfig().getElementError(`Value "${String(val)}" not found in options`, select);
}
}
}).filter((option)=>!isDisabled(option));
if (isDisabled(select) || !selectedOptions.length) return;
const selectOption = (option)=>{
option.selected = newValue;
this.dispatchUIEvent(select, 'input', {
bubbles: true,
cancelable: false,
composed: true
});
this.dispatchUIEvent(select, 'change');
};
if (isElementType(select, 'select')) {
if (select.multiple) {
for (const option of selectedOptions){
const withPointerEvents = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, option);
// events fired for multiple select are weird. Can't use hover...
if (withPointerEvents) {
this.dispatchUIEvent(option, 'pointerover');
this.dispatchUIEvent(select, 'pointerenter');
this.dispatchUIEvent(option, 'mouseover');
this.dispatchUIEvent(select, 'mouseenter');
this.dispatchUIEvent(option, 'pointermove');
this.dispatchUIEvent(option, 'mousemove');
this.dispatchUIEvent(option, 'pointerdown');
this.dispatchUIEvent(option, 'mousedown');
}
focusElement(select);
if (withPointerEvents) {
this.dispatchUIEvent(option, 'pointerup');
this.dispatchUIEvent(option, 'mouseup');
}
selectOption(option);
if (withPointerEvents) {
this.dispatchUIEvent(option, 'click');
}
await wait(this.config);
}
} else if (selectedOptions.length === 1) {
const withPointerEvents = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, select);
// the click to open the select options
if (withPointerEvents) {
await this.click(select);
} else {
focusElement(select);
}
selectOption(selectedOptions[0]);
if (withPointerEvents) {
// the browser triggers another click event on the select for the click on the option
// this second click has no 'down' phase
this.dispatchUIEvent(select, 'pointerover');
this.dispatchUIEvent(select, 'pointerenter');
this.dispatchUIEvent(select, 'mouseover');
this.dispatchUIEvent(select, 'mouseenter');
this.dispatchUIEvent(select, 'pointerup');
this.dispatchUIEvent(select, 'mouseup');
this.dispatchUIEvent(select, 'click');
}
await wait(this.config);
} else {
throw getConfig().getElementError(`Cannot select multiple options on a non-multiple select`, select);
}
} else if (select.getAttribute('role') === 'listbox') {
for (const option of selectedOptions){
await this.click(option);
await this.unhover(option);
}
} else {
throw getConfig().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
}
}
export { deselectOptions, selectOptions };

View File

@@ -0,0 +1,27 @@
import { releaseAllKeys } from '../keyboard/index.js';
import '../utils/click/isClickableInput.js';
import '../utils/dataTransfer/Clipboard.js';
import '../utils/edit/isEditable.js';
import '../utils/edit/maxLength.js';
import '../utils/keyDef/readNextDescriptor.js';
import '../utils/misc/level.js';
import '../options.js';
import { setSelectionRange } from '../event/selection/setSelectionRange.js';
async function type(element, text, { skipClick = this.config.skipClick, skipAutoClose = this.config.skipAutoClose, initialSelectionStart, initialSelectionEnd } = {}) {
// TODO: properly type guard
// we use this workaround for now to prevent changing behavior
if (element.disabled) return;
if (!skipClick) {
await this.click(element);
}
if (initialSelectionStart !== undefined) {
setSelectionRange(element, initialSelectionStart, initialSelectionEnd !== null && initialSelectionEnd !== void 0 ? initialSelectionEnd : initialSelectionStart);
}
await this.keyboard(text);
if (!skipAutoClose) {
await releaseAllKeys(this);
}
}
export { type };

View File

@@ -0,0 +1,62 @@
import '../utils/click/isClickableInput.js';
import { createFileList } from '../utils/dataTransfer/FileList.js';
import '../utils/dataTransfer/Clipboard.js';
import '../utils/edit/isEditable.js';
import '../utils/edit/maxLength.js';
import { setFiles } from '../utils/edit/setFiles.js';
import { isElementType } from '../utils/misc/isElementType.js';
import { isDisabled } from '../utils/misc/isDisabled.js';
import { getWindow } from '../utils/misc/getWindow.js';
import '../utils/keyDef/readNextDescriptor.js';
import '../utils/misc/level.js';
import '../options.js';
async function upload(element, fileOrFiles) {
const input = isElementType(element, 'label') ? element.control : element;
if (!input || !isElementType(input, 'input', {
type: 'file'
})) {
throw new TypeError(`The ${input === element ? 'given' : 'associated'} ${input === null || input === void 0 ? void 0 : input.tagName} element does not accept file uploads`);
}
if (isDisabled(element)) return;
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [
fileOrFiles
]).filter((file)=>!this.config.applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1);
const fileDialog = ()=>{
var _input_files;
// do not fire an input event if the file selection does not change
if (files.length === ((_input_files = input.files) === null || _input_files === void 0 ? void 0 : _input_files.length) && files.every((f, i)=>{
var _input_files;
return f === ((_input_files = input.files) === null || _input_files === void 0 ? void 0 : _input_files.item(i));
})) {
return;
}
setFiles(input, createFileList(getWindow(element), files));
this.dispatchUIEvent(input, 'input');
this.dispatchUIEvent(input, 'change');
};
input.addEventListener('fileDialog', fileDialog);
await this.click(element);
input.removeEventListener('fileDialog', fileDialog);
}
function isAcceptableFile(file, accept) {
if (!accept) {
return true;
}
const wildcards = [
'audio/*',
'image/*',
'video/*'
];
return accept.split(',').some((acceptToken)=>{
if (acceptToken.startsWith('.')) {
// tokens starting with a dot represent a file extension
return file.name.endsWith(acceptToken);
} else if (wildcards.includes(acceptToken)) {
return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
}
return file.type === acceptToken;
});
}
export { upload };