pseudo-dom 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +432 -13
- package/browser/pseudo-dom.js +3364 -603
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/classes/PseudoEventListener.d.ts +96 -96
- package/dist/classes/PseudoEventListener.js +151 -151
- package/dist/classes/PseudoHTMLDocument.d.ts +67 -67
- package/dist/classes/PseudoHTMLDocument.js +144 -144
- package/dist/classes/PseudoNodeList.d.ts +34 -34
- package/dist/classes/PseudoNodeList.js +71 -71
- package/dist/classes.d.ts +20 -20
- package/dist/classes.js +31 -31
- package/dist/factories/createEvent.d.ts +28 -28
- package/dist/factories/createEvent.js +56 -56
- package/dist/factories/cssSelectAdapter.d.ts +23 -0
- package/dist/factories/cssSelectAdapter.js +87 -0
- package/dist/factories/cssSelectAdapter.min.js +1 -0
- package/dist/factories/eventDefaults.d.ts +31 -31
- package/dist/factories/eventDefaults.js +105 -105
- package/dist/factories/generateDocument.d.ts +11 -11
- package/dist/factories/generateDocument.js +65 -65
- package/dist/factories/generateNode.d.ts +32 -32
- package/dist/factories/generateNode.js +85 -85
- package/dist/factories/generateNodeList.d.ts +9 -9
- package/dist/factories/generateNodeList.js +13 -13
- package/dist/factories/query.d.ts +33 -0
- package/dist/factories/query.js +66 -0
- package/dist/factories/query.min.js +1 -0
- package/dist/factories.d.ts +11 -11
- package/dist/factories.js +27 -27
- package/dist/functions/activeElement.d.ts +14 -14
- package/dist/functions/activeElement.js +33 -33
- package/dist/functions/getParentNodes.d.ts +11 -11
- package/dist/functions/getParentNodes.js +22 -22
- package/dist/functions/getParentNodesFromAttribute.d.ts +14 -14
- package/dist/functions/getParentNodesFromAttribute.js +29 -29
- package/dist/functions/modifierState.d.ts +29 -29
- package/dist/functions/modifierState.js +41 -41
- package/dist/functions.d.ts +5 -5
- package/dist/functions.js +23 -23
- package/dist/interfaces/PseudoAnimation.d.ts +3 -3
- package/dist/interfaces/PseudoAnimation.js +5 -5
- package/dist/interfaces/PseudoAttr.d.ts +11 -11
- package/dist/interfaces/PseudoAttr.js +5 -5
- package/dist/interfaces/PseudoDOMTokenList.d.ts +16 -16
- package/dist/interfaces/PseudoDOMTokenList.js +5 -5
- package/dist/interfaces/PseudoDocument.d.ts +7 -0
- package/dist/interfaces/PseudoDocument.js +5 -5
- package/dist/interfaces/PseudoDocumentFragment.d.ts +3 -3
- package/dist/interfaces/PseudoDocumentFragment.js +5 -5
- package/dist/interfaces/PseudoElement.d.ts +20 -7
- package/dist/interfaces/PseudoElement.js +5 -5
- package/dist/interfaces/PseudoEvent.d.ts +79 -79
- package/dist/interfaces/PseudoEvent.js +10 -10
- package/dist/interfaces/PseudoEventTarget.d.ts +46 -46
- package/dist/interfaces/PseudoEventTarget.js +5 -5
- package/dist/interfaces/PseudoHTMLCollection.d.ts +23 -23
- package/dist/interfaces/PseudoHTMLCollection.js +5 -5
- package/dist/interfaces/PseudoHTMLElement.d.ts +22 -22
- package/dist/interfaces/PseudoHTMLElement.js +5 -5
- package/dist/interfaces/PseudoHTMLSlotElement.d.ts +3 -3
- package/dist/interfaces/PseudoHTMLSlotElement.js +5 -5
- package/dist/interfaces/PseudoNamedNodeMap.d.ts +11 -11
- package/dist/interfaces/PseudoNamedNodeMap.js +5 -5
- package/dist/interfaces/PseudoNode.d.ts +179 -179
- package/dist/interfaces/PseudoNode.js +5 -5
- package/dist/interfaces/PseudoShadowRoot.d.ts +3 -3
- package/dist/interfaces/PseudoShadowRoot.js +5 -5
- package/dist/main.d.ts +63 -63
- package/dist/main.js +155 -155
- package/dist/services/AnimationService.d.ts +4 -4
- package/dist/services/AnimationService.js +16 -16
- package/dist/services/AttrService.d.ts +37 -37
- package/dist/services/AttrService.js +81 -81
- package/dist/services/CommentService.d.ts +1 -1
- package/dist/services/CommentService.js +13 -13
- package/dist/services/CustomEventService.d.ts +37 -37
- package/dist/services/CustomEventService.js +35 -35
- package/dist/services/DOMTokenListService.d.ts +33 -33
- package/dist/services/DOMTokenListService.js +117 -117
- package/dist/services/DocumentFragmentService.d.ts +13 -13
- package/dist/services/DocumentFragmentService.js +24 -24
- package/dist/services/DocumentService.d.ts +7 -0
- package/dist/services/DocumentService.js +23 -0
- package/dist/services/DocumentService.min.js +1 -1
- package/dist/services/ElementService.d.ts +13 -0
- package/dist/services/ElementService.js +20 -0
- package/dist/services/ElementService.min.js +1 -1
- package/dist/services/EventService.d.ts +120 -120
- package/dist/services/EventService.js +250 -250
- package/dist/services/EventTargetService.d.ts +84 -84
- package/dist/services/EventTargetService.js +232 -232
- package/dist/services/FocusEventService.d.ts +32 -32
- package/dist/services/FocusEventService.js +35 -35
- package/dist/services/HTMLCollectionService.d.ts +11 -6
- package/dist/services/HTMLCollectionService.js +25 -8
- package/dist/services/HTMLCollectionService.min.js +1 -1
- package/dist/services/HTMLElementService.d.ts +57 -57
- package/dist/services/HTMLElementService.js +163 -163
- package/dist/services/HTMLSlotElementService.d.ts +4 -4
- package/dist/services/HTMLSlotElementService.js +9 -9
- package/dist/services/InputEventService.d.ts +41 -41
- package/dist/services/InputEventService.js +47 -47
- package/dist/services/KeyboardEventService.d.ts +70 -70
- package/dist/services/KeyboardEventService.js +86 -86
- package/dist/services/MouseEventService.d.ts +80 -80
- package/dist/services/MouseEventService.js +108 -108
- package/dist/services/NamedNodeMapService.d.ts +23 -23
- package/dist/services/NamedNodeMapService.js +77 -77
- package/dist/services/NodeService.d.ts +26 -0
- package/dist/services/NodeService.js +42 -0
- package/dist/services/NodeService.min.js +1 -1
- package/dist/services/PointerEventService.d.ts +51 -51
- package/dist/services/PointerEventService.js +67 -67
- package/dist/services/ShadowRootService.d.ts +4 -4
- package/dist/services/ShadowRootService.js +9 -9
- package/dist/services/TextService.d.ts +1 -1
- package/dist/services/TextService.js +13 -13
- package/dist/services/UIEventService.d.ts +43 -43
- package/dist/services/UIEventService.js +42 -42
- package/dist/simulate.d.ts +32 -32
- package/dist/simulate.js +115 -115
- package/package.json +3 -2
package/dist/simulate.js
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
-
return mod && mod.__esModule
|
|
5
|
-
? mod
|
|
6
|
-
: {
|
|
7
|
-
default: mod
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(exports, '__esModule', {
|
|
11
|
-
value: true
|
|
12
|
-
})
|
|
13
|
-
exports.keyPress = exports.click = void 0
|
|
14
|
-
/**
|
|
15
|
-
* @file Simulate what a user does, with the events the browser sends for it.
|
|
16
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
17
|
-
* @version 1.0.0
|
|
18
|
-
* @module pseudoDom/simulate
|
|
19
|
-
*/
|
|
20
|
-
const createEvent_1 = __importDefault(require('./factories/createEvent'))
|
|
21
|
-
const activeElement_1 = require('./functions/activeElement')
|
|
22
|
-
const send = (target, type, init) => target.dispatchEvent((0, createEvent_1.default)(type, init, {
|
|
23
|
-
browser: true,
|
|
24
|
-
trusted: true
|
|
25
|
-
}))
|
|
26
|
-
/**
|
|
27
|
-
* The nearest element (starting with the element itself) which can have the focus.
|
|
28
|
-
* @param {*} element Where to start
|
|
29
|
-
* @returns {*|null}
|
|
30
|
-
*/
|
|
31
|
-
const focusableFrom = element => {
|
|
32
|
-
let current = element
|
|
33
|
-
while (current) {
|
|
34
|
-
if (current.canFocus) {
|
|
35
|
-
return current
|
|
36
|
-
}
|
|
37
|
-
current = current.parentNode
|
|
38
|
-
}
|
|
39
|
-
return null
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Click an element the way a user does: pointerdown and mousedown, then the focus moves to the nearest element which
|
|
43
|
-
* can have it (or is taken away from the one which had it) unless mousedown was cancelled, then pointerup, mouseup
|
|
44
|
-
* and finally click. Every event is trusted and has the options the browser gives it. A disabled element gets nothing.
|
|
45
|
-
* @function click
|
|
46
|
-
* @param {*} element The element to click
|
|
47
|
-
* @param {Object} [init={}] Options for the events (for example clientX, clientY, shiftKey)
|
|
48
|
-
* @returns {boolean} False when the click was cancelled (or the element is disabled), so its default action did not happen
|
|
49
|
-
*/
|
|
50
|
-
const click = (element, init = {}) => {
|
|
51
|
-
if (element.hasAttribute && element.hasAttribute('disabled')) {
|
|
52
|
-
return false
|
|
53
|
-
}
|
|
54
|
-
const pointer = Object.assign({
|
|
55
|
-
pointerId: 1,
|
|
56
|
-
pointerType: 'mouse',
|
|
57
|
-
isPrimary: true,
|
|
58
|
-
button: 0
|
|
59
|
-
}, init)
|
|
60
|
-
send(element, 'pointerdown', Object.assign({
|
|
61
|
-
buttons: 1
|
|
62
|
-
}, pointer))
|
|
63
|
-
if (send(element, 'mousedown', Object.assign({
|
|
64
|
-
buttons: 1,
|
|
65
|
-
detail: 1
|
|
66
|
-
}, init, {
|
|
67
|
-
button: 0
|
|
68
|
-
}))) {
|
|
69
|
-
const focusable = focusableFrom(element)
|
|
70
|
-
if (focusable) {
|
|
71
|
-
focusable.focus()
|
|
72
|
-
} else {
|
|
73
|
-
const active = (0, activeElement_1.getActiveElement)(element.getRootNode())
|
|
74
|
-
if (active) {
|
|
75
|
-
active.blur()
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
send(element, 'pointerup', Object.assign({
|
|
80
|
-
buttons: 0
|
|
81
|
-
}, pointer))
|
|
82
|
-
send(element, 'mouseup', Object.assign({
|
|
83
|
-
buttons: 0,
|
|
84
|
-
detail: 1
|
|
85
|
-
}, init, {
|
|
86
|
-
button: 0
|
|
87
|
-
}))
|
|
88
|
-
return send(element, 'click', Object.assign({
|
|
89
|
-
detail: 1
|
|
90
|
-
}, init, {
|
|
91
|
-
button: 0
|
|
92
|
-
}))
|
|
93
|
-
}
|
|
94
|
-
exports.click = click
|
|
95
|
-
/**
|
|
96
|
-
* Press and release a key on an element (the element which has the focus, or one given): keydown and then keyup.
|
|
97
|
-
* @function keyPress
|
|
98
|
-
* @param {*} element The element which gets the key
|
|
99
|
-
* @param {string} key The value of the key, such as a or Enter
|
|
100
|
-
* @param {Object} [init={}] Options for the events (for example code, shiftKey)
|
|
101
|
-
* @returns {boolean} False when keydown was cancelled, so its default action did not happen
|
|
102
|
-
*/
|
|
103
|
-
const keyPress = (element, key, init = {}) => {
|
|
104
|
-
const options = Object.assign({
|
|
105
|
-
key
|
|
106
|
-
}, init)
|
|
107
|
-
const proceeded = send(element, 'keydown', options)
|
|
108
|
-
send(element, 'keyup', options)
|
|
109
|
-
return proceeded
|
|
110
|
-
}
|
|
111
|
-
exports.keyPress = keyPress
|
|
112
|
-
exports.default = {
|
|
113
|
-
click: exports.click,
|
|
114
|
-
keyPress: exports.keyPress
|
|
115
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule
|
|
5
|
+
? mod
|
|
6
|
+
: {
|
|
7
|
+
default: mod
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(exports, '__esModule', {
|
|
11
|
+
value: true
|
|
12
|
+
})
|
|
13
|
+
exports.keyPress = exports.click = void 0
|
|
14
|
+
/**
|
|
15
|
+
* @file Simulate what a user does, with the events the browser sends for it.
|
|
16
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
17
|
+
* @version 1.0.0
|
|
18
|
+
* @module pseudoDom/simulate
|
|
19
|
+
*/
|
|
20
|
+
const createEvent_1 = __importDefault(require('./factories/createEvent'))
|
|
21
|
+
const activeElement_1 = require('./functions/activeElement')
|
|
22
|
+
const send = (target, type, init) => target.dispatchEvent((0, createEvent_1.default)(type, init, {
|
|
23
|
+
browser: true,
|
|
24
|
+
trusted: true
|
|
25
|
+
}))
|
|
26
|
+
/**
|
|
27
|
+
* The nearest element (starting with the element itself) which can have the focus.
|
|
28
|
+
* @param {*} element Where to start
|
|
29
|
+
* @returns {*|null}
|
|
30
|
+
*/
|
|
31
|
+
const focusableFrom = element => {
|
|
32
|
+
let current = element
|
|
33
|
+
while (current) {
|
|
34
|
+
if (current.canFocus) {
|
|
35
|
+
return current
|
|
36
|
+
}
|
|
37
|
+
current = current.parentNode
|
|
38
|
+
}
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Click an element the way a user does: pointerdown and mousedown, then the focus moves to the nearest element which
|
|
43
|
+
* can have it (or is taken away from the one which had it) unless mousedown was cancelled, then pointerup, mouseup
|
|
44
|
+
* and finally click. Every event is trusted and has the options the browser gives it. A disabled element gets nothing.
|
|
45
|
+
* @function click
|
|
46
|
+
* @param {*} element The element to click
|
|
47
|
+
* @param {Object} [init={}] Options for the events (for example clientX, clientY, shiftKey)
|
|
48
|
+
* @returns {boolean} False when the click was cancelled (or the element is disabled), so its default action did not happen
|
|
49
|
+
*/
|
|
50
|
+
const click = (element, init = {}) => {
|
|
51
|
+
if (element.hasAttribute && element.hasAttribute('disabled')) {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
const pointer = Object.assign({
|
|
55
|
+
pointerId: 1,
|
|
56
|
+
pointerType: 'mouse',
|
|
57
|
+
isPrimary: true,
|
|
58
|
+
button: 0
|
|
59
|
+
}, init)
|
|
60
|
+
send(element, 'pointerdown', Object.assign({
|
|
61
|
+
buttons: 1
|
|
62
|
+
}, pointer))
|
|
63
|
+
if (send(element, 'mousedown', Object.assign({
|
|
64
|
+
buttons: 1,
|
|
65
|
+
detail: 1
|
|
66
|
+
}, init, {
|
|
67
|
+
button: 0
|
|
68
|
+
}))) {
|
|
69
|
+
const focusable = focusableFrom(element)
|
|
70
|
+
if (focusable) {
|
|
71
|
+
focusable.focus()
|
|
72
|
+
} else {
|
|
73
|
+
const active = (0, activeElement_1.getActiveElement)(element.getRootNode())
|
|
74
|
+
if (active) {
|
|
75
|
+
active.blur()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
send(element, 'pointerup', Object.assign({
|
|
80
|
+
buttons: 0
|
|
81
|
+
}, pointer))
|
|
82
|
+
send(element, 'mouseup', Object.assign({
|
|
83
|
+
buttons: 0,
|
|
84
|
+
detail: 1
|
|
85
|
+
}, init, {
|
|
86
|
+
button: 0
|
|
87
|
+
}))
|
|
88
|
+
return send(element, 'click', Object.assign({
|
|
89
|
+
detail: 1
|
|
90
|
+
}, init, {
|
|
91
|
+
button: 0
|
|
92
|
+
}))
|
|
93
|
+
}
|
|
94
|
+
exports.click = click
|
|
95
|
+
/**
|
|
96
|
+
* Press and release a key on an element (the element which has the focus, or one given): keydown and then keyup.
|
|
97
|
+
* @function keyPress
|
|
98
|
+
* @param {*} element The element which gets the key
|
|
99
|
+
* @param {string} key The value of the key, such as a or Enter
|
|
100
|
+
* @param {Object} [init={}] Options for the events (for example code, shiftKey)
|
|
101
|
+
* @returns {boolean} False when keydown was cancelled, so its default action did not happen
|
|
102
|
+
*/
|
|
103
|
+
const keyPress = (element, key, init = {}) => {
|
|
104
|
+
const options = Object.assign({
|
|
105
|
+
key
|
|
106
|
+
}, init)
|
|
107
|
+
const proceeded = send(element, 'keydown', options)
|
|
108
|
+
send(element, 'keyup', options)
|
|
109
|
+
return proceeded
|
|
110
|
+
}
|
|
111
|
+
exports.keyPress = keyPress
|
|
112
|
+
exports.default = {
|
|
113
|
+
click: exports.click,
|
|
114
|
+
keyPress: exports.keyPress
|
|
115
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pseudo-dom",
|
|
3
3
|
"description": "Mock the DOM on the server side for managing state and testing",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
7
7
|
"author": "Joshua Heagle",
|
|
@@ -20,10 +20,11 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"collect-your-stuff": "^2.1.1",
|
|
22
22
|
"core-js": "^3.50.0",
|
|
23
|
+
"css-select": "^6.0.0",
|
|
23
24
|
"si-funciona": "^2.6.1"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"js-build-tools": "^5.
|
|
27
|
+
"js-build-tools": "^5.2.0",
|
|
27
28
|
"jsdoc": "^4.0.5",
|
|
28
29
|
"standard": "^17.1.2",
|
|
29
30
|
"test-filesystem": "^1.5.1"
|