@useinsider/guido 3.21.1 → 3.21.2-beta.cfc5be2

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 (64) hide show
  1. package/README.md +1 -0
  2. package/dist/@types/config/schemas.js +41 -39
  3. package/dist/@types/display-condition.js +25 -0
  4. package/dist/components/Guido.vue.js +6 -6
  5. package/dist/components/Guido.vue2.js +81 -79
  6. package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +20 -0
  7. package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +30 -0
  8. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +30 -0
  9. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +71 -0
  10. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +34 -0
  11. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +57 -0
  12. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +17 -0
  13. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +22 -0
  14. package/dist/composables/useBlocksConfig.js +32 -24
  15. package/dist/composables/useDisplayConditions.js +102 -0
  16. package/dist/config/compiler/utils/recommendationCompilerUtils.js +55 -53
  17. package/dist/enums/academy.js +1 -0
  18. package/dist/enums/display-condition.js +12 -0
  19. package/dist/extensions/Blocks/Recommendation/block.js +52 -37
  20. package/dist/extensions/Blocks/Recommendation/controls/image/index.js +76 -16
  21. package/dist/extensions/Blocks/Recommendation/utils/captureStyleTemplates.js +16 -15
  22. package/dist/extensions/DisplayConditions/bridge.js +17 -0
  23. package/dist/extensions/DisplayConditions/constants.js +17 -0
  24. package/dist/extensions/DisplayConditions/control.js +178 -0
  25. package/dist/extensions/DisplayConditions/display-conditions.css.js +201 -0
  26. package/dist/extensions/DisplayConditions/extension.js +28 -0
  27. package/dist/extensions/DisplayConditions/iconsRegistry.js +20 -0
  28. package/dist/extensions/DisplayConditions/library.js +27 -0
  29. package/dist/extensions/DisplayConditions/settingsPanel.js +17 -0
  30. package/dist/guido.css +1 -1
  31. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +93 -92
  32. package/dist/node_modules/valibot/dist/index.js +297 -261
  33. package/dist/services/displayConditionApi.js +39 -0
  34. package/dist/src/@types/config/schemas.d.ts +4 -0
  35. package/dist/src/@types/display-condition.d.ts +59 -0
  36. package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +43 -0
  37. package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +2 -0
  38. package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +2 -0
  39. package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +2 -0
  40. package/dist/src/composables/useConfig.d.ts +2 -0
  41. package/dist/src/composables/useDisplayConditions.d.ts +16 -0
  42. package/dist/src/enums/academy.d.ts +1 -0
  43. package/dist/src/enums/display-condition.d.ts +15 -0
  44. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +2 -0
  45. package/dist/src/extensions/Blocks/Recommendation/controls/image/index.d.ts +31 -17
  46. package/dist/src/extensions/DisplayConditions/bridge.d.ts +6 -0
  47. package/dist/src/extensions/DisplayConditions/constants.d.ts +14 -0
  48. package/dist/src/extensions/DisplayConditions/control.d.ts +23 -0
  49. package/dist/src/extensions/DisplayConditions/extension.d.ts +2 -0
  50. package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +4 -0
  51. package/dist/src/extensions/DisplayConditions/library.d.ts +8 -0
  52. package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +5 -0
  53. package/dist/src/mock/api/display-conditions.d.ts +2 -0
  54. package/dist/src/services/displayConditionApi.d.ts +8 -0
  55. package/dist/src/stores/config.d.ts +166 -0
  56. package/dist/src/stores/display-condition.d.ts +81 -0
  57. package/dist/src/utils/displayCondition.d.ts +10 -0
  58. package/dist/src/utils/protectTableText.d.ts +2 -0
  59. package/dist/stores/config.js +13 -6
  60. package/dist/stores/display-condition.js +28 -0
  61. package/dist/utils/displayCondition.js +26 -0
  62. package/dist/utils/pairProductVariables.js +15 -14
  63. package/dist/utils/protectTableText.js +22 -0
  64. package/package.json +1 -1
