@useinsider/guido 3.23.0-beta.86bed27 → 3.23.0-beta.95eb6bb

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 (111) 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 +84 -82
  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/components/organisms/unsubscribe/UnsubscribePageSelection.vue.js +11 -11
  15. package/dist/components/organisms/unsubscribe/UnsubscribePageSelection.vue2.js +9 -9
  16. package/dist/composables/useBlocksConfig.js +32 -24
  17. package/dist/composables/useDisplayConditions.js +109 -0
  18. package/dist/config/compiler/utils/itemsCompilerUtils.js +43 -42
  19. package/dist/config/compiler/utils/recommendationCompilerUtils.js +78 -75
  20. package/dist/config/migrator/recommendation/compositionMapper.js +56 -49
  21. package/dist/config/migrator/recommendation/extractors.js +100 -40
  22. package/dist/config/migrator/recommendation/htmlBuilder.js +285 -207
  23. package/dist/config/migrator/recommendation/settingsMapper.js +37 -36
  24. package/dist/config/migrator/recommendation/themeMapper.js +53 -41
  25. package/dist/config/migrator/recommendationMigrator.js +68 -61
  26. package/dist/enums/academy.js +1 -0
  27. package/dist/enums/display-condition.js +12 -0
  28. package/dist/extensions/Blocks/Items/controls/button/link.js +14 -17
  29. package/dist/extensions/Blocks/Items/controls/cardComposition.js +14 -17
  30. package/dist/extensions/Blocks/Items/controls/image/link.js +14 -17
  31. package/dist/extensions/Blocks/Items/controls/name/trimming.js +9 -10
  32. package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +24 -25
  33. package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +12 -13
  34. package/dist/extensions/Blocks/Items/controls/price/formattedPrice.js +29 -30
  35. package/dist/extensions/Blocks/Items/controls/price/hideDiscount.js +15 -16
  36. package/dist/extensions/Blocks/Items/controls/price/priceOrientation.js +25 -26
  37. package/dist/extensions/Blocks/Items/controls/price/singlePrice.js +27 -28
  38. package/dist/extensions/Blocks/Items/controls/settingsControl.js +75 -80
  39. package/dist/extensions/Blocks/Recommendation/block.js +33 -24
  40. package/dist/extensions/Blocks/Recommendation/controls/cardBackground/index.js +3 -3
  41. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +27 -26
  42. package/dist/extensions/Blocks/Recommendation/controls/customAttribute/textTrim.js +13 -13
  43. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +165 -175
  44. package/dist/extensions/Blocks/Recommendation/controls/name/textTrim.js +5 -5
  45. package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/textAfter.js +8 -8
  46. package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/textBefore.js +15 -15
  47. package/dist/extensions/Blocks/Recommendation/controls/omnibusPrice/textAfter.js +12 -12
  48. package/dist/extensions/Blocks/Recommendation/controls/omnibusPrice/textBefore.js +10 -10
  49. package/dist/extensions/Blocks/Recommendation/controls/spacing/index.js +1 -1
  50. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +23 -22
  51. package/dist/extensions/Blocks/Recommendation/templates/list/template.js +19 -18
  52. package/dist/extensions/Blocks/Recommendation/templates/utils.js +82 -91
  53. package/dist/extensions/Blocks/Recommendation/utils/inlinePriceOrder.js +12 -0
  54. package/dist/extensions/Blocks/Recommendation/utils/legacyStrategyMap.js +3 -2
  55. package/dist/extensions/Blocks/common-control.js +62 -55
  56. package/dist/extensions/DisplayConditions/bridge.js +18 -0
  57. package/dist/extensions/DisplayConditions/constants.js +17 -0
  58. package/dist/extensions/DisplayConditions/control.js +182 -0
  59. package/dist/extensions/DisplayConditions/display-conditions.css.js +201 -0
  60. package/dist/extensions/DisplayConditions/extension.js +28 -0
  61. package/dist/extensions/DisplayConditions/iconsRegistry.js +20 -0
  62. package/dist/extensions/DisplayConditions/library.js +27 -0
  63. package/dist/extensions/DisplayConditions/settingsPanel.js +17 -0
  64. package/dist/guido.css +1 -1
  65. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +93 -92
  66. package/dist/node_modules/valibot/dist/index.js +297 -261
  67. package/dist/package.json.js +1 -1
  68. package/dist/services/displayConditionApi.js +39 -0
  69. package/dist/src/@types/config/schemas.d.ts +4 -0
  70. package/dist/src/@types/display-condition.d.ts +60 -0
  71. package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +43 -0
  72. package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +2 -0
  73. package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +2 -0
  74. package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +2 -0
  75. package/dist/src/composables/useConfig.d.ts +2 -0
  76. package/dist/src/composables/useDisplayConditions.d.ts +16 -0
  77. package/dist/src/config/migrator/recommendation/compositionMapper.d.ts +3 -1
  78. package/dist/src/config/migrator/recommendation/extractors.d.ts +35 -6
  79. package/dist/src/config/migrator/recommendation/htmlBuilder.d.ts +3 -1
  80. package/dist/src/config/migrator/recommendation/themeMapper.d.ts +3 -1
  81. package/dist/src/config/migrator/recommendation/types.d.ts +11 -1
  82. package/dist/src/enums/academy.d.ts +1 -0
  83. package/dist/src/enums/display-condition.d.ts +15 -0
  84. package/dist/src/extensions/Blocks/Items/controls/cardComposition.d.ts +0 -1
  85. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +1 -0
  86. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +5 -10
  87. package/dist/src/extensions/Blocks/Recommendation/templates/utils.d.ts +1 -13
  88. package/dist/src/extensions/Blocks/Recommendation/utils/inlinePriceOrder.d.ts +9 -0
  89. package/dist/src/extensions/Blocks/Recommendation/utils/legacyStrategyMap.d.ts +2 -19
  90. package/dist/src/extensions/Blocks/common-control.d.ts +2 -0
  91. package/dist/src/extensions/DisplayConditions/bridge.d.ts +6 -0
  92. package/dist/src/extensions/DisplayConditions/constants.d.ts +14 -0
  93. package/dist/src/extensions/DisplayConditions/control.d.ts +23 -0
  94. package/dist/src/extensions/DisplayConditions/extension.d.ts +2 -0
  95. package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +4 -0
  96. package/dist/src/extensions/DisplayConditions/library.d.ts +8 -0
  97. package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +5 -0
  98. package/dist/src/mock/api/display-conditions.d.ts +2 -0
  99. package/dist/src/services/displayConditionApi.d.ts +8 -0
  100. package/dist/src/stores/config.d.ts +166 -0
  101. package/dist/src/stores/display-condition.d.ts +84 -0
  102. package/dist/src/stores/unsubscribe.d.ts +10 -0
  103. package/dist/src/utils/displayCondition.d.ts +10 -0
  104. package/dist/src/utils/protectTableText.d.ts +2 -0
  105. package/dist/stores/config.js +13 -6
  106. package/dist/stores/display-condition.js +29 -0
  107. package/dist/stores/unsubscribe.js +33 -29
  108. package/dist/utils/displayCondition.js +26 -0
  109. package/dist/utils/pairProductVariables.js +30 -29
  110. package/dist/utils/protectTableText.js +22 -0
  111. package/package.json +2 -2
