@useinsider/guido 3.24.0-beta.adaba3e → 3.24.0-beta.e2e5de9

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 (78) hide show
  1. package/README.md +6 -2
  2. package/dist/@types/config/schemas.js +37 -39
  3. package/dist/components/Guido.vue.js +4 -4
  4. package/dist/components/Guido.vue2.js +92 -98
  5. package/dist/composables/useActionsApi.js +2 -2
  6. package/dist/composables/useBlocksConfig.js +20 -31
  7. package/dist/composables/useEditorTrackingIds.js +49 -0
  8. package/dist/composables/useHtmlCompiler.js +2 -0
  9. package/dist/composables/useStripo.js +70 -70
  10. package/dist/composables/useTranslations.js +1 -2
  11. package/dist/config/compiler/htmlCompilerRules.js +14 -6
  12. package/dist/config/compiler/utils/itemsCompilerUtils.js +42 -43
  13. package/dist/config/compiler/utils/recommendationCompilerUtils.js +64 -67
  14. package/dist/enums/academy.js +0 -1
  15. package/dist/guido.css +1 -1
  16. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +92 -93
  17. package/dist/node_modules/valibot/dist/index.js +261 -297
  18. package/dist/package.json.js +5 -5
  19. package/dist/src/@types/config/schemas.d.ts +0 -4
  20. package/dist/src/composables/useConfig.d.ts +0 -2
  21. package/dist/src/composables/useEditorTrackingIds.d.ts +7 -0
  22. package/dist/src/composables/useStripo.d.ts +1 -1
  23. package/dist/src/enums/academy.d.ts +0 -1
  24. package/dist/src/stores/config.d.ts +0 -167
  25. package/dist/src/utils/linkTrackingIds.d.ts +24 -22
  26. package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
  27. package/dist/stores/config.js +6 -13
  28. package/dist/utils/linkTrackingIds.js +72 -72
  29. package/dist/utils/pairProductVariables.js +29 -30
  30. package/dist/utils/templatePreparation.js +59 -72
  31. package/dist/utils/trimHrefWhitespace.js +10 -0
  32. package/package.json +1 -1
  33. package/dist/@types/display-condition.js +0 -25
  34. package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +0 -18
  35. package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +0 -41
  36. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +0 -30
  37. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +0 -81
  38. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +0 -34
  39. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +0 -63
  40. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +0 -17
  41. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +0 -22
  42. package/dist/composables/useDisplayConditions.js +0 -117
  43. package/dist/enums/display-condition.js +0 -12
  44. package/dist/extensions/DisplayConditions/bridge.js +0 -25
  45. package/dist/extensions/DisplayConditions/constants.js +0 -17
  46. package/dist/extensions/DisplayConditions/control.js +0 -200
  47. package/dist/extensions/DisplayConditions/display-conditions.css.js +0 -201
  48. package/dist/extensions/DisplayConditions/extension.js +0 -28
  49. package/dist/extensions/DisplayConditions/iconsRegistry.js +0 -20
  50. package/dist/extensions/DisplayConditions/library.js +0 -30
  51. package/dist/extensions/DisplayConditions/settingsPanel.js +0 -17
  52. package/dist/extensions/LinkTracking/extension.js +0 -17
  53. package/dist/extensions/LinkTracking/writer.js +0 -41
  54. package/dist/services/displayConditionApi.js +0 -39
  55. package/dist/src/@types/display-condition.d.ts +0 -59
  56. package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +0 -43
  57. package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +0 -2
  58. package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +0 -2
  59. package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +0 -2
  60. package/dist/src/composables/useDisplayConditions.d.ts +0 -18
  61. package/dist/src/enums/display-condition.d.ts +0 -15
  62. package/dist/src/extensions/DisplayConditions/bridge.d.ts +0 -7
  63. package/dist/src/extensions/DisplayConditions/constants.d.ts +0 -14
  64. package/dist/src/extensions/DisplayConditions/control.d.ts +0 -25
  65. package/dist/src/extensions/DisplayConditions/extension.d.ts +0 -2
  66. package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +0 -4
  67. package/dist/src/extensions/DisplayConditions/library.d.ts +0 -8
  68. package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +0 -5
  69. package/dist/src/extensions/LinkTracking/extension.d.ts +0 -2
  70. package/dist/src/extensions/LinkTracking/writer.d.ts +0 -13
  71. package/dist/src/mock/api/display-conditions.d.ts +0 -2
  72. package/dist/src/services/displayConditionApi.d.ts +0 -8
  73. package/dist/src/stores/display-condition.d.ts +0 -84
  74. package/dist/src/utils/displayCondition.d.ts +0 -11
  75. package/dist/src/utils/protectTableText.d.ts +0 -2
  76. package/dist/stores/display-condition.js +0 -29
  77. package/dist/utils/displayCondition.js +0 -26
  78. package/dist/utils/protectTableText.js +0 -22