@@ -1,23 +1,24 @@
1
- var A = Object.defineProperty;
2
- var D = (m, c, e) => c in m ? A(m, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : m[c] = e;
3
- var u = (m, c, e) => D(m, typeof c != "symbol" ? c + "" : c, e);
1
+ var b = Object.defineProperty;
2
+ var A = (m, c, e) => c in m ? b(m, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : m[c] = e;
3
+ var u = (m, c, e) => A(m, typeof c != "symbol" ? c + "" : c, e);
4
4
  import { useConfig as g } from "../../../composables/useConfig.js";
5
- import { BlockId as b } from "../../../enums/block.js";
5
+ import { BlockId as D } from "../../../enums/block.js";
6
6
  import { getMigrationBannerHtml as E } from "../../../utils/migrationBannerHtml.js";
7
7
  import { Block as S, BlockCompositionType as v, ModificationDescription as _ } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
8
- import { CURRENT_CONFIG_VERSION as N, PRE_RRS_CONFIG_VERSION as w } from "./constants/defaultConfig.js";
8
+ import { CURRENT_CONFIG_VERSION as N, PRE_RRS_CONFIG_VERSION as M } from "./constants/defaultConfig.js";
9
9
  import { RECOMMENDATION_ID_ATTR as f } from "./constants/selectors.js";
10
- import { regenerateMobileProductRows as M } from "./controls/main/utils.js";
11
- import { ensureMobileCssRulesExist as I, setMobileLayoutOptOut as R, hasMobileLayoutOptOut as O } from "./controls/mobileLayout/cssRules.js";
10
+ import { ensureMobileFitRule as w, syncHeightBound as O } from "./controls/image/index.js";
11
+ import { regenerateMobileProductRows as H } from "./controls/main/utils.js";
12
+ import { ensureMobileCssRulesExist as I, setMobileLayoutOptOut as R, hasMobileLayoutOptOut as T } from "./controls/mobileLayout/cssRules.js";
12
13
  import { RecommendationConfigService as a } from "./services/configService.js";
13
14
  import { useRecommendationExtensionStore as p } from "./store/recommendation.js";
14
- import { getDefaultTemplate as T } from "./templates/grid/template.js";
15
- import { useRecommendationBlockWarning as x } from "./useRecommendationBlockWarning.js";
16
- import { registerNodeConfigWriter as k, readBlockNodeConfigs as $ } from "./utils/nodeConfigWriter.js";
17
- import { refreshArrivedStrategyBlocks as q, resolveSourceConfig as H, refreshDuplicatedStrategyBlocks as F } from "./utils/strategyCommit.js";
18
- const y = b.Recommendation, d = "recommendation-block-v2", C = "hide-price";
15
+ import { getDefaultTemplate as x } from "./templates/grid/template.js";
16
+ import { useRecommendationBlockWarning as F } from "./useRecommendationBlockWarning.js";
17
+ import { registerNodeConfigWriter as y, readBlockNodeConfigs as $ } from "./utils/nodeConfigWriter.js";
18
+ import { refreshArrivedStrategyBlocks as q, resolveSourceConfig as L, refreshDuplicatedStrategyBlocks as P } from "./utils/strategyCommit.js";
19
+ const k = D.Recommendation, h = "recommendation-block-v2", C = "hide-price";
19
20
  let B = !1;
20
- class te extends S {
21
+ class se extends S {
21
22
  constructor() {
22
23
  super();
23
24
  /**
@@ -34,7 +35,7 @@ class te extends S {
34
35
  u(this, "_refreshClaims", /* @__PURE__ */ new Map());
35
36
  }
36
37
  getId() {
37
- return y;
38
+ return k;
38
39
  }
39
40
  getIcon() {
40
41
  return "recommendation-icon";
@@ -52,7 +53,7 @@ class te extends S {
52
53
  }
53
54
  getSettingsPanelTitleHtml() {
54
55
  return E(
55
- y,
56
+ k,
56
57
  this.api.translate("Recommendation Block"),
57
58
  this.api.translate("This block is switched from the Old Version to the New Version. We recommend you check the Recommendation block and test your message to ensure it works properly.")
58
59
  );
@@ -75,7 +76,7 @@ class te extends S {
75
76
  */
76
77
  getTemplate() {
77
78
  const e = this._generateNextId();
78
- return this._pendingBlockId = e, T(e);
79
+ return this._pendingBlockId = e, x(e);
79
80
  }
80
81
  /**
81
82
  * Called when a new block is dropped into the template
@@ -87,7 +88,7 @@ class te extends S {
87
88
  onCreated(e) {
88
89
  const t = this._getRecommendationId(e);
89
90
  if (t !== null && t > 0) {
90
- if (this._pendingBlockId = null, this._detectDuplicate(t)) {
91
+ if (this._pendingBlockId = null, this._ensureMobileFitRule(e), this._detectDuplicate(t)) {
91
92
  this._handleDuplicate(e, t), this._scheduleArrivalReset(e);
92
93
  return;
93
94
  }
@@ -109,7 +110,7 @@ class te extends S {
109
110
  e,
110
111
  {
111
112
  recommendationId: i,
112
- configVersion: r ? N : w,
113
+ configVersion: r ? N : M,
113
114
  ...s ? { partnerName: g().partnerName.value } : {},
114
115
  // An RRS block picks a strategy, not an algorithm, and its algorithm control is
115
116
  // hidden. Keeping the `mostPopular` default would bake a most-popular feed URL
@@ -119,8 +120,8 @@ class te extends S {
119
120
  ), l = p();
120
121
  if (l.setCurrentBlock(i), this._stampHidePrice(e, n.priceHideIfSameAsDiscounted), o) {
121
122
  I(this.api);
122
- const h = this._getBlockElement(e);
123
- h && (R(this.api, h, !0), M({
123
+ const d = this._getBlockElement(e);
124
+ d && (R(this.api, d, !0), H({
124
125
  currentNode: e,
125
126
  documentModifier: this.api.getDocumentModifier()
126
127
  }));
@@ -131,7 +132,7 @@ class te extends S {
131
132
  onDocumentInit() {
132
133
  try {
133
134
  const e = this.api.getDocumentRoot();
134
- e && "querySelectorAll" in e && e.querySelectorAll(`.${d}`).forEach((t) => this._queueArrivalRefresh(t));
135
+ e && "querySelectorAll" in e && e.querySelectorAll(`.${h}`).forEach((t) => this._queueArrivalRefresh(t));
135
136
  } catch (e) {
136
137
  console.error("[recommendation] refreshing an opened strategy failed", e);
137
138
  }
@@ -154,13 +155,13 @@ class te extends S {
154
155
  "Assign recommendation ID to legacy block"
155
156
  );
156
157
  }
157
- this._healLingeringDuplicate(e), a.needsMigration(e) && this._migrateFromLegacy(e), this._healHidePriceAttr(e);
158
+ this._healLingeringDuplicate(e), a.needsMigration(e) && this._migrateFromLegacy(e), this._healHidePriceAttr(e), this._ensureMobileFitRule(e), this._syncHeightBound(e);
158
159
  try {
159
160
  B || (I(this.api), B = !0);
160
161
  const t = a.getConfig(e), i = this._getBlockElement(e);
161
162
  if (i) {
162
163
  const r = !t.mobileLayoutEnabled;
163
- O(i) !== r && R(this.api, i, r);
164
+ T(i) !== r && R(this.api, i, r);
164
165
  }
165
166
  } catch {
166
167
  }
@@ -176,6 +177,20 @@ class te extends S {
176
177
  const t = this._getRecommendationId(e);
177
178
  t && p().removeBlockState(t);
178
179
  }
180
+ _ensureMobileFitRule(e) {
181
+ try {
182
+ w(this.api, e);
183
+ } catch {
184
+ }
185
+ }
186
+ _syncHeightBound(e) {
187
+ const t = this._getBlockElement(e);
188
+ if (t)
189
+ try {
190
+ O(this.api, t);
191
+ } catch {
192
+ }
193
+ }
179
194
  /**
180
195
  * Warns (dark advisory toaster) when the design holds more than one live
181
196
  * recommendation block. Triggered from the user-add paths only (fresh drop
@@ -190,7 +205,7 @@ class te extends S {
190
205
  */
191
206
  _warnIfMultipleBlocks() {
192
207
  try {
193
- x().warnIfMultipleBlocks(this.api.getDocumentRootHtmlNode());
208
+ F().warnIfMultipleBlocks(this.api.getDocumentRootHtmlNode());
194
209
  } catch {
195
210
  }
196
211
  }
@@ -203,7 +218,7 @@ class te extends S {
203
218
  const t = /* @__PURE__ */ new Set();
204
219
  try {
205
220
  const i = this.api.getDocumentRoot();
206
- i && "querySelectorAll" in i && i.querySelectorAll(`.${d}`).forEach((s) => {
221
+ i && "querySelectorAll" in i && i.querySelectorAll(`.${h}`).forEach((s) => {
207
222
  if ("getAttribute" in s) {
208
223
  const n = s.getAttribute(f), o = n ? parseInt(n) : 0;
209
224
  t.add(o), o > e && (e = o);
@@ -244,7 +259,7 @@ class te extends S {
244
259
  }, 0));
245
260
  }
246
261
  _refreshArrivedBlocks(e) {
247
- k(this.api);
262
+ y(this.api);
248
263
  const t = /* @__PURE__ */ new Set(), i = e.flatMap(({ node: r, id: s }) => {
249
264
  const n = s ?? this._getRecommendationId(r), o = this._getBlockElement(r);
250
265
  if (!n || !o || t.has(n))
@@ -252,8 +267,8 @@ class te extends S {
252
267
  const l = a.getConfig(o);
253
268
  if (!this._canClaimRefresh(n, l.strategyId))
254
269
  return [];
255
- const h = { strategyId: l.strategyId };
256
- return t.add(n), this._refreshClaims.set(n, h), [{ id: n, config: l, claim: h }];
270
+ const d = { strategyId: l.strategyId };
271
+ return t.add(n), this._refreshClaims.set(n, d), [{ id: n, config: l, claim: d }];
257
272
  });
258
273
  i.length && q(i.map(({ id: r, config: s }) => ({ id: r, config: s }))).catch((r) => console.error("[recommendation] refreshing an arrived strategy failed", r)).finally(() => i.forEach(({ id: r, claim: s }) => this._releaseRefreshClaim(r, s)));
259
274
  }
@@ -292,7 +307,7 @@ class te extends S {
292
307
  if (!i || !("querySelectorAll" in i))
293
308
  return;
294
309
  const r = i.querySelectorAll(
295
- `.${d}[${f}="${t}"]`
310
+ `.${h}[${f}="${t}"]`
296
311
  );
297
312
  if (r.length <= 1)
298
313
  return;
@@ -317,7 +332,7 @@ class te extends S {
317
332
  const t = this.api.getDocumentRoot();
318
333
  if (t && "querySelectorAll" in t)
319
334
  return t.querySelectorAll(
320
- `.${d}[${f}="${e}"]`
335
+ `.${h}[${f}="${e}"]`
321
336
  ).length > 1;
322
337
  } catch {
323
338
  }
@@ -327,12 +342,12 @@ class te extends S {
327
342
  _handleDuplicate(e, t) {
328
343
  const i = this._reassignDuplicateId(e, t), r = p();
329
344
  if (r.cloneBlockState(t, i), r.setCurrentBlock(i), g().isFeatureEnabled("reusableRecommendationStrategy")) {
330
- this._resetSourceIds.add(t), k(this.api);
345
+ this._resetSourceIds.add(t), y(this.api);
331
346
  const s = a.getConfig(e), n = [
332
- { id: t, claim: { strategyId: H(t, s).strategyId } },
347
+ { id: t, claim: { strategyId: L(t, s).strategyId } },
333
348
  { id: i, claim: { strategyId: s.strategyId } }
334
349
  ].filter(({ id: o }) => !this._refreshClaims.has(o));
335
- n.forEach(({ id: o, claim: l }) => this._refreshClaims.set(o, l)), F(t, i, s).catch((o) => console.error("[recommendation] refreshing a duplicated strategy failed", o)).finally(() => n.forEach(({ id: o, claim: l }) => this._releaseRefreshClaim(o, l)));
350
+ n.forEach(({ id: o, claim: l }) => this._refreshClaims.set(o, l)), P(t, i, s).catch((o) => console.error("[recommendation] refreshing a duplicated strategy failed", o)).finally(() => n.forEach(({ id: o, claim: l }) => this._releaseRefreshClaim(o, l)));
336
351
  }
337
352
  this._warnIfMultipleBlocks();
338
353
  }
@@ -422,10 +437,10 @@ class te extends S {
422
437
  _getBlockElement(e) {
423
438
  if ("getAttribute" in e) {
424
439
  const t = e.getAttribute("class");
425
- if (t && t.includes(d))
440
+ if (t && t.includes(h))
426
441
  return e;
427
442
  }
428
- return "querySelector" in e ? e.querySelector(`.${d}`) ?? null : null;
443
+ return "querySelector" in e ? e.querySelector(`.${h}`) ?? null : null;
429
444
  }
430
445
  /**
431
446
  * Migrate configuration from legacy format
@@ -435,6 +450,6 @@ class te extends S {
435
450
  }
436
451
  }
437
452
  export {
438
- y as BLOCK_ID,
439
- te as RecommendationBlock
453
+ k as BLOCK_ID,
454
+ se as RecommendationBlock
440
455
  };
@@ -1,19 +1,79 @@
1
- import { createImageMarginsControl as m, createImageSizeControl as n } from "../../../controlFactories.js";
2
- import { RecommendationBlockId as o } from "../../constants/blockIds.js";
3
- import { RecommendationControlId as r } from "../../constants/controlIds.js";
4
- import { BLOCK_ROOT_SELECTOR as t } from "../../constants/selectors.js";
5
- const e = n(
6
- r.IMAGE_SIZE,
7
- o.IMAGE,
8
- t
9
- ), i = m(
10
- r.IMAGE_MARGINS,
11
- o.IMAGE,
12
- t
13
- ), C = {
14
- size: e,
15
- margins: i
1
+ import { EditorStatePropertyType as E, PreviewDeviceMode as I, ModificationDescription as h } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
+ import { createImageMarginsControl as M, createImageSizeControl as C } from "../../../controlFactories.js";
3
+ import { RecommendationBlockId as c } from "../../constants/blockIds.js";
4
+ import { RecommendationControlId as g } from "../../constants/controlIds.js";
5
+ import { BLOCK_ROOT_SELECTOR as l } from "../../constants/selectors.js";
6
+ import { hasGetStyle as a, hasGetAttribute as O } from "../../utils/tagName.js";
7
+ const R = { width: "", height: "auto", "max-height": "" }, f = `${l} img.adapt-img`, x = `*${l.slice(1)}`, p = `@media only screen and (max-width: 600px) { ${f} { max-height: none !important; } }`;
8
+ function _(t) {
9
+ return { width: "auto", height: "auto", "max-height": `${t}px` };
10
+ }
11
+ function A(t) {
12
+ return t.querySelectorAll(x).some((e) => "getSelector" in e && e.getSelector() === f);
13
+ }
14
+ function T(t, e) {
15
+ return a(t) && Object.entries(e).some(([o, n]) => (t.getStyle(o) ?? "") !== n);
16
+ }
17
+ function S(t) {
18
+ const e = t.getDocumentRootCssNode();
19
+ return e && !A(e) ? e : null;
20
+ }
21
+ function H(t, e) {
22
+ const n = e.querySelectorAll("img").some((r) => a(r) && !!r.getStyle("max-height")) ? S(t) : null;
23
+ if (!n)
24
+ return;
25
+ const i = t.getDocumentModifier();
26
+ i.modifyCss(n).appendRule(p), i.apply(new h("Add the reco image mobile fit rule"));
27
+ }
28
+ const B = `[esd-extension-block-id="${c.IMAGE}"]`, L = /^\d+px$/;
29
+ function y(t) {
30
+ return O(t) && Number(t.getAttribute("height")) || 0;
31
+ }
32
+ function b(t) {
33
+ const e = y(t), o = a(t) ? t.getStyle("max-height") ?? "" : "";
34
+ return L.test(o) && e > 0 && o !== `${e}px`;
35
+ }
36
+ function U(t, e) {
37
+ const o = e.querySelectorAll(B).map((i) => i.querySelector("img")).filter(b);
38
+ if (!o.length)
39
+ return;
40
+ const n = t.getDocumentModifier();
41
+ o.forEach((i) => n.modifyHtml(i).setStyle("max-height", `${y(i)}px`)), n.apply(new h("Sync the reco image height bound").asHidden());
42
+ }
43
+ class D extends C(
44
+ g.IMAGE_SIZE,
45
+ c.IMAGE,
46
+ l
47
+ ) {
48
+ getAdditionalModifications(e) {
49
+ if (this.api.getEditorState()[E.previewDeviceMode] === I.MOBILE)
50
+ return;
51
+ const o = this.getFitStyles(), n = this.getTargetNodes(e).map((s) => s.querySelector("img")).filter((s) => T(s, o)), i = o["max-height"] ? S(this.api) : null;
52
+ if (!n.length && !i)
53
+ return;
54
+ const r = this.api.getDocumentModifier();
55
+ return i && r.modifyCss(i).appendRule(p), n.forEach((s) => {
56
+ const m = r.modifyHtml(s);
57
+ Object.entries(o).forEach(([u, d]) => {
58
+ d ? m.setStyle(u, d) : m.removeStyle(u);
59
+ });
60
+ }), r;
61
+ }
62
+ getFitStyles() {
63
+ const { size: e } = this.api.getValues();
64
+ return (e == null ? void 0 : e.type) === "height" && e.value ? _(e.value) : R;
65
+ }
66
+ }
67
+ const F = M(
68
+ g.IMAGE_MARGINS,
69
+ c.IMAGE,
70
+ l
71
+ ), P = {
72
+ size: D,
73
+ margins: F
16
74
  };
17
75
  export {
18
- C as ImageControls
76
+ P as ImageControls,
77
+ H as ensureMobileFitRule,
78
+ U as syncHeightBound
19
79
  };
@@ -1,10 +1,10 @@
1
1
  import { extractWrapperTags as A } from "../../../../utils/preserveTextStyles.js";
2
2
  import { RecommendationBlockId as c } from "../constants/blockIds.js";
3
- import { DESKTOP_CONTAINER_SELECTOR as b, ATTR_PRODUCT_NAME as k, ATTR_PRODUCT_PRICE as y, ATTR_PRODUCT_OLD_PRICE as p, ATTR_PRODUCT_OMNIBUS_PRICE as R, ATTR_PRODUCT_OMNIBUS_DISCOUNT as _, ATTR_PRODUCT_BUTTON as x, ATTR_PRODUCT_IMAGE as q, ATTR_PRODUCT_ATTR as v } from "../constants/selectors.js";
3
+ import { DESKTOP_CONTAINER_SELECTOR as g, ATTR_PRODUCT_NAME as k, ATTR_PRODUCT_PRICE as y, ATTR_PRODUCT_OLD_PRICE as p, ATTR_PRODUCT_OMNIBUS_PRICE as R, ATTR_PRODUCT_OMNIBUS_DISCOUNT as _, ATTR_PRODUCT_BUTTON as x, ATTR_PRODUCT_IMAGE as q, ATTR_PRODUCT_ATTR as v } from "../constants/selectors.js";
4
4
  import { CSS_CLASS_TEXT_TRIM as B } from "../controls/shared/textTrimCssRules.js";
5
5
  import { toCustomCompositionKey as U } from "../templates/utils.js";
6
6
  import { resolveRowVisibilityKeys as N, isMergedInlinePriceRow as C } from "./compositionKeys.js";
7
- import { hasQuerySelectorAll as I, hasGetAttribute as l, hasGetStyle as O, hasGetComputedStyle as M } from "./tagName.js";
7
+ import { hasQuerySelectorAll as I, hasGetAttribute as l, hasGetStyle as h, hasGetComputedStyle as M } from "./tagName.js";
8
8
  const s = [
9
9
  "font-size",
10
10
  "font-family",
@@ -37,9 +37,10 @@ const s = [
37
37
  "width",
38
38
  "height",
39
39
  "max-width",
40
+ "max-height",
40
41
  "border-radius",
41
42
  "margin"
42
- ], g = /* @__PURE__ */ new Set(["transparent", "rgba(0, 0, 0, 0)"]), L = [
43
+ ], b = /* @__PURE__ */ new Set(["transparent", "rgba(0, 0, 0, 0)"]), L = [
43
44
  { attrKey: k, blockId: c.NAME, kind: "text" },
44
45
  { attrKey: y, blockId: c.PRICE, kind: "text" },
45
46
  { attrKey: p, blockId: c.OLD_PRICE, kind: "text" },
@@ -48,14 +49,14 @@ const s = [
48
49
  { attrKey: x, blockId: c.BUTTON, kind: "button" },
49
50
  { attrKey: q, blockId: c.IMAGE, kind: "image" }
50
51
  ];
51
- function h(t) {
52
+ function O(t) {
52
53
  return t && "getInnerHTML" in t && typeof t.getInnerHTML == "function" ? t.getInnerHTML().trim() : "";
53
54
  }
54
55
  function K(t) {
55
56
  return t && "getInnerText" in t && typeof t.getInnerText == "function" ? t.getInnerText().trim() : "";
56
57
  }
57
58
  function a(t, e, r) {
58
- !e || !O(e) || r.forEach((n) => {
59
+ !e || !h(e) || r.forEach((n) => {
59
60
  const o = e.getStyle(n);
60
61
  o && o !== "inherit" && o !== "initial" && (t[n] = o);
61
62
  });
@@ -64,10 +65,10 @@ function E(t) {
64
65
  return Object.entries(t).map(([e, r]) => `${e}: ${r};`).join(" ");
65
66
  }
66
67
  function P(t) {
67
- if (!t || !O(t))
68
+ if (!t || !h(t))
68
69
  return;
69
70
  const e = t.getStyle("background-color") || t.getStyle("background");
70
- return e && !g.has(e) ? e : void 0;
71
+ return e && !b.has(e) ? e : void 0;
71
72
  }
72
73
  function S(t, e) {
73
74
  const r = {};
@@ -76,11 +77,11 @@ function S(t, e) {
76
77
  function $(t) {
77
78
  const e = t.querySelector("p"), r = {};
78
79
  a(r, t, s), a(r, e, s), a(r, t.querySelector("strong"), s), a(r, t.querySelector("em"), s), a(r, t.querySelector("s"), s);
79
- const n = E(r), { openTags: o, closeTags: i } = A(h(e));
80
+ const n = E(r), { openTags: o, closeTags: i } = A(O(e));
80
81
  return !n && !o ? null : { pStyle: n || void 0, openTags: o, closeTags: i };
81
82
  }
82
83
  function H(t) {
83
- const e = t.querySelector(".es-button-border"), r = t.querySelector("a.es-button") ?? t.querySelector("a"), n = S(e, D), o = S(r, w), i = e && "getAttribute" in e ? e.getAttribute("class") ?? "" : "", u = /\bes-fw\b/.test(i), { openTags: T, closeTags: d } = A(h(r)), m = K(r);
84
+ const e = t.querySelector(".es-button-border"), r = t.querySelector("a.es-button") ?? t.querySelector("a"), n = S(e, D), o = S(r, w), i = e && "getAttribute" in e ? e.getAttribute("class") ?? "" : "", u = /\bes-fw\b/.test(i), { openTags: T, closeTags: d } = A(O(r)), m = K(r);
84
85
  return !n && !o && !u && !T && !m ? null : {
85
86
  buttonBorderStyle: n || void 0,
86
87
  buttonAnchorStyle: o || void 0,
@@ -100,7 +101,7 @@ function j(t, e) {
100
101
  function f(t, e) {
101
102
  if (!t || !("querySelector" in t))
102
103
  return;
103
- const r = t.querySelector(b) ?? t;
104
+ const r = t.querySelector(g) ?? t;
104
105
  if (L.forEach(({ attrKey: i, blockId: u, kind: T }) => {
105
106
  const d = r.querySelector(`[esd-extension-block-id="${u}"]`);
106
107
  d && e(d, i, T);
@@ -126,20 +127,20 @@ function V(t) {
126
127
  function X(t) {
127
128
  if (!t || !("querySelector" in t))
128
129
  return;
129
- const e = t.querySelector(b) ?? t, r = e.querySelector(".product-card-segment") ?? e.querySelector(".product-card-wrapper");
130
+ const e = t.querySelector(g) ?? t, r = e.querySelector(".product-card-segment") ?? e.querySelector(".product-card-wrapper");
130
131
  return P(r);
131
132
  }
132
133
  function z(t) {
133
134
  if (!t)
134
135
  return;
135
136
  const e = l(t) ? t.getAttribute("bgcolor") : null;
136
- if (e && !g.has(e))
137
+ if (e && !b.has(e))
137
138
  return e;
138
139
  const r = P(t);
139
140
  if (r)
140
141
  return r;
141
142
  const n = M(t) ? t.getComputedStyle("background-color") : void 0;
142
- return n && !g.has(n) ? n : void 0;
143
+ return n && !b.has(n) ? n : void 0;
143
144
  }
144
145
  function Q(t) {
145
146
  const e = {};
@@ -170,7 +171,7 @@ function J(t) {
170
171
  function Z(t) {
171
172
  if (!t || !("querySelector" in t))
172
173
  return !1;
173
- const e = t.querySelector(b) ?? t;
174
+ const e = t.querySelector(g) ?? t;
174
175
  return C(e.querySelector(`[data-attribute-type="${y}"]`)) || C(e.querySelector(`[data-attribute-type="${p}"]`));
175
176
  }
176
177
  function tt(t) {
@@ -195,7 +196,7 @@ function rt(t) {
195
196
  const e = {};
196
197
  if (!t || !("querySelector" in t))
197
198
  return e;
198
- const r = t.querySelector(b) ?? t;
199
+ const r = t.querySelector(g) ?? t;
199
200
  return I(r) && r.querySelectorAll(".recommendation-attribute-row").forEach((n) => {
200
201
  if (!l(n))
201
202
  return;
@@ -0,0 +1,17 @@
1
+ import { DisplayConditionEvent as e } from "../../enums/display-condition.js";
2
+ let n = null;
3
+ const p = (E, t) => {
4
+ n == null || n();
5
+ const i = (o) => {
6
+ n == null || n(), t.onApply(o.detail.condition);
7
+ }, m = () => {
8
+ var o;
9
+ n == null || n(), (o = t.onCancel) == null || o.call(t);
10
+ };
11
+ document.addEventListener(e.APPLY, i), document.addEventListener(e.CANCEL, m), n = () => {
12
+ document.removeEventListener(e.APPLY, i), document.removeEventListener(e.CANCEL, m), n = null;
13
+ }, document.dispatchEvent(new CustomEvent(e.OPEN, { detail: E }));
14
+ };
15
+ export {
16
+ p as requestDisplayCondition
17
+ };
@@ -0,0 +1,17 @@
1
+ import { BlockType as o } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
+ const n = "conditions", t = "guido-display-conditions-control", c = 10, s = [o.STRIPE, o.STRUCTURE, o.CONTAINER], d = {
3
+ PLUS: "guido-display-condition-plus",
4
+ EDIT: "guido-display-condition-edit",
5
+ TRASH: "guido-display-condition-trash",
6
+ CHEVRON: "guido-display-condition-chevron"
7
+ }, e = ["applyConditionSwitcher", "applyCondition", "displayConditions"], I = "You can add Display Condition by selecting an existing condition or creating a new one to show specific content.", O = "You can create or select a display condition to control content visibility based on your recipients' properties or events.";
8
+ export {
9
+ O as APPLIED_DESCRIPTION,
10
+ e as BUILT_IN_CONDITION_CONTROLS,
11
+ t as CONDITIONS_CONTROL_ID,
12
+ n as CONDITIONS_TAB_ID,
13
+ s as CONDITION_BLOCK_TYPES,
14
+ d as CONDITION_ICONS,
15
+ I as EMPTY_DESCRIPTION,
16
+ c as MAX_COLLAPSED_LINES
17
+ };
@@ -0,0 +1,178 @@
1
+ var O = Object.defineProperty;
2
+ var $ = (o, s, i) => s in o ? O(o, s, { enumerable: !0, configurable: !0, writable: !0, value: i }) : o[s] = i;
3
+ var u = (o, s, i) => $(o, typeof s != "symbol" ? s + "" : s, i);
4
+ import { CommonControl as S } from "../Blocks/common-control.js";
5
+ import { toAppliedCondition as w, parseSource as N } from "../../utils/displayCondition.js";
6
+ import { escapeHtml as f } from "../../utils/htmlEscape.js";
7
+ import { ModificationDescription as D, UIElementType as b, UEAttr as I } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
8
+ import { requestDisplayCondition as E } from "./bridge.js";
9
+ import { CONDITIONS_CONTROL_ID as x, APPLIED_DESCRIPTION as M, EMPTY_DESCRIPTION as T, MAX_COLLAPSED_LINES as v, CONDITION_ICONS as g } from "./constants.js";
10
+ const r = ".guido-display-conditions", L = { id: 0, name: "", description: "", beforeScript: "", afterScript: "" }, _ = (o) => `<${b.ICON} ${I.ICON.src}="${o}"></${b.ICON}>`, c = (o, s, i, t = !1) => `<button type="button" class="${s}" id="${o}"${t ? " hidden" : ""}>${i}</button>`;
11
+ class B extends S {
12
+ constructor() {
13
+ super(...arguments);
14
+ u(this, "expanded", !1);
15
+ u(this, "listeners", []);
16
+ u(this, "resizeObserver", null);
17
+ u(this, "detachOutsideClick", null);
18
+ }
19
+ getId() {
20
+ return x;
21
+ }
22
+ getTemplate() {
23
+ return `
24
+ <div class="guido-display-conditions">
25
+ <div class="guido-display-conditions__header">
26
+ <p class="guido-display-conditions__title">${this.api.translate("Display Conditions")}</p>
27
+ <p class="guido-display-conditions__description" data-dc-description></p>
28
+ </div>
29
+ <div class="guido-display-conditions__empty" data-dc-empty>
30
+ ${c(
31
+ "guido__btn-add-display-condition",
32
+ "guido-display-conditions__add",
33
+ `${_(g.PLUS)}<span>${this.api.translate("Add Display Condition")}</span>`
34
+ )}
35
+ <div class="guido-display-conditions__menu" data-dc-menu hidden>
36
+ ${c(
37
+ "guido__btn-display-condition-create",
38
+ "guido-display-conditions__menu-item",
39
+ this.api.translate("Create New Condition")
40
+ )}
41
+ ${c(
42
+ "guido__btn-display-condition-select",
43
+ "guido-display-conditions__menu-item",
44
+ this.api.translate("Select Saved Condition")
45
+ )}
46
+ </div>
47
+ </div>
48
+ <div class="guido-display-conditions__applied" data-dc-applied hidden>
49
+ <div class="guido-display-conditions__code-box">
50
+ <p class="guido-display-conditions__name" data-dc-name></p>
51
+ <div class="guido-display-conditions__sections" data-dc-sections>
52
+ <p class="guido-display-conditions__section-label">
53
+ ${this.api.translate("Code Before Module")}
54
+ </p>
55
+ <pre class="guido-display-conditions__code" data-dc-before></pre>
56
+ <p class="guido-display-conditions__section-label" data-dc-after-label>
57
+ ${this.api.translate("Code After Module")}
58
+ </p>
59
+ <pre class="guido-display-conditions__code" data-dc-after></pre>
60
+ </div>
61
+ ${c(
62
+ "guido__btn-display-condition-toggle",
63
+ "guido-display-conditions__toggle",
64
+ `${_(g.CHEVRON)}<span data-dc-toggle-label></span>`,
65
+ !0
66
+ )}
67
+ </div>
68
+ <div class="guido-display-conditions__actions">
69
+ ${c(
70
+ "guido__btn-edit-display-condition",
71
+ "guido-display-conditions__action guido-display-conditions__action--edit",
72
+ `${_(g.EDIT)}<span>${this.api.translate("Edit")}</span>`
73
+ )}
74
+ ${c(
75
+ "guido__btn-remove-display-condition",
76
+ "guido-display-conditions__action guido-display-conditions__action--remove",
77
+ `${_(g.TRASH)}<span>${this.api.translate("Remove")}</span>`
78
+ )}
79
+ </div>
80
+ </div>
81
+ </div>
82
+ `;
83
+ }
84
+ onRender() {
85
+ this.teardown(), this.wire("#guido__btn-add-display-condition", () => this.toggleMenu()), this.wire("#guido__btn-display-condition-create", () => this.openDrawer("create")), this.wire("#guido__btn-display-condition-select", () => this.openDrawer("select")), this.wire("#guido__btn-edit-display-condition", () => this.openDrawer("edit")), this.wire("#guido__btn-remove-display-condition", () => this.applyCondition(null)), this.wire("#guido__btn-display-condition-toggle", () => {
86
+ this.expanded = !this.expanded, this.paint();
87
+ }), this.observeCodeSize(), this.paint();
88
+ }
89
+ onTemplateNodeUpdated(i) {
90
+ const t = i !== this.currentNode;
91
+ super.onTemplateNodeUpdated(i), t && (this.expanded = !1, this.toggleMenu(!1)), this.paint();
92
+ }
93
+ onDestroy() {
94
+ super.onDestroy(), this.teardown();
95
+ }
96
+ getCondition() {
97
+ var t;
98
+ const i = this.currentNode;
99
+ return w((t = i == null ? void 0 : i.getDisplayCondition) == null ? void 0 : t.call(i));
100
+ }
101
+ toggleMenu(i) {
102
+ var n, d, a;
103
+ const t = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${r} [data-dc-menu]`);
104
+ if (!t)
105
+ return;
106
+ t.hidden = i === void 0 ? !t.hidden : !i, (d = this.detachOutsideClick) == null || d.call(this), t.hidden || this.listenOutsideClick();
107
+ const e = (a = this.getContainer()) == null ? void 0 : a.querySelector(`${r} #guido__btn-add-display-condition`);
108
+ t.style.width = !t.hidden && e ? `${e.getBoundingClientRect().width}px` : "";
109
+ }
110
+ listenOutsideClick() {
111
+ const i = this.getContainer(), t = (e) => {
112
+ e.composedPath().some((d) => d instanceof HTMLElement && d.matches(`${r} [data-dc-menu], ${r} #guido__btn-add-display-condition`)) || this.toggleMenu(!1);
113
+ };
114
+ i == null || i.addEventListener("pointerdown", t, !0), this.detachOutsideClick = () => {
115
+ i == null || i.removeEventListener("pointerdown", t, !0), this.detachOutsideClick = null;
116
+ };
117
+ }
118
+ openDrawer(i) {
119
+ this.toggleMenu(!1), E(
120
+ { mode: i, current: i === "edit" ? this.getCondition() : null },
121
+ { onApply: (t) => this.applyCondition(t) }
122
+ );
123
+ }
124
+ applyCondition(i) {
125
+ if (!this.currentNode)
126
+ return;
127
+ const t = this.api.getDocumentModifier().modifyHtml(this.currentNode);
128
+ i ? t.setDisplayCondition(i) : t.setDisplayCondition(L), t.apply(new D(
129
+ i ? `Set display condition ${i.name}` : "Remove display condition"
130
+ ));
131
+ }
132
+ wire(i, t) {
133
+ var n;
134
+ const e = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${r} ${i}`);
135
+ e && (e.addEventListener("click", t), this.listeners.push({ element: e, handler: t }));
136
+ }
137
+ teardown() {
138
+ var i, t;
139
+ this.listeners.forEach(({ element: e, handler: n }) => e.removeEventListener("click", n)), this.listeners = [], (i = this.resizeObserver) == null || i.disconnect(), this.resizeObserver = null, (t = this.detachOutsideClick) == null || t.call(this);
140
+ }
141
+ // Line counts depend on layout: the panel font loads late and the panel can be resized.
142
+ observeCodeSize() {
143
+ var t;
144
+ const i = (t = this.getContainer()) == null ? void 0 : t.querySelectorAll(`${r} .guido-display-conditions__code`);
145
+ !(i != null && i.length) || typeof ResizeObserver > "u" || (this.resizeObserver = new ResizeObserver(() => this.paint()), i.forEach((e) => {
146
+ var n;
147
+ return (n = this.resizeObserver) == null ? void 0 : n.observe(e);
148
+ }));
149
+ }
150
+ paint() {
151
+ var C;
152
+ const i = (C = this.getContainer()) == null ? void 0 : C.querySelector(r);
153
+ if (!i)
154
+ return;
155
+ const t = this.getCondition(), e = (h) => i.querySelector(h);
156
+ if (e("[data-dc-empty]").hidden = !!t, e("[data-dc-applied]").hidden = !t, e("[data-dc-description]").textContent = this.api.translate(t ? M : T), !t)
157
+ return;
158
+ e("[data-dc-name]").textContent = t.name, e("#guido__btn-edit-display-condition").hidden = N(t) !== "inline";
159
+ const n = e("[data-dc-sections]"), d = e("[data-dc-before]"), a = e("[data-dc-after]");
160
+ d.innerHTML = f(t.beforeScript), a.innerHTML = f(t.afterScript), a.hidden = !t.afterScript, e("[data-dc-after-label]").hidden = !t.afterScript, n.style.maxHeight = "";
161
+ const l = parseFloat(getComputedStyle(d).lineHeight) || 24, p = (h) => h.hidden ? 0 : Math.round(h.scrollHeight / l), y = p(d) + p(a) > v, m = e("#guido__btn-display-condition-toggle");
162
+ m.hidden = !y, m.classList.toggle("is-expanded", this.expanded), e("[data-dc-toggle-label]").textContent = this.api.translate(this.expanded ? "Show Less" : "Show More"), y && !this.expanded && (n.style.maxHeight = `${this.collapsedHeight(n, [d, a], l)}px`);
163
+ }
164
+ // Labels do not count toward the line limit, so the cut lands after the 10th rendered code line.
165
+ collapsedHeight(i, t, e) {
166
+ const { top: n } = i.getBoundingClientRect();
167
+ let d = v, a = 0;
168
+ return t.filter((l) => !l.hidden).forEach((l) => {
169
+ if (d <= 0)
170
+ return;
171
+ const p = Math.min(d, Math.round(l.scrollHeight / e));
172
+ a = l.getBoundingClientRect().top - n + p * e, d -= p;
173
+ }), a;
174
+ }
175
+ }
176
+ export {
177
+ B as DisplayConditionsControl
178
+ };