@useinsider/guido 2.1.0-beta.42f5dfa → 2.1.0-beta.53ba3d5

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 (133) hide show
  1. package/dist/components/organisms/extensions/recommendation/FilterSelectionDrawer.vue2.js +14 -15
  2. package/dist/components/organisms/header/HeaderWrapper.vue.js +9 -9
  3. package/dist/composables/useHtmlValidator.js +84 -106
  4. package/dist/composables/useRecommendation.js +21 -54
  5. package/dist/config/compiler/recommendationCompilerRules.js +39 -45
  6. package/dist/config/migrator/itemsBlockMigrator.js +17 -17
  7. package/dist/config/migrator/recommendationMigrator.js +2 -2
  8. package/dist/enums/extensions/recommendationBlock.js +1 -1
  9. package/dist/enums/recommendation.js +15 -16
  10. package/dist/extensions/Blocks/Recommendation/block.js +9 -130
  11. package/dist/extensions/Blocks/Recommendation/cardCompositionControl.js +187 -0
  12. package/dist/extensions/Blocks/Recommendation/constants.js +13 -0
  13. package/dist/extensions/Blocks/Recommendation/control.js +336 -0
  14. package/dist/extensions/Blocks/Recommendation/controls/cardBackgroundColorControl.js +68 -0
  15. package/dist/extensions/Blocks/Recommendation/controls/index.js +245 -0
  16. package/dist/extensions/Blocks/Recommendation/controls/nameTextTrimControl.js +74 -0
  17. package/dist/extensions/Blocks/Recommendation/controls/{omnibusDiscount/textAfter.js → omnibusDiscountTextAfterControl.js} +14 -16
  18. package/dist/extensions/Blocks/Recommendation/controls/{omnibusDiscount/textBefore.js → omnibusDiscountTextBeforeControl.js} +14 -16
  19. package/dist/extensions/Blocks/Recommendation/controls/{omnibusPrice/textAfter.js → omnibusPriceTextAfterControl.js} +14 -16
  20. package/dist/extensions/Blocks/Recommendation/controls/{omnibusPrice/textBefore.js → omnibusPriceTextBeforeControl.js} +12 -14
  21. package/dist/extensions/Blocks/Recommendation/controls/spacingControl.js +188 -0
  22. package/dist/extensions/Blocks/Recommendation/extension.js +17 -40
  23. package/dist/extensions/Blocks/Recommendation/iconsRegistry.js +3 -19
  24. package/dist/extensions/Blocks/Recommendation/recommendation.css.js +4 -13
  25. package/dist/extensions/Blocks/Recommendation/settingsPanel.js +10 -21
  26. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +193 -230
  27. package/dist/extensions/Blocks/Recommendation/templates/blockTemplate.js +181 -0
  28. package/dist/extensions/Blocks/Recommendation/templates/migrationTemplate.js +189 -0
  29. package/dist/extensions/Blocks/Recommendation/templates/templateUtils.js +209 -0
  30. package/dist/extensions/Blocks/Recommendation/utils/filterUtil.js +9 -9
  31. package/dist/extensions/Blocks/Recommendation/utils/preserveTextStyles.js +15 -26
  32. package/dist/extensions/Blocks/controlFactories.js +93 -125
  33. package/dist/guido.css +1 -1
  34. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +169 -223
  35. package/dist/services/recommendationApi.js +9 -10
  36. package/dist/services/templateLibraryApi.js +13 -16
  37. package/dist/src/components/wrappers/WpDrawer.vue.d.ts +1 -1
  38. package/dist/src/composables/useRecommendation.d.ts +0 -1
  39. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +0 -67
  40. package/dist/src/extensions/Blocks/Recommendation/{controls/cardComposition/index.d.ts → cardCompositionControl.d.ts} +3 -23
  41. package/dist/src/extensions/Blocks/Recommendation/{constants/controlIds.d.ts → constants.d.ts} +24 -0
  42. package/dist/src/extensions/Blocks/Recommendation/control.d.ts +38 -0
  43. package/dist/src/extensions/Blocks/Recommendation/controls/index.d.ts +589 -21
  44. package/dist/src/extensions/Blocks/Recommendation/controls/nameTextTrimControl.d.ts +16 -0
  45. package/dist/src/extensions/Blocks/Recommendation/extension.d.ts +0 -9
  46. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +468 -131
  47. package/dist/src/extensions/Blocks/Recommendation/templates/blockTemplate.d.ts +16 -0
  48. package/dist/src/extensions/Blocks/Recommendation/templates/{grid/migration.d.ts → migrationTemplate.d.ts} +4 -11
  49. package/dist/src/extensions/Blocks/Recommendation/templates/templateUtils.d.ts +52 -0
  50. package/dist/static/styles/customEditorStyle.css.js +2 -25
  51. package/dist/utils/pairProductVariables.js +56 -57
  52. package/dist/utils/templatePreparation.js +14 -15
  53. package/package.json +1 -1
  54. package/dist/config/compiler/utils/recommendationCompilerUtils.js +0 -116
  55. package/dist/extensions/Blocks/Recommendation/constants/blockIds.js +0 -4
  56. package/dist/extensions/Blocks/Recommendation/constants/controlIds.js +0 -4
  57. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +0 -65
  58. package/dist/extensions/Blocks/Recommendation/constants/layout.js +0 -20
  59. package/dist/extensions/Blocks/Recommendation/constants/selectors.js +0 -19
  60. package/dist/extensions/Blocks/Recommendation/controls/button/index.js +0 -64
  61. package/dist/extensions/Blocks/Recommendation/controls/cardBackground/index.js +0 -80
  62. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +0 -232
  63. package/dist/extensions/Blocks/Recommendation/controls/image/index.js +0 -19
  64. package/dist/extensions/Blocks/Recommendation/controls/layout/index.js +0 -92
  65. package/dist/extensions/Blocks/Recommendation/controls/main/algorithm.js +0 -102
  66. package/dist/extensions/Blocks/Recommendation/controls/main/currency.js +0 -209
  67. package/dist/extensions/Blocks/Recommendation/controls/main/filters.js +0 -52
  68. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +0 -217
  69. package/dist/extensions/Blocks/Recommendation/controls/main/locale.js +0 -70
  70. package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +0 -110
  71. package/dist/extensions/Blocks/Recommendation/controls/main/shuffle.js +0 -67
  72. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +0 -286
  73. package/dist/extensions/Blocks/Recommendation/controls/name/index.js +0 -46
  74. package/dist/extensions/Blocks/Recommendation/controls/name/textTrim.js +0 -108
  75. package/dist/extensions/Blocks/Recommendation/controls/oldPrice/index.js +0 -44
  76. package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/index.js +0 -48
  77. package/dist/extensions/Blocks/Recommendation/controls/omnibusPrice/index.js +0 -48
  78. package/dist/extensions/Blocks/Recommendation/controls/price/index.js +0 -44
  79. package/dist/extensions/Blocks/Recommendation/controls/spacing/index.js +0 -222
  80. package/dist/extensions/Blocks/Recommendation/services/configService.js +0 -240
  81. package/dist/extensions/Blocks/Recommendation/templates/grid/elementRenderer.js +0 -233
  82. package/dist/extensions/Blocks/Recommendation/templates/grid/migration.js +0 -251
  83. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +0 -69
  84. package/dist/extensions/Blocks/Recommendation/templates/index.js +0 -12
  85. package/dist/extensions/Blocks/Recommendation/templates/list/elementRenderer.js +0 -174
  86. package/dist/extensions/Blocks/Recommendation/templates/list/template.js +0 -73
  87. package/dist/extensions/Blocks/Recommendation/templates/utils.js +0 -122
  88. package/dist/extensions/Blocks/Recommendation/types/nodeConfig.js +0 -6
  89. package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +0 -29
  90. package/dist/extensions/Blocks/Recommendation/utils/tagName.js +0 -46
  91. package/dist/src/config/compiler/utils/recommendationCompilerUtils.d.ts +0 -17
  92. package/dist/src/extensions/Blocks/Recommendation/constants/blockIds.d.ts +0 -13
  93. package/dist/src/extensions/Blocks/Recommendation/constants/defaultConfig.d.ts +0 -49
  94. package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +0 -13
  95. package/dist/src/extensions/Blocks/Recommendation/constants/layout.d.ts +0 -35
  96. package/dist/src/extensions/Blocks/Recommendation/constants/selectors.d.ts +0 -31
  97. package/dist/src/extensions/Blocks/Recommendation/controls/button/index.d.ts +0 -143
  98. package/dist/src/extensions/Blocks/Recommendation/controls/cardBackground/index.d.ts +0 -31
  99. package/dist/src/extensions/Blocks/Recommendation/controls/image/index.d.ts +0 -35
  100. package/dist/src/extensions/Blocks/Recommendation/controls/layout/index.d.ts +0 -37
  101. package/dist/src/extensions/Blocks/Recommendation/controls/main/algorithm.d.ts +0 -29
  102. package/dist/src/extensions/Blocks/Recommendation/controls/main/currency.d.ts +0 -52
  103. package/dist/src/extensions/Blocks/Recommendation/controls/main/filters.d.ts +0 -22
  104. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +0 -68
  105. package/dist/src/extensions/Blocks/Recommendation/controls/main/locale.d.ts +0 -24
  106. package/dist/src/extensions/Blocks/Recommendation/controls/main/productLayout.d.ts +0 -42
  107. package/dist/src/extensions/Blocks/Recommendation/controls/main/shuffle.d.ts +0 -23
  108. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +0 -214
  109. package/dist/src/extensions/Blocks/Recommendation/controls/name/index.d.ts +0 -97
  110. package/dist/src/extensions/Blocks/Recommendation/controls/name/textTrim.d.ts +0 -34
  111. package/dist/src/extensions/Blocks/Recommendation/controls/oldPrice/index.d.ts +0 -95
  112. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusDiscount/index.d.ts +0 -100
  113. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusDiscount/textAfter.d.ts +0 -15
  114. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusDiscount/textBefore.d.ts +0 -15
  115. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusPrice/index.d.ts +0 -100
  116. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusPrice/textAfter.d.ts +0 -15
  117. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusPrice/textBefore.d.ts +0 -15
  118. package/dist/src/extensions/Blocks/Recommendation/controls/price/index.d.ts +0 -95
  119. package/dist/src/extensions/Blocks/Recommendation/controls/spacing/index.d.ts +0 -83
  120. package/dist/src/extensions/Blocks/Recommendation/services/configService.d.ts +0 -151
  121. package/dist/src/extensions/Blocks/Recommendation/services/index.d.ts +0 -6
  122. package/dist/src/extensions/Blocks/Recommendation/templates/grid/elementRenderer.d.ts +0 -20
  123. package/dist/src/extensions/Blocks/Recommendation/templates/grid/template.d.ts +0 -33
  124. package/dist/src/extensions/Blocks/Recommendation/templates/index.d.ts +0 -39
  125. package/dist/src/extensions/Blocks/Recommendation/templates/list/elementRenderer.d.ts +0 -8
  126. package/dist/src/extensions/Blocks/Recommendation/templates/list/migration.d.ts +0 -25
  127. package/dist/src/extensions/Blocks/Recommendation/templates/list/template.d.ts +0 -18
  128. package/dist/src/extensions/Blocks/Recommendation/templates/utils.d.ts +0 -57
  129. package/dist/src/extensions/Blocks/Recommendation/types/index.d.ts +0 -7
  130. package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +0 -160
  131. package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +0 -33
  132. package/dist/src/extensions/Blocks/Recommendation/utils/stylePreserver.d.ts +0 -113
  133. package/dist/src/extensions/Blocks/Recommendation/utils/tagName.d.ts +0 -77
