@adobe/alloy 2.14.0 → 2.15.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/libEs5/components/ActivityCollector/attachClickActivityCollector.js +1 -1
  2. package/libEs5/components/ActivityCollector/configValidators.js +2 -1
  3. package/libEs5/components/ActivityCollector/createGetLinkDetails.js +79 -0
  4. package/libEs5/components/ActivityCollector/createLinkClick.js +22 -64
  5. package/libEs5/components/ActivityCollector/getLinkName.js +158 -0
  6. package/libEs5/components/ActivityCollector/getLinkRegion.js +76 -0
  7. package/libEs5/components/ActivityCollector/index.js +43 -4
  8. package/libEs5/components/ActivityCollector/utils.js +52 -2
  9. package/libEs5/components/Audiences/injectProcessDestinations.js +1 -3
  10. package/libEs5/components/Personalization/createClickStorage.js +4 -2
  11. package/libEs5/components/Personalization/createExecuteDecisions.js +8 -2
  12. package/libEs5/components/Personalization/createOnClickHandler.js +4 -2
  13. package/libEs5/components/Personalization/dom-actions/clicks/collectClicks.js +57 -6
  14. package/libEs5/components/Personalization/event.js +12 -2
  15. package/libEs5/constants/libraryVersion.js +1 -1
  16. package/libEs5/core/buildAndValidateConfig.js +33 -21
  17. package/libEs5/core/componentCreators.js +4 -0
  18. package/libEs6/components/ActivityCollector/attachClickActivityCollector.js +1 -1
  19. package/libEs6/components/ActivityCollector/configValidators.js +3 -2
  20. package/libEs6/components/ActivityCollector/createGetLinkDetails.js +77 -0
  21. package/libEs6/components/ActivityCollector/createLinkClick.js +24 -64
  22. package/libEs6/components/ActivityCollector/getLinkName.js +151 -0
  23. package/libEs6/components/ActivityCollector/getLinkRegion.js +68 -0
  24. package/libEs6/components/ActivityCollector/index.js +39 -4
  25. package/libEs6/components/ActivityCollector/utils.js +43 -1
  26. package/libEs6/components/Audiences/injectProcessDestinations.js +1 -3
  27. package/libEs6/components/Personalization/createClickStorage.js +4 -2
  28. package/libEs6/components/Personalization/createExecuteDecisions.js +6 -2
  29. package/libEs6/components/Personalization/createOnClickHandler.js +5 -2
  30. package/libEs6/components/Personalization/dom-actions/clicks/collectClicks.js +50 -6
  31. package/libEs6/components/Personalization/event.js +13 -3
  32. package/libEs6/constants/libraryVersion.js +1 -1
  33. package/libEs6/core/buildAndValidateConfig.js +19 -2
  34. package/libEs6/core/componentCreators.js +4 -0
  35. package/package.json +3 -3
@@ -20,30 +20,81 @@ var getMetasIfMatches = function getMetasIfMatches(clickedElement, selector, get
20
20
  var _document = document,
21
21
  documentElement = _document.documentElement;
22
22
  var element = clickedElement;
23
+ var i = 0;
23
24
 
24
25
  while (element && element !== documentElement) {
25
26
  if ((0, _matchesSelectorWithEq.default)(selector, element)) {
26
- return getClickMetasBySelector(selector);
27
+ var matchedMetas = getClickMetasBySelector(selector);
28
+ var foundMetaWithLabel = matchedMetas.find(function (meta) {
29
+ return meta.trackingLabel;
30
+ });
31
+
32
+ if (foundMetaWithLabel) {
33
+ return {
34
+ metas: matchedMetas,
35
+ label: foundMetaWithLabel.trackingLabel,
36
+ weight: i
37
+ };
38
+ }
39
+
40
+ return {
41
+ metas: matchedMetas
42
+ };
27
43
  }
28
44
 
29
45
  element = element.parentNode;
46
+ i += 1;
30
47
  }
31
48
 
32
- return null;
49
+ return {
50
+ metas: null
51
+ };
52
+ };
53
+
54
+ var cleanMetas = function cleanMetas(metas) {
55
+ return metas.map(function (meta) {
56
+ delete meta.trackingLabel;
57
+ return meta;
58
+ });
59
+ };
60
+
61
+ var dedupMetas = function dedupMetas(metas) {
62
+ return metas.filter(function (meta, index) {
63
+ var stringifiedMeta = JSON.stringify(meta);
64
+ return index === metas.findIndex(function (innerMeta) {
65
+ return JSON.stringify(innerMeta) === stringifiedMeta;
66
+ });
67
+ });
33
68
  };
