@useinsider/guido 3.2.0-beta.87303ed → 3.2.0-beta.895a145

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 (73) hide show
  1. package/README.md +92 -0
  2. package/dist/@types/config/schemas.js +150 -94
  3. package/dist/components/Guido.vue.js +1 -1
  4. package/dist/components/Guido.vue2.js +88 -87
  5. package/dist/composables/useRecommendation.js +46 -26
  6. package/dist/config/compiler/utils/recommendationCompilerUtils.js +104 -71
  7. package/dist/config/migrator/index.js +9 -9
  8. package/dist/config/migrator/recommendation/compositionMapper.js +98 -0
  9. package/dist/config/migrator/recommendation/extractors.js +27 -0
  10. package/dist/config/migrator/recommendation/htmlBuilder.js +496 -0
  11. package/dist/config/migrator/recommendation/parseLegacyConfig.js +33 -0
  12. package/dist/config/migrator/recommendation/settingsMapper.js +70 -0
  13. package/dist/config/migrator/recommendation/themeMapper.js +93 -0
  14. package/dist/config/migrator/recommendationMigrator.js +74 -290
  15. package/dist/enums/extensions/recommendationBlock.js +43 -96
  16. package/dist/enums/unsubscribe.js +24 -25
  17. package/dist/extensions/Blocks/Checkbox/control.js +23 -23
  18. package/dist/extensions/Blocks/RadioButton/control.js +15 -15
  19. package/dist/extensions/Blocks/Recommendation/block.js +35 -32
  20. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +5 -5
  21. package/dist/extensions/Blocks/Recommendation/controls/main/algorithm.js +25 -24
  22. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +228 -181
  23. package/dist/extensions/Blocks/Recommendation/services/configService.js +65 -29
  24. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +130 -90
  25. package/dist/extensions/Blocks/Recommendation/templates/grid/elementRenderer.js +19 -10
  26. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +8 -8
  27. package/dist/extensions/Blocks/Recommendation/templates/list/elementRenderer.js +25 -15
  28. package/dist/extensions/Blocks/Recommendation/templates/utils.js +1 -1
  29. package/dist/extensions/Blocks/Recommendation/utils/legacyStrategyMap.js +21 -0
  30. package/dist/extensions/Blocks/Recommendation/utils/preserveTextStyles.js +13 -22
  31. package/dist/guido.css +1 -1
  32. package/dist/node_modules/valibot/dist/index.js +450 -235
  33. package/dist/src/@types/config/defaults.d.ts +5 -1
  34. package/dist/src/@types/config/index.d.ts +3 -3
  35. package/dist/src/@types/config/schemas.d.ts +213 -0
  36. package/dist/src/@types/config/types.d.ts +9 -1
  37. package/dist/src/components/wrappers/WpModal.vue.d.ts +1 -1
  38. package/dist/src/composables/useConfig.d.ts +56 -0
  39. package/dist/src/composables/useRecommendation.d.ts +10 -1
  40. package/dist/src/composables/useRecommendation.test.d.ts +1 -0
  41. package/dist/src/config/migrator/index.d.ts +2 -1
  42. package/dist/src/config/migrator/recommendation/compositionMapper.d.ts +2 -0
  43. package/dist/src/config/migrator/recommendation/compositionMapper.test.d.ts +1 -0
  44. package/dist/src/config/migrator/recommendation/extractors.d.ts +7 -0
  45. package/dist/src/config/migrator/recommendation/extractors.test.d.ts +1 -0
  46. package/dist/src/config/migrator/recommendation/htmlBuilder.d.ts +11 -0
  47. package/dist/src/config/migrator/recommendation/parseLegacyConfig.d.ts +15 -0
  48. package/dist/src/config/migrator/recommendation/parseLegacyConfig.test.d.ts +1 -0
  49. package/dist/src/config/migrator/recommendation/settingsMapper.d.ts +7 -0
  50. package/dist/src/config/migrator/recommendation/settingsMapper.test.d.ts +1 -0
  51. package/dist/src/config/migrator/recommendation/themeMapper.d.ts +5 -0
  52. package/dist/src/config/migrator/recommendation/themeMapper.test.d.ts +1 -0
  53. package/dist/src/config/migrator/recommendation/types.d.ts +205 -0
  54. package/dist/src/config/migrator/recommendationMigrator.d.ts +13 -1
  55. package/dist/src/config/migrator/recommendationMigrator.test.d.ts +1 -0
  56. package/dist/src/enums/extensions/recommendationBlock.d.ts +1 -5
  57. package/dist/src/enums/unsubscribe.d.ts +3 -8
  58. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.test.d.ts +1 -0
  59. package/dist/src/extensions/Blocks/Recommendation/services/configService.d.ts +10 -0
  60. package/dist/src/extensions/Blocks/Recommendation/services/configService.test.d.ts +1 -0
  61. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +34 -0
  62. package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +1 -1
  63. package/dist/src/extensions/Blocks/Recommendation/utils/legacyStrategyMap.d.ts +21 -0
  64. package/dist/src/extensions/Blocks/Recommendation/utils/legacyStrategyMap.test.d.ts +1 -0
  65. package/dist/src/extensions/Blocks/Recommendation/utils/preserveTextStyles.d.ts +0 -3
  66. package/dist/src/library.d.ts +1 -1
  67. package/dist/src/stores/config.d.ts +504 -0
  68. package/dist/src/utils/htmlEscape.d.ts +5 -0
  69. package/dist/src/utils/htmlEscape.test.d.ts +1 -0
  70. package/dist/utils/htmlEscape.js +13 -0
  71. package/dist/utils/templatePreparation.js +72 -32
  72. package/package.json +5 -1
  73. package/dist/extensions/Blocks/Recommendation/templates/grid/migration.js +0 -251