@@ -1,8 +1,8 @@
1
1
  var h = Object.defineProperty;
2
2
  var T = (A, e, t) => e in A ? h(A, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : A[e] = t;
3
3
  var m = (A, e, t) => T(A, typeof e != "symbol" ? e + "" : e, t);
4
- import P, { prepareProductRows as S } from "../../extensions/Blocks/Recommendation/templates/grid/migration.js";
5
- import { getDefaultProducts as q } from "../../extensions/Blocks/Recommendation/templates/utils.js";
4
+ import P, { prepareProductRows as S } from "../../extensions/Blocks/Recommendation/templates/migrationTemplate.js";
5
+ import { getDefaultProducts as q } from "../../extensions/Blocks/Recommendation/templates/templateUtils.js";
6
6
  class w {
7
7
  constructor() {
8
8
  m(this, "parser");
@@ -1,5 +1,5 @@
1
1
  const s = {
2
- RECOMMENDATION_API_URL: "https://recommendationv2.api.useinsider.com"
2
+ RECOMMENDATION_API_URL: "http://recommendationv2.api.useinsider.com"
3
3
  }, i = [
4
4
  { id: 11, key: "similarViewed", name: "Viewed Together", path: "viewed-together" },
5
5
  { id: 12, key: "similarBought", name: "Purchased Together", path: "purchased-together" },
@@ -1,4 +1,4 @@
1
- const e = 20, s = 320, t = "vertical", m = {
1
+ const s = 20, e = 320, t = {
2
2
  CART_ABANDONMENT: {
3
3
  ins_apr_img_1: "https://s3-eu-west-1.amazonaws.com/web-image.useinsider.com/email-assets/dummyImages/ins_apr_img_1.png",
4
4
  ins_apr_img_2: "https://s3-eu-west-1.amazonaws.com/web-image.useinsider.com/email-assets/dummyImages/ins_apr_img_2.png",
@@ -15,7 +15,7 @@ const e = 20, s = 320, t = "vertical", m = {
15
15
  DISCOUNT: "discount",
16
16
  OMNIBUS_DISCOUNT: "omnibus_discount",
17
17
  OMNIBUS_PRICE: "omnibus_price"
18
- }, _ = {
18
+ }, m = {
19
19
  IF: {
20
20
  discount: `{% if {${i.DISCOUNT}} != "0%" and {${i.DISCOUNT}} != "" %}`,
21
21
  omnibus_discount: `{% if {${i.DISCOUNT}} != "0%" and {${i.DISCOUNT}} != "" and {${i.OMNIBUS_DISCOUNT}} != "0%" and {${i.OMNIBUS_DISCOUNT}} != "" %}`,
@@ -23,17 +23,17 @@ const e = 20, s = 320, t = "vertical", m = {
23
23
  },
24
24
  ELSE: "{% else %}",
25
25
  END_IF: "{% endif %}"
26
- }, a = {
27
- ID: /recommendation-id="(.*?)"/gi,
28
- ATTRIBUTE_PARAGRAPH: /<p[^>]*?product-attr="(discount|omnibus_discount|omnibus_price)"[^>]*>[\S\s]*?<\/p>/gm,
29
- ATTRIBUTE_PARAGRAPH_START_TAG: /<p[^>]*?product-attr="(discount|omnibus_discount|omnibus_price)"[^>]*>/gm,
26
+ }, _ = {
27
+ ID: /ins-recommendation-v3-campaign-id="(.*?)"/gi,
28
+ ATTRIBUTE_PARAGRAPH: /<p[^>]*?product-attr="(discount|omnibus_discount|omnibus_price)">[\S\s]*?<\/p>/gm,
29
+ ATTRIBUTE_PARAGRAPH_START_TAG: /<p[^>]*?product-attr="(discount|omnibus_discount|omnibus_price)">/gm,
30
30
  COMPOSITION: /composition="true"/gm,
31
31
  CUSTOM_FIELD: /{{[0-9]+_[0-8]_(discount|omnibus_discount|omnibus_price)}}/gm,
32
32
  CUSTOM_FIELD_INDEXES_PART: /{{[0-9]+_[0-8]_/gm,
33
33
  CUSTOM_FIELD_NAME_PART: /_(discount|omnibus_discount|omnibus_price)}}/gm
34
- }, n = {
34
+ }, a = {
35
35
  PARAGRAPH_END_TAG: "</p>"
36
- }, o = {
36
+ }, n = {
37
37
  REGULAR_NAME_HEIGHT: ".ext-product-name.ins-vertical p { height:90px!important;",
38
38
  TRIMMED_NAME_HEIGHT: ".ext-product-name.ins-vertical p { height:18px!important;",
39
39
  ELLIPSIS: "text-overflow:ellipsis!important; white-space:nowrap!important;",
@@ -46,12 +46,11 @@ const e = 20, s = 320, t = "vertical", m = {
46
46
  };
47
47
  export {
48
48
  i as ATTRIBUTES,
49
- _ as CONDITIONS,
50
- o as CSS,
51
- m as DUMMY_IMAGE_MAPPINGS,
52
- e as DefaultPadding,
53
- n as HTML,
54
- s as MinDeviceViewport,
55
- a as REGEX,
56
- t as VerticalOrientation
49
+ m as CONDITIONS,
50
+ n as CSS,
51
+ t as DUMMY_IMAGE_MAPPINGS,
52
+ s as DefaultPadding,
53
+ a as HTML,
54
+ e as MinDeviceViewport,
55
+ _ as REGEX
57
56
  };
@@ -1,28 +1,18 @@
1
- var u = Object.defineProperty;
2
- var p = (r, i, t) => i in r ? u(r, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[i] = t;
3
- var g = (r, i, t) => p(r, typeof i != "symbol" ? i + "" : i, t);
4
- import { Block as f, BlockCompositionType as I, ModificationDescription as h } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
- import { RecommendationConfigService as s } from "./services/configService.js";
6
- import { useRecommendationExtensionStore as d } from "./store/recommendation.js";
7
- import { getDefaultTemplate as _ } from "./templates/grid/template.js";
8
- const k = "recommendation-block", c = "ins-recommendation-v3-block-v2", m = "recommendation-id";
9
- class b extends f {
1
+ import { Block as e, BlockCompositionType as t } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
+ import { getDefaultTemplate as o } from "./templates/blockTemplate.js";
3
+ const n = "recommendation-block";
4
+ class m extends e {
10
5
  constructor() {
11
6
  super();
12
- /**
13
- * Stores the ID generated in getTemplate() so onCreated() can reuse it.
14
- * This avoids generating a new (different) ID in onCreated().
15
- */
16
- g(this, "_pendingBlockId", null);
17
7
  }
18
8
  getId() {
19
- return k;
9
+ return n;
20
10
  }
21
11
  getIcon() {
22
12
  return "recommendation-icon";
23
13
  }
24
14
  getBlockCompositionType() {
25
- return I.CONTAINER;
15
+ return t.CONTAINER;
26
16
  }
27
17
  getName() {
28
18
  return this.api.translate("Recommendation Block");
@@ -30,122 +20,11 @@ class b extends f {
30
20
  getDescription() {
31
21
  return this.api.translate("Recommendation Block Title Description");
32
22
  }
33
- /**
34
- * Returns the template HTML for a new recommendation block.
35
- * Generates a unique recommendation ID and embeds the instance class
36
- * (ins-recommendation-v3-block-{id}) directly in the template HTML.
37
- * This is necessary because Stripo's Angular rendering manages the class
38
- * attribute and overwrites dynamically added classes via setAttribute.
39
- */
40
23
  getTemplate() {
41
- const t = this._generateNextId();
42
- return this._pendingBlockId = t, _(t);
43
- }
44
- /**
45
- * Called when a new block is dropped into the template
46
- *
47
- * Uses the ID from getTemplate() (which already embedded the instance class)
48
- * and assigns the recommendation-id attribute + initializes configuration.
49
- * @param node - The newly created block node
50
- */
51
- onCreated(t) {
52
- const e = this._pendingBlockId ?? this._generateNextId();
53
- this._pendingBlockId = null, this._assignRecommendationId(t, e), s.initializeConfig(this.api, t, { recommendationId: e }), d().setCurrentBlock(e);
54
- }
55
- /**
56
- * Called when the document changes or template is loaded
57
- *
58
- * Handles migration from legacy templates that don't have node config
59
- * and assigns recommendation-id to legacy blocks that lack one.
60
- * @param node - The block node that may need migration
61
- */
62
- onDocumentChanged(t) {
63
- if (!(!t || !("getNodeConfig" in t))) {
64
- if (!this._getRecommendationId(t)) {
65
- const e = this._generateNextId();
66
- this._assignRecommendationId(t, e), s.hasConfig(t) && s.updateConfig(
67
- this.api,
68
- t,
69
- { recommendationId: e },
70
- "Assign recommendation ID to legacy block"
71
- );
72
- }
73
- s.needsMigration(t) && this._migrateFromLegacy(t);
74
- }
75
- }
76
- /**
77
- * Called when a block is deleted from the template
78
- *
79
- * Cleans up the per-block state from the Pinia store.
80
- * @param node - The block node being deleted
81
- */
82
- onDelete(t) {
83
- const e = this._getRecommendationId(t);
84
- e && d().removeBlockState(e);
85
- }
86
- /**
87
- * Generates the next unique recommendation ID by scanning all existing blocks
88
- * in the document and finding the maximum existing ID + 1.
89
- */
90
- _generateNextId() {
91
- let t = 0;
92
- try {
93
- const e = this.api.getDocumentRoot();
94
- e && "querySelectorAll" in e && e.querySelectorAll(`.${c}`).forEach((o) => {
95
- if ("getAttribute" in o) {
96
- const a = o.getAttribute(m), l = a ? parseInt(a) : 0;
97
- l > t && (t = l);
98
- }
99
- });
100
- } catch {
101
- }
102
- return t + 1;
103
- }
104
- /**
105
- * Assigns a recommendation-id attribute to the block element.
106
- * The instance class (ins-recommendation-v3-block-{id}) is embedded in the template
107
- * HTML by getTemplate(), since Stripo's Angular rendering overwrites dynamically
108
- * added classes via setAttribute.
109
- */
110
- _assignRecommendationId(t, e) {
111
- const n = this._getBlockElement(t);
112
- if (!n)
113
- return;
114
- const o = this.api.getDocumentModifier();
115
- o.modifyHtml(n).setAttribute(m, e.toString()), o.apply(new h(`Assign recommendation ID ${e}`));
116
- }
117
- /**
118
- * Gets the recommendation-id from a block node
119
- */
120
- _getRecommendationId(t) {
121
- const e = this._getBlockElement(t);
122
- if (!e || !("getAttribute" in e))
123
- return null;
124
- const n = e.getAttribute(m);
125
- if (!n)
126
- return null;
127
- const o = parseInt(n);
128
- return Number.isNaN(o) ? null : o;
129
- }
130
- /**
131
- * Gets the block element (the element with BLOCK_CLASS)
132
- */
133
- _getBlockElement(t) {
134
- if ("getAttribute" in t) {
135
- const e = t.getAttribute("class");
136
- if (e && e.includes(c))
137
- return t;
138
- }
139
- return "querySelector" in t ? t.querySelector(`.${c}`) : null;
140
- }
141
- /**
142
- * Migrate configuration from legacy format
143
- */
144
- _migrateFromLegacy(t) {
145
- s.migrateFromDataAttributes(this.api, t);
24
+ return o();
146
25
  }
147
26
  }
148
27
  export {
149
- k as BLOCK_ID,
150
- b as RecommendationBlock
28
+ n as BLOCK_ID,
29
+ m as RecommendationBlock
151
30
  };
@@ -0,0 +1,187 @@
1
+ import { ModificationDescription as n } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
+ import { CommonControl as _ } from "../common-control.js";
3
+ import { ATTR_PRODUCT_IMAGE as m, ATTR_PRODUCT_NAME as y, ATTR_PRODUCT_PRICE as T, ATTR_PRODUCT_OLD_PRICE as h, ATTR_PRODUCT_OMNIBUS_PRICE as C, ATTR_PRODUCT_OMNIBUS_DISCOUNT as f, ATTR_PRODUCT_BUTTON as g } from "./constants.js";
4
+ const R = "ui-elements-recommendation-card-composition", l = ".recommendation-attribute-row", A = "tr.recommendation-product-row", c = "data-card-composition", a = "data-attribute-type", d = "data-visibility", s = [
5
+ { key: m, label: "Product Image", visible: !0 },
6
+ { key: y, label: "Product Name", visible: !0 },
7
+ { key: T, label: "Product Price", visible: !0 },
8
+ { key: h, label: "Product Original Price", visible: !0 },
9
+ { key: C, label: "Omnibus Price", visible: !1 },
10
+ { key: f, label: "Omnibus Discount", visible: !1 },
11
+ { key: g, label: "Product Button", visible: !0 }
12
+ ];
13
+ class N extends _ {
14
+ getId() {
15
+ return R;
16
+ }
17
+ getTemplate() {
18
+ const t = s.map((i) => ({
19
+ key: i.key,
20
+ label: i.label,
21
+ content: this._createItemContent(i.label, i.key)
22
+ }));
23
+ return `
24
+ <div class="container">
25
+ ${this._GuLabel({ text: "Card Element Order & Visibility" })}
26
+ ${this._GuOrderable("cardComposition", t)}
27
+ </div>
28
+ `;
29
+ }
30
+ onRender() {
31
+ this._initializeComposition(), this._registerValueChangeListeners();
32
+ }
33
+ onTemplateNodeUpdated(t) {
34
+ super.onTemplateNodeUpdated(t), this._initializeComposition();
35
+ }
36
+ /**
37
+ * Creates the HTML content for an orderable item with label and toggle
38
+ */
39
+ _createItemContent(t, i) {
40
+ return `
41
+ <div style="display: flex; align-items: center; justify-content: space-between;
42
+ padding: 8px; gap: 8px;">
43
+ <span style="flex: 1;">${t}</span>
44
+ ${this._GuToggle(`visibility_${i}`)}
45
+ </div>
46
+ `;
47
+ }
48
+ /**
49
+ * Registers event listeners for composition and visibility changes
50
+ */
51
+ _registerValueChangeListeners() {
52
+ this.api.onValueChanged("cardComposition", (t) => {
53
+ this._applyCompositionToBlock(t);
54
+ }), s.forEach((t) => {
55
+ this.api.onValueChanged(`visibility_${t.key}`, (i) => {
56
+ this._applyVisibilityToBlock(t.key, i);
57
+ });
58
+ });
59
+ }
60
+ /**
61
+ * Initializes composition order and visibility state from the current node
62
+ */
63
+ _initializeComposition() {
64
+ const t = this._readCompositionFromNode(), i = this._readVisibilityFromRows(), e = {
65
+ cardComposition: t,
66
+ ...this._buildVisibilityValues(i)
67
+ };
68
+ this.api.updateValues(e);
69
+ }
70
+ /**
71
+ * Reads composition order from node's data-card-composition attribute
72
+ * Falls back to default order if attribute is not present
73
+ */
74
+ _readCompositionFromNode() {
75
+ if (!this.currentNode || !("getAttribute" in this.currentNode))
76
+ return s.map((i) => i.key);
77
+ const t = this.currentNode.getAttribute(c);
78
+ return t ? t.split(",").filter(Boolean) : s.map((i) => i.key);
79
+ }
80
+ /**
81
+ * Builds visibility values object from the visibility map
82
+ */
83
+ _buildVisibilityValues(t) {
84
+ return s.reduce((i, e) => (i[`visibility_${e.key}`] = t[e.key] ?? !0, i), {});
85
+ }
86
+ /**
87
+ * Read visibility state from individual row elements' data-visibility attributes
88
+ * This ensures toggles reflect the actual DOM state
89
+ */
90
+ _readVisibilityFromRows() {
91
+ if (!this.currentNode)
92
+ return this._getDefaultVisibilities();
93
+ const t = Array.from(this.currentNode.querySelectorAll(l));
94
+ console.debug("_readVisibilityFromRows - found attribute rows:", t.length);
95
+ const i = this._extractVisibilityFromRows(t);
96
+ return this._mergeWithDefaults(i);
97
+ }
98
+ /**
99
+ * Returns default visibility values for all items
100
+ */
101
+ _getDefaultVisibilities() {
102
+ return s.reduce((t, i) => (t[i.key] = i.visible, t), {});
103
+ }
104
+ /**
105
+ * Extracts visibility values from DOM nodes
106
+ */
107
+ _extractVisibilityFromRows(t) {
108
+ const i = {};
109
+ return t.forEach((e) => {
110
+ if (!("getAttribute" in e))
111
+ return;
112
+ const o = e.getAttribute(a), r = e.getAttribute(d);
113
+ o && r !== null && (i[o] = this._parseVisibilityValue(r), console.debug(
114
+ `_readVisibilityFromRows - ${o}: ${i[o]} (raw: ${r})`
115
+ ));
116
+ }), i;
117
+ }
118
+ /**
119
+ * Parses visibility value from string to boolean
120
+ * Accepts "1", "true" as true, everything else as false
121
+ */
122
+ _parseVisibilityValue(t) {
123
+ return t === "1" || t === "true";
124
+ }
125
+ /**
126
+ * Merges extracted visibilities with default values for missing keys
127
+ */
128
+ _mergeWithDefaults(t) {
129
+ return s.forEach((i) => {
130
+ i.key in t || (t[i.key] = i.visible, console.debug(`_readVisibilityFromRows - ${i.key}: using default ${i.visible}`));
131
+ }), t;
132
+ }
133
+ /**
134
+ * Apply the reordered composition to the block's HTML structure
135
+ * Updates the data-card-composition attribute and reorders product attributes
136
+ */
137
+ _applyCompositionToBlock(t) {
138
+ if (console.debug("_applyCompositionToBlock - composition:", t), !this.currentNode) {
139
+ console.debug("_applyCompositionToBlock - no current node");
140
+ return;
141
+ }
142
+ this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(c, t.join(",")).apply(new n("Update card composition")), this._reorderProductAttributes(t);
143
+ }
144
+ /**
145
+ * Reorders attribute rows within each product row based on composition order
146
+ */
147
+ _reorderProductAttributes(t) {
148
+ if (!this.currentNode)
149
+ return;
150
+ const i = this.currentNode.querySelectorAll(A);
151
+ if (!(i != null && i.length))
152
+ return;
153
+ const e = this.api.getDocumentModifier();
154
+ i.forEach((o) => {
155
+ const r = this._buildCompositionHtml(o, t);
156
+ e.modifyHtml(o).setInnerHtml(r);
157
+ }), e.apply(new n("Reorder product attributes"));
158
+ }
159
+ /**
160
+ * Builds HTML string with attributes ordered according to composition
161
+ */
162
+ _buildCompositionHtml(t, i) {
163
+ return i.reduce((e, o) => {
164
+ const r = t.querySelector(`${l}[${a}="${o}"]`);
165
+ return r && "getOuterHTML" in r ? e + r.getOuterHTML() : e;
166
+ }, "");
167
+ }
168
+ /**
169
+ * Apply visibility changes to the block's HTML structure
170
+ * Updates display style and data-visibility attribute for all matching rows
171
+ */
172
+ _applyVisibilityToBlock(t, i) {
173
+ if (console.debug("_applyVisibilityToBlock", t, i), !this.currentNode)
174
+ return;
175
+ const e = this.currentNode.querySelectorAll(`${l}[${a}="${t}"]`);
176
+ if (!(e != null && e.length))
177
+ return;
178
+ const o = i ? "table-row" : "none", r = i ? "1" : "0", p = `Set ${t} visibility to ${i ? "visible" : "hidden"}`, u = this.api.getDocumentModifier();
179
+ e.forEach((b) => {
180
+ u.modifyHtml(b).setStyle("display", o).setAttribute(d, r);
181
+ }), u.apply(new n(p));
182
+ }
183
+ }
184
+ export {
185
+ R as COMPOSITION_CONTROL_BLOCK_ID,
186
+ N as RecommendationCardCompositionControl
187
+ };
@@ -0,0 +1,13 @@
1
+ const _ = "productImage", b = "productName", n = "productPrice", i = "productOldPrice", O = "productOmnibusPrice", T = "productOmnibusDiscount", t = "productButton";
2
+ var o = /* @__PURE__ */ ((c) => (c.BUTTON = "recommendation-block-button", c.NAME = "recommendation-block-name", c.PRICE = "recommendation-block-price", c.OLD_PRICE = "recommendation-block-old-price", c.OMNIBUS_PRICE = "recommendation-block-omnibus-price", c.OMNIBUS_DISCOUNT = "recommendation-block-omnibus-discount", c.IMAGE = "recommendation-block-image", c))(o || {}), r = /* @__PURE__ */ ((c) => (c.BUTTON_ALIGN = "recommendation-block-button-align-control", c.BUTTON_BORDER = "recommendation-block-button-border-control", c.BUTTON_BORDER_RADIUS = "recommendation-block-button-border-radius-control", c.BUTTON_COLOR = "recommendation-block-button-color-control", c.BUTTON_FIT_TO_CONTENT = "recommendation-block-button-fit-to-content-control", c.BUTTON_FONT_FAMILY = "recommendation-block-button-font-family-control", c.BUTTON_MARGINS = "recommendation-block-button-margins-control", c.BUTTON_PADDINGS = "recommendation-block-button-paddings-control", c.BUTTON_TEXT = "recommendation-block-button-text-control", c.BUTTON_TEXT_SIZE = "recommendation-block-button-text-size-control", c.BUTTON_TEXT_STYLE_AND_FONT_COLOR = "recommendation-block-button-text-style-and-font-color-control", c.NAME_ALIGN = "recommendation-block-name-align-control", c.NAME_BACKGROUND = "recommendation-block-name-background-control", c.NAME_COLOR = "recommendation-block-name-color-control", c.NAME_FONT_FAMILY = "recommendation-block-name-font-family-control", c.NAME_PADDINGS = "recommendation-block-name-paddings-control", c.NAME_SIZE = "recommendation-block-name-size-control", c.NAME_STYLE = "recommendation-block-name-style-control", c.NAME_TEXT_TRIM = "recommendation-block-name-text-trim-control", c.PRICE_ALIGN = "recommendation-block-price-align-control", c.PRICE_BACKGROUND = "recommendation-block-price-background-control", c.PRICE_COLOR = "recommendation-block-price-color-control", c.PRICE_FONT_FAMILY = "recommendation-block-price-font-family-control", c.PRICE_PADDINGS = "recommendation-block-price-paddings-control", c.PRICE_SIZE = "recommendation-block-price-size-control", c.PRICE_STYLE = "recommendation-block-price-style-control", c.OLD_PRICE_ALIGN = "recommendation-block-old-price-align-control", c.OLD_PRICE_BACKGROUND = "recommendation-block-old-price-background-control", c.OLD_PRICE_COLOR = "recommendation-block-old-price-color-control", c.OLD_PRICE_FONT_FAMILY = "recommendation-block-old-price-font-family-control", c.OLD_PRICE_PADDINGS = "recommendation-block-old-price-paddings-control", c.OLD_PRICE_SIZE = "recommendation-block-old-price-size-control", c.OLD_PRICE_STYLE = "recommendation-block-old-price-style-control", c.OMNIBUS_PRICE_ALIGN = "recommendation-block-omnibus-price-align-control", c.OMNIBUS_PRICE_BACKGROUND = "recommendation-block-omnibus-price-background-control", c.OMNIBUS_PRICE_COLOR = "recommendation-block-omnibus-price-color-control", c.OMNIBUS_PRICE_FONT_FAMILY = "recommendation-block-omnibus-price-font-family-control", c.OMNIBUS_PRICE_PADDINGS = "recommendation-block-omnibus-price-paddings-control", c.OMNIBUS_PRICE_SIZE = "recommendation-block-omnibus-price-size-control", c.OMNIBUS_PRICE_STYLE = "recommendation-block-omnibus-price-style-control", c.OMNIBUS_PRICE_TEXT_BEFORE = "recommendation-block-omnibus-price-text-before-control", c.OMNIBUS_PRICE_TEXT_AFTER = "recommendation-block-omnibus-price-text-after-control", c.OMNIBUS_DISCOUNT_ALIGN = "recommendation-block-omnibus-discount-align-control", c.OMNIBUS_DISCOUNT_BACKGROUND = "recommendation-block-omnibus-discount-background-control", c.OMNIBUS_DISCOUNT_COLOR = "recommendation-block-omnibus-discount-color-control", c.OMNIBUS_DISCOUNT_FONT_FAMILY = "recommendation-block-omnibus-discount-font-family-control", c.OMNIBUS_DISCOUNT_PADDINGS = "recommendation-block-omnibus-discount-paddings-control", c.OMNIBUS_DISCOUNT_SIZE = "recommendation-block-omnibus-discount-size-control", c.OMNIBUS_DISCOUNT_STYLE = "recommendation-block-omnibus-discount-style-control", c.OMNIBUS_DISCOUNT_TEXT_BEFORE = "recommendation-block-omnibus-discount-text-before-control", c.OMNIBUS_DISCOUNT_TEXT_AFTER = "recommendation-block-omnibus-discount-text-after-control", c.IMAGE_SIZE = "recommendation-block-image-size-control", c.IMAGE_MARGINS = "recommendation-block-image-margins-control", c))(r || {});
3
+ export {
4
+ t as ATTR_PRODUCT_BUTTON,
5
+ _ as ATTR_PRODUCT_IMAGE,
6
+ b as ATTR_PRODUCT_NAME,
7
+ i as ATTR_PRODUCT_OLD_PRICE,
8
+ T as ATTR_PRODUCT_OMNIBUS_DISCOUNT,
9
+ O as ATTR_PRODUCT_OMNIBUS_PRICE,
10
+ n as ATTR_PRODUCT_PRICE,
11
+ o as RecommendationBlockId,
12
+ r as RecommendationControlId
13
+ };