34
69
 
35
70
  var _default = function _default(clickedElement, selectors, getClickMetasBySelector) {
36
71
  var result = [];
72
+ var resultLabel = "";
73
+ var resultLabelWeight = Number.MAX_SAFE_INTEGER;
74
+ /* eslint-disable no-continue */
37
75
 
38
76
  for (var i = 0; i < selectors.length; i += 1) {
39
- var metas = getMetasIfMatches(clickedElement, selectors[i], getClickMetasBySelector);
77
+ var _getMetasIfMatches = getMetasIfMatches(clickedElement, selectors[i], getClickMetasBySelector),
78
+ metas = _getMetasIfMatches.metas,
79
+ label = _getMetasIfMatches.label,
80
+ weight = _getMetasIfMatches.weight;
40
81
 
41
- if (metas) {
42
- result.push.apply(result, _toConsumableArray(metas));
82
+ if (!metas) {
83
+ continue;
43
84
  }
85
+
86
+ if (label && weight <= resultLabelWeight) {
87
+ resultLabel = label;
88
+ resultLabelWeight = weight;
89
+ }
90
+
91
+ result.push.apply(result, _toConsumableArray(cleanMetas(metas)));
44
92
  }
45
93
 
46
- return result;
94
+ return {
95
+ decisionsMeta: dedupMetas(result),
96
+ eventLabel: resultLabel
97
+ };
47
98
  };
48
99
 
49
100
  exports.default = _default;
@@ -20,16 +20,26 @@ OF ANY KIND, either express or implied. See the License for the specific languag
20
20
  governing permissions and limitations under the License.
21
21
  */
22
22
  var EVENT_TYPE_TRUE = 1;
23
+ /* eslint-disable no-underscore-dangle */
23
24
 
24
25
  var mergeDecisionsMeta = function mergeDecisionsMeta(event, decisionsMeta, eventType) {
25
- event.mergeXdm({
26
+ var eventLabel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
27
+ var xdm = {
26
28
  _experience: {
27
29
  decisioning: {
28
30
  propositions: decisionsMeta,
29
31
  propositionEventType: _defineProperty({}, eventType, EVENT_TYPE_TRUE)
30
32
  }
31
33
  }
32
- });
34
+ };
35
+
36
+ if (eventLabel) {
37
+ xdm._experience.decisioning.propositionAction = {
38
+ label: eventLabel
39
+ };
40
+ }
41
+
42
+ event.mergeXdm(xdm);
33
43
  };
34
44
 
35
45
  exports.mergeDecisionsMeta = mergeDecisionsMeta;
@@ -15,5 +15,5 @@ governing permissions and limitations under the License.
15
15
  */
16
16
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
17
17
  // see babel-plugin-version
18
- var _default = "2.14.0";
18
+ var _default = "2.15.0-alpha.1";
19
19
  exports.default = _default;
@@ -6,17 +6,12 @@ var _utils = require("../utils");
6
6
 
7
7
  var _validation = require("../utils/validation");
8
8
 
9
- /*
10
- Copyright 2019 Adobe. All rights reserved.
11
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- you may not use this file except in compliance with the License. You may obtain a copy
13
- of the License at http://www.apache.org/licenses/LICENSE-2.0
14
-
15
- Unless required by applicable law or agreed to in writing, software distributed under
16
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- OF ANY KIND, either express or implied. See the License for the specific language
18
- governing permissions and limitations under the License.
19
- */
9
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
+
11
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
+
13
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+
20
15
  var CONFIG_DOC_URI = "https://adobe.ly/3sHh553";
21
16
 
22
17
  var buildSchema = function buildSchema(coreConfigValidators, componentCreators) {
@@ -38,21 +33,38 @@ var transformOptions = function transformOptions(schema, options) {
38
33
  }
39
34
  };
40
35
 
41
- var _default = function _default(_ref) {
42
- var options = _ref.options,
43
- componentCreators = _ref.componentCreators,
44
- coreConfigValidators = _ref.coreConfigValidators,
45
- createConfig = _ref.createConfig,
46
- logger = _ref.logger,
47
- setDebugEnabled = _ref.setDebugEnabled;
36
+ var buildAllOnInstanceConfiguredExtraParams = function buildAllOnInstanceConfiguredExtraParams(config, logger, componentCreators) {
37
+ return componentCreators.reduce(function (memo, _ref) {
38
+ var buildOnInstanceConfiguredExtraParams = _ref.buildOnInstanceConfiguredExtraParams;
39
+
40
+ if (buildOnInstanceConfiguredExtraParams) {
41
+ (0, _utils.assign)(memo, buildOnInstanceConfiguredExtraParams({
42
+ config: config,
43
+ logger: logger
44
+ }));
45
+ }
46
+
47
+ return memo;
48
+ }, {});
49
+ };
50
+
51
+ var _default = function _default(_ref2) {
52
+ var options = _ref2.options,
53
+ componentCreators = _ref2.componentCreators,
54
+ coreConfigValidators = _ref2.coreConfigValidators,
55
+ createConfig = _ref2.createConfig,
56
+ logger = _ref2.logger,
57
+ setDebugEnabled = _ref2.setDebugEnabled;
48
58
  var schema = buildSchema(coreConfigValidators, componentCreators);
49
59
  var config = createConfig(transformOptions(schema, options));
50
60
  setDebugEnabled(config.debugEnabled, {
51
61
  fromConfig: true
52
- });
53
- logger.logOnInstanceConfigured({
62
+ }); // eslint-disable-next-line no-underscore-dangle
63
+
64
+ var extraParams = buildAllOnInstanceConfiguredExtraParams(config, logger, componentCreators);
65
+ logger.logOnInstanceConfigured(_objectSpread(_objectSpread({}, extraParams), {}, {
54
66
  config: config
55
- });
67
+ }));
56
68
  return config;
57
69
  };
