@useinsider/guido 3.24.0-beta.0abeefe → 3.24.0-beta.297168

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 (84) 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/useBlocksConfig.js +20 -31
  6. package/dist/composables/useHtmlCompiler.js +2 -0
  7. package/dist/composables/useStripo.js +70 -70
  8. package/dist/composables/useTranslations.js +1 -2
  9. package/dist/config/compiler/htmlCompilerRules.js +14 -6
  10. package/dist/config/compiler/utils/itemsCompilerUtils.js +42 -43
  11. package/dist/config/compiler/utils/recommendationCompilerUtils.js +64 -67
  12. package/dist/config/migrator/unsubscribeMigrator.js +91 -100
  13. package/dist/enums/academy.js +0 -1
  14. package/dist/extensions/Blocks/Unsubscribe/block.js +104 -96
  15. package/dist/extensions/Blocks/Unsubscribe/utils/constants.js +4 -3
  16. package/dist/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.js +5 -0
  17. package/dist/guido.css +1 -1
  18. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +92 -93
  19. package/dist/node_modules/valibot/dist/index.js +261 -297
  20. package/dist/package.json.js +6 -6
  21. package/dist/src/@types/config/schemas.d.ts +0 -4
  22. package/dist/src/composables/useConfig.d.ts +0 -2
  23. package/dist/src/composables/useStripo.d.ts +1 -1
  24. package/dist/src/enums/academy.d.ts +0 -1
  25. package/dist/src/extensions/Blocks/Unsubscribe/utils/constants.d.ts +1 -0
  26. package/dist/src/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.d.ts +1 -0
  27. package/dist/src/stores/config.d.ts +0 -167
  28. package/dist/src/utils/linkTrackingIds.d.ts +5 -22
  29. package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
  30. package/dist/stores/config.js +6 -13
  31. package/dist/utils/linkTrackingIds.js +48 -82
  32. package/dist/utils/pairProductVariables.js +29 -30
  33. package/dist/utils/templatePreparation.js +57 -67
  34. package/dist/utils/trimHrefWhitespace.js +10 -0
  35. package/package.json +1 -1
  36. package/dist/@types/display-condition.js +0 -25
  37. package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +0 -17
  38. package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +0 -41
  39. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +0 -30
  40. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +0 -81
  41. package/dist/components/organisms/display-conditions/DisplayConditionListState.vue.js +0 -17
  42. package/dist/components/organisms/display-conditions/DisplayConditionListState.vue2.js +0 -45
  43. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +0 -36
  44. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +0 -63
  45. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +0 -17
  46. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +0 -22
  47. package/dist/composables/useDisplayConditions.js +0 -117
  48. package/dist/enums/display-condition.js +0 -12
  49. package/dist/extensions/DisplayConditions/bridge.js +0 -25
  50. package/dist/extensions/DisplayConditions/constants.js +0 -26
  51. package/dist/extensions/DisplayConditions/control.js +0 -215
  52. package/dist/extensions/DisplayConditions/display-conditions.css.js +0 -226
  53. package/dist/extensions/DisplayConditions/extension.js +0 -28
  54. package/dist/extensions/DisplayConditions/iconsRegistry.js +0 -20
  55. package/dist/extensions/DisplayConditions/library.js +0 -30
  56. package/dist/extensions/DisplayConditions/settingsPanel.js +0 -17
  57. package/dist/extensions/LinkTracking/extension.js +0 -17
  58. package/dist/extensions/LinkTracking/writer.js +0 -41
  59. package/dist/services/displayConditionApi.js +0 -39
  60. package/dist/src/@types/display-condition.d.ts +0 -60
  61. package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +0 -43
  62. package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +0 -2
  63. package/dist/src/components/organisms/display-conditions/DisplayConditionListState.vue.d.ts +0 -18
  64. package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +0 -2
  65. package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +0 -2
  66. package/dist/src/composables/useDisplayConditions.d.ts +0 -18
  67. package/dist/src/enums/display-condition.d.ts +0 -15
  68. package/dist/src/extensions/DisplayConditions/bridge.d.ts +0 -7
  69. package/dist/src/extensions/DisplayConditions/constants.d.ts +0 -23
  70. package/dist/src/extensions/DisplayConditions/control.d.ts +0 -25
  71. package/dist/src/extensions/DisplayConditions/extension.d.ts +0 -2
  72. package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +0 -4
  73. package/dist/src/extensions/DisplayConditions/library.d.ts +0 -8
  74. package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +0 -5
  75. package/dist/src/extensions/LinkTracking/extension.d.ts +0 -2
  76. package/dist/src/extensions/LinkTracking/writer.d.ts +0 -13
  77. package/dist/src/mock/api/display-conditions.d.ts +0 -2
  78. package/dist/src/services/displayConditionApi.d.ts +0 -8
  79. package/dist/src/stores/display-condition.d.ts +0 -84
  80. package/dist/src/utils/displayCondition.d.ts +0 -11
  81. package/dist/src/utils/protectTableText.d.ts +0 -2
  82. package/dist/stores/display-condition.js +0 -29
  83. package/dist/utils/displayCondition.js +0 -26
  84. package/dist/utils/protectTableText.js +0 -22
