@useinsider/guido 3.18.0 → 3.18.1-beta.5cddb72

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.
@@ -1,21 +1,22 @@
1
- import { useConfig as m } from "./useConfig.js";
1
+ import { useConfig as E } from "./useConfig.js";
2
+ import { useEditorLock as p } from "./useEditorLock.js";
2
3
  import { useAutosaveStore as A, AUTOSAVE_STATUS as s } from "../stores/autosave.js";
3
- import { useEditorStore as E } from "../stores/editor.js";
4
- import { computed as f, watch as p, onUnmounted as y } from "vue";
5
- const I = 18e4, r = 6e4, T = (b) => {
6
- const { isFeatureEnabled: S } = m(), a = E(), t = A();
4
+ import { useEditorStore as f } from "../stores/editor.js";
5
+ import { computed as y, watch as I, onUnmounted as L } from "vue";
6
+ const w = 18e4, v = 6e4, R = (b) => {
7
+ const { isFeatureEnabled: S } = E(), o = f(), t = A(), { isEditorBusy: g } = p();
7
8
  let i = null, c = 0;
8
- const u = f(
9
+ const u = y(
9
10
  () => S("autosave") && t.isOn
10
- ), g = () => a.hasChanges && a.isInSaveableState, h = () => ({
11
- hasChanges: a.hasChanges,
12
- isInSaveableState: a.isInSaveableState
13
- }), l = async (e) => {
11
+ ), m = () => o.hasChanges && o.isInSaveableState, h = () => ({
12
+ hasChanges: o.hasChanges,
13
+ isInSaveableState: o.isInSaveableState
14
+ }), r = async (e) => {
14
15
  if (!u.value) {
15
16
  console.debug("guido:autosave:skipped", { trigger: e, reason: "not-active" });
16
17
  return;
17
18
  }
18
- if (!g()) {
19
+ if (!m()) {
19
20
  console.debug("guido:autosave:skipped", { trigger: e, reason: "gates-blocked", gates: h() });
20
21
  return;
21
22
  }
@@ -23,15 +24,19 @@ const I = 18e4, r = 6e4, T = (b) => {
23
24
  console.debug("guido:autosave:skipped", { trigger: e, reason: "already-saving" });
24
25
  return;
25
26
  }
27
+ if (g()) {
28
+ console.debug("guido:autosave:skipped", { trigger: e, reason: "editor-busy" });
29
+ return;
30
+ }
26
31
  console.debug("guido:autosave:save-start", { trigger: e }), t.status = s.SAVING;
27
32
  try {
28
33
  if (await b() === void 0) {
29
34
  console.debug("guido:autosave:blocked", { trigger: e, reason: "save-returned-undefined" }), t.status = s.ERROR;
30
35
  return;
31
36
  }
32
- a.hasChanges = !1, t.status = s.SAVED, t.lastSavedAt = /* @__PURE__ */ new Date(), console.debug("guido:autosave:save-complete", { trigger: e, at: t.lastSavedAt });
33
- } catch (o) {
34
- console.debug("guido:autosave:error", { trigger: e, error: o }), t.status = s.ERROR;
37
+ o.hasChanges = !1, t.status = s.SAVED, t.lastSavedAt = /* @__PURE__ */ new Date(), console.debug("guido:autosave:save-complete", { trigger: e, at: t.lastSavedAt });
38
+ } catch (a) {
39
+ console.debug("guido:autosave:error", { trigger: e, error: a }), t.status = s.ERROR;
35
40
  }
36
41
  }, n = () => {
37
42
  const { visibilityState: e } = document;
@@ -40,32 +45,32 @@ const I = 18e4, r = 6e4, T = (b) => {
40
45
  isActive: u.value
41
46
  }), e !== "hidden")
42
47
  return;
43
- const o = Date.now() - c;
44
- if (o < r) {
48
+ const a = Date.now() - c;
49
+ if (a < v) {
45
50
  console.debug("guido:autosave:visibility-debounced", {
46
- sinceLastMs: o,
47
- debounceMs: r
51
+ sinceLastMs: a,
52
+ debounceMs: v
48
53
  });
49
54
  return;
50
55
  }
51
- c = Date.now(), l("visibility");
56
+ c = Date.now(), r("visibility");
52
57
  }, d = () => {
53
58
  i && (clearInterval(i), i = null);
54
- }, v = () => {
59
+ }, l = () => {
55
60
  document.removeEventListener("visibilitychange", n), window.removeEventListener("pagehide", n);
56
61
  };
57
- p(
62
+ I(
58
63
  u,
59
64
  (e) => {
60
65
  console.debug("guido:autosave:active-changed", { active: e }), e ? (d(), i = setInterval(() => {
61
- console.debug("guido:autosave:interval-tick"), l("interval");
62
- }, I), document.addEventListener("visibilitychange", n), window.addEventListener("pagehide", n)) : (d(), v(), t.status = s.IDLE);
66
+ console.debug("guido:autosave:interval-tick"), r("interval");
67
+ }, w), document.addEventListener("visibilitychange", n), window.addEventListener("pagehide", n)) : (d(), l(), t.status = s.IDLE);
63
68
  },
64
69
  { immediate: !0 }
65
- ), y(() => {
66
- d(), v(), t.status = s.IDLE, t.lastSavedAt = null;
70
+ ), L(() => {
71
+ d(), l(), t.status = s.IDLE, t.lastSavedAt = null;
67
72
  });
68
73
  };
69
74
  export {
70
- T as useAutoSave
75
+ R as useAutoSave
71
76
  };
@@ -1,70 +1,129 @@
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 Y, resetEmailTemplateApplier as N } from "./useEmailTemplateApplier.js";
2
+ import { useToaster as X } from "./useToaster.js";
3
+ import { useTranslationWithFallback 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 W } from "vue";
8
+ const Z = "email_template", tt = "chat", et = "guido:debug:ai", rt = 2, nt = 500, ot = (A, p) => `${A}:${p ?? 1}`;
9
+ let S = 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(), _ = Symbol("cortexBlueprintBridge");
23
+ S = _, p.$patch((t) => {
24
+ t.bridgeActive = !0;
25
+ });
26
+ const { markPending: R, applyTemplate: q, applyTemplateDebounced: x } = Y(), { showToaster: C } = X(), H = j(), h = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map(), y = /* @__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), g = (t, e, o, r) => {
31
+ const n = p.applyAcks[t], l = Math.max(Date.now(), ((n == null ? void 0 : n.ackAt) ?? 0) + 1), a = { status: e, requestedAt: o, ackAt: l };
32
+ r !== void 0 && (a.error = K(r)), p.$patch((c) => {
33
+ c.applyAcks = { ...c.applyAcks, [t]: a };
34
+ });
35
+ }, D = (t) => (d.get(t) ?? 0) > 0, m = async (t, e, o, r) => {
36
+ var c, i, L;
37
+ const n = ((c = o.blueprintData) == null ? void 0 : c.html) ?? "", l = ((i = o.blueprintData) == null ? void 0 : i.css) ?? "", a = o.applyRequestedAt ?? 0;
38
+ d.set(t, (d.get(t) ?? 0) + 1);
39
+ try {
40
+ const s = r === "debounced" ? await x(e, { html: n, css: l }) : await q(e, { html: n, css: l });
41
+ if (s.status === "superseded")
42
+ return;
43
+ if (s.status === "applied") {
44
+ h.set(e, n), u.delete(t), g(t, "applied", a);
45
+ return;
46
+ }
47
+ const w = u.get(t);
48
+ u.set(t, { html: n, count: (w == null ? void 0 : w.html) === n ? w.count + 1 : 1 }), g(t, "failed", a, s.error);
49
+ } finally {
50
+ d.set(t, (d.get(t) ?? 1) - 1);
51
+ const s = E.get(t);
52
+ s && !D(t) && (E.delete(t), (((L = s.blueprintData) == null ? void 0 : L.html) ?? "") !== n && m(t, e, s, r));
53
+ }
54
+ }, U = (t) => {
55
+ var c;
56
+ if (t.blueprintType !== Z)
29
57
  return;
30
- const t = r.blueprintId, e = r.blueprintData;
31
- if (!t || !(e != null && e.html))
58
+ const { blueprintId: e } = t, o = (c = t.blueprintData) == null ? void 0 : c.html;
59
+ if (!e || !o)
32
60
  return;
33
- if (!r.applyRequested) {
34
- d(t);
61
+ if (!t.applyRequested) {
62
+ R(e);
35
63
  return;
36
64
  }
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
- });
65
+ const r = ot(e, t.version), n = t.applyRequestedAt ?? 0, l = v.get(r);
66
+ if (l === void 0 || n > l) {
67
+ const i = l === void 0;
68
+ if (v.set(r, n), u.delete(r), i && G().has(r)) {
69
+ h.set(e, o);
70
+ return;
71
+ }
72
+ m(r, e, t, "immediate");
73
+ return;
74
+ }
75
+ const a = h.get(e);
76
+ if (a !== o) {
77
+ if (a === void 0) {
78
+ if (D(r)) {
79
+ E.set(r, t);
80
+ return;
81
+ }
82
+ const i = u.get(r);
83
+ if ((i == null ? void 0 : i.html) === o && i.count >= rt)
84
+ return;
85
+ m(r, e, t, "immediate");
86
+ return;
87
+ }
88
+ m(r, e, t, "debounced");
89
+ }
90
+ }, B = (t) => t === void 0 || y.has(t) ? !1 : (y.add(t), C({
91
+ type: z.Error,
92
+ message: H("newsletter.ai-template-failed", "AI couldn't generate the template. Please try again.")
93
+ }), !0), k = (t) => {
94
+ Array.isArray(t) && t.forEach((e) => {
95
+ const o = e == null ? void 0 : e.id;
96
+ (e == null ? void 0 : e.isError) === !0 && B(o) && M && console.debug(`[guido:cortex] message-level error id=${o}`, e);
97
+ const r = e == null ? void 0 : e.segments;
98
+ Array.isArray(r) && r.forEach((n) => {
99
+ if (n)
100
+ switch (O(o, n), n.type) {
101
+ case "blueprint":
102
+ U(n);
103
+ break;
104
+ case "error":
105
+ B(o);
106
+ break;
107
+ }
60
108
  });
61
- },
62
- { deep: !0, immediate: !0 }
63
- );
64
- D(() => {
65
- m(), i.clear(), a.clear(), _();
109
+ });
110
+ }, P = () => {
111
+ T !== null && (clearInterval(T), T = null);
112
+ }, $ = () => {
113
+ var t;
114
+ return (t = A._s) == null ? void 0 : t.get(tt);
115
+ }, F = (t) => {
116
+ f = t, b = W(() => t.messages, k, { deep: !0, immediate: !0 });
117
+ }, I = $();
118
+ I ? F(I) : T = setInterval(() => {
119
+ const t = $();
120
+ t && (P(), F(t));
121
+ }, nt), V(() => {
122
+ P(), b == null || b(), f = void 0, h.clear(), v.clear(), u.clear(), d.clear(), E.clear(), y.clear(), S === _ && (S = null, p.$patch((t) => {
123
+ t.bridgeActive = !1, t.applyAcks = {};
124
+ }), N());
66
125
  });
67
126
  };
68
127
  export {
69
- H as useCortexBlueprintBridge
128
+ ft as useCortexBlueprintBridge
70
129
  };
@@ -0,0 +1,20 @@
1
+ let o = Promise.resolve(), n = 0, e = 0;
2
+ const s = () => n > 0, c = () => (e += 1, e), u = (t) => t > 0 && t === e, i = (t) => {
3
+ const r = o.then(async () => {
4
+ n += 1;
5
+ try {
6
+ return await t();
7
+ } finally {
8
+ n -= 1;
9
+ }
10
+ });
11
+ return o = r.catch(() => {
12
+ }), r;
13
+ }, a = () => ({ runExclusive: i, isEditorBusy: s, beginMount: c, isCurrentMount: u });
14
+ export {
15
+ c as beginMount,
16
+ u as isCurrentMount,
17
+ s as isEditorBusy,
18
+ i as runExclusive,
19
+ a as useEditorLock
20
+ };
@@ -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 F } from "./useToaster.js";
5
+ import { useTranslationWithFallback as N } from "./useTranslations.js";
6
+ import { ToasterTypeOptions as h } from "../enums/toaster.js";
7
+ import { useDynamicContentStore as q } from "../stores/dynamic-content.js";
8
+ import { useEditorStore as R } from "../stores/editor.js";
9
+ import { flattenDynamicContentList as G } from "../utils/genericUtil.js";
10
+ import { extractUsedDynamicContent as W } from "../utils/registerUsedDynamicContent.js";
11
+ import { ref as $, watch as j } from "vue";
12
+ const J = 250, D = 12e4, c = { status: "superseded" }, S = { status: "failed", error: new Error("Blueprint has no html to apply") }, i = $({}), 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 } = F(), y = N(), { template: U } = x(), A = q(), T = R(), E = (e, t) => {
14
+ u.get(e) !== t && (u.set(e, t), d({
15
+ type: h.Error,
16
+ message: y("newsletter.ai-template-failed-apply", "Failed to apply template")
17
+ }));
18
+ }, O = () => {
19
+ var e, t;
20
+ return T.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 = W(e, o);
29
+ s.length > 0 && A.registerDynamicContent(s);
30
+ } catch {
31
+ }
32
+ }, k = (e, t) => {
33
+ u.delete(e), v.get(e) !== t && (v.set(e, t), d({
34
+ type: h.Success,
35
+ message: y("newsletter.ai-template-applied", "Template applied to the editor")
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"), E(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), k(e, t), { status: "applied" });
46
+ }, H = (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
+ H(e);
54
+ const n = setTimeout(() => {
55
+ r.delete(e), m(e, "failed"), E(e, t), s({
56
+ status: "failed",
57
+ error: new Error(`Editor did not become ready within ${D}ms`)
58
+ });
59
+ }, D);
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(() => T.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(S);
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(S);
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
+ }, J);
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
  };
@@ -1,48 +1,54 @@
1
- import { useActionsApi as g } from "./useActionsApi.js";
2
- import { useConfigStore as I } from "../stores/config.js";
3
- import { useEditorStore as b } from "../stores/editor.js";
4
- import { useGuidoEmailEditorStore as E } from "../stores/guido-email-editor.js";
5
- import { watch as c, onUnmounted as T } from "vue";
6
- const w = 500, z = () => {
7
- const i = b(), a = E(), l = I(), { getTemplateData: m } = g();
8
- let e = null, n = !1;
9
- const r = () => {
10
- e && (clearTimeout(e), e = null);
11
- }, s = async () => {
12
- var t, o;
13
- if (!(n || !i.isStripoInitialized))
1
+ import { useActionsApi as b } from "./useActionsApi.js";
2
+ import { useEditorLock as v } from "./useEditorLock.js";
3
+ import { useConfigStore as T } from "../stores/config.js";
4
+ import { useEditorStore as w } from "../stores/editor.js";
5
+ import { useGuidoEmailEditorStore as y } from "../stores/guido-email-editor.js";
6
+ import { watch as a, onUnmounted as B } from "vue";
7
+ const C = 500, L = () => {
8
+ const i = w(), u = y(), l = T(), { getTemplateData: d } = b(), { runExclusive: m, isEditorBusy: p } = v();
9
+ let o = null, s = !1;
10
+ const n = () => {
11
+ o && (clearTimeout(o), o = null);
12
+ }, c = (t) => {
13
+ n(), o = setTimeout(() => {
14
+ o = null, t();
15
+ }, C);
16
+ }, e = async () => {
17
+ var t, r;
18
+ if (!(s || !i.isStripoInitialized)) {
19
+ if (p()) {
20
+ c(() => void e());
21
+ return;
22
+ }
14
23
  try {
15
- const { html: f, css: h } = await m(), S = ((o = (t = l.config) == null ? void 0 : t.identity) == null ? void 0 : o.templateId) ?? "";
16
- if (n)
24
+ const { html: E, css: g } = await m(d), I = ((r = (t = l.config) == null ? void 0 : t.identity) == null ? void 0 : r.templateId) ?? "";
25
+ if (s)
17
26
  return;
18
- a.$patch({
19
- html: f ?? "",
20
- css: h ?? "",
21
- templateId: S,
27
+ u.$patch({
28
+ html: E ?? "",
29
+ css: g ?? "",
30
+ templateId: I,
22
31
  lastUpdatedAt: Date.now()
23
32
  });
24
33
  } catch {
25
34
  }
26
- }, u = () => {
27
- r(), e = setTimeout(() => {
28
- e = null, s();
29
- }, w);
30
- }, d = c(
35
+ }
36
+ }, f = () => c(() => void e()), h = a(
31
37
  () => i.isStripoInitialized,
32
38
  (t) => {
33
- t && s();
39
+ t && e();
34
40
  },
35
41
  { immediate: !0 }
36
- ), p = c(
42
+ ), S = a(
37
43
  () => i.hasChanges,
38
- (t, o) => {
39
- i.isStripoInitialized && (t ? u() : o && (r(), s()));
44
+ (t, r) => {
45
+ i.isStripoInitialized && (t ? f() : r && (n(), e()));
40
46
  }
41
47
  );
42
- T(() => {
43
- n = !0, r(), d(), p();
48
+ B(() => {
49
+ s = !0, n(), h(), S();
44
50
  });
45
51
  };
46
52
  export {
47
- z as useGuidoStateBridge
53
+ L as useGuidoStateBridge
48
54
  };