@cloudcare/browser-rum 2.2.15 → 3.0.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/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/recorderApi.js +161 -0
- package/cjs/boot/rum.entry.js +6 -1
- package/cjs/boot/rum.js +15 -5
- package/cjs/boot/rumPublicApi.js +8 -4
- package/cjs/boot/startRecording.js +55 -0
- package/cjs/constants.js +52 -0
- package/cjs/domain/assembly.js +1 -7
- package/cjs/domain/configuration.js +3 -2
- package/cjs/domain/contexts/foregroundContexts.js +138 -0
- package/cjs/domain/contexts/internalContext.js +1 -1
- package/cjs/domain/contexts/urlContexts.js +9 -2
- package/cjs/domain/domMutationCollection.js +4 -5
- package/cjs/domain/initViewportObservable.js +52 -0
- package/cjs/domain/locationChangeObservable.js +12 -26
- package/cjs/domain/performanceCollection.js +2 -13
- package/cjs/domain/replay/record/elementsScrollPositions.js +27 -0
- package/cjs/domain/replay/record/index.js +41 -0
- package/cjs/domain/replay/record/mutationBatch.js +58 -0
- package/cjs/domain/replay/record/mutationObserver.js +383 -0
- package/cjs/domain/replay/record/observers.js +473 -0
- package/cjs/domain/replay/record/privacy.js +256 -0
- package/cjs/domain/replay/record/record.js +174 -0
- package/cjs/domain/replay/record/serializationUtils.js +137 -0
- package/cjs/domain/replay/record/serialize.js +488 -0
- package/cjs/domain/replay/record/shadowRootsController.js +61 -0
- package/cjs/domain/replay/record/utils.js +53 -0
- package/cjs/domain/replay/record/viewports.js +104 -0
- package/cjs/domain/replay/replayStats.js +83 -0
- package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +43 -0
- package/cjs/domain/replay/segmentCollection/deflateWorker.js +4399 -0
- package/cjs/domain/replay/segmentCollection/index.js +33 -0
- package/cjs/domain/replay/segmentCollection/segment.js +101 -0
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +179 -0
- package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +126 -0
- package/cjs/domain/requestCollection.js +35 -17
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +12 -4
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +8 -6
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +111 -75
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +94 -54
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +13 -5
- package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +45 -0
- package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
- package/cjs/domain/rumEventsCollection/view/trackViews.js +21 -18
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +12 -9
- package/cjs/domain/rumSessionManager.js +6 -3
- package/cjs/domain/tracing/getDocumentTraceId.js +2 -10
- package/cjs/domain/trackEventCounts.js +10 -2
- package/cjs/domain/waitPageActivityEnd.js +5 -1
- package/cjs/transport/startRumBatch.js +5 -7
- package/cjs/types/index.js +18 -0
- package/cjs/types/sessionReplayConstants.js +56 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/recorderApi.js +149 -0
- package/esm/boot/rum.entry.js +4 -1
- package/esm/boot/rum.js +15 -6
- package/esm/boot/rumPublicApi.js +8 -4
- package/esm/boot/startRecording.js +44 -0
- package/esm/constants.js +31 -0
- package/esm/domain/assembly.js +1 -7
- package/esm/domain/configuration.js +4 -3
- package/esm/domain/contexts/foregroundContexts.js +122 -0
- package/esm/domain/contexts/internalContext.js +1 -1
- package/esm/domain/contexts/urlContexts.js +10 -3
- package/esm/domain/domMutationCollection.js +5 -6
- package/esm/domain/initViewportObservable.js +39 -0
- package/esm/domain/locationChangeObservable.js +13 -27
- package/esm/domain/performanceCollection.js +1 -12
- package/esm/domain/replay/record/elementsScrollPositions.js +20 -0
- package/esm/domain/replay/record/index.js +3 -0
- package/esm/domain/replay/record/mutationBatch.js +35 -0
- package/esm/domain/replay/record/mutationObserver.js +331 -0
- package/esm/domain/replay/record/observers.js +457 -0
- package/esm/domain/replay/record/privacy.js +233 -0
- package/esm/domain/replay/record/record.js +158 -0
- package/esm/domain/replay/record/serializationUtils.js +107 -0
- package/esm/domain/replay/record/serialize.js +461 -0
- package/esm/domain/replay/record/shadowRootsController.js +49 -0
- package/esm/domain/replay/record/utils.js +38 -0
- package/esm/domain/replay/record/viewports.js +87 -0
- package/esm/domain/replay/replayStats.js +64 -0
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js +31 -0
- package/esm/domain/replay/segmentCollection/deflateWorker.js +4390 -0
- package/esm/domain/replay/segmentCollection/index.js +3 -0
- package/esm/domain/replay/segmentCollection/segment.js +84 -0
- package/esm/domain/replay/segmentCollection/segmentCollection.js +158 -0
- package/esm/domain/replay/segmentCollection/startDeflateWorker.js +113 -0
- package/esm/domain/requestCollection.js +36 -18
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +12 -4
- package/esm/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +6 -6
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +105 -74
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +99 -59
- package/esm/domain/rumEventsCollection/error/errorCollection.js +13 -5
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +33 -0
- package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +1 -18
- package/esm/domain/rumEventsCollection/view/trackViews.js +21 -19
- package/esm/domain/rumEventsCollection/view/viewCollection.js +12 -9
- package/esm/domain/rumSessionManager.js +6 -3
- package/esm/domain/tracing/getDocumentTraceId.js +1 -9
- package/esm/domain/trackEventCounts.js +10 -2
- package/esm/domain/waitPageActivityEnd.js +5 -1
- package/esm/transport/startRumBatch.js +5 -7
- package/esm/types/index.js +1 -0
- package/esm/types/sessionReplayConstants.js +45 -0
- package/package.json +3 -3
- package/src/boot/recorderApi.js +166 -0
- package/src/boot/rum.entry.js +4 -1
- package/src/boot/rum.js +38 -10
- package/src/boot/rumPublicApi.js +13 -3
- package/src/boot/startRecording.js +77 -0
- package/src/constants.js +37 -0
- package/src/domain/assembly.js +1 -6
- package/src/domain/configuration.js +10 -2
- package/src/domain/contexts/foregroundContexts.js +140 -0
- package/src/domain/contexts/internalContext.js +10 -4
- package/src/domain/contexts/urlContexts.js +29 -15
- package/src/domain/domMutationCollection.js +14 -6
- package/src/domain/initViewportObservable.js +46 -0
- package/src/domain/locationChangeObservable.js +17 -25
- package/src/domain/performanceCollection.js +42 -42
- package/src/domain/replay/record/elementsScrollPositions.js +22 -0
- package/src/domain/replay/record/index.js +7 -0
- package/src/domain/replay/record/mutationBatch.js +38 -0
- package/src/domain/replay/record/mutationObserver.js +393 -0
- package/src/domain/replay/record/observers.js +562 -0
- package/src/domain/replay/record/privacy.js +304 -0
- package/src/domain/replay/record/record.js +158 -0
- package/src/domain/replay/record/serializationUtils.js +134 -0
- package/src/domain/replay/record/serialize.js +497 -0
- package/src/domain/replay/record/shadowRootsController.js +58 -0
- package/src/domain/replay/record/utils.js +44 -0
- package/src/domain/replay/record/viewports.js +89 -0
- package/src/domain/replay/replayStats.js +67 -0
- package/src/domain/replay/segmentCollection/buildReplayPayload.js +34 -0
- package/src/domain/replay/segmentCollection/deflateWorker.js +4577 -0
- package/src/domain/replay/segmentCollection/index.js +6 -0
- package/src/domain/replay/segmentCollection/segment.js +87 -0
- package/src/domain/replay/segmentCollection/segmentCollection.js +205 -0
- package/src/domain/replay/segmentCollection/startDeflateWorker.js +101 -0
- package/src/domain/requestCollection.js +64 -28
- package/src/domain/rumEventsCollection/actions/actionCollection.js +11 -4
- package/src/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/src/domain/rumEventsCollection/actions/computeFrustration.js +7 -4
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +9 -6
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +130 -108
- package/src/domain/rumEventsCollection/actions/listenActionEvents.js +26 -27
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +162 -92
- package/src/domain/rumEventsCollection/error/errorCollection.js +11 -5
- package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +38 -0
- package/src/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
- package/src/domain/rumEventsCollection/view/trackViews.js +98 -68
- package/src/domain/rumEventsCollection/view/viewCollection.js +15 -7
- package/src/domain/rumSessionManager.js +33 -19
- package/src/domain/tracing/getDocumentTraceId.js +6 -9
- package/src/domain/trackEventCounts.js +10 -4
- package/src/domain/waitPageActivityEnd.js +4 -1
- package/src/transport/startRumBatch.js +29 -24
- package/src/types/index.js +1 -0
- package/src/types/sessionReplayConstants.js +49 -0
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
elementMatches,
|
|
5
5
|
map
|
|
6
6
|
} from '@cloudcare/browser-core'
|
|
7
|
-
|
|
7
|
+
import { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './getActionNameFromElement'
|
|
8
8
|
/**
|
|
9
9
|
* Stable attributes are attributes that are commonly used to identify parts of a UI (ex:
|
|
10
10
|
* component). Those attribute values should not be generated randomly (hardcoded most of the time)
|
|
11
11
|
* and stay the same across deploys. They are not necessarily unique across the document.
|
|
12
12
|
*/
|
|
13
|
-
var STABLE_ATTRIBUTES = [
|
|
14
|
-
|
|
13
|
+
export var STABLE_ATTRIBUTES = [
|
|
14
|
+
DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE,
|
|
15
15
|
// Common test attributes (list provided by google recorder)
|
|
16
16
|
'data-testid',
|
|
17
17
|
'data-test',
|
|
@@ -25,150 +25,150 @@ var STABLE_ATTRIBUTES = [
|
|
|
25
25
|
'data-element',
|
|
26
26
|
'data-source-file'
|
|
27
27
|
]
|
|
28
|
+
// Selectors to use if they target a single element on the whole document. Those selectors are
|
|
29
|
+
// considered as "stable" and uniquely identify an element regardless of the page state. If we find
|
|
30
|
+
// one, we should consider the selector "complete" and stop iterating over ancestors.
|
|
31
|
+
var GLOBALLY_UNIQUE_SELECTOR_GETTERS = [
|
|
32
|
+
getStableAttributeSelector,
|
|
33
|
+
getIDSelector
|
|
34
|
+
]
|
|
28
35
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
selector: getSelectorFromElement(
|
|
40
|
-
element,
|
|
41
|
-
[getIDSelector],
|
|
42
|
-
[getClassSelector]
|
|
43
|
-
),
|
|
44
|
-
selector_with_stable_attributes: getSelectorFromElement(
|
|
45
|
-
element,
|
|
46
|
-
attributeSelectors.concat(getIDSelector),
|
|
47
|
-
attributeSelectors.concat(getClassSelector)
|
|
48
|
-
),
|
|
49
|
-
selector_without_classes: getSelectorFromElement(
|
|
50
|
-
element,
|
|
51
|
-
attributeSelectors.concat(getIDSelector),
|
|
52
|
-
attributeSelectors
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
36
|
+
// Selectors to use if they target a single element among an element descendants. Those selectors
|
|
37
|
+
// are more brittle than "globally unique" selectors and should be combined with ancestor selectors
|
|
38
|
+
// to improve specificity.
|
|
39
|
+
var UNIQUE_AMONG_CHILDREN_SELECTOR_GETTERS = [
|
|
40
|
+
getStableAttributeSelector,
|
|
41
|
+
getClassSelector,
|
|
42
|
+
getTagNameSelector
|
|
43
|
+
]
|
|
56
44
|
|
|
57
|
-
function getSelectorFromElement(
|
|
58
|
-
targetElement,
|
|
59
|
-
globallyUniqueSelectorStrategies,
|
|
60
|
-
uniqueAmongChildrenSelectorStrategies
|
|
61
|
-
) {
|
|
45
|
+
export function getSelectorFromElement(targetElement, actionNameAttribute) {
|
|
62
46
|
var targetElementSelector = []
|
|
63
47
|
var element = targetElement
|
|
64
48
|
|
|
65
49
|
while (element && element.nodeName !== 'HTML') {
|
|
66
50
|
var globallyUniqueSelector = findSelector(
|
|
67
51
|
element,
|
|
68
|
-
|
|
69
|
-
isSelectorUniqueGlobally
|
|
52
|
+
GLOBALLY_UNIQUE_SELECTOR_GETTERS,
|
|
53
|
+
isSelectorUniqueGlobally,
|
|
54
|
+
actionNameAttribute,
|
|
55
|
+
targetElementSelector
|
|
70
56
|
)
|
|
71
57
|
if (globallyUniqueSelector) {
|
|
72
|
-
|
|
73
|
-
break
|
|
58
|
+
return globallyUniqueSelector
|
|
74
59
|
}
|
|
75
60
|
|
|
76
61
|
var uniqueSelectorAmongChildren = findSelector(
|
|
77
62
|
element,
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
UNIQUE_AMONG_CHILDREN_SELECTOR_GETTERS,
|
|
64
|
+
isSelectorUniqueAmongSiblings,
|
|
65
|
+
actionNameAttribute,
|
|
66
|
+
targetElementSelector
|
|
80
67
|
)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
targetElementSelector.unshift(getPositionSelector(element))
|
|
85
|
-
}
|
|
68
|
+
targetElementSelector =
|
|
69
|
+
uniqueSelectorAmongChildren ||
|
|
70
|
+
combineSelector(getPositionSelector(element), targetElementSelector)
|
|
86
71
|
|
|
87
72
|
element = element.parentElement
|
|
88
73
|
}
|
|
89
74
|
|
|
90
|
-
return targetElementSelector
|
|
75
|
+
return targetElementSelector
|
|
76
|
+
}
|
|
77
|
+
function isGeneratedValue(value) {
|
|
78
|
+
// To compute the "URL path group", the backend replaces every URL path parts as a question mark
|
|
79
|
+
// if it thinks the part is an identifier. The condition it uses is to checks whether a digit is
|
|
80
|
+
// present.
|
|
81
|
+
//
|
|
82
|
+
// Here, we use the same strategy: if a the value contains a digit, we consider it generated. This
|
|
83
|
+
// strategy might be a bit naive and fail in some cases, but there are many fallbacks to generate
|
|
84
|
+
// CSS selectors so it should be fine most of the time. We might want to allow customers to
|
|
85
|
+
// provide their own `isGeneratedValue` at some point.
|
|
86
|
+
return /[0-9]/.test(value)
|
|
91
87
|
}
|
|
92
|
-
|
|
93
88
|
function getIDSelector(element) {
|
|
94
|
-
if (element.id) {
|
|
89
|
+
if (element.id && !isGeneratedValue(element.id)) {
|
|
95
90
|
return '#' + cssEscape(element.id)
|
|
96
91
|
}
|
|
97
92
|
}
|
|
98
93
|
|
|
99
94
|
function getClassSelector(element) {
|
|
95
|
+
if (element.tagName === 'BODY') {
|
|
96
|
+
return
|
|
97
|
+
}
|
|
100
98
|
if (element.classList.length > 0) {
|
|
101
|
-
var
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
for (var i = 0; i < element.classList.length; i += 1) {
|
|
100
|
+
var className = element.classList[i]
|
|
101
|
+
if (isGeneratedValue(className)) {
|
|
102
|
+
continue
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return element.tagName + '.' + cssEscape(className)
|
|
106
|
+
}
|
|
108
107
|
}
|
|
109
108
|
}
|
|
109
|
+
function getTagNameSelector(element) {
|
|
110
|
+
return element.tagName
|
|
111
|
+
}
|
|
112
|
+
function getStableAttributeSelector(element, actionNameAttribute) {
|
|
113
|
+
if (actionNameAttribute) {
|
|
114
|
+
var selector = getAttributeSelector(actionNameAttribute)
|
|
115
|
+
if (selector) {
|
|
116
|
+
return selector
|
|
117
|
+
}
|
|
118
|
+
}
|
|
110
119
|
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return function (element) {
|
|
118
|
-
return getAttributeSelector(attribute, element)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
)
|
|
120
|
+
for (var i = 0; i < STABLE_ATTRIBUTES.length; i++) {
|
|
121
|
+
var attributeName = STABLE_ATTRIBUTES[i]
|
|
122
|
+
var selector = getAttributeSelector(attributeName)
|
|
123
|
+
if (selector) {
|
|
124
|
+
return selector
|
|
125
|
+
}
|
|
122
126
|
}
|
|
123
|
-
return stableAttributeSelectorsCache
|
|
124
|
-
}
|
|
125
127
|
|
|
126
|
-
function getAttributeSelector(attributeName
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
function getAttributeSelector(attributeName) {
|
|
129
|
+
if (element.hasAttribute(attributeName)) {
|
|
130
|
+
return (
|
|
131
|
+
element.tagName +
|
|
132
|
+
'[' +
|
|
133
|
+
attributeName +
|
|
134
|
+
'="' +
|
|
135
|
+
cssEscape(element.getAttribute(attributeName)) +
|
|
136
|
+
'"]'
|
|
137
|
+
)
|
|
138
|
+
}
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
function getPositionSelector(element) {
|
|
140
|
-
var
|
|
141
|
-
var
|
|
142
|
-
var currentIndex = 0
|
|
143
|
-
var elementIndex
|
|
143
|
+
var sibling = element.parentElement && element.parentElement.firstElementChild
|
|
144
|
+
var elementIndex = 1
|
|
144
145
|
|
|
145
|
-
while (sibling) {
|
|
146
|
+
while (sibling && sibling !== element) {
|
|
146
147
|
if (sibling.tagName === element.tagName) {
|
|
147
|
-
|
|
148
|
-
if (sibling === element) {
|
|
149
|
-
elementIndex = currentIndex
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (elementIndex !== undefined && currentIndex > 1) {
|
|
153
|
-
// Performance improvement: avoid iterating over all children, stop as soon as we are sure
|
|
154
|
-
// the element is not alone
|
|
155
|
-
break
|
|
156
|
-
}
|
|
148
|
+
elementIndex += 1
|
|
157
149
|
}
|
|
158
150
|
sibling = sibling.nextElementSibling
|
|
159
151
|
}
|
|
160
152
|
|
|
161
|
-
return
|
|
162
|
-
? element.tagName
|
|
163
|
-
: element.tagName + ':nth-of-type(' + elementIndex + ')'
|
|
153
|
+
return element.tagName + ':nth-of-type(' + elementIndex + ')'
|
|
164
154
|
}
|
|
165
155
|
|
|
166
|
-
function findSelector(
|
|
156
|
+
function findSelector(
|
|
157
|
+
element,
|
|
158
|
+
selectorGetters,
|
|
159
|
+
predicate,
|
|
160
|
+
actionNameAttribute,
|
|
161
|
+
childSelector
|
|
162
|
+
) {
|
|
167
163
|
for (var i = 0; i < selectorGetters.length; i++) {
|
|
168
164
|
var selectorGetter = selectorGetters[i]
|
|
169
|
-
var
|
|
170
|
-
if (
|
|
171
|
-
|
|
165
|
+
var elementSelector = selectorGetter(element, actionNameAttribute)
|
|
166
|
+
if (!elementSelector) {
|
|
167
|
+
continue
|
|
168
|
+
}
|
|
169
|
+
var fullSelector = combineSelector(elementSelector, childSelector)
|
|
170
|
+
if (predicate(element, fullSelector)) {
|
|
171
|
+
return fullSelector
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -176,13 +176,35 @@ function findSelector(element, selectorGetters, predicate) {
|
|
|
176
176
|
function isSelectorUniqueGlobally(element, selector) {
|
|
177
177
|
return element.ownerDocument.body.querySelectorAll(selector).length === 1
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Check whether the selector is unique among the element siblings. In other words, it returns true
|
|
181
|
+
* if "ELEMENT_PARENT > SELECTOR" returns a single element.
|
|
182
|
+
*
|
|
183
|
+
* The result will be less accurate on browsers that don't support :scope (i. e. IE): it will check
|
|
184
|
+
* for any element matching the selector contained in the parent (in other words,
|
|
185
|
+
* "ELEMENT_PARENT SELECTOR" returns a single element), regardless of whether the selector is a
|
|
186
|
+
* direct descendent of the element parent. This should not impact results too much: if it
|
|
187
|
+
* inaccurately returns false, we'll just fall back to another strategy.
|
|
188
|
+
*/
|
|
189
|
+
function isSelectorUniqueAmongSiblings(element, selector) {
|
|
190
|
+
return (
|
|
191
|
+
element.parentElement.querySelectorAll(
|
|
192
|
+
supportScopeSelector() ? combineSelector(':scope', selector) : selector
|
|
193
|
+
).length === 1
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
function combineSelector(parent, child) {
|
|
197
|
+
return child ? parent + '>' + child : parent
|
|
198
|
+
}
|
|
199
|
+
var supportScopeSelectorCache
|
|
200
|
+
export function supportScopeSelector() {
|
|
201
|
+
if (supportScopeSelectorCache === undefined) {
|
|
202
|
+
try {
|
|
203
|
+
document.querySelector(':scope')
|
|
204
|
+
supportScopeSelectorCache = true
|
|
205
|
+
} catch {
|
|
206
|
+
supportScopeSelectorCache = false
|
|
185
207
|
}
|
|
186
208
|
}
|
|
187
|
-
return
|
|
209
|
+
return supportScopeSelectorCache
|
|
188
210
|
}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { addEventListener, DOM_EVENT, each } from '@cloudcare/browser-core'
|
|
2
2
|
|
|
3
3
|
export function listenActionEvents(events) {
|
|
4
|
-
var onClick = events.onClick
|
|
5
|
-
var onPointerDown = events.onPointerDown
|
|
6
|
-
var hasSelectionChanged = false
|
|
7
4
|
var selectionEmptyAtPointerDown
|
|
8
|
-
var
|
|
5
|
+
var userActivity = {
|
|
6
|
+
selection: false,
|
|
7
|
+
input: false
|
|
8
|
+
}
|
|
9
9
|
var clickContext
|
|
10
10
|
var listeners = [
|
|
11
11
|
addEventListener(
|
|
12
12
|
window,
|
|
13
13
|
DOM_EVENT.POINTER_DOWN,
|
|
14
14
|
function (event) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (isValidPointerEvent(event)) {
|
|
16
|
+
selectionEmptyAtPointerDown = isSelectionEmpty()
|
|
17
|
+
userActivity = {
|
|
18
|
+
selection: false,
|
|
19
|
+
input: false
|
|
20
|
+
}
|
|
21
|
+
clickContext = events.onPointerDown(event)
|
|
19
22
|
}
|
|
20
23
|
},
|
|
21
24
|
{ capture: true }
|
|
@@ -26,7 +29,7 @@ export function listenActionEvents(events) {
|
|
|
26
29
|
DOM_EVENT.SELECTION_CHANGE,
|
|
27
30
|
function () {
|
|
28
31
|
if (!selectionEmptyAtPointerDown || !isSelectionEmpty()) {
|
|
29
|
-
|
|
32
|
+
userActivity.selection = true
|
|
30
33
|
}
|
|
31
34
|
},
|
|
32
35
|
{ capture: true }
|
|
@@ -34,22 +37,13 @@ export function listenActionEvents(events) {
|
|
|
34
37
|
|
|
35
38
|
addEventListener(
|
|
36
39
|
window,
|
|
37
|
-
DOM_EVENT.
|
|
38
|
-
function (
|
|
39
|
-
if (
|
|
40
|
+
DOM_EVENT.POINTER_UP,
|
|
41
|
+
function (event) {
|
|
42
|
+
if (isValidPointerEvent(event) && clickContext) {
|
|
40
43
|
// Use a scoped variable to make sure the value is not changed by other clicks
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!hasInputChanged) {
|
|
47
|
-
setTimeout(function () {
|
|
48
|
-
userActivity.input = hasInputChanged
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
onClick(clickContext, clickEvent, function () {
|
|
52
|
-
return userActivity
|
|
44
|
+
var localUserActivity = userActivity
|
|
45
|
+
events.onPointerUp(clickContext, event, function () {
|
|
46
|
+
return localUserActivity
|
|
53
47
|
})
|
|
54
48
|
clickContext = undefined
|
|
55
49
|
}
|
|
@@ -61,7 +55,7 @@ export function listenActionEvents(events) {
|
|
|
61
55
|
window,
|
|
62
56
|
DOM_EVENT.INPUT,
|
|
63
57
|
function () {
|
|
64
|
-
|
|
58
|
+
userActivity.input = true
|
|
65
59
|
},
|
|
66
60
|
{ capture: true }
|
|
67
61
|
)
|
|
@@ -80,6 +74,11 @@ function isSelectionEmpty() {
|
|
|
80
74
|
var selection = window.getSelection()
|
|
81
75
|
return !selection || selection.isCollapsed
|
|
82
76
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
77
|
+
function isValidPointerEvent(event) {
|
|
78
|
+
return (
|
|
79
|
+
event.target instanceof Element &&
|
|
80
|
+
// Only consider 'primary' pointer events for now. Multi-touch support could be implemented in
|
|
81
|
+
// the future.
|
|
82
|
+
event.isPrimary !== false
|
|
83
|
+
)
|
|
85
84
|
}
|