@useinsider/guido 3.9.1 → 3.10.0-beta.f7505c1

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,55 +1,59 @@
1
- import { useEmailTemplateApplier as m, resetEmailTemplateApplier as w } from "./useEmailTemplateApplier.js";
2
- import { useToaster as _ } from "./useToaster.js";
3
- import { useTranslations as I } from "./useTranslations.js";
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
4
  import { ToasterTypeOptions as S } from "../enums/toaster.js";
5
5
  import { getActivePinia as v } from "pinia";
6
6
  import { watch as B, onUnmounted as D } from "vue";
7
- const P = "email_template", x = "chat", L = "guido:debug:ai", M = () => {
7
+ const x = "email_template", L = "chat", M = "guido:debug:ai", R = () => {
8
8
  if (typeof window > "u")
9
9
  return !1;
10
10
  try {
11
- return window.localStorage.getItem(L) === "1";
11
+ return window.localStorage.getItem(M) === "1";
12
12
  } catch {
13
13
  return !1;
14
14
  }
15
- }, O = () => {
16
- const a = v();
17
- if (!a)
15
+ }, H = () => {
16
+ const c = v();
17
+ if (!c)
18
18
  return;
19
- const l = a._s, p = l == null ? void 0 : l.get(x);
19
+ const l = c._s, p = l == null ? void 0 : l.get(L);
20
20
  if (!p)
21
21
  return;
22
- const { applyTemplate: d, applyTemplateDebounced: f } = m(), { showToaster: T } = _(), h = I(), A = (e, t) => {
23
- const r = h(e);
24
- return r === e ? t : r;
25
- }, i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set(), u = M(), E = (e, t) => {
26
- u && console.debug(`[guido:cortex] msg=${e ?? "?"} type=${(t == null ? void 0 : t.type) ?? "?"}`, t);
27
- }, y = (e) => {
28
- if (e.blueprintType !== P)
22
+ const { markPending: d, applyTemplate: f, applyTemplateDebounced: T } = w(), { showToaster: h } = I(), y = P(), A = (r, t) => {
23
+ const e = y(r);
24
+ return e === r ? t : e;
25
+ }, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), u = R(), E = (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)
29
29
  return;
30
- const t = e.blueprintId, r = e.blueprintData;
31
- if (!t || !(r != null && r.html))
30
+ const t = r.blueprintId, e = r.blueprintData;
31
+ if (!t || !(e != null && e.html))
32
32
  return;
33
+ if (!r.applyRequested) {
34
+ d(t);
35
+ return;
36
+ }
33
37
  const o = i.get(t);
34
- o === void 0 ? (i.set(t, r.html), d(t, r)) : o !== r.html && (i.set(t, r.html), f(t, r));
35
- }, s = (e) => e === void 0 || c.has(e) ? !1 : (c.add(e), 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), h({
36
40
  type: S.Alert,
37
41
  message: A("newsletter.ai-template-failed", "AI couldn't generate the template. Please try again.")
38
- }), !0), b = B(
42
+ }), !0), m = B(
39
43
  () => p.messages,
40
- (e) => {
41
- Array.isArray(e) && e.forEach((t) => {
42
- const r = t == null ? void 0 : t.id;
43
- (t == null ? void 0 : t.isError) === !0 && s(r) && u && console.debug(`[guido:cortex] message-level error id=${r}`, t);
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);
44
48
  const o = t == null ? void 0 : t.segments;
45
49
  Array.isArray(o) && o.forEach((n) => {
46
50
  if (n)
47
- switch (E(r, n), n.type) {
51
+ switch (E(e, n), n.type) {
48
52
  case "blueprint":
49
- y(n);
53
+ b(n);
50
54
  break;
51
55
  case "error":
52
- s(r);
56
+ s(e);
53
57
  break;
54
58
  }
55
59
  });
@@ -58,9 +62,9 @@ const P = "email_template", x = "chat", L = "guido:debug:ai", M = () => {
58
62
  { deep: !0, immediate: !0 }
59
63
  );
60
64
  D(() => {
61
- b(), i.clear(), c.clear(), w();
65
+ m(), i.clear(), a.clear(), _();
62
66
  });
63
67
  };
64
68
  export {
65
- O as useCortexBlueprintBridge
69
+ H as useCortexBlueprintBridge
66
70
  };
@@ -1,10 +1,12 @@
1
- import { useActionsApi as u } from "./useActionsApi.js";
2
- import { useToaster as T } from "./useToaster.js";
3
- import { useTranslations as f } from "./useTranslations.js";
1
+ import { useActionsApi as T } from "./useActionsApi.js";
2
+ import { useToaster as f } from "./useToaster.js";
3
+ import { useTranslations as y } from "./useTranslations.js";
4
4
  import { ToasterTypeOptions as n } from "../enums/toaster.js";
5
- import { ref as y } from "vue";
6
- const h = 250, s = y({}), o = {}, j = () => {
7
- const { updateHtmlAndCss: l } = u(), { showToaster: r } = T(), i = f(), c = (e, t, p) => {
5
+ import { ref as v } from "vue";
6
+ const h = 250, s = v({}), o = {}, j = () => {
7
+ const { updateHtmlAndCss: l } = T(), { showToaster: r } = f(), i = y(), u = (e) => {
8
+ s.value[e] === void 0 && (s.value = { ...s.value, [e]: "pending" });
9
+ }, c = (e, t, p) => {
8
10
  s.value = { ...s.value, [e]: "applying" };
9
11
  try {
10
12
  l(t, p), s.value = { ...s.value, [e]: "applied" }, r({
@@ -21,7 +23,7 @@ const h = 250, s = y({}), o = {}, j = () => {
21
23
  const t = o[e];
22
24
  t && (clearTimeout(t), delete o[e]);
23
25
  };
24
- return { applyStatus: s, applyTemplate: (e, t) => {
26
+ return { applyStatus: s, markPending: u, applyTemplate: (e, t) => {
25
27
  t.html && (m(e), c(e, t.html, t.css ?? ""));
26
28
  }, applyTemplateDebounced: (e, t) => {
27
29
  if (!t.html)
@@ -32,10 +34,10 @@ const h = 250, s = y({}), o = {}, j = () => {
32
34
  delete o[e], c(e, p, a);
33
35
  }, h);
34
36
  } };
35
- }, w = () => {
37
+ }, k = () => {
36
38
  Object.values(o).forEach(clearTimeout), Object.keys(o).forEach((l) => delete o[l]), s.value = {};
37
39
  };
38
40
  export {
39
- w as resetEmailTemplateApplier,
41
+ k as resetEmailTemplateApplier,
40
42
  j as useEmailTemplateApplier
41
43
  };
@@ -9,8 +9,11 @@
9
9
  * The bridge handles two segment shapes:
10
10
  *
11
11
  * - `blueprint` segments with `blueprintType === 'email_template'` are
12
- * applied to the Stripo editor (immediate on first sighting, debounced on
13
- * update, identical-html no-ops).
12
+ * applied to the Stripo editor, but ONLY after the user clicks
13
+ * "Apply to editor" in cortex-fe (which sets `applyRequested` on the
14
+ * segment). Before that the template is marked `pending` and nothing is
15
+ * written to Stripo. Once applied, refines flow through debounced;
16
+ * identical-html no-ops.
14
17
  * - `error` segments (and message-level `isError` / `isCancelled`) trigger
15
18
  * a localized toaster.
16
19
  *
@@ -2,12 +2,17 @@ type ApplyStatus = 'pending' | 'applying' | 'applied' | 'failed';
2
2
  /**
3
3
  * Applies email_template blueprints from the chat agent to the Stripo editor.
4
4
  *
5
- * - blueprint_create + manual Apply click: immediate.
6
- * - blueprint_update: debounced 250 ms trailing so rapid mid-stream updates
7
- * don't thrash updateHtmlAndCss.
5
+ * The first apply is gated behind the user's "Apply to editor" click — until
6
+ * then a blueprint is only marked `pending` (see `markPending`) and nothing is
7
+ * written to the editor.
8
+ *
9
+ * - manual Apply click (first apply): immediate.
10
+ * - blueprint_update after the user has applied once: debounced 250 ms trailing
11
+ * so rapid mid-stream updates don't thrash updateHtmlAndCss.
8
12
  */
9
13
  export declare const useEmailTemplateApplier: () => {
10
14
  applyStatus: import("vue").Ref<Record<string, ApplyStatus>>;
15
+ markPending: (blueprintId: string) => void;
11
16
  applyTemplate: (blueprintId: string, data: {
12
17
  html?: string;
13
18
  css?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.9.1",
3
+ "version": "3.10.0-beta.f7505c1",
4
4
  "description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
5
5
  "main": "./dist/guido.umd.cjs",
6
6
  "module": "./dist/library.js",