@@ -1,63 +0,0 @@
1
- import { defineComponent as T, ref as r, watch as I, computed as i } from "vue";
2
- import O from "../../wrappers/WpDrawer.vue.js";
3
- import B from "../../wrappers/WpModal.vue.js";
4
- import { useDisplayConditions as L, DISPLAY_CONDITIONS_TRANS_KEY as s } from "../../../composables/useDisplayConditions.js";
5
- import { useTranslations as M } from "../../../composables/useTranslations.js";
6
- import { useDisplayConditionStore as h } from "../../../stores/display-condition.js";
7
- import { getTooltipOptions as C } from "../../../utils/tooltipUtils.js";
8
- import { InSkeleton as $, InDropdownMenu as E, InButtonV2 as b, InBasicTextInput as k } from "@useinsider/design-system-vue";
9
- import w from "./DisplayConditionListState.vue.js";
10
- const ee = /* @__PURE__ */ T({
11
- __name: "DisplayConditionSelectDrawer",
12
- setup(A) {
13
- const g = [40, 76, 76, 76], l = M(), t = h(), { loadList: c, select: v, deleteSaved: d, cancel: D, describeWithAcademyLink: p } = L(), u = r(""), a = r(null), n = r(null), o = r(!1);
14
- I(() => t.isSelectOpen, (e) => {
15
- e && (u.value = "", a.value = null, n.value = null, c());
16
- }, { immediate: !0 });
17
- const f = i(() => {
18
- const e = u.value.trim().toLocaleLowerCase();
19
- return e ? t.list.filter((m) => `${m.name} ${m.description}`.toLocaleLowerCase().includes(e)) : t.list;
20
- }), y = i(() => t.listStatus === "error" ? "error" : t.list.length ? f.value.length ? null : "no-result" : "empty"), _ = i(() => p("select-description")), S = i(() => ({
21
- cancelOrBackButton: {
22
- styling: "ghost",
23
- type: "secondary",
24
- labelText: l(`${s}.back`),
25
- leftIcon: "line-arrow-left"
26
- }
27
- })), x = i(() => ({
28
- cancelOrBackButton: {
29
- type: "secondary",
30
- styling: "ghost",
31
- labelText: l(`${s}.cancel`),
32
- disabledStatus: o.value
33
- },
34
- primaryButton: {
35
- type: "danger",
36
- labelText: l(`${s}.delete`),
37
- loadingStatus: o.value
38
- }
39
- }));
40
- return { __sfc: !0, SKELETON_HEIGHTS: g, trans: l, store: t, loadList: c, select: v, deleteSaved: d, cancel: D, describeWithAcademyLink: p, search: u, expandedId: a, menuId: n, isDeleting: o, filteredList: f, listState: y, descriptionText: _, footerButtonGroupOptions: S, deleteModalButtons: x, toggleExpanded: (e) => {
41
- a.value = a.value === e.id ? null : e.id;
42
- }, toggleMenu: (e) => {
43
- n.value = n.value === e.id ? null : e.id;
44
- }, closeMenu: (e) => {
45
- n.value === e.id && (n.value = null);
46
- }, expandTooltip: (e) => C(
47
- `guido__display-condition-expand-tooltip-${e.id}`,
48
- { staticPosition: "top right" }
49
- ), menuOptions: (e) => [
50
- { text: l(`${s}.delete`), value: `guido__display-condition-delete-${e.id}` }
51
- ], requestDelete: (e) => {
52
- n.value = null, t.pendingDelete = e;
53
- }, confirmDelete: async () => {
54
- !t.pendingDelete || o.value || (o.value = !0, await d(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: O, WpModal: B, KEY: s, InBasicTextInput: k, InButtonV2: b, InDropdownMenu: E, InSkeleton: $, DisplayConditionListState: w };
59
- }
60
- });
61
- export {
62
- ee 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,26 +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", 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
- };
@@ -1,215 +0,0 @@
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
- };