58
70
 
@@ -33,6 +33,10 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
33
33
  OF ANY KIND, either express or implied. See the License for the specific language
34
34
  governing permissions and limitations under the License.
35
35
  */
36
+ // This is the only place where core is allowed to import from components.
37
+ // This makes sure that each component could be removed without breaking the library
38
+
39
+ /* eslint-disable import/no-restricted-paths */
36
40
  // TODO: Register the Components here statically for now. They might be registered differently.
37
41
  // TODO: Figure out how sub-components will be made available/registered
38
42
  var _default = [_DataCollector.default, _ActivityCollector.default, _Identity.default, _Audiences.default, _Personalization.default, _Context.default, _Privacy.default, _EventMerge.default, _LibraryInfo.default, _MachineLearning.default];
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019 Adobe. All rights reserved.
2
+ Copyright 2022 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -9,8 +9,9 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- import { string, boolean } from "../../utils/validation";
12
+ import { string, boolean, callback } from "../../utils/validation";
13
13
  export default {
14
14
  clickCollectionEnabled: boolean().default(true),
15
- downloadLinkQualifier: string().regexp().default("\\.(exe|zip|wav|mp3|mov|mpg|avi|wmv|pdf|doc|docx|xls|xlsx|ppt|pptx)$")
15
+ downloadLinkQualifier: string().regexp().default("\\.(exe|zip|wav|mp3|mov|mpg|avi|wmv|pdf|doc|docx|xls|xlsx|ppt|pptx)$"),
16
+ onBeforeLinkClickSend: callback()
16
17
  };
