@useinsider/guido 3.18.2-beta.45f708c → 3.18.2-beta.545d1bd

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 (46) hide show
  1. package/dist/components/Guido.vue.js +1 -1
  2. package/dist/components/Guido.vue2.js +60 -54
  3. package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue.js +11 -13
  4. package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue2.js +51 -70
  5. package/dist/components/organisms/extensions/recommendation/RemoveStrategyModal.vue2.js +37 -23
  6. package/dist/components/organisms/onboarding/OnboardingWrapper.vue2.js +18 -20
  7. package/dist/composables/useActionsApi.js +24 -20
  8. package/dist/composables/useCortexBlueprintBridge.js +115 -54
  9. package/dist/composables/useCustomInterfaceAppearance.js +46 -56
  10. package/dist/composables/useEmailTemplateApplier.js +93 -50
  11. package/dist/composables/useHtmlValidator.js +79 -84
  12. package/dist/composables/useRecommendation.js +35 -40
  13. package/dist/composables/useStripo.js +30 -30
  14. package/dist/enums/extensions/recommendationBlock.js +31 -38
  15. package/dist/extensions/Blocks/Recommendation/block.js +39 -43
  16. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +20 -21
  17. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +35 -40
  18. package/dist/extensions/Blocks/Recommendation/controls/main/strategy.js +52 -84
  19. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +74 -74
  20. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +90 -189
  21. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +16 -26
  22. package/dist/extensions/Blocks/Recommendation/validation/requiredFields.js +12 -21
  23. package/dist/guido.css +1 -1
  24. package/dist/src/composables/useCortexBlueprintBridge.d.ts +4 -3
  25. package/dist/src/composables/useEmailTemplateApplier.d.ts +22 -2
  26. package/dist/src/enums/extensions/recommendationBlock.d.ts +0 -2
  27. package/dist/src/extensions/Blocks/Recommendation/constants/defaultConfig.d.ts +0 -1
  28. package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +1 -1
  29. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +0 -2
  30. package/dist/src/extensions/Blocks/Recommendation/controls/main/strategy.d.ts +0 -9
  31. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +2 -7
  32. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +0 -75
  33. package/dist/src/extensions/Blocks/Recommendation/validation/requiredFields.d.ts +0 -4
  34. package/dist/src/stores/guido-email-editor.d.ts +29 -7
  35. package/dist/src/stores/onboarding.d.ts +0 -377
  36. package/dist/static/styles/components/recommendation-strategy.css.js +4 -34
  37. package/dist/stores/guido-email-editor.js +5 -1
  38. package/dist/stores/onboarding.js +36 -41
  39. package/dist/utils/templatePreparation.js +55 -55
  40. package/package.json +1 -1
  41. package/dist/components/organisms/onboarding/RecommendationStrategyOnboarding.vue.js +0 -21
  42. package/dist/components/organisms/onboarding/RecommendationStrategyOnboarding.vue2.js +0 -47
  43. package/dist/extensions/Blocks/Recommendation/utils/strategyCommit.js +0 -24
  44. package/dist/src/components/organisms/onboarding/RecommendationStrategyOnboarding.vue.d.ts +0 -2
  45. package/dist/src/extensions/Blocks/Recommendation/utils/strategyCommit.d.ts +0 -14
  46. package/dist/static/styles/components/skeleton.css.js +0 -23
@@ -1,17 +1,21 @@
1
1
  import { filterAmpErrors as v } from "../utils/ampErrorFilter.js";
2
2
  import { useToaster as y } from "./useToaster.js";
