@adobe/alloy 2.20.0 → 2.21.0-beta.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.
Files changed (71) hide show
  1. package/libEs5/components/Personalization/createApplyPropositions.js +27 -10
  2. package/libEs5/components/Personalization/createClickStorage.js +4 -4
  3. package/libEs5/components/Personalization/createInteractionStorage.js +102 -0
  4. package/libEs5/components/Personalization/createOnClickHandler.js +49 -21
  5. package/libEs5/components/Personalization/dom-actions/action.js +4 -4
  6. package/libEs5/components/Personalization/dom-actions/appendHtml.js +2 -1
  7. package/libEs5/components/Personalization/dom-actions/clicks/collectClicks.js +15 -33
  8. package/libEs5/components/Personalization/dom-actions/clicks/collectInteractions.js +81 -0
  9. package/libEs5/components/Personalization/dom-actions/collectInteractions.js +17 -0
  10. package/libEs5/components/Personalization/dom-actions/dom/isDomElement.js +17 -0
  11. package/libEs5/components/Personalization/dom-actions/initDomActionsModules.js +36 -19
  12. package/libEs5/components/Personalization/dom-actions/insertHtmlAfter.js +5 -2
  13. package/libEs5/components/Personalization/dom-actions/insertHtmlBefore.js +2 -1
  14. package/libEs5/components/Personalization/dom-actions/prependHtml.js +2 -1
  15. package/libEs5/components/Personalization/dom-actions/rearrangeChildren.js +3 -1
  16. package/libEs5/components/Personalization/dom-actions/remapCustomCodeOffers.js +2 -2
  17. package/libEs5/components/Personalization/dom-actions/remapHeadOffers.js +2 -2
  18. package/libEs5/components/Personalization/dom-actions/replaceHtml.js +4 -3
  19. package/libEs5/components/Personalization/dom-actions/setAttributes.js +2 -1
  20. package/libEs5/components/Personalization/dom-actions/setHtml.js +2 -2
  21. package/libEs5/components/Personalization/dom-actions/setStyles.js +2 -1
  22. package/libEs5/components/Personalization/dom-actions/setText.js +2 -1
  23. package/libEs5/components/Personalization/dom-actions/swapImage.js +2 -1
  24. package/libEs5/components/Personalization/handlers/createDecorateProposition.js +60 -0
  25. package/libEs5/components/Personalization/handlers/createProcessDomAction.js +10 -6
  26. package/libEs5/components/Personalization/handlers/createProcessHtmlContent.js +6 -2
  27. package/libEs5/components/Personalization/handlers/createProcessPropositions.js +1 -1
  28. package/libEs5/components/Personalization/handlers/injectCreateProposition.js +12 -1
  29. package/libEs5/components/Personalization/index.js +26 -7
  30. package/libEs5/components/Personalization/utils/metaUtils.js +33 -0
  31. package/libEs5/components/Personalization/validateApplyPropositionsOptions.js +12 -1
  32. package/libEs5/constants/decisionProvider.js +3 -2
  33. package/libEs5/constants/libraryVersion.js +1 -1
  34. package/libEs5/constants/propositionInteractionType.js +18 -0
  35. package/libEs5/utils/dom/awaitSelector.js +5 -1
  36. package/libEs6/components/Personalization/createApplyPropositions.js +25 -10
  37. package/libEs6/components/Personalization/createClickStorage.js +4 -4
  38. package/libEs6/components/Personalization/createInteractionStorage.js +85 -0
  39. package/libEs6/components/Personalization/createOnClickHandler.js +49 -22
  40. package/libEs6/components/Personalization/dom-actions/action.js +4 -4
  41. package/libEs6/components/Personalization/dom-actions/appendHtml.js +3 -2
  42. package/libEs6/components/Personalization/dom-actions/clicks/collectClicks.js +8 -18
  43. package/libEs6/components/Personalization/dom-actions/clicks/collectInteractions.js +74 -0
  44. package/libEs6/components/Personalization/dom-actions/collectInteractions.js +15 -0
  45. package/libEs6/components/Personalization/dom-actions/dom/isDomElement.js +12 -0
  46. package/libEs6/components/Personalization/dom-actions/initDomActionsModules.js +46 -16
  47. package/libEs6/components/Personalization/dom-actions/insertHtmlAfter.js +5 -2
  48. package/libEs6/components/Personalization/dom-actions/insertHtmlBefore.js +3 -2
  49. package/libEs6/components/Personalization/dom-actions/prependHtml.js +3 -2
  50. package/libEs6/components/Personalization/dom-actions/rearrangeChildren.js +3 -1
  51. package/libEs6/components/Personalization/dom-actions/remapCustomCodeOffers.js +2 -2
  52. package/libEs6/components/Personalization/dom-actions/remapHeadOffers.js +2 -2
  53. package/libEs6/components/Personalization/dom-actions/replaceHtml.js +4 -3
  54. package/libEs6/components/Personalization/dom-actions/setAttributes.js +2 -1
  55. package/libEs6/components/Personalization/dom-actions/setHtml.js +2 -2
  56. package/libEs6/components/Personalization/dom-actions/setStyles.js +2 -1
  57. package/libEs6/components/Personalization/dom-actions/setText.js +2 -1
  58. package/libEs6/components/Personalization/dom-actions/swapImage.js +3 -2
  59. package/libEs6/components/Personalization/handlers/createDecorateProposition.js +59 -0
  60. package/libEs6/components/Personalization/handlers/createProcessDomAction.js +10 -4
  61. package/libEs6/components/Personalization/handlers/createProcessHtmlContent.js +6 -2
  62. package/libEs6/components/Personalization/handlers/createProcessPropositions.js +1 -1
  63. package/libEs6/components/Personalization/handlers/injectCreateProposition.js +12 -1
  64. package/libEs6/components/Personalization/index.js +32 -8
  65. package/libEs6/components/Personalization/utils/metaUtils.js +23 -0
  66. package/libEs6/components/Personalization/validateApplyPropositionsOptions.js +12 -1
  67. package/libEs6/constants/decisionProvider.js +2 -1
  68. package/libEs6/constants/libraryVersion.js +1 -1
  69. package/libEs6/constants/propositionInteractionType.js +15 -0
  70. package/libEs6/utils/dom/awaitSelector.js +5 -1
  71. package/package.json +2 -2