@@ -1,53 +1,93 @@
1
1
  import { useActionsApi as T } from "../composables/useActionsApi.js";
2
- import { useHtmlCompiler as P } from "../composables/useHtmlCompiler.js";
3
- import { useRecommendationExtensionStore as A } from "../extensions/Blocks/Recommendation/store/recommendation.js";
4
- import { DATA_ATTRIBUTES as l } from "../extensions/Blocks/Unsubscribe/utils/constants.js";
5
- import { parsePageList as h } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
6
- import { useDynamicContentStore as C } from "../stores/dynamic-content.js";
7
- import { useUnsubscribeStore as D } from "../stores/unsubscribe.js";
8
- function x(i, e) {
9
- const r = new DOMParser().parseFromString(i, "text/html").querySelectorAll(`[${l.PAGE_LIST}]`), n = [];
10
- return r.forEach((t) => {
11
- const o = t.getAttribute(l.PAGE_LIST);
12
- o && n.push(...h(o));
13
- }), e.filter((t) => n.includes(t));
2
+ import { useHtmlCompiler as C } from "../composables/useHtmlCompiler.js";
3
+ import { DEFAULT_CURRENCY as l, DEFAULT_NODE_CONFIG as a } from "../extensions/Blocks/Recommendation/constants/defaultConfig.js";
4
+ import { useRecommendationExtensionStore as b } from "../extensions/Blocks/Recommendation/store/recommendation.js";
5
+ import { DATA_ATTRIBUTES as y } from "../extensions/Blocks/Unsubscribe/utils/constants.js";
6
+ import { parsePageList as P } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
7
+ import { useDynamicContentStore as D } from "../stores/dynamic-content.js";
8
+ import { useUnsubscribeStore as E } from "../stores/unsubscribe.js";
9
+ function U(i, r) {
10
+ const s = new DOMParser().parseFromString(i, "text/html").querySelectorAll(`[${y.PAGE_LIST}]`), c = [];
11
+ return s.forEach((t) => {
12
+ const o = t.getAttribute(y.PAGE_LIST);
13
+ o && c.push(...P(o));
14
+ }), r.filter((t) => c.includes(t));
14
15
  }
15
- const I = () => {
16
- const i = C(), e = D(), { getCompiledEmail: a, getTemplateData: m } = T(), { compileHtml: r } = P();
16
+ function F(i) {
17
+ const m = new DOMParser().parseFromString(i, "text/html").querySelectorAll(".recommendation-block-v2");
18
+ if (m.length === 0)
19
+ return;
20
+ const d = b();
21
+ m.forEach((s) => {
22
+ var g, f, u, n, S;
23
+ const c = s.getAttribute("recommendation-id"), t = c ? Number(c) : NaN;
24
+ if (!Number.isFinite(t))
25
+ return;
26
+ const o = s.getAttribute("esd-ext-config");
27
+ if (!o)
28
+ return;
29
+ let e;
30
+ try {
31
+ e = JSON.parse(o);
32
+ } catch {
33
+ return;
34
+ }
35
+ if (!e || typeof e != "object" || Array.isArray(e))
36
+ return;
37
+ const p = {
38
+ strategy: e.strategy ?? a.strategy,
39
+ language: e.language ?? a.language,
40
+ size: e.size ?? a.size,
41
+ // Spread the default arrays so each block gets a fresh reference
42
+ // instead of sharing the singleton in DEFAULT_NODE_CONFIG.
43
+ productIds: e.productIds ?? [...a.productIds],
44
+ filters: e.filters ?? [...a.filters],
45
+ shuffleProducts: e.shuffleProducts ?? a.shuffleProducts,
46
+ currencyCode: ((g = e.currency) == null ? void 0 : g.code) ?? l.code,
47
+ currencyAlignment: ((f = e.currency) == null ? void 0 : f.alignment) ?? l.alignment,
48
+ currencyDecimalCount: ((u = e.currency) == null ? void 0 : u.decimalCount) ?? l.decimalCount,
49
+ currencyDecimalSeparator: ((n = e.currency) == null ? void 0 : n.decimalSeparator) ?? l.decimalSeparator,
50
+ currencyThousandSeparator: ((S = e.currency) == null ? void 0 : S.thousandSeparator) ?? l.thousandSeparator
51
+ };
52
+ d.seedBlockUrlConfig(t, p);
53
+ });
54
+ }
55
+ const _ = () => {
56
+ const i = D(), r = E(), { getCompiledEmail: m, getTemplateData: d } = T(), { compileHtml: s } = C();
17
57
  return {
18
58
  prepareTemplateDetails: async () => {
19
- const { html: t, ampHtml: o = "", ampErrors: p = [] } = await a({
59
+ const { html: t, ampHtml: o = "", ampErrors: e = [] } = await m({
20
60
  minimize: !0,
21
61
  resetDataSavedFlag: !1
22
- }), { html: u, css: d, syncModulesIds: g = [] } = await m();
23
- e.selectedUnsubscribePages.length && await e.fetchTemplates();
24
- const { compiledHtml: c, stats: s, appliedRules: S } = r(t), b = i.getSelectedDynamicContentList, f = A();
62
+ }), { html: p, css: g, syncModulesIds: f = [] } = await d();
63
+ r.selectedUnsubscribePages.length && await r.fetchTemplates(), F(p);
64
+ const { compiledHtml: u, stats: n, appliedRules: S } = s(t), h = i.getSelectedDynamicContentList, A = b();
25
65
  return console.debug("HTML Compilation Stats:", {
26
- originalSize: s.originalSize,
27
- compiledSize: s.compiledSize,
28
- reduction: `${s.reductionPercentage.toFixed(2)}%`,
66
+ originalSize: n.originalSize,
67
+ compiledSize: n.compiledSize,
68
+ reduction: `${n.reductionPercentage.toFixed(2)}%`,
29
69
  appliedRules: S,
30
- executionTime: `${s.executionTime.toFixed(2)}ms`
70
+ executionTime: `${n.executionTime.toFixed(2)}ms`
31
71
  }), {
32
- dynamicContentList: b,
33
- compiledHtml: c,
34
- rawHtml: u,
35
- css: d,
72
+ dynamicContentList: h,
73
+ compiledHtml: u,
74
+ rawHtml: p,
75
+ css: g,
36
76
  ampHtml: o,
37
- ampErrors: p,
38
- modules: g.map(Number),
77
+ ampErrors: e,
78
+ modules: f.map(Number),
39
79
  recommendation: {
40
- campaignUrls: f.recommendationCampaignUrls,
80
+ campaignUrls: A.recommendationCampaignUrls,
41
81
  configs: {}
42
82
  },
43
83
  unsubscribe: {
44
- status: e.unsubscribePagesStatus,
45
- config: x(c, e.selectedUnsubscribePages)
84
+ status: r.unsubscribePagesStatus,
85
+ config: U(u, r.selectedUnsubscribePages)
46
86
  }
47
87
  };
48
88
  }
49
89
  };
50
90
  };
51
91
  export {
52
- I as useTemplatePreparation
92
+ _ as useTemplatePreparation
53
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.2.0-beta.87303ed",
3
+ "version": "3.2.0-beta.895a145",
4
4
  "description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
5
5
  "main": "./dist/guido.umd.cjs",
6
6
  "module": "./dist/library.js",
@@ -24,6 +24,8 @@
24
24
  "lint": "NODE_OPTIONS=--max-old-space-size=2048 eslint ./ && bun run type-check",
25
25
  "lint:fix": "NODE_OPTIONS=--max-old-space-size=2048 eslint --fix ./",
26
26
  "type-check": "vue-tsc --noEmit --project tsconfig.config.json && vue-tsc --noEmit --project tsconfig.app.json",
27
+ "test": "vitest run",
28
+ "test:watch": "vitest",
27
29
  "test:visual-update": "npx playwright test --update-snapshots --reporter html",
28
30
  "prepare": "husky",
29
31
  "preinstall": "rm -rf ./node_modules/.vite"
@@ -69,12 +71,14 @@
69
71
  "eslint-plugin-vue": "10.1.0",
70
72
  "eslint-plugin-vue-scoped-css": "2.6.1",
71
73
  "globals": "16.0.0",
74
+ "happy-dom": "15.11.7",
72
75
  "husky": "9.1.7",
73
76
  "msw": "2.10.3",
74
77
  "sass": "1.69.7",
75
78
  "typescript": "5.5.4",
76
79
  "typescript-eslint": "8.26.0",
77
80
  "vite-plugin-dts": "4.5.4",
81
+ "vitest": "2.1.9",
78
82
  "vue-tsc": "2.2.10"
79
83
  },
80
84
  "overrides": {
@@ -1,251 +0,0 @@
1
- import { ATTR_PRODUCT_BUTTON as s, ATTR_PRODUCT_OMNIBUS_DISCOUNT as d, ATTR_PRODUCT_OMNIBUS_PRICE as c, ATTR_PRODUCT_OLD_PRICE as o, ATTR_PRODUCT_PRICE as i, ATTR_PRODUCT_NAME as r, ATTR_PRODUCT_IMAGE as p } from "../../constants/selectors.js";
2
- import { prepareGridProductRows as b } from "./template.js";
3
- const u = `
4
- <td
5
- align="left"
6
- esd-extension-block-id="recommendation-block"
7
- esd-handler-name="esd-extension-RecommendationBlock"
8
- class="recommendation-block-v2 esd-block-recommendation-v3-block esd-extension-block es-p20"
9
- >
10
- <table width="100%" cellpadding="0" cellspacing="0" border="0">
11
- <tr>
12
- <td align="center">
13
- <table
14
- class="container"
15
- width="100%"
16
- cellpadding="0"
17
- cellspacing="0"
18
- border="0">
19
- <tbody>
20
- <tr>
21
- <td>
22
- <table
23
- width="100%"
24
- cellpadding="0"
25
- cellspacing="0"
26
- border="0">
27
- <tbody>
28
- <tr>
29
- {-{-TITLE-}-}
30
- </tr>
31
- </tbody>
32
- </table>
33
- </td>
34
- </tr>
35
- <tr>
36
- <td class="spacer" style="height: 20px;"></td>
37
- </tr>
38
- <tr>
39
- <td>
40
- <table
41
- class="ins-recommendation-product-container"
42
- width="100%"
43
- cellpadding="0"
44
- cellspacing="0"
45
- border="0"
46
- >
47
- {-{-PRODUCT_ROWS-}-}
48
- </table>
49
- </td>
50
- </tr>
51
- </tbody>
52
- </table>
53
- </td>
54
- </tr>
55
- </table>
56
- </td>
57
- `, e = "0 5px", a = "attribute-cell", g = {
58
- [p]: (t) => `
59
- <td class="${a}" style="padding: ${e}; height: 100%;" valign="top">
60
- <table
61
- class="product-card-segment"
62
- width="100%"
63
- height="100%"
64
- cellpadding="0"
65
- cellspacing="0"
66
- border="0">
67
- <tr>
68
- <td
69
- class="esd-block-image product-image"
70
- esd-extension-block-id="recommendation-block-image"
71
- align="center"
72
- style="font-size: 0px;">
73
- <a target="_blank" href="${t.url}">
74
- <img
75
- src="${t.image_url}"
76
- alt="${t.name}"
77
- width="120"
78
- style="display: block; max-width: 100%; height: auto;"
79
- class="adapt-img">
80
- </a>
81
- </td>
82
- </tr>
83
- </table>
84
- </td>
85
- `,
86
- [r]: (t) => `
87
- <td class="${a}" style="padding: ${e}; height: 100%;" valign="top">
88
- <table
89
- class="product-card-segment"
90
- width="100%"
91
- height="100%"
92
- cellpadding="0"
93
- cellspacing="0"
94
- border="0">
95
- <tr>
96
- <td
97
- class="esd-block-text product-name"
98
- esd-extension-block-id="recommendation-block-name"
99
- align="center">
100
- <p
101
- path="1"
102
- contenteditable="false"
103
- style="font-size: 16px; color: #333333; font-weight: 600; text-align: center;">
104
- <strong path="1,0">${t.name}</strong>
105
- </p>
106
- </td>
107
- </tr>
108
- </table>
109
- </td>
110
- `,
111
- [i]: () => `
112
- <td class="${a}" style="padding: ${e}; height: 100%;" valign="top">
113
- <table
114
- class="product-card-segment"
115
- width="100%"
116
- height="100%"
117
- cellpadding="0"
118
- cellspacing="0"
119
- border="0">
120
- <tr>
121
- <td
122
- class="esd-block-text product-price"
123
- esd-extension-block-id="recommendation-block-price"
124
- align="center">
125
- <p
126
- path="1"
127
- contenteditable="false"
128
- style="font-size: 16px; color: #333333; font-weight: bold; text-align: center;">
129
- <strong path="1,0">18,00 TRY</strong>
130
- </p>
131
- </td>
132
- </tr>
133
- </table>
134
- </td>
135
- `,
136
- [o]: () => `
137
- <td class="${a}" style="padding: ${e}; height: 100%;" valign="top">
138
- <table
139
- class="product-card-segment"
140
- width="100%"
141
- height="100%"
142
- cellpadding="0"
143
- cellspacing="0"
144
- border="0">
145
- <tr>
146
- <td
147
- class="esd-block-text product-old-price"
148
- esd-extension-block-id="recommendation-block-old-price"
149
- align="center">
150
- <p
151
- path="1"
152
- contenteditable="false"
153
- style="font-size: 14px; color: #999999; text-decoration: line-through; text-align: center;">
154
- <s path="1,0">20,00 TRY</s>
155
- </p>
156
- </td>
157
- </tr>
158
- </table>
159
- </td>
160
- `,
161
- [c]: () => `
162
- <td class="${a}" style="padding: ${e}; height: 100%;" valign="top">
163
- <table
164
- class="product-card-segment"
165
- width="100%"
166
- height="100%"
167
- cellpadding="0"
168
- cellspacing="0"
169
- border="0">
170
- <tr>
171
- <td
172
- class="esd-block-text product-omnibus-price"
173
- esd-extension-block-id="recommendation-block-omnibus-price"
174
- data-text-before="Lowest 30-day price: "
175
- data-text-after=""
176
- align="center">
177
- <p
178
- path="1"
179
- contenteditable="false"
180
- style="font-size: 14px; color: #666666; text-align: center;"><span
181
- class="omnibus-text-before">Lowest 30-day price: </span><span
182
- class="omnibus-price-value">17,00 TRY</span><span
183
- class="omnibus-text-after"></span></p>
184
- </td>
185
- </tr>
186
- </table>
187
- </td>
188
- `,
189
- [d]: () => `
190
- <td class="${a}" style="padding: ${e}; height: 100%;" valign="top">
191
- <table
192
- class="product-card-segment"
193
- width="100%"
194
- height="100%"
195
- cellpadding="0"
196
- cellspacing="0"
197
- border="0">
198
- <tr>
199
- <td
200
- class="esd-block-text product-omnibus-discount"
201
- esd-extension-block-id="recommendation-block-omnibus-discount"
202
- data-text-before=""
203
- data-text-after=""
204
- align="center">
205
- <p
206
- path="1"
207
- contenteditable="false"
208
- style="font-size: 14px; color: #666666; text-align: center;"><span
209
- class="omnibus-text-before"></span><span
210
- class="omnibus-discount-value">-6%</span><span
211
- class="omnibus-text-after"></span></p>
212
- </td>
213
- </tr>
214
- </table>
215
- </td>
216
- `,
217
- [s]: (t) => `
218
- <td class="${a}" style="padding: ${e}; height: 100%;" valign="top">
219
- <table
220
- class="product-card-segment"
221
- width="100%"
222
- height="100%"
223
- cellpadding="0"
224
- cellspacing="0"
225
- border="0">
226
- <tr>
227
- <td
228
- class="esd-block-button product-button"
229
- esd-extension-block-id="recommendation-block-button"
230
- align="center">
231
- <span class="es-button-border" style="display: block;">
232
- <a
233
- href="${t.url}"
234
- target="_blank"
235
- class="es-button">
236
- {-{-PRODUCT_BUTTON_TEXT-}-}
237
- </a>
238
- </span>
239
- </td>
240
- </tr>
241
- </table>
242
- </td>
243
- `
244
- };
245
- function T(t, l, n) {
246
- return b(t, l, g, n);
247
- }
248
- export {
249
- u as default,
250
- T as prepareProductRows
251
- };