3
- const D = 1e4, d = 3e4, s = (n, l, u) => new Promise((T, m) => {
4
- const w = setTimeout(
5
- () => m(new Error(`${n} did not report completion within ${l}ms`)),
3
+ const D = 1e4, T = 3e4, p = (n, l, w) => new Promise((A, s) => {
4
+ const c = setTimeout(
5
+ () => s(new Error(`${n} did not report completion within ${l}ms`)),
6
6
  l
7
- ), p = (A) => (t) => {
8
- clearTimeout(w), A(t);
7
+ ), d = (r) => (t) => {
8
+ clearTimeout(c), r(t);
9
9
  };
10
- u(p(T), p(m));
10
+ try {
11
+ w(d(A), d(s));
12
+ } catch (r) {
13
+ clearTimeout(c), s(r instanceof Error ? r : new Error(String(r)));
14
+ }
11
15
  }), I = () => {
12
- const { handleError: n } = y(), l = (t = {}) => s(
16
+ const { handleError: n } = y(), l = (t = {}) => p(
13
17
  "compileEmail",
14
- d,
18
+ T,
15
19
  (e, a) => {
16
20
  const o = { ...{
17
21
  minimize: !0,
@@ -32,9 +36,9 @@ const D = 1e4, d = 3e4, s = (n, l, u) => new Promise((T, m) => {
32
36
  forceAmp: !1,
33
37
  resetDataSavedFlag: !1,
34
38
  disableLineHeightsReplace: !0
35
- }, ...t }, c = {
36
- callback: (r, C, f, S, g) => {
37
- r ? a(r) : e({
39
+ }, ...t }, u = {
40
+ callback: (m, C, f, S, g) => {
41
+ m ? a(m) : e({
38
42
  html: C,
39
43
  ampHtml: f,
40
44
  ampErrors: v(S ?? []),
@@ -43,22 +47,22 @@ const D = 1e4, d = 3e4, s = (n, l, u) => new Promise((T, m) => {
43
47
  },
44
48
  ...o
45
49
  };
46
- window.StripoEditorApi.actionsApi.compileEmail(c);
50
+ window.StripoEditorApi.actionsApi.compileEmail(u);
47
51
  }
48
52
  );
49
53
  return {
50
54
  getCompiledEmail: l,
51
- getTemplateData: () => s(
55
+ getTemplateData: () => p(
52
56
  "getTemplateData",
53
- d,
57
+ T,
54
58
  (t) => {
55
- const e = ({ html: a, css: i, width: o, height: E, utmParams: c, syncModulesIds: r }) => t({
59
+ const e = ({ html: a, css: i, width: o, height: E, utmParams: u, syncModulesIds: m }) => t({
56
60
  html: a,
57
61
  css: i,
58
62
  width: o,
59
63
  height: E,
60
- utmParams: c,
61
- syncModulesIds: r
64
+ utmParams: u,
65
+ syncModulesIds: m
62
66
  });
63
67
  window.StripoEditorApi.actionsApi.getTemplateData(e);
64
68
  }
@@ -105,13 +109,13 @@ const D = 1e4, d = 3e4, s = (n, l, u) => new Promise((T, m) => {
105
109
  }),
106
110
  updateHtmlAndCss: (t, e) => {
107
111
  const { actionsApi: a } = window.StripoEditorApi;
108
- return s("updateHtmlAndCss", D, (i) => {
112
+ return p("updateHtmlAndCss", D, (i) => {
109
113
  a.updateHtmlAndCss(t, e, () => i());
110
114
  });
111
115
  },
112
- editorSave: () => s(
116
+ editorSave: () => p(
113
117
  "save",
114
- d,
118
+ T,
115
119
  (t) => {
116
120
  window.StripoEditorApi.actionsApi.save((e) => {
117
121
  if (e) {
@@ -1,70 +1,131 @@
1
- import { useEmailTemplateApplier as w, resetEmailTemplateApplier as _ } from "./useEmailTemplateApplier.js";
2
- import { useToaster as I } from "./useToaster.js";
3
- import { useTranslations as P } from "./useTranslations.js";
4
- import { ToasterTypeOptions as S } from "../enums/toaster.js";
5
- import { getActivePinia as v } from "pinia";
6
- import { watch as B, onUnmounted as D } from "vue";
7
- const x = "email_template", L = "chat", M = "guido:debug:ai", R = () => {
1
+ import { useEmailTemplateApplier as k, resetEmailTemplateApplier as N } from "./useEmailTemplateApplier.js";
2
+ import { useToaster as X } from "./useToaster.js";
3
+ import { useTranslations as j } from "./useTranslations.js";
4
+ import { ToasterTypeOptions as z } from "../enums/toaster.js";
5
+ import { useGuidoEmailEditorStore as J } from "../stores/guido-email-editor.js";
6
+ import { getActivePinia as Q } from "pinia";
7
+ import { onUnmounted as V, watch as Z } from "vue";
8
+ const W = "email_template", tt = "chat", et = "guido:debug:ai", rt = 2, nt = 500, ot = (A, p) => `${A}:${p ?? 1}`;
9
+ let v = null;
10
+ const it = () => {
8
11
  if (typeof window > "u")
9
12
  return !1;
10
13
  try {
11
- return window.localStorage.getItem(M) === "1";
14
+ return window.localStorage.getItem(et) === "1";
12
15
  } catch {
13
16
  return !1;
14
17
  }
15
- }, H = () => {
16
- const c = v();
17
- if (!c)
18
+ }, ft = () => {
19
+ const A = Q();
20
+ if (!A)
18
21
  return;
19
- const l = c._s, p = l == null ? void 0 : l.get(L);
20
- if (!p)
21
- return;
22
- const { markPending: d, applyTemplate: f, applyTemplateDebounced: T } = w(), { showToaster: E } = I(), h = P(), y = (r, t) => {
23
- const e = h(r);
24
- return e === r ? t : e;
25
- }, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), u = R(), A = (r, t) => {
26
- u && console.debug(`[guido:cortex] msg=${r ?? "?"} type=${(t == null ? void 0 : t.type) ?? "?"}`, t);
27
- }, b = (r) => {
28
- if (r.blueprintType !== x)
22
+ const p = J(), y = Symbol("cortexBlueprintBridge");
23
+ v = y, p.$patch((t) => {
24
+ t.bridgeActive = !0;
25
+ });
26
+ const { markPending: x, applyTemplate: F, applyTemplateDebounced: I } = k(), { showToaster: C } = X(), H = j(), h = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Set(), M = it();
27
+ let T = null, b = null, f;
28
+ const O = (t, e) => {
29
+ M && console.debug(`[guido:cortex] msg=${t ?? "?"} type=${(e == null ? void 0 : e.type) ?? "?"}`, e);
30
+ }, G = () => new Set((f == null ? void 0 : f.appliedBlueprintKeys) ?? []), K = (t) => t instanceof Error ? t.message : String(t), D = (t, e, o, r) => {
31
+ if (v !== y)
32
+ return;
33
+ const n = p.applyAcks[t], l = Math.max(Date.now(), ((n == null ? void 0 : n.ackAt) ?? 0) + 1), c = { status: e, requestedAt: o, ackAt: l };
34
+ r !== void 0 && (c.error = K(r)), p.$patch((a) => {
35
+ a.applyAcks = { ...a.applyAcks, [t]: c };
36
+ });
37
+ }, B = (t) => (d.get(t) ?? 0) > 0, w = async (t, e, o, r) => {
38
+ var a, i, q;
39
+ const n = ((a = o.blueprintData) == null ? void 0 : a.html) ?? "", l = ((i = o.blueprintData) == null ? void 0 : i.css) ?? "", c = o.applyRequestedAt ?? 0;
40
+ d.set(t, (d.get(t) ?? 0) + 1);
41
+ try {
42
+ const s = r === "debounced" ? await I(e, { html: n, css: l }) : await F(e, { html: n, css: l });
43
+ if (s.status === "superseded")
44
+ return;
45
+ if (s.status === "applied") {
46
+ h.set(e, n), u.delete(t), D(t, "applied", c);
47
+ return;
48
+ }
49
+ const m = u.get(t);
50
+ u.set(t, { html: n, count: (m == null ? void 0 : m.html) === n ? m.count + 1 : 1 }), D(t, "failed", c, s.error);
51
+ } finally {
52
+ d.set(t, (d.get(t) ?? 1) - 1);
53
+ const s = E.get(t);
54
+ s && !B(t) && (E.delete(t), (((q = s.blueprintData) == null ? void 0 : q.html) ?? "") !== n && w(t, e, s, r));
55
+ }
56
+ }, U = (t) => {
57
+ var a;
58
+ if (t.blueprintType !== W)
29
59
  return;
30
- const t = r.blueprintId, e = r.blueprintData;
31
- if (!t || !(e != null && e.html))
60
+ const { blueprintId: e } = t, o = (a = t.blueprintData) == null ? void 0 : a.html;
61
+ if (!e || !o)
32
62
  return;
33
- if (!r.applyRequested) {
34
- d(t);
63
+ if (!t.applyRequested) {
64
+ x(e);
35
65
  return;
36
66
  }
37
- const o = i.get(t);
38
- o === void 0 ? (i.set(t, e.html), f(t, e)) : o !== e.html && (i.set(t, e.html), T(t, e));
39
- }, s = (r) => r === void 0 || a.has(r) ? !1 : (a.add(r), E({
40
- type: S.Error,
41
- message: y("newsletter.ai-template-failed", "AI couldn't generate the template. Please try again.")
42
- }), !0), m = B(
43
- () => p.messages,
44
- (r) => {
45
- Array.isArray(r) && r.forEach((t) => {
46
- const e = t == null ? void 0 : t.id;
47
- (t == null ? void 0 : t.isError) === !0 && s(e) && u && console.debug(`[guido:cortex] message-level error id=${e}`, t);
48
- const o = t == null ? void 0 : t.segments;
49
- Array.isArray(o) && o.forEach((n) => {
50
- if (n)
51
- switch (A(e, n), n.type) {
52
- case "blueprint":
53
- b(n);
54
- break;
55
- case "error":
56
- s(e);
57
- break;
58
- }
59
- });
67
+ const r = ot(e, t.version), n = t.applyRequestedAt ?? 0, l = S.get(r);
68
+ if (l === void 0 || n > l) {
69
+ const i = l === void 0;
70
+ if (S.set(r, n), u.delete(r), i && G().has(r)) {
71
+ h.set(e, o);
72
+ return;
73
+ }
74
+ w(r, e, t, "immediate");
75
+ return;
76
+ }
77
+ const c = h.get(e);
78
+ if (c !== o) {
79
+ if (c === void 0) {
80
+ if (B(r)) {
81
+ E.set(r, t);
82
+ return;
83
+ }
84
+ const i = u.get(r);
85
+ if ((i == null ? void 0 : i.html) === o && i.count >= rt)
86
+ return;
87
+ w(r, e, t, "immediate");
88
+ return;
89
+ }
90
+ w(r, e, t, "debounced");
91
+ }
92
+ }, g = (t) => t === void 0 || _.has(t) ? !1 : (_.add(t), C({
93
+ type: z.Error,
94
+ message: H("newsletter.ai-template-failed")
95
+ }), !0), Y = (t) => {
96
+ Array.isArray(t) && t.forEach((e) => {
97
+ const o = e == null ? void 0 : e.id;
98
+ (e == null ? void 0 : e.isError) === !0 && g(o) && M && console.debug(`[guido:cortex] message-level error id=${o}`, e);
99
+ const r = e == null ? void 0 : e.segments;
100
+ Array.isArray(r) && r.forEach((n) => {
101
+ if (n)
102
+ switch (O(o, n), n.type) {
103
+ case "blueprint":
104
+ U(n);
105
+ break;
106
+ case "error":
107
+ g(o);
108
+ break;
109
+ }
60
110
  });
61
- },
62
- { deep: !0, immediate: !0 }
63
- );
64
- D(() => {
65
- m(), i.clear(), a.clear(), _();
111
+ });
112
+ }, P = () => {
113
+ T !== null && (clearInterval(T), T = null);
114
+ }, $ = () => {
115
+ var t;
116
+ return (t = A._s) == null ? void 0 : t.get(tt);
117
+ }, L = (t) => {
118
+ f = t, b = Z(() => t.messages, Y, { deep: !0, immediate: !0 });
119
+ }, R = $();
120
+ R ? L(R) : T = setInterval(() => {
121
+ const t = $();
122
+ t && (P(), L(t));
123
+ }, nt), V(() => {
124
+ P(), b == null || b(), f = void 0, h.clear(), S.clear(), u.clear(), d.clear(), E.clear(), _.clear(), v === y && (v = null, p.$patch((t) => {
125
+ t.bridgeActive = !1, t.applyAcks = {};
126
+ }), N());
66
127
  });
67
128
  };
68
129
  export {
69
- H as useCortexBlueprintBridge
130
+ ft as useCortexBlueprintBridge
70
131
  };
@@ -1,77 +1,67 @@
1
- import p from "../static/assets/icons/line-change.svg.js";
2
- import s from "../static/assets/icons/line-delete.svg.js";
3
- import a from "../static/assets/icons/line-plus.svg.js";
4
- import f from "../static/styles/base.css.js";
5
- import C from "../static/styles/components/alert-message.css.js";
6
- import c from "../static/styles/components/amp-block.css.js";
7
- import l from "../static/styles/components/base-input.css.js";
8
- import d from "../static/styles/components/button-group.css.js";
9
- import u from "../static/styles/components/button.css.js";
10
- import h from "../static/styles/components/combobox.css.js";
11
- import g from "../static/styles/components/counter.css.js";
12
- import w from "../static/styles/components/dropdown-menu.css.js";
13
- import y from "../static/styles/components/loader.css.js";
14
- import I from "../static/styles/components/narrow-panel.css.js";
15
- import A from "../static/styles/components/popup.css.js";
16
- import b from "../static/styles/components/recommendation-strategy.css.js";
17
- import B from "../static/styles/components/skeleton.css.js";
18
- import D from "../static/styles/components/switcher.css.js";
19
- import $ from "../static/styles/components/tabs.css.js";
20
- import P from "../static/styles/components/tools.css.js";
21
- import R from "../static/styles/components/version-history.css.js";
22
- import T from "../static/styles/components/wide-panel.css.js";
1
+ import S from "../static/assets/icons/line-change.svg.js";
2
+ import i from "../static/assets/icons/line-delete.svg.js";
3
+ import n from "../static/assets/icons/line-plus.svg.js";
4
+ import p from "../static/styles/base.css.js";
5
+ import s from "../static/styles/components/alert-message.css.js";
6
+ import C from "../static/styles/components/amp-block.css.js";
7
+ import a from "../static/styles/components/base-input.css.js";
8
+ import f from "../static/styles/components/button-group.css.js";
9
+ import c from "../static/styles/components/button.css.js";
10
+ import u from "../static/styles/components/combobox.css.js";
11
+ import l from "../static/styles/components/counter.css.js";
12
+ import d from "../static/styles/components/dropdown-menu.css.js";
13
+ import h from "../static/styles/components/loader.css.js";
14
+ import g from "../static/styles/components/narrow-panel.css.js";
15
+ import I from "../static/styles/components/popup.css.js";
16
+ import w from "../static/styles/components/recommendation-strategy.css.js";
17
+ import y from "../static/styles/components/switcher.css.js";
18
+ import b from "../static/styles/components/tabs.css.js";
19
+ import B from "../static/styles/components/tools.css.js";
20
+ import $ from "../static/styles/components/version-history.css.js";
21
+ import P from "../static/styles/components/wide-panel.css.js";
23
22
  import x from "../static/styles/variables.css.js";
24
- function r(S, o) {
25
- return `--guido-icon-${S}: url("data:image/svg+xml,${encodeURIComponent(o.trim())}");`;
23
+ function r(t, o) {
24
+ return `--guido-icon-${t}: url("data:image/svg+xml,${encodeURIComponent(o.trim())}");`;
26
25
  }
27
- const M = `:host {
28
- ${r("line-change", p)}
29
- ${r("line-delete", s)}
30
- ${r("line-plus", a)}
31
- }`, O = [
26
+ const A = `:host {
27
+ ${r("line-change", S)}
28
+ ${r("line-delete", i)}
29
+ ${r("line-plus", n)}
30
+ }`, R = [
32
31
  x,
33
32
  // Must be on top
34
- M,
35
- f,
33
+ A,
34
+ p,
36
35
  // Must be on top
36
+ s,
37
37
  C,
38
+ a,
39
+ f,
38
40
  c,
41
+ u,
39
42
  l,
40
43
  d,
41
- u,
42
44
  h,
43
45
  g,
44
- w,
45
- y,
46
46
  I,
47
- A,
47
+ y,
48
+ b,
48
49
  B,
49
- D,
50
50
  $,
51
51
  P,
52
- R,
53
- T,
54
- b
52
+ w
55
53
  // Last: overrides button.css / wide-panel.css defaults
56
54
  ].join(`
57
55
 
58
- `), V = 3e4;
59
- let e = null;
60
- function W() {
61
- return e || (e = new CSSStyleSheet(), e.replaceSync(O)), e;
62
- }
63
- const So = () => ({ importCss: () => {
64
- const o = W(), i = Date.now() + V, m = () => {
65
- var n;
66
- const t = (n = document.querySelector("ui-editor")) == null ? void 0 : n.shadowRoot;
67
- if (t) {
68
- t.adoptedStyleSheets.includes(o) || (t.adoptedStyleSheets = [...t.adoptedStyleSheets, o]);
69
- return;
70
- }
71
- Date.now() < i && requestAnimationFrame(m);
72
- };
73
- m();
56
+ `), Y = () => ({ importCss: () => {
57
+ const o = new CSSStyleSheet();
58
+ o.replaceSync(R);
59
+ const e = document.querySelector("ui-editor");
60
+ if (!e)
61
+ return;
62
+ const m = e.shadowRoot;
63
+ m && (m.adoptedStyleSheets = [o]);
74
64
  } });
75
65
  export {
76
- So as useCustomInterfaceAppearance
66
+ Y as useCustomInterfaceAppearance
77
67
  };
@@ -1,59 +1,102 @@
1
- import { useActionsApi as C } from "./useActionsApi.js";
2
- import { useConfig as h } from "./useConfig.js";
3
- import { useToaster as D } from "./useToaster.js";
4
- import { useTranslations as E } from "./useTranslations.js";
5
- import { ToasterTypeOptions as f } from "../enums/toaster.js";
6
- import { useDynamicContentStore as A } from "../stores/dynamic-content.js";
7
- import { flattenDynamicContentList as w } from "../utils/genericUtil.js";
8
- import { extractUsedDynamicContent as S } from "../utils/registerUsedDynamicContent.js";
9
- import { ref as O } from "vue";
10
- const U = 250, o = O({}), s = {}, u = /* @__PURE__ */ new Map(), z = () => {
11
- const { updateHtmlAndCss: r } = C(), { showToaster: m } = D(), y = E(), { template: T } = h(), d = A(), g = (e, t) => {
12
- const a = y(e);
13
- return a === e ? t : a;
14
- }, v = (e) => {
15
- o.value[e] === void 0 && (o.value = { ...o.value, [e]: "pending" });
16
- }, l = (e, t, a) => {
17
- var c;
18
- o.value = { ...o.value, [e]: "applying" };
1
+ import { useActionsApi as Q } from "./useActionsApi.js";
2
+ import { useConfig as x } from "./useConfig.js";
3
+ import { useEditorLock as z } from "./useEditorLock.js";
4
+ import { useToaster as N } from "./useToaster.js";
5
+ import { useTranslations as q } from "./useTranslations.js";
6
+ import { ToasterTypeOptions as D } from "../enums/toaster.js";
7
+ import { useDynamicContentStore as R } from "../stores/dynamic-content.js";
8
+ import { useEditorStore as F } from "../stores/editor.js";
9
+ import { flattenDynamicContentList as G } from "../utils/genericUtil.js";
10
+ import { extractUsedDynamicContent as $ } from "../utils/registerUsedDynamicContent.js";
11
+ import { ref as j, watch as J } from "vue";
12
+ const K = 250, S = 12e4, c = { status: "superseded" }, h = { status: "failed", error: new Error("Blueprint has no html to apply") }, i = j({}), v = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), ie = () => {
13
+ const { updateHtmlAndCss: a } = Q(), { runExclusive: M } = z(), { showToaster: d } = N(), y = q(), { template: U } = x(), A = R(), E = F(), T = (e, t) => {
14
+ u.get(e) !== t && (u.set(e, t), d({
15
+ type: D.Error,
16
+ message: y("newsletter.ai-template-failed-apply")
17
+ }));
18
+ }, O = () => {
19
+ var e, t;
20
+ return E.isStripoInitialized && typeof ((t = (e = window.StripoEditorApi) == null ? void 0 : e.actionsApi) == null ? void 0 : t.updateHtmlAndCss) == "function";
21
+ }, P = (e) => {
22
+ i.value[e] === void 0 && (i.value = { ...i.value, [e]: "pending" });
23
+ }, m = (e, t) => {
24
+ i.value = { ...i.value, [e]: t };
25
+ }, _ = (e) => {
26
+ var t;
19
27
  try {
20
- r(t, a).catch((n) => {
21
- console.warn("Editor did not acknowledge the template apply.", n);
22
- }), o.value = { ...o.value, [e]: "applied" };
23
- try {
24
- const n = w((c = T.value) == null ? void 0 : c.dynamicContentList), i = S(t, n);
25
- i.length > 0 && d.registerDynamicContent(i);
26
- } catch {
27
- }
28
- u.get(e) !== t && (u.set(e, t), m({
29
- type: f.Success,
30
- message: g("newsletter.ai-template-applied", "Template applied to the editor")
31
- }));
28
+ const o = G((t = U.value) == null ? void 0 : t.dynamicContentList), s = $(e, o);
29
+ s.length > 0 && A.registerDynamicContent(s);
30
+ } catch {
31
+ }
32
+ }, H = (e, t) => {
33
+ u.delete(e), v.get(e) !== t && (v.set(e, t), d({
34
+ type: D.Success,
35
+ message: y("newsletter.ai-template-applied")
36
+ }));
37
+ }, g = async (e, t, o) => {
38
+ const s = (l.get(e) ?? 0) + 1;
39
+ l.set(e, s), m(e, "applying");
40
+ try {
41
+ await M(() => a(t, o));
32
42
  } catch (n) {
33
- o.value = { ...o.value, [e]: "failed" }, m({
34
- type: f.Error,
35
- message: n instanceof Error ? n.message : "Failed to apply template"
36
- });
43
+ return l.get(e) !== s ? c : (console.error("[guido:apply] editor did not acknowledge the template apply", n), m(e, "failed"), T(e, t), { status: "failed", error: n });
37
44
  }
38
- }, p = (e) => {
39
- const t = s[e];
40
- t && (clearTimeout(t), delete s[e]);
45
+ return l.get(e) !== s ? c : (m(e, "applied"), _(t), H(e, t), { status: "applied" });
46
+ }, k = (e) => {
47
+ const t = r.get(e);
48
+ t && (clearTimeout(t.timer), r.delete(e), t.settle(c));
49
+ }, w = (e) => {
50
+ const t = p.get(e);
51
+ t && (clearTimeout(t.timer), p.delete(e), t.settle(c));
52
+ }, B = (e, t, o) => new Promise((s) => {
53
+ k(e);
54
+ const n = setTimeout(() => {
55
+ r.delete(e), m(e, "failed"), T(e, t), s({
56
+ status: "failed",
57
+ error: new Error(`Editor did not become ready within ${S}ms`)
58
+ });
59
+ }, S);
60
+ r.set(e, { html: t, css: o, timer: n, settle: s }), m(e, "applying");
61
+ }), C = (e, t, o) => O() ? g(e, t, o) : B(e, t, o), L = async () => {
62
+ if (r.size === 0)
63
+ return;
64
+ const e = [...r.entries()];
65
+ r.clear(), e.forEach(([, n]) => clearTimeout(n.timer));
66
+ const t = e.pop();
67
+ if (e.forEach(([n, f]) => {
68
+ m(n, "pending"), f.settle(c);
69
+ }), !t)
70
+ return;
71
+ const [o, s] = t;
72
+ s.settle(await g(o, s.html, s.css));
41
73
  };
42
- return { applyStatus: o, markPending: v, applyTemplate: (e, t) => {
43
- t.html && (p(e), l(e, t.html, t.css ?? ""));
74
+ return J(() => E.isStripoInitialized, (e) => {
75
+ e && L();
76
+ }, { immediate: !0 }), { applyStatus: i, markPending: P, applyTemplate: (e, t) => {
77
+ const { html: o } = t;
78
+ return o ? (w(e), C(e, o, t.css ?? "")) : Promise.resolve(h);
44
79
  }, applyTemplateDebounced: (e, t) => {
45
- if (!t.html)
46
- return;
47
- p(e);
48
- const { html: a } = t, c = t.css ?? "";
49
- s[e] = setTimeout(() => {
50
- delete s[e], l(e, a, c);
51
- }, U);
80
+ const { html: o } = t;
81
+ if (!o)
82
+ return Promise.resolve(h);
83
+ const s = t.css ?? "";
84
+ return new Promise((n) => {
85
+ w(e);
86
+ const f = setTimeout(() => {
87
+ p.delete(e), C(e, o, s).then(n);
88
+ }, K);
89
+ p.set(e, { timer: f, settle: n });
90
+ });
52
91
  } };
53
- }, G = () => {
54
- Object.values(s).forEach(clearTimeout), Object.keys(s).forEach((r) => delete s[r]), o.value = {};
92
+ }, ce = () => {
93
+ p.forEach((a) => {
94
+ clearTimeout(a.timer), a.settle(c);
95
+ }), p.clear(), r.forEach((a) => {
96
+ clearTimeout(a.timer), a.settle(c);
97
+ }), r.clear(), l.clear(), u.clear(), i.value = {};
55
98
  };
56
99
  export {
57
- G as resetEmailTemplateApplier,
58
- z as useEmailTemplateApplier
100
+ ce as resetEmailTemplateApplier,
101
+ ie as useEmailTemplateApplier
59
102
  };