@@ -20,7 +20,7 @@ const metasToArray = metas => {
20
20
  };
21
21
  export default (() => {
22
22
  const clickStorage = {};
23
- const storeClickMetrics = ({
23
+ const storeClickMeta = ({
24
24
  selector,
25
25
  meta: {
26
26
  id,
@@ -43,7 +43,7 @@ export default (() => {
43
43
  const getClickSelectors = () => {
44
44
  return Object.keys(clickStorage);
45
45
  };
46
- const getClickMetasBySelector = selector => {
46
+ const getClickMetas = selector => {
47
47
  const metas = clickStorage[selector];
48
48
  if (!metas) {
49
49
  return {};
@@ -51,8 +51,8 @@ export default (() => {
51
51
  return metasToArray(clickStorage[selector]);
52
52
  };
53
53
  return {
54
- storeClickMetrics,
54
+ storeClickMeta,
55
55
  getClickSelectors,
56
- getClickMetasBySelector
56
+ getClickMetas
57
57
  };
58
58
  });
@@ -0,0 +1,85 @@
1
+ /*
2
+ Copyright 2020 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
+
13
+ export default (() => {
14
+ const clickMetaStorage = {};
15
+ /*
16
+ clickMetaStorage example.
17
+ `abc' and 'def' are proposition IDs. 1 is an interact id. The object with an id, scope and scopeDetails
18
+ is the notification.
19
+ {
20
+ 1: {
21
+ "abc": { "id": "abc", "scope": "proposition", "scopeDetails": {} },
22
+ "def": { "id": "def", "scope": "proposition", "scopeDetails": {} }
23
+ }
24
+ }
25
+ */
26
+
27
+ const clickItemStorage = {};
28
+ /*
29
+ clickItemStorage example.
30
+ `abc' and 'def' are proposition IDs. 1 is an interact id. The sets contain proposition-item IDs which
31
+ are used in notifications that are sent.
32
+ {
33
+ 1: {
34
+ abc: new Set(["itemAAA", "itemCCC"]),
35
+ def: new Set(["itemEEE", "itemFFF"]),
36
+ },
37
+ }
38
+ */
39
+
40
+ const storeInteractionMeta = (propositionId, itemId, scopeType, notification, interactId) => {
41
+ // eslint-disable-next-line no-param-reassign
42
+ interactId = parseInt(interactId, 10);
43
+ if (!clickMetaStorage[interactId]) {
44
+ clickMetaStorage[interactId] = {};
45
+ clickItemStorage[interactId] = {};
46
+ }
47
+ if (!clickItemStorage[interactId][propositionId]) {
48
+ clickItemStorage[interactId][propositionId] = new Set();
49
+ }
50
+ clickItemStorage[interactId][propositionId].add(itemId);
51
+ clickMetaStorage[interactId][propositionId] = {
52
+ ...notification,
53
+ scopeType
54
+ };
55
+ };
56
+ const getInteractionMetas = interactIds => {
57
+ if (!Array.isArray(interactIds) || interactIds.length === 0) {
58
+ return [];
59
+ }
60
+ return Object.values(interactIds.map(value => parseInt(value, 10)).reduce((metaMap, interactId) => {
61
+ Object.keys(clickMetaStorage[interactId] || {}).forEach(propositionId => {
62
+ if (!metaMap[propositionId]) {
63
+ metaMap[propositionId] = {
64
+ proposition: clickMetaStorage[interactId][propositionId],
65
+ items: new Set()
66
+ };
67
+ }
68
+ metaMap[propositionId].items = new Set([...metaMap[propositionId].items, ...clickItemStorage[interactId][propositionId]]);
69
+ });
70
+ return metaMap;
71
+ }, {})).map(({
72
+ proposition,
73
+ items
74
+ }) => ({
75
+ ...proposition,
76
+ items: Array.from(items).map(id => ({
77
+ id
78
+ }))
79
+ }));
80
+ };
81
+ return {
82
+ storeInteractionMeta,
83
+ getInteractionMetas
84
+ };
85
+ });
@@ -13,40 +13,67 @@ governing permissions and limitations under the License.
13
13
  import { isNonEmptyArray } from "../../utils/index.js";
14
14
  import { INTERACT } from "../../constants/eventType.js";
15
15
  import { PropositionEventType } from "../../constants/propositionEventType.js";
16
+ const createPropositionAction = (clickLabel, clickToken) => {
17
+ if (!clickToken && !clickLabel) {
18
+ return undefined;
19
+ }
20
+ const propositionAction = {};
21
+ if (clickLabel) {
22
+ propositionAction.label = clickLabel;
23
+ }
24
+ if (clickToken) {
25
+ propositionAction.tokens = [clickToken];
26
+ }
27
+ return propositionAction;
28
+ };
16
29
  export default (({
17
30
  mergeDecisionsMeta,
31
+ collectInteractions,
18
32
  collectClicks,
33
+ getInteractionMetas,
34
+ getClickMetas,
19
35
  getClickSelectors,
20
- getClickMetasBySelector
36
+ autoCollectPropositionInteractions
21
37
  }) => {
22
38
  // Called when an element qualifying for conversion within an offer is clicked.
23
39
  return ({
24
40
  event,
25
41
  clickedElement
26
42
  }) => {
27
- const selectors = getClickSelectors();
28
- if (isNonEmptyArray(selectors)) {
29
- const {
30
- decisionsMeta,
31
- eventLabel,
32
- viewName
33
- } = collectClicks(clickedElement, selectors, getClickMetasBySelector);
34
- if (isNonEmptyArray(decisionsMeta)) {
35
- const xdm = {
36
- eventType: INTERACT
43
+ const decisionsMeta = [];
44
+ let propositionActionLabel;
45
+ let propositionActionToken;
46
+ let viewName;
47
+ [collectInteractions(clickedElement, getInteractionMetas, autoCollectPropositionInteractions), collectClicks(clickedElement, getClickSelectors(), getClickMetas)].forEach(({
48
+ decisionsMeta: curDecisionsMeta,
49
+ propositionActionLabel: curPropositionActionLabel,
50
+ propositionActionToken: curPropositionActionToken,
51
+ viewName: curViewName
52
+ }) => {
53
+ Array.prototype.push.apply(decisionsMeta, curDecisionsMeta);
54
+ if (!propositionActionLabel && curPropositionActionLabel) {
55
+ propositionActionLabel = curPropositionActionLabel;
56
+ }
57
+ if (!propositionActionToken && curPropositionActionToken) {
58
+ propositionActionToken = curPropositionActionToken;
59
+ }
60
+ if (!viewName && curViewName) {
61
+ viewName = curViewName;
62
+ }
63
+ });
64
+ if (isNonEmptyArray(decisionsMeta)) {
65
+ const xdm = {
66
+ eventType: INTERACT
67
+ };
68
+ if (viewName) {
69
+ xdm.web = {
70
+ webPageDetails: {
71
+ viewName
72
+ }
37
73
  };
38
- if (viewName) {
39
- xdm.web = {
40
- webPageDetails: {
41
- viewName
42
- }
43
- };
44
- }
45
- event.mergeXdm(xdm);
46
- mergeDecisionsMeta(event, decisionsMeta, [PropositionEventType.INTERACT], eventLabel ? {
47
- label: eventLabel
48
- } : undefined);
49
74
  }
75
+ event.mergeXdm(xdm);
76
+ mergeDecisionsMeta(event, decisionsMeta, [PropositionEventType.INTERACT], createPropositionAction(propositionActionLabel, propositionActionToken));
50
77
  }
51
78
  };
52
79
  });
@@ -24,19 +24,19 @@ export { default as setStyles } from "./setStyles.js";
24
24
  export { default as setAttributes } from "./setAttributes.js";
25
25
  export { default as swapImage } from "./swapImage.js";
26
26
  export { default as rearrangeChildren } from "./rearrangeChildren.js";
27
- const renderContent = (elements, content, renderFunc) => {
28
- const executions = elements.map(element => renderFunc(element, content));
27
+ const renderContent = (elements, content, decorateProposition, renderFunc) => {
28
+ const executions = elements.map(element => renderFunc(element, content, decorateProposition));
29
29
  return Promise.all(executions);
30
30
  };
31
31
  export const createAction = renderFunc => {
32
- return itemData => {
32
+ return (itemData, decorateProposition) => {
33
33
  const {
34
34
  selector,
35
35
  prehidingSelector,
36
36
  content
37
37
  } = itemData;
38
38
  hideElements(prehidingSelector);
39
- return awaitSelector(selector, selectNodesWithEq).then(elements => renderContent(elements, content, renderFunc)).then(() => {
39
+ return awaitSelector(selector, selectNodesWithEq).then(elements => renderContent(elements, content, decorateProposition, renderFunc)).then(() => {
40
40
  // if everything is OK, show elements
41
41
  showElements(prehidingSelector);
42
42
  }, error => {
@@ -14,8 +14,8 @@ import { appendNode } from "../../../utils/dom/index.js";
14
14
  import { createFragment, getChildNodes } from "./dom/index.js";
15
15
  import { loadImages } from "./images.js";
16
16
  import addNonceToInlineStyleElements from "./addNonceToInlineStyleElements.js";
17
- import { getInlineScripts, getRemoteScriptsUrls, executeInlineScripts, executeRemoteScripts } from "./scripts.js";
18
- export default ((container, html) => {
17
+ import { executeInlineScripts, executeRemoteScripts, getInlineScripts, getRemoteScriptsUrls } from "./scripts.js";
18
+ export default ((container, html, decorateProposition) => {
19
19
  const fragment = createFragment(html);
20
20
  addNonceToInlineStyleElements(fragment);
21
21
  const elements = getChildNodes(fragment);
@@ -25,6 +25,7 @@ export default ((container, html) => {
25
25
  elements.forEach(element => {
26
26
  appendNode(container, element);
27
27
  });
28
+ decorateProposition(container);
28
29
  executeInlineScripts(container, scripts);
29
30
  return executeRemoteScripts(scriptsUrls);
30
31
  });
@@ -12,7 +12,8 @@ governing permissions and limitations under the License.
12
12
 
13
13
  import matchesSelectorWithEq from "../dom/matchesSelectorWithEq.js";
14
14
  import { VIEW_SCOPE_TYPE } from "../../constants/scopeType.js";
15
- const getMetasIfMatches = (clickedElement, selector, getClickMetasBySelector) => {
15
+ import { cleanMetas, dedupeMetas } from "../../utils/metaUtils.js";
16
+ const getMetasIfMatches = (clickedElement, selector, getClickMetas) => {
16
17
  const {
17
18
  documentElement
18
19
  } = document;
@@ -20,7 +21,7 @@ const getMetasIfMatches = (clickedElement, selector, getClickMetasBySelector) =>
20
21
  let i = 0;
21
22
  while (element && element !== documentElement) {
22
23
  if (matchesSelectorWithEq(selector, element)) {
23
- const matchedMetas = getClickMetasBySelector(selector);
24
+ const matchedMetas = getClickMetas(selector);
24
25
  const returnValue = {
25
26
  metas: matchedMetas
26
27
  };
@@ -43,19 +44,7 @@ const getMetasIfMatches = (clickedElement, selector, getClickMetasBySelector) =>
43
44
  metas: null
44
45
  };
45
46
  };
46
- const cleanMetas = metas => metas.map(meta => {
47
- const {
48
- trackingLabel,
49
- scopeType,
50
- ...rest
51
- } = meta;
52
- return rest;
53
- });
54
- const dedupMetas = metas => metas.filter((meta, index) => {
55
- const stringifiedMeta = JSON.stringify(meta);
56
- return index === metas.findIndex(innerMeta => JSON.stringify(innerMeta) === stringifiedMeta);
57
- });
58
- export default ((clickedElement, selectors, getClickMetasBySelector) => {
47
+ export default ((clickedElement, selectors, getClickMetas) => {
59
48
  const result = [];
60
49
  let resultLabel = "";
61
50
  let resultLabelWeight = Number.MAX_SAFE_INTEGER;
@@ -69,7 +58,7 @@ export default ((clickedElement, selectors, getClickMetasBySelector) => {
69
58
  label,
70
59
  weight,
71
60
  viewName
72
- } = getMetasIfMatches(clickedElement, selectors[i], getClickMetasBySelector);
61
+ } = getMetasIfMatches(clickedElement, selectors[i], getClickMetas);
73
62
  if (!metas) {
74
63
  continue;
75
64
  }
@@ -84,8 +73,9 @@ export default ((clickedElement, selectors, getClickMetasBySelector) => {
84
73
  result.push(...cleanMetas(metas));
85
74
  }
86
75
  return {
87
- decisionsMeta: dedupMetas(result),
88
- eventLabel: resultLabel,
76
+ decisionsMeta: dedupeMetas(result),
77
+ propositionActionLabel: resultLabel,
78
+ propositionActionToken: undefined,
89
79
  viewName: resultViewName
90
80
  };
91
81
  });
@@ -0,0 +1,74 @@
1
+ /*
2
+ Copyright 2019 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
+
13
+ import { VIEW_SCOPE_TYPE } from "../../constants/scopeType.js";
14
+ import getAttribute from "../dom/getAttribute.js";
15
+ import { CLICK_LABEL_DATA_ATTRIBUTE, CLICK_TOKEN_DATA_ATTRIBUTE, INTERACT_ID_DATA_ATTRIBUTE } from "../../handlers/createDecorateProposition.js";
16
+ import { cleanMetas } from "../../utils/metaUtils.js";
17
+ import { ALWAYS, DECORATED_ELEMENTS_ONLY } from "../../../../constants/propositionInteractionType.js";
18
+ const getInteractionDetail = clickedElement => {
19
+ const {
20
+ documentElement
21
+ } = document;
22
+ let element = clickedElement;
23
+ const interactIds = new Set();
24
+ let clickLabel;
25
+ let clickToken;
26
+ while (element && element !== documentElement) {
27
+ const interactId = getAttribute(element, INTERACT_ID_DATA_ATTRIBUTE);
28
+ if (interactId) {
29
+ interactIds.add(interactId);
30
+ }
31
+ clickLabel = clickLabel || getAttribute(element, CLICK_LABEL_DATA_ATTRIBUTE);
32
+ clickToken = clickToken || getAttribute(element, CLICK_TOKEN_DATA_ATTRIBUTE);
33
+ element = element.parentNode;
34
+ }
35
+ return {
36
+ interactIds: [...interactIds],
37
+ clickLabel,
38
+ clickToken
39
+ };
40
+ };
41
+ const extractViewName = metas => {
42
+ const foundMetaWithScopeTypeView = metas.find(meta => meta.scopeType === VIEW_SCOPE_TYPE);
43
+ return foundMetaWithScopeTypeView ? foundMetaWithScopeTypeView.scope : undefined;
44
+ };
45
+ const createMetaFilter = (autoCollectPropositionInteractions, clickLabel, clickToken) => meta => {
46
+ const {
47
+ scopeDetails = {}
48
+ } = meta;
49
+ const {
50
+ decisionProvider
51
+ } = scopeDetails;
52
+ if (autoCollectPropositionInteractions[decisionProvider] === ALWAYS) {
53
+ return true;
54
+ }
55
+ return autoCollectPropositionInteractions[decisionProvider] === DECORATED_ELEMENTS_ONLY && (clickLabel || clickToken);
56
+ };
57
+ export default ((clickedElement, getInteractionMetas, autoCollectPropositionInteractions) => {
58
+ const {
59
+ interactIds,
60
+ clickLabel = "",
61
+ clickToken
62
+ } = getInteractionDetail(clickedElement);
63
+ const metasMatchingConfigurationOptions = createMetaFilter(autoCollectPropositionInteractions, clickLabel, clickToken);
64
+ if (interactIds.length === 0) {
65
+ return {};
66
+ }
67
+ const metas = getInteractionMetas(interactIds).filter(metasMatchingConfigurationOptions);
68
+ return {
69
+ decisionsMeta: cleanMetas(metas),
70
+ propositionActionLabel: clickLabel,
71
+ propositionActionToken: clickToken,
72
+ viewName: extractViewName(metas)
73
+ };
74
+ });
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2019 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
+
13
+ export default ((container, content, decorateProposition) => {
14
+ decorateProposition(container);
15
+ });
@@ -0,0 +1,12 @@
1
+ /*
2
+ Copyright 2024 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 (element => element instanceof Element || element instanceof HTMLDocument);
@@ -11,23 +11,53 @@ governing permissions and limitations under the License.
11
11
  */
12
12
 
13
13
  import { removeNode } from "../../../utils/dom/index.js";
14
- import { createAction, setHtml, setText, setAttributes, swapImage, setStyles, rearrangeChildren, replaceHtml, appendHtml, prependHtml, insertHtmlAfter, insertHtmlBefore } from "./action.js";
14
+ import setHtml from "./setHtml.js";
15
+ import prependHtml from "./prependHtml.js";
16
+ import { createAction } from "./action.js";
17
+ import setText from "./setText.js";
18
+ import setAttributes from "./setAttributes.js";
19
+ import swapImage from "./swapImage.js";
20
+ import setStyles from "./setStyles.js";
21
+ import rearrangeChildren from "./rearrangeChildren.js";
22
+ import insertHtmlAfter from "./insertHtmlAfter.js";
23
+ import insertHtmlBefore from "./insertHtmlBefore.js";
24
+ import replaceHtml from "./replaceHtml.js";
25
+ import appendHtml from "./appendHtml.js";
26
+ import collectInteractions from "./collectInteractions.js";
27
+ export const DOM_ACTION_SET_HTML = "setHtml";
28
+ export const DOM_ACTION_CUSTOM_CODE = "customCode";
29
+ export const DOM_ACTION_SET_TEXT = "setText";
30
+ export const DOM_ACTION_SET_ATTRIBUTE = "setAttribute";
31
+ export const DOM_ACTION_SET_IMAGE_SOURCE = "setImageSource";
32
+ export const DOM_ACTION_SET_STYLE = "setStyle";
33
+ export const DOM_ACTION_MOVE = "move";
34
+ export const DOM_ACTION_RESIZE = "resize";
35
+ export const DOM_ACTION_REARRANGE = "rearrange";
36
+ export const DOM_ACTION_REMOVE = "remove";
37
+ export const DOM_ACTION_INSERT_AFTER = "insertAfter";
38
+ export const DOM_ACTION_INSERT_BEFORE = "insertBefore";
39
+ export const DOM_ACTION_REPLACE_HTML = "replaceHtml";
40
+ export const DOM_ACTION_PREPEND_HTML = "prependHtml";
41
+ export const DOM_ACTION_APPEND_HTML = "appendHtml";
42
+ export const DOM_ACTION_CLICK = "click";
43
+ export const DOM_ACTION_COLLECT_INTERACTIONS = "collectInteractions";
15
44
  export default (() => {
16
45
  return {
17
- setHtml: createAction(setHtml),
18
- customCode: createAction(prependHtml),
19
- setText: createAction(setText),
20
- setAttribute: createAction(setAttributes),
21
- setImageSource: createAction(swapImage),
22
- setStyle: createAction(setStyles),
23
- move: createAction(setStyles),
24
- resize: createAction(setStyles),
25
- rearrange: createAction(rearrangeChildren),
26
- remove: createAction(removeNode),
27
- insertAfter: createAction(insertHtmlAfter),
28
- insertBefore: createAction(insertHtmlBefore),
29
- replaceHtml: createAction(replaceHtml),
30
- prependHtml: createAction(prependHtml),
31
- appendHtml: createAction(appendHtml)
46
+ [DOM_ACTION_SET_HTML]: createAction(setHtml),
47
+ [DOM_ACTION_CUSTOM_CODE]: createAction(prependHtml),
48
+ [DOM_ACTION_SET_TEXT]: createAction(setText),
49
+ [DOM_ACTION_SET_ATTRIBUTE]: createAction(setAttributes),
50
+ [DOM_ACTION_SET_IMAGE_SOURCE]: createAction(swapImage),
51
+ [DOM_ACTION_SET_STYLE]: createAction(setStyles),
52
+ [DOM_ACTION_MOVE]: createAction(setStyles),
53
+ [DOM_ACTION_RESIZE]: createAction(setStyles),
54
+ [DOM_ACTION_REARRANGE]: createAction(rearrangeChildren),
55
+ [DOM_ACTION_REMOVE]: createAction(removeNode),
56
+ [DOM_ACTION_INSERT_AFTER]: createAction(insertHtmlAfter),
57
+ [DOM_ACTION_INSERT_BEFORE]: createAction(insertHtmlBefore),
58
+ [DOM_ACTION_REPLACE_HTML]: createAction(replaceHtml),
59
+ [DOM_ACTION_PREPEND_HTML]: createAction(prependHtml),
60
+ [DOM_ACTION_APPEND_HTML]: createAction(appendHtml),
61
+ [DOM_ACTION_COLLECT_INTERACTIONS]: createAction(collectInteractions)
32
62
  };
33
63
  });
@@ -14,15 +14,18 @@ import { createFragment, getChildNodes, insertAfter } from "./dom/index.js";
14
14
  import { loadImages } from "./images.js";
15
15
  import addNonceToInlineStyleElements from "./addNonceToInlineStyleElements.js";
16
16
  import { getInlineScripts, getRemoteScriptsUrls, executeInlineScripts, executeRemoteScripts } from "./scripts.js";
17
- export default ((container, html) => {
17
+ export default ((container, html, decorateProposition) => {
18
18
  const fragment = createFragment(html);
19
19
  addNonceToInlineStyleElements(fragment);
20
20
  const elements = getChildNodes(fragment);
21
21
  const scripts = getInlineScripts(fragment);
22
22
  const scriptsUrls = getRemoteScriptsUrls(fragment);
23
23
  loadImages(fragment);
24
+ let insertionPoint = container;
24
25
  elements.forEach(element => {
25
- insertAfter(container, element);
26
+ decorateProposition(element);
27
+ insertAfter(insertionPoint, element);
28
+ insertionPoint = element;
26
29
  });
27
30
  executeInlineScripts(container, scripts);
28
31
  return executeRemoteScripts(scriptsUrls);
@@ -13,8 +13,8 @@ governing permissions and limitations under the License.
13
13
  import { createFragment, getChildNodes, insertBefore } from "./dom/index.js";
14
14
  import { loadImages } from "./images.js";
15
15
  import addNonceToInlineStyleElements from "./addNonceToInlineStyleElements.js";
16
- import { getInlineScripts, getRemoteScriptsUrls, executeInlineScripts, executeRemoteScripts } from "./scripts.js";
17
- export default ((container, html) => {
16
+ import { executeInlineScripts, executeRemoteScripts, getInlineScripts, getRemoteScriptsUrls } from "./scripts.js";
17
+ export default ((container, html, decorateProposition) => {
18
18
  const fragment = createFragment(html);
19
19
  addNonceToInlineStyleElements(fragment);
20
20
  const elements = getChildNodes(fragment);
@@ -22,6 +22,7 @@ export default ((container, html) => {
22
22
  const scriptsUrls = getRemoteScriptsUrls(fragment);
23
23
  loadImages(fragment);
24
24
  elements.forEach(element => {
25
+ decorateProposition(element);
25
26
  insertBefore(container, element);
26
27
  });
27
28
  executeInlineScripts(container, scripts);
@@ -14,8 +14,8 @@ import { appendNode } from "../../../utils/dom/index.js";
14
14
  import { createFragment, getChildNodes, getFirstChild, insertBefore } from "./dom/index.js";
15
15
  import { loadImages } from "./images.js";
16
16
  import addNonceToInlineStyleElements from "./addNonceToInlineStyleElements.js";
17
- import { getInlineScripts, getRemoteScriptsUrls, executeInlineScripts, executeRemoteScripts } from "./scripts.js";
18
- export default ((container, html) => {
17
+ import { executeInlineScripts, executeRemoteScripts, getInlineScripts, getRemoteScriptsUrls } from "./scripts.js";
18
+ export default ((container, html, decorateProposition) => {
19
19
  const fragment = createFragment(html);
20
20
  addNonceToInlineStyleElements(fragment);
21
21
  const elements = getChildNodes(fragment);
@@ -32,6 +32,7 @@ export default ((container, html) => {
32
32
  // We are inserting elements in reverse order
33
33
  while (i >= 0) {
34
34
  const element = elements[i];
35
+ decorateProposition(element);
35
36
  const firstChild = getFirstChild(container);
36
37
  if (firstChild) {
37
38
  insertBefore(firstChild, element);
@@ -14,7 +14,7 @@ import { getChildren, insertAfter, insertBefore } from "./dom/index.js";
14
14
  export default ((container, {
15
15
  from,
16
16
  to
17
- }) => {
17
+ }, decorateProposition) => {
18
18
  const children = getChildren(container);
19
19
  const elementFrom = children[from];
20
20
  const elementTo = children[to];
@@ -28,4 +28,6 @@ export default ((container, {
28
28
  } else {
29
29
  insertBefore(elementTo, elementFrom);
30
30
  }
31
+ decorateProposition(elementTo);
32
+ decorateProposition(elementFrom);
31
33
  });
@@ -15,14 +15,14 @@ governing permissions and limitations under the License.
15
15
  * target offers, to align with the way it works in at.js.
16
16
  */
17
17
  import { assign } from "../../../utils/index.js";
18
- const ACTION_CUSTOM_CODE = "customCode";
18
+ import { DOM_ACTION_CUSTOM_CODE } from "./initDomActionsModules.js";
19
19
  const TARGET_BODY_SELECTOR = "BODY > *:eq(0)";
20
20
  export default (action => {
21
21
  const {
22
22
  selector,
23
23
  type
24
24
  } = action;
25
- if (type !== ACTION_CUSTOM_CODE) {
25
+ if (type !== DOM_ACTION_CUSTOM_CODE) {
26
26
  return action;
27
27
  }
28
28
  if (selector !== TARGET_BODY_SELECTOR) {
@@ -22,7 +22,7 @@ import { createFragment, selectNodesWithEq } from "./dom/index.js";
22
22
  import { assign } from "../../../utils/index.js";
23
23
  import isBlankString from "../../../utils/isBlankString.js";
24
24
  import { HEAD } from "../../../constants/tagName.js";
25
- const APPEND_HTML = "appendHtml";
25
+ import { DOM_ACTION_APPEND_HTML } from "./initDomActionsModules.js";
26
26
  const HEAD_TAGS_SELECTOR = "SCRIPT,LINK,STYLE";
27
27
  const filterHeadContent = content => {
28
28
  const container = createFragment(content);
@@ -45,7 +45,7 @@ export default (action => {
45
45
  if (!is(container[0], HEAD)) {
46
46
  return result;
47
47
  }
48
- result.type = APPEND_HTML;
48
+ result.type = DOM_ACTION_APPEND_HTML;
49
49
  result.content = filterHeadContent(content);
50
50
  return result;
51
51
  });
@@ -12,7 +12,8 @@ governing permissions and limitations under the License.
12
12
 
13
13
  import { removeNode } from "../../../utils/dom/index.js";
14
14
  import insertHtmlBefore from "./insertHtmlBefore.js";
15
- export default ((container, html) => {
16
- insertHtmlBefore(container, html);
17
- removeNode(container);
15
+ export default ((container, html, decorateProposition) => {
16
+ return insertHtmlBefore(container, html, decorateProposition).then(() => {
17
+ removeNode(container);
18
+ });
18
19
  });
@@ -11,8 +11,9 @@ governing permissions and limitations under the License.
11
11
  */
12
12
 
13
13
  import { setAttribute } from "./dom/index.js";
14
- export default ((container, attributes) => {
14
+ export default ((container, attributes, decorateProposition) => {
15
15
  Object.keys(attributes).forEach(key => {
16
16
  setAttribute(container, key, attributes[key]);
17
17
  });
18
+ decorateProposition(container);
18
19
  });
@@ -18,7 +18,7 @@ const clear = container => {
18
18
  const childNodes = getChildNodes(container);
19
19
  childNodes.forEach(removeNode);
20
20
  };
21
- export default ((container, html) => {
21
+ export default ((container, html, decorateProposition) => {
22
22
  clear(container);
23
- appendHtml(container, html);
23
+ return appendHtml(container, html, decorateProposition);
24
24
  });
@@ -11,7 +11,7 @@ governing permissions and limitations under the License.
11
11
  */
12
12
 
13
13
  import { setStyle } from "./dom/index.js";
14
- export default ((container, styles) => {
14
+ export default ((container, styles, decorateProposition) => {
15
15
  const {
16
16
  priority,
17
17
  ...style
@@ -19,4 +19,5 @@ export default ((container, styles) => {
19
19
  Object.keys(style).forEach(key => {
20
20
  setStyle(container, key, style[key], priority);
21
21
  });
22
+ decorateProposition(container);
22
23
  });
@@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
10
10
  governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export default ((container, text) => {
13
+ export default ((container, text, decorateProposition) => {
14
+ decorateProposition(container);
14
15
  container.textContent = text;
15
16
  });