@aswin.dev/editor 0.6.3 → 0.7.0
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/dist/AccessibilityPanel-CvQGLdu6.js +108 -0
- package/dist/AiChatSidebar-B3SJIKG_.js +229 -0
- package/dist/AiFeatureMenu-BLLKoOos.js +63 -0
- package/dist/BlockA11yBadge-CXDLqkcJ.js +34 -0
- package/dist/CloudEditor-BCz1ZTYC.js +1172 -0
- package/dist/CollaboratorBar-DuPYW5iF.js +95 -0
- package/dist/CommentsSidebar-B1pvJdqF.js +441 -0
- package/dist/CountdownBlock-BNSj1jvJ.js +92 -0
- package/dist/CountdownToolbar-ClJr2GzL.js +210 -0
- package/dist/DesignReferenceSidebar-B8V_F2yF.js +276 -0
- package/dist/LoadingTrack-B0CWFHXQ.js +10 -0
- package/dist/ModuleBrowserModal-DrUFMTDx.js +206 -0
- package/dist/ModulePreviewCanvas-CHdOwV_4.js +106 -0
- package/dist/NumberWithSuffix-DkXUez9t.js +422 -0
- package/dist/ParagraphEditor-D75wl3BX.js +695 -0
- package/dist/RichTextEditorContent-DYkIauIk.js +137 -0
- package/dist/SaveModuleDialog-FZ9lxY7_.js +123 -0
- package/dist/SnapshotHistory-BR3eV120.js +127 -0
- package/dist/TemplateScoringPanel-4GTNHej5.js +256 -0
- package/dist/TestEmailModal--ue5w9fT.js +94 -0
- package/dist/TitleEditor-fStSADI-.js +172 -0
- package/dist/TplModal-BwSfxIHf.js +44 -0
- package/dist/_plugin-vue_export-helper-B0hnzhyu.js +8 -0
- package/dist/accessibility-e8JYu_zd.js +27 -0
- package/dist/blockTypeIcons-BcTrDjmH.js +126 -0
- package/dist/bundle-stats.json +10 -0
- package/dist/cdn/chunks/AccessibilityPanel-B6DOjojm.js +97 -0
- package/dist/cdn/chunks/AccessibilityPanel-B6DOjojm.js.map +1 -0
- package/dist/cdn/chunks/AiFeatureMenu-qEdB2fZJ.js +59 -0
- package/dist/cdn/chunks/AiFeatureMenu-qEdB2fZJ.js.map +1 -0
- package/dist/cdn/chunks/BlockA11yBadge-DcEZftf6.js +33 -0
- package/dist/cdn/chunks/BlockA11yBadge-DcEZftf6.js.map +1 -0
- package/dist/cdn/chunks/CloudEditor-D2GsEC_n.js +1143 -0
- package/dist/cdn/chunks/CloudEditor-D2GsEC_n.js.map +1 -0
- package/dist/cdn/chunks/CollaboratorBar--nO7TX6b.js +51 -0
- package/dist/cdn/chunks/CollaboratorBar--nO7TX6b.js.map +1 -0
- package/dist/cdn/chunks/CountdownBlock-5YdT1uUu.js +93 -0
- package/dist/cdn/chunks/CountdownBlock-5YdT1uUu.js.map +1 -0
- package/dist/cdn/chunks/CountdownToolbar-DXPXrbAA.js +212 -0
- package/dist/cdn/chunks/CountdownToolbar-DXPXrbAA.js.map +1 -0
- package/dist/cdn/chunks/ModuleBrowserModal-DxoPp81s.js +195 -0
- package/dist/cdn/chunks/ModuleBrowserModal-DxoPp81s.js.map +1 -0
- package/dist/cdn/chunks/ModulePreviewCanvas-CoLdb4ar.js +107 -0
- package/dist/cdn/chunks/ModulePreviewCanvas-CoLdb4ar.js.map +1 -0
- package/dist/cdn/chunks/NumberWithSuffix-CE3NrZhH.js +423 -0
- package/dist/cdn/chunks/NumberWithSuffix-CE3NrZhH.js.map +1 -0
- package/dist/cdn/chunks/ParagraphEditor-B6Ygu-Mq.js +544 -0
- package/dist/cdn/chunks/ParagraphEditor-B6Ygu-Mq.js.map +1 -0
- package/dist/cdn/chunks/RichTextEditorContent-DL_y2SrR.js +106 -0
- package/dist/cdn/chunks/RichTextEditorContent-DL_y2SrR.js.map +1 -0
- package/dist/cdn/chunks/SaveModuleDialog-B0TnO_o9.js +119 -0
- package/dist/cdn/chunks/SaveModuleDialog-B0TnO_o9.js.map +1 -0
- package/dist/cdn/chunks/TitleEditor-BHpfxvwy.js +171 -0
- package/dist/cdn/chunks/TitleEditor-BHpfxvwy.js.map +1 -0
- package/dist/cdn/chunks/blockTypeIcons-BzzY9_kA.js +22 -0
- package/dist/cdn/chunks/blockTypeIcons-BzzY9_kA.js.map +1 -0
- package/dist/cdn/chunks/de-Ce-LbJ2J.js +89 -0
- package/dist/cdn/chunks/de-Ce-LbJ2J.js.map +1 -0
- package/dist/cdn/chunks/de-D8CnZxV9.js +523 -0
- package/dist/cdn/chunks/de-D8CnZxV9.js.map +1 -0
- package/dist/cdn/chunks/de-RQrZR56a.js +209 -0
- package/dist/cdn/chunks/de-RQrZR56a.js.map +1 -0
- package/dist/cdn/chunks/draggable-Bcb86AsV.js +11572 -0
- package/dist/cdn/chunks/draggable-Bcb86AsV.js.map +1 -0
- package/dist/cdn/chunks/emojiData-EMFlj6FJ.js +19 -0
- package/dist/cdn/chunks/emojiData-EMFlj6FJ.js.map +1 -0
- package/dist/cdn/chunks/en-8FHaQv4V.js +523 -0
- package/dist/cdn/chunks/en-8FHaQv4V.js.map +1 -0
- package/dist/cdn/chunks/en-Bl1ecfRF.js +209 -0
- package/dist/cdn/chunks/en-Bl1ecfRF.js.map +1 -0
- package/dist/cdn/chunks/en-DiCWK5fG.js +89 -0
- package/dist/cdn/chunks/en-DiCWK5fG.js.map +1 -0
- package/dist/cdn/chunks/extensions-DIxF31tA.js +598 -0
- package/dist/cdn/chunks/extensions-DIxF31tA.js.map +1 -0
- package/dist/cdn/chunks/features-DEMb13KS.js +6814 -0
- package/dist/cdn/chunks/features-DEMb13KS.js.map +1 -0
- package/dist/cdn/chunks/icons-CsLTcirh.js +700 -0
- package/dist/cdn/chunks/icons-CsLTcirh.js.map +1 -0
- package/dist/cdn/chunks/liquid.browser-lQbkge2E.js +3279 -0
- package/dist/cdn/chunks/liquid.browser-lQbkge2E.js.map +1 -0
- package/dist/cdn/chunks/media-library-CVaNvhpM.js +6014 -0
- package/dist/cdn/chunks/media-library-CVaNvhpM.js.map +1 -0
- package/dist/cdn/chunks/pusher-CDbNlZBE.js +2508 -0
- package/dist/cdn/chunks/pusher-CDbNlZBE.js.map +1 -0
- package/dist/cdn/chunks/quality-BaBfc54_.js +1456 -0
- package/dist/cdn/chunks/quality-BaBfc54_.js.map +1 -0
- package/dist/cdn/chunks/readableTextColor-DhoK4XiZ.js +32 -0
- package/dist/cdn/chunks/readableTextColor-DhoK4XiZ.js.map +1 -0
- package/dist/cdn/chunks/renderer-CUxvx7ro.js +548 -0
- package/dist/cdn/chunks/renderer-CUxvx7ro.js.map +1 -0
- package/dist/cdn/chunks/rolldown-runtime-BNuo_Jkg.js +20 -0
- package/dist/cdn/chunks/src-CRaqN-p8.js +497 -0
- package/dist/cdn/chunks/src-CRaqN-p8.js.map +1 -0
- package/dist/cdn/chunks/styleConstants-DP1VOca8.js +57 -0
- package/dist/cdn/chunks/styleConstants-DP1VOca8.js.map +1 -0
- package/dist/cdn/chunks/styles-BHJULjNR.js +2947 -0
- package/dist/cdn/chunks/styles-BHJULjNR.js.map +1 -0
- package/dist/cdn/chunks/tiptap-ZhwKyFp7.js +14654 -0
- package/dist/cdn/chunks/tiptap-ZhwKyFp7.js.map +1 -0
- package/dist/cdn/editor.css +2 -0
- package/dist/cdn/editor.js +250 -0
- package/dist/cdn/editor.js.map +1 -0
- package/dist/check-Da05j8yl.js +7 -0
- package/dist/chevron-down-R2uY34iD.js +7 -0
- package/dist/circle-alert-DZuGWPX-.js +25 -0
- package/dist/clock-CRp2sIub.js +12 -0
- package/dist/cloud-DEk_b4CR.js +1733 -0
- package/dist/createLucideIcon-C3pa2siy.js +43 -0
- package/dist/de-Brqvgr43.js +521 -0
- package/dist/de-DCaaCE5s.js +207 -0
- package/dist/dist-B1IR0bpH.js +326 -0
- package/dist/dist-BFawx6IS.js +519 -0
- package/dist/dist-BaQIYPsn.js +35 -0
- package/dist/dist-Cp0zXPAD.js +189 -0
- package/dist/dist-D6uC2xhi.js +5 -0
- package/dist/dist-D90y8dvT.js +2082 -0
- package/dist/dist-DDJIWTRY.js +776 -0
- package/dist/dist-DJmnUmW9.js +362 -0
- package/dist/dist-DjviJBCi.js +74 -0
- package/dist/dist-KoBJjK1G.js +61 -0
- package/dist/dist-aRzjfSRN.js +35 -0
- package/dist/dist-iLBdeBDR.js +10658 -0
- package/dist/dist-us-RpCWN.js +47 -0
- package/dist/dist-wzMIGj-D.js +5 -0
- package/dist/emojiData-PQyVa4bU.js +17 -0
- package/dist/en-DXCyK4-X.js +207 -0
- package/dist/en-WDVp87TE.js +521 -0
- package/dist/extensions-CUcl9Ok4.js +799 -0
- package/dist/formatRelativeTime-BOEf47hq.js +12 -0
- package/dist/image-up-MBZKKg9p.js +23 -0
- package/dist/index.d.ts +275 -0
- package/dist/info-CJEC7piy.js +19 -0
- package/dist/keys-ciNfSSGj.js +10 -0
- package/dist/liquid.browser-CdMv1BTn.js +3277 -0
- package/dist/loader-circle-DsY5Yg33.js +7 -0
- package/dist/message-circle-yElBbR2C.js +7 -0
- package/dist/readableTextColor-CY3SiRnt.js +30 -0
- package/dist/refresh-cw-CE_AGtn8.js +29 -0
- package/dist/rolldown-runtime-BZGGJVDF.js +20 -0
- package/dist/scan-line-D0vcUekt.js +25 -0
- package/dist/send-DH4oDQqC.js +10 -0
- package/dist/shield-check-CfJgs2Hd.js +10 -0
- package/dist/sparkles-CvRXGqFs.js +23 -0
- package/dist/style.css +2 -0
- package/dist/styleConstants-fWzlIIwN.js +55 -0
- package/dist/styles-DEXEkBvg.js +3176 -0
- package/dist/templatical-editor.js +249 -0
- package/dist/text-align-start-BT9VUDxK.js +43 -0
- package/dist/timeouts-BSGxjuUF.js +4 -0
- package/dist/trash-2-DbP2Y6t2.js +25 -0
- package/dist/triangle-alert-aOXceTSe.js +17 -0
- package/dist/useCloudI18n-BuIwR6OE.js +23 -0
- package/dist/useEditorCore-C6ost42Q.js +9342 -0
- package/dist/useI18n-lb2DHDiu.js +17 -0
- package/dist/useMergeTag-CBwKnnNB.js +34 -0
- package/dist/vue.runtime.esm-bundler-DpvJL-nX.js +5775 -0
- package/dist/x-u2oVmjN_.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1733 @@
|
|
|
1
|
+
import { Q as e, X as t, Y as n, Z as r, p as i, z as a } from "./vue.runtime.esm-bundler-DpvJL-nX.js";
|
|
2
|
+
import { r as o, u as s } from "./dist-DJmnUmW9.js";
|
|
3
|
+
//#region ../core/dist/cloud/index.js
|
|
4
|
+
var c = class e {
|
|
5
|
+
static DEFAULT_BASE_URL = "https://templatical.com";
|
|
6
|
+
accessToken = null;
|
|
7
|
+
expiresAt = null;
|
|
8
|
+
_projectId = null;
|
|
9
|
+
_tenantId = null;
|
|
10
|
+
_tenantSlug = null;
|
|
11
|
+
_testEmailConfig = null;
|
|
12
|
+
_userConfig = null;
|
|
13
|
+
url;
|
|
14
|
+
baseUrl;
|
|
15
|
+
requestOptions;
|
|
16
|
+
onError;
|
|
17
|
+
refreshPromise = null;
|
|
18
|
+
static REFRESH_THRESHOLD_MS = 60 * 1e3;
|
|
19
|
+
constructor(t) {
|
|
20
|
+
this.url = t.url, this.baseUrl = (t.baseUrl ?? e.DEFAULT_BASE_URL).replace(/\/$/, ""), this.requestOptions = t.requestOptions ?? {}, this.onError = t.onError;
|
|
21
|
+
}
|
|
22
|
+
resolveUrl(e) {
|
|
23
|
+
if (e.startsWith("http://") || e.startsWith("https://")) return e;
|
|
24
|
+
let t = e.startsWith("/") ? e : `/${e}`;
|
|
25
|
+
return `${this.baseUrl}${t}`;
|
|
26
|
+
}
|
|
27
|
+
get projectId() {
|
|
28
|
+
if (!this._projectId) throw Error("Project ID not available. Call initialize() first.");
|
|
29
|
+
return this._projectId;
|
|
30
|
+
}
|
|
31
|
+
get tenantId() {
|
|
32
|
+
if (!this._tenantId) throw Error("Tenant ID not available. Call initialize() first.");
|
|
33
|
+
return this._tenantId;
|
|
34
|
+
}
|
|
35
|
+
get tenantSlug() {
|
|
36
|
+
if (!this._tenantSlug) throw Error("Tenant slug not available. Call initialize() first.");
|
|
37
|
+
return this._tenantSlug;
|
|
38
|
+
}
|
|
39
|
+
get testEmailConfig() {
|
|
40
|
+
return this._testEmailConfig;
|
|
41
|
+
}
|
|
42
|
+
get userConfig() {
|
|
43
|
+
return this._userConfig;
|
|
44
|
+
}
|
|
45
|
+
get accessTokenValue() {
|
|
46
|
+
return this.accessToken;
|
|
47
|
+
}
|
|
48
|
+
async initialize() {
|
|
49
|
+
await this.ensureToken();
|
|
50
|
+
}
|
|
51
|
+
async ensureToken() {
|
|
52
|
+
return this.accessToken && !this.isTokenExpiringSoon() ? this.accessToken : this.refreshToken();
|
|
53
|
+
}
|
|
54
|
+
isTokenExpiringSoon() {
|
|
55
|
+
return this.expiresAt ? this.expiresAt.getTime() - Date.now() < e.REFRESH_THRESHOLD_MS : !0;
|
|
56
|
+
}
|
|
57
|
+
async refreshToken() {
|
|
58
|
+
if (this.refreshPromise) return this.refreshPromise;
|
|
59
|
+
this.refreshPromise = this.performRefresh();
|
|
60
|
+
try {
|
|
61
|
+
return await this.refreshPromise;
|
|
62
|
+
} finally {
|
|
63
|
+
this.refreshPromise = null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async performRefresh() {
|
|
67
|
+
try {
|
|
68
|
+
let e = this.requestOptions.method ?? "POST", t = {
|
|
69
|
+
Accept: "application/json",
|
|
70
|
+
...this.requestOptions.headers
|
|
71
|
+
}, n = {
|
|
72
|
+
method: e,
|
|
73
|
+
headers: t,
|
|
74
|
+
credentials: this.requestOptions.credentials ?? "include"
|
|
75
|
+
};
|
|
76
|
+
e === "POST" && this.requestOptions.body && (t["Content-Type"] = "application/json", n.body = JSON.stringify(this.requestOptions.body));
|
|
77
|
+
let r = await fetch(this.url, n);
|
|
78
|
+
if (!r.ok) throw new o(`Token refresh failed: ${r.status}`, r.status);
|
|
79
|
+
let i = await r.json();
|
|
80
|
+
if (!i.token || !i.expires_at || !i.project_id || !i.tenant) throw Error("Invalid token response: missing token, expires_at, project_id, or tenant");
|
|
81
|
+
return this.accessToken = i.token, this.expiresAt = /* @__PURE__ */ new Date(i.expires_at * 1e3), this._projectId = i.project_id, this._tenantSlug = i.tenant, i.test_email?.allowed_emails && i.test_email?.signature ? this._testEmailConfig = {
|
|
82
|
+
allowedEmails: i.test_email.allowed_emails,
|
|
83
|
+
signature: i.test_email.signature
|
|
84
|
+
} : this._testEmailConfig = null, i.user?.id && i.user?.name && i.user?.signature ? this._userConfig = {
|
|
85
|
+
id: i.user.id,
|
|
86
|
+
name: i.user.name,
|
|
87
|
+
signature: i.user.signature
|
|
88
|
+
} : this._userConfig = null, this.accessToken;
|
|
89
|
+
} catch (e) {
|
|
90
|
+
let t = e instanceof Error ? e : Error("Token refresh failed", { cause: e });
|
|
91
|
+
throw this.onError?.(t), t;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async authenticatedFetch(e, t = {}) {
|
|
95
|
+
let n = await this.ensureToken(), r = this.resolveUrl(e), i = async (e) => fetch(r, {
|
|
96
|
+
...t,
|
|
97
|
+
headers: {
|
|
98
|
+
...t.headers,
|
|
99
|
+
Authorization: `Bearer ${e}`
|
|
100
|
+
}
|
|
101
|
+
}), a = await i(n);
|
|
102
|
+
return a.status === 401 && (a = await i(await this.refreshToken())), a;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
function l(e, t) {
|
|
106
|
+
return e.replace(/\{(\w+)\}/g, (e, n) => encodeURIComponent(t[n] ?? ""));
|
|
107
|
+
}
|
|
108
|
+
var u = "/api/v1/projects/{project}/tenants/{tenant}", d = `${u}/templates/{template}`, f = `${d}/ai`, p = `${u}/media`, m = `${p}/folders`, h = `${u}/saved-modules`, g = {
|
|
109
|
+
health: "/api/v1/health",
|
|
110
|
+
"projects.config": `${u}/config`,
|
|
111
|
+
"broadcasting.auth": `${u}/broadcasting/auth`,
|
|
112
|
+
"templates.store": `${u}/templates`,
|
|
113
|
+
"templates.show": `${d}`,
|
|
114
|
+
"templates.update": `${d}`,
|
|
115
|
+
"templates.destroy": `${d}`,
|
|
116
|
+
"templates.export": `${d}/export`,
|
|
117
|
+
"templates.importFromBeefree": `${u}/templates/import/from-beefree`,
|
|
118
|
+
"templates.sendTestEmail": `${d}/send-test-email`,
|
|
119
|
+
"snapshots.index": `${d}/snapshots`,
|
|
120
|
+
"snapshots.store": `${d}/snapshots`,
|
|
121
|
+
"snapshots.show": `${d}/snapshots/{snapshot}`,
|
|
122
|
+
"snapshots.restore": `${d}/snapshots/{snapshot}/restore`,
|
|
123
|
+
"comments.index": `${d}/comments`,
|
|
124
|
+
"comments.store": `${d}/comments`,
|
|
125
|
+
"comments.update": `${d}/comments/{comment}`,
|
|
126
|
+
"comments.destroy": `${d}/comments/{comment}`,
|
|
127
|
+
"comments.resolve": `${d}/comments/{comment}/resolve`,
|
|
128
|
+
"ai.generate": `${f}/generate`,
|
|
129
|
+
"ai.conversationMessages": `${f}/conversation-messages`,
|
|
130
|
+
"ai.suggestions": `${f}/suggestions`,
|
|
131
|
+
"ai.rewriteText": `${f}/rewrite-text`,
|
|
132
|
+
"ai.score": `${f}/score`,
|
|
133
|
+
"ai.fixFinding": `${f}/fix-finding`,
|
|
134
|
+
"ai.generateFromDesign": `${f}/generate-from-design`,
|
|
135
|
+
"media.upload": `${p}/upload`,
|
|
136
|
+
"media.browse": `${p}/browse`,
|
|
137
|
+
"media.delete": `${p}/delete`,
|
|
138
|
+
"media.move": `${p}/move`,
|
|
139
|
+
"media.update": `${p}/{media}`,
|
|
140
|
+
"media.replace": `${p}/{media}/replace`,
|
|
141
|
+
"media.checkUsage": `${p}/check-usage`,
|
|
142
|
+
"media.frequentlyUsed": `${p}/frequently-used`,
|
|
143
|
+
"media.importFromUrl": `${p}/import-from-url`,
|
|
144
|
+
"folders.index": `${m}`,
|
|
145
|
+
"folders.store": `${m}`,
|
|
146
|
+
"folders.update": `${m}/{mediaFolder}`,
|
|
147
|
+
"folders.destroy": `${m}/{mediaFolder}`,
|
|
148
|
+
"savedModules.index": `${h}`,
|
|
149
|
+
"savedModules.store": `${h}`,
|
|
150
|
+
"savedModules.update": `${h}/{savedModule}`,
|
|
151
|
+
"savedModules.destroy": `${h}/{savedModule}`
|
|
152
|
+
}, _ = class {
|
|
153
|
+
constructor(e) {
|
|
154
|
+
this.authManager = e;
|
|
155
|
+
}
|
|
156
|
+
authManager;
|
|
157
|
+
get projectId() {
|
|
158
|
+
return this.authManager.projectId;
|
|
159
|
+
}
|
|
160
|
+
get tenantSlug() {
|
|
161
|
+
return this.authManager.tenantSlug;
|
|
162
|
+
}
|
|
163
|
+
get baseParams() {
|
|
164
|
+
return {
|
|
165
|
+
project: this.projectId,
|
|
166
|
+
tenant: this.tenantSlug
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async request(e, t = {}) {
|
|
170
|
+
let n = await this.authManager.authenticatedFetch(e, {
|
|
171
|
+
...t,
|
|
172
|
+
headers: {
|
|
173
|
+
"Content-Type": "application/json",
|
|
174
|
+
Accept: "application/json",
|
|
175
|
+
...t.headers
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
if (!n.ok) {
|
|
179
|
+
let e = await n.json().catch(() => ({ message: `HTTP error ${n.status}` }));
|
|
180
|
+
throw new o(this.extractFirstValidationError(e), n.status);
|
|
181
|
+
}
|
|
182
|
+
if (n.status !== 204) return (await n.json()).data;
|
|
183
|
+
}
|
|
184
|
+
extractFirstValidationError(e) {
|
|
185
|
+
if (e.errors) {
|
|
186
|
+
let t = Object.keys(e.errors)[0];
|
|
187
|
+
if (t && e.errors[t]?.length > 0) return e.errors[t][0];
|
|
188
|
+
}
|
|
189
|
+
return e.message;
|
|
190
|
+
}
|
|
191
|
+
async createTemplate(e) {
|
|
192
|
+
return this.request(l(g["templates.store"], this.baseParams), {
|
|
193
|
+
method: "POST",
|
|
194
|
+
body: JSON.stringify({ content: e })
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
async getTemplate(e) {
|
|
198
|
+
return this.request(l(g["templates.show"], {
|
|
199
|
+
...this.baseParams,
|
|
200
|
+
template: e
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
async updateTemplate(e, t) {
|
|
204
|
+
return this.request(l(g["templates.update"], {
|
|
205
|
+
...this.baseParams,
|
|
206
|
+
template: e
|
|
207
|
+
}), {
|
|
208
|
+
method: "PUT",
|
|
209
|
+
body: JSON.stringify({ content: t })
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async createSnapshot(e, t) {
|
|
213
|
+
return this.request(l(g["snapshots.store"], {
|
|
214
|
+
...this.baseParams,
|
|
215
|
+
template: e
|
|
216
|
+
}), {
|
|
217
|
+
method: "POST",
|
|
218
|
+
body: JSON.stringify({ content: t })
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
async deleteTemplate(e) {
|
|
222
|
+
return this.request(l(g["templates.destroy"], {
|
|
223
|
+
...this.baseParams,
|
|
224
|
+
template: e
|
|
225
|
+
}), { method: "DELETE" });
|
|
226
|
+
}
|
|
227
|
+
async getSnapshots(e) {
|
|
228
|
+
return this.request(l(g["snapshots.index"], {
|
|
229
|
+
...this.baseParams,
|
|
230
|
+
template: e
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
async restoreSnapshot(e, t) {
|
|
234
|
+
return this.request(l(g["snapshots.restore"], {
|
|
235
|
+
...this.baseParams,
|
|
236
|
+
template: e,
|
|
237
|
+
snapshot: t
|
|
238
|
+
}), { method: "POST" });
|
|
239
|
+
}
|
|
240
|
+
async exportTemplate(e, t) {
|
|
241
|
+
let n = t ? JSON.stringify({
|
|
242
|
+
custom_fonts: t.customFonts,
|
|
243
|
+
default_fallback: t.defaultFallback
|
|
244
|
+
}) : void 0;
|
|
245
|
+
return this.request(l(g["templates.export"], {
|
|
246
|
+
...this.baseParams,
|
|
247
|
+
template: e
|
|
248
|
+
}), {
|
|
249
|
+
method: "POST",
|
|
250
|
+
body: n
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
async sendTestEmail(e, t) {
|
|
254
|
+
await this.request(l(g["templates.sendTestEmail"], {
|
|
255
|
+
...this.baseParams,
|
|
256
|
+
template: e
|
|
257
|
+
}), {
|
|
258
|
+
method: "POST",
|
|
259
|
+
body: JSON.stringify(t)
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
commentsUrl(e, t) {
|
|
263
|
+
return t ? l(g["comments.update"], {
|
|
264
|
+
...this.baseParams,
|
|
265
|
+
template: e,
|
|
266
|
+
comment: t
|
|
267
|
+
}) : l(g["comments.index"], {
|
|
268
|
+
...this.baseParams,
|
|
269
|
+
template: e
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
async getComments(e) {
|
|
273
|
+
return this.request(this.commentsUrl(e));
|
|
274
|
+
}
|
|
275
|
+
async createComment(e, t, n) {
|
|
276
|
+
return this.request(this.commentsUrl(e), {
|
|
277
|
+
method: "POST",
|
|
278
|
+
body: JSON.stringify(t),
|
|
279
|
+
headers: n
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
async updateComment(e, t, n, r) {
|
|
283
|
+
return this.request(this.commentsUrl(e, t), {
|
|
284
|
+
method: "PUT",
|
|
285
|
+
body: JSON.stringify(n),
|
|
286
|
+
headers: r
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
async deleteComment(e, t, n, r) {
|
|
290
|
+
return this.request(this.commentsUrl(e, t), {
|
|
291
|
+
method: "DELETE",
|
|
292
|
+
body: JSON.stringify(n),
|
|
293
|
+
headers: r
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
async resolveComment(e, t, n, r) {
|
|
297
|
+
return this.request(l(g["comments.resolve"], {
|
|
298
|
+
...this.baseParams,
|
|
299
|
+
template: e,
|
|
300
|
+
comment: t
|
|
301
|
+
}), {
|
|
302
|
+
method: "POST",
|
|
303
|
+
body: JSON.stringify(n),
|
|
304
|
+
headers: r
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
async fetchConfig() {
|
|
308
|
+
return this.request(l(g["projects.config"], this.baseParams));
|
|
309
|
+
}
|
|
310
|
+
async listModules(e) {
|
|
311
|
+
let t = l(g["savedModules.index"], this.baseParams), n = e ? `?search=${encodeURIComponent(e)}` : "";
|
|
312
|
+
return this.request(`${t}${n}`);
|
|
313
|
+
}
|
|
314
|
+
async createModule(e) {
|
|
315
|
+
return this.request(l(g["savedModules.store"], this.baseParams), {
|
|
316
|
+
method: "POST",
|
|
317
|
+
body: JSON.stringify(e)
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
async updateModule(e, t) {
|
|
321
|
+
return this.request(l(g["savedModules.update"], {
|
|
322
|
+
...this.baseParams,
|
|
323
|
+
savedModule: e
|
|
324
|
+
}), {
|
|
325
|
+
method: "PUT",
|
|
326
|
+
body: JSON.stringify(t)
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
async deleteModule(e) {
|
|
330
|
+
return this.request(l(g["savedModules.destroy"], {
|
|
331
|
+
...this.baseParams,
|
|
332
|
+
savedModule: e
|
|
333
|
+
}), { method: "DELETE" });
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
function v(e) {
|
|
337
|
+
return {
|
|
338
|
+
host: e.host,
|
|
339
|
+
port: e.port,
|
|
340
|
+
appKey: e.app_key
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
var y = class {
|
|
344
|
+
pusher = null;
|
|
345
|
+
authManager;
|
|
346
|
+
config;
|
|
347
|
+
onError;
|
|
348
|
+
constructor(e) {
|
|
349
|
+
this.authManager = e.authManager, this.config = e.config, this.onError = e.onError;
|
|
350
|
+
}
|
|
351
|
+
async connect() {
|
|
352
|
+
if (this.pusher) return;
|
|
353
|
+
let e;
|
|
354
|
+
try {
|
|
355
|
+
({default: e} = await import("pusher-js"));
|
|
356
|
+
} catch {
|
|
357
|
+
throw Error("Cloud features require the optional peer dependency 'pusher-js'. Install it with: npm install pusher-js");
|
|
358
|
+
}
|
|
359
|
+
let { host: t, port: n, appKey: r } = this.config, i = this.authManager.resolveUrl(l(g["broadcasting.auth"], {
|
|
360
|
+
project: this.authManager.projectId,
|
|
361
|
+
tenant: this.authManager.tenantSlug
|
|
362
|
+
}));
|
|
363
|
+
this.pusher = new e(r, {
|
|
364
|
+
wsHost: t,
|
|
365
|
+
wsPort: n,
|
|
366
|
+
wssPort: n,
|
|
367
|
+
forceTLS: !0,
|
|
368
|
+
disableStats: !0,
|
|
369
|
+
enabledTransports: ["ws", "wss"],
|
|
370
|
+
cluster: "",
|
|
371
|
+
channelAuthorization: {
|
|
372
|
+
transport: "ajax",
|
|
373
|
+
endpoint: i,
|
|
374
|
+
headers: {
|
|
375
|
+
Authorization: `Bearer ${this.authManager.accessTokenValue}`,
|
|
376
|
+
Accept: "application/json"
|
|
377
|
+
},
|
|
378
|
+
params: {
|
|
379
|
+
user_id: this.authManager.userConfig?.id ?? "",
|
|
380
|
+
user_name: this.authManager.userConfig?.name ?? "",
|
|
381
|
+
user_signature: this.authManager.userConfig?.signature ?? ""
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}), this.pusher.connection.bind("error", (e) => {
|
|
385
|
+
this.onError?.(e instanceof Error ? e : /* @__PURE__ */ Error("WebSocket connection error"));
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
subscribePresence(e) {
|
|
389
|
+
if (!this.pusher) throw Error("WebSocketClient not connected. Call connect() first.");
|
|
390
|
+
return this.pusher.subscribe(e);
|
|
391
|
+
}
|
|
392
|
+
unsubscribe(e) {
|
|
393
|
+
this.pusher?.unsubscribe(e);
|
|
394
|
+
}
|
|
395
|
+
getChannel(e) {
|
|
396
|
+
return this.pusher?.channel(e);
|
|
397
|
+
}
|
|
398
|
+
disconnect() {
|
|
399
|
+
this.pusher &&= (this.pusher.disconnect(), null);
|
|
400
|
+
}
|
|
401
|
+
getSocketId() {
|
|
402
|
+
return this.pusher?.connection.socket_id ?? null;
|
|
403
|
+
}
|
|
404
|
+
get isConnected() {
|
|
405
|
+
return this.pusher?.connection.state === "connected";
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
function b(e, t) {
|
|
409
|
+
let { operation: n, data: r } = t;
|
|
410
|
+
switch (n) {
|
|
411
|
+
case "add_block":
|
|
412
|
+
e.addBlock(r.block, r.section_id, r.column_index, r.index);
|
|
413
|
+
break;
|
|
414
|
+
case "update_block":
|
|
415
|
+
e.updateBlock(r.block_id, r.updates);
|
|
416
|
+
break;
|
|
417
|
+
case "delete_block":
|
|
418
|
+
e.removeBlock(r.block_id);
|
|
419
|
+
break;
|
|
420
|
+
case "move_block":
|
|
421
|
+
e.moveBlock(r.block_id, r.index, r.section_id, r.column_index);
|
|
422
|
+
break;
|
|
423
|
+
case "update_settings":
|
|
424
|
+
e.updateSettings(r.updates);
|
|
425
|
+
break;
|
|
426
|
+
case "set_content":
|
|
427
|
+
e.setContent(r.content);
|
|
428
|
+
break;
|
|
429
|
+
case "update_block_style":
|
|
430
|
+
e.updateBlock(r.block_id, { styles: r.styles });
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function x(e) {
|
|
435
|
+
let n = new _(e.authManager), a = t({
|
|
436
|
+
template: null,
|
|
437
|
+
content: s(e.defaultFontFamily, e.templateDefaults),
|
|
438
|
+
selectedBlockId: null,
|
|
439
|
+
viewport: "desktop",
|
|
440
|
+
darkMode: !1,
|
|
441
|
+
previewMode: !1,
|
|
442
|
+
isDirty: !1,
|
|
443
|
+
isSaving: !1,
|
|
444
|
+
isLoading: !1,
|
|
445
|
+
uiTheme: "auto"
|
|
446
|
+
}), c = i({
|
|
447
|
+
get: () => a.content,
|
|
448
|
+
set: (e) => {
|
|
449
|
+
a.content = e, a.isDirty = !0;
|
|
450
|
+
}
|
|
451
|
+
}), l = i(() => a.selectedBlockId ? d(a.content.blocks, a.selectedBlockId) : null), u = i(() => {
|
|
452
|
+
let e = /* @__PURE__ */ new Set(), t = a.template?.content?.blocks;
|
|
453
|
+
if (!t) return e;
|
|
454
|
+
for (let n of t) if (e.add(n.id), n.type === "section") for (let t of n.children) for (let n of t) e.add(n.id);
|
|
455
|
+
return e;
|
|
456
|
+
});
|
|
457
|
+
function d(e, t) {
|
|
458
|
+
for (let n of e) {
|
|
459
|
+
if (n.id === t) return n;
|
|
460
|
+
if (n.type === "section") for (let e of n.children) {
|
|
461
|
+
let n = d(e, t);
|
|
462
|
+
if (n) return n;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
function f(e, t, n = { blocks: e }) {
|
|
468
|
+
for (let r = 0; r < e.length; r++) {
|
|
469
|
+
let i = e[r];
|
|
470
|
+
if (i.id === t) return n;
|
|
471
|
+
if (i.type === "section") for (let e = 0; e < i.children.length; e++) {
|
|
472
|
+
let n = f(i.children[e], t, {
|
|
473
|
+
blocks: i.children[e],
|
|
474
|
+
sectionId: i.id,
|
|
475
|
+
columnIndex: e
|
|
476
|
+
});
|
|
477
|
+
if (n) return n;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
function p(t) {
|
|
483
|
+
return e.lockedBlocks?.value.has(t) ?? !1;
|
|
484
|
+
}
|
|
485
|
+
function m(e, t = !0) {
|
|
486
|
+
a.content = e, t && (a.isDirty = !0);
|
|
487
|
+
}
|
|
488
|
+
function h(e) {
|
|
489
|
+
e && p(e) || (a.selectedBlockId = e);
|
|
490
|
+
}
|
|
491
|
+
function g(e) {
|
|
492
|
+
a.viewport = e;
|
|
493
|
+
}
|
|
494
|
+
function v(e) {
|
|
495
|
+
a.darkMode = e;
|
|
496
|
+
}
|
|
497
|
+
function y(e) {
|
|
498
|
+
a.uiTheme = e;
|
|
499
|
+
}
|
|
500
|
+
function b(e) {
|
|
501
|
+
a.previewMode = e, e && (a.selectedBlockId = null);
|
|
502
|
+
}
|
|
503
|
+
function x(e, t) {
|
|
504
|
+
if (p(e)) return;
|
|
505
|
+
let n = d(a.content.blocks, e);
|
|
506
|
+
n && (Object.assign(n, t), a.isDirty = !0);
|
|
507
|
+
}
|
|
508
|
+
function S(e) {
|
|
509
|
+
a.content.settings = {
|
|
510
|
+
...a.content.settings,
|
|
511
|
+
...e
|
|
512
|
+
}, a.isDirty = !0;
|
|
513
|
+
}
|
|
514
|
+
function C(e, t, n = 0, r) {
|
|
515
|
+
if (t) {
|
|
516
|
+
let i = d(a.content.blocks, t);
|
|
517
|
+
if (i && i.type === "section") {
|
|
518
|
+
i.children[n] = i.children[n] || [];
|
|
519
|
+
let t = i.children[n];
|
|
520
|
+
r !== void 0 && r < t.length ? t.splice(r, 0, e) : t.push(e);
|
|
521
|
+
}
|
|
522
|
+
} else r !== void 0 && r < a.content.blocks.length ? a.content.blocks.splice(r, 0, e) : a.content.blocks.push(e);
|
|
523
|
+
a.isDirty = !0;
|
|
524
|
+
}
|
|
525
|
+
function w(e) {
|
|
526
|
+
if (p(e)) return;
|
|
527
|
+
let t = f(a.content.blocks, e);
|
|
528
|
+
if (t) {
|
|
529
|
+
let n = t.blocks.findIndex((t) => t.id === e);
|
|
530
|
+
n !== -1 && (t.blocks.splice(n, 1), a.selectedBlockId === e && (a.selectedBlockId = null), a.isDirty = !0);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function T(e, t, n, r = 0) {
|
|
534
|
+
let i = f(a.content.blocks, e);
|
|
535
|
+
if (!i) return;
|
|
536
|
+
let o = i.blocks.findIndex((t) => t.id === e);
|
|
537
|
+
if (o === -1) return;
|
|
538
|
+
let [s] = i.blocks.splice(o, 1);
|
|
539
|
+
if (n) {
|
|
540
|
+
let e = d(a.content.blocks, n);
|
|
541
|
+
e && e.type === "section" && (e.children[r] = e.children[r] || [], e.children[r].splice(t, 0, s));
|
|
542
|
+
} else a.content.blocks.splice(t, 0, s);
|
|
543
|
+
a.isDirty = !0;
|
|
544
|
+
}
|
|
545
|
+
async function E(t) {
|
|
546
|
+
a.isLoading = !0;
|
|
547
|
+
try {
|
|
548
|
+
t && (a.content = t);
|
|
549
|
+
let e = await n.createTemplate(a.content);
|
|
550
|
+
return a.template = e, a.isDirty = !1, e;
|
|
551
|
+
} catch (t) {
|
|
552
|
+
throw e.onError?.(t), t;
|
|
553
|
+
} finally {
|
|
554
|
+
a.isLoading = !1;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
async function D(t) {
|
|
558
|
+
a.isLoading = !0;
|
|
559
|
+
try {
|
|
560
|
+
let e = await n.getTemplate(t);
|
|
561
|
+
return a.template = e, a.content = e.content, a.isDirty = !1, e;
|
|
562
|
+
} catch (t) {
|
|
563
|
+
throw e.onError?.(t), t;
|
|
564
|
+
} finally {
|
|
565
|
+
a.isLoading = !1;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
async function O() {
|
|
569
|
+
if (!a.template?.id) throw new o("No template loaded. Call create() or load() before saving.");
|
|
570
|
+
a.isSaving = !0;
|
|
571
|
+
try {
|
|
572
|
+
let e = await n.updateTemplate(a.template.id, a.content);
|
|
573
|
+
return a.template = e, a.isDirty = !1, e;
|
|
574
|
+
} catch (t) {
|
|
575
|
+
throw e.onError?.(t), t;
|
|
576
|
+
} finally {
|
|
577
|
+
a.isSaving = !1;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async function k() {
|
|
581
|
+
if (a.template?.id) try {
|
|
582
|
+
await n.createSnapshot(a.template.id, a.content);
|
|
583
|
+
} catch (t) {
|
|
584
|
+
throw e.onError?.(t), t;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function A() {
|
|
588
|
+
return a.template?.id !== void 0;
|
|
589
|
+
}
|
|
590
|
+
function j() {
|
|
591
|
+
a.isDirty = !0;
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
state: r(a),
|
|
595
|
+
content: c,
|
|
596
|
+
selectedBlock: l,
|
|
597
|
+
savedBlockIds: u,
|
|
598
|
+
isBlockLocked: p,
|
|
599
|
+
setContent: m,
|
|
600
|
+
selectBlock: h,
|
|
601
|
+
setViewport: g,
|
|
602
|
+
setDarkMode: v,
|
|
603
|
+
setUiTheme: y,
|
|
604
|
+
setPreviewMode: b,
|
|
605
|
+
updateBlock: x,
|
|
606
|
+
updateSettings: S,
|
|
607
|
+
addBlock: C,
|
|
608
|
+
removeBlock: w,
|
|
609
|
+
moveBlock: T,
|
|
610
|
+
create: E,
|
|
611
|
+
load: D,
|
|
612
|
+
save: O,
|
|
613
|
+
createSnapshot: k,
|
|
614
|
+
hasTemplate: A,
|
|
615
|
+
markDirty: j
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
var S = 0;
|
|
619
|
+
function C() {
|
|
620
|
+
return `msg_${Date.now()}_${++S}`;
|
|
621
|
+
}
|
|
622
|
+
function w(t) {
|
|
623
|
+
let { authManager: n, getTemplateId: r, onApply: i, onError: a } = t, o = e([]), s = e(!1), c = e(!1), u = e(null), d = e(null), f = e(null), p = e(null), m = e(null), h = e(null), _ = e(!1), v = e([]), y = e(!1);
|
|
624
|
+
function b(e, t) {
|
|
625
|
+
let n = o.value.findIndex((t) => t.id === e);
|
|
626
|
+
if (n === -1) return;
|
|
627
|
+
let r = {
|
|
628
|
+
...o.value[n],
|
|
629
|
+
...t
|
|
630
|
+
};
|
|
631
|
+
o.value = [
|
|
632
|
+
...o.value.slice(0, n),
|
|
633
|
+
r,
|
|
634
|
+
...o.value.slice(n + 1)
|
|
635
|
+
];
|
|
636
|
+
}
|
|
637
|
+
async function x() {
|
|
638
|
+
let e = r();
|
|
639
|
+
if (e) {
|
|
640
|
+
c.value = !0;
|
|
641
|
+
try {
|
|
642
|
+
let t = l(g["ai.conversationMessages"], {
|
|
643
|
+
project: n.projectId,
|
|
644
|
+
tenant: n.tenantSlug,
|
|
645
|
+
template: e
|
|
646
|
+
}), r = await n.authenticatedFetch(t, {
|
|
647
|
+
method: "GET",
|
|
648
|
+
headers: { Accept: "application/json" }
|
|
649
|
+
});
|
|
650
|
+
if (!r.ok) return;
|
|
651
|
+
let i = await r.json();
|
|
652
|
+
i.conversation_id && (f.value = i.conversation_id), Array.isArray(i.data) && i.data.length > 0 && (o.value = i.data.map((e) => ({
|
|
653
|
+
id: e.id,
|
|
654
|
+
role: e.role,
|
|
655
|
+
content: e.content,
|
|
656
|
+
timestamp: new Date(e.created_at).getTime()
|
|
657
|
+
})));
|
|
658
|
+
} catch {} finally {
|
|
659
|
+
c.value = !1;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
async function S(e, t) {
|
|
664
|
+
let i = r();
|
|
665
|
+
if (i) {
|
|
666
|
+
y.value = !0;
|
|
667
|
+
try {
|
|
668
|
+
let r = l(g["ai.suggestions"], {
|
|
669
|
+
project: n.projectId,
|
|
670
|
+
tenant: n.tenantSlug,
|
|
671
|
+
template: i
|
|
672
|
+
}), a = await n.authenticatedFetch(r, {
|
|
673
|
+
method: "POST",
|
|
674
|
+
headers: {
|
|
675
|
+
"Content-Type": "application/json",
|
|
676
|
+
Accept: "text/event-stream"
|
|
677
|
+
},
|
|
678
|
+
body: JSON.stringify({
|
|
679
|
+
current_content: e,
|
|
680
|
+
merge_tags: t.map((e) => ({
|
|
681
|
+
label: e.label,
|
|
682
|
+
value: e.value
|
|
683
|
+
}))
|
|
684
|
+
})
|
|
685
|
+
});
|
|
686
|
+
if (!a.ok) return;
|
|
687
|
+
let o = a.body?.getReader();
|
|
688
|
+
if (!o) return;
|
|
689
|
+
let s = new TextDecoder(), c = "";
|
|
690
|
+
for (;;) {
|
|
691
|
+
let { done: e, value: t } = await o.read();
|
|
692
|
+
if (e) break;
|
|
693
|
+
c += s.decode(t, { stream: !0 });
|
|
694
|
+
let n = c.split("\n");
|
|
695
|
+
c = n.pop() ?? "";
|
|
696
|
+
for (let e of n) {
|
|
697
|
+
if (!e.startsWith("data: ")) continue;
|
|
698
|
+
let t;
|
|
699
|
+
try {
|
|
700
|
+
t = JSON.parse(e.slice(6));
|
|
701
|
+
} catch {
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
t.type === "done" && Array.isArray(t.suggestions) && (v.value = t.suggestions.slice(0, 3));
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
} catch {} finally {
|
|
708
|
+
y.value = !1;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
async function w(e, t, c) {
|
|
713
|
+
let y = r();
|
|
714
|
+
if (!y) throw Error("Template must be saved before using AI generation");
|
|
715
|
+
s.value = !0, u.value = null, d.value = null, v.value = [];
|
|
716
|
+
let x = C();
|
|
717
|
+
o.value = [...o.value, {
|
|
718
|
+
id: x,
|
|
719
|
+
role: "user",
|
|
720
|
+
content: e,
|
|
721
|
+
timestamp: Date.now()
|
|
722
|
+
}];
|
|
723
|
+
let S = C();
|
|
724
|
+
o.value = [...o.value, {
|
|
725
|
+
id: S,
|
|
726
|
+
role: "assistant",
|
|
727
|
+
content: "",
|
|
728
|
+
timestamp: Date.now()
|
|
729
|
+
}];
|
|
730
|
+
try {
|
|
731
|
+
let r = l(g["ai.generate"], {
|
|
732
|
+
project: n.projectId,
|
|
733
|
+
tenant: n.tenantSlug,
|
|
734
|
+
template: y
|
|
735
|
+
}), a = await n.authenticatedFetch(r, {
|
|
736
|
+
method: "POST",
|
|
737
|
+
headers: {
|
|
738
|
+
"Content-Type": "application/json",
|
|
739
|
+
Accept: "text/event-stream"
|
|
740
|
+
},
|
|
741
|
+
body: JSON.stringify({
|
|
742
|
+
prompt: e,
|
|
743
|
+
current_content: t,
|
|
744
|
+
merge_tags: c.map((e) => ({
|
|
745
|
+
label: e.label,
|
|
746
|
+
value: e.value
|
|
747
|
+
})),
|
|
748
|
+
conversation_id: f.value
|
|
749
|
+
})
|
|
750
|
+
});
|
|
751
|
+
if (!a.ok) {
|
|
752
|
+
let e = await a.json().catch(() => null);
|
|
753
|
+
throw a.status === 403 ? Error("ai_generation_not_available") : Error(e?.message || "Failed to generate template");
|
|
754
|
+
}
|
|
755
|
+
let s = a.body?.getReader();
|
|
756
|
+
if (!s) throw Error("Failed to read stream");
|
|
757
|
+
let d = new TextDecoder(), v = "", x = null;
|
|
758
|
+
try {
|
|
759
|
+
for (;;) {
|
|
760
|
+
let { done: e, value: n } = await s.read();
|
|
761
|
+
if (e) break;
|
|
762
|
+
v += d.decode(n, { stream: !0 });
|
|
763
|
+
let r = v.split("\n");
|
|
764
|
+
v = r.pop() ?? "";
|
|
765
|
+
for (let e of r) {
|
|
766
|
+
if (!e.startsWith("data: ")) continue;
|
|
767
|
+
let n = e.slice(6), r;
|
|
768
|
+
try {
|
|
769
|
+
r = JSON.parse(n);
|
|
770
|
+
} catch {
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
if (r.type === "text") b(S, { content: (o.value.find((e) => e.id === S)?.content ?? "") + r.text });
|
|
774
|
+
else if (r.type === "error") throw Error(r.message || "Failed to generate template");
|
|
775
|
+
else r.type === "done" && (r.conversation_id && (f.value = r.conversation_id), b(S, { content: r.text }), x = r.content ?? null, x ? (m.value = t, h.value = x, p.value = S, _.value = !1, i?.(x)) : u.value = "ai_apply_failed");
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
} finally {
|
|
779
|
+
s.cancel().catch(() => {});
|
|
780
|
+
}
|
|
781
|
+
return x;
|
|
782
|
+
} catch (t) {
|
|
783
|
+
let n = t instanceof Error ? t : Error("Failed to generate template", { cause: t });
|
|
784
|
+
return u.value = n.message, d.value = e, a?.(n), o.value = o.value.filter((e) => e.id !== x && e.id !== S), null;
|
|
785
|
+
} finally {
|
|
786
|
+
s.value = !1;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
function T() {
|
|
790
|
+
_.value ? (h.value && i?.(h.value), _.value = !1) : (m.value && i?.(m.value), _.value = !0);
|
|
791
|
+
}
|
|
792
|
+
function E() {
|
|
793
|
+
o.value = [], f.value = null, u.value = null, p.value = null, m.value = null, h.value = null, _.value = !1;
|
|
794
|
+
}
|
|
795
|
+
return {
|
|
796
|
+
messages: o,
|
|
797
|
+
isGenerating: s,
|
|
798
|
+
isLoadingHistory: c,
|
|
799
|
+
isLastChangeReverted: _,
|
|
800
|
+
lastApplyMessageId: p,
|
|
801
|
+
error: u,
|
|
802
|
+
failedPrompt: d,
|
|
803
|
+
suggestions: v,
|
|
804
|
+
isLoadingSuggestions: y,
|
|
805
|
+
sendPrompt: w,
|
|
806
|
+
toggleLastRevert: T,
|
|
807
|
+
loadConversation: x,
|
|
808
|
+
loadSuggestions: S,
|
|
809
|
+
clearChat: E
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
function T(e) {
|
|
813
|
+
function t(t) {
|
|
814
|
+
return e === !1 ? !1 : e?.[t] !== !1;
|
|
815
|
+
}
|
|
816
|
+
return {
|
|
817
|
+
isFeatureEnabled: t,
|
|
818
|
+
hasAnyMenuFeature: i(() => t("chat") || t("scoring") || t("designToTemplate"))
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
function E(t) {
|
|
822
|
+
let { authManager: n, getTemplateId: r } = t, i = e(!1), a = e(null), o = e(null), s = e(null), c = e(""), u = e(null);
|
|
823
|
+
async function d(e, t) {
|
|
824
|
+
let s = r();
|
|
825
|
+
if (!s) return null;
|
|
826
|
+
i.value = !0, o.value = null, a.value = null;
|
|
827
|
+
try {
|
|
828
|
+
let r = l(g["ai.score"], {
|
|
829
|
+
project: n.projectId,
|
|
830
|
+
tenant: n.tenantSlug,
|
|
831
|
+
template: s
|
|
832
|
+
}), i = await n.authenticatedFetch(r, {
|
|
833
|
+
method: "POST",
|
|
834
|
+
headers: {
|
|
835
|
+
"Content-Type": "application/json",
|
|
836
|
+
Accept: "text/event-stream"
|
|
837
|
+
},
|
|
838
|
+
body: JSON.stringify({
|
|
839
|
+
current_content: e,
|
|
840
|
+
merge_tags: t.map((e) => ({
|
|
841
|
+
label: e.label,
|
|
842
|
+
value: e.value
|
|
843
|
+
}))
|
|
844
|
+
})
|
|
845
|
+
});
|
|
846
|
+
if (!i.ok) {
|
|
847
|
+
if (i.status === 403) throw Error("ai_generation_not_available");
|
|
848
|
+
let e = await i.json().catch(() => null);
|
|
849
|
+
throw Error(e?.message || "Failed to score template");
|
|
850
|
+
}
|
|
851
|
+
let o = i.body?.getReader();
|
|
852
|
+
if (!o) throw Error("Failed to read stream");
|
|
853
|
+
let c = new TextDecoder(), u = "", d = null;
|
|
854
|
+
for (;;) {
|
|
855
|
+
let { done: e, value: t } = await o.read();
|
|
856
|
+
if (e) break;
|
|
857
|
+
u += c.decode(t, { stream: !0 });
|
|
858
|
+
let n = u.split("\n");
|
|
859
|
+
u = n.pop() ?? "";
|
|
860
|
+
for (let e of n) {
|
|
861
|
+
if (!e.startsWith("data: ")) continue;
|
|
862
|
+
let t;
|
|
863
|
+
try {
|
|
864
|
+
t = JSON.parse(e.slice(6));
|
|
865
|
+
} catch {
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
if (t.type === "error") throw Error(t.message || "Failed to score template");
|
|
869
|
+
t.type === "done" && (d = t.result ?? null);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (d) for (let [e, t] of Object.entries(d.categories)) for (let n of t.findings) n.category = e;
|
|
873
|
+
return a.value = d, d;
|
|
874
|
+
} catch (e) {
|
|
875
|
+
return o.value = e instanceof Error ? e.message : "Failed to score template", null;
|
|
876
|
+
} finally {
|
|
877
|
+
i.value = !1;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
async function f(e, t, i) {
|
|
881
|
+
let a = r();
|
|
882
|
+
if (!a) return null;
|
|
883
|
+
s.value = t.id, c.value = "", u.value = null;
|
|
884
|
+
try {
|
|
885
|
+
let r = l(g["ai.fixFinding"], {
|
|
886
|
+
project: n.projectId,
|
|
887
|
+
tenant: n.tenantSlug,
|
|
888
|
+
template: a
|
|
889
|
+
}), o = await n.authenticatedFetch(r, {
|
|
890
|
+
method: "POST",
|
|
891
|
+
headers: {
|
|
892
|
+
"Content-Type": "application/json",
|
|
893
|
+
Accept: "text/event-stream"
|
|
894
|
+
},
|
|
895
|
+
body: JSON.stringify({
|
|
896
|
+
content: e,
|
|
897
|
+
finding: {
|
|
898
|
+
id: t.id,
|
|
899
|
+
message: t.message,
|
|
900
|
+
suggestion: t.suggestion,
|
|
901
|
+
category: t.category
|
|
902
|
+
},
|
|
903
|
+
merge_tags: i.map((e) => ({
|
|
904
|
+
label: e.label,
|
|
905
|
+
value: e.value
|
|
906
|
+
}))
|
|
907
|
+
})
|
|
908
|
+
});
|
|
909
|
+
if (!o.ok) {
|
|
910
|
+
if (o.status === 403) throw Error("ai_generation_not_available");
|
|
911
|
+
let e = await o.json().catch(() => null);
|
|
912
|
+
throw Error(e?.message || "Failed to fix finding");
|
|
913
|
+
}
|
|
914
|
+
let s = o.body?.getReader();
|
|
915
|
+
if (!s) throw Error("Failed to read stream");
|
|
916
|
+
let u = new TextDecoder(), d = "", f = null;
|
|
917
|
+
for (;;) {
|
|
918
|
+
let { done: e, value: t } = await s.read();
|
|
919
|
+
if (e) break;
|
|
920
|
+
d += u.decode(t, { stream: !0 });
|
|
921
|
+
let n = d.split("\n");
|
|
922
|
+
d = n.pop() ?? "";
|
|
923
|
+
for (let e of n) {
|
|
924
|
+
if (!e.startsWith("data: ")) continue;
|
|
925
|
+
let t;
|
|
926
|
+
try {
|
|
927
|
+
t = JSON.parse(e.slice(6));
|
|
928
|
+
} catch {
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
if (t.type === "text") c.value += t.text;
|
|
932
|
+
else if (t.type === "error") throw Error(t.message || "Failed to fix finding");
|
|
933
|
+
else t.type === "done" && (f = t.content ?? null);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return f;
|
|
937
|
+
} catch (e) {
|
|
938
|
+
return u.value = e instanceof Error ? e.message : "Failed to fix finding", null;
|
|
939
|
+
} finally {
|
|
940
|
+
s.value = null;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
function p(e, t) {
|
|
944
|
+
if (!a.value) return;
|
|
945
|
+
let n = a.value.categories[e];
|
|
946
|
+
n && (n.findings = n.findings.filter((e) => e.id !== t));
|
|
947
|
+
}
|
|
948
|
+
function m() {
|
|
949
|
+
i.value = !1, a.value = null, o.value = null, s.value = null, c.value = "", u.value = null;
|
|
950
|
+
}
|
|
951
|
+
return {
|
|
952
|
+
isScoring: i,
|
|
953
|
+
scoringResult: a,
|
|
954
|
+
error: o,
|
|
955
|
+
fixingFindingId: s,
|
|
956
|
+
fixStreamingText: c,
|
|
957
|
+
fixError: u,
|
|
958
|
+
score: d,
|
|
959
|
+
fixFinding: f,
|
|
960
|
+
removeFinding: p,
|
|
961
|
+
reset: m
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
function D(t) {
|
|
965
|
+
let { authManager: n, getTemplateId: r, onApply: i, onError: a } = t, o = e(!1), s = e(null);
|
|
966
|
+
async function c(e) {
|
|
967
|
+
let t = r();
|
|
968
|
+
if (!t) throw Error("Template must be saved before using design reference");
|
|
969
|
+
o.value = !0, s.value = null;
|
|
970
|
+
try {
|
|
971
|
+
let r = new FormData();
|
|
972
|
+
e.prompt && r.append("prompt", e.prompt), e.imageUpload && r.append("image_upload", e.imageUpload), e.pdfUpload && r.append("pdf_upload", e.pdfUpload);
|
|
973
|
+
let a = l(g["ai.generateFromDesign"], {
|
|
974
|
+
project: n.projectId,
|
|
975
|
+
tenant: n.tenantSlug,
|
|
976
|
+
template: t
|
|
977
|
+
}), o = await n.authenticatedFetch(a, {
|
|
978
|
+
method: "POST",
|
|
979
|
+
headers: { Accept: "text/event-stream" },
|
|
980
|
+
body: r
|
|
981
|
+
});
|
|
982
|
+
if (!o.ok) {
|
|
983
|
+
let e = await o.json().catch(() => null);
|
|
984
|
+
throw o.status === 403 ? Error("ai_generation_not_available") : Error(e?.message || "Failed to generate template from design");
|
|
985
|
+
}
|
|
986
|
+
let s = o.body?.getReader();
|
|
987
|
+
if (!s) throw Error("Failed to read stream");
|
|
988
|
+
let c = new TextDecoder(), u = "", d = null;
|
|
989
|
+
for (;;) {
|
|
990
|
+
let { done: e, value: t } = await s.read();
|
|
991
|
+
if (e) break;
|
|
992
|
+
u += c.decode(t, { stream: !0 });
|
|
993
|
+
let n = u.split("\n");
|
|
994
|
+
u = n.pop() ?? "";
|
|
995
|
+
for (let e of n) {
|
|
996
|
+
if (!e.startsWith("data: ")) continue;
|
|
997
|
+
let t = e.slice(6), n;
|
|
998
|
+
try {
|
|
999
|
+
n = JSON.parse(t);
|
|
1000
|
+
} catch {
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
if (n.type === "error") throw Error(n.message || "Failed to generate template from design");
|
|
1004
|
+
n.type === "done" && (d = n.content ?? null, d && i?.(d));
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
return d;
|
|
1008
|
+
} catch (e) {
|
|
1009
|
+
let t = e instanceof Error ? e : Error("Failed to generate template from design", { cause: e });
|
|
1010
|
+
return s.value = t.message, a?.(t), null;
|
|
1011
|
+
} finally {
|
|
1012
|
+
o.value = !1;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
function u() {
|
|
1016
|
+
o.value = !1, s.value = null;
|
|
1017
|
+
}
|
|
1018
|
+
return {
|
|
1019
|
+
isGenerating: o,
|
|
1020
|
+
error: s,
|
|
1021
|
+
generate: c,
|
|
1022
|
+
reset: u
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
function O(t) {
|
|
1026
|
+
let { authManager: n, getTemplateId: r, getSocketId: a, onComment: o, onError: s, hasCommentingFeature: c } = t, l = new _(n), u = e([]), d = e(!1), f = e(!1), p = i(() => (c?.() ?? !1) && n.userConfig !== null), m = i(() => {
|
|
1027
|
+
let e = 0;
|
|
1028
|
+
for (let t of u.value) e += 1 + (t.replies?.length ?? 0);
|
|
1029
|
+
return e;
|
|
1030
|
+
}), h = i(() => u.value.filter((e) => !e.resolved_at).length), g = i(() => {
|
|
1031
|
+
let e = /* @__PURE__ */ new Map();
|
|
1032
|
+
for (let t of u.value) t.block_id && e.set(t.block_id, (e.get(t.block_id) ?? 0) + 1 + (t.replies?.length ?? 0));
|
|
1033
|
+
return e;
|
|
1034
|
+
});
|
|
1035
|
+
function v() {
|
|
1036
|
+
let e = n.userConfig;
|
|
1037
|
+
if (!e) throw Error("User config not available");
|
|
1038
|
+
return {
|
|
1039
|
+
user_id: e.id,
|
|
1040
|
+
user_name: e.name,
|
|
1041
|
+
user_signature: e.signature
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
function y() {
|
|
1045
|
+
let e = a?.();
|
|
1046
|
+
if (e) return { "X-Socket-ID": e };
|
|
1047
|
+
}
|
|
1048
|
+
function b(e, t) {
|
|
1049
|
+
o?.({
|
|
1050
|
+
type: e,
|
|
1051
|
+
comment: t
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
function x(e) {
|
|
1055
|
+
for (let t of u.value) {
|
|
1056
|
+
if (t.id === e) return t;
|
|
1057
|
+
for (let n of t.replies ?? []) if (n.id === e) return n;
|
|
1058
|
+
}
|
|
1059
|
+
return null;
|
|
1060
|
+
}
|
|
1061
|
+
async function S() {
|
|
1062
|
+
let e = r();
|
|
1063
|
+
if (e) {
|
|
1064
|
+
d.value = !0;
|
|
1065
|
+
try {
|
|
1066
|
+
u.value = await l.getComments(e);
|
|
1067
|
+
} catch (e) {
|
|
1068
|
+
let t = e instanceof Error ? e : Error("Failed to load comments", { cause: e });
|
|
1069
|
+
s?.(t);
|
|
1070
|
+
} finally {
|
|
1071
|
+
d.value = !1;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
async function C(e, t, n) {
|
|
1076
|
+
let i = r();
|
|
1077
|
+
if (!i) return null;
|
|
1078
|
+
f.value = !0;
|
|
1079
|
+
try {
|
|
1080
|
+
let r = await l.createComment(i, {
|
|
1081
|
+
body: e,
|
|
1082
|
+
block_id: t,
|
|
1083
|
+
parent_id: n,
|
|
1084
|
+
...v()
|
|
1085
|
+
}, y());
|
|
1086
|
+
if (n) {
|
|
1087
|
+
let e = x(n);
|
|
1088
|
+
e && (e.replies = [...e.replies ?? [], r]);
|
|
1089
|
+
} else u.value = [...u.value, r];
|
|
1090
|
+
return b("created", r), r;
|
|
1091
|
+
} catch (e) {
|
|
1092
|
+
let t = e instanceof Error ? e : Error("Failed to create comment", { cause: e });
|
|
1093
|
+
return s?.(t), null;
|
|
1094
|
+
} finally {
|
|
1095
|
+
f.value = !1;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
async function w(e, t) {
|
|
1099
|
+
let n = r();
|
|
1100
|
+
if (!n) return null;
|
|
1101
|
+
f.value = !0;
|
|
1102
|
+
try {
|
|
1103
|
+
let r = await l.updateComment(n, e, {
|
|
1104
|
+
body: t,
|
|
1105
|
+
...v()
|
|
1106
|
+
}, y());
|
|
1107
|
+
return A(e, r), b("updated", r), r;
|
|
1108
|
+
} catch (e) {
|
|
1109
|
+
let t = e instanceof Error ? e : Error("Failed to update comment", { cause: e });
|
|
1110
|
+
return s?.(t), null;
|
|
1111
|
+
} finally {
|
|
1112
|
+
f.value = !1;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
async function T(e) {
|
|
1116
|
+
let t = r();
|
|
1117
|
+
if (!t) return !1;
|
|
1118
|
+
let n = x(e);
|
|
1119
|
+
if (!n) return !1;
|
|
1120
|
+
let i = {
|
|
1121
|
+
...n,
|
|
1122
|
+
replies: [...n.replies ?? []]
|
|
1123
|
+
};
|
|
1124
|
+
f.value = !0;
|
|
1125
|
+
try {
|
|
1126
|
+
if (await l.deleteComment(t, e, v(), y()), n.parent_id) {
|
|
1127
|
+
let t = x(n.parent_id);
|
|
1128
|
+
t && (t.replies = (t.replies ?? []).filter((t) => t.id !== e));
|
|
1129
|
+
} else u.value = u.value.filter((t) => t.id !== e);
|
|
1130
|
+
return b("deleted", i), !0;
|
|
1131
|
+
} catch (e) {
|
|
1132
|
+
let t = e instanceof Error ? e : Error("Failed to delete comment", { cause: e });
|
|
1133
|
+
return s?.(t), !1;
|
|
1134
|
+
} finally {
|
|
1135
|
+
f.value = !1;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
async function E(e) {
|
|
1139
|
+
let t = r();
|
|
1140
|
+
if (!t) return null;
|
|
1141
|
+
f.value = !0;
|
|
1142
|
+
try {
|
|
1143
|
+
let n = await l.resolveComment(t, e, v(), y());
|
|
1144
|
+
return A(e, n), b(n.resolved_at ? "resolved" : "unresolved", n), n;
|
|
1145
|
+
} catch (e) {
|
|
1146
|
+
let t = e instanceof Error ? e : Error("Failed to toggle comment resolution", { cause: e });
|
|
1147
|
+
return s?.(t), null;
|
|
1148
|
+
} finally {
|
|
1149
|
+
f.value = !1;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
function D(e) {
|
|
1153
|
+
if (e.parent_id) {
|
|
1154
|
+
let t = x(e.parent_id);
|
|
1155
|
+
t && (t.replies = [...t.replies ?? [], e]);
|
|
1156
|
+
} else u.value = [...u.value, e];
|
|
1157
|
+
b("created", e);
|
|
1158
|
+
}
|
|
1159
|
+
function O(e) {
|
|
1160
|
+
A(e.id, e), b("updated", e);
|
|
1161
|
+
}
|
|
1162
|
+
function k(e, t) {
|
|
1163
|
+
let n = x(e), r = n ? {
|
|
1164
|
+
...n,
|
|
1165
|
+
replies: [...n.replies ?? []]
|
|
1166
|
+
} : null;
|
|
1167
|
+
if (t) {
|
|
1168
|
+
let n = x(t);
|
|
1169
|
+
n && (n.replies = (n.replies ?? []).filter((t) => t.id !== e));
|
|
1170
|
+
} else u.value = u.value.filter((t) => t.id !== e);
|
|
1171
|
+
r && b("deleted", r);
|
|
1172
|
+
}
|
|
1173
|
+
function A(e, t) {
|
|
1174
|
+
for (let n = 0; n < u.value.length; n++) {
|
|
1175
|
+
if (u.value[n].id === e) {
|
|
1176
|
+
u.value = [
|
|
1177
|
+
...u.value.slice(0, n),
|
|
1178
|
+
{
|
|
1179
|
+
...t,
|
|
1180
|
+
replies: u.value[n].replies
|
|
1181
|
+
},
|
|
1182
|
+
...u.value.slice(n + 1)
|
|
1183
|
+
];
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
let r = u.value[n].replies ?? [];
|
|
1187
|
+
for (let i = 0; i < r.length; i++) if (r[i].id === e) {
|
|
1188
|
+
let e = [
|
|
1189
|
+
...r.slice(0, i),
|
|
1190
|
+
t,
|
|
1191
|
+
...r.slice(i + 1)
|
|
1192
|
+
];
|
|
1193
|
+
u.value = [
|
|
1194
|
+
...u.value.slice(0, n),
|
|
1195
|
+
{
|
|
1196
|
+
...u.value[n],
|
|
1197
|
+
replies: e
|
|
1198
|
+
},
|
|
1199
|
+
...u.value.slice(n + 1)
|
|
1200
|
+
];
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
return {
|
|
1206
|
+
comments: u,
|
|
1207
|
+
isLoading: d,
|
|
1208
|
+
isSubmitting: f,
|
|
1209
|
+
isEnabled: p,
|
|
1210
|
+
commentCountByBlock: g,
|
|
1211
|
+
totalCount: m,
|
|
1212
|
+
unresolvedCount: h,
|
|
1213
|
+
loadComments: S,
|
|
1214
|
+
addComment: C,
|
|
1215
|
+
editComment: w,
|
|
1216
|
+
removeComment: T,
|
|
1217
|
+
toggleResolve: E,
|
|
1218
|
+
applyRemoteCreate: D,
|
|
1219
|
+
applyRemoteUpdate: O,
|
|
1220
|
+
applyRemoteDelete: k
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
function k(e) {
|
|
1224
|
+
let { comments: t, channel: r } = e;
|
|
1225
|
+
a(r, (e, n) => {
|
|
1226
|
+
n && n.unbind("comment-broadcast"), e && e.bind("comment-broadcast", (e) => {
|
|
1227
|
+
A(t, e);
|
|
1228
|
+
});
|
|
1229
|
+
}), n(() => {
|
|
1230
|
+
r.value?.unbind("comment-broadcast");
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
function A(e, t) {
|
|
1234
|
+
switch (t.action) {
|
|
1235
|
+
case "comment_created":
|
|
1236
|
+
e.applyRemoteCreate(t.comment);
|
|
1237
|
+
break;
|
|
1238
|
+
case "comment_updated":
|
|
1239
|
+
e.applyRemoteUpdate(t.comment);
|
|
1240
|
+
break;
|
|
1241
|
+
case "comment_deleted":
|
|
1242
|
+
e.applyRemoteDelete(t.comment.id, t.comment.parent_id);
|
|
1243
|
+
break;
|
|
1244
|
+
case "comment_resolved":
|
|
1245
|
+
case "comment_unresolved":
|
|
1246
|
+
e.applyRemoteUpdate(t.comment);
|
|
1247
|
+
break;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
var j = [
|
|
1251
|
+
"pusher:member_added",
|
|
1252
|
+
"pusher:member_removed",
|
|
1253
|
+
"client-block_locked",
|
|
1254
|
+
"client-block_unlocked",
|
|
1255
|
+
"client-operation",
|
|
1256
|
+
"mcp-operation"
|
|
1257
|
+
];
|
|
1258
|
+
function M(e) {
|
|
1259
|
+
for (let t of j) e.unbind(t);
|
|
1260
|
+
}
|
|
1261
|
+
var N = [
|
|
1262
|
+
"#3b82f6",
|
|
1263
|
+
"#ef4444",
|
|
1264
|
+
"#10b981",
|
|
1265
|
+
"#f59e0b",
|
|
1266
|
+
"#8b5cf6",
|
|
1267
|
+
"#ec4899",
|
|
1268
|
+
"#06b6d4",
|
|
1269
|
+
"#f97316",
|
|
1270
|
+
"#6366f1",
|
|
1271
|
+
"#14b8a6"
|
|
1272
|
+
];
|
|
1273
|
+
function P(t) {
|
|
1274
|
+
let { authManager: r, editor: o, channel: s } = t, c = e([]), l = e(/* @__PURE__ */ new Map()), u = 0, d = !1, f = i(() => r.userConfig?.id ?? "");
|
|
1275
|
+
function p() {
|
|
1276
|
+
let e = N[u % N.length];
|
|
1277
|
+
return u++, e;
|
|
1278
|
+
}
|
|
1279
|
+
function m(e) {
|
|
1280
|
+
if (e.id === f.value || c.value.some((t) => t.id === e.id)) return;
|
|
1281
|
+
let t = {
|
|
1282
|
+
id: e.id,
|
|
1283
|
+
name: e.name,
|
|
1284
|
+
color: p(),
|
|
1285
|
+
selectedBlockId: null
|
|
1286
|
+
};
|
|
1287
|
+
return c.value = [...c.value, t], t;
|
|
1288
|
+
}
|
|
1289
|
+
function h(e) {
|
|
1290
|
+
let t = new Map(l.value);
|
|
1291
|
+
for (let [n, r] of t) r.id === e && t.delete(n);
|
|
1292
|
+
l.value = t, c.value = c.value.filter((t) => t.id !== e);
|
|
1293
|
+
}
|
|
1294
|
+
function g(e) {
|
|
1295
|
+
let t = c.value.find((t) => t.id === e.userId);
|
|
1296
|
+
if (!t) return;
|
|
1297
|
+
c.value = c.value.map((t) => t.id === e.userId ? {
|
|
1298
|
+
...t,
|
|
1299
|
+
selectedBlockId: e.blockId
|
|
1300
|
+
} : t);
|
|
1301
|
+
let n = new Map(l.value);
|
|
1302
|
+
for (let [t, r] of n) r.id === e.userId && n.delete(t);
|
|
1303
|
+
n.set(e.blockId, {
|
|
1304
|
+
...t,
|
|
1305
|
+
selectedBlockId: e.blockId
|
|
1306
|
+
}), l.value = n, o.state.selectedBlockId === e.blockId && o.selectBlock(null);
|
|
1307
|
+
}
|
|
1308
|
+
function _(e) {
|
|
1309
|
+
let t = new Map(l.value), n = t.get(e.blockId);
|
|
1310
|
+
t.delete(e.blockId), l.value = t, n && (c.value = c.value.map((e) => e.id === n.id ? {
|
|
1311
|
+
...e,
|
|
1312
|
+
selectedBlockId: null
|
|
1313
|
+
} : e));
|
|
1314
|
+
}
|
|
1315
|
+
function v(e) {
|
|
1316
|
+
d = !0;
|
|
1317
|
+
try {
|
|
1318
|
+
b(o, e);
|
|
1319
|
+
} finally {
|
|
1320
|
+
d = !1;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
function y(e) {
|
|
1324
|
+
!s.value || d || s.value.trigger("client-operation", e);
|
|
1325
|
+
}
|
|
1326
|
+
function x(e) {
|
|
1327
|
+
s.value && s.value.trigger("client-block_locked", {
|
|
1328
|
+
blockId: e,
|
|
1329
|
+
userId: f.value
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
function S(e) {
|
|
1333
|
+
s.value && s.value.trigger("client-block_unlocked", { blockId: e });
|
|
1334
|
+
}
|
|
1335
|
+
return a(() => o.state.selectedBlockId, (e, t) => {
|
|
1336
|
+
d || (t && S(t), e && x(e));
|
|
1337
|
+
}), a(s, (e, n) => {
|
|
1338
|
+
if (n && M(n), !e) {
|
|
1339
|
+
c.value = [], l.value = /* @__PURE__ */ new Map(), u = 0;
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
let r = e.members;
|
|
1343
|
+
r && r.each((e) => {
|
|
1344
|
+
m(e.info);
|
|
1345
|
+
}), e.bind("pusher:member_added", (e) => {
|
|
1346
|
+
let n = m(e.info);
|
|
1347
|
+
n && t.onCollaboratorJoined?.(n);
|
|
1348
|
+
}), e.bind("pusher:member_removed", (e) => {
|
|
1349
|
+
let n = c.value.find((t) => t.id === e.id);
|
|
1350
|
+
h(e.id), n && t.onCollaboratorLeft?.(n);
|
|
1351
|
+
}), e.bind("client-block_locked", (e) => {
|
|
1352
|
+
g(e);
|
|
1353
|
+
let n = c.value.find((t) => t.id === e.userId);
|
|
1354
|
+
n && t.onBlockLocked?.({
|
|
1355
|
+
blockId: e.blockId,
|
|
1356
|
+
collaborator: n
|
|
1357
|
+
});
|
|
1358
|
+
}), e.bind("client-block_unlocked", (e) => {
|
|
1359
|
+
let n = l.value.get(e.blockId);
|
|
1360
|
+
_(e), n && t.onBlockUnlocked?.({
|
|
1361
|
+
blockId: e.blockId,
|
|
1362
|
+
collaborator: n
|
|
1363
|
+
});
|
|
1364
|
+
}), e.bind("client-operation", (e) => {
|
|
1365
|
+
v(e);
|
|
1366
|
+
}), e.bind("mcp-operation", (e) => {
|
|
1367
|
+
v(e);
|
|
1368
|
+
});
|
|
1369
|
+
}), n(() => {
|
|
1370
|
+
s.value && M(s.value);
|
|
1371
|
+
}), {
|
|
1372
|
+
collaborators: c,
|
|
1373
|
+
lockedBlocks: l,
|
|
1374
|
+
_broadcastOperation: y,
|
|
1375
|
+
_isProcessingRemoteOperation: () => d
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
function F(e, t) {
|
|
1379
|
+
let n = e.addBlock, r = e.updateBlock, i = e.removeBlock, a = e.moveBlock, o = e.updateSettings, s = e.setContent;
|
|
1380
|
+
e.addBlock = (e, r, i) => {
|
|
1381
|
+
n(e, r, i), t._broadcastOperation({
|
|
1382
|
+
operation: "add_block",
|
|
1383
|
+
data: {
|
|
1384
|
+
block: e,
|
|
1385
|
+
section_id: r,
|
|
1386
|
+
column_index: i
|
|
1387
|
+
},
|
|
1388
|
+
timestamp: Date.now()
|
|
1389
|
+
});
|
|
1390
|
+
}, e.updateBlock = (e, n) => {
|
|
1391
|
+
r(e, n), t._broadcastOperation({
|
|
1392
|
+
operation: "update_block",
|
|
1393
|
+
data: {
|
|
1394
|
+
block_id: e,
|
|
1395
|
+
updates: n
|
|
1396
|
+
},
|
|
1397
|
+
timestamp: Date.now()
|
|
1398
|
+
});
|
|
1399
|
+
}, e.removeBlock = (e) => {
|
|
1400
|
+
i(e), t._broadcastOperation({
|
|
1401
|
+
operation: "delete_block",
|
|
1402
|
+
data: { block_id: e },
|
|
1403
|
+
timestamp: Date.now()
|
|
1404
|
+
});
|
|
1405
|
+
}, e.moveBlock = (e, n, r, i) => {
|
|
1406
|
+
a(e, n, r, i), t._broadcastOperation({
|
|
1407
|
+
operation: "move_block",
|
|
1408
|
+
data: {
|
|
1409
|
+
block_id: e,
|
|
1410
|
+
index: n,
|
|
1411
|
+
section_id: r,
|
|
1412
|
+
column_index: i
|
|
1413
|
+
},
|
|
1414
|
+
timestamp: Date.now()
|
|
1415
|
+
});
|
|
1416
|
+
}, e.updateSettings = (e) => {
|
|
1417
|
+
o(e), t._broadcastOperation({
|
|
1418
|
+
operation: "update_settings",
|
|
1419
|
+
data: { updates: e },
|
|
1420
|
+
timestamp: Date.now()
|
|
1421
|
+
});
|
|
1422
|
+
}, e.setContent = (e, n) => {
|
|
1423
|
+
s(e, n), t._broadcastOperation({
|
|
1424
|
+
operation: "set_content",
|
|
1425
|
+
data: { content: e },
|
|
1426
|
+
timestamp: Date.now()
|
|
1427
|
+
});
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
function I(t) {
|
|
1431
|
+
let { authManager: n, onError: r } = t, i = e(null), a = e(!1), o = null, s = null;
|
|
1432
|
+
async function c(e, t) {
|
|
1433
|
+
if (o) return;
|
|
1434
|
+
o = new y({
|
|
1435
|
+
authManager: n,
|
|
1436
|
+
config: t,
|
|
1437
|
+
onError: r
|
|
1438
|
+
}), await o.connect(), s = `presence-template.${e}`;
|
|
1439
|
+
let c = o.subscribePresence(s);
|
|
1440
|
+
c.bind("pusher:subscription_succeeded", () => {
|
|
1441
|
+
a.value = !0, i.value = c;
|
|
1442
|
+
}), c.bind("pusher:subscription_error", (e) => {
|
|
1443
|
+
a.value = !1, i.value = null, r?.(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to subscribe to template channel"));
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
function l() {
|
|
1447
|
+
s && o && o.unsubscribe(s), o?.disconnect(), o = null, s = null, i.value = null, a.value = !1;
|
|
1448
|
+
}
|
|
1449
|
+
function u() {
|
|
1450
|
+
return o?.getSocketId() ?? null;
|
|
1451
|
+
}
|
|
1452
|
+
return {
|
|
1453
|
+
channel: i,
|
|
1454
|
+
isConnected: a,
|
|
1455
|
+
connect: c,
|
|
1456
|
+
disconnect: l,
|
|
1457
|
+
getSocketId: u
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
function L(t) {
|
|
1461
|
+
let n = new _(t.authManager), r = e([]), i = e(!1);
|
|
1462
|
+
async function a(e) {
|
|
1463
|
+
i.value = !0;
|
|
1464
|
+
try {
|
|
1465
|
+
r.value = await n.listModules(e);
|
|
1466
|
+
} catch (e) {
|
|
1467
|
+
throw t.onError?.(e), e;
|
|
1468
|
+
} finally {
|
|
1469
|
+
i.value = !1;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
async function o(e, i) {
|
|
1473
|
+
try {
|
|
1474
|
+
let t = await n.createModule({
|
|
1475
|
+
name: e,
|
|
1476
|
+
content: i
|
|
1477
|
+
});
|
|
1478
|
+
return r.value = [t, ...r.value], t;
|
|
1479
|
+
} catch (e) {
|
|
1480
|
+
throw t.onError?.(e), e;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
async function s(e, i) {
|
|
1484
|
+
try {
|
|
1485
|
+
let t = await n.updateModule(e, i);
|
|
1486
|
+
return r.value = r.value.map((n) => n.id === e ? t : n), t;
|
|
1487
|
+
} catch (e) {
|
|
1488
|
+
throw t.onError?.(e), e;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
async function c(e) {
|
|
1492
|
+
try {
|
|
1493
|
+
await n.deleteModule(e), r.value = r.value.filter((t) => t.id !== e);
|
|
1494
|
+
} catch (e) {
|
|
1495
|
+
throw t.onError?.(e), e;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return {
|
|
1499
|
+
modules: r,
|
|
1500
|
+
isLoading: i,
|
|
1501
|
+
loadModules: a,
|
|
1502
|
+
createModule: o,
|
|
1503
|
+
updateModule: s,
|
|
1504
|
+
deleteModule: c
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
function R(t) {
|
|
1508
|
+
let n = new _(t.authManager), r = e([]), i = e(!1), a = e(!1);
|
|
1509
|
+
async function o() {
|
|
1510
|
+
i.value = !0;
|
|
1511
|
+
try {
|
|
1512
|
+
r.value = await n.getSnapshots(t.templateId);
|
|
1513
|
+
} catch (e) {
|
|
1514
|
+
throw t.onError?.(e), e;
|
|
1515
|
+
} finally {
|
|
1516
|
+
i.value = !1;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
async function s(e) {
|
|
1520
|
+
a.value = !0;
|
|
1521
|
+
try {
|
|
1522
|
+
let r = await n.restoreSnapshot(t.templateId, e);
|
|
1523
|
+
return t.onRestore?.(r), r;
|
|
1524
|
+
} catch (e) {
|
|
1525
|
+
throw t.onError?.(e), e;
|
|
1526
|
+
} finally {
|
|
1527
|
+
a.value = !1;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
return {
|
|
1531
|
+
snapshots: r,
|
|
1532
|
+
isLoading: i,
|
|
1533
|
+
isRestoring: a,
|
|
1534
|
+
loadSnapshots: o,
|
|
1535
|
+
restoreSnapshot: s
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
function z(t) {
|
|
1539
|
+
let { authManager: n, getTemplateId: r, save: o, exportHtml: s, onError: c, isAuthReady: l, onBeforeTestEmail: u } = t, d = new _(n), f = e(!1), p = e(null), m = e(null);
|
|
1540
|
+
l && a(l, (e) => {
|
|
1541
|
+
e && (m.value = n.testEmailConfig);
|
|
1542
|
+
}, { immediate: !0 });
|
|
1543
|
+
let h = i(() => m.value !== null), g = i(() => m.value?.allowedEmails ?? []);
|
|
1544
|
+
async function v(e) {
|
|
1545
|
+
if (!m.value) throw Error("Test email is not enabled for this project");
|
|
1546
|
+
let t = r();
|
|
1547
|
+
if (!t) throw Error("Template must be saved before sending a test email");
|
|
1548
|
+
f.value = !0, p.value = null;
|
|
1549
|
+
try {
|
|
1550
|
+
await o();
|
|
1551
|
+
let { html: n } = await s(t);
|
|
1552
|
+
u && (n = await u(n)), await d.sendTestEmail(t, {
|
|
1553
|
+
recipient: e,
|
|
1554
|
+
html: n,
|
|
1555
|
+
allowed_emails: m.value.allowedEmails,
|
|
1556
|
+
signature: m.value.signature
|
|
1557
|
+
});
|
|
1558
|
+
} catch (e) {
|
|
1559
|
+
let t = e instanceof Error ? e : Error("Failed to send test email", { cause: e });
|
|
1560
|
+
throw p.value = t.message, c?.(t), t;
|
|
1561
|
+
} finally {
|
|
1562
|
+
f.value = !1;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
return {
|
|
1566
|
+
isEnabled: h,
|
|
1567
|
+
allowedEmails: g,
|
|
1568
|
+
isSending: f,
|
|
1569
|
+
error: p,
|
|
1570
|
+
sendTestEmail: v
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
function B(e) {
|
|
1574
|
+
let { authManager: t, getFontsConfig: n, canUseCustomFonts: r } = e, i = new _(t);
|
|
1575
|
+
function a() {
|
|
1576
|
+
let e = n?.();
|
|
1577
|
+
return {
|
|
1578
|
+
customFonts: (r?.() ?? !0) && e?.customFonts ? e.customFonts : [],
|
|
1579
|
+
defaultFallback: e?.defaultFallback ?? "Arial, sans-serif"
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
async function o(e) {
|
|
1583
|
+
let t = a(), n = await i.exportTemplate(e, t);
|
|
1584
|
+
return {
|
|
1585
|
+
html: n.html,
|
|
1586
|
+
mjml: n.mjml
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
async function s(e) {
|
|
1590
|
+
let t = a();
|
|
1591
|
+
return (await i.exportTemplate(e, t)).mjml;
|
|
1592
|
+
}
|
|
1593
|
+
return {
|
|
1594
|
+
exportHtml: o,
|
|
1595
|
+
getMjmlSource: s
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
function V(t) {
|
|
1599
|
+
let { authManager: n, onError: r } = t, a = e(null), o = e(!1), s = new _(n), c = i(() => a.value?.features ?? null);
|
|
1600
|
+
function l(e) {
|
|
1601
|
+
return a.value?.features[e] ?? !1;
|
|
1602
|
+
}
|
|
1603
|
+
async function u() {
|
|
1604
|
+
if (!o.value) {
|
|
1605
|
+
o.value = !0;
|
|
1606
|
+
try {
|
|
1607
|
+
a.value = await s.fetchConfig();
|
|
1608
|
+
} catch (e) {
|
|
1609
|
+
r?.(e instanceof Error ? e : Error("Failed to fetch config", { cause: e }));
|
|
1610
|
+
} finally {
|
|
1611
|
+
o.value = !1;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
return {
|
|
1616
|
+
config: a,
|
|
1617
|
+
isLoading: o,
|
|
1618
|
+
hasFeature: l,
|
|
1619
|
+
features: c,
|
|
1620
|
+
fetchConfig: u
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
var H = 5e3;
|
|
1624
|
+
function U(e) {
|
|
1625
|
+
return e.authManager ? e.authManager.resolveUrl(g.health) : `${(e.baseUrl ?? "https://templatical.com").replace(/\/$/, "")}${g.health}`;
|
|
1626
|
+
}
|
|
1627
|
+
async function W(e, t) {
|
|
1628
|
+
let n = performance.now();
|
|
1629
|
+
try {
|
|
1630
|
+
let r = t ? await t.authenticatedFetch(g.health, {
|
|
1631
|
+
method: "GET",
|
|
1632
|
+
headers: { Accept: "application/json" }
|
|
1633
|
+
}) : await fetch(e, {
|
|
1634
|
+
method: "GET",
|
|
1635
|
+
headers: { Accept: "application/json" }
|
|
1636
|
+
}), i = Math.round(performance.now() - n);
|
|
1637
|
+
if (r.status === 401) return {
|
|
1638
|
+
api: {
|
|
1639
|
+
ok: !0,
|
|
1640
|
+
latency: i
|
|
1641
|
+
},
|
|
1642
|
+
auth: {
|
|
1643
|
+
ok: !1,
|
|
1644
|
+
error: "HTTP 401"
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
if (!r.ok) return {
|
|
1648
|
+
api: {
|
|
1649
|
+
ok: !1,
|
|
1650
|
+
latency: i
|
|
1651
|
+
},
|
|
1652
|
+
auth: {
|
|
1653
|
+
ok: !t,
|
|
1654
|
+
error: t ? `HTTP ${r.status}` : void 0
|
|
1655
|
+
}
|
|
1656
|
+
};
|
|
1657
|
+
let a = await r.json();
|
|
1658
|
+
return {
|
|
1659
|
+
api: {
|
|
1660
|
+
ok: a.status === "ok",
|
|
1661
|
+
latency: i
|
|
1662
|
+
},
|
|
1663
|
+
auth: { ok: !0 },
|
|
1664
|
+
wsConfig: a.websocket
|
|
1665
|
+
};
|
|
1666
|
+
} catch (e) {
|
|
1667
|
+
return {
|
|
1668
|
+
api: {
|
|
1669
|
+
ok: !1,
|
|
1670
|
+
latency: Math.round(performance.now() - n)
|
|
1671
|
+
},
|
|
1672
|
+
auth: {
|
|
1673
|
+
ok: !t,
|
|
1674
|
+
error: t ? e instanceof Error ? e.message : "Authentication check failed" : void 0
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
async function G(e) {
|
|
1680
|
+
if (!e?.host || !e?.app_key) return {
|
|
1681
|
+
ok: !1,
|
|
1682
|
+
error: "WebSocket configuration not available"
|
|
1683
|
+
};
|
|
1684
|
+
if (typeof WebSocket > "u") return {
|
|
1685
|
+
ok: !1,
|
|
1686
|
+
error: "WebSocket not supported in this environment"
|
|
1687
|
+
};
|
|
1688
|
+
let t = `${e.port === 443 ? "wss" : "ws"}://${e.host}:${e.port}/app/${e.app_key}?protocol=7&client=js&version=8.4.0-rc2&flash=false`;
|
|
1689
|
+
return new Promise((e) => {
|
|
1690
|
+
let n = null, r = setTimeout(() => {
|
|
1691
|
+
n?.close(), e({
|
|
1692
|
+
ok: !1,
|
|
1693
|
+
error: "WebSocket connection timed out"
|
|
1694
|
+
});
|
|
1695
|
+
}, H);
|
|
1696
|
+
try {
|
|
1697
|
+
n = new WebSocket(t);
|
|
1698
|
+
} catch (t) {
|
|
1699
|
+
clearTimeout(r), e({
|
|
1700
|
+
ok: !1,
|
|
1701
|
+
error: t instanceof Error ? t.message : "WebSocket connection failed"
|
|
1702
|
+
});
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1705
|
+
n.onopen = () => {
|
|
1706
|
+
clearTimeout(r), n?.close(), e({ ok: !0 });
|
|
1707
|
+
}, n.onerror = () => {
|
|
1708
|
+
clearTimeout(r), e({
|
|
1709
|
+
ok: !1,
|
|
1710
|
+
error: "WebSocket connection failed"
|
|
1711
|
+
});
|
|
1712
|
+
};
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
async function K(e = {}) {
|
|
1716
|
+
let t = await W(U(e), e.authManager), n = await G(t.wsConfig);
|
|
1717
|
+
return {
|
|
1718
|
+
api: t.api,
|
|
1719
|
+
websocket: n,
|
|
1720
|
+
auth: t.auth,
|
|
1721
|
+
overall: t.api.ok && t.auth.ok
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
function q(e) {
|
|
1725
|
+
let { editor: t, channel: n, onOperation: r } = e;
|
|
1726
|
+
a(n, (e, n) => {
|
|
1727
|
+
n && n.unbind("mcp-operation"), e && e.bind("mcp-operation", (e) => {
|
|
1728
|
+
b(t, e), r?.(e);
|
|
1729
|
+
});
|
|
1730
|
+
});
|
|
1731
|
+
}
|
|
1732
|
+
//#endregion
|
|
1733
|
+
export { E as _, T as a, k as c, x as d, B as f, R as g, L as h, w as i, O as l, V as m, K as n, P as o, q as p, v as r, F as s, c as t, D as u, z as v, I as y };
|