@@ -0,0 +1,77 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export default (({
13
+ window,
14
+ getLinkName,
15
+ getLinkRegion,
16
+ getAbsoluteUrlFromAnchorElement,
17
+ findSupportedAnchorElement,
18
+ determineLinkType
19
+ }) => {
20
+ return ({
21
+ targetElement,
22
+ config,
23
+ logger
24
+ }) => {
25
+ const anchorElement = findSupportedAnchorElement(targetElement);
26
+
27
+ if (!anchorElement) {
28
+ logger.info("This link click event is not triggered because the HTML element is not an anchor.");
29
+ return undefined;
30
+ }
31
+
32
+ const linkUrl = getAbsoluteUrlFromAnchorElement(window, anchorElement);
33
+
34
+ if (!linkUrl) {
35
+ logger.info("This link click event is not triggered because the HTML element doesn't have an URL.");
36
+ return undefined;
37
+ }
38
+
39
+ const linkType = determineLinkType(window, config, linkUrl, anchorElement);
40
+ const linkRegion = getLinkRegion(anchorElement);
41
+ const linkName = getLinkName(anchorElement);
42
+ const {
43
+ onBeforeLinkClickSend
44
+ } = config;
45
+ const options = {
46
+ xdm: {
47
+ eventType: "web.webinteraction.linkClicks",
48
+ web: {
49
+ webInteraction: {
50
+ name: linkName,
51
+ region: linkRegion,
52
+ type: linkType,
53
+ URL: linkUrl,
54
+ linkClicks: {
55
+ value: 1
56
+ }
57
+ }
58
+ }
59
+ },
60
+ data: {},
61
+ clickedElement: targetElement
62
+ };
63
+
64
+ if (!onBeforeLinkClickSend) {
65
+ return options;
66
+ }
67
+
68
+ const shouldEventBeTracked = onBeforeLinkClickSend(options);
69
+
70
+ if (shouldEventBeTracked !== false) {
71
+ return options;
72
+ }
73
+
74
+ logger.info("This link click event is not triggered because it was canceled in onBeforeLinkClickSend.");
75
+ return undefined;
76
+ };
77
+ });
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019 Adobe. All rights reserved.
2
+ Copyright 2022 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -9,72 +9,32 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- import { getAbsoluteUrlFromAnchorElement, isSupportedAnchorElement, isDownloadLink, isExitLink } from "./utils";
13
-
14
- const determineLinkType = (window, config, linkUrl, clickedObj) => {
15
- let linkType = "other";
16
-
17
- if (isDownloadLink(config.downloadLinkQualifier, linkUrl, clickedObj)) {
18
- linkType = "download";
19
- } else if (isExitLink(window, linkUrl)) {
20
- linkType = "exit";
21
- }
22
-
23
- return linkType;
24
- };
25
-
26
- const findSupportedAnchorElement = targetElement => {
27
- let node = targetElement;
28
-
29
- while (node) {
30
- if (isSupportedAnchorElement(node)) {
31
- return node;
32
- }
33
-
34
- node = node.parentNode;
12
+ export default (({
13
+ getLinkDetails,
14
+ config,
15
+ logger
16
+ }) => {
17
+ const {
18
+ clickCollectionEnabled
19
+ } = config;
20
+
21
+ if (!clickCollectionEnabled) {
22
+ return () => undefined;
35
23
  }
36
24
 
37
- return null;
38
- };
39
-
40
- export default ((window, config) => {
41
- return (event, targetElement) => {
42
- const clickCollectionEnabled = config.clickCollectionEnabled;
43
-
44
- if (!clickCollectionEnabled) {
45
- return;
46
- } // Search parent elements for an anchor element
47
- // TODO: Replace with generic DOM tool that can fetch configured properties
48
-
49
-
50
- const anchorElement = findSupportedAnchorElement(targetElement);
51
-
52
- if (!anchorElement) {
53
- return;
54
- }
55
-
56
- const linkUrl = getAbsoluteUrlFromAnchorElement(window, anchorElement);
25
+ return ({
26
+ targetElement,
27
+ event
28
+ }) => {
29
+ const linkDetails = getLinkDetails({
30
+ targetElement,
31
+ config,
32
+ logger
33
+ });
57
34
 
58
- if (!linkUrl) {
59
- return;
35
+ if (linkDetails) {
36
+ event.mergeXdm(linkDetails.xdm);
37
+ event.setUserData(linkDetails.data);
60
38
  }
61
-
62
- const linkType = determineLinkType(window, config, linkUrl, anchorElement); // TODO: Update link name from the clicked element context
63
-
64
- const linkName = "Link Click";
65
- event.documentMayUnload();
66
- event.mergeXdm({
67
- eventType: "web.webinteraction.linkClicks",
68
- web: {
69
- webInteraction: {
70
- name: linkName,
71
- type: linkType,
72
- URL: linkUrl,
73
- linkClicks: {
74
- value: 1
75
- }
76
- }
77
- }
78
- });
79
39
  };
80
40
  });
@@ -0,0 +1,151 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { truncateWhiteSpace } from "./utils";
13
+ const unsupportedNodeNames = /^(SCRIPT|STYLE|LINK|CANVAS|NOSCRIPT|#COMMENT)$/i;
14
+ /**
15
+ * Determines if a node qualifies as a supported link text node.
16
+ * @param {*} node Node to determine support for.
17
+ * @returns {boolean}
18
+ */
19
+
20
+ const isSupportedTextNode = node => {
21
+ if (node && node.nodeName) {
22
+ if (node.nodeName.match(unsupportedNodeNames)) {
23
+ return false;
24
+ }
25
+ }
26
+
27
+ return true;
28
+ };
29
+ /**
30
+ * Orders and returns specified node and its child nodes in arrays of supported
31
+ * and unsupported nodes.
32
+ * @param {*} node The node to extract supported and unsupported nodes from.
33
+ * @returns {{supportedNodes: Array, includesUnsupportedNodes: boolean}} Node support object.
34
+ */
35
+
36
+
37
+ const extractSupportedNodes = node => {
38
+ let supportedNodes = [];
39
+ let includesUnsupportedNodes = false;
40
+
41
+ if (isSupportedTextNode(node)) {
42
+ supportedNodes.push(node);
43
+
44
+ if (node.childNodes) {
45
+ const childNodes = Array.prototype.slice.call(node.childNodes);
46
+ childNodes.forEach(childNode => {
47
+ const nodes = extractSupportedNodes(childNode);
48
+ supportedNodes = supportedNodes.concat(nodes.supportedNodes);
49
+ includesUnsupportedNodes = includesUnsupportedNodes || nodes.includesUnsupportedNodes;
50
+ });
51
+ }
52
+ } else {
53
+ includesUnsupportedNodes = true;
54
+ }
55
+
56
+ return {
57
+ supportedNodes,
58
+ includesUnsupportedNodes
59
+ };
60
+ };
61
+ /**
62
+ * Returns the value of a node attribute.
63
+ * @param {*} node The node holding the attribute.
64
+ * @param {string} attributeName The name of the attribute.
65
+ * @param {string} nodeName Optional node name constraint.
66
+ * @returns {string} Attribute value or undefined.
67
+ */
68
+
69
+
70
+ const getNodeAttributeValue = (node, attributeName, nodeName) => {
71
+ let attributeValue;
72
+
73
+ if (!nodeName || nodeName === node.nodeName.toUpperCase()) {
74
+ attributeValue = node.getAttribute(attributeName);
75
+ }
76
+
77
+ return attributeValue;
78
+ };
79
+ /**
80
+ * Extracts the children supported nodes attributes map
81
+ * @param {*} nodes The nodes array holding the children nodes.
82
+ * The returned map contains the supported not empty children attributes values.
83
+ * */
84
+
85
+
86
+ const getChildrenAttributes = nodes => {
87
+ const attributes = {
88
+ texts: []
89
+ };
90
+ nodes.supportedNodes.forEach(supportedNode => {
91
+ if (supportedNode.getAttribute) {
92
+ if (!attributes.alt) {
93
+ attributes.alt = truncateWhiteSpace(supportedNode.getAttribute("alt"));
94
+ }
95
+
96
+ if (!attributes.title) {
97
+ attributes.title = truncateWhiteSpace(supportedNode.getAttribute("title"));
98
+ }
99
+
100
+ if (!attributes.inputValue) {
101
+ attributes.inputValue = truncateWhiteSpace(getNodeAttributeValue(supportedNode, "value", "INPUT"));
102
+ }
103
+
104
+ if (!attributes.imgSrc) {
105
+ attributes.imgSrc = truncateWhiteSpace(getNodeAttributeValue(supportedNode, "src", "IMG"));
106
+ }
107
+ }
108
+
109
+ if (supportedNode.nodeValue) {
110
+ attributes.texts.push(supportedNode.nodeValue);
111
+ }
112
+ });
113
+ return attributes;
114
+ };
115
+ /**
116
+ * Extracts a link-name from a given node.
117
+ *
118
+ * The returned link-name is set to one of the following (in order of priority):
119
+ *
120
+ * 1. Clicked node innerText
121
+ * 2. Clicked node textContent
122
+ * 3. Clicked node and its child nodes nodeValue appended together.
123
+ * 4. Clicked node alt attribute or node descendant alt attribute.
124
+ * Whichever is found first.
125
+ * 5. Clicked node text attribute or node descendant text attribute.
126
+ * Whichever is found first.
127
+ * 6. Clicked node INPUT descendant value attribute.
128
+ * Whichever is found first.
129
+ * 7. Clicked node IMG descendant src attribute.
130
+ * Whichever is found first.
131
+ *
132
+ * @param {*} node The node to find link text for.
133
+ * @returns {string} link-name or an empty string if not link-name is found.
134
+ */
135
+
136
+
137
+ export default (node => {
138
+ let nodeText = truncateWhiteSpace(node.innerText || node.textContent);
139
+ const nodes = extractSupportedNodes(node); // if contains unsupported nodes we want children node attributes
140
+
141
+ if (!nodeText || nodes.includesUnsupportedNodes) {
142
+ const attributesMap = getChildrenAttributes(nodes);
143
+ nodeText = truncateWhiteSpace(attributesMap.texts.join(""));
144
+
145
+ if (!nodeText) {
146
+ nodeText = attributesMap.alt || attributesMap.title || attributesMap.inputValue || attributesMap.imgSrc;
147
+ }
148
+ }
149
+
150
+ return nodeText || "";
151
+ });
@@ -0,0 +1,68 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { truncateWhiteSpace } from "./utils";
13
+ import { isNonEmptyString } from "../../utils";
14
+ const semanticElements = /^(HEADER|MAIN|FOOTER|NAV)$/i;
15
+
16
+ const getAriaRegionLabel = node => {
17
+ let regionLabel;
18
+
19
+ if (node.role === "region" && isNonEmptyString(node["aria-label"])) {
20
+ regionLabel = node["aria-label"];
21
+ }
22
+
23
+ return regionLabel;
24
+ };
25
+
26
+ const getSectionNodeName = node => {
27
+ let nodeName;
28
+
29
+ if (node && node.nodeName) {
30
+ if (node.nodeName.match(semanticElements)) {
31
+ nodeName = node.nodeName;
32
+ }
33
+ }
34
+
35
+ return nodeName;
36
+ };
37
+ /**
38
+ * Extracts a node link-region.
39
+ *
40
+ * The link-region is determined by traversing up the DOM
41
+ * looking for a region that is determined in order of priority:
42
+ *
43
+ * 1. element.id
44
+ * 2. Aria region label
45
+ * 3. Semantic element name
46
+ * 4. BODY (if no other link-region is found).
47
+ *
48
+ * @param {*} node The node to find link region for.
49
+ * @returns {string} link-region.
50
+ */
51
+
52
+
53
+ export default (node => {
54
+ let linkParentNode = node.parentNode;
55
+ let regionName;
56
+
57
+ while (linkParentNode) {
58
+ regionName = truncateWhiteSpace(linkParentNode.id || getAriaRegionLabel(linkParentNode) || getSectionNodeName(linkParentNode));
59
+
60
+ if (regionName) {
61
+ return regionName;
62
+ }
63
+
64
+ linkParentNode = linkParentNode.parentNode;
65
+ }
66
+
67
+ return "BODY";
68
+ });