@useinsider/guido 3.21.1 → 3.21.2-beta.cfc5be2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +1 -0
  2. package/dist/@types/config/schemas.js +41 -39
  3. package/dist/@types/display-condition.js +25 -0
  4. package/dist/components/Guido.vue.js +6 -6
  5. package/dist/components/Guido.vue2.js +81 -79
  6. package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +20 -0
  7. package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +30 -0
  8. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +30 -0
  9. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +71 -0
  10. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +34 -0
  11. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +57 -0
  12. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +17 -0
  13. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +22 -0
  14. package/dist/composables/useBlocksConfig.js +32 -24
  15. package/dist/composables/useDisplayConditions.js +102 -0
  16. package/dist/config/compiler/utils/recommendationCompilerUtils.js +55 -53
  17. package/dist/enums/academy.js +1 -0
  18. package/dist/enums/display-condition.js +12 -0
  19. package/dist/extensions/Blocks/Recommendation/block.js +52 -37
  20. package/dist/extensions/Blocks/Recommendation/controls/image/index.js +76 -16
  21. package/dist/extensions/Blocks/Recommendation/utils/captureStyleTemplates.js +16 -15
  22. package/dist/extensions/DisplayConditions/bridge.js +17 -0
  23. package/dist/extensions/DisplayConditions/constants.js +17 -0
  24. package/dist/extensions/DisplayConditions/control.js +178 -0
  25. package/dist/extensions/DisplayConditions/display-conditions.css.js +201 -0
  26. package/dist/extensions/DisplayConditions/extension.js +28 -0
  27. package/dist/extensions/DisplayConditions/iconsRegistry.js +20 -0
  28. package/dist/extensions/DisplayConditions/library.js +27 -0
  29. package/dist/extensions/DisplayConditions/settingsPanel.js +17 -0
  30. package/dist/guido.css +1 -1
  31. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +93 -92
  32. package/dist/node_modules/valibot/dist/index.js +297 -261
  33. package/dist/services/displayConditionApi.js +39 -0
  34. package/dist/src/@types/config/schemas.d.ts +4 -0
  35. package/dist/src/@types/display-condition.d.ts +59 -0
  36. package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +43 -0
  37. package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +2 -0
  38. package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +2 -0
  39. package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +2 -0
  40. package/dist/src/composables/useConfig.d.ts +2 -0
  41. package/dist/src/composables/useDisplayConditions.d.ts +16 -0
  42. package/dist/src/enums/academy.d.ts +1 -0
  43. package/dist/src/enums/display-condition.d.ts +15 -0
  44. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +2 -0
  45. package/dist/src/extensions/Blocks/Recommendation/controls/image/index.d.ts +31 -17
  46. package/dist/src/extensions/DisplayConditions/bridge.d.ts +6 -0
  47. package/dist/src/extensions/DisplayConditions/constants.d.ts +14 -0
  48. package/dist/src/extensions/DisplayConditions/control.d.ts +23 -0
  49. package/dist/src/extensions/DisplayConditions/extension.d.ts +2 -0
  50. package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +4 -0
  51. package/dist/src/extensions/DisplayConditions/library.d.ts +8 -0
  52. package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +5 -0
  53. package/dist/src/mock/api/display-conditions.d.ts +2 -0
  54. package/dist/src/services/displayConditionApi.d.ts +8 -0
  55. package/dist/src/stores/config.d.ts +166 -0
  56. package/dist/src/stores/display-condition.d.ts +81 -0
  57. package/dist/src/utils/displayCondition.d.ts +10 -0
  58. package/dist/src/utils/protectTableText.d.ts +2 -0
  59. package/dist/stores/config.js +13 -6
  60. package/dist/stores/display-condition.js +28 -0
  61. package/dist/utils/displayCondition.js +26 -0
  62. package/dist/utils/pairProductVariables.js +15 -14
  63. package/dist/utils/protectTableText.js +22 -0
  64. package/package.json +1 -1