@@ -3,9 +3,10 @@ function r(e) {
3
3
  return e;
4
4
  switch (e) {
5
5
  case "viewedTogether":
6
- return "similarViewed";
7
6
  case "purchasedTogether":
8
- return "similarBought";
7
+ case "similarViewed":
8
+ case "similarBought":
9
+ return "mostPopular";
9
10
  case "trending":
10
11
  return "trendingProducts";
11
12
  case "mostValuable":
@@ -1,12 +1,14 @@
1
- var c = Object.defineProperty;
2
- var i = (l, a, e) => a in l ? c(l, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[a] = e;
3
- var T = (l, a, e) => i(l, typeof a != "symbol" ? a + "" : a, e);
1
+ var u = Object.defineProperty;
2
+ var c = (l, E, e) => E in l ? u(l, E, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[E] = e;
3
+ var i = (l, E, e) => c(l, typeof E != "symbol" ? E + "" : E, e);
4
4
  import { Control as I, UIElementType as n, UEAttr as $ } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
5
  class _ extends I {
6
6
  constructor() {
7
7
  super(...arguments);
8
- T(this, "currentNode");
9
- T(this, "lastBlockInstanceId", null);
8
+ i(this, "currentNode");
9
+ i(this, "lastBlockInstanceId", null);
10
+ // Set until the control handles the node Stripo hands a freshly rendered panel.
11
+ i(this, "isAwaitingPanelNode", !1);
10
12
  }
11
13
  getContainer() {
12
14
  var e;
@@ -18,6 +20,11 @@ class _ extends I {
18
20
  onDestroy() {
19
21
  this.lastBlockInstanceId = null;
20
22
  }
23
+ // Stripo renders a panel before it hands that panel its node, so a node still held is the last
24
+ // panel's and may be disposed. Controls Stripo renders call this first in onRender.
25
+ forgetLastPanelNode() {
26
+ this.currentNode = void 0, this.isAwaitingPanelNode = !0;
27
+ }
21
28
  /**
22
29
  * Gets the Items block container element from the current node.
23
30
  * @returns The container element or null if not found
@@ -44,18 +51,18 @@ class _ extends I {
44
51
  * @returns true if block instance changed, false otherwise
45
52
  */
46
53
  handleBlockInstanceChange(e) {
47
- const t = this.getBlockInstanceId();
48
- if (!t)
49
- return !1;
50
- const E = t !== this.lastBlockInstanceId;
51
- return e(), E && (this.lastBlockInstanceId = t), E;
54
+ const t = this.getBlockInstanceId(), o = this.isAwaitingPanelNode;
55
+ if (this.isAwaitingPanelNode = !1, !t)
56
+ return o && e(), !1;
57
+ const a = t !== this.lastBlockInstanceId;
58
+ return e(), a && (this.lastBlockInstanceId = t), a;
52
59
  }
53
- _GuLabel({ text: e, name: t = "", hint: E }) {
60
+ _GuLabel({ text: e, name: t = "", hint: o }) {
54
61
  return `
55
62
  <${n.LABEL}
56
63
  ${$.LABEL.text}="${e}"
57
64
  ${$.LABEL.name}="${t || `${e} Label`}"
58
- ${E ? `${$.LABEL.hint}="${E}"` : ""}>
65
+ ${o ? `${$.LABEL.hint}="${o}"` : ""}>
59
66
  </${n.LABEL}>
60
67
  `;
61
68
  }
@@ -73,7 +80,7 @@ class _ extends I {
73
80
  * Use in getTemplate() — the icon is registered in a hidden store so Stripo initializes it.
74
81
  * Pair with _setInfoMessageValue() in onRender() to set the text content.
75
82
  */
76
- _GuOnPageMessage({ name: e, icon: t = "not-found", type: E = "info" }) {
83
+ _GuOnPageMessage({ name: e, icon: t = "not-found", type: o = "info" }) {
77
84
  return `
78
85
  <div data-info-message="${e}" style="display: none; padding: 16px 16px 0;">
79
86
  <div class="icon-store" style="display: none;">
@@ -81,7 +88,7 @@ class _ extends I {
81
88
  ${this._GuIcon({ src: t, className: "icon" })}
82
89
  </div>
83
90
  </div>
84
- ${this._GuMessage({ name: e, type: E })}
91
+ ${this._GuMessage({ name: e, type: o })}
85
92
  </div>
86
93
  `;
87
94
  }
@@ -91,21 +98,21 @@ class _ extends I {
91
98
  * and combines it with the text in Stripo's alert-message layout.
92
99
  */
93
100
  _setInfoMessageValue(e, t) {
94
- const E = this.getContainer(), o = E.querySelector(`[data-icon-key="${e}"]`), r = o == null ? void 0 : o.querySelector("ue-icon-component"), s = (r == null ? void 0 : r.outerHTML) ?? "";
101
+ const o = this.getContainer(), a = o.querySelector(`[data-icon-key="${e}"]`), s = a == null ? void 0 : a.querySelector("ue-icon-component"), r = (s == null ? void 0 : s.outerHTML) ?? "";
95
102
  this.api.setUIEAttribute(
96
103
  e,
97
104
  "value",
98
105
  `
99
106
  <div class="service-element alert-message-main" style="align-items: start;">
100
- ${s}
107
+ ${r}
101
108
  <div class="service-element alert-message-text">
102
109
  ${t}
103
110
  </div>
104
111
  </div>
105
112
  `
106
113
  );
107
- const u = E.querySelector(`[data-info-message="${e}"]`);
108
- u && (u.style.display = "");
114
+ const T = o.querySelector(`[data-info-message="${e}"]`);
115
+ T && (T.style.display = "");
109
116
  }
110
117
  _GuToggle(e) {
111
118
  return `
@@ -124,66 +131,66 @@ class _ extends I {
124
131
  _GuSelect({
125
132
  name: e,
126
133
  placeholder: t,
127
- options: E,
128
- className: o = "es-180w",
129
- searchable: r = !1
134
+ options: o,
135
+ className: a = "es-180w",
136
+ searchable: s = !1
130
137
  }) {
131
138
  return `
132
139
  <${n.SELECTPICKER}
133
- class="${o}"
140
+ class="${a}"
134
141
  ${$.SELECTPICKER.name}="${e}"
135
- ${r ? `${$.SELECTPICKER.searchable}="true"` : ""}
142
+ ${s ? `${$.SELECTPICKER.searchable}="true"` : ""}
136
143
  ${$.SELECTPICKER.placeholder}="${t}">
137
- ${E.map((s) => this._GuSelectItem(s)).join("")}
144
+ ${o.map((r) => this._GuSelectItem(r)).join("")}
138
145
  </${n.SELECTPICKER}>
139
146
  `;
140
147
  }
141
- _GuTextInput({ name: e, placeholder: t, className: E = "", disabled: o = !1 }) {
148
+ _GuTextInput({ name: e, placeholder: t, className: o = "", disabled: a = !1 }) {
142
149
  return `
143
150
  <${n.TEXT}
144
- class=${E}
151
+ class=${o}
145
152
  ${$.TEXT.name}="${e}"
146
153
  placeholder="${t || e}"
147
- ${o ? `${$.TEXT.disabled}="true"` : ""}>
154
+ ${a ? `${$.TEXT.disabled}="true"` : ""}>
148
155
  </${n.TEXT}>
149
156
  `;
150
157
  }
151
- _GuCounter({ name: e, maxValue: t, minValue: E = 1, step: o = 1 }) {
158
+ _GuCounter({ name: e, maxValue: t, minValue: o = 1, step: a = 1 }) {
152
159
  return `
153
160
  <${n.COUNTER}
154
161
  ${$.COUNTER.name}="${e}"
155
- ${$.COUNTER.minValue}="${E}"
162
+ ${$.COUNTER.minValue}="${o}"
156
163
  ${$.COUNTER.maxValue}="${t}"
157
- ${$.COUNTER.step}="${o}">
164
+ ${$.COUNTER.step}="${a}">
158
165
  </${n.COUNTER}>
159
166
  `;
160
167
  }
161
- _GuRadioButtonItem({ text: e, value: t, icon: E }) {
168
+ _GuRadioButtonItem({ text: e, value: t, icon: o }) {
162
169
  return `
163
170
  <${n.RADIO_ITEM}
164
171
  ${$.RADIO_ITEM.value}="${t}"
165
172
  ${e ? `${$.RADIO_ITEM.text}="${e}"` : ""}
166
- ${E ? `${$.RADIO_ITEM.icon}="${E}"` : ""}>
173
+ ${o ? `${$.RADIO_ITEM.icon}="${o}"` : ""}>
167
174
  </${n.RADIO_ITEM}>
168
175
  `;
169
176
  }
170
- _GuRadioButton({ name: e, buttons: t, id: E = "" }) {
177
+ _GuRadioButton({ name: e, buttons: t, id: o = "" }) {
171
178
  return `
172
179
  <${n.RADIO_BUTTONS}
173
- ${E ? `id="${E}"` : ""}
180
+ ${o ? `id="${o}"` : ""}
174
181
  ${$.RADIO_BUTTONS.name}="${e}">
175
- ${t.map((o) => this._GuRadioButtonItem(o)).join("")}
182
+ ${t.map((a) => this._GuRadioButtonItem(a)).join("")}
176
183
  </${n.RADIO_BUTTONS}>
177
184
  `;
178
185
  }
179
- _GuButton({ name: e, label: t, id: E = "", className: o = "", icon: r = "", disabled: s = !1 }) {
186
+ _GuButton({ name: e, label: t, id: o = "", className: a = "", icon: s = "", disabled: r = !1 }) {
180
187
  return `
181
188
  <${n.BUTTON}
182
189
  ${$.BUTTON.name}="${e}"
183
- ${E ? `id="${E}"` : ""}
184
- ${o ? `class="${o}"` : ""}
185
- ${r ? `${$.BUTTON.icon}="${r}"` : ""}
186
- ${s ? `${$.BUTTON.disabled}="true"` : ""}
190
+ ${o ? `id="${o}"` : ""}
191
+ ${a ? `class="${a}"` : ""}
192
+ ${s ? `${$.BUTTON.icon}="${s}"` : ""}
193
+ ${r ? `${$.BUTTON.disabled}="true"` : ""}
187
194
  ${$.BUTTON.caption}="${t}">
188
195
  </${n.BUTTON}>
189
196
  `;
@@ -201,10 +208,10 @@ class _ extends I {
201
208
  * @param param0
202
209
  * @returns It returns a button with an icon.
203
210
  */
204
- _GuIconButton({ name: e, icon: t, className: E = "" }) {
211
+ _GuIconButton({ name: e, icon: t, className: o = "" }) {
205
212
  return `
206
213
  <${n.BUTTON}
207
- class="${E}"
214
+ class="${o}"
208
215
  ${$.BUTTON.name}="${e}"
209
216
  ${$.BUTTON.icon}="${t}">
210
217
  </${n.BUTTON}>
@@ -232,19 +239,19 @@ class _ extends I {
232
239
  * @returns HTML string for the orderable control
233
240
  */
234
241
  _GuOrderable(e, t) {
235
- let E = "";
236
- t.forEach((r) => {
237
- const s = $.ORDERABLE_ITEM && "name" in $.ORDERABLE_ITEM ? $.ORDERABLE_ITEM.name : "name";
238
- E += `
239
- <${n.ORDERABLE_ITEM} ${s}="${r.key}">
240
- ${r.content}
242
+ let o = "";
243
+ t.forEach((s) => {
244
+ const r = $.ORDERABLE_ITEM && "name" in $.ORDERABLE_ITEM ? $.ORDERABLE_ITEM.name : "name";
245
+ o += `
246
+ <${n.ORDERABLE_ITEM} ${r}="${s.key}">
247
+ ${s.content}
241
248
  </${n.ORDERABLE_ITEM}>
242
249
  `;
243
250
  });
244
- const o = $.ORDERABLE && "name" in $.ORDERABLE ? $.ORDERABLE.name : "name";
251
+ const a = $.ORDERABLE && "name" in $.ORDERABLE ? $.ORDERABLE.name : "name";
245
252
  return `
246
- <${n.ORDERABLE} ${o}="${e}">
247
- ${E}
253
+ <${n.ORDERABLE} ${a}="${e}">
254
+ ${o}
248
255
  </${n.ORDERABLE}>
249
256
  `;
250
257
  }
@@ -285,16 +292,16 @@ class _ extends I {
285
292
  `;
286
293
  }
287
294
  _GuRadioButtons(e, t) {
288
- const E = t.map((o) => `
295
+ const o = t.map((a) => `
289
296
  <${n.RADIO_ITEM}
290
- ${$.RADIO_ITEM.text}="${o.text}"
291
- ${$.RADIO_ITEM.value}="${o.value}">
297
+ ${$.RADIO_ITEM.text}="${a.text}"
298
+ ${$.RADIO_ITEM.value}="${a.value}">
292
299
  </${n.RADIO_ITEM}>
293
300
  `).join("");
294
301
  return `
295
302
  <${n.RADIO_BUTTONS}
296
303
  ${$.RADIO_BUTTONS.name}="${e}">
297
- ${E}
304
+ ${o}
298
305
  </${n.RADIO_BUTTONS}>
299
306
  `;
300
307
  }
@@ -0,0 +1,18 @@
1
+ import { DisplayConditionEvent as e } from "../../enums/display-condition.js";
2
+ let n = null;
3
+ const u = (m, t) => {
4
+ n == null || n();
5
+ const i = (o) => {
6
+ const l = o.detail;
7
+ n == null || n(), l.applied = t.onApply(l.condition);
8
+ }, p = () => {
9
+ var o;
10
+ n == null || n(), (o = t.onCancel) == null || o.call(t);
11
+ };
12
+ document.addEventListener(e.APPLY, i), document.addEventListener(e.CANCEL, p), n = () => {
13
+ document.removeEventListener(e.APPLY, i), document.removeEventListener(e.CANCEL, p), n = null;
14
+ }, document.dispatchEvent(new CustomEvent(e.OPEN, { detail: m }));
15
+ };
16
+ export {
17
+ u as requestDisplayCondition
18
+ };
@@ -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,182 @@
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 l = ".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.forgetLastPanelNode(), 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();
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(`${l} [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(`${l} #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(`${l} [data-dc-menu], ${l} #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 !1;
127
+ try {
128
+ const t = this.api.getDocumentModifier().modifyHtml(this.currentNode);
129
+ return t.setDisplayCondition(i || L), t.apply(new D(
130
+ i ? `Set display condition ${i.name}` : "Remove display condition"
131
+ )), !0;
132
+ } catch (t) {
133
+ return console.warn("Display condition could not be applied.", t), !1;
134
+ }
135
+ }
136
+ wire(i, t) {
137
+ var n;
138
+ const e = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${l} ${i}`);
139
+ e && (e.addEventListener("click", t), this.listeners.push({ element: e, handler: t }));
140
+ }
141
+ teardown() {
142
+ var i, t;
143
+ 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);
144
+ }
145
+ // Line counts depend on layout: the panel font loads late and the panel can be resized.
146
+ observeCodeSize() {
147
+ var t;
148
+ const i = (t = this.getContainer()) == null ? void 0 : t.querySelectorAll(`${l} .guido-display-conditions__code`);
149
+ !(i != null && i.length) || typeof ResizeObserver > "u" || (this.resizeObserver = new ResizeObserver(() => this.paint()), i.forEach((e) => {
150
+ var n;
151
+ return (n = this.resizeObserver) == null ? void 0 : n.observe(e);
152
+ }));
153
+ }
154
+ paint() {
155
+ var C;
156
+ const i = (C = this.getContainer()) == null ? void 0 : C.querySelector(l);
157
+ if (!i)
158
+ return;
159
+ const t = this.getCondition(), e = (h) => i.querySelector(h);
160
+ 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)
161
+ return;
162
+ e("[data-dc-name]").textContent = t.name, e("#guido__btn-edit-display-condition").hidden = N(t) !== "inline";
163
+ const n = e("[data-dc-sections]"), d = e("[data-dc-before]"), a = e("[data-dc-after]");
164
+ 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 = "";
165
+ const r = parseFloat(getComputedStyle(d).lineHeight) || 24, p = (h) => h.hidden ? 0 : Math.round(h.scrollHeight / r), y = p(d) + p(a) > v, m = e("#guido__btn-display-condition-toggle");
166
+ 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], r)}px`);
167
+ }
168
+ // Labels do not count toward the line limit, so the cut lands after the 10th rendered code line.
169
+ collapsedHeight(i, t, e) {
170
+ const { top: n } = i.getBoundingClientRect();
171
+ let d = v, a = 0;
172
+ return t.filter((r) => !r.hidden).forEach((r) => {
173
+ if (d <= 0)
174
+ return;
175
+ const p = Math.min(d, Math.round(r.scrollHeight / e));
176
+ a = r.getBoundingClientRect().top - n + p * e, d -= p;
177
+ }), a;
178
+ }
179
+ }
180
+ export {
181
+ B as DisplayConditionsControl
182
+ };