@testing-library/user-event
Advanced tools
Comparing version 14.4.2 to 14.4.3
@@ -5,24 +5,14 @@ 'use strict'; | ||
require('../setup/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
var Clipboard = require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
var copySelection = require('../utils/focus/copySelection.js'); | ||
require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../utils/misc/level.js'); | ||
require('../options.js'); | ||
var config = require('../setup/config.js'); | ||
var copySelection = require('../document/copySelection.js'); | ||
async function copy() { | ||
const doc = this[config.Config].document; | ||
const doc = this.config.document; | ||
var _activeElement; | ||
@@ -36,3 +26,3 @@ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body; | ||
clipboardData | ||
}) && this[config.Config].writeToClipboard) { | ||
}) && this.config.writeToClipboard) { | ||
await Clipboard.writeDataTransferToClipboard(doc, clipboardData); | ||
@@ -39,0 +29,0 @@ } |
@@ -5,24 +5,14 @@ 'use strict'; | ||
require('../setup/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
var Clipboard = require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
var copySelection = require('../utils/focus/copySelection.js'); | ||
require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../utils/misc/level.js'); | ||
require('../options.js'); | ||
var config = require('../setup/config.js'); | ||
var copySelection = require('../document/copySelection.js'); | ||
async function cut() { | ||
const doc = this[config.Config].document; | ||
const doc = this.config.document; | ||
var _activeElement; | ||
@@ -36,3 +26,3 @@ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body; | ||
clipboardData | ||
}) && this[config.Config].writeToClipboard) { | ||
}) && this.config.writeToClipboard) { | ||
await Clipboard.writeDataTransferToClipboard(target.ownerDocument, clipboardData); | ||
@@ -39,0 +29,0 @@ } |
@@ -5,16 +5,7 @@ 'use strict'; | ||
require('../setup/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
var DataTransfer = require('../utils/dataTransfer/DataTransfer.js'); | ||
var Clipboard = require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
var getWindow = require('../utils/misc/getWindow.js'); | ||
@@ -24,6 +15,5 @@ require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../options.js'); | ||
var config = require('../setup/config.js'); | ||
async function paste(clipboardData) { | ||
const doc = this[config.Config].document; | ||
const doc = this.config.document; | ||
var _activeElement; | ||
@@ -30,0 +20,0 @@ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body; |
@@ -5,8 +5,5 @@ 'use strict'; | ||
require('../setup/index.js'); | ||
var config = require('../setup/config.js'); | ||
async function click(element) { | ||
const pointerIn = []; | ||
if (!this[config.Config].skipHover) { | ||
if (!this.config.skipHover) { | ||
pointerIn.push({ | ||
@@ -13,0 +10,0 @@ target: element |
@@ -5,15 +5,6 @@ 'use strict'; | ||
require('../setup/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -23,3 +14,2 @@ require('../utils/keyDef/readNextDescriptor.js'); | ||
var cssPointerEvents = require('../utils/pointer/cssPointerEvents.js'); | ||
var config = require('../setup/config.js'); | ||
@@ -32,3 +22,3 @@ async function hover(element) { | ||
async function unhover(element) { | ||
cssPointerEvents.assertPointerEvents(this[config.Config], this[config.Config].system.pointer.getMouseTarget(this[config.Config])); | ||
cssPointerEvents.assertPointerEvents(this, this.system.pointer.getMouseTarget(this)); | ||
return this.pointer({ | ||
@@ -35,0 +25,0 @@ target: element.ownerDocument.body |
@@ -5,71 +5,16 @@ 'use strict'; | ||
var index = require('../event/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom'); | ||
var isElementType = require('../utils/misc/isElementType.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../utils/misc/level.js'); | ||
require('../options.js'); | ||
var selection = require('./selection.js'); | ||
var setRangeText = require('./setRangeText.js'); | ||
var value = require('./value.js'); | ||
var UI = require('./UI.js'); | ||
var getValueOrTextContent = require('./getValueOrTextContent.js'); | ||
var copySelection = require('./copySelection.js'); | ||
var trackValue = require('./trackValue.js'); | ||
const isPrepared = Symbol('Node prepared with document state workarounds'); | ||
function prepareDocument(document) { | ||
if (document[isPrepared]) { | ||
return; | ||
} | ||
document.addEventListener('focus', (e)=>{ | ||
const el = e.target; | ||
prepareElement(el); | ||
}, { | ||
capture: true, | ||
passive: true | ||
}); | ||
// Our test environment defaults to `document.body` as `activeElement`. | ||
// In other environments this might be `null` when preparing. | ||
// istanbul ignore else | ||
if (document.activeElement) { | ||
prepareElement(document.activeElement); | ||
} | ||
document.addEventListener('blur', (e)=>{ | ||
const el = e.target; | ||
const initialValue = value.getInitialValue(el); | ||
if (initialValue !== undefined) { | ||
if (el.value !== initialValue) { | ||
index.dispatchUIEvent({}, el, 'change'); | ||
} | ||
value.clearInitialValue(el); | ||
} | ||
}, { | ||
capture: true, | ||
passive: true | ||
}); | ||
document[isPrepared] = isPrepared; | ||
} | ||
function prepareElement(el) { | ||
if (el[isPrepared]) { | ||
return; | ||
} | ||
if (isElementType.isElementType(el, [ | ||
'input', | ||
'textarea' | ||
])) { | ||
value.prepareValueInterceptor(el); | ||
selection.prepareSelectionInterceptor(el); | ||
setRangeText.prepareRangeTextInterceptor(el); | ||
} | ||
el[isPrepared] = isPrepared; | ||
} | ||
exports.getUISelection = selection.getUISelection; | ||
exports.setUISelection = selection.setUISelection; | ||
exports.clearInitialValue = value.clearInitialValue; | ||
exports.commitValueAfterInput = value.commitValueAfterInput; | ||
exports.getUIValue = value.getUIValue; | ||
exports.setUIValue = value.setUIValue; | ||
exports.prepareDocument = prepareDocument; | ||
exports.clearInitialValue = UI.clearInitialValue; | ||
exports.getUISelection = UI.getUISelection; | ||
exports.getUIValue = UI.getUIValue; | ||
exports.setUISelection = UI.setUISelection; | ||
exports.setUIValue = UI.setUIValue; | ||
exports.getValueOrTextContent = getValueOrTextContent.getValueOrTextContent; | ||
exports.copySelection = copySelection.copySelection; | ||
exports.commitValueAfterInput = trackValue.commitValueAfterInput; |
@@ -5,2 +5,14 @@ 'use strict'; | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
var isElementType = require('../utils/misc/isElementType.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../utils/misc/level.js'); | ||
require('../options.js'); | ||
var trackValue = require('./trackValue.js'); | ||
var UI = require('./UI.js'); | ||
const Interceptor = Symbol('Interceptor for programmatical calls'); | ||
@@ -30,3 +42,74 @@ function prepareInterceptor(element, propName, interceptorImpl) { | ||
} | ||
function prepareValueInterceptor(element) { | ||
prepareInterceptor(element, 'value', function interceptorImpl(v) { | ||
const isUI = UI.isUIValue(v); | ||
if (isUI) { | ||
trackValue.startTrackValue(this); | ||
} | ||
return { | ||
applyNative: !!isUI, | ||
realArgs: sanitizeValue(this, v), | ||
then: isUI ? undefined : ()=>trackValue.trackOrSetValue(this, String(v)) | ||
}; | ||
}); | ||
} | ||
function sanitizeValue(element, v) { | ||
// Workaround for JSDOM | ||
if (isElementType.isElementType(element, 'input', { | ||
type: 'number' | ||
}) && String(v) !== '' && !Number.isNaN(Number(v))) { | ||
// Setting value to "1." results in `null` in JSDOM | ||
return String(Number(v)); | ||
} | ||
return String(v); | ||
} | ||
function prepareSelectionInterceptor(element) { | ||
prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) { | ||
const isUI = UI.isUISelectionStart(start); | ||
return { | ||
applyNative: !!isUI, | ||
realArgs: [ | ||
Number(start), | ||
...others | ||
], | ||
then: ()=>isUI ? undefined : UI.setUISelectionClean(element) | ||
}; | ||
}); | ||
prepareInterceptor(element, 'selectionStart', function interceptorImpl(v) { | ||
return { | ||
realArgs: v, | ||
then: ()=>UI.setUISelectionClean(element) | ||
}; | ||
}); | ||
prepareInterceptor(element, 'selectionEnd', function interceptorImpl(v) { | ||
return { | ||
realArgs: v, | ||
then: ()=>UI.setUISelectionClean(element) | ||
}; | ||
}); | ||
prepareInterceptor(element, 'select', function interceptorImpl() { | ||
return { | ||
realArgs: [], | ||
then: ()=>UI.setUISelectionRaw(element, { | ||
anchorOffset: 0, | ||
focusOffset: UI.getUIValue(element).length | ||
}) | ||
}; | ||
}); | ||
} | ||
function prepareRangeTextInterceptor(element) { | ||
prepareInterceptor(element, 'setRangeText', function interceptorImpl(...realArgs) { | ||
return { | ||
realArgs, | ||
then: ()=>{ | ||
UI.setUIValueClean(element); | ||
UI.setUISelectionClean(element); | ||
} | ||
}; | ||
}); | ||
} | ||
exports.prepareInterceptor = prepareInterceptor; | ||
exports.prepareRangeTextInterceptor = prepareRangeTextInterceptor; | ||
exports.prepareSelectionInterceptor = prepareSelectionInterceptor; | ||
exports.prepareValueInterceptor = prepareValueInterceptor; |
@@ -5,19 +5,15 @@ 'use strict'; | ||
require('../../utils/dataTransfer/Clipboard.js'); | ||
require('../eventMap.js'); | ||
var dispatchEvent = require('../dispatchEvent.js'); | ||
require('../../utils/edit/isEditable.js'); | ||
require('../../utils/edit/maxLength.js'); | ||
require('../../utils/edit/isEditable.js'); | ||
var focus = require('../../utils/focus/focus.js'); | ||
var isElementType = require('../../utils/misc/isElementType.js'); | ||
var getWindow = require('../../utils/misc/getWindow.js'); | ||
var isElementType = require('../../utils/misc/isElementType.js'); | ||
var blur = require('../../utils/focus/blur.js'); | ||
var isFocusable = require('../../utils/focus/isFocusable.js'); | ||
require('../../utils/keyDef/readNextDescriptor.js'); | ||
var cloneEvent = require('../../utils/misc/cloneEvent.js'); | ||
require('@testing-library/dom'); | ||
require('../../utils/misc/level.js'); | ||
require('../../options.js'); | ||
var focus = require('../focus.js'); | ||
var registry = require('./registry.js'); | ||
registry.behavior.click = (event, target, config)=>{ | ||
registry.behavior.click = (event, target, instance)=>{ | ||
const context = target.closest('button,input,label,select,textarea'); | ||
@@ -28,5 +24,5 @@ const control = context && isElementType.isElementType(context, 'label') && context.control; | ||
if (isFocusable.isFocusable(control)) { | ||
focus.focus(control); | ||
focus.focusElement(control); | ||
} | ||
dispatchEvent.dispatchEvent(config, control, cloneEvent.cloneEvent(event)); | ||
instance.dispatchEvent(control, cloneEvent.cloneEvent(event)); | ||
}; | ||
@@ -38,8 +34,8 @@ } else if (isElementType.isElementType(target, 'input', { | ||
// blur fires when the file selector pops up | ||
blur.blur(target); | ||
focus.blurElement(target); | ||
target.dispatchEvent(new (getWindow.getWindow(target)).Event('fileDialog')); | ||
// focus fires after the file selector has been closed | ||
focus.focus(target); | ||
focus.focusElement(target); | ||
}; | ||
} | ||
}; |
@@ -5,12 +5,4 @@ 'use strict'; | ||
require('../../utils/dataTransfer/Clipboard.js'); | ||
require('../eventMap.js'); | ||
require('./click.js'); | ||
require('./keydown.js'); | ||
require('./keypress.js'); | ||
require('./keyup.js'); | ||
require('./paste.js'); | ||
var registry = require('./registry.js'); | ||
require('@testing-library/dom'); | ||
var input = require('../../utils/edit/input.js'); | ||
var isEditable = require('../../utils/edit/isEditable.js'); | ||
require('../../utils/edit/maxLength.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -20,9 +12,11 @@ require('../../utils/keyDef/readNextDescriptor.js'); | ||
require('../../options.js'); | ||
var input = require('../input.js'); | ||
var registry = require('./registry.js'); | ||
registry.behavior.cut = (event, target, config)=>{ | ||
registry.behavior.cut = (event, target, instance)=>{ | ||
return ()=>{ | ||
if (isEditable.isEditable(target)) { | ||
input.input(config, target, '', 'deleteByCut'); | ||
input.input(instance, target, '', 'deleteByCut'); | ||
} | ||
}; | ||
}; |
'use strict'; | ||
var UI = require('../../document/UI.js'); | ||
var getValueOrTextContent = require('../../document/getValueOrTextContent.js'); | ||
require('../../utils/click/isClickableInput.js'); | ||
require('../../utils/dataTransfer/Clipboard.js'); | ||
var getValue = require('../../utils/edit/getValue.js'); | ||
var input = require('../../utils/edit/input.js'); | ||
var isContentEditable = require('../../utils/edit/isContentEditable.js'); | ||
var isEditable = require('../../utils/edit/isEditable.js'); | ||
var walkRadio = require('../../utils/edit/walkRadio.js'); | ||
require('@testing-library/dom'); | ||
require('../../utils/edit/maxLength.js'); | ||
var isElementType = require('../../utils/misc/isElementType.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
var getTabDestination = require('../../utils/focus/getTabDestination.js'); | ||
var selection = require('../../utils/focus/selection.js'); | ||
var focus = require('../../utils/focus/focus.js'); | ||
var getTabDestination = require('../../utils/focus/getTabDestination.js'); | ||
var selectAll = require('../../utils/focus/selectAll.js'); | ||
require('../../utils/keyDef/readNextDescriptor.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
require('../../utils/misc/level.js'); | ||
require('../../options.js'); | ||
require('../eventMap.js'); | ||
require('./click.js'); | ||
require('./cut.js'); | ||
require('./keypress.js'); | ||
require('./keyup.js'); | ||
require('./paste.js'); | ||
var focus = require('../focus.js'); | ||
var input = require('../input.js'); | ||
var moveSelection = require('../selection/moveSelection.js'); | ||
var selectAll = require('../selection/selectAll.js'); | ||
var setSelectionRange = require('../selection/setSelectionRange.js'); | ||
var radio = require('../radio.js'); | ||
var registry = require('./registry.js'); | ||
var selection$1 = require('../../document/selection.js'); | ||
registry.behavior.keydown = (event, target, config)=>{ | ||
registry.behavior.keydown = (event, target, instance)=>{ | ||
var ref; | ||
var ref1; | ||
return (ref1 = (ref = keydownBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keydownBehavior, event, target, config)) !== null && ref1 !== void 0 ? ref1 : combinationBehavior(event, target, config); | ||
return (ref1 = (ref = keydownBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keydownBehavior, event, target, instance)) !== null && ref1 !== void 0 ? ref1 : combinationBehavior(event, target, instance); | ||
}; | ||
const keydownBehavior = { | ||
ArrowDown: (event, target, config)=>{ | ||
ArrowDown: (event, target, instance)=>{ | ||
/* istanbul ignore else */ if (isElementType.isElementType(target, 'input', { | ||
type: 'radio' | ||
})) { | ||
return ()=>walkRadio.walkRadio(config, target, -1); | ||
return ()=>radio.walkRadio(instance, target, -1); | ||
} | ||
}, | ||
ArrowLeft: (event, target, config)=>{ | ||
ArrowLeft: (event, target, instance)=>{ | ||
if (isElementType.isElementType(target, 'input', { | ||
type: 'radio' | ||
})) { | ||
return ()=>walkRadio.walkRadio(config, target, -1); | ||
return ()=>radio.walkRadio(instance, target, -1); | ||
} | ||
return ()=>selection.moveSelection(target, -1); | ||
return ()=>moveSelection.moveSelection(target, -1); | ||
}, | ||
ArrowRight: (event, target, config)=>{ | ||
ArrowRight: (event, target, instance)=>{ | ||
if (isElementType.isElementType(target, 'input', { | ||
type: 'radio' | ||
})) { | ||
return ()=>walkRadio.walkRadio(config, target, 1); | ||
return ()=>radio.walkRadio(instance, target, 1); | ||
} | ||
return ()=>selection.moveSelection(target, 1); | ||
return ()=>moveSelection.moveSelection(target, 1); | ||
}, | ||
ArrowUp: (event, target, config)=>{ | ||
ArrowUp: (event, target, instance)=>{ | ||
/* istanbul ignore else */ if (isElementType.isElementType(target, 'input', { | ||
type: 'radio' | ||
})) { | ||
return ()=>walkRadio.walkRadio(config, target, 1); | ||
return ()=>radio.walkRadio(instance, target, 1); | ||
} | ||
}, | ||
Backspace: (event, target, config)=>{ | ||
Backspace: (event, target, instance)=>{ | ||
if (isEditable.isEditable(target)) { | ||
return ()=>{ | ||
input.input(config, target, '', 'deleteContentBackward'); | ||
input.input(instance, target, '', 'deleteContentBackward'); | ||
}; | ||
} | ||
}, | ||
Delete: (event, target, config)=>{ | ||
Delete: (event, target, instance)=>{ | ||
if (isEditable.isEditable(target)) { | ||
return ()=>{ | ||
input.input(config, target, '', 'deleteContentForward'); | ||
input.input(instance, target, '', 'deleteContentForward'); | ||
}; | ||
@@ -87,4 +83,4 @@ } | ||
var ref1; | ||
const newPos = (ref1 = (ref = getValue.getValue(target)) === null || ref === void 0 ? void 0 : ref.length) !== null && ref1 !== void 0 ? ref1 : /* istanbul ignore next */ 0; | ||
selection.setSelectionRange(target, newPos, newPos); | ||
const newPos = (ref1 = (ref = getValueOrTextContent.getValueOrTextContent(target)) === null || ref === void 0 ? void 0 : ref.length) !== null && ref1 !== void 0 ? ref1 : /* istanbul ignore next */ 0; | ||
setSelectionRange.setSelectionRange(target, newPos, newPos); | ||
}; | ||
@@ -99,3 +95,3 @@ } | ||
return ()=>{ | ||
selection.setSelectionRange(target, 0, 0); | ||
setSelectionRange.setSelectionRange(target, 0, 0); | ||
}; | ||
@@ -109,4 +105,4 @@ } | ||
return ()=>{ | ||
const newPos = getValue.getValue(target).length; | ||
selection.setSelectionRange(target, newPos, newPos); | ||
const newPos = UI.getUIValue(target).length; | ||
setSelectionRange.setSelectionRange(target, newPos, newPos); | ||
}; | ||
@@ -120,12 +116,12 @@ } | ||
return ()=>{ | ||
selection.setSelectionRange(target, 0, 0); | ||
setSelectionRange.setSelectionRange(target, 0, 0); | ||
}; | ||
} | ||
}, | ||
Tab: (event, target, config)=>{ | ||
Tab: (event, target, instance)=>{ | ||
return ()=>{ | ||
const dest = getTabDestination.getTabDestination(target, config.system.keyboard.modifiers.Shift); | ||
focus.focus(dest); | ||
const dest = getTabDestination.getTabDestination(target, instance.system.keyboard.modifiers.Shift); | ||
focus.focusElement(dest); | ||
if (selection.hasOwnSelection(dest)) { | ||
selection$1.setUISelection(dest, { | ||
UI.setUISelection(dest, { | ||
anchorOffset: 0, | ||
@@ -138,6 +134,6 @@ focusOffset: dest.value.length | ||
}; | ||
const combinationBehavior = (event, target, config)=>{ | ||
if (event.code === 'KeyA' && config.system.keyboard.modifiers.Control) { | ||
const combinationBehavior = (event, target, instance)=>{ | ||
if (event.code === 'KeyA' && instance.system.keyboard.modifiers.Control) { | ||
return ()=>selectAll.selectAll(target); | ||
} | ||
}; |
'use strict'; | ||
var index = require('../index.js'); | ||
require('../../utils/click/isClickableInput.js'); | ||
require('../../utils/dataTransfer/Clipboard.js'); | ||
var isContentEditable = require('../../utils/edit/isContentEditable.js'); | ||
var input = require('../../utils/edit/input.js'); | ||
var isEditable = require('../../utils/edit/isEditable.js'); | ||
require('@testing-library/dom'); | ||
require('../../utils/edit/maxLength.js'); | ||
var isElementType = require('../../utils/misc/isElementType.js'); | ||
@@ -15,9 +13,10 @@ require('@testing-library/dom/dist/helpers.js'); | ||
require('../../options.js'); | ||
var input = require('../input.js'); | ||
var registry = require('./registry.js'); | ||
registry.behavior.keypress = (event, target, config)=>{ | ||
registry.behavior.keypress = (event, target, instance)=>{ | ||
if (event.key === 'Enter') { | ||
if (isElementType.isElementType(target, 'button') || isElementType.isElementType(target, 'input') && ClickInputOnEnter.includes(target.type) || isElementType.isElementType(target, 'a') && Boolean(target.href)) { | ||
return ()=>{ | ||
index.dispatchUIEvent(config, target, 'click'); | ||
instance.dispatchUIEvent(target, 'click'); | ||
}; | ||
@@ -28,5 +27,5 @@ } else if (isElementType.isElementType(target, 'input')) { | ||
if (submit) { | ||
return ()=>index.dispatchUIEvent(config, submit, 'click'); | ||
return ()=>instance.dispatchUIEvent(submit, 'click'); | ||
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) { | ||
return ()=>index.dispatchUIEvent(config, form, 'submit'); | ||
return ()=>instance.dispatchUIEvent(form, 'submit'); | ||
} else { | ||
@@ -38,5 +37,5 @@ return; | ||
if (isEditable.isEditable(target)) { | ||
const inputType = event.key === 'Enter' ? isContentEditable.isContentEditable(target) && !config.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText'; | ||
const inputType = event.key === 'Enter' ? isContentEditable.isContentEditable(target) && !instance.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText'; | ||
const inputData = event.key === 'Enter' ? '\n' : event.key; | ||
return ()=>input.input(config, target, inputData, inputType); | ||
return ()=>input.input(instance, target, inputData, inputType); | ||
} | ||
@@ -43,0 +42,0 @@ }; |
@@ -5,6 +5,4 @@ 'use strict'; | ||
require('../../utils/dataTransfer/Clipboard.js'); | ||
var index = require('../index.js'); | ||
require('../../utils/edit/isEditable.js'); | ||
require('../../utils/edit/maxLength.js'); | ||
require('../../utils/edit/isEditable.js'); | ||
require('@testing-library/dom'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -16,12 +14,12 @@ require('../../utils/keyDef/readNextDescriptor.js'); | ||
registry.behavior.keyup = (event, target, config)=>{ | ||
registry.behavior.keyup = (event, target, instance)=>{ | ||
var ref; | ||
return (ref = keyupBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keyupBehavior, event, target, config); | ||
return (ref = keyupBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keyupBehavior, event, target, instance); | ||
}; | ||
const keyupBehavior = { | ||
' ': (event, target, config)=>{ | ||
' ': (event, target, instance)=>{ | ||
if (isClickableInput.isClickableInput(target)) { | ||
return ()=>index.dispatchUIEvent(config, target, 'click'); | ||
return ()=>instance.dispatchUIEvent(target, 'click'); | ||
} | ||
} | ||
}; |
@@ -5,12 +5,4 @@ 'use strict'; | ||
require('../../utils/dataTransfer/Clipboard.js'); | ||
require('../eventMap.js'); | ||
require('./click.js'); | ||
require('./cut.js'); | ||
require('./keydown.js'); | ||
require('./keypress.js'); | ||
require('./keyup.js'); | ||
var registry = require('./registry.js'); | ||
require('@testing-library/dom'); | ||
var input = require('../../utils/edit/input.js'); | ||
var isEditable = require('../../utils/edit/isEditable.js'); | ||
require('../../utils/edit/maxLength.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -20,4 +12,6 @@ require('../../utils/keyDef/readNextDescriptor.js'); | ||
require('../../options.js'); | ||
var input = require('../input.js'); | ||
var registry = require('./registry.js'); | ||
registry.behavior.paste = (event, target, config)=>{ | ||
registry.behavior.paste = (event, target, instance)=>{ | ||
if (isEditable.isEditable(target)) { | ||
@@ -28,3 +22,3 @@ return ()=>{ | ||
if (insertData) { | ||
input.input(config, target, insertData, 'insertFromPaste'); | ||
input.input(instance, target, insertData, 'insertFromPaste'); | ||
} | ||
@@ -31,0 +25,0 @@ }; |
@@ -7,12 +7,4 @@ 'use strict'; | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('./behavior/click.js'); | ||
require('./behavior/cut.js'); | ||
require('./behavior/keydown.js'); | ||
require('./behavior/keypress.js'); | ||
require('./behavior/keyup.js'); | ||
require('./behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
var eventMap = require('./eventMap.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
var getWindow = require('../utils/misc/getWindow.js'); | ||
@@ -22,2 +14,3 @@ require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../options.js'); | ||
var eventMap = require('./eventMap.js'); | ||
@@ -24,0 +17,0 @@ const eventInitializer = { |
@@ -13,7 +13,19 @@ 'use strict'; | ||
var wrapEvent = require('./wrapEvent.js'); | ||
var eventMap = require('./eventMap.js'); | ||
var createEvent = require('./createEvent.js'); | ||
function dispatchEvent(config, target, event, preventDefault = false) { | ||
function dispatchUIEvent(target, type, init, preventDefault = false) { | ||
if (eventMap.isMouseEvent(type) || eventMap.isKeyboardEvent(type)) { | ||
init = { | ||
...init, | ||
...this.system.getUIEventModifiers() | ||
}; | ||
} | ||
const event = createEvent.createEvent(type, target, init); | ||
return dispatchEvent.call(this, target, event, preventDefault); | ||
} | ||
function dispatchEvent(target, event, preventDefault = false) { | ||
var ref; | ||
const type = event.type; | ||
const behaviorImplementation = preventDefault ? ()=>{} : (ref = registry.behavior[type]) === null || ref === void 0 ? void 0 : ref(event, target, config); | ||
const behaviorImplementation = preventDefault ? ()=>{} : (ref = registry.behavior[type]) === null || ref === void 0 ? void 0 : ref(event, target, this); | ||
if (behaviorImplementation) { | ||
@@ -38,3 +50,9 @@ event.preventDefault(); | ||
} | ||
function dispatchDOMEvent(target, type, init) { | ||
const event = createEvent.createEvent(type, target, init); | ||
wrapEvent.wrapEvent(()=>target.dispatchEvent(event)); | ||
} | ||
exports.dispatchDOMEvent = dispatchDOMEvent; | ||
exports.dispatchEvent = dispatchEvent; | ||
exports.dispatchUIEvent = dispatchUIEvent; |
@@ -5,21 +5,28 @@ 'use strict'; | ||
var createEvent = require('./createEvent.js'); | ||
var dispatchEvent = require('./dispatchEvent.js'); | ||
var eventMap = require('./eventMap.js'); | ||
var focus = require('./focus.js'); | ||
var input = require('./input.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../utils/misc/level.js'); | ||
require('../options.js'); | ||
var setSelectionPerMouse = require('./selection/setSelectionPerMouse.js'); | ||
var modifySelectionPerMouse = require('./selection/modifySelectionPerMouse.js'); | ||
var selectAll = require('./selection/selectAll.js'); | ||
function dispatchUIEvent(config, target, type, init, preventDefault = false) { | ||
if (eventMap.isMouseEvent(type) || eventMap.isKeyboardEvent(type)) { | ||
init = { | ||
...init, | ||
...config.system.getUIEventModifiers() | ||
}; | ||
} | ||
const event = createEvent.createEvent(type, target, init); | ||
return dispatchEvent.dispatchEvent(config, target, event, preventDefault); | ||
} | ||
function bindDispatchUIEvent(config) { | ||
return dispatchUIEvent.bind(undefined, config); | ||
} | ||
exports.bindDispatchUIEvent = bindDispatchUIEvent; | ||
exports.dispatchUIEvent = dispatchUIEvent; | ||
exports.dispatchDOMEvent = dispatchEvent.dispatchDOMEvent; | ||
exports.dispatchEvent = dispatchEvent.dispatchEvent; | ||
exports.dispatchUIEvent = dispatchEvent.dispatchUIEvent; | ||
exports.blurElement = focus.blurElement; | ||
exports.focusElement = focus.focusElement; | ||
exports.input = input.input; | ||
exports.setSelectionPerMouseDown = setSelectionPerMouse.setSelectionPerMouseDown; | ||
exports.modifySelectionPerMouseMove = modifySelectionPerMouse.modifySelectionPerMouseMove; | ||
exports.isAllSelected = selectAll.isAllSelected; | ||
exports.selectAll = selectAll.selectAll; |
@@ -5,15 +5,6 @@ 'use strict'; | ||
require('../setup/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -25,22 +16,21 @@ require('../utils/keyDef/readNextDescriptor.js'); | ||
var parseKeyDef = require('./parseKeyDef.js'); | ||
var config = require('../setup/config.js'); | ||
async function keyboard(text) { | ||
const actions = parseKeyDef.parseKeyDef(this[config.Config].keyboardMap, text); | ||
const actions = parseKeyDef.parseKeyDef(this.config.keyboardMap, text); | ||
for(let i = 0; i < actions.length; i++){ | ||
await wait.wait(this[config.Config]); | ||
await keyboardAction(this[config.Config], actions[i]); | ||
await wait.wait(this.config); | ||
await keyboardAction(this, actions[i]); | ||
} | ||
} | ||
async function keyboardAction(config, { keyDef , releasePrevious , releaseSelf , repeat }) { | ||
const { system } = config; | ||
async function keyboardAction(instance, { keyDef , releasePrevious , releaseSelf , repeat }) { | ||
const { system } = instance; | ||
// Release the key automatically if it was pressed before. | ||
if (system.keyboard.isKeyPressed(keyDef)) { | ||
await system.keyboard.keyup(config, keyDef); | ||
await system.keyboard.keyup(instance, keyDef); | ||
} | ||
if (!releasePrevious) { | ||
for(let i = 1; i <= repeat; i++){ | ||
await system.keyboard.keydown(config, keyDef); | ||
await system.keyboard.keydown(instance, keyDef); | ||
if (i < repeat) { | ||
await wait.wait(config); | ||
await wait.wait(instance.config); | ||
} | ||
@@ -50,9 +40,9 @@ } | ||
if (releaseSelf) { | ||
await system.keyboard.keyup(config, keyDef); | ||
await system.keyboard.keyup(instance, keyDef); | ||
} | ||
} | ||
} | ||
async function releaseAllKeys(config) { | ||
for (const k of config.system.keyboard.getPressedKeys()){ | ||
await config.system.keyboard.keyup(config, k); | ||
async function releaseAllKeys(instance) { | ||
for (const k of instance.system.keyboard.getPressedKeys()){ | ||
await instance.system.keyboard.keyup(instance, k); | ||
} | ||
@@ -59,0 +49,0 @@ } |
@@ -7,12 +7,4 @@ 'use strict'; | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -19,0 +11,0 @@ var readNextDescriptor = require('../utils/keyDef/readNextDescriptor.js'); |
@@ -5,5 +5,2 @@ 'use strict'; | ||
var keyMap = require('./keyboard/keyMap.js'); | ||
var keyMap$1 = require('./pointer/keyMap.js'); | ||
exports.PointerEventsCheckLevel = void 0; | ||
@@ -19,26 +16,1 @@ (function(PointerEventsCheckLevel) { | ||
})(exports.PointerEventsCheckLevel || (exports.PointerEventsCheckLevel = {})); | ||
/** | ||
* Default options applied when API is called per `userEvent.anyApi()` | ||
*/ const defaultOptionsDirect = { | ||
applyAccept: true, | ||
autoModify: true, | ||
delay: 0, | ||
document: globalThis.document, | ||
keyboardMap: keyMap.defaultKeyMap, | ||
pointerMap: keyMap$1.defaultKeyMap, | ||
pointerEventsCheck: exports.PointerEventsCheckLevel.EachApiCall, | ||
skipAutoClose: false, | ||
skipClick: false, | ||
skipHover: false, | ||
writeToClipboard: false, | ||
advanceTimers: ()=>Promise.resolve() | ||
}; | ||
/** | ||
* Default options applied when API is called per `userEvent().anyApi()` | ||
*/ const defaultOptionsSetup = { | ||
...defaultOptionsDirect, | ||
writeToClipboard: true | ||
}; | ||
exports.defaultOptionsDirect = defaultOptionsDirect; | ||
exports.defaultOptionsSetup = defaultOptionsSetup; |
@@ -5,15 +5,6 @@ 'use strict'; | ||
require('../setup/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -25,6 +16,5 @@ require('../utils/keyDef/readNextDescriptor.js'); | ||
var parseKeyDef = require('./parseKeyDef.js'); | ||
var config = require('../setup/config.js'); | ||
async function pointer(input) { | ||
const { pointerMap } = this[config.Config]; | ||
const { pointerMap } = this.config; | ||
const actions = []; | ||
@@ -46,14 +36,14 @@ (Array.isArray(input) ? input : [ | ||
for(let i = 0; i < actions.length; i++){ | ||
await wait.wait(this[config.Config]); | ||
await pointerAction(this[config.Config], actions[i]); | ||
await wait.wait(this.config); | ||
await pointerAction(this, actions[i]); | ||
} | ||
this[config.Config].system.pointer.resetClickCount(); | ||
this.system.pointer.resetClickCount(); | ||
} | ||
async function pointerAction(config, action) { | ||
async function pointerAction(instance, action) { | ||
var ref, ref1; | ||
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? config.system.pointer.getPointerName(action.keyDef) : 'mouse'; | ||
const previousPosition = config.system.pointer.getPreviousPosition(pointerName); | ||
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? instance.system.pointer.getPointerName(action.keyDef) : 'mouse'; | ||
const previousPosition = instance.system.pointer.getPreviousPosition(pointerName); | ||
var _target, _coords, _node, _offset; | ||
const position = { | ||
target: (_target = action.target) !== null && _target !== void 0 ? _target : getPrevTarget(config, previousPosition), | ||
target: (_target = action.target) !== null && _target !== void 0 ? _target : getPrevTarget(instance, previousPosition), | ||
coords: (_coords = action.coords) !== null && _coords !== void 0 ? _coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords, | ||
@@ -66,17 +56,17 @@ caret: { | ||
if ('keyDef' in action) { | ||
if (config.system.pointer.isKeyPressed(action.keyDef)) { | ||
level.setLevelRef(config, level.ApiLevel.Trigger); | ||
await config.system.pointer.release(config, action.keyDef, position); | ||
if (instance.system.pointer.isKeyPressed(action.keyDef)) { | ||
level.setLevelRef(instance, level.ApiLevel.Trigger); | ||
await instance.system.pointer.release(instance, action.keyDef, position); | ||
} | ||
if (!action.releasePrevious) { | ||
level.setLevelRef(config, level.ApiLevel.Trigger); | ||
await config.system.pointer.press(config, action.keyDef, position); | ||
level.setLevelRef(instance, level.ApiLevel.Trigger); | ||
await instance.system.pointer.press(instance, action.keyDef, position); | ||
if (action.releaseSelf) { | ||
level.setLevelRef(config, level.ApiLevel.Trigger); | ||
await config.system.pointer.release(config, action.keyDef, position); | ||
level.setLevelRef(instance, level.ApiLevel.Trigger); | ||
await instance.system.pointer.release(instance, action.keyDef, position); | ||
} | ||
} | ||
} else { | ||
level.setLevelRef(config, level.ApiLevel.Trigger); | ||
await config.system.pointer.move(config, pointerName, position); | ||
level.setLevelRef(instance, level.ApiLevel.Trigger); | ||
await instance.system.pointer.move(instance, pointerName, position); | ||
} | ||
@@ -88,3 +78,3 @@ } | ||
} | ||
function getPrevTarget(config, position) { | ||
function getPrevTarget(instance, position) { | ||
if (!position) { | ||
@@ -94,5 +84,5 @@ throw new Error('This pointer has no previous position. Provide a target property!'); | ||
var _target; | ||
return (_target = position.target) !== null && _target !== void 0 ? _target : config.document.body; | ||
return (_target = position.target) !== null && _target !== void 0 ? _target : instance.config.document.body; | ||
} | ||
exports.pointer = pointer; |
@@ -7,12 +7,4 @@ 'use strict'; | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -19,0 +11,0 @@ var readNextDescriptor = require('../utils/keyDef/readNextDescriptor.js'); |
@@ -29,8 +29,8 @@ 'use strict'; | ||
async function keyboard(text, options = {}) { | ||
const { config , api } = setup.setupDirect(options); | ||
return api.keyboard(text).then(()=>config.system); | ||
const { api , system } = setup.setupDirect(options); | ||
return api.keyboard(text).then(()=>system); | ||
} | ||
async function pointer(input, options = {}) { | ||
const { config , api } = setup.setupDirect(options); | ||
return api.pointer(input).then(()=>config.system); | ||
const { api , system } = setup.setupDirect(options); | ||
return api.pointer(input).then(()=>system); | ||
} | ||
@@ -50,4 +50,4 @@ function paste(clipboardData, options) { | ||
function unhover(element, options = {}) { | ||
const { config , api } = setup.setupDirect(options); | ||
config.system.pointer.setMousePosition({ | ||
const { api , system } = setup.setupDirect(options); | ||
system.pointer.setMousePosition({ | ||
target: element | ||
@@ -54,0 +54,0 @@ }); |
@@ -6,3 +6,2 @@ 'use strict'; | ||
var setup = require('./setup.js'); | ||
var config = require('./config.js'); | ||
var directApi = require('./directApi.js'); | ||
@@ -15,3 +14,2 @@ | ||
exports.Config = config.Config; | ||
exports.userEvent = userEvent; |
@@ -5,10 +5,8 @@ 'use strict'; | ||
var index$1 = require('../document/index.js'); | ||
var index$2 = require('../event/index.js'); | ||
var options = require('../options.js'); | ||
var prepareDocument = require('../document/prepareDocument.js'); | ||
var dispatchEvent = require('../event/dispatchEvent.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
var Clipboard = require('../utils/dataTransfer/Clipboard.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -19,15 +17,38 @@ require('../utils/keyDef/readNextDescriptor.js'); | ||
var wait = require('../utils/misc/wait.js'); | ||
var options = require('../options.js'); | ||
require('@testing-library/dom'); | ||
var keyMap = require('../keyboard/keyMap.js'); | ||
var keyMap$1 = require('../pointer/keyMap.js'); | ||
var index = require('../system/index.js'); | ||
var config = require('./config.js'); | ||
var api = require('./api.js'); | ||
var wrapAsync = require('./wrapAsync.js'); | ||
function createConfig(options$1 = {}, defaults = options.defaultOptionsSetup, node) { | ||
const document = getDocument(options$1, node, defaults); | ||
var _system; | ||
/** | ||
* Default options applied when API is called per `userEvent.anyApi()` | ||
*/ const defaultOptionsDirect = { | ||
applyAccept: true, | ||
autoModify: true, | ||
delay: 0, | ||
document: globalThis.document, | ||
keyboardMap: keyMap.defaultKeyMap, | ||
pointerMap: keyMap$1.defaultKeyMap, | ||
pointerEventsCheck: options.PointerEventsCheckLevel.EachApiCall, | ||
skipAutoClose: false, | ||
skipClick: false, | ||
skipHover: false, | ||
writeToClipboard: false, | ||
advanceTimers: ()=>Promise.resolve() | ||
}; | ||
/** | ||
* Default options applied when API is called per `userEvent().anyApi()` | ||
*/ const defaultOptionsSetup = { | ||
...defaultOptionsDirect, | ||
writeToClipboard: true | ||
}; | ||
function createConfig(options = {}, defaults = defaultOptionsSetup, node) { | ||
const document = getDocument(options, node, defaults); | ||
return { | ||
...defaults, | ||
...options$1, | ||
document, | ||
system: (_system = options$1.system) !== null && _system !== void 0 ? _system : new index.System() | ||
...options, | ||
document | ||
}; | ||
@@ -40,19 +61,18 @@ } | ||
const config = createConfig(options); | ||
index$1.prepareDocument(config.document); | ||
prepareDocument.prepareDocument(config.document); | ||
var _defaultView; | ||
const view = (_defaultView = config.document.defaultView) !== null && _defaultView !== void 0 ? _defaultView : /* istanbul ignore next */ globalThis.window; | ||
Clipboard.attachClipboardStubToView(view); | ||
return doSetup(config); | ||
return createInstance(config).api; | ||
} | ||
/** | ||
* Setup in direct call per `userEvent.anyApi()` | ||
*/ function setupDirect({ keyboardState , pointerState , ...options$1 } = {}, node) { | ||
const config = createConfig({ | ||
...options$1, | ||
system: pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState | ||
}, options.defaultOptionsDirect, node); | ||
index$1.prepareDocument(config.document); | ||
*/ function setupDirect({ keyboardState , pointerState , ...options } = {}, node) { | ||
const config = createConfig(options, defaultOptionsDirect, node); | ||
prepareDocument.prepareDocument(config.document); | ||
var ref; | ||
const system = (ref = pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState) !== null && ref !== void 0 ? ref : new index.System(); | ||
return { | ||
config, | ||
api: doSetup(config) | ||
api: createInstance(config, system).api, | ||
system | ||
}; | ||
@@ -63,12 +83,12 @@ } | ||
*/ function setupSub(options) { | ||
return doSetup({ | ||
...this[config.Config], | ||
return createInstance({ | ||
...this.config, | ||
...options | ||
}); | ||
}, this.system).api; | ||
} | ||
function wrapAndBindImpl(instance, impl) { | ||
function method(...args) { | ||
level.setLevelRef(instance[config.Config], level.ApiLevel.Call); | ||
level.setLevelRef(instance, level.ApiLevel.Call); | ||
return wrapAsync.wrapAsync(()=>impl.apply(instance, args).then(async (ret)=>{ | ||
await wait.wait(instance[config.Config]); | ||
await wait.wait(instance.config); | ||
return ret; | ||
@@ -82,14 +102,21 @@ })); | ||
} | ||
function doSetup(config$1) { | ||
const instance = { | ||
[config.Config]: config$1, | ||
dispatchUIEvent: index$2.bindDispatchUIEvent(config$1), | ||
function createInstance(config, system = new index.System()) { | ||
const instance = {}; | ||
Object.assign(instance, { | ||
config, | ||
dispatchEvent: dispatchEvent.dispatchEvent.bind(instance), | ||
dispatchUIEvent: dispatchEvent.dispatchUIEvent.bind(instance), | ||
system, | ||
levelRefs: {}, | ||
...api | ||
}; | ||
}); | ||
return { | ||
...Object.fromEntries(Object.entries(api).map(([name, api])=>[ | ||
name, | ||
wrapAndBindImpl(instance, api), | ||
])), | ||
setup: setupSub.bind(instance) | ||
instance, | ||
api: { | ||
...Object.fromEntries(Object.entries(api).map(([name, api])=>[ | ||
name, | ||
wrapAndBindImpl(instance, api), | ||
])), | ||
setup: setupSub.bind(instance) | ||
} | ||
}; | ||
@@ -103,4 +130,5 @@ } | ||
exports.createConfig = createConfig; | ||
exports.createInstance = createInstance; | ||
exports.setupDirect = setupDirect; | ||
exports.setupMain = setupMain; | ||
exports.setupSub = setupSub; |
@@ -5,8 +5,6 @@ 'use strict'; | ||
var index = require('../event/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('@testing-library/dom'); | ||
var getActiveElement = require('../utils/focus/getActiveElement.js'); | ||
@@ -55,6 +53,6 @@ require('@testing-library/dom/dist/helpers.js'); | ||
} | ||
/** Press a key */ async keydown(config, keyDef) { | ||
/** Press a key */ async keydown(instance, keyDef) { | ||
const key = String(keyDef.key); | ||
const code = String(keyDef.code); | ||
const target = getActiveElement.getActiveElementOrBody(config.document); | ||
const target = getActiveElement.getActiveElementOrBody(instance.config.document); | ||
this.setKeydownTarget(target); | ||
@@ -69,3 +67,3 @@ var ref; | ||
} | ||
const unprevented = index.dispatchUIEvent(config, target, 'keydown', { | ||
const unprevented = instance.dispatchUIEvent(target, 'keydown', { | ||
key, | ||
@@ -80,3 +78,3 @@ code | ||
if (unprevented && this.hasKeyPress(key)) { | ||
index.dispatchUIEvent(config, getActiveElement.getActiveElementOrBody(config.document), 'keypress', { | ||
instance.dispatchUIEvent(getActiveElement.getActiveElementOrBody(instance.config.document), 'keypress', { | ||
key, | ||
@@ -88,3 +86,3 @@ code, | ||
} | ||
/** Release a key */ async keyup(config, keyDef) { | ||
/** Release a key */ async keyup(instance, keyDef) { | ||
const key = String(keyDef.key); | ||
@@ -98,3 +96,3 @@ const code = String(keyDef.code); | ||
} | ||
index.dispatchUIEvent(config, getActiveElement.getActiveElementOrBody(config.document), 'keyup', { | ||
instance.dispatchUIEvent(getActiveElement.getActiveElementOrBody(instance.config.document), 'keyup', { | ||
key, | ||
@@ -101,0 +99,0 @@ code |
@@ -15,5 +15,5 @@ 'use strict'; | ||
} | ||
async press(config, keyDef, position) { | ||
async press(instance, keyDef, position) { | ||
const pointerName = this.getPointerName(keyDef); | ||
const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef).init(config, position) : this.pointers.get(pointerName); | ||
const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef).init(instance, position) : this.pointers.get(pointerName); | ||
// TODO: deprecate the following implicit setting of position | ||
@@ -26,8 +26,8 @@ pointer.position = position; | ||
this.buttons.down(keyDef); | ||
pointer.down(config, keyDef); | ||
pointer.down(instance, keyDef); | ||
if (pointer.pointerType !== 'touch' && !pointer.isPrevented) { | ||
this.mouse.down(config, keyDef, pointer); | ||
this.mouse.down(instance, keyDef, pointer); | ||
} | ||
} | ||
async move(config, pointerName, position) { | ||
async move(instance, pointerName, position) { | ||
const pointer = this.pointers.get(pointerName); | ||
@@ -38,4 +38,4 @@ // In (some?) browsers this order of events can be observed. | ||
// the order in which they interweave/follow on a user interaction depends on the implementation. | ||
const pointermove = pointer.move(config, position); | ||
const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(config, position); | ||
const pointermove = pointer.move(instance, position); | ||
const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(instance, position); | ||
pointermove === null || pointermove === void 0 ? void 0 : pointermove.leave(); | ||
@@ -48,3 +48,3 @@ mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave(); | ||
} | ||
async release(config, keyDef, position) { | ||
async release(instance, keyDef, position) { | ||
const device = this.devices.get(keyDef.pointerType); | ||
@@ -60,21 +60,21 @@ device.removePressed(keyDef); | ||
if (device.countPressed === 0) { | ||
pointer.up(config, keyDef); | ||
pointer.up(instance, keyDef); | ||
} | ||
if (pointer.pointerType === 'touch') { | ||
pointer.release(config); | ||
pointer.release(instance); | ||
} | ||
if (!pointer.isPrevented) { | ||
if (pointer.pointerType === 'touch' && !pointer.isMultitouch) { | ||
const mousemove = this.mouse.move(config, pointer.position); | ||
const mousemove = this.mouse.move(instance, pointer.position); | ||
mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave(); | ||
mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter(); | ||
mousemove === null || mousemove === void 0 ? void 0 : mousemove.move(); | ||
this.mouse.down(config, keyDef, pointer); | ||
this.mouse.down(instance, keyDef, pointer); | ||
} | ||
if (!pointer.isMultitouch) { | ||
const mousemove1 = this.mouse.move(config, pointer.position); | ||
const mousemove1 = this.mouse.move(instance, pointer.position); | ||
mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.leave(); | ||
mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.enter(); | ||
mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.move(); | ||
this.mouse.up(config, keyDef, pointer); | ||
this.mouse.up(instance, keyDef, pointer); | ||
} | ||
@@ -92,5 +92,5 @@ } | ||
} | ||
getMouseTarget(config) { | ||
getMouseTarget(instance) { | ||
var _target; | ||
return (_target = this.mouse.position.target) !== null && _target !== void 0 ? _target : config.document.body; | ||
return (_target = this.mouse.position.target) !== null && _target !== void 0 ? _target : instance.config.document.body; | ||
} | ||
@@ -154,8 +154,3 @@ setMousePosition(position) { | ||
} | ||
function isDifferentPointerPosition(positionA, positionB) { | ||
var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7; | ||
return positionA.target !== positionB.target || ((ref = positionA.coords) === null || ref === void 0 ? void 0 : ref.x) !== ((ref1 = positionB.coords) === null || ref1 === void 0 ? void 0 : ref1.y) || ((ref2 = positionA.coords) === null || ref2 === void 0 ? void 0 : ref2.y) !== ((ref3 = positionB.coords) === null || ref3 === void 0 ? void 0 : ref3.y) || ((ref4 = positionA.caret) === null || ref4 === void 0 ? void 0 : ref4.node) !== ((ref5 = positionB.caret) === null || ref5 === void 0 ? void 0 : ref5.node) || ((ref6 = positionA.caret) === null || ref6 === void 0 ? void 0 : ref6.offset) !== ((ref7 = positionB.caret) === null || ref7 === void 0 ? void 0 : ref7.offset); | ||
} | ||
exports.PointerHost = PointerHost; | ||
exports.isDifferentPointerPosition = isDifferentPointerPosition; |
@@ -5,12 +5,16 @@ 'use strict'; | ||
var index$1 = require('../../event/index.js'); | ||
require('../../event/behavior/click.js'); | ||
require('../../event/behavior/cut.js'); | ||
require('../../event/behavior/keydown.js'); | ||
require('../../event/behavior/keypress.js'); | ||
require('../../event/behavior/keyup.js'); | ||
require('../../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../../event/eventMap.js'); | ||
require('../../utils/click/isClickableInput.js'); | ||
require('../../utils/dataTransfer/Clipboard.js'); | ||
require('../../utils/edit/isEditable.js'); | ||
require('../../utils/edit/maxLength.js'); | ||
require('../../utils/edit/isEditable.js'); | ||
var focus = require('../../utils/focus/focus.js'); | ||
var isDisabled = require('../../utils/misc/isDisabled.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
var isDisabled = require('../../utils/misc/isDisabled.js'); | ||
require('@testing-library/dom'); | ||
var selection = require('../../utils/focus/selection.js'); | ||
require('../../utils/keyDef/readNextDescriptor.js'); | ||
@@ -20,4 +24,7 @@ var getTreeDiff = require('../../utils/misc/getTreeDiff.js'); | ||
require('../../options.js'); | ||
var index = require('./index.js'); | ||
var focus = require('../../event/focus.js'); | ||
var setSelectionPerMouse = require('../../event/selection/setSelectionPerMouse.js'); | ||
var modifySelectionPerMouse = require('../../event/selection/modifySelectionPerMouse.js'); | ||
var buttons = require('./buttons.js'); | ||
var shared = require('./shared.js'); | ||
@@ -27,10 +34,10 @@ /** | ||
*/ class Mouse { | ||
move(config, position) { | ||
move(instance, position) { | ||
const prevPosition = this.position; | ||
const prevTarget = this.getTarget(config); | ||
const prevTarget = this.getTarget(instance); | ||
this.position = position; | ||
if (!index.isDifferentPointerPosition(prevPosition, position)) { | ||
if (!shared.isDifferentPointerPosition(prevPosition, position)) { | ||
return; | ||
} | ||
const nextTarget = this.getTarget(config); | ||
const nextTarget = this.getTarget(instance); | ||
const init = this.getEventInit('mousemove'); | ||
@@ -41,4 +48,4 @@ const [leave, enter] = getTreeDiff.getTreeDiff(prevTarget, nextTarget); | ||
if (prevTarget !== nextTarget) { | ||
index$1.dispatchUIEvent(config, prevTarget, 'mouseout', init); | ||
leave.forEach((el)=>index$1.dispatchUIEvent(config, el, 'mouseleave', init)); | ||
instance.dispatchUIEvent(prevTarget, 'mouseout', init); | ||
leave.forEach((el)=>instance.dispatchUIEvent(el, 'mouseleave', init)); | ||
} | ||
@@ -48,13 +55,13 @@ }, | ||
if (prevTarget !== nextTarget) { | ||
index$1.dispatchUIEvent(config, nextTarget, 'mouseover', init); | ||
enter.forEach((el)=>index$1.dispatchUIEvent(config, el, 'mouseenter', init)); | ||
instance.dispatchUIEvent(nextTarget, 'mouseover', init); | ||
enter.forEach((el)=>instance.dispatchUIEvent(el, 'mouseenter', init)); | ||
} | ||
}, | ||
move: ()=>{ | ||
index$1.dispatchUIEvent(config, nextTarget, 'mousemove', init); | ||
this.modifySelecting(config); | ||
instance.dispatchUIEvent(nextTarget, 'mousemove', init); | ||
this.modifySelecting(instance); | ||
} | ||
}; | ||
} | ||
down(config, keyDef, pointer) { | ||
down(instance, keyDef, pointer) { | ||
const button = this.buttons.down(keyDef); | ||
@@ -64,15 +71,15 @@ if (button === undefined) { | ||
} | ||
const target = this.getTarget(config); | ||
const target = this.getTarget(instance); | ||
this.buttonDownTarget[button] = target; | ||
const disabled = isDisabled.isDisabled(target); | ||
const init = this.getEventInit('mousedown', keyDef.button); | ||
if (disabled || index$1.dispatchUIEvent(config, target, 'mousedown', init)) { | ||
this.startSelecting(config, init.detail); | ||
focus.focus(target); | ||
if (disabled || instance.dispatchUIEvent(target, 'mousedown', init)) { | ||
this.startSelecting(instance, init.detail); | ||
focus.focusElement(target); | ||
} | ||
if (!disabled && buttons.getMouseEventButton(keyDef.button) === 2) { | ||
index$1.dispatchUIEvent(config, target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button, pointer)); | ||
instance.dispatchUIEvent(target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button, pointer)); | ||
} | ||
} | ||
up(config, keyDef, pointer) { | ||
up(instance, keyDef, pointer) { | ||
const button = this.buttons.up(keyDef); | ||
@@ -82,5 +89,5 @@ if (button === undefined) { | ||
} | ||
const target = this.getTarget(config); | ||
const target = this.getTarget(instance); | ||
if (!isDisabled.isDisabled(target)) { | ||
index$1.dispatchUIEvent(config, target, 'mouseup', this.getEventInit('mouseup', keyDef.button)); | ||
instance.dispatchUIEvent(target, 'mouseup', this.getEventInit('mouseup', keyDef.button)); | ||
this.endSelecting(); | ||
@@ -91,5 +98,5 @@ const clickTarget = getTreeDiff.getTreeDiff(this.buttonDownTarget[button], target)[2][0]; | ||
if (init.detail) { | ||
index$1.dispatchUIEvent(config, clickTarget, init.button === 0 ? 'click' : 'auxclick', init); | ||
instance.dispatchUIEvent(clickTarget, init.button === 0 ? 'click' : 'auxclick', init); | ||
if (init.button === 0 && init.detail === 2) { | ||
index$1.dispatchUIEvent(config, clickTarget, 'dblclick', { | ||
instance.dispatchUIEvent(clickTarget, 'dblclick', { | ||
...this.getEventInit('dblclick', keyDef.button), | ||
@@ -126,12 +133,12 @@ detail: init.detail | ||
} | ||
getTarget(config) { | ||
getTarget(instance) { | ||
var _target; | ||
return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body; | ||
return (_target = this.position.target) !== null && _target !== void 0 ? _target : instance.config.document.body; | ||
} | ||
startSelecting(config, clickCount) { | ||
startSelecting(instance, clickCount) { | ||
var ref, ref1; | ||
// TODO: support extending range (shift) | ||
this.selecting = selection.setSelectionPerMouseDown({ | ||
document: config.document, | ||
target: this.getTarget(config), | ||
this.selecting = setSelectionPerMouse.setSelectionPerMouseDown({ | ||
document: instance.config.document, | ||
target: this.getTarget(instance), | ||
node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node, | ||
@@ -142,3 +149,3 @@ offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset, | ||
} | ||
modifySelecting(config) { | ||
modifySelecting(instance) { | ||
var ref, ref1; | ||
@@ -148,5 +155,5 @@ if (!this.selecting) { | ||
} | ||
selection.modifySelectionPerMouseMove(this.selecting, { | ||
document: config.document, | ||
target: this.getTarget(config), | ||
modifySelectionPerMouse.modifySelectionPerMouseMove(this.selecting, { | ||
document: instance.config.document, | ||
target: this.getTarget(instance), | ||
node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node, | ||
@@ -153,0 +160,0 @@ offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset |
@@ -5,8 +5,6 @@ 'use strict'; | ||
var index = require('../../event/index.js'); | ||
require('../../utils/click/isClickableInput.js'); | ||
require('../../utils/dataTransfer/Clipboard.js'); | ||
require('../../utils/edit/isEditable.js'); | ||
require('../../utils/edit/maxLength.js'); | ||
require('../../utils/edit/isEditable.js'); | ||
require('@testing-library/dom'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -17,23 +15,23 @@ require('../../utils/keyDef/readNextDescriptor.js'); | ||
var cssPointerEvents = require('../../utils/pointer/cssPointerEvents.js'); | ||
var index$1 = require('./index.js'); | ||
var shared = require('./shared.js'); | ||
class Pointer { | ||
init(config, position) { | ||
init(instance, position) { | ||
this.position = position; | ||
const target = this.getTarget(config); | ||
const target = this.getTarget(instance); | ||
const [, enter] = getTreeDiff.getTreeDiff(null, target); | ||
const init = this.getEventInit(); | ||
cssPointerEvents.assertPointerEvents(config, target); | ||
index.dispatchUIEvent(config, target, 'pointerover', init); | ||
enter.forEach((el)=>index.dispatchUIEvent(config, el, 'pointerenter', init)); | ||
cssPointerEvents.assertPointerEvents(instance, target); | ||
instance.dispatchUIEvent(target, 'pointerover', init); | ||
enter.forEach((el)=>instance.dispatchUIEvent(el, 'pointerenter', init)); | ||
return this; | ||
} | ||
move(config, position) { | ||
move(instance, position) { | ||
const prevPosition = this.position; | ||
const prevTarget = this.getTarget(config); | ||
const prevTarget = this.getTarget(instance); | ||
this.position = position; | ||
if (!index$1.isDifferentPointerPosition(prevPosition, position)) { | ||
if (!shared.isDifferentPointerPosition(prevPosition, position)) { | ||
return; | ||
} | ||
const nextTarget = this.getTarget(config); | ||
const nextTarget = this.getTarget(instance); | ||
const init = this.getEventInit(); | ||
@@ -43,6 +41,6 @@ const [leave, enter] = getTreeDiff.getTreeDiff(prevTarget, nextTarget); | ||
leave: ()=>{ | ||
if (cssPointerEvents.hasPointerEvents(config, prevTarget)) { | ||
if (cssPointerEvents.hasPointerEvents(instance, prevTarget)) { | ||
if (prevTarget !== nextTarget) { | ||
index.dispatchUIEvent(config, prevTarget, 'pointerout', init); | ||
leave.forEach((el)=>index.dispatchUIEvent(config, el, 'pointerleave', init)); | ||
instance.dispatchUIEvent(prevTarget, 'pointerout', init); | ||
leave.forEach((el)=>instance.dispatchUIEvent(el, 'pointerleave', init)); | ||
} | ||
@@ -52,33 +50,33 @@ } | ||
enter: ()=>{ | ||
cssPointerEvents.assertPointerEvents(config, nextTarget); | ||
cssPointerEvents.assertPointerEvents(instance, nextTarget); | ||
if (prevTarget !== nextTarget) { | ||
index.dispatchUIEvent(config, nextTarget, 'pointerover', init); | ||
enter.forEach((el)=>index.dispatchUIEvent(config, el, 'pointerenter', init)); | ||
instance.dispatchUIEvent(nextTarget, 'pointerover', init); | ||
enter.forEach((el)=>instance.dispatchUIEvent(el, 'pointerenter', init)); | ||
} | ||
}, | ||
move: ()=>{ | ||
index.dispatchUIEvent(config, nextTarget, 'pointermove', init); | ||
instance.dispatchUIEvent(nextTarget, 'pointermove', init); | ||
} | ||
}; | ||
} | ||
down(config, _keyDef) { | ||
down(instance, _keyDef) { | ||
if (this.isDown) { | ||
return; | ||
} | ||
const target = this.getTarget(config); | ||
cssPointerEvents.assertPointerEvents(config, target); | ||
const target = this.getTarget(instance); | ||
cssPointerEvents.assertPointerEvents(instance, target); | ||
this.isDown = true; | ||
this.isPrevented = !index.dispatchUIEvent(config, target, 'pointerdown', this.getEventInit()); | ||
this.isPrevented = !instance.dispatchUIEvent(target, 'pointerdown', this.getEventInit()); | ||
} | ||
up(config, _keyDef) { | ||
up(instance, _keyDef) { | ||
if (!this.isDown) { | ||
return; | ||
} | ||
const target = this.getTarget(config); | ||
cssPointerEvents.assertPointerEvents(config, target); | ||
const target = this.getTarget(instance); | ||
cssPointerEvents.assertPointerEvents(instance, target); | ||
this.isDown = false; | ||
index.dispatchUIEvent(config, target, 'pointerup', this.getEventInit()); | ||
instance.dispatchUIEvent(target, 'pointerup', this.getEventInit()); | ||
} | ||
release(config) { | ||
const target = this.getTarget(config); | ||
release(instance) { | ||
const target = this.getTarget(instance); | ||
const [leave] = getTreeDiff.getTreeDiff(target, null); | ||
@@ -88,11 +86,11 @@ const init = this.getEventInit(); | ||
// make this check not use the *asserted* cached value from `up`. | ||
/* istanbul ignore else */ if (cssPointerEvents.hasPointerEvents(config, target)) { | ||
index.dispatchUIEvent(config, target, 'pointerout', init); | ||
leave.forEach((el)=>index.dispatchUIEvent(config, el, 'pointerleave', init)); | ||
/* istanbul ignore else */ if (cssPointerEvents.hasPointerEvents(instance, target)) { | ||
instance.dispatchUIEvent(target, 'pointerout', init); | ||
leave.forEach((el)=>instance.dispatchUIEvent(el, 'pointerleave', init)); | ||
} | ||
this.isCancelled = true; | ||
} | ||
getTarget(config) { | ||
getTarget(instance) { | ||
var _target; | ||
return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body; | ||
return (_target = this.position.target) !== null && _target !== void 0 ? _target : instance.config.document.body; | ||
} | ||
@@ -99,0 +97,0 @@ getEventInit() { |
@@ -5,6 +5,2 @@ 'use strict'; | ||
require('../setup/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
@@ -17,12 +13,15 @@ require('../event/behavior/cut.js'); | ||
require('@testing-library/dom'); | ||
var input = require('../utils/edit/input.js'); | ||
require('../event/eventMap.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
var isEditable = require('../utils/edit/isEditable.js'); | ||
var focus = require('../utils/focus/focus.js'); | ||
require('../utils/edit/maxLength.js'); | ||
var isDisabled = require('../utils/misc/isDisabled.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
var isDisabled = require('../utils/misc/isDisabled.js'); | ||
var selectAll = require('../utils/focus/selectAll.js'); | ||
require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../utils/misc/level.js'); | ||
require('../options.js'); | ||
var config = require('../setup/config.js'); | ||
var focus = require('../event/focus.js'); | ||
var input = require('../event/input.js'); | ||
var selectAll = require('../event/selection/selectAll.js'); | ||
@@ -33,3 +32,3 @@ async function clear(element) { | ||
} | ||
focus.focus(element); | ||
focus.focusElement(element); | ||
if (element.ownerDocument.activeElement !== element) { | ||
@@ -42,5 +41,5 @@ throw new Error('The element to be cleared could not be focused.'); | ||
} | ||
input.input(this[config.Config], element, '', 'deleteContentBackward'); | ||
input.input(this, element, '', 'deleteContentBackward'); | ||
} | ||
exports.clear = clear; |
@@ -8,3 +8,11 @@ 'use strict'; | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
var isElementType = require('../utils/misc/isElementType.js'); | ||
var isDisabled = require('../utils/misc/isDisabled.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../utils/misc/level.js'); | ||
var wait = require('../utils/misc/wait.js'); | ||
var cssPointerEvents = require('../utils/pointer/cssPointerEvents.js'); | ||
require('../event/behavior/click.js'); | ||
@@ -16,14 +24,4 @@ require('../event/behavior/cut.js'); | ||
require('../event/behavior/paste.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
var focus = require('../utils/focus/focus.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
var isDisabled = require('../utils/misc/isDisabled.js'); | ||
var isElementType = require('../utils/misc/isElementType.js'); | ||
require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../utils/misc/level.js'); | ||
var wait = require('../utils/misc/wait.js'); | ||
var cssPointerEvents = require('../utils/pointer/cssPointerEvents.js'); | ||
require('../setup/index.js'); | ||
var config = require('../setup/config.js'); | ||
require('../event/eventMap.js'); | ||
var focus = require('../event/focus.js'); | ||
@@ -69,3 +67,3 @@ async function selectOptions(select, values) { | ||
for (const option of selectedOptions){ | ||
const withPointerEvents = this[config.Config].pointerEventsCheck === 0 ? true : cssPointerEvents.hasPointerEvents(this[config.Config], option); | ||
const withPointerEvents = this.config.pointerEventsCheck === 0 ? true : cssPointerEvents.hasPointerEvents(this, option); | ||
// events fired for multiple select are weird. Can't use hover... | ||
@@ -82,3 +80,3 @@ if (withPointerEvents) { | ||
} | ||
focus.focus(select); | ||
focus.focusElement(select); | ||
if (withPointerEvents) { | ||
@@ -92,6 +90,6 @@ this.dispatchUIEvent(option, 'pointerup'); | ||
} | ||
await wait.wait(this[config.Config]); | ||
await wait.wait(this.config); | ||
} | ||
} else if (selectedOptions.length === 1) { | ||
const withPointerEvents1 = this[config.Config].pointerEventsCheck === 0 ? true : cssPointerEvents.hasPointerEvents(this[config.Config], select); | ||
const withPointerEvents1 = this.config.pointerEventsCheck === 0 ? true : cssPointerEvents.hasPointerEvents(this, select); | ||
// the click to open the select options | ||
@@ -101,3 +99,3 @@ if (withPointerEvents1) { | ||
} else { | ||
focus.focus(select); | ||
focus.focusElement(select); | ||
} | ||
@@ -116,3 +114,3 @@ selectOption(selectedOptions[0]); | ||
} | ||
await wait.wait(this[config.Config]); | ||
await wait.wait(this.config); | ||
} else { | ||
@@ -119,0 +117,0 @@ throw dom.getConfig().getElementError(`Cannot select multiple options on a non-multiple select`, select); |
@@ -5,15 +5,7 @@ 'use strict'; | ||
var index = require('../keyboard/index.js'); | ||
require('../utils/click/isClickableInput.js'); | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
var selection = require('../utils/focus/selection.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
@@ -23,6 +15,5 @@ require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../options.js'); | ||
var index = require('../keyboard/index.js'); | ||
var config = require('../setup/config.js'); | ||
var setSelectionRange = require('../event/selection/setSelectionRange.js'); | ||
async function type(element, text, { skipClick =this[config.Config].skipClick , skipAutoClose =this[config.Config].skipAutoClose , initialSelectionStart , initialSelectionEnd } = {}) { | ||
async function type(element, text, { skipClick =this.config.skipClick , skipAutoClose =this.config.skipAutoClose , initialSelectionStart , initialSelectionEnd } = {}) { | ||
// TODO: properly type guard | ||
@@ -35,7 +26,7 @@ // we use this workaround for now to prevent changing behavior | ||
if (initialSelectionStart !== undefined) { | ||
selection.setSelectionRange(element, initialSelectionStart, initialSelectionEnd !== null && initialSelectionEnd !== void 0 ? initialSelectionEnd : initialSelectionStart); | ||
setSelectionRange.setSelectionRange(element, initialSelectionStart, initialSelectionEnd !== null && initialSelectionEnd !== void 0 ? initialSelectionEnd : initialSelectionStart); | ||
} | ||
await this.keyboard(text); | ||
if (!skipAutoClose) { | ||
await index.releaseAllKeys(this[config.Config]); | ||
await index.releaseAllKeys(this); | ||
} | ||
@@ -42,0 +33,0 @@ } |
@@ -8,15 +8,7 @@ 'use strict'; | ||
require('../utils/dataTransfer/Clipboard.js'); | ||
require('../event/eventMap.js'); | ||
require('../event/behavior/click.js'); | ||
require('../event/behavior/cut.js'); | ||
require('../event/behavior/keydown.js'); | ||
require('../event/behavior/keypress.js'); | ||
require('../event/behavior/keyup.js'); | ||
require('../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../utils/edit/isEditable.js'); | ||
require('../utils/edit/maxLength.js'); | ||
require('../utils/edit/isEditable.js'); | ||
var setFiles = require('../utils/edit/setFiles.js'); | ||
var isElementType = require('../utils/misc/isElementType.js'); | ||
var isDisabled = require('../utils/misc/isDisabled.js'); | ||
var isElementType = require('../utils/misc/isElementType.js'); | ||
var getWindow = require('../utils/misc/getWindow.js'); | ||
@@ -26,4 +18,2 @@ require('../utils/keyDef/readNextDescriptor.js'); | ||
require('../options.js'); | ||
require('../setup/index.js'); | ||
var config = require('../setup/config.js'); | ||
@@ -40,3 +30,3 @@ async function upload(element, fileOrFiles) { | ||
fileOrFiles | ||
]).filter((file)=>!this[config.Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); | ||
]).filter((file)=>!this.config.applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); | ||
const fileDialog = ()=>{ | ||
@@ -43,0 +33,0 @@ var ref; |
@@ -5,19 +5,5 @@ 'use strict'; | ||
require('../click/isClickableInput.js'); | ||
var getWindow = require('../misc/getWindow.js'); | ||
var Blob = require('./Blob.js'); | ||
var DataTransfer = require('./DataTransfer.js'); | ||
require('../../event/eventMap.js'); | ||
require('../../event/behavior/click.js'); | ||
require('../../event/behavior/cut.js'); | ||
require('../../event/behavior/keydown.js'); | ||
require('../../event/behavior/keypress.js'); | ||
require('../../event/behavior/keyup.js'); | ||
require('../../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../edit/maxLength.js'); | ||
require('../edit/isEditable.js'); | ||
var getWindow = require('../misc/getWindow.js'); | ||
require('../keyDef/readNextDescriptor.js'); | ||
require('../misc/level.js'); | ||
require('../../options.js'); | ||
@@ -24,0 +10,0 @@ // Clipboard is not available in jsdom |
@@ -9,7 +9,5 @@ 'use strict'; | ||
function isEditable(element) { | ||
return isEditableInput(element) || isElementType.isElementType(element, 'textarea', { | ||
readOnly: false | ||
}) || isContentEditable.isContentEditable(element); | ||
return isEditableInputOrTextArea(element) && !element.readOnly || isContentEditable.isContentEditable(element); | ||
} | ||
exports.editableInputTypes = void 0; | ||
var editableInputTypes; | ||
(function(editableInputTypes) { | ||
@@ -28,10 +26,8 @@ editableInputTypes['text'] = 'text'; | ||
editableInputTypes['week'] = 'week'; | ||
})(exports.editableInputTypes || (exports.editableInputTypes = {})); | ||
function isEditableInput(element) { | ||
return isElementType.isElementType(element, 'input', { | ||
readOnly: false | ||
}) && Boolean(exports.editableInputTypes[element.type]); | ||
})(editableInputTypes || (editableInputTypes = {})); | ||
function isEditableInputOrTextArea(element) { | ||
return isElementType.isElementType(element, 'textarea') || isElementType.isElementType(element, 'input') && element.type in editableInputTypes; | ||
} | ||
exports.isEditable = isEditable; | ||
exports.isEditableInput = isEditableInput; | ||
exports.isEditableInputOrTextArea = isEditableInputOrTextArea; |
@@ -6,3 +6,2 @@ 'use strict'; | ||
var isElementType = require('../misc/isElementType.js'); | ||
var getValue = require('./getValue.js'); | ||
@@ -18,16 +17,5 @@ var maxLengthSupportedTypes; | ||
})(maxLengthSupportedTypes || (maxLengthSupportedTypes = {})); | ||
function getSpaceUntilMaxLength(element) { | ||
const value = getValue.getValue(element); | ||
/* istanbul ignore if */ if (value === null) { | ||
return undefined; | ||
} | ||
const maxLength = getSanitizedMaxLength(element); | ||
return maxLength ? maxLength - value.length : undefined; | ||
} | ||
// can't use .maxLength property because of a jsdom bug: | ||
// https://github.com/jsdom/jsdom/issues/2927 | ||
function getSanitizedMaxLength(element) { | ||
if (!supportsMaxLength(element)) { | ||
return undefined; | ||
} | ||
function getMaxLength(element) { | ||
var ref; | ||
@@ -38,5 +26,6 @@ const attr = (ref = element.getAttribute('maxlength')) !== null && ref !== void 0 ? ref : ''; | ||
function supportsMaxLength(element) { | ||
return isElementType.isElementType(element, 'textarea') || isElementType.isElementType(element, 'input') && Boolean(maxLengthSupportedTypes[element.type]); | ||
return isElementType.isElementType(element, 'textarea') || isElementType.isElementType(element, 'input') && element.type in maxLengthSupportedTypes; | ||
} | ||
exports.getSpaceUntilMaxLength = getSpaceUntilMaxLength; | ||
exports.getMaxLength = getMaxLength; | ||
exports.supportsMaxLength = supportsMaxLength; |
@@ -5,20 +5,4 @@ 'use strict'; | ||
require('../click/isClickableInput.js'); | ||
require('../dataTransfer/Clipboard.js'); | ||
require('../../event/eventMap.js'); | ||
require('../../event/behavior/click.js'); | ||
require('../../event/behavior/cut.js'); | ||
require('../../event/behavior/keydown.js'); | ||
require('../../event/behavior/keypress.js'); | ||
require('../../event/behavior/keyup.js'); | ||
require('../../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
var isContentEditable = require('../edit/isContentEditable.js'); | ||
require('../edit/maxLength.js'); | ||
require('../edit/isEditable.js'); | ||
var isElementType = require('../misc/isElementType.js'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
require('../keyDef/readNextDescriptor.js'); | ||
require('../misc/level.js'); | ||
require('../../options.js'); | ||
@@ -25,0 +9,0 @@ function getNextCursorPosition(node, offset, direction, inputType) { |
@@ -5,52 +5,10 @@ 'use strict'; | ||
var isElementType = require('../misc/isElementType.js'); | ||
var isClickableInput = require('../click/isClickableInput.js'); | ||
require('../dataTransfer/Clipboard.js'); | ||
var isContentEditable = require('../edit/isContentEditable.js'); | ||
require('../edit/maxLength.js'); | ||
var isEditable = require('../edit/isEditable.js'); | ||
require('@testing-library/dom'); | ||
require('@testing-library/dom/dist/helpers.js'); | ||
var cursor = require('./cursor.js'); | ||
var resolveCaretPosition = require('./resolveCaretPosition.js'); | ||
require('../keyDef/readNextDescriptor.js'); | ||
require('../misc/level.js'); | ||
require('../../options.js'); | ||
require('../../event/eventMap.js'); | ||
require('../../event/behavior/click.js'); | ||
require('../../event/behavior/cut.js'); | ||
require('../../event/behavior/keydown.js'); | ||
require('../../event/behavior/keypress.js'); | ||
require('../../event/behavior/keyup.js'); | ||
require('../../event/behavior/paste.js'); | ||
var selection = require('../../document/selection.js'); | ||
var value = require('../../document/value.js'); | ||
/** | ||
* Backward-compatible selection. | ||
* | ||
* Handles input elements and contenteditable if it only contains a single text node. | ||
*/ function setSelectionRange(element, anchorOffset, focusOffset) { | ||
var ref; | ||
if (hasOwnSelection(element)) { | ||
return setSelection({ | ||
focusNode: element, | ||
anchorOffset, | ||
focusOffset | ||
}); | ||
} | ||
/* istanbul ignore else */ if (isContentEditable.isContentEditable(element) && ((ref = element.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3) { | ||
return setSelection({ | ||
focusNode: element.firstChild, | ||
anchorOffset, | ||
focusOffset | ||
}); | ||
} | ||
/* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.'); | ||
} | ||
/** | ||
* Determine if the element has its own selection implementation | ||
* and does not interact with the Document Selection API. | ||
*/ function hasOwnSelection(node) { | ||
return isElement(node) && (isElementType.isElementType(node, 'textarea') || isElementType.isElementType(node, 'input') && node.type in isEditable.editableInputTypes); | ||
return isElement(node) && isEditable.isEditableInputOrTextArea(node); | ||
} | ||
@@ -63,232 +21,4 @@ function hasNoSelection(node) { | ||
} | ||
/** | ||
* Determine which selection logic and selection ranges to consider. | ||
*/ function getTargetTypeAndSelection(node) { | ||
const element = getElement(node); | ||
if (element && hasOwnSelection(element)) { | ||
return { | ||
type: 'input', | ||
selection: selection.getUISelection(element) | ||
}; | ||
} | ||
const selection$1 = element === null || element === void 0 ? void 0 : element.ownerDocument.getSelection(); | ||
// It is possible to extend a single-range selection into a contenteditable. | ||
// This results in the range acting like a range outside of contenteditable. | ||
const isCE = isContentEditable.getContentEditable(node) && (selection$1 === null || selection$1 === void 0 ? void 0 : selection$1.anchorNode) && isContentEditable.getContentEditable(selection$1.anchorNode); | ||
return { | ||
type: isCE ? 'contenteditable' : 'default', | ||
selection: selection$1 | ||
}; | ||
} | ||
function getElement(node) { | ||
return node.nodeType === 1 ? node : node.parentElement; | ||
} | ||
/** | ||
* Reset the Document Selection when moving focus into an element | ||
* with own selection implementation. | ||
*/ function updateSelectionOnFocus(element) { | ||
const selection = element.ownerDocument.getSelection(); | ||
/* istanbul ignore if */ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) { | ||
return; | ||
} | ||
// If the focus moves inside an element with own selection implementation, | ||
// the document selection will be this element. | ||
// But if the focused element is inside a contenteditable, | ||
// 1) a collapsed selection will be retained. | ||
// 2) other selections will be replaced by a cursor | ||
// 2.a) at the start of the first child if it is a text node | ||
// 2.b) at the start of the contenteditable. | ||
if (hasOwnSelection(element)) { | ||
const contenteditable = isContentEditable.getContentEditable(selection.focusNode); | ||
if (contenteditable) { | ||
if (!selection.isCollapsed) { | ||
var ref; | ||
const focusNode = ((ref = contenteditable.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3 ? contenteditable.firstChild : contenteditable; | ||
selection.setBaseAndExtent(focusNode, 0, focusNode, 0); | ||
} | ||
} else { | ||
selection.setBaseAndExtent(element, 0, element, 0); | ||
} | ||
} | ||
} | ||
/** | ||
* Get the range that would be overwritten by input. | ||
*/ function getInputRange(focusNode) { | ||
const typeAndSelection = getTargetTypeAndSelection(focusNode); | ||
if (typeAndSelection.type === 'input') { | ||
return typeAndSelection.selection; | ||
} else if (typeAndSelection.type === 'contenteditable') { | ||
var ref; | ||
// Multi-range on contenteditable edits the first selection instead of the last | ||
return (ref = typeAndSelection.selection) === null || ref === void 0 ? void 0 : ref.getRangeAt(0); | ||
} | ||
} | ||
/** | ||
* Extend/shrink the selection like with Shift+Arrows or Shift+Mouse | ||
*/ function modifySelection({ focusNode , focusOffset }) { | ||
var ref, ref1; | ||
const typeAndSelection = getTargetTypeAndSelection(focusNode); | ||
if (typeAndSelection.type === 'input') { | ||
return selection.setUISelection(focusNode, { | ||
anchorOffset: typeAndSelection.selection.anchorOffset, | ||
focusOffset | ||
}, 'modify'); | ||
} | ||
(ref1 = (ref = focusNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.extend(focusNode, focusOffset); | ||
} | ||
/** | ||
* Set the selection | ||
*/ function setSelection({ focusNode , focusOffset , anchorNode =focusNode , anchorOffset =focusOffset }) { | ||
var ref, ref1; | ||
const typeAndSelection = getTargetTypeAndSelection(focusNode); | ||
if (typeAndSelection.type === 'input') { | ||
return selection.setUISelection(focusNode, { | ||
anchorOffset, | ||
focusOffset | ||
}); | ||
} | ||
(ref1 = (ref = anchorNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset); | ||
} | ||
/** | ||
* Move the selection | ||
*/ function moveSelection(node, direction) { | ||
// TODO: implement shift | ||
if (hasOwnSelection(node)) { | ||
const selection$1 = selection.getUISelection(node); | ||
setSelection({ | ||
focusNode: node, | ||
focusOffset: selection$1.startOffset === selection$1.endOffset ? selection$1.focusOffset + direction : direction < 0 ? selection$1.startOffset : selection$1.endOffset | ||
}); | ||
} else { | ||
const selection1 = node.ownerDocument.getSelection(); | ||
if (!(selection1 === null || selection1 === void 0 ? void 0 : selection1.focusNode)) { | ||
return; | ||
} | ||
if (selection1.isCollapsed) { | ||
const nextPosition = cursor.getNextCursorPosition(selection1.focusNode, selection1.focusOffset, direction); | ||
if (nextPosition) { | ||
setSelection({ | ||
focusNode: nextPosition.node, | ||
focusOffset: nextPosition.offset | ||
}); | ||
} | ||
} else { | ||
selection1[direction < 0 ? 'collapseToStart' : 'collapseToEnd'](); | ||
} | ||
} | ||
} | ||
function setSelectionPerMouseDown({ document , target , clickCount , node , offset }) { | ||
if (hasNoSelection(target)) { | ||
return; | ||
} | ||
const targetHasOwnSelection = hasOwnSelection(target); | ||
// On non-input elements the text selection per multiple click | ||
// can extend beyond the target boundaries. | ||
// The exact mechanism what is considered in the same line is unclear. | ||
// Looks it might be every inline element. | ||
// TODO: Check what might be considered part of the same line of text. | ||
const text = String(targetHasOwnSelection ? value.getUIValue(target) : target.textContent); | ||
const [start, end] = node ? // which elements might be considered in the same line of text. | ||
// TODO: support expanding initial range on multiple clicks if node is given | ||
[ | ||
offset, | ||
offset | ||
] : getTextRange(text, offset, clickCount); | ||
// TODO: implement modifying selection per shift/ctrl+mouse | ||
if (targetHasOwnSelection) { | ||
selection.setUISelection(target, { | ||
anchorOffset: start !== null && start !== void 0 ? start : text.length, | ||
focusOffset: end !== null && end !== void 0 ? end : text.length | ||
}); | ||
return { | ||
node: target, | ||
start: start !== null && start !== void 0 ? start : 0, | ||
end: end !== null && end !== void 0 ? end : text.length | ||
}; | ||
} else { | ||
const { node: startNode , offset: startOffset } = resolveCaretPosition.resolveCaretPosition({ | ||
target, | ||
node, | ||
offset: start | ||
}); | ||
const { node: endNode , offset: endOffset } = resolveCaretPosition.resolveCaretPosition({ | ||
target, | ||
node, | ||
offset: end | ||
}); | ||
const range = target.ownerDocument.createRange(); | ||
try { | ||
range.setStart(startNode, startOffset); | ||
range.setEnd(endNode, endOffset); | ||
} catch (e) { | ||
throw new Error('The given offset is out of bounds.'); | ||
} | ||
const selection = document.getSelection(); | ||
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges(); | ||
selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange()); | ||
return range; | ||
} | ||
} | ||
function getTextRange(text, pos, clickCount) { | ||
if (clickCount % 3 === 1 || text.length === 0) { | ||
return [ | ||
pos, | ||
pos | ||
]; | ||
} | ||
const textPos = pos !== null && pos !== void 0 ? pos : text.length; | ||
if (clickCount % 3 === 2) { | ||
return [ | ||
textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length, | ||
pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length, | ||
]; | ||
} | ||
// triple click | ||
return [ | ||
textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length, | ||
pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length, | ||
]; | ||
} | ||
function modifySelectionPerMouseMove(selectionRange, { document , target , node , offset }) { | ||
const selectionFocus = resolveCaretPosition.resolveCaretPosition({ | ||
target, | ||
node, | ||
offset | ||
}); | ||
if ('node' in selectionRange) { | ||
// When the mouse is dragged outside of an input/textarea, | ||
// the selection is extended to the beginning or end of the input | ||
// depending on pointer position. | ||
// TODO: extend selection according to pointer position | ||
/* istanbul ignore else */ if (selectionFocus.node === selectionRange.node) { | ||
const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start; | ||
const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end; | ||
selection.setUISelection(selectionRange.node, { | ||
anchorOffset, | ||
focusOffset | ||
}); | ||
} | ||
} else { | ||
const range = selectionRange.cloneRange(); | ||
const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset); | ||
if (cmp < 0) { | ||
range.setStart(selectionFocus.node, selectionFocus.offset); | ||
} else if (cmp > 0) { | ||
range.setEnd(selectionFocus.node, selectionFocus.offset); | ||
} | ||
const selection = document.getSelection(); | ||
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges(); | ||
selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange()); | ||
} | ||
} | ||
exports.getInputRange = getInputRange; | ||
exports.hasNoSelection = hasNoSelection; | ||
exports.hasOwnSelection = hasOwnSelection; | ||
exports.modifySelection = modifySelection; | ||
exports.modifySelectionPerMouseMove = modifySelectionPerMouseMove; | ||
exports.moveSelection = moveSelection; | ||
exports.setSelection = setSelection; | ||
exports.setSelectionPerMouseDown = setSelectionPerMouseDown; | ||
exports.setSelectionRange = setSelectionRange; | ||
exports.updateSelectionOnFocus = updateSelectionOnFocus; |
@@ -10,17 +10,11 @@ 'use strict'; | ||
var Clipboard = require('./dataTransfer/Clipboard.js'); | ||
var getValue = require('./edit/getValue.js'); | ||
var input = require('./edit/input.js'); | ||
var timeValue = require('./edit/timeValue.js'); | ||
var isContentEditable = require('./edit/isContentEditable.js'); | ||
var isEditable = require('./edit/isEditable.js'); | ||
var maxLength = require('./edit/maxLength.js'); | ||
var setFiles = require('./edit/setFiles.js'); | ||
var walkRadio = require('./edit/walkRadio.js'); | ||
var blur = require('./focus/blur.js'); | ||
var copySelection = require('./focus/copySelection.js'); | ||
var cursor = require('./focus/cursor.js'); | ||
var focus = require('./focus/focus.js'); | ||
var getActiveElement = require('./focus/getActiveElement.js'); | ||
var getTabDestination = require('./focus/getTabDestination.js'); | ||
var isFocusable = require('./focus/isFocusable.js'); | ||
var selectAll = require('./focus/selectAll.js'); | ||
var resolveCaretPosition = require('./focus/resolveCaretPosition.js'); | ||
var selection = require('./focus/selection.js'); | ||
@@ -30,3 +24,2 @@ var selector = require('./focus/selector.js'); | ||
var cloneEvent = require('./misc/cloneEvent.js'); | ||
var eventWrapper = require('./misc/eventWrapper.js'); | ||
var findClosest = require('./misc/findClosest.js'); | ||
@@ -57,18 +50,12 @@ var getDocumentFromNode = require('./misc/getDocumentFromNode.js'); | ||
exports.writeDataTransferToClipboard = Clipboard.writeDataTransferToClipboard; | ||
exports.getValue = getValue.getValue; | ||
exports.input = input.input; | ||
exports.buildTimeValue = timeValue.buildTimeValue; | ||
exports.isValidDateOrTimeValue = timeValue.isValidDateOrTimeValue; | ||
exports.getContentEditable = isContentEditable.getContentEditable; | ||
exports.isContentEditable = isContentEditable.isContentEditable; | ||
Object.defineProperty(exports, 'editableInputTypes', { | ||
enumerable: true, | ||
get: function () { return isEditable.editableInputTypes; } | ||
}); | ||
exports.isEditable = isEditable.isEditable; | ||
exports.isEditableInput = isEditable.isEditableInput; | ||
exports.isEditableInputOrTextArea = isEditable.isEditableInputOrTextArea; | ||
exports.getMaxLength = maxLength.getMaxLength; | ||
exports.supportsMaxLength = maxLength.supportsMaxLength; | ||
exports.setFiles = setFiles.setFiles; | ||
exports.walkRadio = walkRadio.walkRadio; | ||
exports.blur = blur.blur; | ||
exports.copySelection = copySelection.copySelection; | ||
exports.getNextCursorPosition = cursor.getNextCursorPosition; | ||
exports.focus = focus.focus; | ||
exports.getActiveElement = getActiveElement.getActiveElement; | ||
@@ -78,19 +65,7 @@ exports.getActiveElementOrBody = getActiveElement.getActiveElementOrBody; | ||
exports.isFocusable = isFocusable.isFocusable; | ||
exports.isAllSelected = selectAll.isAllSelected; | ||
exports.selectAll = selectAll.selectAll; | ||
exports.resolveCaretPosition = resolveCaretPosition.resolveCaretPosition; | ||
exports.getInputRange = selection.getInputRange; | ||
exports.hasNoSelection = selection.hasNoSelection; | ||
exports.hasOwnSelection = selection.hasOwnSelection; | ||
exports.modifySelection = selection.modifySelection; | ||
exports.modifySelectionPerMouseMove = selection.modifySelectionPerMouseMove; | ||
exports.moveSelection = selection.moveSelection; | ||
exports.setSelection = selection.setSelection; | ||
exports.setSelectionPerMouseDown = selection.setSelectionPerMouseDown; | ||
exports.setSelectionRange = selection.setSelectionRange; | ||
exports.updateSelectionOnFocus = selection.updateSelectionOnFocus; | ||
exports.FOCUSABLE_SELECTOR = selector.FOCUSABLE_SELECTOR; | ||
exports.readNextDescriptor = readNextDescriptor.readNextDescriptor; | ||
exports.cloneEvent = cloneEvent.cloneEvent; | ||
exports.eventWrapper = eventWrapper.eventWrapper; | ||
exports.findClosest = findClosest.findClosest; | ||
@@ -97,0 +72,0 @@ exports.getDocumentFromNode = getDocumentFromNode.getDocumentFromNode; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var _config, _Level; | ||
exports.ApiLevel = void 0; | ||
@@ -12,11 +11,7 @@ (function(ApiLevel) { | ||
})(exports.ApiLevel || (exports.ApiLevel = {})); | ||
const Level = Symbol('Api level refs'); | ||
function setLevelRef(config, level) { | ||
var ref; | ||
(ref = (_config = config)[_Level = Level]) !== null && ref !== void 0 ? ref : _config[_Level] = {}; | ||
config[Level][level] = {}; | ||
function setLevelRef(instance, level) { | ||
instance.levelRefs[level] = {}; | ||
} | ||
function getLevelRef(config, level) { | ||
var ref; | ||
return (ref = config[Level]) === null || ref === void 0 ? void 0 : ref[level]; | ||
function getLevelRef(instance, level) { | ||
return instance.levelRefs[level]; | ||
} | ||
@@ -23,0 +18,0 @@ |
@@ -6,22 +6,9 @@ 'use strict'; | ||
var options = require('../../options.js'); | ||
require('../click/isClickableInput.js'); | ||
require('../dataTransfer/Clipboard.js'); | ||
require('../../event/eventMap.js'); | ||
require('../../event/behavior/click.js'); | ||
require('../../event/behavior/cut.js'); | ||
require('../../event/behavior/keydown.js'); | ||
require('../../event/behavior/keypress.js'); | ||
require('../../event/behavior/keyup.js'); | ||
require('../../event/behavior/paste.js'); | ||
require('@testing-library/dom'); | ||
require('../edit/maxLength.js'); | ||
require('../edit/isEditable.js'); | ||
var getWindow = require('../misc/getWindow.js'); | ||
var isElementType = require('../misc/isElementType.js'); | ||
var getWindow = require('../misc/getWindow.js'); | ||
require('../keyDef/readNextDescriptor.js'); | ||
var level = require('../misc/level.js'); | ||
function hasPointerEvents(config, element) { | ||
function hasPointerEvents(instance, element) { | ||
var ref; | ||
return ((ref = checkPointerEvents(config, element)) === null || ref === void 0 ? void 0 : ref.pointerEvents) !== 'none'; | ||
return ((ref = checkPointerEvents(instance, element)) === null || ref === void 0 ? void 0 : ref.pointerEvents) !== 'none'; | ||
} | ||
@@ -46,5 +33,5 @@ function closestPointerEventsDeclaration(element) { | ||
const PointerEventsCheck = Symbol('Last check for pointer-events'); | ||
function checkPointerEvents(config, element) { | ||
function checkPointerEvents(instance, element) { | ||
const lastCheck = element[PointerEventsCheck]; | ||
const needsCheck = config.pointerEventsCheck !== options.PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(config.pointerEventsCheck, options.PointerEventsCheckLevel.EachApiCall) && lastCheck[level.ApiLevel.Call] !== level.getLevelRef(config, level.ApiLevel.Call) || hasBitFlag(config.pointerEventsCheck, options.PointerEventsCheckLevel.EachTrigger) && lastCheck[level.ApiLevel.Trigger] !== level.getLevelRef(config, level.ApiLevel.Trigger)); | ||
const needsCheck = instance.config.pointerEventsCheck !== options.PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(instance.config.pointerEventsCheck, options.PointerEventsCheckLevel.EachApiCall) && lastCheck[level.ApiLevel.Call] !== level.getLevelRef(instance, level.ApiLevel.Call) || hasBitFlag(instance.config.pointerEventsCheck, options.PointerEventsCheckLevel.EachTrigger) && lastCheck[level.ApiLevel.Trigger] !== level.getLevelRef(instance, level.ApiLevel.Trigger)); | ||
if (!needsCheck) { | ||
@@ -55,4 +42,4 @@ return lastCheck === null || lastCheck === void 0 ? void 0 : lastCheck.result; | ||
element[PointerEventsCheck] = { | ||
[level.ApiLevel.Call]: level.getLevelRef(config, level.ApiLevel.Call), | ||
[level.ApiLevel.Trigger]: level.getLevelRef(config, level.ApiLevel.Trigger), | ||
[level.ApiLevel.Call]: level.getLevelRef(instance, level.ApiLevel.Call), | ||
[level.ApiLevel.Trigger]: level.getLevelRef(instance, level.ApiLevel.Trigger), | ||
result: declaration | ||
@@ -62,4 +49,4 @@ }; | ||
} | ||
function assertPointerEvents(config, element) { | ||
const declaration = checkPointerEvents(config, element); | ||
function assertPointerEvents(instance, element) { | ||
const declaration = checkPointerEvents(instance, element); | ||
if ((declaration === null || declaration === void 0 ? void 0 : declaration.pointerEvents) === 'none') { | ||
@@ -66,0 +53,0 @@ throw new Error([ |
@@ -1,23 +0,13 @@ | ||
import '../setup/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import { copySelection } from '../utils/focus/copySelection.js'; | ||
import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../utils/misc/level.js'; | ||
import '../options.js'; | ||
import { Config } from '../setup/config.js'; | ||
import { copySelection } from '../document/copySelection.js'; | ||
async function copy() { | ||
const doc = this[Config].document; | ||
const doc = this.config.document; | ||
var _activeElement; | ||
@@ -31,3 +21,3 @@ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body; | ||
clipboardData | ||
}) && this[Config].writeToClipboard) { | ||
}) && this.config.writeToClipboard) { | ||
await writeDataTransferToClipboard(doc, clipboardData); | ||
@@ -34,0 +24,0 @@ } |
@@ -1,23 +0,13 @@ | ||
import '../setup/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import { copySelection } from '../utils/focus/copySelection.js'; | ||
import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../utils/misc/level.js'; | ||
import '../options.js'; | ||
import { Config } from '../setup/config.js'; | ||
import { copySelection } from '../document/copySelection.js'; | ||
async function cut() { | ||
const doc = this[Config].document; | ||
const doc = this.config.document; | ||
var _activeElement; | ||
@@ -31,3 +21,3 @@ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body; | ||
clipboardData | ||
}) && this[Config].writeToClipboard) { | ||
}) && this.config.writeToClipboard) { | ||
await writeDataTransferToClipboard(target.ownerDocument, clipboardData); | ||
@@ -34,0 +24,0 @@ } |
@@ -1,15 +0,6 @@ | ||
import '../setup/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import { createDataTransfer } from '../utils/dataTransfer/DataTransfer.js'; | ||
import { readDataTransferFromClipboard } from '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import { getWindow } from '../utils/misc/getWindow.js'; | ||
@@ -19,6 +10,5 @@ import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../options.js'; | ||
import { Config } from '../setup/config.js'; | ||
async function paste(clipboardData) { | ||
const doc = this[Config].document; | ||
const doc = this.config.document; | ||
var _activeElement; | ||
@@ -25,0 +15,0 @@ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body; |
@@ -1,7 +0,4 @@ | ||
import '../setup/index.js'; | ||
import { Config } from '../setup/config.js'; | ||
async function click(element) { | ||
const pointerIn = []; | ||
if (!this[Config].skipHover) { | ||
if (!this.config.skipHover) { | ||
pointerIn.push({ | ||
@@ -8,0 +5,0 @@ target: element |
@@ -1,14 +0,5 @@ | ||
import '../setup/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -18,3 +9,2 @@ import '../utils/keyDef/readNextDescriptor.js'; | ||
import { assertPointerEvents } from '../utils/pointer/cssPointerEvents.js'; | ||
import { Config } from '../setup/config.js'; | ||
@@ -27,3 +17,3 @@ async function hover(element) { | ||
async function unhover(element) { | ||
assertPointerEvents(this[Config], this[Config].system.pointer.getMouseTarget(this[Config])); | ||
assertPointerEvents(this, this.system.pointer.getMouseTarget(this)); | ||
return this.pointer({ | ||
@@ -30,0 +20,0 @@ target: element.ownerDocument.body |
@@ -1,66 +0,4 @@ | ||
import { dispatchUIEvent } from '../event/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom'; | ||
import { isElementType } from '../utils/misc/isElementType.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../utils/misc/level.js'; | ||
import '../options.js'; | ||
import { prepareSelectionInterceptor } from './selection.js'; | ||
export { getUISelection, setUISelection } from './selection.js'; | ||
import { prepareRangeTextInterceptor } from './setRangeText.js'; | ||
import { getInitialValue, clearInitialValue, prepareValueInterceptor } from './value.js'; | ||
export { clearInitialValue, commitValueAfterInput, getUIValue, setUIValue } from './value.js'; | ||
const isPrepared = Symbol('Node prepared with document state workarounds'); | ||
function prepareDocument(document) { | ||
if (document[isPrepared]) { | ||
return; | ||
} | ||
document.addEventListener('focus', (e)=>{ | ||
const el = e.target; | ||
prepareElement(el); | ||
}, { | ||
capture: true, | ||
passive: true | ||
}); | ||
// Our test environment defaults to `document.body` as `activeElement`. | ||
// In other environments this might be `null` when preparing. | ||
// istanbul ignore else | ||
if (document.activeElement) { | ||
prepareElement(document.activeElement); | ||
} | ||
document.addEventListener('blur', (e)=>{ | ||
const el = e.target; | ||
const initialValue = getInitialValue(el); | ||
if (initialValue !== undefined) { | ||
if (el.value !== initialValue) { | ||
dispatchUIEvent({}, el, 'change'); | ||
} | ||
clearInitialValue(el); | ||
} | ||
}, { | ||
capture: true, | ||
passive: true | ||
}); | ||
document[isPrepared] = isPrepared; | ||
} | ||
function prepareElement(el) { | ||
if (el[isPrepared]) { | ||
return; | ||
} | ||
if (isElementType(el, [ | ||
'input', | ||
'textarea' | ||
])) { | ||
prepareValueInterceptor(el); | ||
prepareSelectionInterceptor(el); | ||
prepareRangeTextInterceptor(el); | ||
} | ||
el[isPrepared] = isPrepared; | ||
} | ||
export { prepareDocument }; | ||
export { clearInitialValue, getUISelection, getUIValue, setUISelection, setUIValue } from './UI.js'; | ||
export { getValueOrTextContent } from './getValueOrTextContent.js'; | ||
export { copySelection } from './copySelection.js'; | ||
export { commitValueAfterInput } from './trackValue.js'; |
@@ -0,1 +1,13 @@ | ||
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 '@testing-library/dom/dist/helpers.js'; | ||
import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../utils/misc/level.js'; | ||
import '../options.js'; | ||
import { startTrackValue, trackOrSetValue } from './trackValue.js'; | ||
import { setUISelectionClean, setUISelectionRaw, getUIValue, setUIValueClean, isUIValue, isUISelectionStart } from './UI.js'; | ||
const Interceptor = Symbol('Interceptor for programmatical calls'); | ||
@@ -25,3 +37,71 @@ function prepareInterceptor(element, propName, interceptorImpl) { | ||
} | ||
function prepareValueInterceptor(element) { | ||
prepareInterceptor(element, 'value', function interceptorImpl(v) { | ||
const isUI = isUIValue(v); | ||
if (isUI) { | ||
startTrackValue(this); | ||
} | ||
return { | ||
applyNative: !!isUI, | ||
realArgs: sanitizeValue(this, v), | ||
then: isUI ? undefined : ()=>trackOrSetValue(this, String(v)) | ||
}; | ||
}); | ||
} | ||
function sanitizeValue(element, v) { | ||
// Workaround for JSDOM | ||
if (isElementType(element, 'input', { | ||
type: 'number' | ||
}) && String(v) !== '' && !Number.isNaN(Number(v))) { | ||
// Setting value to "1." results in `null` in JSDOM | ||
return String(Number(v)); | ||
} | ||
return String(v); | ||
} | ||
function prepareSelectionInterceptor(element) { | ||
prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) { | ||
const isUI = isUISelectionStart(start); | ||
return { | ||
applyNative: !!isUI, | ||
realArgs: [ | ||
Number(start), | ||
...others | ||
], | ||
then: ()=>isUI ? undefined : setUISelectionClean(element) | ||
}; | ||
}); | ||
prepareInterceptor(element, 'selectionStart', function interceptorImpl(v) { | ||
return { | ||
realArgs: v, | ||
then: ()=>setUISelectionClean(element) | ||
}; | ||
}); | ||
prepareInterceptor(element, 'selectionEnd', function interceptorImpl(v) { | ||
return { | ||
realArgs: v, | ||
then: ()=>setUISelectionClean(element) | ||
}; | ||
}); | ||
prepareInterceptor(element, 'select', function interceptorImpl() { | ||
return { | ||
realArgs: [], | ||
then: ()=>setUISelectionRaw(element, { | ||
anchorOffset: 0, | ||
focusOffset: getUIValue(element).length | ||
}) | ||
}; | ||
}); | ||
} | ||
function prepareRangeTextInterceptor(element) { | ||
prepareInterceptor(element, 'setRangeText', function interceptorImpl(...realArgs) { | ||
return { | ||
realArgs, | ||
then: ()=>{ | ||
setUIValueClean(element); | ||
setUISelectionClean(element); | ||
} | ||
}; | ||
}); | ||
} | ||
export { prepareInterceptor }; | ||
export { prepareInterceptor, prepareRangeTextInterceptor, prepareSelectionInterceptor, prepareValueInterceptor }; |
import '../../utils/click/isClickableInput.js'; | ||
import '../../utils/dataTransfer/Clipboard.js'; | ||
import '../eventMap.js'; | ||
import { dispatchEvent } from '../dispatchEvent.js'; | ||
import '../../utils/edit/isEditable.js'; | ||
import '../../utils/edit/maxLength.js'; | ||
import '../../utils/edit/isEditable.js'; | ||
import { focus } from '../../utils/focus/focus.js'; | ||
import { isElementType } from '../../utils/misc/isElementType.js'; | ||
import { getWindow } from '../../utils/misc/getWindow.js'; | ||
import { isElementType } from '../../utils/misc/isElementType.js'; | ||
import { blur } from '../../utils/focus/blur.js'; | ||
import { isFocusable } from '../../utils/focus/isFocusable.js'; | ||
import '../../utils/keyDef/readNextDescriptor.js'; | ||
import { cloneEvent } from '../../utils/misc/cloneEvent.js'; | ||
import '@testing-library/dom'; | ||
import '../../utils/misc/level.js'; | ||
import '../../options.js'; | ||
import { focusElement, blurElement } from '../focus.js'; | ||
import { behavior } from './registry.js'; | ||
behavior.click = (event, target, config)=>{ | ||
behavior.click = (event, target, instance)=>{ | ||
const context = target.closest('button,input,label,select,textarea'); | ||
@@ -25,5 +21,5 @@ const control = context && isElementType(context, 'label') && context.control; | ||
if (isFocusable(control)) { | ||
focus(control); | ||
focusElement(control); | ||
} | ||
dispatchEvent(config, control, cloneEvent(event)); | ||
instance.dispatchEvent(control, cloneEvent(event)); | ||
}; | ||
@@ -35,8 +31,8 @@ } else if (isElementType(target, 'input', { | ||
// blur fires when the file selector pops up | ||
blur(target); | ||
blurElement(target); | ||
target.dispatchEvent(new (getWindow(target)).Event('fileDialog')); | ||
// focus fires after the file selector has been closed | ||
focus(target); | ||
focusElement(target); | ||
}; | ||
} | ||
}; |
import '../../utils/click/isClickableInput.js'; | ||
import '../../utils/dataTransfer/Clipboard.js'; | ||
import '../eventMap.js'; | ||
import './click.js'; | ||
import './keydown.js'; | ||
import './keypress.js'; | ||
import './keyup.js'; | ||
import './paste.js'; | ||
import { behavior } from './registry.js'; | ||
import '@testing-library/dom'; | ||
import { input } from '../../utils/edit/input.js'; | ||
import { isEditable } from '../../utils/edit/isEditable.js'; | ||
import '../../utils/edit/maxLength.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -17,9 +9,11 @@ import '../../utils/keyDef/readNextDescriptor.js'; | ||
import '../../options.js'; | ||
import { input } from '../input.js'; | ||
import { behavior } from './registry.js'; | ||
behavior.cut = (event, target, config)=>{ | ||
behavior.cut = (event, target, instance)=>{ | ||
return ()=>{ | ||
if (isEditable(target)) { | ||
input(config, target, '', 'deleteByCut'); | ||
input(instance, target, '', 'deleteByCut'); | ||
} | ||
}; | ||
}; |
@@ -0,74 +1,70 @@ | ||
import { getUIValue, setUISelection } from '../../document/UI.js'; | ||
import { getValueOrTextContent } from '../../document/getValueOrTextContent.js'; | ||
import '../../utils/click/isClickableInput.js'; | ||
import '../../utils/dataTransfer/Clipboard.js'; | ||
import { getValue } from '../../utils/edit/getValue.js'; | ||
import { input } from '../../utils/edit/input.js'; | ||
import { isContentEditable } from '../../utils/edit/isContentEditable.js'; | ||
import { isEditable } from '../../utils/edit/isEditable.js'; | ||
import { walkRadio } from '../../utils/edit/walkRadio.js'; | ||
import '@testing-library/dom'; | ||
import '../../utils/edit/maxLength.js'; | ||
import { isElementType } from '../../utils/misc/isElementType.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import { moveSelection, setSelectionRange, hasOwnSelection } from '../../utils/focus/selection.js'; | ||
import { focus } from '../../utils/focus/focus.js'; | ||
import { getTabDestination } from '../../utils/focus/getTabDestination.js'; | ||
import { selectAll } from '../../utils/focus/selectAll.js'; | ||
import { hasOwnSelection } from '../../utils/focus/selection.js'; | ||
import '../../utils/keyDef/readNextDescriptor.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import '../../utils/misc/level.js'; | ||
import '../../options.js'; | ||
import '../eventMap.js'; | ||
import './click.js'; | ||
import './cut.js'; | ||
import './keypress.js'; | ||
import './keyup.js'; | ||
import './paste.js'; | ||
import { focusElement } from '../focus.js'; | ||
import { input } from '../input.js'; | ||
import { moveSelection } from '../selection/moveSelection.js'; | ||
import { selectAll } from '../selection/selectAll.js'; | ||
import { setSelectionRange } from '../selection/setSelectionRange.js'; | ||
import { walkRadio } from '../radio.js'; | ||
import { behavior } from './registry.js'; | ||
import { setUISelection } from '../../document/selection.js'; | ||
behavior.keydown = (event, target, config)=>{ | ||
behavior.keydown = (event, target, instance)=>{ | ||
var ref; | ||
var ref1; | ||
return (ref1 = (ref = keydownBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keydownBehavior, event, target, config)) !== null && ref1 !== void 0 ? ref1 : combinationBehavior(event, target, config); | ||
return (ref1 = (ref = keydownBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keydownBehavior, event, target, instance)) !== null && ref1 !== void 0 ? ref1 : combinationBehavior(event, target, instance); | ||
}; | ||
const keydownBehavior = { | ||
ArrowDown: (event, target, config)=>{ | ||
ArrowDown: (event, target, instance)=>{ | ||
/* istanbul ignore else */ if (isElementType(target, 'input', { | ||
type: 'radio' | ||
})) { | ||
return ()=>walkRadio(config, target, -1); | ||
return ()=>walkRadio(instance, target, -1); | ||
} | ||
}, | ||
ArrowLeft: (event, target, config)=>{ | ||
ArrowLeft: (event, target, instance)=>{ | ||
if (isElementType(target, 'input', { | ||
type: 'radio' | ||
})) { | ||
return ()=>walkRadio(config, target, -1); | ||
return ()=>walkRadio(instance, target, -1); | ||
} | ||
return ()=>moveSelection(target, -1); | ||
}, | ||
ArrowRight: (event, target, config)=>{ | ||
ArrowRight: (event, target, instance)=>{ | ||
if (isElementType(target, 'input', { | ||
type: 'radio' | ||
})) { | ||
return ()=>walkRadio(config, target, 1); | ||
return ()=>walkRadio(instance, target, 1); | ||
} | ||
return ()=>moveSelection(target, 1); | ||
}, | ||
ArrowUp: (event, target, config)=>{ | ||
ArrowUp: (event, target, instance)=>{ | ||
/* istanbul ignore else */ if (isElementType(target, 'input', { | ||
type: 'radio' | ||
})) { | ||
return ()=>walkRadio(config, target, 1); | ||
return ()=>walkRadio(instance, target, 1); | ||
} | ||
}, | ||
Backspace: (event, target, config)=>{ | ||
Backspace: (event, target, instance)=>{ | ||
if (isEditable(target)) { | ||
return ()=>{ | ||
input(config, target, '', 'deleteContentBackward'); | ||
input(instance, target, '', 'deleteContentBackward'); | ||
}; | ||
} | ||
}, | ||
Delete: (event, target, config)=>{ | ||
Delete: (event, target, instance)=>{ | ||
if (isEditable(target)) { | ||
return ()=>{ | ||
input(config, target, '', 'deleteContentForward'); | ||
input(instance, target, '', 'deleteContentForward'); | ||
}; | ||
@@ -85,3 +81,3 @@ } | ||
var ref1; | ||
const newPos = (ref1 = (ref = getValue(target)) === null || ref === void 0 ? void 0 : ref.length) !== null && ref1 !== void 0 ? ref1 : /* istanbul ignore next */ 0; | ||
const newPos = (ref1 = (ref = getValueOrTextContent(target)) === null || ref === void 0 ? void 0 : ref.length) !== null && ref1 !== void 0 ? ref1 : /* istanbul ignore next */ 0; | ||
setSelectionRange(target, newPos, newPos); | ||
@@ -106,3 +102,3 @@ }; | ||
return ()=>{ | ||
const newPos = getValue(target).length; | ||
const newPos = getUIValue(target).length; | ||
setSelectionRange(target, newPos, newPos); | ||
@@ -121,6 +117,6 @@ }; | ||
}, | ||
Tab: (event, target, config)=>{ | ||
Tab: (event, target, instance)=>{ | ||
return ()=>{ | ||
const dest = getTabDestination(target, config.system.keyboard.modifiers.Shift); | ||
focus(dest); | ||
const dest = getTabDestination(target, instance.system.keyboard.modifiers.Shift); | ||
focusElement(dest); | ||
if (hasOwnSelection(dest)) { | ||
@@ -135,6 +131,6 @@ setUISelection(dest, { | ||
}; | ||
const combinationBehavior = (event, target, config)=>{ | ||
if (event.code === 'KeyA' && config.system.keyboard.modifiers.Control) { | ||
const combinationBehavior = (event, target, instance)=>{ | ||
if (event.code === 'KeyA' && instance.system.keyboard.modifiers.Control) { | ||
return ()=>selectAll(target); | ||
} | ||
}; |
@@ -1,8 +0,6 @@ | ||
import { dispatchUIEvent } from '../index.js'; | ||
import '../../utils/click/isClickableInput.js'; | ||
import '../../utils/dataTransfer/Clipboard.js'; | ||
import { isContentEditable } from '../../utils/edit/isContentEditable.js'; | ||
import { input } from '../../utils/edit/input.js'; | ||
import { isEditable } from '../../utils/edit/isEditable.js'; | ||
import '@testing-library/dom'; | ||
import '../../utils/edit/maxLength.js'; | ||
import { isElementType } from '../../utils/misc/isElementType.js'; | ||
@@ -13,9 +11,10 @@ import '@testing-library/dom/dist/helpers.js'; | ||
import '../../options.js'; | ||
import { input } from '../input.js'; | ||
import { behavior } from './registry.js'; | ||
behavior.keypress = (event, target, config)=>{ | ||
behavior.keypress = (event, target, instance)=>{ | ||
if (event.key === 'Enter') { | ||
if (isElementType(target, 'button') || isElementType(target, 'input') && ClickInputOnEnter.includes(target.type) || isElementType(target, 'a') && Boolean(target.href)) { | ||
return ()=>{ | ||
dispatchUIEvent(config, target, 'click'); | ||
instance.dispatchUIEvent(target, 'click'); | ||
}; | ||
@@ -26,5 +25,5 @@ } else if (isElementType(target, 'input')) { | ||
if (submit) { | ||
return ()=>dispatchUIEvent(config, submit, 'click'); | ||
return ()=>instance.dispatchUIEvent(submit, 'click'); | ||
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) { | ||
return ()=>dispatchUIEvent(config, form, 'submit'); | ||
return ()=>instance.dispatchUIEvent(form, 'submit'); | ||
} else { | ||
@@ -36,5 +35,5 @@ return; | ||
if (isEditable(target)) { | ||
const inputType = event.key === 'Enter' ? isContentEditable(target) && !config.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText'; | ||
const inputType = event.key === 'Enter' ? isContentEditable(target) && !instance.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText'; | ||
const inputData = event.key === 'Enter' ? '\n' : event.key; | ||
return ()=>input(config, target, inputData, inputType); | ||
return ()=>input(instance, target, inputData, inputType); | ||
} | ||
@@ -41,0 +40,0 @@ }; |
import { isClickableInput } from '../../utils/click/isClickableInput.js'; | ||
import '../../utils/dataTransfer/Clipboard.js'; | ||
import { dispatchUIEvent } from '../index.js'; | ||
import '../../utils/edit/isEditable.js'; | ||
import '../../utils/edit/maxLength.js'; | ||
import '../../utils/edit/isEditable.js'; | ||
import '@testing-library/dom'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -13,12 +11,12 @@ import '../../utils/keyDef/readNextDescriptor.js'; | ||
behavior.keyup = (event, target, config)=>{ | ||
behavior.keyup = (event, target, instance)=>{ | ||
var ref; | ||
return (ref = keyupBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keyupBehavior, event, target, config); | ||
return (ref = keyupBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keyupBehavior, event, target, instance); | ||
}; | ||
const keyupBehavior = { | ||
' ': (event, target, config)=>{ | ||
' ': (event, target, instance)=>{ | ||
if (isClickableInput(target)) { | ||
return ()=>dispatchUIEvent(config, target, 'click'); | ||
return ()=>instance.dispatchUIEvent(target, 'click'); | ||
} | ||
} | ||
}; |
import '../../utils/click/isClickableInput.js'; | ||
import '../../utils/dataTransfer/Clipboard.js'; | ||
import '../eventMap.js'; | ||
import './click.js'; | ||
import './cut.js'; | ||
import './keydown.js'; | ||
import './keypress.js'; | ||
import './keyup.js'; | ||
import { behavior } from './registry.js'; | ||
import '@testing-library/dom'; | ||
import { input } from '../../utils/edit/input.js'; | ||
import { isEditable } from '../../utils/edit/isEditable.js'; | ||
import '../../utils/edit/maxLength.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -17,4 +9,6 @@ import '../../utils/keyDef/readNextDescriptor.js'; | ||
import '../../options.js'; | ||
import { input } from '../input.js'; | ||
import { behavior } from './registry.js'; | ||
behavior.paste = (event, target, config)=>{ | ||
behavior.paste = (event, target, instance)=>{ | ||
if (isEditable(target)) { | ||
@@ -25,3 +19,3 @@ return ()=>{ | ||
if (insertData) { | ||
input(config, target, insertData, 'insertFromPaste'); | ||
input(instance, target, insertData, 'insertFromPaste'); | ||
} | ||
@@ -28,0 +22,0 @@ }; |
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import './behavior/click.js'; | ||
import './behavior/cut.js'; | ||
import './behavior/keydown.js'; | ||
import './behavior/keypress.js'; | ||
import './behavior/keyup.js'; | ||
import './behavior/paste.js'; | ||
import '@testing-library/dom'; | ||
import { eventMap, eventMapKeys } from './eventMap.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import { getWindow } from '../utils/misc/getWindow.js'; | ||
@@ -17,2 +9,3 @@ import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../options.js'; | ||
import { eventMap, eventMapKeys } from './eventMap.js'; | ||
@@ -19,0 +12,0 @@ const eventInitializer = { |
@@ -9,7 +9,19 @@ import './behavior/click.js'; | ||
import { wrapEvent } from './wrapEvent.js'; | ||
import { isMouseEvent, isKeyboardEvent } from './eventMap.js'; | ||
import { createEvent } from './createEvent.js'; | ||
function dispatchEvent(config, target, event, preventDefault = false) { | ||
function dispatchUIEvent(target, type, init, preventDefault = false) { | ||
if (isMouseEvent(type) || isKeyboardEvent(type)) { | ||
init = { | ||
...init, | ||
...this.system.getUIEventModifiers() | ||
}; | ||
} | ||
const event = createEvent(type, target, init); | ||
return dispatchEvent.call(this, target, event, preventDefault); | ||
} | ||
function dispatchEvent(target, event, preventDefault = false) { | ||
var ref; | ||
const type = event.type; | ||
const behaviorImplementation = preventDefault ? ()=>{} : (ref = behavior[type]) === null || ref === void 0 ? void 0 : ref(event, target, config); | ||
const behaviorImplementation = preventDefault ? ()=>{} : (ref = behavior[type]) === null || ref === void 0 ? void 0 : ref(event, target, this); | ||
if (behaviorImplementation) { | ||
@@ -34,3 +46,7 @@ event.preventDefault(); | ||
} | ||
function dispatchDOMEvent(target, type, init) { | ||
const event = createEvent(type, target, init); | ||
wrapEvent(()=>target.dispatchEvent(event)); | ||
} | ||
export { dispatchEvent }; | ||
export { dispatchDOMEvent, dispatchEvent, dispatchUIEvent }; |
@@ -1,19 +0,14 @@ | ||
import { createEvent } from './createEvent.js'; | ||
import { dispatchEvent } from './dispatchEvent.js'; | ||
import { isMouseEvent, isKeyboardEvent } from './eventMap.js'; | ||
function dispatchUIEvent(config, target, type, init, preventDefault = false) { | ||
if (isMouseEvent(type) || isKeyboardEvent(type)) { | ||
init = { | ||
...init, | ||
...config.system.getUIEventModifiers() | ||
}; | ||
} | ||
const event = createEvent(type, target, init); | ||
return dispatchEvent(config, target, event, preventDefault); | ||
} | ||
function bindDispatchUIEvent(config) { | ||
return dispatchUIEvent.bind(undefined, config); | ||
} | ||
export { bindDispatchUIEvent, dispatchUIEvent }; | ||
export { dispatchDOMEvent, dispatchEvent, dispatchUIEvent } from './dispatchEvent.js'; | ||
export { blurElement, focusElement } from './focus.js'; | ||
export { input } from './input.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../utils/misc/level.js'; | ||
import '../options.js'; | ||
export { setSelectionPerMouseDown } from './selection/setSelectionPerMouse.js'; | ||
export { modifySelectionPerMouseMove } from './selection/modifySelectionPerMouse.js'; | ||
export { isAllSelected, selectAll } from './selection/selectAll.js'; |
@@ -1,14 +0,5 @@ | ||
import '../setup/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -20,22 +11,21 @@ import '../utils/keyDef/readNextDescriptor.js'; | ||
import { parseKeyDef } from './parseKeyDef.js'; | ||
import { Config } from '../setup/config.js'; | ||
async function keyboard(text) { | ||
const actions = parseKeyDef(this[Config].keyboardMap, text); | ||
const actions = parseKeyDef(this.config.keyboardMap, text); | ||
for(let i = 0; i < actions.length; i++){ | ||
await wait(this[Config]); | ||
await keyboardAction(this[Config], actions[i]); | ||
await wait(this.config); | ||
await keyboardAction(this, actions[i]); | ||
} | ||
} | ||
async function keyboardAction(config, { keyDef , releasePrevious , releaseSelf , repeat }) { | ||
const { system } = config; | ||
async function keyboardAction(instance, { keyDef , releasePrevious , releaseSelf , repeat }) { | ||
const { system } = instance; | ||
// Release the key automatically if it was pressed before. | ||
if (system.keyboard.isKeyPressed(keyDef)) { | ||
await system.keyboard.keyup(config, keyDef); | ||
await system.keyboard.keyup(instance, keyDef); | ||
} | ||
if (!releasePrevious) { | ||
for(let i = 1; i <= repeat; i++){ | ||
await system.keyboard.keydown(config, keyDef); | ||
await system.keyboard.keydown(instance, keyDef); | ||
if (i < repeat) { | ||
await wait(config); | ||
await wait(instance.config); | ||
} | ||
@@ -45,9 +35,9 @@ } | ||
if (releaseSelf) { | ||
await system.keyboard.keyup(config, keyDef); | ||
await system.keyboard.keyup(instance, keyDef); | ||
} | ||
} | ||
} | ||
async function releaseAllKeys(config) { | ||
for (const k of config.system.keyboard.getPressedKeys()){ | ||
await config.system.keyboard.keyup(config, k); | ||
async function releaseAllKeys(instance) { | ||
for (const k of instance.system.keyboard.getPressedKeys()){ | ||
await instance.system.keyboard.keyup(instance, k); | ||
} | ||
@@ -54,0 +44,0 @@ } |
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -14,0 +6,0 @@ import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js'; |
@@ -1,4 +0,1 @@ | ||
import { defaultKeyMap } from './keyboard/keyMap.js'; | ||
import { defaultKeyMap as defaultKeyMap$1 } from './pointer/keyMap.js'; | ||
var PointerEventsCheckLevel; | ||
@@ -14,25 +11,3 @@ (function(PointerEventsCheckLevel) { | ||
})(PointerEventsCheckLevel || (PointerEventsCheckLevel = {})); | ||
/** | ||
* Default options applied when API is called per `userEvent.anyApi()` | ||
*/ const defaultOptionsDirect = { | ||
applyAccept: true, | ||
autoModify: true, | ||
delay: 0, | ||
document: globalThis.document, | ||
keyboardMap: defaultKeyMap, | ||
pointerMap: defaultKeyMap$1, | ||
pointerEventsCheck: PointerEventsCheckLevel.EachApiCall, | ||
skipAutoClose: false, | ||
skipClick: false, | ||
skipHover: false, | ||
writeToClipboard: false, | ||
advanceTimers: ()=>Promise.resolve() | ||
}; | ||
/** | ||
* Default options applied when API is called per `userEvent().anyApi()` | ||
*/ const defaultOptionsSetup = { | ||
...defaultOptionsDirect, | ||
writeToClipboard: true | ||
}; | ||
export { PointerEventsCheckLevel, defaultOptionsDirect, defaultOptionsSetup }; | ||
export { PointerEventsCheckLevel }; |
@@ -1,14 +0,5 @@ | ||
import '../setup/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -20,6 +11,5 @@ import '../utils/keyDef/readNextDescriptor.js'; | ||
import { parseKeyDef } from './parseKeyDef.js'; | ||
import { Config } from '../setup/config.js'; | ||
async function pointer(input) { | ||
const { pointerMap } = this[Config]; | ||
const { pointerMap } = this.config; | ||
const actions = []; | ||
@@ -41,14 +31,14 @@ (Array.isArray(input) ? input : [ | ||
for(let i = 0; i < actions.length; i++){ | ||
await wait(this[Config]); | ||
await pointerAction(this[Config], actions[i]); | ||
await wait(this.config); | ||
await pointerAction(this, actions[i]); | ||
} | ||
this[Config].system.pointer.resetClickCount(); | ||
this.system.pointer.resetClickCount(); | ||
} | ||
async function pointerAction(config, action) { | ||
async function pointerAction(instance, action) { | ||
var ref, ref1; | ||
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? config.system.pointer.getPointerName(action.keyDef) : 'mouse'; | ||
const previousPosition = config.system.pointer.getPreviousPosition(pointerName); | ||
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? instance.system.pointer.getPointerName(action.keyDef) : 'mouse'; | ||
const previousPosition = instance.system.pointer.getPreviousPosition(pointerName); | ||
var _target, _coords, _node, _offset; | ||
const position = { | ||
target: (_target = action.target) !== null && _target !== void 0 ? _target : getPrevTarget(config, previousPosition), | ||
target: (_target = action.target) !== null && _target !== void 0 ? _target : getPrevTarget(instance, previousPosition), | ||
coords: (_coords = action.coords) !== null && _coords !== void 0 ? _coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords, | ||
@@ -61,17 +51,17 @@ caret: { | ||
if ('keyDef' in action) { | ||
if (config.system.pointer.isKeyPressed(action.keyDef)) { | ||
setLevelRef(config, ApiLevel.Trigger); | ||
await config.system.pointer.release(config, action.keyDef, position); | ||
if (instance.system.pointer.isKeyPressed(action.keyDef)) { | ||
setLevelRef(instance, ApiLevel.Trigger); | ||
await instance.system.pointer.release(instance, action.keyDef, position); | ||
} | ||
if (!action.releasePrevious) { | ||
setLevelRef(config, ApiLevel.Trigger); | ||
await config.system.pointer.press(config, action.keyDef, position); | ||
setLevelRef(instance, ApiLevel.Trigger); | ||
await instance.system.pointer.press(instance, action.keyDef, position); | ||
if (action.releaseSelf) { | ||
setLevelRef(config, ApiLevel.Trigger); | ||
await config.system.pointer.release(config, action.keyDef, position); | ||
setLevelRef(instance, ApiLevel.Trigger); | ||
await instance.system.pointer.release(instance, action.keyDef, position); | ||
} | ||
} | ||
} else { | ||
setLevelRef(config, ApiLevel.Trigger); | ||
await config.system.pointer.move(config, pointerName, position); | ||
setLevelRef(instance, ApiLevel.Trigger); | ||
await instance.system.pointer.move(instance, pointerName, position); | ||
} | ||
@@ -83,3 +73,3 @@ } | ||
} | ||
function getPrevTarget(config, position) { | ||
function getPrevTarget(instance, position) { | ||
if (!position) { | ||
@@ -89,5 +79,5 @@ throw new Error('This pointer has no previous position. Provide a target property!'); | ||
var _target; | ||
return (_target = position.target) !== null && _target !== void 0 ? _target : config.document.body; | ||
return (_target = position.target) !== null && _target !== void 0 ? _target : instance.config.document.body; | ||
} | ||
export { pointer }; |
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -14,0 +6,0 @@ import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js'; |
@@ -25,8 +25,8 @@ import { setupDirect } from './setup.js'; | ||
async function keyboard(text, options = {}) { | ||
const { config , api } = setupDirect(options); | ||
return api.keyboard(text).then(()=>config.system); | ||
const { api , system } = setupDirect(options); | ||
return api.keyboard(text).then(()=>system); | ||
} | ||
async function pointer(input, options = {}) { | ||
const { config , api } = setupDirect(options); | ||
return api.pointer(input).then(()=>config.system); | ||
const { api , system } = setupDirect(options); | ||
return api.pointer(input).then(()=>system); | ||
} | ||
@@ -46,4 +46,4 @@ function paste(clipboardData, options) { | ||
function unhover(element, options = {}) { | ||
const { config , api } = setupDirect(options); | ||
config.system.pointer.setMousePosition({ | ||
const { api , system } = setupDirect(options); | ||
system.pointer.setMousePosition({ | ||
target: element | ||
@@ -50,0 +50,0 @@ }); |
import { setupMain } from './setup.js'; | ||
export { Config } from './config.js'; | ||
import * as directApi from './directApi.js'; | ||
@@ -4,0 +3,0 @@ |
@@ -1,9 +0,7 @@ | ||
import { prepareDocument } from '../document/index.js'; | ||
import { bindDispatchUIEvent } from '../event/index.js'; | ||
import { defaultOptionsSetup, defaultOptionsDirect } from '../options.js'; | ||
import { prepareDocument } from '../document/prepareDocument.js'; | ||
import { dispatchEvent, dispatchUIEvent } from '../event/dispatchEvent.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import { attachClipboardStubToView } from '../utils/dataTransfer/Clipboard.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -14,15 +12,38 @@ import '../utils/keyDef/readNextDescriptor.js'; | ||
import { wait } from '../utils/misc/wait.js'; | ||
import { PointerEventsCheckLevel } from '../options.js'; | ||
import '@testing-library/dom'; | ||
import { defaultKeyMap } from '../keyboard/keyMap.js'; | ||
import { defaultKeyMap as defaultKeyMap$1 } from '../pointer/keyMap.js'; | ||
import { System } from '../system/index.js'; | ||
import { Config } from './config.js'; | ||
import * as api from './api.js'; | ||
import { wrapAsync } from './wrapAsync.js'; | ||
/** | ||
* Default options applied when API is called per `userEvent.anyApi()` | ||
*/ const defaultOptionsDirect = { | ||
applyAccept: true, | ||
autoModify: true, | ||
delay: 0, | ||
document: globalThis.document, | ||
keyboardMap: defaultKeyMap, | ||
pointerMap: defaultKeyMap$1, | ||
pointerEventsCheck: PointerEventsCheckLevel.EachApiCall, | ||
skipAutoClose: false, | ||
skipClick: false, | ||
skipHover: false, | ||
writeToClipboard: false, | ||
advanceTimers: ()=>Promise.resolve() | ||
}; | ||
/** | ||
* Default options applied when API is called per `userEvent().anyApi()` | ||
*/ const defaultOptionsSetup = { | ||
...defaultOptionsDirect, | ||
writeToClipboard: true | ||
}; | ||
function createConfig(options = {}, defaults = defaultOptionsSetup, node) { | ||
const document = getDocument(options, node, defaults); | ||
var _system; | ||
return { | ||
...defaults, | ||
...options, | ||
document, | ||
system: (_system = options.system) !== null && _system !== void 0 ? _system : new System() | ||
document | ||
}; | ||
@@ -39,3 +60,3 @@ } | ||
attachClipboardStubToView(view); | ||
return doSetup(config); | ||
return createInstance(config).api; | ||
} | ||
@@ -45,10 +66,9 @@ /** | ||
*/ function setupDirect({ keyboardState , pointerState , ...options } = {}, node) { | ||
const config = createConfig({ | ||
...options, | ||
system: pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState | ||
}, defaultOptionsDirect, node); | ||
const config = createConfig(options, defaultOptionsDirect, node); | ||
prepareDocument(config.document); | ||
var ref; | ||
const system = (ref = pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState) !== null && ref !== void 0 ? ref : new System(); | ||
return { | ||
config, | ||
api: doSetup(config) | ||
api: createInstance(config, system).api, | ||
system | ||
}; | ||
@@ -59,12 +79,12 @@ } | ||
*/ function setupSub(options) { | ||
return doSetup({ | ||
...this[Config], | ||
return createInstance({ | ||
...this.config, | ||
...options | ||
}); | ||
}, this.system).api; | ||
} | ||
function wrapAndBindImpl(instance, impl) { | ||
function method(...args) { | ||
setLevelRef(instance[Config], ApiLevel.Call); | ||
setLevelRef(instance, ApiLevel.Call); | ||
return wrapAsync(()=>impl.apply(instance, args).then(async (ret)=>{ | ||
await wait(instance[Config]); | ||
await wait(instance.config); | ||
return ret; | ||
@@ -78,14 +98,21 @@ })); | ||
} | ||
function doSetup(config) { | ||
const instance = { | ||
[Config]: config, | ||
dispatchUIEvent: bindDispatchUIEvent(config), | ||
function createInstance(config, system = new System()) { | ||
const instance = {}; | ||
Object.assign(instance, { | ||
config, | ||
dispatchEvent: dispatchEvent.bind(instance), | ||
dispatchUIEvent: dispatchUIEvent.bind(instance), | ||
system, | ||
levelRefs: {}, | ||
...api | ||
}; | ||
}); | ||
return { | ||
...Object.fromEntries(Object.entries(api).map(([name, api])=>[ | ||
name, | ||
wrapAndBindImpl(instance, api), | ||
])), | ||
setup: setupSub.bind(instance) | ||
instance, | ||
api: { | ||
...Object.fromEntries(Object.entries(api).map(([name, api])=>[ | ||
name, | ||
wrapAndBindImpl(instance, api), | ||
])), | ||
setup: setupSub.bind(instance) | ||
} | ||
}; | ||
@@ -98,2 +125,2 @@ } | ||
export { createConfig, setupDirect, setupMain, setupSub }; | ||
export { createConfig, createInstance, setupDirect, setupMain, setupSub }; |
@@ -1,7 +0,5 @@ | ||
import { dispatchUIEvent } from '../event/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import '@testing-library/dom'; | ||
import { getActiveElementOrBody } from '../utils/focus/getActiveElement.js'; | ||
@@ -50,6 +48,6 @@ import '@testing-library/dom/dist/helpers.js'; | ||
} | ||
/** Press a key */ async keydown(config, keyDef) { | ||
/** Press a key */ async keydown(instance, keyDef) { | ||
const key = String(keyDef.key); | ||
const code = String(keyDef.code); | ||
const target = getActiveElementOrBody(config.document); | ||
const target = getActiveElementOrBody(instance.config.document); | ||
this.setKeydownTarget(target); | ||
@@ -64,3 +62,3 @@ var ref; | ||
} | ||
const unprevented = dispatchUIEvent(config, target, 'keydown', { | ||
const unprevented = instance.dispatchUIEvent(target, 'keydown', { | ||
key, | ||
@@ -75,3 +73,3 @@ code | ||
if (unprevented && this.hasKeyPress(key)) { | ||
dispatchUIEvent(config, getActiveElementOrBody(config.document), 'keypress', { | ||
instance.dispatchUIEvent(getActiveElementOrBody(instance.config.document), 'keypress', { | ||
key, | ||
@@ -83,3 +81,3 @@ code, | ||
} | ||
/** Release a key */ async keyup(config, keyDef) { | ||
/** Release a key */ async keyup(instance, keyDef) { | ||
const key = String(keyDef.key); | ||
@@ -93,3 +91,3 @@ const code = String(keyDef.code); | ||
} | ||
dispatchUIEvent(config, getActiveElementOrBody(config.document), 'keyup', { | ||
instance.dispatchUIEvent(getActiveElementOrBody(instance.config.document), 'keyup', { | ||
key, | ||
@@ -96,0 +94,0 @@ code |
@@ -11,5 +11,5 @@ import { Buttons } from './buttons.js'; | ||
} | ||
async press(config, keyDef, position) { | ||
async press(instance, keyDef, position) { | ||
const pointerName = this.getPointerName(keyDef); | ||
const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef).init(config, position) : this.pointers.get(pointerName); | ||
const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef).init(instance, position) : this.pointers.get(pointerName); | ||
// TODO: deprecate the following implicit setting of position | ||
@@ -22,8 +22,8 @@ pointer.position = position; | ||
this.buttons.down(keyDef); | ||
pointer.down(config, keyDef); | ||
pointer.down(instance, keyDef); | ||
if (pointer.pointerType !== 'touch' && !pointer.isPrevented) { | ||
this.mouse.down(config, keyDef, pointer); | ||
this.mouse.down(instance, keyDef, pointer); | ||
} | ||
} | ||
async move(config, pointerName, position) { | ||
async move(instance, pointerName, position) { | ||
const pointer = this.pointers.get(pointerName); | ||
@@ -34,4 +34,4 @@ // In (some?) browsers this order of events can be observed. | ||
// the order in which they interweave/follow on a user interaction depends on the implementation. | ||
const pointermove = pointer.move(config, position); | ||
const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(config, position); | ||
const pointermove = pointer.move(instance, position); | ||
const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(instance, position); | ||
pointermove === null || pointermove === void 0 ? void 0 : pointermove.leave(); | ||
@@ -44,3 +44,3 @@ mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave(); | ||
} | ||
async release(config, keyDef, position) { | ||
async release(instance, keyDef, position) { | ||
const device = this.devices.get(keyDef.pointerType); | ||
@@ -56,21 +56,21 @@ device.removePressed(keyDef); | ||
if (device.countPressed === 0) { | ||
pointer.up(config, keyDef); | ||
pointer.up(instance, keyDef); | ||
} | ||
if (pointer.pointerType === 'touch') { | ||
pointer.release(config); | ||
pointer.release(instance); | ||
} | ||
if (!pointer.isPrevented) { | ||
if (pointer.pointerType === 'touch' && !pointer.isMultitouch) { | ||
const mousemove = this.mouse.move(config, pointer.position); | ||
const mousemove = this.mouse.move(instance, pointer.position); | ||
mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave(); | ||
mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter(); | ||
mousemove === null || mousemove === void 0 ? void 0 : mousemove.move(); | ||
this.mouse.down(config, keyDef, pointer); | ||
this.mouse.down(instance, keyDef, pointer); | ||
} | ||
if (!pointer.isMultitouch) { | ||
const mousemove1 = this.mouse.move(config, pointer.position); | ||
const mousemove1 = this.mouse.move(instance, pointer.position); | ||
mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.leave(); | ||
mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.enter(); | ||
mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.move(); | ||
this.mouse.up(config, keyDef, pointer); | ||
this.mouse.up(instance, keyDef, pointer); | ||
} | ||
@@ -88,5 +88,5 @@ } | ||
} | ||
getMouseTarget(config) { | ||
getMouseTarget(instance) { | ||
var _target; | ||
return (_target = this.mouse.position.target) !== null && _target !== void 0 ? _target : config.document.body; | ||
return (_target = this.mouse.position.target) !== null && _target !== void 0 ? _target : instance.config.document.body; | ||
} | ||
@@ -150,7 +150,3 @@ setMousePosition(position) { | ||
} | ||
function isDifferentPointerPosition(positionA, positionB) { | ||
var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7; | ||
return positionA.target !== positionB.target || ((ref = positionA.coords) === null || ref === void 0 ? void 0 : ref.x) !== ((ref1 = positionB.coords) === null || ref1 === void 0 ? void 0 : ref1.y) || ((ref2 = positionA.coords) === null || ref2 === void 0 ? void 0 : ref2.y) !== ((ref3 = positionB.coords) === null || ref3 === void 0 ? void 0 : ref3.y) || ((ref4 = positionA.caret) === null || ref4 === void 0 ? void 0 : ref4.node) !== ((ref5 = positionB.caret) === null || ref5 === void 0 ? void 0 : ref5.node) || ((ref6 = positionA.caret) === null || ref6 === void 0 ? void 0 : ref6.offset) !== ((ref7 = positionB.caret) === null || ref7 === void 0 ? void 0 : ref7.offset); | ||
} | ||
export { PointerHost, isDifferentPointerPosition }; | ||
export { PointerHost }; |
@@ -1,11 +0,15 @@ | ||
import { dispatchUIEvent } from '../../event/index.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 '@testing-library/dom'; | ||
import '../../event/eventMap.js'; | ||
import '../../utils/click/isClickableInput.js'; | ||
import '../../utils/dataTransfer/Clipboard.js'; | ||
import '../../utils/edit/isEditable.js'; | ||
import '../../utils/edit/maxLength.js'; | ||
import '../../utils/edit/isEditable.js'; | ||
import { focus } from '../../utils/focus/focus.js'; | ||
import { isDisabled } from '../../utils/misc/isDisabled.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import { isDisabled } from '../../utils/misc/isDisabled.js'; | ||
import '@testing-library/dom'; | ||
import { setSelectionPerMouseDown, modifySelectionPerMouseMove } from '../../utils/focus/selection.js'; | ||
import '../../utils/keyDef/readNextDescriptor.js'; | ||
@@ -15,4 +19,7 @@ import { getTreeDiff } from '../../utils/misc/getTreeDiff.js'; | ||
import '../../options.js'; | ||
import { isDifferentPointerPosition } from './index.js'; | ||
import { focusElement } from '../../event/focus.js'; | ||
import { setSelectionPerMouseDown } from '../../event/selection/setSelectionPerMouse.js'; | ||
import { modifySelectionPerMouseMove } from '../../event/selection/modifySelectionPerMouse.js'; | ||
import { getMouseEventButton, Buttons } from './buttons.js'; | ||
import { isDifferentPointerPosition } from './shared.js'; | ||
@@ -22,5 +29,5 @@ /** | ||
*/ class Mouse { | ||
move(config, position) { | ||
move(instance, position) { | ||
const prevPosition = this.position; | ||
const prevTarget = this.getTarget(config); | ||
const prevTarget = this.getTarget(instance); | ||
this.position = position; | ||
@@ -30,3 +37,3 @@ if (!isDifferentPointerPosition(prevPosition, position)) { | ||
} | ||
const nextTarget = this.getTarget(config); | ||
const nextTarget = this.getTarget(instance); | ||
const init = this.getEventInit('mousemove'); | ||
@@ -37,4 +44,4 @@ const [leave, enter] = getTreeDiff(prevTarget, nextTarget); | ||
if (prevTarget !== nextTarget) { | ||
dispatchUIEvent(config, prevTarget, 'mouseout', init); | ||
leave.forEach((el)=>dispatchUIEvent(config, el, 'mouseleave', init)); | ||
instance.dispatchUIEvent(prevTarget, 'mouseout', init); | ||
leave.forEach((el)=>instance.dispatchUIEvent(el, 'mouseleave', init)); | ||
} | ||
@@ -44,13 +51,13 @@ }, | ||
if (prevTarget !== nextTarget) { | ||
dispatchUIEvent(config, nextTarget, 'mouseover', init); | ||
enter.forEach((el)=>dispatchUIEvent(config, el, 'mouseenter', init)); | ||
instance.dispatchUIEvent(nextTarget, 'mouseover', init); | ||
enter.forEach((el)=>instance.dispatchUIEvent(el, 'mouseenter', init)); | ||
} | ||
}, | ||
move: ()=>{ | ||
dispatchUIEvent(config, nextTarget, 'mousemove', init); | ||
this.modifySelecting(config); | ||
instance.dispatchUIEvent(nextTarget, 'mousemove', init); | ||
this.modifySelecting(instance); | ||
} | ||
}; | ||
} | ||
down(config, keyDef, pointer) { | ||
down(instance, keyDef, pointer) { | ||
const button = this.buttons.down(keyDef); | ||
@@ -60,15 +67,15 @@ if (button === undefined) { | ||
} | ||
const target = this.getTarget(config); | ||
const target = this.getTarget(instance); | ||
this.buttonDownTarget[button] = target; | ||
const disabled = isDisabled(target); | ||
const init = this.getEventInit('mousedown', keyDef.button); | ||
if (disabled || dispatchUIEvent(config, target, 'mousedown', init)) { | ||
this.startSelecting(config, init.detail); | ||
focus(target); | ||
if (disabled || instance.dispatchUIEvent(target, 'mousedown', init)) { | ||
this.startSelecting(instance, init.detail); | ||
focusElement(target); | ||
} | ||
if (!disabled && getMouseEventButton(keyDef.button) === 2) { | ||
dispatchUIEvent(config, target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button, pointer)); | ||
instance.dispatchUIEvent(target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button, pointer)); | ||
} | ||
} | ||
up(config, keyDef, pointer) { | ||
up(instance, keyDef, pointer) { | ||
const button = this.buttons.up(keyDef); | ||
@@ -78,5 +85,5 @@ if (button === undefined) { | ||
} | ||
const target = this.getTarget(config); | ||
const target = this.getTarget(instance); | ||
if (!isDisabled(target)) { | ||
dispatchUIEvent(config, target, 'mouseup', this.getEventInit('mouseup', keyDef.button)); | ||
instance.dispatchUIEvent(target, 'mouseup', this.getEventInit('mouseup', keyDef.button)); | ||
this.endSelecting(); | ||
@@ -87,5 +94,5 @@ const clickTarget = getTreeDiff(this.buttonDownTarget[button], target)[2][0]; | ||
if (init.detail) { | ||
dispatchUIEvent(config, clickTarget, init.button === 0 ? 'click' : 'auxclick', init); | ||
instance.dispatchUIEvent(clickTarget, init.button === 0 ? 'click' : 'auxclick', init); | ||
if (init.button === 0 && init.detail === 2) { | ||
dispatchUIEvent(config, clickTarget, 'dblclick', { | ||
instance.dispatchUIEvent(clickTarget, 'dblclick', { | ||
...this.getEventInit('dblclick', keyDef.button), | ||
@@ -122,12 +129,12 @@ detail: init.detail | ||
} | ||
getTarget(config) { | ||
getTarget(instance) { | ||
var _target; | ||
return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body; | ||
return (_target = this.position.target) !== null && _target !== void 0 ? _target : instance.config.document.body; | ||
} | ||
startSelecting(config, clickCount) { | ||
startSelecting(instance, clickCount) { | ||
var ref, ref1; | ||
// TODO: support extending range (shift) | ||
this.selecting = setSelectionPerMouseDown({ | ||
document: config.document, | ||
target: this.getTarget(config), | ||
document: instance.config.document, | ||
target: this.getTarget(instance), | ||
node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node, | ||
@@ -138,3 +145,3 @@ offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset, | ||
} | ||
modifySelecting(config) { | ||
modifySelecting(instance) { | ||
var ref, ref1; | ||
@@ -145,4 +152,4 @@ if (!this.selecting) { | ||
modifySelectionPerMouseMove(this.selecting, { | ||
document: config.document, | ||
target: this.getTarget(config), | ||
document: instance.config.document, | ||
target: this.getTarget(instance), | ||
node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node, | ||
@@ -149,0 +156,0 @@ offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset |
@@ -1,7 +0,5 @@ | ||
import { dispatchUIEvent } from '../../event/index.js'; | ||
import '../../utils/click/isClickableInput.js'; | ||
import '../../utils/dataTransfer/Clipboard.js'; | ||
import '../../utils/edit/isEditable.js'; | ||
import '../../utils/edit/maxLength.js'; | ||
import '../../utils/edit/isEditable.js'; | ||
import '@testing-library/dom'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -12,18 +10,18 @@ import '../../utils/keyDef/readNextDescriptor.js'; | ||
import { assertPointerEvents, hasPointerEvents } from '../../utils/pointer/cssPointerEvents.js'; | ||
import { isDifferentPointerPosition } from './index.js'; | ||
import { isDifferentPointerPosition } from './shared.js'; | ||
class Pointer { | ||
init(config, position) { | ||
init(instance, position) { | ||
this.position = position; | ||
const target = this.getTarget(config); | ||
const target = this.getTarget(instance); | ||
const [, enter] = getTreeDiff(null, target); | ||
const init = this.getEventInit(); | ||
assertPointerEvents(config, target); | ||
dispatchUIEvent(config, target, 'pointerover', init); | ||
enter.forEach((el)=>dispatchUIEvent(config, el, 'pointerenter', init)); | ||
assertPointerEvents(instance, target); | ||
instance.dispatchUIEvent(target, 'pointerover', init); | ||
enter.forEach((el)=>instance.dispatchUIEvent(el, 'pointerenter', init)); | ||
return this; | ||
} | ||
move(config, position) { | ||
move(instance, position) { | ||
const prevPosition = this.position; | ||
const prevTarget = this.getTarget(config); | ||
const prevTarget = this.getTarget(instance); | ||
this.position = position; | ||
@@ -33,3 +31,3 @@ if (!isDifferentPointerPosition(prevPosition, position)) { | ||
} | ||
const nextTarget = this.getTarget(config); | ||
const nextTarget = this.getTarget(instance); | ||
const init = this.getEventInit(); | ||
@@ -39,6 +37,6 @@ const [leave, enter] = getTreeDiff(prevTarget, nextTarget); | ||
leave: ()=>{ | ||
if (hasPointerEvents(config, prevTarget)) { | ||
if (hasPointerEvents(instance, prevTarget)) { | ||
if (prevTarget !== nextTarget) { | ||
dispatchUIEvent(config, prevTarget, 'pointerout', init); | ||
leave.forEach((el)=>dispatchUIEvent(config, el, 'pointerleave', init)); | ||
instance.dispatchUIEvent(prevTarget, 'pointerout', init); | ||
leave.forEach((el)=>instance.dispatchUIEvent(el, 'pointerleave', init)); | ||
} | ||
@@ -48,33 +46,33 @@ } | ||
enter: ()=>{ | ||
assertPointerEvents(config, nextTarget); | ||
assertPointerEvents(instance, nextTarget); | ||
if (prevTarget !== nextTarget) { | ||
dispatchUIEvent(config, nextTarget, 'pointerover', init); | ||
enter.forEach((el)=>dispatchUIEvent(config, el, 'pointerenter', init)); | ||
instance.dispatchUIEvent(nextTarget, 'pointerover', init); | ||
enter.forEach((el)=>instance.dispatchUIEvent(el, 'pointerenter', init)); | ||
} | ||
}, | ||
move: ()=>{ | ||
dispatchUIEvent(config, nextTarget, 'pointermove', init); | ||
instance.dispatchUIEvent(nextTarget, 'pointermove', init); | ||
} | ||
}; | ||
} | ||
down(config, _keyDef) { | ||
down(instance, _keyDef) { | ||
if (this.isDown) { | ||
return; | ||
} | ||
const target = this.getTarget(config); | ||
assertPointerEvents(config, target); | ||
const target = this.getTarget(instance); | ||
assertPointerEvents(instance, target); | ||
this.isDown = true; | ||
this.isPrevented = !dispatchUIEvent(config, target, 'pointerdown', this.getEventInit()); | ||
this.isPrevented = !instance.dispatchUIEvent(target, 'pointerdown', this.getEventInit()); | ||
} | ||
up(config, _keyDef) { | ||
up(instance, _keyDef) { | ||
if (!this.isDown) { | ||
return; | ||
} | ||
const target = this.getTarget(config); | ||
assertPointerEvents(config, target); | ||
const target = this.getTarget(instance); | ||
assertPointerEvents(instance, target); | ||
this.isDown = false; | ||
dispatchUIEvent(config, target, 'pointerup', this.getEventInit()); | ||
instance.dispatchUIEvent(target, 'pointerup', this.getEventInit()); | ||
} | ||
release(config) { | ||
const target = this.getTarget(config); | ||
release(instance) { | ||
const target = this.getTarget(instance); | ||
const [leave] = getTreeDiff(target, null); | ||
@@ -84,11 +82,11 @@ const init = this.getEventInit(); | ||
// make this check not use the *asserted* cached value from `up`. | ||
/* istanbul ignore else */ if (hasPointerEvents(config, target)) { | ||
dispatchUIEvent(config, target, 'pointerout', init); | ||
leave.forEach((el)=>dispatchUIEvent(config, el, 'pointerleave', init)); | ||
/* istanbul ignore else */ if (hasPointerEvents(instance, target)) { | ||
instance.dispatchUIEvent(target, 'pointerout', init); | ||
leave.forEach((el)=>instance.dispatchUIEvent(el, 'pointerleave', init)); | ||
} | ||
this.isCancelled = true; | ||
} | ||
getTarget(config) { | ||
getTarget(instance) { | ||
var _target; | ||
return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body; | ||
return (_target = this.position.target) !== null && _target !== void 0 ? _target : instance.config.document.body; | ||
} | ||
@@ -95,0 +93,0 @@ getEventInit() { |
@@ -1,5 +0,1 @@ | ||
import '../setup/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.js'; | ||
import '../event/behavior/click.js'; | ||
@@ -12,12 +8,15 @@ import '../event/behavior/cut.js'; | ||
import '@testing-library/dom'; | ||
import { input } from '../utils/edit/input.js'; | ||
import '../event/eventMap.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import { isEditable } from '../utils/edit/isEditable.js'; | ||
import { focus } from '../utils/focus/focus.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import { isDisabled } from '../utils/misc/isDisabled.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import { isDisabled } from '../utils/misc/isDisabled.js'; | ||
import { selectAll, isAllSelected } from '../utils/focus/selectAll.js'; | ||
import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../utils/misc/level.js'; | ||
import '../options.js'; | ||
import { Config } from '../setup/config.js'; | ||
import { focusElement } from '../event/focus.js'; | ||
import { input } from '../event/input.js'; | ||
import { selectAll, isAllSelected } from '../event/selection/selectAll.js'; | ||
@@ -28,3 +27,3 @@ async function clear(element) { | ||
} | ||
focus(element); | ||
focusElement(element); | ||
if (element.ownerDocument.activeElement !== element) { | ||
@@ -37,5 +36,5 @@ throw new Error('The element to be cleared could not be focused.'); | ||
} | ||
input(this[Config], element, '', 'deleteContentBackward'); | ||
input(this, element, '', 'deleteContentBackward'); | ||
} | ||
export { clear }; |
import { getConfig } from '@testing-library/dom'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom/dist/helpers.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'; | ||
@@ -11,14 +19,4 @@ import '../event/behavior/cut.js'; | ||
import '../event/behavior/paste.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import { focus } from '../utils/focus/focus.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import { isDisabled } from '../utils/misc/isDisabled.js'; | ||
import { isElementType } from '../utils/misc/isElementType.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 '../setup/index.js'; | ||
import { Config } from '../setup/config.js'; | ||
import '../event/eventMap.js'; | ||
import { focusElement } from '../event/focus.js'; | ||
@@ -64,3 +62,3 @@ async function selectOptions(select, values) { | ||
for (const option of selectedOptions){ | ||
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], option); | ||
const withPointerEvents = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, option); | ||
// events fired for multiple select are weird. Can't use hover... | ||
@@ -77,3 +75,3 @@ if (withPointerEvents) { | ||
} | ||
focus(select); | ||
focusElement(select); | ||
if (withPointerEvents) { | ||
@@ -87,6 +85,6 @@ this.dispatchUIEvent(option, 'pointerup'); | ||
} | ||
await wait(this[Config]); | ||
await wait(this.config); | ||
} | ||
} else if (selectedOptions.length === 1) { | ||
const withPointerEvents1 = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], select); | ||
const withPointerEvents1 = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, select); | ||
// the click to open the select options | ||
@@ -96,3 +94,3 @@ if (withPointerEvents1) { | ||
} else { | ||
focus(select); | ||
focusElement(select); | ||
} | ||
@@ -111,3 +109,3 @@ selectOption(selectedOptions[0]); | ||
} | ||
await wait(this[Config]); | ||
await wait(this.config); | ||
} else { | ||
@@ -114,0 +112,0 @@ throw getConfig().getElementError(`Cannot select multiple options on a non-multiple select`, select); |
@@ -0,14 +1,6 @@ | ||
import { releaseAllKeys } from '../keyboard/index.js'; | ||
import '../utils/click/isClickableInput.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import { setSelectionRange } from '../utils/focus/selection.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
@@ -18,6 +10,5 @@ import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../options.js'; | ||
import { releaseAllKeys } from '../keyboard/index.js'; | ||
import { Config } from '../setup/config.js'; | ||
import { setSelectionRange } from '../event/selection/setSelectionRange.js'; | ||
async function type(element, text, { skipClick =this[Config].skipClick , skipAutoClose =this[Config].skipAutoClose , initialSelectionStart , initialSelectionEnd } = {}) { | ||
async function type(element, text, { skipClick =this.config.skipClick , skipAutoClose =this.config.skipAutoClose , initialSelectionStart , initialSelectionEnd } = {}) { | ||
// TODO: properly type guard | ||
@@ -34,3 +25,3 @@ // we use this workaround for now to prevent changing behavior | ||
if (!skipAutoClose) { | ||
await releaseAllKeys(this[Config]); | ||
await releaseAllKeys(this); | ||
} | ||
@@ -37,0 +28,0 @@ } |
import '../utils/click/isClickableInput.js'; | ||
import { createFileList } from '../utils/dataTransfer/FileList.js'; | ||
import '../utils/dataTransfer/Clipboard.js'; | ||
import '../event/eventMap.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 '@testing-library/dom'; | ||
import '../utils/edit/isEditable.js'; | ||
import '../utils/edit/maxLength.js'; | ||
import '../utils/edit/isEditable.js'; | ||
import { setFiles } from '../utils/edit/setFiles.js'; | ||
import { isElementType } from '../utils/misc/isElementType.js'; | ||
import { isDisabled } from '../utils/misc/isDisabled.js'; | ||
import { isElementType } from '../utils/misc/isElementType.js'; | ||
import { getWindow } from '../utils/misc/getWindow.js'; | ||
@@ -21,4 +13,2 @@ import '../utils/keyDef/readNextDescriptor.js'; | ||
import '../options.js'; | ||
import '../setup/index.js'; | ||
import { Config } from '../setup/config.js'; | ||
@@ -35,3 +25,3 @@ async function upload(element, fileOrFiles) { | ||
fileOrFiles | ||
]).filter((file)=>!this[Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); | ||
]).filter((file)=>!this.config.applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); | ||
const fileDialog = ()=>{ | ||
@@ -38,0 +28,0 @@ var ref; |
@@ -1,18 +0,4 @@ | ||
import '../click/isClickableInput.js'; | ||
import { getWindow } from '../misc/getWindow.js'; | ||
import { readBlobText } from './Blob.js'; | ||
import { createDataTransfer, getBlobFromDataTransferItem } from './DataTransfer.js'; | ||
import '../../event/eventMap.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 '@testing-library/dom'; | ||
import '../edit/maxLength.js'; | ||
import '../edit/isEditable.js'; | ||
import { getWindow } from '../misc/getWindow.js'; | ||
import '../keyDef/readNextDescriptor.js'; | ||
import '../misc/level.js'; | ||
import '../../options.js'; | ||
@@ -19,0 +5,0 @@ // Clipboard is not available in jsdom |
@@ -5,5 +5,3 @@ import { isElementType } from '../misc/isElementType.js'; | ||
function isEditable(element) { | ||
return isEditableInput(element) || isElementType(element, 'textarea', { | ||
readOnly: false | ||
}) || isContentEditable(element); | ||
return isEditableInputOrTextArea(element) && !element.readOnly || isContentEditable(element); | ||
} | ||
@@ -25,8 +23,6 @@ var editableInputTypes; | ||
})(editableInputTypes || (editableInputTypes = {})); | ||
function isEditableInput(element) { | ||
return isElementType(element, 'input', { | ||
readOnly: false | ||
}) && Boolean(editableInputTypes[element.type]); | ||
function isEditableInputOrTextArea(element) { | ||
return isElementType(element, 'textarea') || isElementType(element, 'input') && element.type in editableInputTypes; | ||
} | ||
export { editableInputTypes, isEditable, isEditableInput }; | ||
export { isEditable, isEditableInputOrTextArea }; |
import { isElementType } from '../misc/isElementType.js'; | ||
import { getValue } from './getValue.js'; | ||
@@ -13,16 +12,5 @@ var maxLengthSupportedTypes; | ||
})(maxLengthSupportedTypes || (maxLengthSupportedTypes = {})); | ||
function getSpaceUntilMaxLength(element) { | ||
const value = getValue(element); | ||
/* istanbul ignore if */ if (value === null) { | ||
return undefined; | ||
} | ||
const maxLength = getSanitizedMaxLength(element); | ||
return maxLength ? maxLength - value.length : undefined; | ||
} | ||
// can't use .maxLength property because of a jsdom bug: | ||
// https://github.com/jsdom/jsdom/issues/2927 | ||
function getSanitizedMaxLength(element) { | ||
if (!supportsMaxLength(element)) { | ||
return undefined; | ||
} | ||
function getMaxLength(element) { | ||
var ref; | ||
@@ -33,5 +21,5 @@ const attr = (ref = element.getAttribute('maxlength')) !== null && ref !== void 0 ? ref : ''; | ||
function supportsMaxLength(element) { | ||
return isElementType(element, 'textarea') || isElementType(element, 'input') && Boolean(maxLengthSupportedTypes[element.type]); | ||
return isElementType(element, 'textarea') || isElementType(element, 'input') && element.type in maxLengthSupportedTypes; | ||
} | ||
export { getSpaceUntilMaxLength }; | ||
export { getMaxLength, supportsMaxLength }; |
@@ -1,19 +0,3 @@ | ||
import '../click/isClickableInput.js'; | ||
import '../dataTransfer/Clipboard.js'; | ||
import '../../event/eventMap.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 '@testing-library/dom'; | ||
import { isContentEditable } from '../edit/isContentEditable.js'; | ||
import '../edit/maxLength.js'; | ||
import '../edit/isEditable.js'; | ||
import { isElementType } from '../misc/isElementType.js'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import '../keyDef/readNextDescriptor.js'; | ||
import '../misc/level.js'; | ||
import '../../options.js'; | ||
@@ -20,0 +4,0 @@ function getNextCursorPosition(node, offset, direction, inputType) { |
@@ -1,51 +0,9 @@ | ||
import { isElementType } from '../misc/isElementType.js'; | ||
import { isClickableInput } from '../click/isClickableInput.js'; | ||
import '../dataTransfer/Clipboard.js'; | ||
import { isContentEditable, getContentEditable } from '../edit/isContentEditable.js'; | ||
import '../edit/maxLength.js'; | ||
import { editableInputTypes } from '../edit/isEditable.js'; | ||
import '@testing-library/dom'; | ||
import '@testing-library/dom/dist/helpers.js'; | ||
import { getNextCursorPosition } from './cursor.js'; | ||
import { resolveCaretPosition } from './resolveCaretPosition.js'; | ||
import '../keyDef/readNextDescriptor.js'; | ||
import '../misc/level.js'; | ||
import '../../options.js'; | ||
import '../../event/eventMap.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 { setUISelection, getUISelection } from '../../document/selection.js'; | ||
import { getUIValue } from '../../document/value.js'; | ||
import { isEditableInputOrTextArea } from '../edit/isEditable.js'; | ||
/** | ||
* Backward-compatible selection. | ||
* | ||
* Handles input elements and contenteditable if it only contains a single text node. | ||
*/ function setSelectionRange(element, anchorOffset, focusOffset) { | ||
var ref; | ||
if (hasOwnSelection(element)) { | ||
return setSelection({ | ||
focusNode: element, | ||
anchorOffset, | ||
focusOffset | ||
}); | ||
} | ||
/* istanbul ignore else */ if (isContentEditable(element) && ((ref = element.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3) { | ||
return setSelection({ | ||
focusNode: element.firstChild, | ||
anchorOffset, | ||
focusOffset | ||
}); | ||
} | ||
/* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.'); | ||
} | ||
/** | ||
* Determine if the element has its own selection implementation | ||
* and does not interact with the Document Selection API. | ||
*/ function hasOwnSelection(node) { | ||
return isElement(node) && (isElementType(node, 'textarea') || isElementType(node, 'input') && node.type in editableInputTypes); | ||
return isElement(node) && isEditableInputOrTextArea(node); | ||
} | ||
@@ -58,223 +16,3 @@ function hasNoSelection(node) { | ||
} | ||
/** | ||
* Determine which selection logic and selection ranges to consider. | ||
*/ function getTargetTypeAndSelection(node) { | ||
const element = getElement(node); | ||
if (element && hasOwnSelection(element)) { | ||
return { | ||
type: 'input', | ||
selection: getUISelection(element) | ||
}; | ||
} | ||
const selection = element === null || element === void 0 ? void 0 : element.ownerDocument.getSelection(); | ||
// It is possible to extend a single-range selection into a contenteditable. | ||
// This results in the range acting like a range outside of contenteditable. | ||
const isCE = getContentEditable(node) && (selection === null || selection === void 0 ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode); | ||
return { | ||
type: isCE ? 'contenteditable' : 'default', | ||
selection | ||
}; | ||
} | ||
function getElement(node) { | ||
return node.nodeType === 1 ? node : node.parentElement; | ||
} | ||
/** | ||
* Reset the Document Selection when moving focus into an element | ||
* with own selection implementation. | ||
*/ function updateSelectionOnFocus(element) { | ||
const selection = element.ownerDocument.getSelection(); | ||
/* istanbul ignore if */ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) { | ||
return; | ||
} | ||
// If the focus moves inside an element with own selection implementation, | ||
// the document selection will be this element. | ||
// But if the focused element is inside a contenteditable, | ||
// 1) a collapsed selection will be retained. | ||
// 2) other selections will be replaced by a cursor | ||
// 2.a) at the start of the first child if it is a text node | ||
// 2.b) at the start of the contenteditable. | ||
if (hasOwnSelection(element)) { | ||
const contenteditable = getContentEditable(selection.focusNode); | ||
if (contenteditable) { | ||
if (!selection.isCollapsed) { | ||
var ref; | ||
const focusNode = ((ref = contenteditable.firstChild) === null || ref === void 0 ? void 0 : ref.nodeType) === 3 ? contenteditable.firstChild : contenteditable; | ||
selection.setBaseAndExtent(focusNode, 0, focusNode, 0); | ||
} | ||
} else { | ||
selection.setBaseAndExtent(element, 0, element, 0); | ||
} | ||
} | ||
} | ||
/** | ||
* Get the range that would be overwritten by input. | ||
*/ function getInputRange(focusNode) { | ||
const typeAndSelection = getTargetTypeAndSelection(focusNode); | ||
if (typeAndSelection.type === 'input') { | ||
return typeAndSelection.selection; | ||
} else if (typeAndSelection.type === 'contenteditable') { | ||
var ref; | ||
// Multi-range on contenteditable edits the first selection instead of the last | ||
return (ref = typeAndSelection.selection) === null || ref === void 0 ? void 0 : ref.getRangeAt(0); | ||
} | ||
} | ||
/** | ||
* Extend/shrink the selection like with Shift+Arrows or Shift+Mouse | ||
*/ function modifySelection({ focusNode , focusOffset }) { | ||
var ref, ref1; | ||
const typeAndSelection = getTargetTypeAndSelection(focusNode); | ||
if (typeAndSelection.type === 'input') { | ||
return setUISelection(focusNode, { | ||
anchorOffset: typeAndSelection.selection.anchorOffset, | ||
focusOffset | ||
}, 'modify'); | ||
} | ||
(ref1 = (ref = focusNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.extend(focusNode, focusOffset); | ||
} | ||
/** | ||
* Set the selection | ||
*/ function setSelection({ focusNode , focusOffset , anchorNode =focusNode , anchorOffset =focusOffset }) { | ||
var ref, ref1; | ||
const typeAndSelection = getTargetTypeAndSelection(focusNode); | ||
if (typeAndSelection.type === 'input') { | ||
return setUISelection(focusNode, { | ||
anchorOffset, | ||
focusOffset | ||
}); | ||
} | ||
(ref1 = (ref = anchorNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset); | ||
} | ||
/** | ||
* Move the selection | ||
*/ function moveSelection(node, direction) { | ||
// TODO: implement shift | ||
if (hasOwnSelection(node)) { | ||
const selection = getUISelection(node); | ||
setSelection({ | ||
focusNode: node, | ||
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset | ||
}); | ||
} else { | ||
const selection1 = node.ownerDocument.getSelection(); | ||
if (!(selection1 === null || selection1 === void 0 ? void 0 : selection1.focusNode)) { | ||
return; | ||
} | ||
if (selection1.isCollapsed) { | ||
const nextPosition = getNextCursorPosition(selection1.focusNode, selection1.focusOffset, direction); | ||
if (nextPosition) { | ||
setSelection({ | ||
focusNode: nextPosition.node, | ||
focusOffset: nextPosition.offset | ||
}); | ||
} | ||
} else { | ||
selection1[direction < 0 ? 'collapseToStart' : 'collapseToEnd'](); | ||
} | ||
} | ||
} | ||
function setSelectionPerMouseDown({ document , target , clickCount , node , offset }) { | ||
if (hasNoSelection(target)) { | ||
return; | ||
} | ||
const targetHasOwnSelection = hasOwnSelection(target); | ||
// On non-input elements the text selection per multiple click | ||
// can extend beyond the target boundaries. | ||
// The exact mechanism what is considered in the same line is unclear. | ||
// Looks it might be every inline element. | ||
// TODO: Check what might be considered part of the same line of text. | ||
const text = String(targetHasOwnSelection ? getUIValue(target) : target.textContent); | ||
const [start, end] = node ? // which elements might be considered in the same line of text. | ||
// TODO: support expanding initial range on multiple clicks if node is given | ||
[ | ||
offset, | ||
offset | ||
] : getTextRange(text, offset, clickCount); | ||
// TODO: implement modifying selection per shift/ctrl+mouse | ||
if (targetHasOwnSelection) { | ||
setUISelection(target, { | ||
anchorOffset: start !== null && start !== void 0 ? start : text.length, | ||
focusOffset: end !== null && end !== void 0 ? end : text.length | ||
}); | ||
return { | ||
node: target, | ||
start: start !== null && start !== void 0 ? start : 0, | ||
end: end !== null && end !== void 0 ? end : text.length | ||
}; | ||
} else { | ||
const { node: startNode , offset: startOffset } = resolveCaretPosition({ | ||
target, | ||
node, | ||
offset: start | ||
}); | ||
const { node: endNode , offset: endOffset } = resolveCaretPosition({ | ||
target, | ||
node, | ||
offset: end | ||
}); | ||
const range = target.ownerDocument.createRange(); | ||
try { | ||
range.setStart(startNode, startOffset); | ||
range.setEnd(endNode, endOffset); | ||
} catch (e) { | ||
throw new Error('The given offset is out of bounds.'); | ||
} | ||
const selection = document.getSelection(); | ||
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges(); | ||
selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange()); | ||
return range; | ||
} | ||
} | ||
function getTextRange(text, pos, clickCount) { | ||
if (clickCount % 3 === 1 || text.length === 0) { | ||
return [ | ||
pos, | ||
pos | ||
]; | ||
} | ||
const textPos = pos !== null && pos !== void 0 ? pos : text.length; | ||
if (clickCount % 3 === 2) { | ||
return [ | ||
textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length, | ||
pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length, | ||
]; | ||
} | ||
// triple click | ||
return [ | ||
textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length, | ||
pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length, | ||
]; | ||
} | ||
function modifySelectionPerMouseMove(selectionRange, { document , target , node , offset }) { | ||
const selectionFocus = resolveCaretPosition({ | ||
target, | ||
node, | ||
offset | ||
}); | ||
if ('node' in selectionRange) { | ||
// When the mouse is dragged outside of an input/textarea, | ||
// the selection is extended to the beginning or end of the input | ||
// depending on pointer position. | ||
// TODO: extend selection according to pointer position | ||
/* istanbul ignore else */ if (selectionFocus.node === selectionRange.node) { | ||
const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start; | ||
const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end; | ||
setUISelection(selectionRange.node, { | ||
anchorOffset, | ||
focusOffset | ||
}); | ||
} | ||
} else { | ||
const range = selectionRange.cloneRange(); | ||
const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset); | ||
if (cmp < 0) { | ||
range.setStart(selectionFocus.node, selectionFocus.offset); | ||
} else if (cmp > 0) { | ||
range.setEnd(selectionFocus.node, selectionFocus.offset); | ||
} | ||
const selection = document.getSelection(); | ||
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges(); | ||
selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange()); | ||
} | ||
} | ||
export { getInputRange, hasNoSelection, hasOwnSelection, modifySelection, modifySelectionPerMouseMove, moveSelection, setSelection, setSelectionPerMouseDown, setSelectionRange, updateSelectionOnFocus }; | ||
export { hasNoSelection, hasOwnSelection }; |
@@ -6,22 +6,15 @@ export { isClickableInput } from './click/isClickableInput.js'; | ||
export { attachClipboardStubToView, createClipboardItem, detachClipboardStubFromView, readDataTransferFromClipboard, resetClipboardStubOnView, writeDataTransferToClipboard } from './dataTransfer/Clipboard.js'; | ||
export { getValue } from './edit/getValue.js'; | ||
export { input } from './edit/input.js'; | ||
export { buildTimeValue, isValidDateOrTimeValue } from './edit/timeValue.js'; | ||
export { getContentEditable, isContentEditable } from './edit/isContentEditable.js'; | ||
export { editableInputTypes, isEditable, isEditableInput } from './edit/isEditable.js'; | ||
export { isEditable, isEditableInputOrTextArea } from './edit/isEditable.js'; | ||
export { getMaxLength, supportsMaxLength } from './edit/maxLength.js'; | ||
export { setFiles } from './edit/setFiles.js'; | ||
export { walkRadio } from './edit/walkRadio.js'; | ||
export { blur } from './focus/blur.js'; | ||
export { copySelection } from './focus/copySelection.js'; | ||
export { getNextCursorPosition } from './focus/cursor.js'; | ||
export { focus } from './focus/focus.js'; | ||
export { getActiveElement, getActiveElementOrBody } from './focus/getActiveElement.js'; | ||
export { getTabDestination } from './focus/getTabDestination.js'; | ||
export { isFocusable } from './focus/isFocusable.js'; | ||
export { isAllSelected, selectAll } from './focus/selectAll.js'; | ||
export { resolveCaretPosition } from './focus/resolveCaretPosition.js'; | ||
export { getInputRange, hasNoSelection, hasOwnSelection, modifySelection, modifySelectionPerMouseMove, moveSelection, setSelection, setSelectionPerMouseDown, setSelectionRange, updateSelectionOnFocus } from './focus/selection.js'; | ||
export { hasNoSelection, hasOwnSelection } from './focus/selection.js'; | ||
export { FOCUSABLE_SELECTOR } from './focus/selector.js'; | ||
export { readNextDescriptor } from './keyDef/readNextDescriptor.js'; | ||
export { cloneEvent } from './misc/cloneEvent.js'; | ||
export { eventWrapper } from './misc/eventWrapper.js'; | ||
export { findClosest } from './misc/findClosest.js'; | ||
@@ -28,0 +21,0 @@ export { getDocumentFromNode } from './misc/getDocumentFromNode.js'; |
@@ -1,2 +0,1 @@ | ||
var _config, _Level; | ||
var ApiLevel; | ||
@@ -7,13 +6,9 @@ (function(ApiLevel) { | ||
})(ApiLevel || (ApiLevel = {})); | ||
const Level = Symbol('Api level refs'); | ||
function setLevelRef(config, level) { | ||
var ref; | ||
(ref = (_config = config)[_Level = Level]) !== null && ref !== void 0 ? ref : _config[_Level] = {}; | ||
config[Level][level] = {}; | ||
function setLevelRef(instance, level) { | ||
instance.levelRefs[level] = {}; | ||
} | ||
function getLevelRef(config, level) { | ||
var ref; | ||
return (ref = config[Level]) === null || ref === void 0 ? void 0 : ref[level]; | ||
function getLevelRef(instance, level) { | ||
return instance.levelRefs[level]; | ||
} | ||
export { ApiLevel, getLevelRef, setLevelRef }; |
import { PointerEventsCheckLevel } from '../../options.js'; | ||
import '../click/isClickableInput.js'; | ||
import '../dataTransfer/Clipboard.js'; | ||
import '../../event/eventMap.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 '@testing-library/dom'; | ||
import '../edit/maxLength.js'; | ||
import '../edit/isEditable.js'; | ||
import { getWindow } from '../misc/getWindow.js'; | ||
import { isElementType } from '../misc/isElementType.js'; | ||
import { getWindow } from '../misc/getWindow.js'; | ||
import '../keyDef/readNextDescriptor.js'; | ||
import { ApiLevel, getLevelRef } from '../misc/level.js'; | ||
function hasPointerEvents(config, element) { | ||
function hasPointerEvents(instance, element) { | ||
var ref; | ||
return ((ref = checkPointerEvents(config, element)) === null || ref === void 0 ? void 0 : ref.pointerEvents) !== 'none'; | ||
return ((ref = checkPointerEvents(instance, element)) === null || ref === void 0 ? void 0 : ref.pointerEvents) !== 'none'; | ||
} | ||
@@ -41,5 +28,5 @@ function closestPointerEventsDeclaration(element) { | ||
const PointerEventsCheck = Symbol('Last check for pointer-events'); | ||
function checkPointerEvents(config, element) { | ||
function checkPointerEvents(instance, element) { | ||
const lastCheck = element[PointerEventsCheck]; | ||
const needsCheck = config.pointerEventsCheck !== PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(config.pointerEventsCheck, PointerEventsCheckLevel.EachApiCall) && lastCheck[ApiLevel.Call] !== getLevelRef(config, ApiLevel.Call) || hasBitFlag(config.pointerEventsCheck, PointerEventsCheckLevel.EachTrigger) && lastCheck[ApiLevel.Trigger] !== getLevelRef(config, ApiLevel.Trigger)); | ||
const needsCheck = instance.config.pointerEventsCheck !== PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(instance.config.pointerEventsCheck, PointerEventsCheckLevel.EachApiCall) && lastCheck[ApiLevel.Call] !== getLevelRef(instance, ApiLevel.Call) || hasBitFlag(instance.config.pointerEventsCheck, PointerEventsCheckLevel.EachTrigger) && lastCheck[ApiLevel.Trigger] !== getLevelRef(instance, ApiLevel.Trigger)); | ||
if (!needsCheck) { | ||
@@ -50,4 +37,4 @@ return lastCheck === null || lastCheck === void 0 ? void 0 : lastCheck.result; | ||
element[PointerEventsCheck] = { | ||
[ApiLevel.Call]: getLevelRef(config, ApiLevel.Call), | ||
[ApiLevel.Trigger]: getLevelRef(config, ApiLevel.Trigger), | ||
[ApiLevel.Call]: getLevelRef(instance, ApiLevel.Call), | ||
[ApiLevel.Trigger]: getLevelRef(instance, ApiLevel.Trigger), | ||
result: declaration | ||
@@ -57,4 +44,4 @@ }; | ||
} | ||
function assertPointerEvents(config, element) { | ||
const declaration = checkPointerEvents(config, element); | ||
function assertPointerEvents(instance, element) { | ||
const declaration = checkPointerEvents(instance, element); | ||
if ((declaration === null || declaration === void 0 ? void 0 : declaration.pointerEvents) === 'none') { | ||
@@ -61,0 +48,0 @@ throw new Error([ |
@@ -1,2 +0,2 @@ | ||
import { Instance } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
export declare function copy(this: Instance): Promise<DataTransfer | undefined>; |
@@ -1,2 +0,2 @@ | ||
import { Instance } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
export declare function cut(this: Instance): Promise<DataTransfer | undefined>; |
@@ -1,2 +0,2 @@ | ||
import { Instance } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
export declare function paste(this: Instance, clipboardData?: DataTransfer | string): Promise<void>; |
@@ -1,4 +0,4 @@ | ||
import { Instance } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
export declare function click(this: Instance, element: Element): Promise<void>; | ||
export declare function dblClick(this: Instance, element: Element): Promise<void>; | ||
export declare function tripleClick(this: Instance, element: Element): Promise<void>; |
@@ -1,3 +0,3 @@ | ||
import { Instance } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
export declare function hover(this: Instance, element: Element): Promise<void>; | ||
export declare function unhover(this: Instance, element: Element): Promise<void>; |
@@ -1,10 +0,5 @@ | ||
declare const isPrepared: unique symbol; | ||
declare global { | ||
interface Node { | ||
[isPrepared]?: typeof isPrepared; | ||
} | ||
} | ||
export declare function prepareDocument(document: Document): void; | ||
export { getUIValue, setUIValue, commitValueAfterInput, clearInitialValue, } from './value'; | ||
export { getUISelection, setUISelection } from './selection'; | ||
export type { UISelectionRange } from './selection'; | ||
export { getUISelection, getUIValue, setUISelection, setUIValue, clearInitialValue, } from './UI'; | ||
export type { UISelectionRange } from './UI'; | ||
export { getValueOrTextContent } from './getValueOrTextContent'; | ||
export { copySelection } from './copySelection'; | ||
export { commitValueAfterInput } from './trackValue'; |
@@ -16,2 +16,5 @@ declare type anyFunc = (...a: any[]) => any; | ||
}): void; | ||
export declare function prepareValueInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void; | ||
export declare function prepareSelectionInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void; | ||
export declare function prepareRangeTextInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void; | ||
export {}; |
@@ -1,5 +0,5 @@ | ||
import { Config } from '../../setup'; | ||
import type { Instance } from '../../setup'; | ||
import { EventType } from '../types'; | ||
export interface BehaviorPlugin<Type extends EventType> { | ||
(event: DocumentEventMap[Type], target: Element, config: Config): // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
(event: DocumentEventMap[Type], target: Element, instance: Instance): // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
void | (() => void); | ||
@@ -6,0 +6,0 @@ } |
@@ -1,2 +0,5 @@ | ||
import { Config } from '../setup'; | ||
export declare function dispatchEvent(config: Config, target: Element, event: Event, preventDefault?: boolean): boolean; | ||
import type { Instance } from '../setup'; | ||
import { EventType, EventTypeInit } from './types'; | ||
export declare function dispatchUIEvent<K extends EventType>(this: Instance, target: Element, type: K, init?: EventTypeInit<K>, preventDefault?: boolean): boolean; | ||
export declare function dispatchEvent(this: Instance, target: Element, event: Event, preventDefault?: boolean): boolean; | ||
export declare function dispatchDOMEvent<K extends EventType>(target: Element, type: K, init?: EventTypeInit<K>): void; |
@@ -1,5 +0,7 @@ | ||
import { Config } from '../setup'; | ||
import { EventType, EventTypeInit, PointerCoords } from './types'; | ||
import { EventType, PointerCoords } from './types'; | ||
export type { EventType, PointerCoords }; | ||
export declare function dispatchUIEvent<K extends EventType>(config: Config, target: Element, type: K, init?: EventTypeInit<K>, preventDefault?: boolean): boolean; | ||
export declare function bindDispatchUIEvent(config: Config): (target: Element, type: keyof DocumentEventMap, init?: InputEventInit | UIEventInit | EventInit | ClipboardEventInit | MouseEventInit | PointerEventInit | KeyboardEventInit | undefined, preventDefault?: boolean | undefined) => boolean; | ||
export { dispatchEvent, dispatchUIEvent, dispatchDOMEvent } from './dispatchEvent'; | ||
export { blurElement, focusElement } from './focus'; | ||
export { input } from './input'; | ||
export type { SelectionRange } from './selection'; | ||
export { isAllSelected, modifySelectionPerMouseMove, setSelectionPerMouseDown, selectAll, } from './selection'; |
@@ -1,3 +0,3 @@ | ||
import { Config, Instance } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
export declare function keyboard(this: Instance, text: string): Promise<void>; | ||
export declare function releaseAllKeys(config: Config): Promise<void>; | ||
export declare function releaseAllKeys(instance: Instance): Promise<void>; |
@@ -116,9 +116,1 @@ import type { keyboardKey } from './system/keyboard'; | ||
} | ||
/** | ||
* Default options applied when API is called per `userEvent.anyApi()` | ||
*/ | ||
export declare const defaultOptionsDirect: Required<Options>; | ||
/** | ||
* Default options applied when API is called per `userEvent().anyApi()` | ||
*/ | ||
export declare const defaultOptionsSetup: Required<Options>; |
@@ -1,4 +0,4 @@ | ||
import { PointerCoords } from '../event'; | ||
import { Instance } from '../setup'; | ||
import { pointerKey } from '../system/pointer'; | ||
import type { PointerCoords } from '../event'; | ||
import type { Instance } from '../setup'; | ||
import type { pointerKey } from '../system/pointer'; | ||
declare type PointerActionInput = string | ({ | ||
@@ -5,0 +5,0 @@ keys: string; |
import type { Options } from '../options'; | ||
import type { PointerInput } from '../pointer'; | ||
import type { System } from '../system'; | ||
import type { UserEventApi } from '.'; | ||
import type { UserEventApi } from './setup'; | ||
export declare type DirectOptions = Options & { | ||
@@ -6,0 +6,0 @@ keyboardState?: System; |
@@ -1,17 +0,4 @@ | ||
import type { bindDispatchUIEvent } from '../event'; | ||
import type * as userEventApi from './api'; | ||
import { setupMain, setupSub } from './setup'; | ||
import { Config } from './config'; | ||
import { setupMain } from './setup'; | ||
import * as directApi from './directApi'; | ||
export { Config }; | ||
export declare type UserEventApi = typeof userEventApi; | ||
export declare type Instance = UserEventApi & { | ||
[Config]: Config; | ||
dispatchUIEvent: ReturnType<typeof bindDispatchUIEvent>; | ||
}; | ||
export declare type UserEvent = { | ||
readonly setup: (...args: Parameters<typeof setupSub>) => UserEvent; | ||
} & { | ||
readonly [k in keyof UserEventApi]: (...args: Parameters<UserEventApi[k]>) => ReturnType<UserEventApi[k]>; | ||
}; | ||
export type { Instance } from './setup'; | ||
export declare const userEvent: { | ||
@@ -18,0 +5,0 @@ readonly setup: typeof setupMain; |
@@ -0,7 +1,21 @@ | ||
import { dispatchEvent, dispatchUIEvent } from '../event'; | ||
import { Options } from '../options'; | ||
import { System } from '../system'; | ||
import type { Instance, UserEvent } from './index'; | ||
import { Config } from './config'; | ||
import * as userEventApi from './api'; | ||
import { DirectOptions } from './directApi'; | ||
export declare function createConfig(options?: Partial<Config>, defaults?: Required<Options>, node?: Node): Config; | ||
export declare type UserEventApi = typeof userEventApi; | ||
export declare type UserEvent = { | ||
readonly setup: (...args: Parameters<typeof setupSub>) => UserEvent; | ||
} & { | ||
readonly [k in keyof UserEventApi]: (...args: Parameters<UserEventApi[k]>) => ReturnType<UserEventApi[k]>; | ||
}; | ||
export declare type Instance = UserEventApi & { | ||
config: Config; | ||
dispatchEvent: OmitThisParameter<typeof dispatchEvent>; | ||
dispatchUIEvent: OmitThisParameter<typeof dispatchUIEvent>; | ||
system: System; | ||
levelRefs: Record<number, object | undefined>; | ||
}; | ||
export declare type Config = Required<Options>; | ||
export declare function createConfig(options?: Options, defaults?: Required<Options>, node?: Node): Config; | ||
/** | ||
@@ -15,9 +29,9 @@ * Start a "session" with userEvent. | ||
*/ | ||
export declare function setupDirect({ keyboardState, pointerState, ...options }?: DirectOptions & // backward-compatibility | ||
{ | ||
export declare function setupDirect({ keyboardState, pointerState, ...options }?: DirectOptions & { | ||
keyboardState?: System; | ||
pointerState?: System; | ||
}, node?: Node): { | ||
config: Config; | ||
}, // backward-compatibility | ||
node?: Node): { | ||
api: UserEvent; | ||
system: System; | ||
}; | ||
@@ -28,1 +42,5 @@ /** | ||
export declare function setupSub(this: Instance, options: Options): UserEvent; | ||
export declare function createInstance(config: Config, system?: System): { | ||
instance: Instance; | ||
api: UserEvent; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { Config } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
import type { System } from '.'; | ||
@@ -48,7 +48,7 @@ export declare enum DOM_KEY_LOCATION { | ||
/** Press a key */ | ||
keydown(config: Config, keyDef: keyboardKey): Promise<void>; | ||
keydown(instance: Instance, keyDef: keyboardKey): Promise<void>; | ||
/** Release a key */ | ||
keyup(config: Config, keyDef: keyboardKey): Promise<void>; | ||
keyup(instance: Instance, keyDef: keyboardKey): Promise<void>; | ||
private setKeydownTarget; | ||
private hasKeyPress; | ||
} |
@@ -1,2 +0,2 @@ | ||
import type { pointerKey } from '.'; | ||
import type { pointerKey } from './shared'; | ||
export declare class Buttons { | ||
@@ -3,0 +3,0 @@ private readonly pressed; |
import { System } from '..'; | ||
import { PointerCoords } from '../../event'; | ||
import { Config } from '../../setup'; | ||
import { MouseButton } from './buttons'; | ||
export interface pointerKey { | ||
/** Name of the pointer key */ | ||
name: string; | ||
/** Type of the pointer device */ | ||
pointerType: 'mouse' | 'pen' | 'touch'; | ||
/** Type of button */ | ||
button?: MouseButton; | ||
} | ||
export interface PointerPosition { | ||
target?: Element; | ||
coords?: PointerCoords; | ||
caret?: CaretPosition; | ||
} | ||
export interface CaretPosition { | ||
node?: Node; | ||
offset?: number; | ||
} | ||
import { Instance } from '../../setup'; | ||
import { pointerKey, PointerPosition } from './shared'; | ||
export type { pointerKey, PointerPosition } from './shared'; | ||
export declare class PointerHost { | ||
@@ -30,11 +13,10 @@ readonly system: System; | ||
isKeyPressed(keyDef: pointerKey): boolean; | ||
press(config: Config, keyDef: pointerKey, position: PointerPosition): Promise<void>; | ||
move(config: Config, pointerName: string, position: PointerPosition): Promise<void>; | ||
release(config: Config, keyDef: pointerKey, position: PointerPosition): Promise<void>; | ||
press(instance: Instance, keyDef: pointerKey, position: PointerPosition): Promise<void>; | ||
move(instance: Instance, pointerName: string, position: PointerPosition): Promise<void>; | ||
release(instance: Instance, keyDef: pointerKey, position: PointerPosition): Promise<void>; | ||
getPointerName(keyDef: pointerKey): string; | ||
getPreviousPosition(pointerName: string): PointerPosition | undefined; | ||
resetClickCount(): void; | ||
getMouseTarget(config: Config): Element; | ||
getMouseTarget(instance: Instance): Element; | ||
setMousePosition(position: PointerPosition): void; | ||
} | ||
export declare function isDifferentPointerPosition(positionA: PointerPosition, positionB: PointerPosition): boolean; |
@@ -1,4 +0,4 @@ | ||
import { Config } from '../../setup'; | ||
import { pointerKey, PointerPosition } from '.'; | ||
import type { Instance } from '../../setup'; | ||
import type { Pointer } from './pointer'; | ||
import { pointerKey, PointerPosition } from './shared'; | ||
/** | ||
@@ -13,3 +13,3 @@ * This object is the single "virtual" mouse that might be controlled by multiple different pointer devices. | ||
private readonly clickCount; | ||
move(config: Config, position: PointerPosition): { | ||
move(instance: Instance, position: PointerPosition): { | ||
leave: () => void; | ||
@@ -19,4 +19,4 @@ enter: () => void; | ||
} | undefined; | ||
down(config: Config, keyDef: pointerKey, pointer: Pointer): void; | ||
up(config: Config, keyDef: pointerKey, pointer: Pointer): void; | ||
down(instance: Instance, keyDef: pointerKey, pointer: Pointer): void; | ||
up(instance: Instance, keyDef: pointerKey, pointer: Pointer): void; | ||
resetClickCount(): void; | ||
@@ -23,0 +23,0 @@ private getEventInit; |
@@ -1,3 +0,3 @@ | ||
import { Config } from '../../setup'; | ||
import { pointerKey, PointerPosition } from '.'; | ||
import type { Instance } from '../../setup'; | ||
import { pointerKey, PointerPosition } from './shared'; | ||
declare type PointerInit = { | ||
@@ -18,4 +18,4 @@ pointerId: number; | ||
position: PointerPosition; | ||
init(config: Config, position: PointerPosition): this; | ||
move(config: Config, position: PointerPosition): { | ||
init(instance: Instance, position: PointerPosition): this; | ||
move(instance: Instance, position: PointerPosition): { | ||
leave: () => void; | ||
@@ -25,5 +25,5 @@ enter: () => void; | ||
} | undefined; | ||
down(config: Config, _keyDef: pointerKey): void; | ||
up(config: Config, _keyDef: pointerKey): void; | ||
release(config: Config): void; | ||
down(instance: Instance, _keyDef: pointerKey): void; | ||
up(instance: Instance, _keyDef: pointerKey): void; | ||
release(instance: Instance): void; | ||
private getTarget; | ||
@@ -30,0 +30,0 @@ private getEventInit; |
@@ -1,2 +0,2 @@ | ||
import { Instance } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
export declare function clear(this: Instance, element: Element): Promise<void>; |
@@ -1,3 +0,3 @@ | ||
import { Instance } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
export declare function selectOptions(this: Instance, select: Element, values: HTMLElement | HTMLElement[] | string[] | string): Promise<void>; | ||
export declare function deselectOptions(this: Instance, select: Element, values: HTMLElement | HTMLElement[] | string[] | string): Promise<void>; |
import type { Instance } from '../setup'; | ||
import { Config } from '../setup/config'; | ||
import type { Options } from '../options'; | ||
export interface typeOptions { | ||
skipClick?: Config['skipClick']; | ||
skipAutoClose?: Config['skipClick']; | ||
skipClick?: Options['skipClick']; | ||
skipAutoClose?: Options['skipAutoClose']; | ||
initialSelectionStart?: number; | ||
@@ -7,0 +7,0 @@ initialSelectionEnd?: number; |
@@ -1,2 +0,2 @@ | ||
import { Instance } from '../setup'; | ||
import type { Instance } from '../setup'; | ||
export interface uploadInit { | ||
@@ -3,0 +3,0 @@ changeInit?: EventInit; |
@@ -11,6 +11,6 @@ declare enum clickableInputTypes { | ||
} | ||
export declare type ClickableInputType = keyof typeof clickableInputTypes; | ||
export declare function isClickableInput(element: Element): element is HTMLButtonElement | (HTMLInputElement & { | ||
export declare type ClickableInputOrButton = HTMLButtonElement | (HTMLInputElement & { | ||
type: clickableInputTypes; | ||
}); | ||
export declare function isClickableInput(element: Element): element is ClickableInputOrButton; | ||
export {}; |
import { isContentEditable } from './isContentEditable'; | ||
declare type GuardedType<T> = T extends (x: any) => x is infer R ? R : never; | ||
export declare function isEditable(element: Element): element is GuardedType<typeof isContentEditable> | GuardedType<typeof isEditableInput> | (HTMLTextAreaElement & { | ||
export declare function isEditable(element: Element): element is GuardedType<typeof isContentEditable> | (EditableInputOrTextarea & { | ||
readOnly: false; | ||
}); | ||
export declare enum editableInputTypes { | ||
declare enum editableInputTypes { | ||
'text' = "text", | ||
@@ -20,7 +20,6 @@ 'date' = "date", | ||
} | ||
export declare type EditableInputType = keyof typeof editableInputTypes; | ||
export declare function isEditableInput(element: Element): element is HTMLInputElement & { | ||
readOnly: false; | ||
export declare type EditableInputOrTextarea = HTMLTextAreaElement | (HTMLInputElement & { | ||
type: editableInputTypes; | ||
}; | ||
}); | ||
export declare function isEditableInputOrTextArea(element: Element): element is EditableInputOrTextarea; | ||
export {}; |
@@ -1,1 +0,14 @@ | ||
export declare function getSpaceUntilMaxLength(element: Element): number | undefined; | ||
declare enum maxLengthSupportedTypes { | ||
'email' = "email", | ||
'password' = "password", | ||
'search' = "search", | ||
'telephone' = "telephone", | ||
'text' = "text", | ||
'url' = "url" | ||
} | ||
declare type ElementWithMaxLengthSupport = HTMLTextAreaElement | (HTMLInputElement & { | ||
type: maxLengthSupportedTypes; | ||
}); | ||
export declare function getMaxLength(element: ElementWithMaxLengthSupport): number | undefined; | ||
export declare function supportsMaxLength(element: Element): element is ElementWithMaxLengthSupport; | ||
export {}; |
@@ -1,73 +0,8 @@ | ||
import { UISelectionRange } from '../../document'; | ||
import { EditableInputType, editableInputTypes } from '../edit/isEditable'; | ||
import { ClickableInputOrButton } from '../click/isClickableInput'; | ||
import { EditableInputOrTextarea } from '../edit/isEditable'; | ||
/** | ||
* Backward-compatible selection. | ||
* | ||
* Handles input elements and contenteditable if it only contains a single text node. | ||
*/ | ||
export declare function setSelectionRange(element: Element, anchorOffset: number, focusOffset: number): void; | ||
/** | ||
* Determine if the element has its own selection implementation | ||
* and does not interact with the Document Selection API. | ||
*/ | ||
export declare function hasOwnSelection(node: Node): node is HTMLTextAreaElement | (HTMLInputElement & { | ||
type: editableInputTypes; | ||
}); | ||
export declare function hasNoSelection(node: Node): boolean; | ||
/** | ||
* Reset the Document Selection when moving focus into an element | ||
* with own selection implementation. | ||
*/ | ||
export declare function updateSelectionOnFocus(element: Element): void; | ||
/** | ||
* Get the range that would be overwritten by input. | ||
*/ | ||
export declare function getInputRange(focusNode: Node): UISelectionRange | Range | undefined; | ||
/** | ||
* Extend/shrink the selection like with Shift+Arrows or Shift+Mouse | ||
*/ | ||
export declare function modifySelection({ focusNode, focusOffset, }: { | ||
focusNode: Node; | ||
/** DOM Offset */ | ||
focusOffset: number; | ||
}): void; | ||
/** | ||
* Set the selection | ||
*/ | ||
export declare function setSelection({ focusNode, focusOffset, anchorNode, anchorOffset, }: { | ||
anchorNode?: Node; | ||
/** DOM offset */ | ||
anchorOffset?: number; | ||
focusNode: Node; | ||
focusOffset: number; | ||
}): void; | ||
/** | ||
* Move the selection | ||
*/ | ||
export declare function moveSelection(node: Element, direction: -1 | 1): void; | ||
export declare type SelectionRange = { | ||
node: (HTMLInputElement & { | ||
type: EditableInputType; | ||
}) | HTMLTextAreaElement; | ||
start: number; | ||
end: number; | ||
}; | ||
export declare function setSelectionPerMouseDown({ document, target, clickCount, node, offset, }: { | ||
document: Document; | ||
target: Element; | ||
clickCount: number; | ||
node?: Node; | ||
offset?: number; | ||
}): Range | { | ||
node: HTMLTextAreaElement | (HTMLInputElement & { | ||
type: editableInputTypes; | ||
}); | ||
start: number; | ||
end: number; | ||
} | undefined; | ||
export declare function modifySelectionPerMouseMove(selectionRange: Range | SelectionRange, { document, target, node, offset, }: { | ||
document: Document; | ||
target: Element; | ||
node?: Node; | ||
offset?: number; | ||
}): void; | ||
export declare function hasOwnSelection(node: Node): node is EditableInputOrTextarea; | ||
export declare function hasNoSelection(node: Node): node is ClickableInputOrButton; |
@@ -6,17 +6,11 @@ export * from './click/isClickableInput'; | ||
export * from './dataTransfer/Clipboard'; | ||
export * from './edit/getValue'; | ||
export * from './edit/input'; | ||
export * from './edit/timeValue'; | ||
export * from './edit/isContentEditable'; | ||
export * from './edit/isEditable'; | ||
export * from './edit/maxLength'; | ||
export * from './edit/setFiles'; | ||
export * from './edit/walkRadio'; | ||
export * from './focus/blur'; | ||
export * from './focus/copySelection'; | ||
export * from './focus/cursor'; | ||
export * from './focus/focus'; | ||
export * from './focus/getActiveElement'; | ||
export * from './focus/getTabDestination'; | ||
export * from './focus/isFocusable'; | ||
export * from './focus/selectAll'; | ||
export * from './focus/resolveCaretPosition'; | ||
export * from './focus/selection'; | ||
@@ -26,3 +20,2 @@ export * from './focus/selector'; | ||
export * from './misc/cloneEvent'; | ||
export * from './misc/eventWrapper'; | ||
export * from './misc/findClosest'; | ||
@@ -29,0 +22,0 @@ export * from './misc/getDocumentFromNode'; |
@@ -1,2 +0,2 @@ | ||
import { Config } from '../../setup'; | ||
import type { Instance } from '../../setup'; | ||
export declare enum ApiLevel { | ||
@@ -6,13 +6,4 @@ Trigger = 2, | ||
} | ||
declare const Level: unique symbol; | ||
interface LevelRefs { | ||
[k: number]: object | undefined; | ||
} | ||
declare module '../../setup' { | ||
interface Config { | ||
[Level]?: LevelRefs; | ||
} | ||
} | ||
export declare function setLevelRef(config: Config, level: ApiLevel): void; | ||
export declare function getLevelRef(config: Config, level: ApiLevel): object | undefined; | ||
export {}; | ||
export declare type LevelRefs = Record<ApiLevel, object | undefined>; | ||
export declare function setLevelRef(instance: Instance, level: ApiLevel): void; | ||
export declare function getLevelRef(instance: Instance, level: ApiLevel): object | undefined; |
@@ -1,2 +0,2 @@ | ||
import { Config } from '../../setup'; | ||
export declare function wait(config: Config): Promise<[void, void]> | undefined; | ||
import type { Instance } from '../../setup'; | ||
export declare function wait(config: Instance['config']): Promise<[void, void]> | undefined; |
@@ -1,4 +0,4 @@ | ||
import { Config } from '../../setup'; | ||
import { ApiLevel } from '..'; | ||
export declare function hasPointerEvents(config: Config, element: Element): boolean; | ||
import type { Instance } from '../../setup'; | ||
import { ApiLevel } from '../misc/level'; | ||
export declare function hasPointerEvents(instance: Instance, element: Element): boolean; | ||
declare function closestPointerEventsDeclaration(element: Element): { | ||
@@ -18,3 +18,3 @@ pointerEvents: string; | ||
} | ||
export declare function assertPointerEvents(config: Config, element: Element): void; | ||
export declare function assertPointerEvents(instance: Instance, element: Element): void; | ||
export {}; |
{ | ||
"name": "@testing-library/user-event", | ||
"version": "14.4.2", | ||
"version": "14.4.3", | ||
"description": "Fire events the same way the user does", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@ph.fritsche/scripts-config": "^2.3.1", | ||
"@ph.fritsche/scripts-config": "^2.4.0", | ||
"@testing-library/dom": "^8.11.4", | ||
@@ -68,2 +68,3 @@ "@testing-library/jest-dom": "^5.16.3", | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"require": "./dist/cjs/index.js", | ||
@@ -70,0 +71,0 @@ "default": "./dist/esm/index.js" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
309
419746
10460