@@ -1,63 +0,0 @@
1
- import { defineComponent as x, ref as a, watch as D, computed as r, onBeforeUnmount as M } from "vue";
2
- import b from "../../wrappers/WpDrawer.vue.js";
3
- import h from "../../wrappers/WpModal.vue.js";
4
- import { useDisplayConditions as C, DISPLAY_CONDITIONS_TRANS_KEY as c } from "../../../composables/useDisplayConditions.js";
5
- import { useTranslations as w } from "../../../composables/useTranslations.js";
6
- import { useDisplayConditionStore as k } from "../../../stores/display-condition.js";
7
- import { InSkeleton as A, InNoData as N, InIcons as $, InButtonV2 as K, InBasicTextInput as P } from "@useinsider/design-system-vue";
8
- const Q = /* @__PURE__ */ x({
9
- __name: "DisplayConditionSelectDrawer",
10
- setup(W) {
11
- const I = [40, 76, 76, 76], l = w(), t = k(), { loadList: m, select: y, deleteSaved: f, cancel: _, describeWithAcademyLink: v } = C(), u = a(""), i = a(null), n = a(null), o = a(!1);
12
- D(() => t.isSelectOpen, (e) => {
13
- e && (u.value = "", i.value = null, n.value = null, m());
14
- }, { immediate: !0 });
15
- const O = r(() => {
16
- const e = u.value.trim().toLocaleLowerCase();
17
- return e ? t.list.filter((d) => `${d.name} ${d.description}`.toLocaleLowerCase().includes(e)) : t.list;
18
- }), S = r(() => v("select-description")), B = r(() => ({
19
- cancelOrBackButton: {
20
- styling: "ghost",
21
- type: "secondary",
22
- labelText: l(`${c}.back`),
23
- leftIcon: "line-arrow-left"
24
- }
25
- })), L = r(() => ({
26
- cancelOrBackButton: {
27
- type: "secondary",
28
- styling: "ghost",
29
- labelText: l(`${c}.cancel`),
30
- disabledStatus: o.value
31
- },
32
- primaryButton: {
33
- type: "danger",
34
- labelText: l(`${c}.delete`),
35
- loadingStatus: o.value
36
- }
37
- })), E = (e) => {
38
- i.value = i.value === e.id ? null : e.id;
39
- }, T = (e) => {
40
- n.value = n.value === e.id ? null : e.id;
41
- }, s = (e) => {
42
- e.composedPath().some((p) => {
43
- var g;
44
- return p instanceof Element && p.matches(".guido-display-condition-card__split") && ((g = p.closest(".guido-display-condition-card")) == null ? void 0 : g.getAttribute("data-condition-id")) === String(n.value);
45
- }) || (n.value = null);
46
- };
47
- return D(n, (e) => {
48
- e === null ? document.removeEventListener("pointerdown", s, !0) : document.addEventListener("pointerdown", s, !0);
49
- }), M(() => {
50
- document.removeEventListener("pointerdown", s, !0);
51
- }), { __sfc: !0, SKELETON_HEIGHTS: I, trans: l, store: t, loadList: m, select: y, deleteSaved: f, cancel: _, describeWithAcademyLink: v, search: u, expandedId: i, menuId: n, isDeleting: o, filteredList: O, descriptionText: S, footerButtonGroupOptions: B, deleteModalButtons: L, toggleExpanded: E, toggleMenu: T, closeMenuOnOutsidePointer: s, requestDelete: (e) => {
52
- n.value = null, t.pendingDelete = e;
53
- }, confirmDelete: async () => {
54
- !t.pendingDelete || o.value || (o.value = !0, await f(t.pendingDelete), o.value = !1);
55
- }, closeDeleteModal: () => {
56
- o.value || (t.pendingDelete = null);
57
- }, codeOf: (e) => [e.codeBefore, e.codeAfter].filter(Boolean).join(`
58
- `), WpDrawer: b, WpModal: h, KEY: c, InBasicTextInput: P, InButtonV2: K, InIcons: $, InNoData: N, InSkeleton: A };
59
- }
60
- });
61
- export {
62
- Q as default
63
- };
@@ -1,17 +0,0 @@
1
- import e from "./DisplayConditionsHost.vue2.js";
2
- import n from "../../../_virtual/_plugin-vue2_normalizer.js";
3
- var r = function() {
4
- var s = this, o = s._self._c, t = s._self._setupProxy;
5
- return o("div", { staticClass: "guido-display-conditions-host" }, [o(t.DisplayConditionCreateDrawer), o(t.DisplayConditionSelectDrawer)], 1);
6
- }, i = [], a = /* @__PURE__ */ n(
7
- e,
8
- r,
9
- i,
10
- !1,
11
- null,
12
- null
13
- );
14
- const p = a.exports;
15
- export {
16
- p as default
17
- };
@@ -1,22 +0,0 @@
1
- import { defineComponent as i, onMounted as s, onBeforeUnmount as m } from "vue";
2
- import { useDisplayConditions as p } from "../../../composables/useDisplayConditions.js";
3
- import { DisplayConditionEvent as n } from "../../../enums/display-condition.js";
4
- import { useDisplayConditionStore as a } from "../../../stores/display-condition.js";
5
- import d from "./DisplayConditionCreateDrawer.vue.js";
6
- import f from "./DisplayConditionSelectDrawer.vue.js";
7
- const E = /* @__PURE__ */ i({
8
- __name: "DisplayConditionsHost",
9
- setup(l) {
10
- const o = a(), { handleOpen: t } = p(), e = (r) => {
11
- t(r.detail);
12
- };
13
- return s(() => {
14
- o.$reset(), document.addEventListener(n.OPEN, e);
15
- }), m(() => {
16
- document.removeEventListener(n.OPEN, e), o.$reset();
17
- }), { __sfc: !0, store: o, handleOpen: t, onOpen: e, DisplayConditionCreateDrawer: d, DisplayConditionSelectDrawer: f };
18
- }
19
- });
20
- export {
21
- E as default
22
- };
@@ -1,117 +0,0 @@
1
- import { useToaster as M } from "./useToaster.js";
2
- import { useTranslations as x } from "./useTranslations.js";
3
- import { ACADEMY_LINKS as L } from "../enums/academy.js";
4
- import { DisplayConditionSourceType as y, DISPLAY_CONDITION_LIMITS as s, DisplayConditionEvent as I } from "../enums/display-condition.js";
5
- import { ToasterTypeOptions as l } from "../enums/toaster.js";
6
- import { useDisplayConditionApi as O } from "../services/displayConditionApi.js";
7
- import { useConfigStore as q } from "../stores/config.js";
8
- import { useDisplayConditionStore as P } from "../stores/display-condition.js";
9
- import { findInvalidCodeFields as Y, nextConditionId as w } from "../utils/displayCondition.js";
10
- import { escapeHtml as R } from "../utils/htmlEscape.js";
11
- import { computed as B } from "vue";
12
- const X = "email-editor.display-conditions", i = X, b = 409, S = (n, m, r) => ({
13
- id: w(),
14
- name: n.name.trim(),
15
- description: n.description.trim(),
16
- beforeScript: n.codeBefore,
17
- afterScript: n.codeAfter,
18
- extraData: JSON.stringify(r === void 0 ? { source: m } : { source: m, savedId: r })
19
- }), v = (n) => ({
20
- name: n.name,
21
- description: n.description,
22
- codeBefore: n.codeBefore,
23
- codeAfter: n.codeAfter
24
- }), ne = () => {
25
- const n = P(), m = q(), r = O(), o = x(), { showToaster: p } = M(), u = B(() => {
26
- var e;
27
- return (e = m.features) != null && e.liquidSyntax ? "liquid" : "pongo";
28
- }), f = (e) => {
29
- const t = { condition: e };
30
- return document.dispatchEvent(new CustomEvent(I.APPLY, { detail: t })), n.close(), t.applied === !0;
31
- }, D = () => {
32
- n.view !== "none" && (document.dispatchEvent(new CustomEvent(I.CANCEL)), n.close());
33
- }, N = (e) => {
34
- if (e.mode === "select") {
35
- n.openSelect();
36
- return;
37
- }
38
- n.openCreate(e.mode === "edit" ? e.current : null);
39
- }, $ = async () => {
40
- const e = ++n.listRequest;
41
- n.listStatus = "loading";
42
- try {
43
- const t = await r.list(u.value);
44
- e === n.listRequest && (n.list = t, n.listStatus = "loaded");
45
- } catch (t) {
46
- console.warn("Display conditions could not be loaded.", t), e === n.listRequest && (n.listStatus = "error");
47
- }
48
- }, h = (e) => {
49
- const t = {}, d = e.name.trim();
50
- d ? d.length < s.NAME_MIN ? t.name = o(`${i}.error-name-min`, { min: s.NAME_MIN }) : d.length > s.NAME_MAX && (t.name = o(`${i}.error-name-max`, { max: s.NAME_MAX })) : t.name = o(`${i}.error-name-required`);
51
- const { DESCRIPTION_MAX: C } = s;
52
- e.description.trim().length > C && (t.description = o(`${i}.error-description-max`, { max: C }));
53
- const g = Y(e.codeBefore, e.codeAfter, u.value);
54
- return ["codeBefore", "codeAfter"].forEach((a) => {
55
- e[a].trim() ? g.includes(a) ? t[a] = o(`${i}.error-code-invalid`) : e[a].length > s.CODE_MAX && (t[a] = o(`${i}.error-code-max`, { max: s.CODE_MAX })) : t[a] = o(`${i}.error-code-required`);
56
- }), t;
57
- }, A = (e, t) => {
58
- p(e ? { type: l.Success, message: t } : { type: l.Error, message: o("products.something-went-wrong") });
59
- }, T = (e) => o(
60
- `${i}.${e}`,
61
- {
62
- academyLink: `<a href="${L.EMAIL_DISPLAY_CONDITIONS}" target="_blank" style="color: #0A2ECC; text-decoration: underline;">${o(`${i}.academy`)}</a>`
63
- }
64
- ), _ = () => {
65
- p({ type: l.Error, message: o(`${i}.validation-failed`) });
66
- }, c = (e) => ({ name: R(e) }), E = (e, t) => {
67
- e != null && e.authReported || (console.warn(t, e), p({ type: l.Error, message: t }));
68
- };
69
- return {
70
- syntax: u,
71
- handleOpen: N,
72
- cancel: D,
73
- loadList: $,
74
- validate: h,
75
- notifyInvalid: _,
76
- describeWithAcademyLink: T,
77
- createInline: (e) => {
78
- A(
79
- f(S(e, y.INLINE)),
80
- o(`${i}.created`, c(e.name.trim()))
81
- );
82
- },
83
- createAndSave: async (e) => {
84
- try {
85
- const t = await r.create(e, u.value);
86
- return n.list = [t, ...n.list.filter((d) => d.id !== t.id)], A(
87
- f(S(v(t), y.SAVED, t.id)),
88
- o(`${i}.created-and-saved`, c(t.name))
89
- ), {};
90
- } catch (t) {
91
- return (t == null ? void 0 : t.status) === b ? { name: o(`${i}.error-name-exists`) } : (E(t, o(`${i}.save-failed`, c(e.name.trim()))), null);
92
- }
93
- },
94
- select: (e) => {
95
- A(
96
- f(S(v(e), y.SAVED, e.id)),
97
- o(`${i}.applied`, c(e.name))
98
- );
99
- },
100
- deleteSaved: async (e) => {
101
- try {
102
- await r.remove(e.id), n.list = n.list.filter((t) => t.id !== e.id), p({
103
- type: l.Success,
104
- message: o(`${i}.deleted`, c(e.name))
105
- });
106
- } catch (t) {
107
- E(t, o(`${i}.delete-failed`));
108
- } finally {
109
- n.pendingDelete = null;
110
- }
111
- }
112
- };
113
- };
114
- export {
115
- X as DISPLAY_CONDITIONS_TRANS_KEY,
116
- ne as useDisplayConditions
117
- };
@@ -1,12 +0,0 @@
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
- };
@@ -1,25 +0,0 @@
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
- };
@@ -1,17 +0,0 @@
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
- };
@@ -1,200 +0,0 @@
1
- var $ = Object.defineProperty;
2
- var w = (s, a, i) => a in s ? $(s, a, { enumerable: !0, configurable: !0, writable: !0, value: i }) : s[a] = i;
3
- var c = (s, a, i) => w(s, typeof a != "symbol" ? a + "" : a, i);
4
- import { useToaster as S } from "../../composables/useToaster.js";
5
- import { useTranslations as N } from "../../composables/useTranslations.js";
6
- import { DisplayConditionSourceType as D } from "../../enums/display-condition.js";
7
- import { ToasterTypeOptions as I } from "../../enums/toaster.js";
8
- import { CommonControl as T } from "../Blocks/common-control.js";
9
- import { toAppliedCondition as E, parseSource as x } from "../../utils/displayCondition.js";
10
- import { escapeHtml as b } from "../../utils/htmlEscape.js";
11
- import { ModificationDescription as M, UIElementType as v, UEAttr as R } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
12
- import { requestDisplayCondition as L } from "./bridge.js";
13
- import { CONDITIONS_CONTROL_ID as H, APPLIED_DESCRIPTION as q, EMPTY_DESCRIPTION as A, MAX_COLLAPSED_LINES as O, CONDITION_ICONS as g } from "./constants.js";
14
- const l = ".guido-display-conditions", k = { id: 0, name: "", description: "", beforeScript: "", afterScript: "" }, _ = (s) => `<${v.ICON} ${R.ICON.src}="${s}"></${v.ICON}>`, p = (s, a, i, t = !1) => `<button type="button" class="${a}" id="${s}"${t ? " hidden" : ""}>${i}</button>`;
15
- class K extends T {
16
- constructor() {
17
- super(...arguments);
18
- c(this, "expanded", !1);
19
- c(this, "listeners", []);
20
- c(this, "resizeObserver", null);
21
- c(this, "detachOutsideClick", null);
22
- c(this, "detachRequest", null);
23
- }
24
- getId() {
25
- return H;
26
- }
27
- getTemplate() {
28
- return `
29
- <div class="guido-display-conditions">
30
- <div class="guido-display-conditions__header">
31
- <p class="guido-display-conditions__title">${this.api.translate("Display Conditions")}</p>
32
- <p class="guido-display-conditions__description" data-dc-description></p>
33
- </div>
34
- <div class="guido-display-conditions__empty" data-dc-empty>
35
- ${p(
36
- "guido__btn-add-display-condition",
37
- "guido-display-conditions__add",
38
- `${_(g.PLUS)}<span>${this.api.translate("Add Display Condition")}</span>`
39
- )}
40
- <div class="guido-display-conditions__menu" data-dc-menu hidden>
41
- ${p(
42
- "guido__btn-display-condition-create",
43
- "guido-display-conditions__menu-item",
44
- this.api.translate("Create New Condition")
45
- )}
46
- ${p(
47
- "guido__btn-display-condition-select",
48
- "guido-display-conditions__menu-item",
49
- this.api.translate("Select Saved Condition")
50
- )}
51
- </div>
52
- </div>
53
- <div class="guido-display-conditions__applied" data-dc-applied hidden>
54
- <div class="guido-display-conditions__code-box">
55
- <p class="guido-display-conditions__name" data-dc-name></p>
56
- <div class="guido-display-conditions__sections" data-dc-sections>
57
- <p class="guido-display-conditions__section-label">
58
- ${this.api.translate("Code Before Module")}
59
- </p>
60
- <pre class="guido-display-conditions__code" data-dc-before></pre>
61
- <p class="guido-display-conditions__section-label" data-dc-after-label>
62
- ${this.api.translate("Code After Module")}
63
- </p>
64
- <pre class="guido-display-conditions__code" data-dc-after></pre>
65
- </div>
66
- ${p(
67
- "guido__btn-display-condition-toggle",
68
- "guido-display-conditions__toggle",
69
- `${_(g.CHEVRON)}<span data-dc-toggle-label></span>`,
70
- !0
71
- )}
72
- </div>
73
- <div class="guido-display-conditions__actions">
74
- ${p(
75
- "guido__btn-edit-display-condition",
76
- "guido-display-conditions__action guido-display-conditions__action--edit",
77
- `${_(g.EDIT)}<span>${this.api.translate("Edit")}</span>`
78
- )}
79
- ${p(
80
- "guido__btn-remove-display-condition",
81
- "guido-display-conditions__action guido-display-conditions__action--remove",
82
- `${_(g.TRASH)}<span>${this.api.translate("Remove")}</span>`
83
- )}
84
- </div>
85
- </div>
86
- </div>
87
- `;
88
- }
89
- onRender() {
90
- 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-toggle", () => {
91
- this.expanded = !this.expanded, this.paint();
92
- }), this.observeCodeSize();
93
- }
94
- onTemplateNodeUpdated(i) {
95
- const t = i !== this.currentNode;
96
- super.onTemplateNodeUpdated(i), t && (this.expanded = !1, this.toggleMenu(!1)), this.paint();
97
- }
98
- onDestroy() {
99
- var i;
100
- super.onDestroy(), this.teardown(), (i = this.detachRequest) == null || i.call(this), this.detachRequest = null;
101
- }
102
- getCondition() {
103
- var t;
104
- const i = this.currentNode;
105
- return E((t = i == null ? void 0 : i.getDisplayCondition) == null ? void 0 : t.call(i));
106
- }
107
- toggleMenu(i) {
108
- var n, d, o;
109
- const t = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${l} [data-dc-menu]`);
110
- if (!t)
111
- return;
112
- t.hidden = i === void 0 ? !t.hidden : !i, (d = this.detachOutsideClick) == null || d.call(this), t.hidden || this.listenOutsideClick();
113
- const e = (o = this.getContainer()) == null ? void 0 : o.querySelector(`${l} #guido__btn-add-display-condition`);
114
- t.style.width = !t.hidden && e ? `${e.getBoundingClientRect().width}px` : "";
115
- }
116
- listenOutsideClick() {
117
- var e;
118
- const i = ((e = this.getContainer()) == null ? void 0 : e.ownerDocument) ?? document, t = (n) => {
119
- n.composedPath().some((o) => o instanceof HTMLElement && o.matches(`${l} [data-dc-menu], ${l} #guido__btn-add-display-condition`)) || this.toggleMenu(!1);
120
- };
121
- i.addEventListener("pointerdown", t, !0), this.detachOutsideClick = () => {
122
- i.removeEventListener("pointerdown", t, !0), this.detachOutsideClick = null;
123
- };
124
- }
125
- openDrawer(i) {
126
- const t = this.currentNode;
127
- this.toggleMenu(!1), this.detachRequest = L(
128
- { mode: i, current: i === "edit" ? this.getCondition() : null },
129
- { onApply: (e) => this.applyCondition(e, t) }
130
- );
131
- }
132
- // The drawer flows toast through useDisplayConditions; Remove has no drawer, so it toasts here.
133
- removeCondition() {
134
- this.applyCondition(null) || S().showToaster({
135
- type: I.Error,
136
- message: N()("products.something-went-wrong")
137
- });
138
- }
139
- // The panel can move to another block while the drawer is open; apply onto the block it was opened for.
140
- applyCondition(i, t = this.currentNode) {
141
- if (!t)
142
- return !1;
143
- try {
144
- const e = this.api.getDocumentModifier().modifyHtml(t);
145
- return e.setDisplayCondition(i || k), e.apply(new M(
146
- i ? `Set display condition ${i.name}` : "Remove display condition"
147
- )), !0;
148
- } catch (e) {
149
- return console.warn("Display condition could not be applied.", e), !1;
150
- }
151
- }
152
- wire(i, t) {
153
- var n;
154
- const e = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${l} ${i}`);
155
- e && (e.addEventListener("click", t), this.listeners.push({ element: e, handler: t }));
156
- }
157
- teardown() {
158
- var i, t;
159
- 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);
160
- }
161
- // Line counts depend on layout: the panel font loads late and the panel can be resized.
162
- observeCodeSize() {
163
- var t;
164
- const i = (t = this.getContainer()) == null ? void 0 : t.querySelectorAll(`${l} .guido-display-conditions__code`);
165
- !(i != null && i.length) || typeof ResizeObserver > "u" || (this.resizeObserver = new ResizeObserver(() => this.paint()), i.forEach((e) => {
166
- var n;
167
- return (n = this.resizeObserver) == null ? void 0 : n.observe(e);
168
- }));
169
- }
170
- paint() {
171
- var C;
172
- const i = (C = this.getContainer()) == null ? void 0 : C.querySelector(l);
173
- if (!i)
174
- return;
175
- const t = this.getCondition(), e = (h) => i.querySelector(h);
176
- if (e("[data-dc-empty]").hidden = !!t, e("[data-dc-applied]").hidden = !t, e("[data-dc-description]").textContent = this.api.translate(t ? q : A), !t)
177
- return;
178
- e("[data-dc-name]").textContent = t.name;
179
- const n = x(t) === D.INLINE;
180
- e("#guido__btn-edit-display-condition").hidden = !n;
181
- const d = e("[data-dc-sections]"), o = e("[data-dc-before]"), r = e("[data-dc-after]");
182
- o.innerHTML = b(t.beforeScript), r.innerHTML = b(t.afterScript), r.hidden = !t.afterScript, e("[data-dc-after-label]").hidden = !t.afterScript, d.style.maxHeight = "";
183
- const u = parseFloat(getComputedStyle(o).lineHeight) || 24, y = (h) => h.hidden ? 0 : Math.round(h.scrollHeight / u), m = y(o) + y(r) > O, f = e("#guido__btn-display-condition-toggle");
184
- f.hidden = !m, f.classList.toggle("is-expanded", this.expanded), e("[data-dc-toggle-label]").textContent = this.api.translate(this.expanded ? "Show Less" : "Show More"), m && !this.expanded && (d.style.maxHeight = `${this.collapsedHeight(d, [o, r], u)}px`);
185
- }
186
- // Labels do not count toward the line limit, so the cut lands after the 10th rendered code line.
187
- collapsedHeight(i, t, e) {
188
- const { top: n } = i.getBoundingClientRect();
189
- let d = O, o = 0;
190
- return t.filter((r) => !r.hidden).forEach((r) => {
191
- if (d <= 0)
192
- return;
193
- const u = Math.min(d, Math.round(r.scrollHeight / e));
194
- o = r.getBoundingClientRect().top - n + u * e, d -= u;
195
- }), o;
196
- }
197
- }
198
- export {
199
- K as DisplayConditionsControl
200
- };
@@ -1,201 +0,0 @@
1
- const n = `.guido-display-conditions {
2
- display: flex;
3
- flex-direction: column;
4
- font-family: inherit;
5
- }
6
-
7
- .guido-display-conditions__header {
8
- padding: 16px;
9
- }
10
-
11
- .guido-display-conditions__title {
12
- margin: 0 0 8px;
13
- color: var(--guido-color-gray-800);
14
- font-size: 16px;
15
- font-weight: 600;
16
- line-height: 24px;
17
- }
18
-
19
- .guido-display-conditions__description {
20
- margin: 0;
21
- color: var(--guido-color-gray-600);
22
- font-size: 13px;
23
- line-height: 16px;
24
- }
25
-
26
- .guido-display-conditions__empty {
27
- padding: 8px 16px 16px;
28
- }
29
-
30
- .guido-display-conditions__add {
31
- display: flex;
32
- gap: 8px;
33
- align-items: center;
34
- justify-content: center;
35
- width: 100%;
36
- height: 40px;
37
- padding: 0 16px;
38
- border: none;
39
- border-radius: 4px;
40
- background: var(--guido-color-primary-100);
41
- color: var(--guido-color-primary-500);
42
- font: inherit;
43
- font-size: 15px;
44
- line-height: 24px;
45
- cursor: pointer;
46
- }
47
-
48
- /* Stripo draws registered icons at 100% of ue-icon-component (Figma: 20px glyph in a 24px box). */
49
- .guido-display-conditions ue-icon-component {
50
- display: inline-flex;
51
- flex-shrink: 0;
52
- align-items: center;
53
- justify-content: center;
54
- width: 24px;
55
- height: 24px;
56
- }
57
-
58
- .guido-display-conditions ue-icon-component svg {
59
- width: 20px;
60
- height: 20px;
61
- }
62
-
63
- .guido-display-conditions__add:hover {
64
- background: var(--guido-color-primary-200);
65
- }
66
-
67
- .guido-display-conditions__add:focus-visible,
68
- .guido-display-conditions__action:focus-visible,
69
- .guido-display-conditions__toggle:focus-visible {
70
- outline: 2px solid var(--guido-color-primary-500);
71
- outline-offset: 2px;
72
- }
73
-
74
- .guido-display-conditions__code-box {
75
- display: flex;
76
- flex-direction: column;
77
- gap: 8px;
78
- padding: 16px;
79
- background: var(--guido-color-gray-0);
80
- }
81
-
82
- .guido-display-conditions__sections {
83
- display: flex;
84
- flex-direction: column;
85
- gap: 8px;
86
- overflow: hidden;
87
- }
88
-
89
- .guido-display-conditions__name,
90
- .guido-display-conditions__section-label {
91
- margin: 0;
92
- color: var(--guido-color-gray-800);
93
- font-size: 15px;
94
- font-weight: 600;
95
- line-height: 24px;
96
- word-break: break-word;
97
- }
98
-
99
- .guido-display-conditions__code {
100
- margin: 0;
101
- color: #101727;
102
- font-family: inherit;
103
- font-size: 15px;
104
- line-height: 24px;
105
- white-space: pre-wrap;
106
- word-break: break-word;
107
- }
108
-
109
- .guido-display-conditions__toggle {
110
- display: inline-flex;
111
- align-items: center;
112
- align-self: flex-start;
113
- padding: 8px 0;
114
- border: none;
115
- background: none;
116
- color: var(--guido-color-primary-500);
117
- font: inherit;
118
- font-size: 15px;
119
- line-height: 24px;
120
- cursor: pointer;
121
- }
122
-
123
- .guido-display-conditions__toggle span {
124
- padding: 0 8px;
125
- }
126
-
127
- .guido-display-conditions__toggle.is-expanded ue-icon-component {
128
- transform: rotate(180deg);
129
- }
130
-
131
- .guido-display-conditions__actions {
132
- display: flex;
133
- gap: 16px;
134
- align-items: center;
135
- height: 48px;
136
- padding: 0 8px;
137
- background: var(--guido-color-white);
138
- }
139
-
140
- .guido-display-conditions__action {
141
- display: inline-flex;
142
- align-items: center;
143
- padding: 8px;
144
- border: none;
145
- background: none;
146
- font: inherit;
147
- font-size: 15px;
148
- line-height: 24px;
149
- cursor: pointer;
150
- }
151
-
152
- .guido-display-conditions__action span {
153
- padding: 0 8px;
154
- }
155
-
156
- .guido-display-conditions__action--edit {
157
- color: var(--guido-color-primary-500);
158
- }
159
-
160
- .guido-display-conditions__action--remove {
161
- color: var(--guido-color-danger-500);
162
- }
163
-
164
- .guido-display-conditions [hidden] {
165
- display: none !important;
166
- }
167
-
168
- /* No positioned ancestor inside Stripo's clipping scroller: the menu keeps its static spot but escapes the clip. */
169
- .guido-display-conditions__menu {
170
- position: absolute;
171
- z-index: 2;
172
- margin-top: 4px;
173
- padding: 4px 0;
174
- border-radius: 4px;
175
- background-color: #FFFFFF;
176
- box-shadow: 0 4px 16px rgba(34, 41, 56, 0.16);
177
- }
178
-
179
- .guido-display-conditions__menu-item {
180
- display: block;
181
- width: 100%;
182
- padding: 8px 16px;
183
- border: 0;
184
- background: none;
185
- color: var(--guido-color-neutral-800);
186
- cursor: pointer;
187
- font: inherit;
188
- font-size: 14px;
189
- line-height: 24px;
190
- text-align: left;
191
- }
192
-
193
- .guido-display-conditions__menu-item:hover,
194
- .guido-display-conditions__menu-item:focus-visible {
195
- background-color: var(--guido-color-neutral-100);
196
- outline: none;
197
- }
198
- `;
199
- export {
200
- n as default
201
- };