@useinsider/guido 3.26.0 → 3.27.0-beta.3e42e7a
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.
- package/README.md +1 -0
- package/dist/@types/config/schemas.js +91 -89
- package/dist/@types/display-condition.js +25 -0
- package/dist/components/Guido.vue.js +5 -5
- package/dist/components/Guido.vue2.js +95 -90
- package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +17 -0
- package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +41 -0
- package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +30 -0
- package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +81 -0
- package/dist/components/organisms/display-conditions/DisplayConditionListState.vue.js +17 -0
- package/dist/components/organisms/display-conditions/DisplayConditionListState.vue2.js +45 -0
- package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +36 -0
- package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +63 -0
- package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +17 -0
- package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +22 -0
- package/dist/composables/useBlocksConfig.js +29 -20
- package/dist/composables/useDisplayConditions.js +116 -0
- package/dist/composables/useTranslations.js +2 -1
- package/dist/config/compiler/utils/itemsCompilerUtils.js +43 -42
- package/dist/config/compiler/utils/recommendationCompilerUtils.js +67 -64
- package/dist/enums/academy.js +1 -0
- package/dist/enums/display-condition.js +12 -0
- package/dist/extensions/DisplayConditions/bridge.js +25 -0
- package/dist/extensions/DisplayConditions/constants.js +26 -0
- package/dist/extensions/DisplayConditions/control.js +215 -0
- package/dist/extensions/DisplayConditions/display-conditions.css.js +226 -0
- package/dist/extensions/DisplayConditions/extension.js +28 -0
- package/dist/extensions/DisplayConditions/iconsRegistry.js +20 -0
- package/dist/extensions/DisplayConditions/library.js +30 -0
- package/dist/extensions/DisplayConditions/settingsPanel.js +17 -0
- package/dist/guido.css +1 -1
- package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +93 -92
- package/dist/node_modules/valibot/dist/index.js +297 -261
- package/dist/package.json.js +4 -4
- package/dist/services/displayConditionApi.js +39 -0
- package/dist/src/@types/config/schemas.d.ts +4 -0
- package/dist/src/@types/display-condition.d.ts +61 -0
- package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +43 -0
- package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +2 -0
- package/dist/src/components/organisms/display-conditions/DisplayConditionListState.vue.d.ts +18 -0
- package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +2 -0
- package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +2 -0
- package/dist/src/composables/useConfig.d.ts +2 -0
- package/dist/src/composables/useDisplayConditions.d.ts +18 -0
- package/dist/src/enums/academy.d.ts +1 -0
- package/dist/src/enums/display-condition.d.ts +15 -0
- package/dist/src/extensions/DisplayConditions/bridge.d.ts +7 -0
- package/dist/src/extensions/DisplayConditions/constants.d.ts +23 -0
- package/dist/src/extensions/DisplayConditions/control.d.ts +25 -0
- package/dist/src/extensions/DisplayConditions/extension.d.ts +2 -0
- package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +4 -0
- package/dist/src/extensions/DisplayConditions/library.d.ts +8 -0
- package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +5 -0
- package/dist/src/mock/api/display-conditions.d.ts +2 -0
- package/dist/src/services/displayConditionApi.d.ts +8 -0
- package/dist/src/stores/config.d.ts +170 -0
- package/dist/src/stores/display-condition.d.ts +86 -0
- package/dist/src/utils/displayCondition.d.ts +11 -0
- package/dist/src/utils/protectTableText.d.ts +2 -0
- package/dist/static/styles/variables.css.js +1 -0
- package/dist/stores/config.js +13 -6
- package/dist/stores/display-condition.js +29 -0
- package/dist/utils/displayCondition.js +29 -0
- package/dist/utils/pairProductVariables.js +29 -28
- package/dist/utils/protectTableText.js +22 -0
- package/package.json +1 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { useConfig as C } from "../../../composables/useConfig.js";
|
|
2
2
|
import { useRecommendation as O } from "../../../composables/useRecommendation.js";
|
|
3
|
-
import { MOBILE_ROW_SELECTOR as q, MOBILE_CONTAINER_SELECTOR as M, CSS_CLASS_RECO_BUTTON as
|
|
4
|
-
import { useRecommendationExtensionStore as
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import { MOBILE_ROW_SELECTOR as q, MOBILE_CONTAINER_SELECTOR as M, CSS_CLASS_RECO_BUTTON as T } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
|
|
4
|
+
import { useRecommendationExtensionStore as B } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
|
|
5
|
+
import { protectTableText as N, restoreTableText as L } from "../../../utils/protectTableText.js";
|
|
6
|
+
import { isIgnoredRecommendationBlock as P } from "./recommendationIgnoreUtils.js";
|
|
7
|
+
function R(t, r, e, o, c = "") {
|
|
7
8
|
const i = `{{${c}${t}_${r}_${e}}}`, n = `{{${c}${t}_${r}_currency}}`;
|
|
8
9
|
return o === "before" ? `${n} ${i}` : `${i} ${n}`;
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
+
function b(t) {
|
|
11
12
|
let r = t;
|
|
12
13
|
for (; r.children.length === 1; )
|
|
13
14
|
[r] = r.children;
|
|
@@ -19,12 +20,12 @@ function _(t, r, e, o, c, i) {
|
|
|
19
20
|
const n = t.querySelector("img");
|
|
20
21
|
n && (n.setAttribute("src", `{{${i}${e}_${o}_image_url}}`), n.setAttribute("alt", `{{${i}${e}_${o}_name}}`));
|
|
21
22
|
const s = t.querySelector("a");
|
|
22
|
-
s && (s.setAttribute("href", `{{${i}${e}_${o}_url}}`), s.classList.add(
|
|
23
|
+
s && (s.setAttribute("href", `{{${i}${e}_${o}_url}}`), s.classList.add(T));
|
|
23
24
|
break;
|
|
24
25
|
}
|
|
25
26
|
case "productName": {
|
|
26
27
|
const n = t.querySelector("p");
|
|
27
|
-
n && (
|
|
28
|
+
n && (b(n).textContent = `{{${i}${e}_${o}_name}}`);
|
|
28
29
|
break;
|
|
29
30
|
}
|
|
30
31
|
// Inline mode ("Move to next line" OFF) merges BOTH prices into one row
|
|
@@ -32,16 +33,16 @@ function _(t, r, e, o, c, i) {
|
|
|
32
33
|
// substitute by cell content, not by the row's anchor (SD-145161).
|
|
33
34
|
case "productPrice":
|
|
34
35
|
case "productOldPrice": {
|
|
35
|
-
const n = (
|
|
36
|
-
|
|
36
|
+
const n = (l, d) => {
|
|
37
|
+
l && (b(l).textContent = R(
|
|
37
38
|
e,
|
|
38
39
|
o,
|
|
39
|
-
|
|
40
|
+
d,
|
|
40
41
|
c,
|
|
41
42
|
i
|
|
42
43
|
));
|
|
43
|
-
}, s = t.querySelector(".product-price p"),
|
|
44
|
-
n(s ?? (r === "productPrice" ? u : null), "price"), n(
|
|
44
|
+
}, s = t.querySelector(".product-price p"), a = t.querySelector(".product-old-price p"), u = !s && !a ? t.querySelector("p") : null;
|
|
45
|
+
n(s ?? (r === "productPrice" ? u : null), "price"), n(a ?? (r === "productOldPrice" ? u : null), "original_price");
|
|
45
46
|
break;
|
|
46
47
|
}
|
|
47
48
|
case "productButton": {
|
|
@@ -70,72 +71,72 @@ function _(t, r, e, o, c, i) {
|
|
|
70
71
|
default: {
|
|
71
72
|
const n = t.getAttribute("product-attr") ? t : t.querySelector("[product-attr]");
|
|
72
73
|
if (n) {
|
|
73
|
-
const s = n.getAttribute("product-attr"),
|
|
74
|
-
|
|
74
|
+
const s = n.getAttribute("product-attr"), a = n.querySelector("p");
|
|
75
|
+
a && (b(a).textContent = `{{${i}${e}_${o}_${s}}}`);
|
|
75
76
|
}
|
|
76
77
|
break;
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
|
-
const
|
|
81
|
+
const w = "name";
|
|
81
82
|
function y(t, r, e, o) {
|
|
82
|
-
const c = `${o}${r}_${e}_${
|
|
83
|
+
const c = `${o}${r}_${e}_${w}`;
|
|
83
84
|
return {
|
|
84
85
|
open: t.createComment(`{% if ${c} and ${c} != "" %}`),
|
|
85
86
|
close: t.createComment("{% endif %}")
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
|
-
function
|
|
89
|
+
function D(t, r, e) {
|
|
89
90
|
return y(t, r, 0, e);
|
|
90
91
|
}
|
|
91
|
-
function
|
|
92
|
+
function v(t, r, e, o) {
|
|
92
93
|
if (!t.innerHTML.includes("{{"))
|
|
93
94
|
return;
|
|
94
95
|
const { open: c, close: i } = y(t.ownerDocument, r, e, o);
|
|
95
96
|
t.insertBefore(c, t.firstChild), t.appendChild(i);
|
|
96
97
|
}
|
|
97
|
-
function
|
|
98
|
+
function W(t, r, e, o) {
|
|
98
99
|
var n, s;
|
|
99
100
|
if (!t.innerHTML.includes("{{"))
|
|
100
101
|
return;
|
|
101
102
|
const { open: c, close: i } = y(t.ownerDocument, r, e, o);
|
|
102
103
|
(n = t.parentNode) == null || n.insertBefore(c, t), (s = t.parentNode) == null || s.insertBefore(i, t.nextSibling);
|
|
103
104
|
}
|
|
104
|
-
function
|
|
105
|
+
function H(t, r, e, o) {
|
|
105
106
|
t.querySelectorAll(".recommendation-product-row").forEach((i, n) => {
|
|
106
|
-
i.querySelectorAll("[data-attribute-type]").forEach((
|
|
107
|
-
const u =
|
|
108
|
-
|
|
109
|
-
_(
|
|
110
|
-
}) : _(
|
|
111
|
-
}),
|
|
107
|
+
i.querySelectorAll("[data-attribute-type]").forEach((a) => {
|
|
108
|
+
const u = a.getAttribute("data-attribute-type") || "", l = a.querySelectorAll(".attribute-cell");
|
|
109
|
+
l.length > 0 ? l.forEach((d) => {
|
|
110
|
+
_(d, u, r, n, e, o);
|
|
111
|
+
}) : _(a, u, r, n, e, o);
|
|
112
|
+
}), W(i, r, n, o);
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
|
-
function
|
|
115
|
+
function x(t, r, e, o) {
|
|
115
116
|
const c = t.querySelectorAll(".recommendation-product-row");
|
|
116
117
|
if (!c.length)
|
|
117
118
|
return;
|
|
118
119
|
const [i] = c, n = i.querySelector("[data-attribute-type]"), s = n ? n.querySelectorAll(".attribute-cell").length : 1;
|
|
119
|
-
c.forEach((
|
|
120
|
-
|
|
121
|
-
const p =
|
|
122
|
-
|
|
120
|
+
c.forEach((a, u) => {
|
|
121
|
+
a.querySelectorAll("[data-attribute-type]").forEach((d) => {
|
|
122
|
+
const p = d.getAttribute("data-attribute-type") || "";
|
|
123
|
+
d.querySelectorAll(".attribute-cell").forEach((m, h) => {
|
|
123
124
|
const S = u * s + h;
|
|
124
|
-
_(m, p, r, S, e, o),
|
|
125
|
+
_(m, p, r, S, e, o), v(m, r, S, o);
|
|
125
126
|
});
|
|
126
127
|
});
|
|
127
128
|
});
|
|
128
129
|
}
|
|
129
|
-
function
|
|
130
|
+
function F(t, r, e, o) {
|
|
130
131
|
t.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
|
|
131
|
-
|
|
132
|
+
x(i, r, e, o);
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
|
-
function
|
|
135
|
+
function G(t, r, e) {
|
|
135
136
|
const o = t.getAttribute("data-layout") || "grid", c = t.getAttribute("currency-alignment"), i = c === "0" || c === "before" ? "before" : "after";
|
|
136
|
-
o === "list" ?
|
|
137
|
+
o === "list" ? H(t, r, i, e) : F(t, r, i, e);
|
|
137
138
|
}
|
|
138
|
-
function
|
|
139
|
+
function A(t, r, e) {
|
|
139
140
|
const o = new RegExp(`${r}\\s*:\\s*(\\d+)\\s*px`, "i"), c = t.match(o);
|
|
140
141
|
return c ? parseInt(c[1]) : e;
|
|
141
142
|
}
|
|
@@ -150,7 +151,7 @@ function g(t) {
|
|
|
150
151
|
const e = (t.getAttribute("style") || "").match(/(?:^|[;\s])width\s*:\s*(\d+(?:\.\d+)?(?:px|%))/i);
|
|
151
152
|
return e && $(e[1]) ? e[1] : null;
|
|
152
153
|
}
|
|
153
|
-
function
|
|
154
|
+
function V(t, r) {
|
|
154
155
|
let e = t.parentElement;
|
|
155
156
|
for (; e && e !== r; ) {
|
|
156
157
|
if (e.tagName === "TD" && g(e))
|
|
@@ -159,62 +160,64 @@ function x(t, r) {
|
|
|
159
160
|
}
|
|
160
161
|
return null;
|
|
161
162
|
}
|
|
162
|
-
function
|
|
163
|
-
const r = t.getAttribute("style") || "", e =
|
|
163
|
+
function U(t) {
|
|
164
|
+
const r = t.getAttribute("style") || "", e = A(r, "width", 600), o = A(r, "padding", 0) * 2, c = Math.max(0, e - o);
|
|
164
165
|
c !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
|
|
165
166
|
if (i.hasAttribute("width"))
|
|
166
167
|
return;
|
|
167
|
-
const n =
|
|
168
|
+
const n = V(i, t);
|
|
168
169
|
if (!n)
|
|
169
170
|
return;
|
|
170
|
-
const s = g(n),
|
|
171
|
+
const s = g(n), a = A(n.getAttribute("style") || "", "padding", 0) * 2, u = s.endsWith("%") ? Math.floor(c * parseFloat(s) / 100) : parseInt(s), l = Math.max(1, u - a), d = i.getAttribute("style") || "", p = /(?:^|[;\s])max-height\s*:\s*(\d+(?:\.\d+)?)px/i.exec(d);
|
|
171
172
|
if (p) {
|
|
172
|
-
i.setAttribute("width", String(Math.max(1, Math.min(
|
|
173
|
+
i.setAttribute("width", String(Math.max(1, Math.min(l, Math.floor(parseFloat(p[1])))))), i.removeAttribute("height");
|
|
173
174
|
return;
|
|
174
175
|
}
|
|
175
|
-
if (i.setAttribute("width", String(
|
|
176
|
-
const f =
|
|
177
|
-
i.setAttribute("style", `${
|
|
176
|
+
if (i.setAttribute("width", String(l)), !/\bwidth\s*:\s*\d/i.test(d)) {
|
|
177
|
+
const f = d && !d.trim().endsWith(";") ? "; " : "";
|
|
178
|
+
i.setAttribute("style", `${d}${f}width: ${l}px`);
|
|
178
179
|
}
|
|
179
180
|
});
|
|
180
181
|
}
|
|
181
|
-
const E = "MSO_MOBILE_HIDE_START",
|
|
182
|
-
function
|
|
182
|
+
const E = "MSO_MOBILE_HIDE_START", X = "MSO_MOBILE_HIDE_END";
|
|
183
|
+
function j(t, r) {
|
|
183
184
|
t.querySelectorAll(q).forEach((e) => {
|
|
184
185
|
var i, n;
|
|
185
186
|
const o = e.querySelector(M);
|
|
186
187
|
if (!o || o.children.length === 0)
|
|
187
188
|
return;
|
|
188
189
|
const c = e.previousSibling;
|
|
189
|
-
(c == null ? void 0 : c.nodeType) === Node.COMMENT_NODE && c.data === E || ((i = e.parentNode) == null || i.insertBefore(r.createComment(E), e), (n = e.parentNode) == null || n.insertBefore(r.createComment(
|
|
190
|
+
(c == null ? void 0 : c.nodeType) === Node.COMMENT_NODE && c.data === E || ((i = e.parentNode) == null || i.insertBefore(r.createComment(E), e), (n = e.parentNode) == null || n.insertBefore(r.createComment(X), e.nextSibling));
|
|
190
191
|
});
|
|
191
192
|
}
|
|
192
|
-
function
|
|
193
|
+
function Y(t, r) {
|
|
193
194
|
const e = t.match(/<!DOCTYPE[^>]*>/i);
|
|
194
195
|
return (e ? `${e[0]}
|
|
195
196
|
` : "") + r.documentElement.outerHTML;
|
|
196
197
|
}
|
|
197
|
-
function
|
|
198
|
-
const r = t.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(r, "text/html"), o = e.querySelectorAll(".recommendation-block-v2");
|
|
198
|
+
function I(t) {
|
|
199
|
+
const r = N(t).replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(r, "text/html"), o = e.querySelectorAll(".recommendation-block-v2");
|
|
199
200
|
if (!o.length)
|
|
200
201
|
return t;
|
|
201
|
-
const { buildCampaignUrl: c } = O(), i =
|
|
202
|
+
const { buildCampaignUrl: c } = O(), i = B();
|
|
202
203
|
i.recommendationCampaignUrls = {};
|
|
203
204
|
const { isFeatureEnabled: n } = C(), s = n("liquidSyntax") ? "reco_" : "";
|
|
204
|
-
|
|
205
|
-
var
|
|
206
|
-
const
|
|
207
|
-
if (
|
|
208
|
-
if ((
|
|
209
|
-
|
|
210
|
-
const { open: h, close: S } =
|
|
205
|
+
o.forEach((u) => {
|
|
206
|
+
var d, p, f, m;
|
|
207
|
+
const l = u.getAttribute("recommendation-id");
|
|
208
|
+
if (l) {
|
|
209
|
+
if ((d = u.parentNode) == null || d.insertBefore(e.createComment("REC_START"), u), (p = u.parentNode) == null || p.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((h) => h.remove()), c(l), j(u, e), !P(u)) {
|
|
210
|
+
G(u, l, s);
|
|
211
|
+
const { open: h, close: S } = D(e, l, s);
|
|
211
212
|
(f = u.parentNode) == null || f.insertBefore(h, u), (m = u.parentNode) == null || m.insertBefore(S, u.nextSibling);
|
|
212
213
|
}
|
|
213
|
-
|
|
214
|
+
U(u);
|
|
214
215
|
}
|
|
215
|
-
})
|
|
216
|
+
});
|
|
217
|
+
const a = Y(r, e);
|
|
218
|
+
return L(a.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}"));
|
|
216
219
|
}
|
|
217
220
|
export {
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
R as formatPriceVariable,
|
|
222
|
+
I as prepareRecommendationBlocks
|
|
220
223
|
};
|
package/dist/enums/academy.js
CHANGED
|
@@ -2,6 +2,7 @@ const e = "https://academy.insiderone.com", o = {
|
|
|
2
2
|
EMAIL_EDITOR: `${e}/docs/email-drag-and-drop-editor`,
|
|
3
3
|
GLOBAL_UNSUBSCRIBE: `${e}/docs/global-unsubscribe-preference-center`,
|
|
4
4
|
AMP_FOR_EMAILS: `${e}/docs/amp-for-emails`,
|
|
5
|
+
EMAIL_DISPLAY_CONDITIONS: `${e}/docs/new-editor-add-display-conditions-to-an-email`,
|
|
5
6
|
EMAIL_RECOMMENDATION_BLOCK: `${e}/docs/new-editor-email-recommendation-block`,
|
|
6
7
|
LEGACY_UNSUBSCRIBE_MODULE: `${e}/docs/new-editor-add-unsubscribe-pages-into-emails`
|
|
7
8
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var N = /* @__PURE__ */ ((I) => (I.OPEN = "display-condition:open", I.APPLY = "display-condition:apply", I.CANCEL = "display-condition:cancel", I))(N || {}), A = /* @__PURE__ */ ((I) => (I.INLINE = "inline", I.SAVED = "saved", I))(A || {});
|
|
2
|
+
const M = {
|
|
3
|
+
NAME_MIN: 2,
|
|
4
|
+
NAME_MAX: 40,
|
|
5
|
+
DESCRIPTION_MAX: 200,
|
|
6
|
+
CODE_MAX: 65535
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
M as DISPLAY_CONDITION_LIMITS,
|
|
10
|
+
N as DisplayConditionEvent,
|
|
11
|
+
A as DisplayConditionSourceType
|
|
12
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DisplayConditionEvent as i } from "../../enums/display-condition.js";
|
|
2
|
+
let n = null;
|
|
3
|
+
const d = () => {
|
|
4
|
+
n == null || n.detach();
|
|
5
|
+
}, L = (p, e) => {
|
|
6
|
+
var C;
|
|
7
|
+
const t = n;
|
|
8
|
+
t == null || t.detach(), (C = t == null ? void 0 : t.onCancel) == null || C.call(t);
|
|
9
|
+
let o = () => {
|
|
10
|
+
};
|
|
11
|
+
const l = (c) => {
|
|
12
|
+
const m = c.detail;
|
|
13
|
+
o(), m.applied = e.onApply(m.condition);
|
|
14
|
+
}, a = () => {
|
|
15
|
+
var c;
|
|
16
|
+
o(), (c = e.onCancel) == null || c.call(e);
|
|
17
|
+
};
|
|
18
|
+
return o = () => {
|
|
19
|
+
document.removeEventListener(i.APPLY, l), document.removeEventListener(i.CANCEL, a), (n == null ? void 0 : n.detach) === o && (n = null);
|
|
20
|
+
}, document.addEventListener(i.APPLY, l), document.addEventListener(i.CANCEL, a), n = { detach: o, onCancel: e.onCancel }, document.dispatchEvent(new CustomEvent(i.OPEN, { detail: p })), o;
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
d as disposeDisplayConditionRequest,
|
|
24
|
+
L as requestDisplayCondition
|
|
25
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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", d = 10, s = [o.STRIPE, o.STRUCTURE, o.CONTAINER], c = {
|
|
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 = {
|
|
8
|
+
ADD: "guidoDisplayConditionAdd",
|
|
9
|
+
CREATE: "guidoDisplayConditionCreate",
|
|
10
|
+
SELECT: "guidoDisplayConditionSelect",
|
|
11
|
+
SHOW_MORE: "guidoDisplayConditionShowMore",
|
|
12
|
+
SHOW_LESS: "guidoDisplayConditionShowLess",
|
|
13
|
+
EDIT: "guidoDisplayConditionEdit",
|
|
14
|
+
REMOVE: "guidoDisplayConditionRemove"
|
|
15
|
+
}, C = ["applyConditionSwitcher", "applyCondition", "displayConditions"], a = "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.";
|
|
16
|
+
export {
|
|
17
|
+
O as APPLIED_DESCRIPTION,
|
|
18
|
+
C as BUILT_IN_CONDITION_CONTROLS,
|
|
19
|
+
t as CONDITIONS_CONTROL_ID,
|
|
20
|
+
n as CONDITIONS_TAB_ID,
|
|
21
|
+
s as CONDITION_BLOCK_TYPES,
|
|
22
|
+
e as CONDITION_BUTTONS,
|
|
23
|
+
c as CONDITION_ICONS,
|
|
24
|
+
a as EMPTY_DESCRIPTION,
|
|
25
|
+
d as MAX_COLLAPSED_LINES
|
|
26
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var v = (c, a, i) => a in c ? b(c, a, { enumerable: !0, configurable: !0, writable: !0, value: i }) : c[a] = i;
|
|
3
|
+
var u = (c, a, i) => v(c, typeof a != "symbol" ? a + "" : a, i);
|
|
4
|
+
import { useToaster as O } from "../../composables/useToaster.js";
|
|
5
|
+
import { useTranslations as w } from "../../composables/useTranslations.js";
|
|
6
|
+
import { DisplayConditionSourceType as N } from "../../enums/display-condition.js";
|
|
7
|
+
import { ToasterTypeOptions as S } from "../../enums/toaster.js";
|
|
8
|
+
import { CommonControl as E } from "../Blocks/common-control.js";
|
|
9
|
+
import { toAppliedCondition as D, parseSource as T } from "../../utils/displayCondition.js";
|
|
10
|
+
import { escapeHtml as f } from "../../utils/htmlEscape.js";
|
|
11
|
+
import { ModificationDescription as I } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
12
|
+
import { requestDisplayCondition as M } from "./bridge.js";
|
|
13
|
+
import { CONDITIONS_CONTROL_ID as $, CONDITION_ICONS as h, CONDITION_BUTTONS as r, APPLIED_DESCRIPTION as x, EMPTY_DESCRIPTION as L, MAX_COLLAPSED_LINES as C } from "./constants.js";
|
|
14
|
+
const l = ".guido-display-conditions", R = { id: 0, name: "", description: "", beforeScript: "", afterScript: "" };
|
|
15
|
+
class F extends E {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
u(this, "expanded", !1);
|
|
19
|
+
u(this, "listeners", []);
|
|
20
|
+
u(this, "resizeObserver", null);
|
|
21
|
+
u(this, "detachOutsideClick", null);
|
|
22
|
+
}
|
|
23
|
+
getId() {
|
|
24
|
+
return $;
|
|
25
|
+
}
|
|
26
|
+
getTemplate() {
|
|
27
|
+
return `
|
|
28
|
+
<div class="guido-display-conditions">
|
|
29
|
+
<div class="guido-display-conditions__header">
|
|
30
|
+
<p class="guido-display-conditions__title">${this.api.translate("Display Conditions")}</p>
|
|
31
|
+
<p class="guido-display-conditions__description" data-dc-description></p>
|
|
32
|
+
</div>
|
|
33
|
+
<div class="guido-display-conditions__empty" data-dc-empty>
|
|
34
|
+
${this._GuButton({
|
|
35
|
+
name: r.ADD,
|
|
36
|
+
id: "guido__btn-add-display-condition",
|
|
37
|
+
className: "guido-display-conditions__add",
|
|
38
|
+
icon: h.PLUS,
|
|
39
|
+
label: this.api.translate("Add Display Condition")
|
|
40
|
+
})}
|
|
41
|
+
<div class="guido-display-conditions__menu" data-dc-menu hidden>
|
|
42
|
+
${this._GuButton({
|
|
43
|
+
name: r.CREATE,
|
|
44
|
+
id: "guido__btn-display-condition-create",
|
|
45
|
+
className: "guido-display-conditions__menu-item",
|
|
46
|
+
label: this.api.translate("Create New Condition")
|
|
47
|
+
})}
|
|
48
|
+
${this._GuButton({
|
|
49
|
+
name: r.SELECT,
|
|
50
|
+
id: "guido__btn-display-condition-select",
|
|
51
|
+
className: "guido-display-conditions__menu-item",
|
|
52
|
+
label: this.api.translate("Select Saved Condition")
|
|
53
|
+
})}
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
<div class="guido-display-conditions__applied" data-dc-applied hidden>
|
|
57
|
+
<div class="guido-display-conditions__code-box">
|
|
58
|
+
<p class="guido-display-conditions__name" data-dc-name></p>
|
|
59
|
+
<div class="guido-display-conditions__sections" data-dc-sections>
|
|
60
|
+
<p class="guido-display-conditions__section-label">
|
|
61
|
+
${this.api.translate("Code Before Module")}
|
|
62
|
+
</p>
|
|
63
|
+
<pre class="guido-display-conditions__code" data-dc-before></pre>
|
|
64
|
+
<p class="guido-display-conditions__section-label" data-dc-after-label>
|
|
65
|
+
${this.api.translate("Code After Module")}
|
|
66
|
+
</p>
|
|
67
|
+
<pre class="guido-display-conditions__code" data-dc-after></pre>
|
|
68
|
+
</div>
|
|
69
|
+
${this._GuButton({
|
|
70
|
+
name: r.SHOW_MORE,
|
|
71
|
+
id: "guido__btn-display-condition-show-more",
|
|
72
|
+
className: "guido-display-conditions__toggle",
|
|
73
|
+
icon: h.CHEVRON,
|
|
74
|
+
label: this.api.translate("Show More")
|
|
75
|
+
})}
|
|
76
|
+
${this._GuButton({
|
|
77
|
+
name: r.SHOW_LESS,
|
|
78
|
+
id: "guido__btn-display-condition-show-less",
|
|
79
|
+
className: "guido-display-conditions__toggle guido-display-conditions__toggle--less",
|
|
80
|
+
icon: h.CHEVRON,
|
|
81
|
+
label: this.api.translate("Show Less")
|
|
82
|
+
})}
|
|
83
|
+
</div>
|
|
84
|
+
<div class="guido-display-conditions__actions">
|
|
85
|
+
${this._GuButton({
|
|
86
|
+
name: r.EDIT,
|
|
87
|
+
id: "guido__btn-edit-display-condition",
|
|
88
|
+
className: "guido-display-conditions__action guido-display-conditions__action--edit",
|
|
89
|
+
icon: h.EDIT,
|
|
90
|
+
label: this.api.translate("Edit")
|
|
91
|
+
})}
|
|
92
|
+
${this._GuButton({
|
|
93
|
+
name: r.REMOVE,
|
|
94
|
+
id: "guido__btn-remove-display-condition",
|
|
95
|
+
className: "guido-display-conditions__action guido-display-conditions__action--remove",
|
|
96
|
+
icon: h.TRASH,
|
|
97
|
+
label: this.api.translate("Remove")
|
|
98
|
+
})}
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
`;
|
|
103
|
+
}
|
|
104
|
+
onRender() {
|
|
105
|
+
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.removeCondition()), this.wire("#guido__btn-display-condition-show-more", () => this.setExpanded(!0)), this.wire("#guido__btn-display-condition-show-less", () => this.setExpanded(!1)), this.observeCodeSize();
|
|
106
|
+
}
|
|
107
|
+
onTemplateNodeUpdated(i) {
|
|
108
|
+
const t = i !== this.currentNode;
|
|
109
|
+
super.onTemplateNodeUpdated(i), t && (this.expanded = !1, this.toggleMenu(!1)), this.paint();
|
|
110
|
+
}
|
|
111
|
+
onDestroy() {
|
|
112
|
+
super.onDestroy(), this.teardown();
|
|
113
|
+
}
|
|
114
|
+
setExpanded(i) {
|
|
115
|
+
this.expanded = i, this.paint();
|
|
116
|
+
}
|
|
117
|
+
getCondition() {
|
|
118
|
+
var t;
|
|
119
|
+
const i = this.currentNode;
|
|
120
|
+
return D((t = i == null ? void 0 : i.getDisplayCondition) == null ? void 0 : t.call(i));
|
|
121
|
+
}
|
|
122
|
+
toggleMenu(i) {
|
|
123
|
+
var o, s, n;
|
|
124
|
+
const t = (o = this.getContainer()) == null ? void 0 : o.querySelector(`${l} [data-dc-menu]`);
|
|
125
|
+
if (!t)
|
|
126
|
+
return;
|
|
127
|
+
t.hidden = i === void 0 ? !t.hidden : !i, (s = this.detachOutsideClick) == null || s.call(this), t.hidden || this.listenOutsideClick();
|
|
128
|
+
const e = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${l} #guido__btn-add-display-condition`);
|
|
129
|
+
t.style.width = !t.hidden && e ? `${e.getBoundingClientRect().width}px` : "";
|
|
130
|
+
}
|
|
131
|
+
listenOutsideClick() {
|
|
132
|
+
var e;
|
|
133
|
+
const i = ((e = this.getContainer()) == null ? void 0 : e.ownerDocument) ?? document, t = (o) => {
|
|
134
|
+
o.composedPath().some((n) => n instanceof HTMLElement && n.matches(`${l} [data-dc-menu], ${l} #guido__btn-add-display-condition`)) || this.toggleMenu(!1);
|
|
135
|
+
};
|
|
136
|
+
i.addEventListener("pointerdown", t, !0), this.detachOutsideClick = () => {
|
|
137
|
+
i.removeEventListener("pointerdown", t, !0), this.detachOutsideClick = null;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
openDrawer(i) {
|
|
141
|
+
const t = this.currentNode;
|
|
142
|
+
this.toggleMenu(!1), M(
|
|
143
|
+
{ mode: i, current: i === "edit" ? this.getCondition() : null },
|
|
144
|
+
{ onApply: (e) => this.applyCondition(e, t) }
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
// The drawer flows toast through useDisplayConditions; Remove has no drawer, so it toasts here.
|
|
148
|
+
removeCondition() {
|
|
149
|
+
this.applyCondition(null) || O().showToaster({
|
|
150
|
+
type: S.Error,
|
|
151
|
+
message: w()("products.something-went-wrong")
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
// The panel can move to another block while the drawer is open; apply onto the block it was opened for.
|
|
155
|
+
applyCondition(i, t = this.currentNode) {
|
|
156
|
+
if (!t)
|
|
157
|
+
return !1;
|
|
158
|
+
try {
|
|
159
|
+
const e = this.api.getDocumentModifier().modifyHtml(t);
|
|
160
|
+
return e.setDisplayCondition(i || R), e.apply(new I(
|
|
161
|
+
i ? `Set display condition ${i.name}` : "Remove display condition"
|
|
162
|
+
)), !0;
|
|
163
|
+
} catch (e) {
|
|
164
|
+
return console.warn("Display condition could not be applied.", e), !1;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
wire(i, t) {
|
|
168
|
+
var o;
|
|
169
|
+
const e = (o = this.getContainer()) == null ? void 0 : o.querySelector(`${l} ${i}`);
|
|
170
|
+
e && (e.addEventListener("click", t), this.listeners.push({ element: e, handler: t }));
|
|
171
|
+
}
|
|
172
|
+
teardown() {
|
|
173
|
+
var i, t;
|
|
174
|
+
this.listeners.forEach(({ element: e, handler: o }) => e.removeEventListener("click", o)), this.listeners = [], (i = this.resizeObserver) == null || i.disconnect(), this.resizeObserver = null, (t = this.detachOutsideClick) == null || t.call(this);
|
|
175
|
+
}
|
|
176
|
+
// Line counts depend on layout: the panel font loads late and the panel can be resized.
|
|
177
|
+
observeCodeSize() {
|
|
178
|
+
var t;
|
|
179
|
+
const i = (t = this.getContainer()) == null ? void 0 : t.querySelectorAll(`${l} .guido-display-conditions__code`);
|
|
180
|
+
!(i != null && i.length) || typeof ResizeObserver > "u" || (this.resizeObserver = new ResizeObserver(() => this.paint()), i.forEach((e) => {
|
|
181
|
+
var o;
|
|
182
|
+
return (o = this.resizeObserver) == null ? void 0 : o.observe(e);
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
paint() {
|
|
186
|
+
var y;
|
|
187
|
+
const i = (y = this.getContainer()) == null ? void 0 : y.querySelector(l);
|
|
188
|
+
if (!i)
|
|
189
|
+
return;
|
|
190
|
+
const t = this.getCondition(), e = (_) => i.querySelector(_);
|
|
191
|
+
if (e("[data-dc-empty]").hidden = !!t, e("[data-dc-applied]").hidden = !t, e("[data-dc-description]").textContent = this.api.translate(t ? x : L), !t)
|
|
192
|
+
return;
|
|
193
|
+
e("[data-dc-name]").textContent = t.name;
|
|
194
|
+
const o = T(t) === N.INLINE;
|
|
195
|
+
e("#guido__btn-edit-display-condition").hidden = !o;
|
|
196
|
+
const s = e("[data-dc-sections]"), n = e("[data-dc-before]"), d = e("[data-dc-after]");
|
|
197
|
+
n.innerHTML = f(t.beforeScript), d.innerHTML = f(t.afterScript), d.hidden = !t.afterScript, e("[data-dc-after-label]").hidden = !t.afterScript, s.style.maxHeight = "";
|
|
198
|
+
const p = parseFloat(getComputedStyle(n).lineHeight) || 24, m = (_) => _.hidden ? 0 : Math.round(_.scrollHeight / p), g = m(n) + m(d) > C;
|
|
199
|
+
e("#guido__btn-display-condition-show-more").hidden = !g || this.expanded, e("#guido__btn-display-condition-show-less").hidden = !g || !this.expanded, g && !this.expanded && (s.style.maxHeight = `${this.collapsedHeight(s, [n, d], p)}px`);
|
|
200
|
+
}
|
|
201
|
+
// Labels do not count toward the line limit, so the cut lands after the 10th rendered code line.
|
|
202
|
+
collapsedHeight(i, t, e) {
|
|
203
|
+
const { top: o } = i.getBoundingClientRect();
|
|
204
|
+
let s = C, n = 0;
|
|
205
|
+
return t.filter((d) => !d.hidden).forEach((d) => {
|
|
206
|
+
if (s <= 0)
|
|
207
|
+
return;
|
|
208
|
+
const p = Math.min(s, Math.round(d.scrollHeight / e));
|
|
209
|
+
n = d.getBoundingClientRect().top - o + p * e, s -= p;
|
|
210
|
+
}), n;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export {
|
|
214
|
+
F as DisplayConditionsControl
|
|
215
|
+
};
|