@useinsider/guido 3.18.3-beta.ec88281 → 3.19.0-beta.5355c3f
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.
- package/README.md +20 -0
- package/dist/components/Guido.vue.js +3 -3
- package/dist/components/Guido.vue2.js +67 -61
- package/dist/composables/useActionsApi.js +24 -20
- package/dist/composables/useCortexBlueprintBridge.js +115 -54
- package/dist/composables/useEmailTemplateApplier.js +93 -50
- package/dist/composables/useGuidoStateBridge.js +29 -24
- package/dist/composables/useStripo.js +7 -7
- package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +4 -4
- package/dist/extensions/Blocks/Recommendation/recommendation.css.js +6 -3
- package/dist/guido.css +1 -1
- package/dist/library.js +15 -13
- package/dist/package.json.js +1 -1
- package/dist/public/editorState.js +4 -0
- package/dist/src/composables/useCortexBlueprintBridge.d.ts +4 -3
- package/dist/src/composables/useEmailTemplateApplier.d.ts +22 -2
- package/dist/src/composables/useGuidoStateBridge.d.ts +11 -7
- package/dist/src/library.d.ts +2 -0
- package/dist/src/public/editorState.d.ts +14 -0
- package/dist/src/public/trackingIds.d.ts +6 -2
- package/dist/src/stores/editor.d.ts +25 -0
- package/dist/src/stores/guido-email-editor.d.ts +49 -27
- package/dist/src/utils/liquidDynamicContent.d.ts +20 -0
- package/dist/stores/editor.js +4 -0
- package/dist/stores/guido-email-editor.js +3 -5
- package/dist/utils/genericUtil.js +64 -61
- package/dist/utils/liquidDynamicContent.js +15 -0
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -561,6 +561,26 @@ import {
|
|
|
561
561
|
import '@useinsider/guido/style';
|
|
562
562
|
```
|
|
563
563
|
|
|
564
|
+
### Subpath entries
|
|
565
|
+
|
|
566
|
+
Two surfaces also ship as their own entry points. Importing one pulls in only its
|
|
567
|
+
own dependencies, so a consumer that needs the store or the tracking-id helpers
|
|
568
|
+
never loads the editor:
|
|
569
|
+
|
|
570
|
+
```typescript
|
|
571
|
+
// Live editor state, published by the editor into the host's shared Pinia instance.
|
|
572
|
+
// Store id `guidoEmailEditor` is the cross-app contract — read it, do not redeclare it.
|
|
573
|
+
import { useGuidoEmailEditorStore } from '@useinsider/guido/editor-state';
|
|
574
|
+
import type { GuidoEmailEditorState } from '@useinsider/guido/editor-state';
|
|
575
|
+
|
|
576
|
+
// Persistent link ids for the click heatmap.
|
|
577
|
+
import { assignTrackingIds, TRACK_ID_ATTRIBUTE } from '@useinsider/guido/tracking-ids';
|
|
578
|
+
import type { TrackingIdResult } from '@useinsider/guido/tracking-ids';
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
Both are re-exported from the root barrel as well; the subpath is what keeps the
|
|
582
|
+
editor out of the consumer's module graph.
|
|
583
|
+
|
|
564
584
|
---
|
|
565
585
|
|
|
566
586
|
## Constants
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { defineComponent as ne, defineAsyncComponent as
|
|
2
|
-
import { useCortexBlueprintBridge as
|
|
3
|
-
import { useEditorLock as
|
|
1
|
+
import { defineComponent as ne, defineAsyncComponent as u, ref as P, computed as p, watch as x, onMounted as re, onUnmounted as se } from "vue";
|
|
2
|
+
import { useCortexBlueprintBridge as ie } from "../composables/useCortexBlueprintBridge.js";
|
|
3
|
+
import { useEditorLock as ae } from "../composables/useEditorLock.js";
|
|
4
4
|
import { provideGuidoActions as ce } from "../composables/useGuidoActions.js";
|
|
5
5
|
import { useGuidoStateBridge as de } from "../composables/useGuidoStateBridge.js";
|
|
6
6
|
import { usePartner as me } from "../composables/usePartner.js";
|
|
7
7
|
import { useStripo as le } from "../composables/useStripo.js";
|
|
8
8
|
import { useTimerClone as ue } from "../composables/useTimerClone.js";
|
|
9
|
-
import { migrate as
|
|
10
|
-
import { ModuleFolderDefaults as
|
|
9
|
+
import { migrate as W } from "../config/migrator/index.js";
|
|
10
|
+
import { ModuleFolderDefaults as G } from "../enums/defaults.js";
|
|
11
11
|
import { RIBBON_SELECTOR as pe } from "../enums/onboarding.js";
|
|
12
|
-
import { useRecommendationExtensionStore as
|
|
12
|
+
import { useRecommendationExtensionStore as z } from "../extensions/Blocks/Recommendation/store/recommendation.js";
|
|
13
13
|
import fe from "./organisms/AutoSaveController.vue.js";
|
|
14
14
|
import ye from "./organisms/base/Toaster.vue.js";
|
|
15
15
|
import ge from "./organisms/extensions/recommendation/FilterSelectionDrawer.vue.js";
|
|
16
16
|
import ve from "./organisms/header/HeaderWrapper.vue.js";
|
|
17
17
|
import Se from "./organisms/LoadingWrapper.vue.js";
|
|
18
|
-
import
|
|
19
|
-
import
|
|
18
|
+
import he from "./organisms/save-as-template/SaveAsTemplateDrawer.vue.js";
|
|
19
|
+
import be from "./organisms/unsubscribe/UnsubscribeWrapper.vue.js";
|
|
20
20
|
import { useStripoApi as Ee } from "../services/stripoApi.js";
|
|
21
21
|
import { useConfigStore as we } from "../stores/config.js";
|
|
22
22
|
import { useDynamicContentStore as Ce } from "../stores/dynamic-content.js";
|
|
23
|
-
import { useEditorStore as
|
|
23
|
+
import { useEditorStore as E } from "../stores/editor.js";
|
|
24
24
|
import { usePreviewStore as De } from "../stores/preview.js";
|
|
25
25
|
import { useTemplateStore as ke } from "../stores/template.js";
|
|
26
|
-
import { useUnsubscribeStore as
|
|
27
|
-
import { readTrackFloor as
|
|
26
|
+
import { useUnsubscribeStore as Fe } from "../stores/unsubscribe.js";
|
|
27
|
+
import { readTrackFloor as H } from "../utils/linkTrackingIds.js";
|
|
28
28
|
const et = /* @__PURE__ */ ne({
|
|
29
29
|
__name: "Guido",
|
|
30
30
|
props: {
|
|
@@ -32,41 +32,41 @@ const et = /* @__PURE__ */ ne({
|
|
|
32
32
|
ready: { type: Boolean, default: !0 }
|
|
33
33
|
},
|
|
34
34
|
emits: ["dynamic-content:open", "back", "save:start", "save:complete", "on-change", "ready", "onboarding:finished", "test-email:click"],
|
|
35
|
-
setup(
|
|
36
|
-
const
|
|
35
|
+
setup($, { expose: q, emit: r }) {
|
|
36
|
+
const i = $, K = u(
|
|
37
37
|
() => import("./organisms/email-preview/PreviewContainer.vue.js")
|
|
38
|
-
), V =
|
|
38
|
+
), V = u(
|
|
39
39
|
() => import("./organisms/onboarding/OnboardingWrapper.vue.js")
|
|
40
|
-
), j =
|
|
40
|
+
), j = u(
|
|
41
41
|
() => import("./organisms/extensions/recommendation/AssignStrategyDrawer.vue.js")
|
|
42
|
-
), J =
|
|
42
|
+
), J = u(
|
|
43
43
|
() => import("./organisms/extensions/recommendation/RemoveStrategyModal.vue.js")
|
|
44
|
-
),
|
|
45
|
-
|
|
46
|
-
const c =
|
|
44
|
+
), w = P(), f = P(), y = Ce(), C = Fe(), o = we();
|
|
45
|
+
i.ready && o.init(i.config);
|
|
46
|
+
const c = E(), Q = De(), m = p(() => c.hasChanges), { isTestPartner: X } = me(), D = () => {
|
|
47
47
|
var t;
|
|
48
|
-
return (t =
|
|
49
|
-
},
|
|
48
|
+
return (t = w.value) == null ? void 0 : t.handleSave(!0);
|
|
49
|
+
}, k = (t) => {
|
|
50
50
|
c.loadingStatus = t;
|
|
51
51
|
};
|
|
52
|
-
|
|
53
|
-
const
|
|
52
|
+
ie(), de();
|
|
53
|
+
const g = () => {
|
|
54
54
|
var t, e;
|
|
55
55
|
return {
|
|
56
56
|
emailId: o.templateId,
|
|
57
57
|
userId: o.userId,
|
|
58
58
|
username: o.username,
|
|
59
59
|
partnerName: o.partnerName,
|
|
60
|
-
savedModulesFolderName: ((t = o.editor) == null ? void 0 : t.savedModulesFolderName) ||
|
|
61
|
-
defaultModulesFolderName: ((e = o.editor) == null ? void 0 : e.defaultModulesFolderName) ||
|
|
60
|
+
savedModulesFolderName: ((t = o.editor) == null ? void 0 : t.savedModulesFolderName) || G.SAVED_MODULES,
|
|
61
|
+
defaultModulesFolderName: ((e = o.editor) == null ? void 0 : e.defaultModulesFolderName) || G.DEFAULT_MODULES
|
|
62
62
|
};
|
|
63
|
-
}, { initPlugin:
|
|
64
|
-
let
|
|
65
|
-
const { getDefaultTemplate:
|
|
63
|
+
}, { initPlugin: F, preloadRuntime: T } = le(), { runExclusive: I, beginMount: M, isCurrentMount: v } = ae();
|
|
64
|
+
let l = 0;
|
|
65
|
+
const { getDefaultTemplate: R } = Ee(), { cloneTimersOnSave: L, hasTimerBlocks: B } = ue(), Y = p(() => {
|
|
66
66
|
var t;
|
|
67
67
|
return !((t = o.ui) != null && t.showHeader);
|
|
68
|
-
}), Z =
|
|
69
|
-
() => !!
|
|
68
|
+
}), Z = p(() => o.isFeatureEnabled("reusableRecommendationStrategy")), ee = p(
|
|
69
|
+
() => !!z().recommendationConfigs.strategyId
|
|
70
70
|
);
|
|
71
71
|
ce({
|
|
72
72
|
onBack: () => {
|
|
@@ -76,70 +76,76 @@ const et = /* @__PURE__ */ ne({
|
|
|
76
76
|
console.debug("guido:save:start"), r("save:start");
|
|
77
77
|
},
|
|
78
78
|
onSaveComplete: (t) => {
|
|
79
|
-
const e = { ...t, metadata:
|
|
79
|
+
const e = { ...t, metadata: g() };
|
|
80
80
|
console.debug("guido:save:complete", e), r("save:complete", e);
|
|
81
81
|
},
|
|
82
82
|
onTestEmailClick: () => {
|
|
83
83
|
console.debug("guido:test-email:click"), r("test-email:click");
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
|
-
const
|
|
87
|
-
console.debug("dynamic-content:close", t),
|
|
88
|
-
},
|
|
86
|
+
const A = (t) => {
|
|
87
|
+
console.debug("dynamic-content:close", t), y.setSelectedDynamicContent(t), document.dispatchEvent(new CustomEvent("dynamic-content:close", { detail: t }));
|
|
88
|
+
}, U = () => {
|
|
89
89
|
console.debug("dynamic-content:close", "Without Data"), document.dispatchEvent(new CustomEvent("dynamic-content:close", { detail: { text: "", value: "" } }));
|
|
90
90
|
};
|
|
91
|
-
|
|
91
|
+
x(() => m.value, () => {
|
|
92
92
|
r("on-change", m.value);
|
|
93
93
|
});
|
|
94
|
-
const
|
|
94
|
+
const S = (t) => {
|
|
95
95
|
const e = t, { attribute: s, position: d } = e.detail;
|
|
96
96
|
console.debug("dynamic-content:open", e.detail), r("dynamic-content:open", s, d);
|
|
97
97
|
};
|
|
98
|
-
let
|
|
99
|
-
const
|
|
98
|
+
let a = null;
|
|
99
|
+
const h = () => {
|
|
100
100
|
var e;
|
|
101
101
|
const t = document.querySelector(pe);
|
|
102
|
-
(e =
|
|
102
|
+
(e = f.value) == null || e.style.setProperty("--ribbon-offset", `${(t == null ? void 0 : t.offsetHeight) ?? 0}px`);
|
|
103
103
|
}, b = async () => {
|
|
104
104
|
var t;
|
|
105
105
|
try {
|
|
106
|
-
o.initialized || o.init(
|
|
107
|
-
const e = o.template, s = (e == null ? void 0 : e.html) || "", d = (e == null ? void 0 : e.css) || "",
|
|
108
|
-
|
|
109
|
-
const
|
|
106
|
+
o.initialized || o.init(i.config), c.templateId = o.templateId;
|
|
107
|
+
const e = o.template, s = (e == null ? void 0 : e.html) || "", d = (e == null ? void 0 : e.css) || "", _ = (e == null ? void 0 : e.preselectedDynamicContent) || [];
|
|
108
|
+
C.selectedUnsubscribePages = (e == null ? void 0 : e.selectedUnsubscribePages) || [];
|
|
109
|
+
const N = ((t = e == null ? void 0 : e.migration) == null ? void 0 : t.recommendationConfigs) ?? {}, O = o.isFeatureEnabled("linkTrackingIds");
|
|
110
110
|
let n = {
|
|
111
|
-
html: s && await
|
|
111
|
+
html: s && await W(s, N),
|
|
112
112
|
css: d
|
|
113
113
|
};
|
|
114
|
-
n.html || (n = await
|
|
115
|
-
const te =
|
|
116
|
-
|
|
114
|
+
n.html || (n = await R(), n.html = await W(n.html, N));
|
|
115
|
+
const te = O ? H(n.html, (e == null ? void 0 : e.trackIdCounter) || 0) : 0;
|
|
116
|
+
B(n.html) && (n.html = await L(n.html)), O && (c.trackIdSessionFloor = Math.max(te, H(n.html)));
|
|
117
117
|
const oe = {
|
|
118
|
-
preselectedDynamicContentList:
|
|
118
|
+
preselectedDynamicContentList: _,
|
|
119
119
|
onReady: () => {
|
|
120
120
|
console.debug("guido:ready"), r("ready");
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
|
-
|
|
123
|
+
l = M(), await F(n, g(), oe), y.selectedDynamicContentList = _;
|
|
124
124
|
} catch (e) {
|
|
125
125
|
console.error("Failed to initialize Stripo editor:", e);
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
128
|
return re(async () => {
|
|
129
129
|
var e;
|
|
130
|
-
console.debug("Guido says happy coding 🎉"), console.debug("🚗 Ka-Chow"),
|
|
131
|
-
const t = (e =
|
|
132
|
-
if (t && (
|
|
130
|
+
console.debug("Guido says happy coding 🎉"), console.debug("🚗 Ka-Chow"), z().$reset(), E().$reset(), ke().$reset(), h();
|
|
131
|
+
const t = (e = f.value) == null ? void 0 : e.parentElement;
|
|
132
|
+
if (t && (a = new ResizeObserver(h), a.observe(t)), T(), i.ready)
|
|
133
133
|
await b();
|
|
134
134
|
else {
|
|
135
|
-
const s =
|
|
135
|
+
const s = x(() => i.ready, (d) => {
|
|
136
136
|
d && (s(), b());
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
document.addEventListener("dynamic-content:open",
|
|
139
|
+
document.addEventListener("dynamic-content:open", S);
|
|
140
140
|
}), se(() => {
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
if (a == null || a.disconnect(), document.removeEventListener("dynamic-content:open", S), v(l))
|
|
142
|
+
try {
|
|
143
|
+
E().isStripoInitialized = !1;
|
|
144
|
+
} catch (t) {
|
|
145
|
+
console.debug("Failed to close the editor readiness gate on unmount", t);
|
|
146
|
+
}
|
|
147
|
+
I(async () => {
|
|
148
|
+
if (v(l))
|
|
143
149
|
try {
|
|
144
150
|
window.UIEditor.removeEditor();
|
|
145
151
|
} catch {
|
|
@@ -148,13 +154,13 @@ const et = /* @__PURE__ */ ne({
|
|
|
148
154
|
}), o.reset();
|
|
149
155
|
}), q({
|
|
150
156
|
dynamicContent: {
|
|
151
|
-
insert:
|
|
152
|
-
close:
|
|
157
|
+
insert: A,
|
|
158
|
+
close: U
|
|
153
159
|
},
|
|
154
160
|
hasChanges: m,
|
|
155
|
-
saveSilent:
|
|
156
|
-
setLoading:
|
|
157
|
-
}), { __sfc: !0, PreviewContainer: K, OnboardingWrapper: V, AssignStrategyDrawer: j, RemoveStrategyModal: J, headerWrapperRef:
|
|
161
|
+
saveSilent: D,
|
|
162
|
+
setLoading: k
|
|
163
|
+
}), { __sfc: !0, PreviewContainer: K, OnboardingWrapper: V, AssignStrategyDrawer: j, RemoveStrategyModal: J, headerWrapperRef: w, wrapperRef: f, dynamicContentStore: y, unsubscribeStore: C, props: i, configStore: o, editorStore: c, previewStore: Q, hasChanges: m, isTestPartner: X, saveSilent: D, setLoading: k, emit: r, buildMetadata: g, initPlugin: F, preloadRuntime: T, runExclusive: I, beginMount: M, isCurrentMount: v, mountGeneration: l, getDefaultTemplate: R, cloneTimersOnSave: L, hasTimerBlocks: B, noHeader: Y, isRrsEnabled: Z, hasAssignedStrategy: ee, insertDynamicContent: A, closeDynamicContent: U, handleDynamicContentOpen: S, ribbonObserver: a, updateRibbonOffset: h, startEditor: b, AutoSaveController: fe, Toaster: ye, FilterSelectionDrawer: ge, HeaderWrapper: ve, LoadingWrapper: Se, SaveAsTemplateDrawer: he, UnsubscribeWrapper: be };
|
|
158
164
|
}
|
|
159
165
|
});
|
|
160
166
|
export {
|
|
@@ -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,
|
|
4
|
-
const
|
|
5
|
-
() =>
|
|
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
|
-
),
|
|
8
|
-
clearTimeout(
|
|
7
|
+
), d = (r) => (t) => {
|
|
8
|
+
clearTimeout(c), r(t);
|
|
9
9
|
};
|
|
10
|
-
|
|
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 = {}) =>
|
|
16
|
+
const { handleError: n } = y(), l = (t = {}) => p(
|
|
13
17
|
"compileEmail",
|
|
14
|
-
|
|
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 },
|
|
36
|
-
callback: (
|
|
37
|
-
|
|
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(
|
|
50
|
+
window.StripoEditorApi.actionsApi.compileEmail(u);
|
|
47
51
|
}
|
|
48
52
|
);
|
|
49
53
|
return {
|
|
50
54
|
getCompiledEmail: l,
|
|
51
|
-
getTemplateData: () =>
|
|
55
|
+
getTemplateData: () => p(
|
|
52
56
|
"getTemplateData",
|
|
53
|
-
|
|
57
|
+
T,
|
|
54
58
|
(t) => {
|
|
55
|
-
const e = ({ html: a, css: i, width: o, height: E, utmParams:
|
|
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:
|
|
61
|
-
syncModulesIds:
|
|
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
|
|
112
|
+
return p("updateHtmlAndCss", D, (i) => {
|
|
109
113
|
a.updateHtmlAndCss(t, e, () => i());
|
|
110
114
|
});
|
|
111
115
|
},
|
|
112
|
-
editorSave: () =>
|
|
116
|
+
editorSave: () => p(
|
|
113
117
|
"save",
|
|
114
|
-
|
|
118
|
+
T,
|
|
115
119
|
(t) => {
|
|
116
120
|
window.StripoEditorApi.actionsApi.save((e) => {
|
|
117
121
|
if (e) {
|
|
@@ -1,70 +1,131 @@
|
|
|
1
|
-
import { useEmailTemplateApplier as
|
|
2
|
-
import { useToaster as
|
|
3
|
-
import { useTranslations as
|
|
4
|
-
import { ToasterTypeOptions as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
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(
|
|
14
|
+
return window.localStorage.getItem(et) === "1";
|
|
12
15
|
} catch {
|
|
13
16
|
return !1;
|
|
14
17
|
}
|
|
15
|
-
},
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
18
|
+
}, ft = () => {
|
|
19
|
+
const A = Q();
|
|
20
|
+
if (!A)
|
|
18
21
|
return;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
if (
|
|
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
|
|
31
|
-
if (!
|
|
60
|
+
const { blueprintId: e } = t, o = (a = t.blueprintData) == null ? void 0 : a.html;
|
|
61
|
+
if (!e || !o)
|
|
32
62
|
return;
|
|
33
|
-
if (!
|
|
34
|
-
|
|
63
|
+
if (!t.applyRequested) {
|
|
64
|
+
x(e);
|
|
35
65
|
return;
|
|
36
66
|
}
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
130
|
+
ft as useCortexBlueprintBridge
|
|
70
131
|
};
|