@@ -0,0 +1,71 @@
1
+ import { defineComponent as D, reactive as $, ref as s, watch as C, computed as u } from "vue";
2
+ import O from "../../wrappers/WpDrawer.vue.js";
3
+ import { useDisplayConditions as T } from "../../../composables/useDisplayConditions.js";
4
+ import { useTranslations as L } from "../../../composables/useTranslations.js";
5
+ import { ACADEMY_LINKS as x } from "../../../enums/academy.js";
6
+ import { DISPLAY_CONDITION_LIMITS as h } from "../../../enums/display-condition.js";
7
+ import { useDisplayConditionStore as k } from "../../../stores/display-condition.js";
8
+ import { InRadioButton as N, InBasicTextInput as w } from "@useinsider/design-system-vue";
9
+ import E from "./CodeEditorField.vue.js";
10
+ const J = /* @__PURE__ */ D({
11
+ __name: "DisplayConditionCreateDrawer",
12
+ setup(Y) {
13
+ const r = "email-editor.display-conditions", i = L(), c = k(), { validate: p, notifyInvalid: l, createInline: f, createAndSave: m, cancel: y } = T(), d = () => ({ name: "", description: "", codeBefore: "", codeAfter: "" }), e = $(d()), o = s({}), a = s(!1), v = s(), _ = s();
14
+ C(() => c.isCreateOpen, (n) => {
15
+ if (!n)
16
+ return;
17
+ const { editing: t } = c;
18
+ Object.assign(e, t ? {
19
+ name: t.name,
20
+ description: t.description,
21
+ codeBefore: t.beforeScript,
22
+ codeAfter: t.afterScript
23
+ } : d()), o.value = {}, a.value = !1;
24
+ }, { immediate: !0 });
25
+ const g = u(() => i(`${r}.create-description`, {
26
+ academyLink: `<a href="${x.EMAIL_DISPLAY_CONDITIONS}" class="guido-display-condition-academy" target="_blank">${i(`${r}.academy`)}</a>`
27
+ })), S = u(() => ({
28
+ cancelOrBackButton: {
29
+ styling: "ghost",
30
+ type: "secondary",
31
+ labelText: i(`${r}.cancel`),
32
+ disabledStatus: a.value
33
+ },
34
+ secondaryButton: {
35
+ styling: "solid",
36
+ type: "subtle-primary",
37
+ labelText: i(`${r}.create-and-save`),
38
+ loadingStatus: a.value
39
+ },
40
+ primaryButton: {
41
+ styling: "solid",
42
+ type: "primary",
43
+ labelText: i(`${r}.create`),
44
+ disabledStatus: a.value
45
+ }
46
+ })), B = (n, t) => {
47
+ t !== e[n] && (e[n] = t, o.value[n] && (o.value = { ...o.value, [n]: void 0 }));
48
+ }, A = u(() => `${i(`${r}.condition-description`)} <span class="guido-display-condition-create__optional">(${i(`${r}.optional`)})</span>`);
49
+ return { __sfc: !0, KEY: r, trans: i, store: c, validate: p, notifyInvalid: l, createInline: f, createAndSave: m, cancel: y, emptyDraft: d, draft: e, errors: o, isSaving: a, codeBeforeRef: v, codeAfterRef: _, descriptionText: g, footerButtonGroupOptions: S, updateField: B, descriptionLabel: A, submit: async (n) => {
50
+ var I, b;
51
+ if (a.value)
52
+ return;
53
+ if (e.codeBefore = ((I = v.value) == null ? void 0 : I.read()) ?? e.codeBefore, e.codeAfter = ((b = _.value) == null ? void 0 : b.read()) ?? e.codeAfter, o.value = p(e), Object.keys(o.value).length) {
54
+ l();
55
+ return;
56
+ }
57
+ if (n === "inline") {
58
+ f({ ...e });
59
+ return;
60
+ }
61
+ a.value = !0;
62
+ const t = await m({ ...e });
63
+ a.value = !1, o.value = t ?? {}, Object.keys(o.value).length && l();
64
+ }, close: () => {
65
+ a.value || y();
66
+ }, WpDrawer: O, DISPLAY_CONDITION_LIMITS: h, InBasicTextInput: w, InRadioButton: N, CodeEditorField: E };
67
+ }
68
+ });
69
+ export {
70
+ J as default
71
+ };
@@ -0,0 +1,34 @@
1
+ import a from "./DisplayConditionSelectDrawer.vue2.js";
2
+ /* empty css */
3
+ import o from "../../../_virtual/_plugin-vue2_normalizer.js";
4
+ var d = function() {
5
+ var s = this, i = s._self._c, t = s._self._setupProxy;
6
+ return i("div", { staticClass: "guido-display-condition-select-root" }, [i(t.WpDrawer, { attrs: { id: "guido__display-condition-select-drawer", "description-status": "", "class-name": "guido-display-condition-select-drawer", size: "large", "description-text": t.descriptionText, "footer-button-group-options": t.footerButtonGroupOptions, status: t.store.isSelectOpen, "title-text": t.trans(`${t.KEY}.select-title`) }, on: { cancelOrBackButtonEvent: t.cancel, onCloseEvent: t.cancel } }, [i("div", { staticClass: "guido-display-condition-select" }, [t.store.listStatus === "loaded" && t.store.list.length ? i(t.InBasicTextInput, { staticClass: "mb-4 w-1", attrs: { id: "guido__display-condition-search-input", name: "displayConditionSearch", "character-counter-status": !1, "label-status": !1, "placeholder-text": t.trans(`${t.KEY}.search`), "tooltip-status": !1, value: t.search }, on: { input: function(e) {
7
+ t.search = e;
8
+ } } }) : s._e(), t.store.listStatus === "loading" || t.store.listStatus === "idle" ? i("div", { staticClass: "guido-display-condition-select__list", attrs: { "data-testid": "display-condition-loading" } }, s._l(t.SKELETON_HEIGHTS, function(e, n) {
9
+ return i(t.InSkeleton, { key: n, attrs: { sizing: { width: 856, height: e } } });
10
+ }), 1) : t.store.listStatus === "error" ? i(t.InNoData, { attrs: { id: "guido__display-condition-error", "button-status": "", icon: "no-data", "button-text": t.trans(`${t.KEY}.retry`), description: t.trans(`${t.KEY}.error-load`), title: t.trans(`${t.KEY}.error-load-title`) }, on: { click: t.loadList } }) : t.store.list.length ? t.filteredList.length ? i("ul", { staticClass: "guido-display-condition-select__list" }, s._l(t.filteredList, function(e) {
11
+ return i("li", { key: e.id, staticClass: "guido-display-condition-card", attrs: { "data-condition-id": e.id } }, [i("div", { staticClass: "guido-display-condition-card__header" }, [i("div", { staticClass: "guido-display-condition-card__text" }, [i("p", { staticClass: "guido-display-condition-card__name" }, [s._v(" " + s._s(e.name) + " ")]), e.description ? i("p", { staticClass: "guido-display-condition-card__description" }, [s._v(" " + s._s(e.description) + " ")]) : s._e()]), i("div", { staticClass: "guido-display-condition-card__actions" }, [i("div", { staticClass: "guido-display-condition-card__split" }, [i(t.InButtonV2, { attrs: { id: `guido__display-condition-select-${e.id}`, type: "subtle-primary", "label-text": t.trans(`${t.KEY}.select`) }, on: { click: function(n) {
12
+ return t.select(e);
13
+ } } }), i(t.InButtonV2, { attrs: { id: `guido__display-condition-menu-${e.id}`, "left-icon": "filled-dropdown-down", type: "subtle-primary", "label-text-status": !1 }, on: { click: function(n) {
14
+ return t.toggleMenu(e);
15
+ } } }), t.menuId === e.id ? i("div", { staticClass: "guido-display-condition-card__menu" }, [i("button", { staticClass: "guido-display-condition-card__menu-item", attrs: { id: `guido__display-condition-delete-${e.id}`, type: "button" }, on: { click: function(n) {
16
+ return t.requestDelete(e);
17
+ } } }, [s._v(" " + s._s(t.trans(`${t.KEY}.delete`)) + " ")])]) : s._e()], 1), i("span", { staticClass: "guido-display-condition-card__divider" }), i("button", { staticClass: "guido-display-condition-card__expand", attrs: { id: `guido__display-condition-expand-${e.id}`, type: "button", "aria-expanded": t.expandedId === e.id ? "true" : "false", "aria-label": t.trans(`${t.KEY}.preview`) }, on: { click: function(n) {
18
+ return t.toggleExpanded(e);
19
+ } } }, [i(t.InIcons, { attrs: { name: t.expandedId === e.id ? "filled-dropdown-up" : "filled-dropdown-down" } })], 1)])]), t.expandedId === e.id ? i("pre", { staticClass: "guido-display-condition-card__code" }, [s._v(s._s(t.codeOf(e)))]) : s._e()]);
20
+ }), 0) : i(t.InNoData, { attrs: { id: "guido__display-condition-no-result", icon: "no-data", title: t.trans(`${t.KEY}.no-result`) } }) : i(t.InNoData, { attrs: { id: "guido__display-condition-empty", "button-status": "", icon: "no-personalization", "button-text": t.trans(`${t.KEY}.create-new`), description: t.trans(`${t.KEY}.empty-description`), title: t.trans(`${t.KEY}.empty-title`) }, on: { click: function(e) {
21
+ return t.store.openCreate();
22
+ } } })], 1)]), t.store.pendingDelete ? i("div", { staticClass: "guido-display-condition-select__delete-modal" }, [i(t.WpModal, { attrs: { id: "guido__display-condition-delete-modal", size: "X-small", state: "danger", "close-on-outside-click": !1, "footer-button-options": t.deleteModalButtons, title: t.trans(`${t.KEY}.delete-confirm-title`) }, on: { close: t.closeDeleteModal, "primary-action": t.confirmDelete } }, [i("p", { staticClass: "guido-display-condition-select__delete-text" }, [s._v(" " + s._s(t.trans(`${t.KEY}.delete-confirm-description`, { name: t.store.pendingDelete.name })) + " ")])])], 1) : s._e()], 1);
23
+ }, l = [], c = /* @__PURE__ */ o(
24
+ a,
25
+ d,
26
+ l,
27
+ !1,
28
+ null,
29
+ "10ac7a13"
30
+ );
31
+ const y = c.exports;
32
+ export {
33
+ y as default
34
+ };
@@ -0,0 +1,57 @@
1
+ import { defineComponent as _, ref as i, watch as S, computed as c } from "vue";
2
+ import B from "../../wrappers/WpDrawer.vue.js";
3
+ import L from "../../wrappers/WpModal.vue.js";
4
+ import { useDisplayConditions as x } from "../../../composables/useDisplayConditions.js";
5
+ import { useTranslations as O } from "../../../composables/useTranslations.js";
6
+ import { ACADEMY_LINKS as T } from "../../../enums/academy.js";
7
+ import { useDisplayConditionStore as $ } from "../../../stores/display-condition.js";
8
+ import { InSkeleton as C, InNoData as E, InIcons as M, InButtonV2 as b, InBasicTextInput as k } from "@useinsider/design-system-vue";
9
+ const J = /* @__PURE__ */ _({
10
+ __name: "DisplayConditionSelectDrawer",
11
+ setup(h) {
12
+ const o = "email-editor.display-conditions", m = [40, 76, 76, 76], l = O(), t = $(), { loadList: d, select: f, deleteSaved: u, cancel: g } = x(), r = i(""), s = i(null), a = i(null), n = i(!1);
13
+ S(() => t.isSelectOpen, (e) => {
14
+ e && (r.value = "", s.value = null, a.value = null, d());
15
+ }, { immediate: !0 });
16
+ const D = c(() => {
17
+ const e = r.value.trim().toLocaleLowerCase();
18
+ return e ? t.list.filter((p) => `${p.name} ${p.description}`.toLocaleLowerCase().includes(e)) : t.list;
19
+ }), v = c(() => l(`${o}.select-description`, {
20
+ academyLink: `<a href="${T.EMAIL_DISPLAY_CONDITIONS}" class="guido-display-condition-academy" target="_blank">${l(`${o}.academy`)}</a>`
21
+ })), y = c(() => ({
22
+ cancelOrBackButton: {
23
+ styling: "ghost",
24
+ type: "secondary",
25
+ labelText: l(`${o}.back`),
26
+ leftIcon: "line-arrow-left"
27
+ }
28
+ })), I = c(() => ({
29
+ cancelOrBackButton: {
30
+ type: "secondary",
31
+ styling: "ghost",
32
+ labelText: l(`${o}.cancel`),
33
+ disabledStatus: n.value
34
+ },
35
+ primaryButton: {
36
+ type: "danger",
37
+ labelText: l(`${o}.delete`),
38
+ loadingStatus: n.value
39
+ }
40
+ }));
41
+ return { __sfc: !0, KEY: o, SKELETON_HEIGHTS: m, trans: l, store: t, loadList: d, select: f, deleteSaved: u, cancel: g, search: r, expandedId: s, menuId: a, isDeleting: n, filteredList: D, descriptionText: v, footerButtonGroupOptions: y, deleteModalButtons: I, toggleExpanded: (e) => {
42
+ s.value = s.value === e.id ? null : e.id;
43
+ }, toggleMenu: (e) => {
44
+ a.value = a.value === e.id ? null : e.id;
45
+ }, requestDelete: (e) => {
46
+ a.value = null, t.pendingDelete = e;
47
+ }, confirmDelete: async () => {
48
+ !t.pendingDelete || n.value || (n.value = !0, await u(t.pendingDelete), n.value = !1);
49
+ }, closeDeleteModal: () => {
50
+ n.value || (t.pendingDelete = null);
51
+ }, codeOf: (e) => [e.codeBefore, e.codeAfter].filter(Boolean).join(`
52
+ `), WpDrawer: B, WpModal: L, InBasicTextInput: k, InButtonV2: b, InIcons: M, InNoData: E, InSkeleton: C };
53
+ }
54
+ });
55
+ export {
56
+ J as default
57
+ };
@@ -0,0 +1,17 @@
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
+ };
@@ -0,0 +1,22 @@
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,6 +1,6 @@
1
- import r from "../extensions/ModulesTabIcons/extension.js";
2
- import { useConfigStore as l } from "../stores/config.js";
3
- const a = {
1
+ import l from "../extensions/ModulesTabIcons/extension.js";
2
+ import { useConfigStore as c } from "../stores/config.js";
3
+ const s = {
4
4
  "amp-accordion": "ampAccordionEnabled",
5
5
  "amp-carousel": "ampCarouselEnabled",
6
6
  "amp-form-controls": "ampFormControlsEnabled",
@@ -14,7 +14,7 @@ const a = {
14
14
  "text-block": "textEnabled",
15
15
  "timer-block": "timerEnabled",
16
16
  "video-block": "videoEnabled"
17
- }, s = {
17
+ }, i = {
18
18
  "dynamic-content": () => import("../extensions/DynamicContent/extension.js"),
19
19
  "checkbox-block": () => import("../extensions/Blocks/Checkbox/extension.js"),
20
20
  "radio-button-block": () => import("../extensions/Blocks/RadioButton/extension.js"),
@@ -22,40 +22,48 @@ const a = {
22
22
  "unsubscribe-block": () => import("../extensions/Blocks/Unsubscribe/extension.js"),
23
23
  "coupon-block": () => import("../extensions/Blocks/CouponBlock/extension.js"),
24
24
  "items-block": () => import("../extensions/Blocks/Items/extension.js")
25
- }, i = (n) => {
26
- if (!n || !n.length)
25
+ }, b = (o) => {
26
+ if (!o || !o.length)
27
27
  return {};
28
28
  const t = {};
29
- return n.forEach((o) => {
30
- const e = a[o];
29
+ return o.forEach((n) => {
30
+ const e = s[n];
31
31
  e && (t[e] = !1);
32
32
  }), t;
33
- }, b = () => [r], m = async (n) => {
34
- const t = b();
35
- if (!n || !n.length)
36
- return t;
37
- const o = await Promise.all(
38
- n.map(async (e) => {
39
- const c = s[e];
40
- return c ? (await c()).default : null;
33
+ }, m = async (o) => {
34
+ if (!o)
35
+ return [l];
36
+ const t = await import("../extensions/DisplayConditions/extension.js");
37
+ return [l, t.default];
38
+ }, d = async (o, t = !1) => {
39
+ const n = await m(t);
40
+ if (!o || !o.length)
41
+ return n;
42
+ const e = await Promise.all(
43
+ o.map(async (r) => {
44
+ const a = i[r];
45
+ return a ? (await a()).default : null;
41
46
  })
42
47
  );
43
48
  return [
44
- ...t,
45
- ...o.filter((e) => e !== null)
49
+ ...n,
50
+ ...e.filter((r) => r !== null)
46
51
  ];
47
- }, E = () => {
48
- const n = l();
52
+ }, k = () => {
53
+ const o = c();
49
54
  return {
50
55
  getStripoBlocksConfig: async () => {
51
- const o = n.blocks;
56
+ const n = o.blocks;
52
57
  return {
53
- baseBlocks: i(o == null ? void 0 : o.excludeDefaults),
54
- extensions: await m(o == null ? void 0 : o.includeCustoms)
58
+ baseBlocks: b(n == null ? void 0 : n.excludeDefaults),
59
+ extensions: await d(
60
+ n == null ? void 0 : n.includeCustoms,
61
+ o.externalDisplayConditions
62
+ )
55
63
  };
56
64
  }
57
65
  };
58
66
  };
59
67
  export {
60
- E as useBlocksConfig
68
+ k as useBlocksConfig
61
69
  };
@@ -0,0 +1,102 @@
1
+ import { useToaster as T } from "./useToaster.js";
2
+ import { useTranslations as x } from "./useTranslations.js";
3
+ import { DISPLAY_CONDITION_LIMITS as s, DisplayConditionEvent as S } from "../enums/display-condition.js";
4
+ import { ToasterTypeOptions as d } from "../enums/toaster.js";
5
+ import { useDisplayConditionApi as M } from "../services/displayConditionApi.js";
6
+ import { useConfigStore as N } from "../stores/config.js";
7
+ import { useDisplayConditionStore as _ } from "../stores/display-condition.js";
8
+ import { findInvalidCodeFields as O, nextConditionId as L } from "../utils/displayCondition.js";
9
+ import { escapeHtml as B } from "../utils/htmlEscape.js";
10
+ import { computed as P } from "vue";
11
+ const i = "email-editor.display-conditions", X = 409, y = (n, p, r) => ({
12
+ id: L(),
13
+ name: n.name.trim(),
14
+ description: n.description.trim(),
15
+ beforeScript: n.codeBefore,
16
+ afterScript: n.codeAfter,
17
+ extraData: JSON.stringify(r === void 0 ? { source: p } : { source: p, savedId: r })
18
+ }), C = (n) => ({
19
+ name: n.name,
20
+ description: n.description,
21
+ codeBefore: n.codeBefore,
22
+ codeAfter: n.codeAfter
23
+ }), U = () => {
24
+ const n = _(), p = N(), r = M(), o = x(), { showToaster: a } = T(), u = P(() => {
25
+ var e;
26
+ return (e = p.features) != null && e.liquidSyntax ? "liquid" : "pongo";
27
+ }), f = (e) => {
28
+ const t = { condition: e };
29
+ document.dispatchEvent(new CustomEvent(S.APPLY, { detail: t })), n.close();
30
+ }, E = () => {
31
+ n.view !== "none" && (document.dispatchEvent(new CustomEvent(S.CANCEL)), n.close());
32
+ }, $ = (e) => {
33
+ if (e.mode === "select") {
34
+ n.openSelect();
35
+ return;
36
+ }
37
+ n.openCreate(e.mode === "edit" ? e.current : null);
38
+ }, g = async () => {
39
+ n.listStatus = "loading";
40
+ try {
41
+ n.list = await r.list(u.value), n.listStatus = "loaded";
42
+ } catch (e) {
43
+ console.warn("Display conditions could not be loaded.", e), n.listStatus = "error";
44
+ }
45
+ }, h = (e) => {
46
+ const t = {}, m = e.name.trim();
47
+ m ? m.length < s.NAME_MIN ? t.name = o(`${i}.error-name-min`, { min: s.NAME_MIN }) : m.length > s.NAME_MAX && (t.name = o(`${i}.error-name-max`, { max: s.NAME_MAX })) : t.name = o(`${i}.error-name-required`);
48
+ const { DESCRIPTION_MAX: A } = s;
49
+ e.description.trim().length > A && (t.description = o(`${i}.error-description-max`, { max: A }));
50
+ const D = O(e.codeBefore, e.codeAfter);
51
+ return ["codeBefore", "codeAfter"].forEach((c) => {
52
+ e[c].trim() ? D.includes(c) ? t[c] = o(`${i}.error-code-invalid`) : e[c].length > s.CODE_MAX && (t[c] = o(`${i}.error-code-max`, { max: s.CODE_MAX })) : t[c] = o(`${i}.error-code-required`);
53
+ }), t;
54
+ }, I = () => {
55
+ a({ type: d.Error, message: o(`${i}.validation-failed`) });
56
+ }, l = (e) => ({ name: B(e) }), v = (e, t) => {
57
+ e != null && e.authReported || (console.warn(t, e), a({ type: d.Error, message: t }));
58
+ };
59
+ return {
60
+ syntax: u,
61
+ handleOpen: $,
62
+ cancel: E,
63
+ loadList: g,
64
+ validate: h,
65
+ notifyInvalid: I,
66
+ createInline: (e) => {
67
+ f(y(e, "inline")), a({
68
+ type: d.Success,
69
+ message: o(`${i}.created`, l(e.name.trim()))
70
+ });
71
+ },
72
+ createAndSave: async (e) => {
73
+ try {
74
+ const t = await r.create(e, u.value);
75
+ return n.list = [t, ...n.list.filter((m) => m.id !== t.id)], f(y(C(t), "saved", t.id)), a({
76
+ type: d.Success,
77
+ message: o(`${i}.created-and-saved`, l(t.name))
78
+ }), {};
79
+ } catch (t) {
80
+ return (t == null ? void 0 : t.status) === X ? { name: o(`${i}.error-name-exists`) } : (v(t, o(`${i}.save-failed`, l(e.name.trim()))), null);
81
+ }
82
+ },
83
+ select: (e) => {
84
+ f(y(C(e), "saved", e.id)), a({ type: d.Success, message: o(`${i}.applied`, l(e.name)) });
85
+ },
86
+ deleteSaved: async (e) => {
87
+ try {
88
+ await r.remove(e.id), n.list = n.list.filter((t) => t.id !== e.id), a({
89
+ type: d.Success,
90
+ message: o(`${i}.deleted`, l(e.name))
91
+ });
92
+ } catch (t) {
93
+ v(t, o(`${i}.delete-failed`));
94
+ } finally {
95
+ n.pendingDelete = null;
96
+ }
97
+ }
98
+ };
99
+ };
100
+ export {
101
+ U as useDisplayConditions
102
+ };
@@ -7,13 +7,13 @@ function L(t, r, e, o, c = "") {
7
7
  const i = `{{${c}${t}_${r}_${e}}}`, n = `{{${c}${t}_${r}_currency}}`;
8
8
  return o === "before" ? `${n} ${i}` : `${i} ${n}`;
9
9
  }
10
- function _(t) {
10
+ function A(t) {
11
11
  let r = t;
12
12
  for (; r.children.length === 1; )
13
13
  [r] = r.children;
14
14
  return r;
15
15
  }
16
- function A(t, r, e, o, c, i) {
16
+ function y(t, r, e, o, c, i) {
17
17
  switch (r) {
18
18
  case "productImage": {
19
19
  const n = t.querySelector("img");
@@ -24,7 +24,7 @@ function A(t, r, e, o, c, i) {
24
24
  }
25
25
  case "productName": {
26
26
  const n = t.querySelector("p");
27
- n && (_(n).textContent = `{{${i}${e}_${o}_name}}`);
27
+ n && (A(n).textContent = `{{${i}${e}_${o}_name}}`);
28
28
  break;
29
29
  }
30
30
  // Inline mode ("Move to next line" OFF) merges BOTH prices into one row
@@ -32,16 +32,16 @@ function A(t, r, e, o, c, i) {
32
32
  // substitute by cell content, not by the row's anchor (SD-145161).
33
33
  case "productPrice":
34
34
  case "productOldPrice": {
35
- const n = (l, d) => {
36
- l && (_(l).textContent = L(
35
+ const n = (a, l) => {
36
+ a && (A(a).textContent = L(
37
37
  e,
38
38
  o,
39
- d,
39
+ l,
40
40
  c,
41
41
  i
42
42
  ));
43
- }, s = t.querySelector(".product-price p"), a = t.querySelector(".product-old-price p"), u = !s && !a ? t.querySelector("p") : null;
44
- n(s ?? (r === "productPrice" ? u : null), "price"), n(a ?? (r === "productOldPrice" ? u : null), "original_price");
43
+ }, s = t.querySelector(".product-price p"), d = t.querySelector(".product-old-price p"), u = !s && !d ? t.querySelector("p") : null;
44
+ n(s ?? (r === "productPrice" ? u : null), "price"), n(d ?? (r === "productOldPrice" ? u : null), "original_price");
45
45
  break;
46
46
  }
47
47
  case "productButton": {
@@ -70,8 +70,8 @@ function A(t, r, e, o, c, i) {
70
70
  default: {
71
71
  const n = t.getAttribute("product-attr") ? t : t.querySelector("[product-attr]");
72
72
  if (n) {
73
- const s = n.getAttribute("product-attr"), a = n.querySelector("p");
74
- a && (_(a).textContent = `{{${i}${e}_${o}_${s}}}`);
73
+ const s = n.getAttribute("product-attr"), d = n.querySelector("p");
74
+ d && (A(d).textContent = `{{${i}${e}_${o}_${s}}}`);
75
75
  }
76
76
  break;
77
77
  }
@@ -88,54 +88,54 @@ function b(t, r, e, o) {
88
88
  function R(t, r, e) {
89
89
  return b(t, r, 0, e);
90
90
  }
91
- function D(t, r, e, o) {
91
+ function w(t, r, e, o) {
92
92
  if (!t.innerHTML.includes("{{"))
93
93
  return;
94
94
  const { open: c, close: i } = b(t.ownerDocument, r, e, o);
95
95
  t.insertBefore(c, t.firstChild), t.appendChild(i);
96
96
  }
97
- function w(t, r, e, o) {
97
+ function D(t, r, e, o) {
98
98
  var n, s;
99
99
  if (!t.innerHTML.includes("{{"))
100
100
  return;
101
101
  const { open: c, close: i } = b(t.ownerDocument, r, e, o);
102
102
  (n = t.parentNode) == null || n.insertBefore(c, t), (s = t.parentNode) == null || s.insertBefore(i, t.nextSibling);
103
103
  }
104
- function W(t, r, e, o) {
104
+ function v(t, r, e, o) {
105
105
  t.querySelectorAll(".recommendation-product-row").forEach((i, n) => {
106
- i.querySelectorAll("[data-attribute-type]").forEach((a) => {
107
- const u = a.getAttribute("data-attribute-type") || "", l = a.querySelectorAll(".attribute-cell");
108
- l.length > 0 ? l.forEach((d) => {
109
- A(d, u, r, n, e, o);
110
- }) : A(a, u, r, n, e, o);
111
- }), w(i, r, n, o);
106
+ i.querySelectorAll("[data-attribute-type]").forEach((d) => {
107
+ const u = d.getAttribute("data-attribute-type") || "", a = d.querySelectorAll(".attribute-cell");
108
+ a.length > 0 ? a.forEach((l) => {
109
+ y(l, u, r, n, e, o);
110
+ }) : y(d, u, r, n, e, o);
111
+ }), D(i, r, n, o);
112
112
  });
113
113
  }
114
- function v(t, r, e, o) {
114
+ function H(t, r, e, o) {
115
115
  const c = t.querySelectorAll(".recommendation-product-row");
116
116
  if (!c.length)
117
117
  return;
118
118
  const [i] = c, n = i.querySelector("[data-attribute-type]"), s = n ? n.querySelectorAll(".attribute-cell").length : 1;
119
- c.forEach((a, u) => {
120
- a.querySelectorAll("[data-attribute-type]").forEach((d) => {
121
- const p = d.getAttribute("data-attribute-type") || "";
122
- d.querySelectorAll(".attribute-cell").forEach((f, m) => {
123
- const h = u * s + m;
124
- A(f, p, r, h, e, o), D(f, r, h, o);
119
+ c.forEach((d, u) => {
120
+ d.querySelectorAll("[data-attribute-type]").forEach((l) => {
121
+ const p = l.getAttribute("data-attribute-type") || "";
122
+ l.querySelectorAll(".attribute-cell").forEach((f, h) => {
123
+ const S = u * s + h;
124
+ y(f, p, r, S, e, o), w(f, r, S, o);
125
125
  });
126
126
  });
127
127
  });
128
128
  }
129
- function H(t, r, e, o) {
129
+ function W(t, r, e, o) {
130
130
  t.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
131
- v(i, r, e, o);
131
+ H(i, r, e, o);
132
132
  });
133
133
  }
134
134
  function F(t, r, e) {
135
135
  const o = t.getAttribute("data-layout") || "grid", c = t.getAttribute("currency-alignment") || "after";
136
- o === "list" ? W(t, r, c, e) : H(t, r, c, e);
136
+ o === "list" ? v(t, r, c, e) : W(t, r, c, e);
137
137
  }
138
- function y(t, r, e) {
138
+ function _(t, r, e) {
139
139
  const o = new RegExp(`${r}\\s*:\\s*(\\d+)\\s*px`, "i"), c = t.match(o);
140
140
  return c ? parseInt(c[1]) : e;
141
141
  }
@@ -150,7 +150,7 @@ function C(t) {
150
150
  const e = (t.getAttribute("style") || "").match(/(?:^|[;\s])width\s*:\s*(\d+(?:\.\d+)?(?:px|%))/i);
151
151
  return e && $(e[1]) ? e[1] : null;
152
152
  }
153
- function G(t, r) {
153
+ function x(t, r) {
154
154
  let e = t.parentElement;
155
155
  for (; e && e !== r; ) {
156
156
  if (e.tagName === "TD" && C(e))
@@ -159,35 +159,37 @@ function G(t, r) {
159
159
  }
160
160
  return null;
161
161
  }
162
- function V(t) {
163
- const r = t.getAttribute("style") || "", e = y(r, "width", 600), o = y(r, "padding", 0) * 2, c = Math.max(0, e - o);
162
+ function G(t) {
163
+ const r = t.getAttribute("style") || "", e = _(r, "width", 600), o = _(r, "padding", 0) * 2, c = Math.max(0, e - o);
164
164
  c !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
165
165
  if (i.hasAttribute("width"))
166
166
  return;
167
- const n = G(i, t);
167
+ const n = x(i, t);
168
168
  if (!n)
169
169
  return;
170
- const s = C(n), a = y(n.getAttribute("style") || "", "padding", 0) * 2, u = s.endsWith("%") ? Math.floor(c * parseFloat(s) / 100) : parseInt(s), l = Math.max(1, u - a);
171
- i.setAttribute("width", String(l));
172
- const d = i.getAttribute("style") || "";
173
- if (!/\bwidth\s*:\s*\d/i.test(d)) {
174
- const p = d && !d.trim().endsWith(";") ? "; " : "";
175
- i.setAttribute("style", `${d}${p}width: ${l}px`);
170
+ const s = C(n), d = _(n.getAttribute("style") || "", "padding", 0) * 2, u = s.endsWith("%") ? Math.floor(c * parseFloat(s) / 100) : parseInt(s), a = Math.max(1, u - d), l = i.getAttribute("style") || "", p = /(?:^|[;\s])max-height\s*:\s*(\d+(?:\.\d+)?)px/i.exec(l);
171
+ if (p) {
172
+ i.setAttribute("width", String(Math.max(1, Math.min(a, Math.floor(parseFloat(p[1])))))), i.removeAttribute("height");
173
+ return;
174
+ }
175
+ if (i.setAttribute("width", String(a)), !/\bwidth\s*:\s*\d/i.test(l)) {
176
+ const m = l && !l.trim().endsWith(";") ? "; " : "";
177
+ i.setAttribute("style", `${l}${m}width: ${a}px`);
176
178
  }
177
179
  });
178
180
  }
179
- const E = "MSO_MOBILE_HIDE_START", U = "MSO_MOBILE_HIDE_END";
180
- function X(t, r) {
181
+ const E = "MSO_MOBILE_HIDE_START", V = "MSO_MOBILE_HIDE_END";
182
+ function U(t, r) {
181
183
  t.querySelectorAll(q).forEach((e) => {
182
184
  var i, n;
183
185
  const o = e.querySelector(M);
184
186
  if (!o || o.children.length === 0)
185
187
  return;
186
188
  const c = e.previousSibling;
187
- (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(U), e.nextSibling));
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(V), e.nextSibling));
188
190
  });
189
191
  }
190
- function j(t, r) {
192
+ function X(t, r) {
191
193
  const e = t.match(/<!DOCTYPE[^>]*>/i);
192
194
  return (e ? `${e[0]}
193
195
  ` : "") + r.documentElement.outerHTML;
@@ -200,17 +202,17 @@ function Q(t) {
200
202
  i.recommendationCampaignUrls = {};
201
203
  const { isFeatureEnabled: n } = g(), s = n("liquidSyntax") ? "reco_" : "";
202
204
  return o.forEach((u) => {
203
- var d, p, S, f;
204
- const l = u.getAttribute("recommendation-id");
205
- if (l) {
206
- 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((m) => m.remove()), c(l), X(u, e), !T(u)) {
207
- F(u, l, s);
208
- const { open: m, close: h } = R(e, l, s);
209
- (S = u.parentNode) == null || S.insertBefore(m, u), (f = u.parentNode) == null || f.insertBefore(h, u.nextSibling);
205
+ var l, p, m, f;
206
+ const a = u.getAttribute("recommendation-id");
207
+ if (a) {
208
+ if ((l = u.parentNode) == null || l.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(a), U(u, e), !T(u)) {
209
+ F(u, a, s);
210
+ const { open: h, close: S } = R(e, a, s);
211
+ (m = u.parentNode) == null || m.insertBefore(h, u), (f = u.parentNode) == null || f.insertBefore(S, u.nextSibling);
210
212
  }
211
- V(u);
213
+ G(u);
212
214
  }
213
- }), j(r, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
215
+ }), X(r, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
214
216
  }
215
217
  export {
216
218
  L as formatPriceVariable,
@@ -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
  };
7
8
  export {
@@ -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
+ };