@enerex/template-studio 1.1.39 → 1.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +3 -1
  2. package/dist/enerex-template-editor.es.js +1492 -916
  3. package/dist/enerex-template-editor.umd.js +13 -13
  4. package/dist/template-studio.css +1 -1
  5. package/dist/types/component/TemplateList/index.d.ts +20 -0
  6. package/dist/types/component/TemplateList/pagination/pagination.d.ts +10 -0
  7. package/dist/types/component/TemplateList/template-row.d.ts +15 -0
  8. package/dist/types/component/editor-widget-content/index.d.ts +2 -0
  9. package/dist/types/component/editormodal/index.d.ts +18 -0
  10. package/dist/types/component/form-input/select.d.ts +10 -3
  11. package/dist/types/component/form-input/textbox.d.ts +1 -0
  12. package/dist/types/component/icons/serach-icon.d.ts +2 -0
  13. package/dist/types/component/loader/index.d.ts +8 -0
  14. package/dist/types/component/modal/index.d.ts +1 -2
  15. package/dist/types/component/notification/notification.d.ts +10 -0
  16. package/dist/types/component/template-form/index.d.ts +9 -3
  17. package/dist/types/component/template-form/index1.d.ts +11 -0
  18. package/dist/types/context/notification-provider.d.ts +8 -0
  19. package/dist/types/hook/useNotification.d.ts +5 -0
  20. package/dist/types/hook/usePagination.d.ts +11 -0
  21. package/dist/types/queries/delete_template.mutation.d.ts +1 -0
  22. package/dist/types/queries/duplicate_template.mutation.d.ts +6 -0
  23. package/dist/types/queries/endpoints.d.ts +3 -0
  24. package/dist/types/queries/get_template_list_all.query.d.ts +2 -0
  25. package/dist/types/queries/types.d.ts +11 -0
  26. package/dist/types/service/api-client.d.ts +2 -0
  27. package/dist/types/type/application-type.d.ts +2 -0
  28. package/package.json +1 -1
@@ -1,11 +1,925 @@
1
- import { jsx as n, jsxs as S, Fragment as Ee } from "react/jsx-runtime";
2
- import M, { useContext as qe, useState as w, useRef as st, useEffect as E } from "react";
3
- import { QueryClient as it, QueryClientProvider as at, useQuery as ce, useMutation as Te, useQueryClient as lt } from "@tanstack/react-query";
4
- import _e from "axios";
5
- import { Spinner as z, Form as H, Card as ke, Row as ot, Col as U, Button as J } from "react-bootstrap";
6
- import { Controller as dt, useForm as ct } from "react-hook-form";
7
- import Ae, { components as Le } from "react-select";
8
- const de = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
1
+ import { jsx as t, jsxs as c, Fragment as fe } from "react/jsx-runtime";
2
+ import W, { useContext as Se, useEffect as L, useState as N, useRef as J, useCallback as xe, createContext as je, memo as qe, useMemo as re } from "react";
3
+ import { QueryClient as Ue, QueryClientProvider as Ve, useQuery as he, useMutation as oe, useQueryClient as He } from "@tanstack/react-query";
4
+ import be from "axios";
5
+ import { Spinner as Ke } from "react-bootstrap";
6
+ import { Controller as Ge, useForm as We } from "react-hook-form";
7
+ import Le, { components as Pe } from "react-select";
8
+ const Me = W.createContext(
9
+ void 0
10
+ ), ze = ({
11
+ children: e,
12
+ configs: n
13
+ }) => {
14
+ const [s, a] = W.useState(n.clientId), [i, r] = W.useState(n.apiKey), [l, o] = W.useState(
15
+ n.enerexIdentifier
16
+ ), [d, y] = W.useState(n.projectId), [m, T] = W.useState(n.userEmail), [w, E] = W.useState(n.isAdmin), [A, h] = W.useState(n.meBaseUrl), [g, b] = W.useState(
17
+ n.defaultSelector
18
+ ), p = (v) => {
19
+ r(v.apiKey), a(v.clientId), y(v.projectId), o(v.enerexIdentifier), T(v.userEmail), E(v.isAdmin), b(v.defaultSelector), h(v.meBaseUrl);
20
+ };
21
+ return /* @__PURE__ */ t(
22
+ Me.Provider,
23
+ {
24
+ value: {
25
+ clientId: s,
26
+ apiKey: i,
27
+ setConfiguration: p,
28
+ enerexIdentifier: l,
29
+ projectId: d,
30
+ userEmail: m,
31
+ isAdmin: w,
32
+ defaultSelector: g,
33
+ meBaseUrl: A
34
+ },
35
+ children: e
36
+ }
37
+ );
38
+ }, q = () => {
39
+ const e = Se(Me);
40
+ if (!e)
41
+ throw new Error("widgetConfig must be used within a ConfigProvider");
42
+ return e;
43
+ }, Qe = ({
44
+ message: e,
45
+ type: n = "info",
46
+ duration: s = 3e3,
47
+ onClose: a
48
+ }) => (L(() => {
49
+ const i = setTimeout(a, s);
50
+ return () => clearTimeout(i);
51
+ }, [s, a]), /* @__PURE__ */ c("div", { className: `ts-toast ts-toast-${n}`, children: [
52
+ /* @__PURE__ */ t("span", { className: "ts-toast-message", children: e }),
53
+ /* @__PURE__ */ t("button", { className: "ts-toast-close", onClick: a, children: "×" })
54
+ ] })), Xe = () => {
55
+ const [e, n] = N(null), s = J(null);
56
+ return { showNotification: xe(
57
+ (r, l = "info") => {
58
+ s.current !== r && (s.current = r, n({ message: r, type: l }));
59
+ },
60
+ []
61
+ ), NotificationRenderer: () => e ? /* @__PURE__ */ t(
62
+ Qe,
63
+ {
64
+ message: e.message,
65
+ type: e.type,
66
+ onClose: () => {
67
+ s.current = null, n(null);
68
+ }
69
+ }
70
+ ) : null };
71
+ }, Re = je(null), Ye = ({
72
+ children: e
73
+ }) => {
74
+ const n = Xe();
75
+ return /* @__PURE__ */ c(Re.Provider, { value: n, children: [
76
+ e,
77
+ /* @__PURE__ */ t(n.NotificationRenderer, {})
78
+ ] });
79
+ }, ke = () => {
80
+ const e = Se(Re);
81
+ if (!e)
82
+ throw new Error(
83
+ "useGlobalNotification must be used within NotificationProvider"
84
+ );
85
+ return e;
86
+ }, Oe = (e = "", n) => ({ get: async (r, l) => {
87
+ try {
88
+ const o = await be.get(
89
+ `${e}${r}`,
90
+ l ?? n
91
+ );
92
+ if (o.status === 200)
93
+ return o.data;
94
+ } catch (o) {
95
+ throw o;
96
+ }
97
+ }, post: async (r, l, o) => {
98
+ try {
99
+ const d = await be.post(
100
+ `${e}${r}`,
101
+ l,
102
+ o ?? n
103
+ );
104
+ if (d.status === 200)
105
+ return d.data;
106
+ } catch (d) {
107
+ throw d;
108
+ }
109
+ }, delete: async (r, l) => {
110
+ try {
111
+ const o = await be.delete(
112
+ `${e}${r}`,
113
+ l ?? n
114
+ );
115
+ if (o.status === 200 || o.status === 204)
116
+ return o.data;
117
+ } catch (o) {
118
+ throw o;
119
+ }
120
+ } }), Be = W.createContext({
121
+ get: () => {
122
+ throw new Error("HttpClientContext.get not implemented");
123
+ },
124
+ post: () => {
125
+ throw new Error("HttpClientContext.post not implemented");
126
+ },
127
+ delete: () => {
128
+ throw new Error("HttpClientContext.delete not implemented");
129
+ }
130
+ }), Je = ({ children: e }) => {
131
+ const { clientId: n, apiKey: s, isAdmin: a, meBaseUrl: i } = q(), r = {
132
+ headers: {
133
+ client_id: n,
134
+ "x-api-key": s,
135
+ "Security-Context": a ? "admin" : "viewer"
136
+ }
137
+ }, { get: l, post: o, delete: d } = Oe(i, r);
138
+ return /* @__PURE__ */ t(Be.Provider, { value: { get: l, post: o, delete: d }, children: e });
139
+ }, Ze = ({ children: e }) => {
140
+ const n = new Ue();
141
+ return /* @__PURE__ */ t(Je, { children: /* @__PURE__ */ t(Ve, { client: n, children: e }) });
142
+ }, z = () => {
143
+ const e = Se(Be);
144
+ if (e)
145
+ return e;
146
+ throw new Error("useHttpClient must be used within a HttpClientProvider");
147
+ }, Q = {
148
+ Template_list: "/Template/list/",
149
+ Template: "/Template/GetTemplate/",
150
+ MergeTags: "/Template/TemplateMergeTags/",
151
+ ExcludeCategory: "/Template/GetExcludeCategories/",
152
+ SaveTemplate: "/Template/save-update/",
153
+ TemplateTypes: "/Template/TemplateTypes/",
154
+ markFavourite: "/Template/MarkFavourite/",
155
+ deleteTemplate: "/Template/DeleteTemplate/",
156
+ duplicateTemplate: "/Template/DuplicateTemplate/"
157
+ }, et = () => {
158
+ const e = z(), { enerexIdentifier: n, projectId: s } = q();
159
+ return he({
160
+ queryKey: ["getTemplatesList"],
161
+ queryFn: async (i) => await e.get(
162
+ `${Q.Template_list}${s}/${n}`
163
+ ),
164
+ refetchOnWindowFocus: !1,
165
+ refetchOnReconnect: !1,
166
+ refetchOnMount: !1
167
+ });
168
+ }, tt = () => {
169
+ const e = z(), { enerexIdentifier: n, projectId: s } = q();
170
+ return he({
171
+ queryKey: ["getTemplateTypes"],
172
+ queryFn: async (i) => await e.get(
173
+ `${Q.TemplateTypes}${n}/${s}`
174
+ ),
175
+ refetchOnWindowFocus: !1,
176
+ refetchOnReconnect: !1,
177
+ refetchOnMount: !1
178
+ });
179
+ }, nt = () => {
180
+ const e = z(), { enerexIdentifier: n, projectId: s } = q();
181
+ return oe({
182
+ mutationKey: ["getTemplate"],
183
+ mutationFn: async ({ id: i }) => {
184
+ if (i)
185
+ return await e.get(
186
+ `${Q.Template}${n}/${i}/${s}`
187
+ );
188
+ }
189
+ });
190
+ }, se = ({
191
+ size: e = "md",
192
+ center: n = !1,
193
+ overlay: s = !1
194
+ }) => {
195
+ const a = /* @__PURE__ */ t("div", { className: `ts-loader ts-loader-${e}` });
196
+ return s ? /* @__PURE__ */ t("div", { className: "ts-loader-overlay", children: a }) : n ? /* @__PURE__ */ t("div", { className: "ts-loader-center", children: a }) : a;
197
+ }, Fe = () => {
198
+ const e = z(), { enerexIdentifier: n, projectId: s } = q();
199
+ return oe({
200
+ mutationKey: ["markFavourite"],
201
+ mutationFn: async (i) => await e.post(
202
+ `${Q.markFavourite}${s}/${n}`,
203
+ i
204
+ )
205
+ });
206
+ }, Ee = (e) => {
207
+ let n = /* @__PURE__ */ t(
208
+ "span",
209
+ {
210
+ style: { width: "20px", height: "20px", display: "inline-block" }
211
+ }
212
+ );
213
+ return e.variant === "filled" ? n = /* @__PURE__ */ t(
214
+ "svg",
215
+ {
216
+ version: "1.0",
217
+ id: "Layer_1",
218
+ xmlns: "http://www.w3.org/2000/svg",
219
+ width: "20px",
220
+ height: "20px",
221
+ viewBox: "0 0 64 64",
222
+ "enable-background": "new 0 0 64 64",
223
+ children: /* @__PURE__ */ t(
224
+ "path",
225
+ {
226
+ fill: "#2196F3",
227
+ d: `M63.893,24.277c-0.238-0.711-0.854-1.229-1.595-1.343l-19.674-3.006L33.809,1.15\r
228
+ C33.479,0.448,32.773,0,31.998,0s-1.48,0.448-1.811,1.15l-8.815,18.778L1.698,22.935c-0.741,0.113-1.356,0.632-1.595,1.343\r
229
+ c-0.238,0.71-0.059,1.494,0.465,2.031l14.294,14.657L11.484,61.67c-0.124,0.756,0.195,1.517,0.822,1.957\r
230
+ c0.344,0.243,0.747,0.366,1.151,0.366c0.332,0,0.666-0.084,0.968-0.25l17.572-9.719l17.572,9.719c0.302,0.166,0.636,0.25,0.968,0.25\r
231
+ c0.404,0,0.808-0.123,1.151-0.366c0.627-0.44,0.946-1.201,0.822-1.957l-3.378-20.704l14.294-14.657\r
232
+ C63.951,25.771,64.131,24.987,63.893,24.277z`
233
+ }
234
+ )
235
+ }
236
+ ) : e.variant === "outlined" && (n = /* @__PURE__ */ t(
237
+ "svg",
238
+ {
239
+ version: "1.0",
240
+ id: "Layer_1",
241
+ xmlns: "http://www.w3.org/2000/svg",
242
+ width: "20px",
243
+ height: "20px",
244
+ viewBox: "0 0 64 64",
245
+ enableBackground: "new 0 0 64 64",
246
+ children: /* @__PURE__ */ t(
247
+ "path",
248
+ {
249
+ fill: e.fill || "rgba(247, 216, 40, 0)",
250
+ stroke: e.stroke || "#000000",
251
+ strokeWidth: e.strokeWidth || "2",
252
+ d: `M63.893,24.277c-0.238-0.711-0.854-1.229-1.595-1.343l-19.674-3.006L33.809,1.15\r
253
+ C33.479,0.448,32.773,0,31.998,0s-1.48,0.448-1.811,1.15l-8.815,18.778L1.698,22.935c-0.741,0.113-1.356,0.632-1.595,1.343\r
254
+ c-0.238,0.71-0.059,1.494,0.465,2.031l14.294,14.657L11.484,61.67c-0.124,0.756,0.195,1.517,0.822,1.957\r
255
+ c0.344,0.243,0.747,0.366,1.151,0.366c0.332,0,0.666-0.084,0.968-0.25l17.572-9.719l17.572,9.719c0.302,0.166,0.636,0.25,0.968,0.25\r
256
+ c0.404,0,0.808-0.123,1.151-0.366c0.627-0.44,0.946-1.201,0.822-1.957l-3.378-20.704l14.294-14.657\r
257
+ C63.951,25.771,64.131,24.987,63.893,24.277z`
258
+ }
259
+ )
260
+ }
261
+ )), n;
262
+ };
263
+ function rt({
264
+ template: e,
265
+ openActionId: n,
266
+ setOpenActionId: s,
267
+ onEdit: a,
268
+ onDuplicate: i,
269
+ onRemove: r,
270
+ onPreview: l,
271
+ onRefresh: o
272
+ }) {
273
+ const { isAdmin: d } = q(), y = n === e.id, m = J(null), T = J(null), [w, E, A] = e.categoryChain, { mutateAsync: h, isPending: g } = Fe(), { showNotification: b } = ke(), p = E?.key, v = A?.key, O = p === 9, M = d || v !== 2, P = d || v !== 2;
274
+ L(() => {
275
+ function C(k) {
276
+ y && m.current && !m.current.contains(k.target) && !T.current?.contains(k.target) && s(null);
277
+ }
278
+ return document.addEventListener("mousedown", C), () => document.removeEventListener("mousedown", C);
279
+ }, [y, s]), L(() => {
280
+ function C(k) {
281
+ k.key === "Escape" && s(null);
282
+ }
283
+ return y && document.addEventListener("keydown", C), () => document.removeEventListener("keydown", C);
284
+ }, [y, s]), L(() => {
285
+ if (!y || !m.current) return;
286
+ const C = Array.from(
287
+ m.current.querySelectorAll('[role="menuitem"]')
288
+ );
289
+ if (!C.length) return;
290
+ let k = 0;
291
+ C[0].focus();
292
+ function x($) {
293
+ $.key === "ArrowDown" && (k = (k + 1) % C.length, C[k].focus(), $.preventDefault()), $.key === "ArrowUp" && (k = (k - 1 + C.length) % C.length, C[k].focus(), $.preventDefault());
294
+ }
295
+ return document.addEventListener("keydown", x), () => document.removeEventListener("keydown", x);
296
+ }, [y]);
297
+ const U = async () => {
298
+ try {
299
+ await h({
300
+ categoryId: v?.toString() ?? "",
301
+ templateId: e.id ?? ""
302
+ }), o(), b(
303
+ `Template "${e?.name}" marked as favourite`,
304
+ "success"
305
+ );
306
+ } catch (C) {
307
+ console.error(C), b(
308
+ "Unable to mark template as favourite. Please try again.",
309
+ "error"
310
+ );
311
+ }
312
+ };
313
+ return /* @__PURE__ */ t(fe, { children: /* @__PURE__ */ c("tr", { className: "ts-table-row", children: [
314
+ /* @__PURE__ */ t("td", { children: /* @__PURE__ */ c("div", { className: "ts-name-cell", children: [
315
+ O && /* @__PURE__ */ t(
316
+ "button",
317
+ {
318
+ type: "button",
319
+ className: "ts-fav-btn ts-btn-light",
320
+ disabled: e.is_favourite,
321
+ onClick: U,
322
+ title: "Mark as favourite",
323
+ children: g ? /* @__PURE__ */ t(se, { size: "sm" }) : e.is_favourite ? /* @__PURE__ */ t(Ee, { variant: "filled" }) : /* @__PURE__ */ t(Ee, { variant: "outlined" })
324
+ }
325
+ ),
326
+ /* @__PURE__ */ t(
327
+ "span",
328
+ {
329
+ className: e.readonly ? "ts-badge default" : "ts-badge custom",
330
+ children: e.readonly ? "Default" : "Custom"
331
+ }
332
+ ),
333
+ /* @__PURE__ */ t("span", { className: "ts-template-name", children: e.name })
334
+ ] }) }),
335
+ /* @__PURE__ */ t("td", { children: w?.name ?? "" }),
336
+ /* @__PURE__ */ t("td", { children: E?.name ?? "" }),
337
+ /* @__PURE__ */ t("td", { children: A?.name ?? "" }),
338
+ /* @__PURE__ */ t("td", { children: e?.updatedByName ?? "" }),
339
+ /* @__PURE__ */ t("td", { className: "ts-actions-cell", children: /* @__PURE__ */ c("div", { className: "ts-actions-wrapper", children: [
340
+ /* @__PURE__ */ t(
341
+ "button",
342
+ {
343
+ ref: T,
344
+ className: "ts-actions-btn",
345
+ "aria-haspopup": "true",
346
+ "aria-expanded": y,
347
+ onClick: () => s(y ? null : e.id),
348
+ children: "⋯"
349
+ }
350
+ ),
351
+ /* @__PURE__ */ c(
352
+ "div",
353
+ {
354
+ ref: m,
355
+ className: `ts-actions-menu ${y ? "open" : ""}`,
356
+ role: "menu",
357
+ children: [
358
+ /* @__PURE__ */ t(
359
+ "button",
360
+ {
361
+ type: "button",
362
+ role: "menuitem",
363
+ className: "ts-menu-item",
364
+ onClick: () => {
365
+ s(null), l(e);
366
+ },
367
+ children: "Preview"
368
+ }
369
+ ),
370
+ M && /* @__PURE__ */ t(
371
+ "button",
372
+ {
373
+ type: "button",
374
+ role: "menuitem",
375
+ className: "ts-menu-item",
376
+ onClick: () => {
377
+ s(null), a(e);
378
+ },
379
+ children: "Edit"
380
+ }
381
+ ),
382
+ /* @__PURE__ */ t(
383
+ "button",
384
+ {
385
+ type: "button",
386
+ role: "menuitem",
387
+ className: "ts-menu-item",
388
+ onClick: () => {
389
+ s(null), i(e);
390
+ },
391
+ children: "Duplicate"
392
+ }
393
+ ),
394
+ P && /* @__PURE__ */ t(
395
+ "button",
396
+ {
397
+ type: "button",
398
+ role: "menuitem",
399
+ className: "ts-menu-item danger",
400
+ onClick: () => {
401
+ s(null), r(e);
402
+ },
403
+ children: "Remove"
404
+ }
405
+ )
406
+ ]
407
+ }
408
+ )
409
+ ] }) })
410
+ ] }) });
411
+ }
412
+ const st = qe(rt), ve = 5, at = ({
413
+ page: e,
414
+ pageSize: n,
415
+ totalRecords: s,
416
+ onPageChange: a,
417
+ onPageSizeChange: i
418
+ }) => {
419
+ const r = Math.ceil(s / n), o = r <= ve ? Array.from({ length: r }, (m, T) => T + 1) : Array.from({ length: ve }, (m, T) => T + 1), d = r > ve, y = r;
420
+ return /* @__PURE__ */ c("div", { className: "ts-pagination-bar", children: [
421
+ /* @__PURE__ */ c("div", { className: "ts-page-container", children: [
422
+ /* @__PURE__ */ c("div", { className: "ts-page-size", children: [
423
+ "Display:",
424
+ /* @__PURE__ */ t(
425
+ "select",
426
+ {
427
+ value: n,
428
+ onChange: (m) => {
429
+ i(Number(m.target.value)), a(1);
430
+ },
431
+ children: [10, 25, 50, 100].map((m) => /* @__PURE__ */ t("option", { value: m, children: m }, m))
432
+ }
433
+ )
434
+ ] }),
435
+ /* @__PURE__ */ c("div", { className: "ts-page-info", children: [
436
+ "Page ",
437
+ e,
438
+ " of ",
439
+ r
440
+ ] }),
441
+ /* @__PURE__ */ c("div", { className: "ts-go-to", children: [
442
+ "Go to page:",
443
+ /* @__PURE__ */ t(
444
+ "input",
445
+ {
446
+ type: "number",
447
+ min: 1,
448
+ max: r,
449
+ value: e,
450
+ onChange: (m) => {
451
+ const T = Number(m.target.value);
452
+ T >= 1 && T <= r && a(T);
453
+ }
454
+ }
455
+ )
456
+ ] })
457
+ ] }),
458
+ /* @__PURE__ */ c("div", { className: "ts-total", children: [
459
+ "Total: ",
460
+ s
461
+ ] }),
462
+ /* @__PURE__ */ c("div", { className: "ts-page-buttons", children: [
463
+ /* @__PURE__ */ t("button", { disabled: e === 1, onClick: () => a(e - 1), children: "‹" }),
464
+ o.map((m) => /* @__PURE__ */ t(
465
+ "button",
466
+ {
467
+ className: m === e ? "active" : "",
468
+ onClick: () => a(m),
469
+ children: m
470
+ },
471
+ m
472
+ )),
473
+ d && /* @__PURE__ */ t("span", { style: { padding: "0 6px" }, children: "…" }),
474
+ d && /* @__PURE__ */ t(
475
+ "button",
476
+ {
477
+ className: e === y ? "active" : "",
478
+ onClick: () => a(y),
479
+ children: y
480
+ }
481
+ ),
482
+ /* @__PURE__ */ t(
483
+ "button",
484
+ {
485
+ disabled: e === r,
486
+ onClick: () => a(e + 1),
487
+ children: "›"
488
+ }
489
+ )
490
+ ] })
491
+ ] });
492
+ }, it = ({
493
+ show: e,
494
+ variant: n,
495
+ title: s = "Are you sure?",
496
+ message: a,
497
+ label: i = "Name",
498
+ value: r = "",
499
+ placeholder: l = "",
500
+ requiredMessage: o = "This field is required",
501
+ externalError: d = !1,
502
+ externalErrorMessage: y = "",
503
+ confirmText: m = "Ok",
504
+ cancelText: T = "Cancel",
505
+ confirmButtonVariant: w = "danger",
506
+ disableConfirm: E = !1,
507
+ onConfirm: A,
508
+ onCancel: h,
509
+ onInputChange: g
510
+ }) => {
511
+ const [b, p] = N(r), [v, O] = N(!1), M = J(null);
512
+ if (L(() => {
513
+ if (!e) return;
514
+ const x = ($) => {
515
+ $.key === "Escape" && h();
516
+ };
517
+ return document.addEventListener("keydown", x), () => document.removeEventListener("keydown", x);
518
+ }, [e, h]), L(() => {
519
+ if (!e) return;
520
+ const x = ($) => {
521
+ M.current && !M.current.contains($.target) && h();
522
+ };
523
+ return document.addEventListener("mousedown", x), () => document.removeEventListener("mousedown", x);
524
+ }, [e, h]), L(() => {
525
+ if (e)
526
+ return document.body.style.overflow = "hidden", () => {
527
+ document.body.style.overflow = "";
528
+ };
529
+ }, [e]), L(() => {
530
+ e && (p(r), O(!1));
531
+ }, [e, r]), L(() => {
532
+ d && O(!0);
533
+ }, [d]), !e) return null;
534
+ const P = n === "input" && !b.trim(), U = n === "input" && (P || d), C = P ? o : d ? y : "", k = () => {
535
+ if (U || E) {
536
+ O(!0);
537
+ return;
538
+ }
539
+ A(b.trim());
540
+ };
541
+ return /* @__PURE__ */ t("div", { className: "ts-modal-overlay", children: /* @__PURE__ */ c("div", { ref: M, className: "ts-modal", children: [
542
+ /* @__PURE__ */ c("div", { className: "ts-modal-header", children: [
543
+ /* @__PURE__ */ t("h4", { className: "ts-modal-title ", children: s }),
544
+ /* @__PURE__ */ t("button", { className: "ts-modal-close", onClick: h, children: "✕" })
545
+ ] }),
546
+ /* @__PURE__ */ c("div", { className: "ts-modal-body", children: [
547
+ a && /* @__PURE__ */ t("p", { className: "ts-modal-message", children: a }),
548
+ n === "input" && /* @__PURE__ */ c("div", { className: "ts-form-group", children: [
549
+ /* @__PURE__ */ c("label", { className: "ts-label", children: [
550
+ i,
551
+ /* @__PURE__ */ t("span", { className: "ts-required", children: "*" })
552
+ ] }),
553
+ /* @__PURE__ */ t(
554
+ "input",
555
+ {
556
+ type: "text",
557
+ className: `ts-input ${v && U ? "ts-input-error" : ""}`,
558
+ placeholder: l,
559
+ value: b,
560
+ onChange: (x) => {
561
+ p(x.target.value), v && O(!1), g?.(x.target.value);
562
+ },
563
+ autoFocus: !0,
564
+ style: { paddingBlock: "0", paddingInline: "0" }
565
+ }
566
+ ),
567
+ v && U && /* @__PURE__ */ t("div", { className: "ts-error-text", children: C })
568
+ ] })
569
+ ] }),
570
+ /* @__PURE__ */ c("div", { className: "ts-modal-footer", children: [
571
+ /* @__PURE__ */ t(
572
+ "button",
573
+ {
574
+ type: "button",
575
+ className: "ts-btn ts-btn-secondary",
576
+ onClick: h,
577
+ children: T
578
+ }
579
+ ),
580
+ /* @__PURE__ */ t(
581
+ "button",
582
+ {
583
+ type: "button",
584
+ className: `ts-btn ts-btn-${w}`,
585
+ onClick: k,
586
+ disabled: E,
587
+ children: m
588
+ }
589
+ )
590
+ ] })
591
+ ] }) });
592
+ }, lt = () => /* @__PURE__ */ t(
593
+ "svg",
594
+ {
595
+ xmlns: "http://www.w3.org/2000/svg",
596
+ viewBox: "0 0 512 512",
597
+ width: "16px",
598
+ height: "16px",
599
+ children: /* @__PURE__ */ t("path", { fill: "#ffffff", d: "M368 208A160 160 0 1 0 48 208a160 160 0 1 0 320 0zM337.1 371.1C301.7 399.2 256.8 416 208 416C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208c0 48.8-16.8 93.7-44.9 129.1L505 471c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0L337.1 371.1z" })
600
+ }
601
+ ), ot = () => {
602
+ const e = z(), { enerexIdentifier: n, projectId: s, userEmail: a } = q();
603
+ return oe({
604
+ mutationKey: ["duplicateTemplate"],
605
+ mutationFn: async ({ templateId: r, request: l }) => (l.enerexIdentifier = n ?? "", l.projectId = s ?? "", l.updatedBy = a ?? "", await e.post(
606
+ `${Q.duplicateTemplate}${r}`,
607
+ l
608
+ ))
609
+ });
610
+ }, ct = () => {
611
+ const e = z();
612
+ return oe({
613
+ mutationKey: ["deleteTemplate"],
614
+ mutationFn: async (n) => {
615
+ await e.delete(
616
+ `${Q.deleteTemplate}${n}`
617
+ );
618
+ }
619
+ });
620
+ }, dt = ({
621
+ data: e,
622
+ page: n,
623
+ pageSize: s
624
+ }) => {
625
+ const a = re(() => Math.ceil(e.length / s), [e.length, s]);
626
+ return { pagedData: re(() => {
627
+ const r = (n - 1) * s, l = n * s;
628
+ return e.slice(r, l);
629
+ }, [e, n, s]), totalPages: a };
630
+ }, mt = ({
631
+ templates: e,
632
+ templateTypes: n,
633
+ onRefresh: s,
634
+ onAdd: a,
635
+ onEdit: i,
636
+ onPreview: r
637
+ }) => {
638
+ const { mutateAsync: l, isPending: o } = ot(), { mutateAsync: d, isPending: y } = ct(), [m, T] = N(""), [w, E] = N(""), [A, h] = N(null), [g, b] = N(e), [p, v] = N(n), [O, M] = N(!1), [P, U] = N("input"), [C, k] = N(!1), [x, $] = N(null), [B, ce] = N("asc"), V = (u) => {
639
+ x === u ? ce((S) => S === "asc" ? "desc" : "asc") : ($(u), ce("asc")), ie(1);
640
+ }, [K, G] = N(null);
641
+ L(() => {
642
+ const u = [...e].sort((S, R) => {
643
+ if (S.is_favourite !== R.is_favourite)
644
+ return Number(R.is_favourite) - Number(S.is_favourite);
645
+ const D = new Date(R.updatedDateTime).getTime() - new Date(S.updatedDateTime).getTime();
646
+ return D !== 0 ? D : S.readonly !== R.readonly ? Number(S.readonly) - Number(R.readonly) : S.name.localeCompare(R.name);
647
+ });
648
+ b(u), $(null);
649
+ }, [e]), L(() => {
650
+ v(n.filter((u) => u.id != null));
651
+ }, [n]);
652
+ const Z = re(() => {
653
+ const u = /* @__PURE__ */ new Map();
654
+ return p.forEach((S) => u.set(S.id, S)), u;
655
+ }, [p]), ye = xe(
656
+ (u) => {
657
+ const S = [], R = /* @__PURE__ */ new Set();
658
+ let D = Z.get(u);
659
+ for (; D && !(R.has(D.id) || (R.add(D.id), S.push({ id: D.id, name: D.name, key: D.key }), !D.parent_id)); )
660
+ D = Z.get(D.parent_id);
661
+ return S.reverse();
662
+ },
663
+ [Z]
664
+ ), ee = re(() => !g.length || !p.length ? [] : g.map((u) => ({
665
+ ...u,
666
+ categoryChain: ye(u.type)
667
+ })), [g, p]);
668
+ L(() => {
669
+ const u = setTimeout(() => {
670
+ E(m), ie(1);
671
+ }, 300);
672
+ return () => clearTimeout(u);
673
+ }, [m]);
674
+ const [te, ae] = N(10), [H, ie] = N(1), ne = re(() => {
675
+ const u = w.trim().toLowerCase();
676
+ return u ? ee.filter((S) => {
677
+ const R = S.name.toLowerCase().includes(u), D = S.categoryChain?.some(
678
+ (Y) => Y.name.toLowerCase().includes(u)
679
+ );
680
+ return R || D;
681
+ }) : ee;
682
+ }, [ee, w]), de = re(() => {
683
+ const u = [...ne];
684
+ return u.sort((S, R) => {
685
+ let D = "", Y = "";
686
+ switch (x) {
687
+ case "name":
688
+ D = S.name, Y = R.name;
689
+ break;
690
+ case "category":
691
+ D = S.categoryChain?.[0]?.name ?? "", Y = R.categoryChain?.[0]?.name ?? "";
692
+ break;
693
+ case "type":
694
+ D = S.categoryChain?.[1]?.name ?? "", Y = R.categoryChain?.[1]?.name ?? "";
695
+ break;
696
+ case "subtype":
697
+ D = S.categoryChain?.[2]?.name ?? "", Y = R.categoryChain?.[2]?.name ?? "";
698
+ break;
699
+ }
700
+ const Ie = D.localeCompare(Y, void 0, {
701
+ sensitivity: "base"
702
+ });
703
+ return B === "asc" ? Ie : -Ie;
704
+ }), u;
705
+ }, [ne, x, B]), { pagedData: le } = dt({
706
+ data: de,
707
+ page: H,
708
+ pageSize: te
709
+ }), ge = xe(
710
+ (u) => g.some(
711
+ (S) => S.name.trim().toLowerCase() === u.trim().toLowerCase()
712
+ ),
713
+ [g]
714
+ ), f = (u) => {
715
+ G(u), k(!1), U("input"), M(!0);
716
+ }, I = (u) => {
717
+ G(u), U("confirm"), M(!0);
718
+ }, { showNotification: _ } = ke(), j = async (u) => {
719
+ if (K)
720
+ try {
721
+ if (P === "input") {
722
+ if (!u) return;
723
+ if (ge(u)) {
724
+ k(!0);
725
+ return;
726
+ }
727
+ await l({
728
+ templateId: K.id,
729
+ request: {
730
+ projectId: "",
731
+ enerexIdentifier: "",
732
+ newName: u,
733
+ parent_id: K.id ?? null
734
+ }
735
+ }), _(
736
+ `Template "${u}" duplicated successfully`,
737
+ "success"
738
+ );
739
+ }
740
+ P === "confirm" && (await d(K.id), _(
741
+ `Template "${K.name}" deleted successfully`,
742
+ "success"
743
+ )), M(!1), G(null), s();
744
+ } catch {
745
+ _(
746
+ P === "confirm" ? "Failed to delete template. Please try again." : "Failed to duplicate template. Please try again.",
747
+ "error"
748
+ );
749
+ }
750
+ }, X = K?.categoryChain?.[2]?.name?.toLowerCase() ?? "this", F = K?.name?.toLowerCase() ?? "";
751
+ return /* @__PURE__ */ c(fe, { children: [
752
+ (o || y) && /* @__PURE__ */ t(se, { overlay: !0 }),
753
+ /* @__PURE__ */ c("div", { className: "ts-page", children: [
754
+ /* @__PURE__ */ c("div", { className: "ts-header", children: [
755
+ /* @__PURE__ */ t("h1", { className: "ts-title", children: "Templates" }),
756
+ /* @__PURE__ */ t("button", { className: "ts-btn ts-btn-primary", onClick: a, children: "+ Add Template" })
757
+ ] }),
758
+ /* @__PURE__ */ t("div", { className: "ts-search", children: /* @__PURE__ */ c("div", { className: "ts-search-box", children: [
759
+ /* @__PURE__ */ t(
760
+ "input",
761
+ {
762
+ type: "text",
763
+ placeholder: "Search...",
764
+ value: m,
765
+ onChange: (u) => T(u.target.value)
766
+ }
767
+ ),
768
+ m && /* @__PURE__ */ t(
769
+ "button",
770
+ {
771
+ className: "ts-clear-btn",
772
+ "aria-label": "Clear search",
773
+ onClick: () => T(""),
774
+ children: "×"
775
+ }
776
+ ),
777
+ /* @__PURE__ */ t("button", { className: "ts-search-btn", "aria-label": "Search", children: /* @__PURE__ */ t(lt, {}) })
778
+ ] }) }),
779
+ /* @__PURE__ */ c("div", { className: "ts-table-wrapper", children: [
780
+ /* @__PURE__ */ c("table", { className: "ts-table", children: [
781
+ /* @__PURE__ */ t("thead", { children: /* @__PURE__ */ c("tr", { children: [
782
+ /* @__PURE__ */ t("th", { onClick: () => V("name"), className: "ts-sortable", children: /* @__PURE__ */ c("div", { className: "ts-th-sort", children: [
783
+ "Name",
784
+ /* @__PURE__ */ c("span", { className: "ts-sort-icons", children: [
785
+ /* @__PURE__ */ t(
786
+ "span",
787
+ {
788
+ className: x === "name" && B === "asc" ? "active" : "",
789
+ children: "▲"
790
+ }
791
+ ),
792
+ /* @__PURE__ */ t(
793
+ "span",
794
+ {
795
+ className: x === "name" && B === "desc" ? "active" : "",
796
+ children: "▼"
797
+ }
798
+ )
799
+ ] })
800
+ ] }) }),
801
+ /* @__PURE__ */ t(
802
+ "th",
803
+ {
804
+ onClick: () => V("category"),
805
+ className: "ts-sortable",
806
+ children: /* @__PURE__ */ c("div", { className: "ts-th-sort", children: [
807
+ "Category",
808
+ /* @__PURE__ */ c("span", { className: "ts-sort-icons", children: [
809
+ /* @__PURE__ */ t(
810
+ "span",
811
+ {
812
+ className: x === "category" && B === "asc" ? "active" : "",
813
+ children: "▲"
814
+ }
815
+ ),
816
+ /* @__PURE__ */ t(
817
+ "span",
818
+ {
819
+ className: x === "category" && B === "desc" ? "active" : "",
820
+ children: "▼"
821
+ }
822
+ )
823
+ ] })
824
+ ] })
825
+ }
826
+ ),
827
+ /* @__PURE__ */ t("th", { onClick: () => V("type"), className: "ts-sortable", children: /* @__PURE__ */ c("div", { className: "ts-th-sort", children: [
828
+ "Type",
829
+ /* @__PURE__ */ c("span", { className: "ts-sort-icons", children: [
830
+ /* @__PURE__ */ t(
831
+ "span",
832
+ {
833
+ className: x === "type" && B === "asc" ? "active" : "",
834
+ children: "▲"
835
+ }
836
+ ),
837
+ /* @__PURE__ */ t(
838
+ "span",
839
+ {
840
+ className: x === "type" && B === "desc" ? "active" : "",
841
+ children: "▼"
842
+ }
843
+ )
844
+ ] })
845
+ ] }) }),
846
+ /* @__PURE__ */ t(
847
+ "th",
848
+ {
849
+ onClick: () => V("subtype"),
850
+ className: "ts-sortable",
851
+ children: /* @__PURE__ */ c("div", { className: "ts-th-sort", children: [
852
+ "Subtype",
853
+ /* @__PURE__ */ c("span", { className: "ts-sort-icons", children: [
854
+ /* @__PURE__ */ t(
855
+ "span",
856
+ {
857
+ className: x === "subtype" && B === "asc" ? "active" : "",
858
+ children: "▲"
859
+ }
860
+ ),
861
+ /* @__PURE__ */ t(
862
+ "span",
863
+ {
864
+ className: x === "subtype" && B === "desc" ? "active" : "",
865
+ children: "▼"
866
+ }
867
+ )
868
+ ] })
869
+ ] })
870
+ }
871
+ ),
872
+ /* @__PURE__ */ t("th", { children: "Updated by" }),
873
+ /* @__PURE__ */ t("th", { className: "align-right", children: "Actions" })
874
+ ] }) }),
875
+ /* @__PURE__ */ t("tbody", { children: le.map((u) => /* @__PURE__ */ t(
876
+ st,
877
+ {
878
+ template: u,
879
+ openActionId: A,
880
+ setOpenActionId: h,
881
+ onDuplicate: f,
882
+ onEdit: i,
883
+ onRemove: I,
884
+ onPreview: r,
885
+ onRefresh: s
886
+ },
887
+ u.id
888
+ )) })
889
+ ] }),
890
+ /* @__PURE__ */ t(
891
+ at,
892
+ {
893
+ page: H,
894
+ pageSize: te,
895
+ totalRecords: de.length,
896
+ onPageChange: ie,
897
+ onPageSizeChange: ae
898
+ }
899
+ )
900
+ ] })
901
+ ] }),
902
+ /* @__PURE__ */ t(
903
+ it,
904
+ {
905
+ show: O,
906
+ variant: P,
907
+ title: P === "confirm" ? "Are you sure?" : "Save Template As",
908
+ message: P === "confirm" ? `Are you sure you want to remove ${X} template "${F}"?` : "",
909
+ placeholder: P === "input" ? "New name" : "",
910
+ label: "New Name",
911
+ requiredMessage: "Enter a new name",
912
+ externalError: C,
913
+ externalErrorMessage: "Template name already exists. Please choose a different name",
914
+ confirmText: P === "confirm" ? "Ok" : "Save as",
915
+ confirmButtonVariant: P === "confirm" ? "danger" : "primary",
916
+ onConfirm: j,
917
+ onCancel: () => M(!1),
918
+ onInputChange: P === "input" ? () => k(!1) : void 0
919
+ }
920
+ )
921
+ ] });
922
+ }, pe = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
9
923
  <html\r
10
924
  dir="ltr"\r
11
925
  xmlns:o="urn:schemas-microsoft-com:office:office"\r
@@ -361,160 +1275,70 @@ const de = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http
361
1275
  </div>\r
362
1276
  </body>\r
363
1277
  </html>\r
364
- `, Re = M.createContext(
365
- void 0
366
- ), pt = ({
367
- children: t,
368
- configs: s
369
- }) => {
370
- const [l, a] = M.useState(s.clientId), [i, e] = M.useState(s.apiKey), [d, o] = M.useState(
371
- s.enerexIdentifier
372
- ), [b, D] = M.useState(s.projectId), [A, m] = M.useState(s.userEmail), [_, u] = M.useState(s.isAdmin), [j, h] = M.useState(s.meBaseUrl), [v, y] = M.useState(
373
- s.defaultSelector
374
- ), f = (g) => {
375
- e(g.apiKey), a(g.clientId), D(g.projectId), o(g.enerexIdentifier), m(g.userEmail), u(g.isAdmin), y(g.defaultSelector), h(g.meBaseUrl);
376
- };
377
- return /* @__PURE__ */ n(
378
- Re.Provider,
379
- {
380
- value: {
381
- clientId: l,
382
- apiKey: i,
383
- setConfiguration: f,
384
- enerexIdentifier: d,
385
- projectId: b,
386
- userEmail: A,
387
- isAdmin: _,
388
- defaultSelector: v,
389
- meBaseUrl: j
390
- },
391
- children: t
392
- }
393
- );
394
- }, B = () => {
395
- const t = qe(Re);
396
- if (!t)
397
- throw new Error("widgetConfig must be used within a ConfigProvider");
398
- return t;
399
- }, Me = (t = "", s) => ({ get: async (i, e) => {
400
- try {
401
- const d = await _e.get(
402
- `${t}${i}`,
403
- e ?? s
404
- );
405
- if (d.status === 200)
406
- return d.data;
407
- } catch (d) {
408
- throw d;
409
- }
410
- }, post: async (i, e, d) => {
411
- try {
412
- const o = await _e.post(
413
- `${t}${i}`,
414
- e,
415
- d ?? s
416
- );
417
- if (o.status === 200)
418
- return o.data;
419
- } catch (o) {
420
- throw o;
421
- }
422
- } }), Be = M.createContext({
423
- get: () => {
424
- throw new Error("HttpClientContext.get not implemented");
425
- },
426
- post: () => {
427
- throw new Error("HttpClientContext.post not implemented");
428
- }
429
- }), mt = ({ children: t }) => {
430
- const { clientId: s, apiKey: l, isAdmin: a, meBaseUrl: i } = B(), e = {
431
- headers: {
432
- client_id: s,
433
- "x-api-key": l,
434
- "Security-Context": a ? "admin" : "viewer"
435
- }
436
- }, { get: d, post: o } = Me(i, e);
437
- return /* @__PURE__ */ n(Be.Provider, { value: { get: d, post: o }, children: t });
438
- }, ut = ({ children: t }) => {
439
- const s = new it();
440
- return /* @__PURE__ */ n(mt, { children: /* @__PURE__ */ n(at, { client: s, children: t }) });
441
- }, he = {
1278
+ `, we = {
442
1279
  EDITOR_SCRIPT_URL: "https://plugins.stripo.email/resources/uieditor/latest/UIEditor.js",
443
1280
  EDITOR_PLUGIN_ID: "1afdc3161ec7409a8627a1c8561d45f5",
444
1281
  EDITOR_SECRET_KEY: "54ba748ed7e94f2e929555783acb03da"
445
- }, ft = (t) => {
446
- const s = Array.from(new Set(t.map((a) => a.category))), l = [];
447
- return s.forEach((a) => {
448
- const i = t.filter((e) => e.category === a).map((e) => ({
449
- label: e.label,
450
- value: e.value,
451
- hint: e.hint,
452
- hidden: e.hidden
1282
+ }, ut = (e) => {
1283
+ const n = Array.from(new Set(e.map((a) => a.category))), s = [];
1284
+ return n.forEach((a) => {
1285
+ const i = e.filter((r) => r.category === a).map((r) => ({
1286
+ label: r.label,
1287
+ value: r.value,
1288
+ hint: r.hint,
1289
+ hidden: r.hidden
453
1290
  }));
454
- l.push({ category: a, entries: i });
455
- }), l;
456
- }, V = () => {
457
- const t = qe(Be);
458
- if (t)
459
- return t;
460
- throw new Error("useHttpClient must be used within a HttpClientProvider");
461
- }, G = {
462
- Template_list: "/Template/list/",
463
- Template: "/Template/GetTemplate/",
464
- MergeTags: "/Template/TemplateMergeTags/",
465
- ExcludeCategory: "/Template/GetExcludeCategories/",
466
- SaveTemplate: "/Template/save-update/",
467
- TemplateTypes: "/Template/TemplateTypes/",
468
- markFavourite: "/Template/MarkFavourite/"
469
- }, yt = () => {
470
- const t = V(), { enerexIdentifier: s, projectId: l } = B();
471
- return ce({
1291
+ s.push({ category: a, entries: i });
1292
+ }), s;
1293
+ }, pt = () => {
1294
+ const e = z(), { enerexIdentifier: n, projectId: s } = q();
1295
+ return he({
472
1296
  queryKey: ["getTemplateTags"],
473
- queryFn: async (i) => await t.get(
474
- `${G.MergeTags}${l}/${s}`
1297
+ queryFn: async (i) => await e.get(
1298
+ `${Q.MergeTags}${s}/${n}`
475
1299
  )
476
1300
  });
477
- }, gt = () => {
478
- const t = V(), { enerexIdentifier: s, projectId: l } = B();
479
- return ce({
1301
+ }, ft = () => {
1302
+ const e = z(), { enerexIdentifier: n, projectId: s } = q();
1303
+ return he({
480
1304
  queryKey: ["getExcludeCategory"],
481
- queryFn: async (i) => await t.get(
482
- `${G.ExcludeCategory}${l}/${s}`
1305
+ queryFn: async (i) => await e.get(
1306
+ `${Q.ExcludeCategory}${s}/${n}`
483
1307
  )
484
1308
  });
485
1309
  }, ht = ({
486
- templateHTML: t,
487
- className: s = "",
488
- loading: l = !1,
1310
+ templateHTML: e,
1311
+ className: n = "",
1312
+ loading: s = !1,
489
1313
  onEditorInitialized: a
490
1314
  }) => {
491
- const { post: i } = Me(), { data: e } = yt(), { data: d } = gt(), [o, b] = w(
492
- t ?? { html: de, css: "" }
493
- ), { userEmail: D } = B(), A = st(null), m = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", _ = "https://plugins.stripo.email/api/v1/auth";
494
- E(() => {
495
- (async () => (await u(), e && d && await j(he.EDITOR_SCRIPT_URL)))();
496
- }, [e, d]);
497
- async function u() {
498
- window.Zone || await new Promise((v, y) => {
499
- const f = document.createElement("script");
500
- f.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
501
- const g = document.querySelector("script[nonce]")?.nonce;
502
- g && f.setAttribute("nonce", g), f.onload = () => v(), f.onerror = () => y(new Error("Failed to load zone.js")), document.head.appendChild(f);
1315
+ const { post: i } = Oe(), { data: r } = pt(), { data: l } = ft(), [o, d] = N(
1316
+ e ?? { html: pe, css: "" }
1317
+ ), { userEmail: y } = q(), m = J(null), T = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", w = "https://plugins.stripo.email/api/v1/auth";
1318
+ L(() => {
1319
+ (async () => (await E(), r && l && await A(we.EDITOR_SCRIPT_URL)))();
1320
+ }, [r, l]);
1321
+ async function E() {
1322
+ window.Zone || await new Promise((g, b) => {
1323
+ const p = document.createElement("script");
1324
+ p.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
1325
+ const v = document.querySelector("script[nonce]")?.nonce;
1326
+ v && p.setAttribute("nonce", v), p.onload = () => g(), p.onerror = () => b(new Error("Failed to load zone.js")), document.head.appendChild(p);
503
1327
  });
504
1328
  }
505
- async function j(v) {
506
- let y = document.getElementById(
1329
+ async function A(g) {
1330
+ let b = document.getElementById(
507
1331
  "UiEditorScript"
508
1332
  );
509
- y || (y = document.createElement("script"), y.id = "UiEditorScript", y.src = v, y.onload = async () => {
1333
+ b || (b = document.createElement("script"), b.id = "UiEditorScript", b.src = g, b.onload = async () => {
510
1334
  await h();
511
- }, document.body.appendChild(y)), await new Promise(
512
- (f) => y.addEventListener("load", () => f(), { once: !0 })
1335
+ }, document.body.appendChild(b)), await new Promise(
1336
+ (p) => b.addEventListener("load", () => p(), { once: !0 })
513
1337
  );
514
1338
  }
515
1339
  const h = async () => {
516
- const v = A.current;
517
- if (!v) {
1340
+ const g = m.current;
1341
+ if (!g) {
518
1342
  console.error("Missing #stripoEditorContainer in DOM");
519
1343
  return;
520
1344
  }
@@ -522,261 +1346,156 @@ const de = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http
522
1346
  console.error("UIEditor script not loaded or not exposing initEditor");
523
1347
  return;
524
1348
  }
525
- const y = {
1349
+ const b = {
526
1350
  html: o.html,
527
1351
  css: o.css,
528
- modulesExcludedCategories: d ?? [],
1352
+ modulesExcludedCategories: l ?? [],
529
1353
  forceRecreate: !0,
530
1354
  metadata: {
531
- emailId: D,
1355
+ emailId: y,
532
1356
  userId: "1",
533
1357
  // username: userName,
534
- avatarUrl: m
1358
+ avatarUrl: T
535
1359
  },
536
1360
  locale: "en",
537
- onTokenRefreshRequest: async (f) => {
538
- const g = {
539
- pluginId: he.EDITOR_PLUGIN_ID,
540
- secretKey: he.EDITOR_SECRET_KEY,
541
- userId: D,
1361
+ onTokenRefreshRequest: async (p) => {
1362
+ const v = {
1363
+ pluginId: we.EDITOR_PLUGIN_ID,
1364
+ secretKey: we.EDITOR_SECRET_KEY,
1365
+ userId: y,
542
1366
  role: "user"
543
- }, T = await i(
544
- _,
545
- g
1367
+ }, O = await i(
1368
+ w,
1369
+ v
546
1370
  );
547
- T?.token && f(T.token);
1371
+ O?.token && p(O.token);
548
1372
  },
549
1373
  onTemplateLoaded: () => {
550
1374
  a && a(!0);
551
1375
  },
552
- mergeTags: ft(e ?? [])
1376
+ mergeTags: ut(r ?? [])
553
1377
  };
554
- for (const [f, g] of Object.entries({
1378
+ for (const [p, v] of Object.entries({
555
1379
  codeEditorButtonSelector: "#codeEditor",
556
1380
  undoButtonSelector: "#undoButton",
557
1381
  redoButtonSelector: "#redoButton",
558
1382
  mobileViewButtonSelector: "#mobileViewButton",
559
1383
  desktopViewButtonSelector: "#desktopViewButton"
560
1384
  }))
561
- v.ownerDocument && v.getRootNode() instanceof ShadowRoot && v.getRootNode().querySelector(g) && (y[f] = g);
562
- await window.UIEditor.initEditor(v, y);
1385
+ g.ownerDocument && g.getRootNode() instanceof ShadowRoot && g.getRootNode().querySelector(v) && (b[p] = v);
1386
+ await window.UIEditor.initEditor(g, b);
563
1387
  };
564
- return /* @__PURE__ */ n("div", { className: "position-relative", children: /* @__PURE__ */ S("div", { className: `editor-container ${s}`, children: [
565
- l && /* @__PURE__ */ n("div", { className: "loading-overlay", children: /* @__PURE__ */ n(
566
- z,
1388
+ return /* @__PURE__ */ t("div", { className: "position-relative", children: /* @__PURE__ */ c("div", { className: `editor-container ${n}`, children: [
1389
+ s && /* @__PURE__ */ t("div", { className: "loading-overlay", children: /* @__PURE__ */ t(
1390
+ Ke,
567
1391
  {
568
1392
  animation: "border",
569
1393
  style: { width: "11px", height: "11px" },
570
1394
  size: "sm",
571
1395
  role: "status",
572
1396
  className: "me-1",
573
- children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1397
+ children: /* @__PURE__ */ t("span", { className: "visually-hidden", children: "Loading..." })
574
1398
  }
575
1399
  ) }),
576
- /* @__PURE__ */ n("div", { id: "externalSystemContainer" }),
577
- /* @__PURE__ */ n("div", { id: "stripoEditorContainer", ref: A })
1400
+ /* @__PURE__ */ t("div", { id: "externalSystemContainer" }),
1401
+ /* @__PURE__ */ t("div", { id: "stripoEditorContainer", ref: m })
578
1402
  ] }) });
579
- }, je = ({
580
- label: t,
581
- register: s,
582
- validation: l,
1403
+ }, $e = ({
1404
+ label: e,
1405
+ register: n,
1406
+ validation: s,
583
1407
  required: a = !1,
584
1408
  name: i,
585
- error: e,
586
- className: d = "",
1409
+ error: r,
1410
+ className: l = "",
587
1411
  ...o
588
- }) => /* @__PURE__ */ S(H.Group, { className: d + " mb-1", style: { width: "100%" }, children: [
589
- t ? /* @__PURE__ */ S(H.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
590
- t,
591
- a && /* @__PURE__ */ n("label", { className: "text-danger", children: "*" })
592
- ] }) : null,
593
- /* @__PURE__ */ n(
594
- H.Control,
595
- {
596
- name: i,
597
- type: "text",
598
- ...o,
599
- isInvalid: !!(e && e[i]),
600
- ...s ? s(i, {
601
- ...l
602
- }) : {},
603
- className: `react-select__control ${e && e[i] && "border border-danger"}`
604
- }
605
- ),
606
- e && e[i] ? /* @__PURE__ */ n(H.Control.Feedback, { type: "invalid", children: e[i].message }) : null
607
- ] }), bt = ({
608
- show: t,
609
- variant: s,
610
- title: l = "Are you sure?",
611
- message: a,
612
- label: i = "Name",
613
- value: e = "",
614
- placeholder: d = "",
615
- requiredMessage: o = "This field is required",
616
- externalError: b = !1,
617
- externalErrorMessage: D = "",
618
- confirmText: A = "Ok",
619
- cancelText: m = "Cancel",
620
- confirmButtonVariant: _ = "danger",
621
- onConfirm: u,
622
- onCancel: j,
623
- onInputChange: h
624
1412
  }) => {
625
- const [v, y] = w(e), [f, g] = w(!1);
626
- if (E(() => {
627
- t && (y(e), g(!1));
628
- }, [t, e]), E(() => {
629
- b && g(!0);
630
- }, [b]), !t) return null;
631
- const T = s === "input" && !v.trim(), P = s === "input" && (T || b), pe = T ? o : b ? D : "", K = () => {
632
- if (P) {
633
- g(!0);
634
- return;
635
- }
636
- u(v.trim());
637
- };
638
- return /* @__PURE__ */ n("div", { className: "template-studio-modal-overlay", children: /* @__PURE__ */ S("div", { className: "template-studio-modal", children: [
639
- /* @__PURE__ */ S("div", { className: "template-studio-modal-header", children: [
640
- /* @__PURE__ */ n("h4", { children: l }),
641
- /* @__PURE__ */ n("button", { className: "template-studio-modal-close", onClick: j, children: "✕" })
642
- ] }),
643
- /* @__PURE__ */ S("div", { className: "template-studio-modal-body", children: [
644
- a && /* @__PURE__ */ n("p", { children: a }),
645
- s === "input" && /* @__PURE__ */ S("div", { className: "mb-3", children: [
646
- /* @__PURE__ */ S("label", { className: "form-label", children: [
647
- i,
648
- /* @__PURE__ */ n("span", { className: "text-danger", children: "*" })
649
- ] }),
650
- /* @__PURE__ */ n(
651
- "input",
652
- {
653
- type: "text",
654
- className: `form-control ${f && P ? "is-invalid" : ""}`,
655
- placeholder: d,
656
- value: v,
657
- onChange: (ee) => {
658
- y(ee.target.value), f && g(!1), h?.(ee.target.value);
659
- },
660
- autoFocus: !0
661
- }
662
- ),
663
- f && P && /* @__PURE__ */ n("div", { className: "invalid-feedback d-block", children: pe })
664
- ] })
1413
+ const d = !!(r && r[i]);
1414
+ return /* @__PURE__ */ c("div", { className: `ts-form-group ${l}`, children: [
1415
+ e && /* @__PURE__ */ c("label", { className: "ts-form-label", children: [
1416
+ e,
1417
+ a && /* @__PURE__ */ t("span", { className: "ts-required", children: "*" })
665
1418
  ] }),
666
- /* @__PURE__ */ S("div", { className: "template-studio-modal-footer", children: [
667
- /* @__PURE__ */ n("button", { className: "btn btn-secondary", onClick: j, children: m }),
668
- /* @__PURE__ */ n(
669
- "button",
670
- {
671
- className: `btn btn-${_}`,
672
- onClick: K,
673
- children: A
674
- }
675
- )
676
- ] })
677
- ] }) });
678
- }, vt = () => {
679
- const t = V(), { enerexIdentifier: s, projectId: l } = B();
680
- return ce({
681
- queryKey: ["getTemplatesList"],
682
- queryFn: async (i) => await t.get(
683
- `${G.Template_list}${l}/${s}`
684
- )
685
- });
1419
+ /* @__PURE__ */ t(
1420
+ "input",
1421
+ {
1422
+ name: i,
1423
+ type: "text",
1424
+ ...o,
1425
+ ...n ? n(i, {
1426
+ ...s
1427
+ }) : {},
1428
+ className: `ts-input ${d ? "ts-input-error" : ""}`,
1429
+ "aria-invalid": d
1430
+ }
1431
+ ),
1432
+ d && /* @__PURE__ */ t("div", { className: "ts-error-text", children: r?.[i]?.message })
1433
+ ] });
686
1434
  };
687
- function be(t) {
688
- return t.sort((s, l) => s.name.localeCompare(l.name));
1435
+ function Ne(e) {
1436
+ return e.sort((n, s) => n.name.localeCompare(s.name));
689
1437
  }
690
- function wt(t) {
691
- const s = /* @__PURE__ */ new Map(), l = [];
692
- t.forEach((e) => s.set(e.id, e));
693
- let a = t.filter((e) => e.parent_id === 0), i = 0;
1438
+ function yt(e) {
1439
+ const n = /* @__PURE__ */ new Map(), s = [];
1440
+ e.forEach((r) => n.set(r.id, r));
1441
+ let a = e.filter((r) => r.parent_id === 0), i = 0;
694
1442
  for (; a.length > 0; ) {
695
- l.push({ level: i, data: a });
696
- const e = a.map((o) => o.id);
697
- a = t.filter(
698
- (o) => e.includes(o.parent_id)
1443
+ s.push({ level: i, data: a });
1444
+ const r = a.map((o) => o.id);
1445
+ a = e.filter(
1446
+ (o) => r.includes(o.parent_id)
699
1447
  ), i++;
700
1448
  }
701
- return l;
1449
+ return s;
702
1450
  }
703
- function ve(t, s) {
704
- const a = wt(t).find((i) => i.level === s);
1451
+ function Te(e, n) {
1452
+ const a = yt(e).find((i) => i.level === n);
705
1453
  return a ? a.data : [];
706
1454
  }
707
- const Tt = () => {
708
- const t = V(), { enerexIdentifier: s, projectId: l } = B();
709
- return Te({
710
- mutationKey: ["markFavourite"],
711
- mutationFn: async (i) => await t.post(
712
- `${G.markFavourite}${l}/${s}`,
713
- i
714
- )
715
- });
716
- }, xt = () => {
717
- const t = V(), { enerexIdentifier: s, projectId: l } = B();
718
- return Te({
719
- mutationKey: ["getTemplate"],
720
- mutationFn: async ({ id: i }) => {
721
- if (i)
722
- return await t.get(
723
- `${G.Template}${s}/${i}/${l}`
724
- );
725
- }
726
- });
727
- }, St = () => {
728
- const t = V(), { enerexIdentifier: s, projectId: l } = B();
729
- return ce({
730
- queryKey: ["getTemplateTypes"],
731
- queryFn: async (i) => await t.get(
732
- `${G.TemplateTypes}${s}/${l}`
733
- )
734
- });
735
- };
736
- function Ct(t) {
737
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
1455
+ function gt(e) {
1456
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
738
1457
  }
739
- var we = { exports: {} };
1458
+ var Ce = { exports: {} };
740
1459
  /*!
741
1460
  Copyright (c) 2018 Jed Watson.
742
1461
  Licensed under the MIT License (MIT), see
743
1462
  http://jedwatson.github.io/classnames
744
1463
  */
745
- var Pe;
746
- function Nt() {
747
- return Pe || (Pe = 1, function(t) {
1464
+ var Ae;
1465
+ function bt() {
1466
+ return Ae || (Ae = 1, function(e) {
748
1467
  (function() {
749
- var s = {}.hasOwnProperty;
750
- function l() {
751
- for (var e = "", d = 0; d < arguments.length; d++) {
752
- var o = arguments[d];
753
- o && (e = i(e, a(o)));
1468
+ var n = {}.hasOwnProperty;
1469
+ function s() {
1470
+ for (var r = "", l = 0; l < arguments.length; l++) {
1471
+ var o = arguments[l];
1472
+ o && (r = i(r, a(o)));
754
1473
  }
755
- return e;
1474
+ return r;
756
1475
  }
757
- function a(e) {
758
- if (typeof e == "string" || typeof e == "number")
759
- return e;
760
- if (typeof e != "object")
1476
+ function a(r) {
1477
+ if (typeof r == "string" || typeof r == "number")
1478
+ return r;
1479
+ if (typeof r != "object")
761
1480
  return "";
762
- if (Array.isArray(e))
763
- return l.apply(null, e);
764
- if (e.toString !== Object.prototype.toString && !e.toString.toString().includes("[native code]"))
765
- return e.toString();
766
- var d = "";
767
- for (var o in e)
768
- s.call(e, o) && e[o] && (d = i(d, o));
769
- return d;
1481
+ if (Array.isArray(r))
1482
+ return s.apply(null, r);
1483
+ if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
1484
+ return r.toString();
1485
+ var l = "";
1486
+ for (var o in r)
1487
+ n.call(r, o) && r[o] && (l = i(l, o));
1488
+ return l;
770
1489
  }
771
- function i(e, d) {
772
- return d ? e ? e + " " + d : e + d : e;
1490
+ function i(r, l) {
1491
+ return l ? r ? r + " " + l : r + l : r;
773
1492
  }
774
- t.exports ? (l.default = l, t.exports = l) : window.classNames = l;
1493
+ e.exports ? (s.default = s, e.exports = s) : window.classNames = s;
775
1494
  })();
776
- }(we)), we.exports;
1495
+ }(Ce)), Ce.exports;
777
1496
  }
778
- var It = Nt();
779
- const Oe = /* @__PURE__ */ Ct(It), $e = (t) => t.data.isSeparator ? /* @__PURE__ */ n("div", { style: { padding: 0, margin: "2px 0" }, children: /* @__PURE__ */ n(
1497
+ var vt = bt();
1498
+ const _e = /* @__PURE__ */ gt(vt), De = (e) => e.data.isSeparator ? /* @__PURE__ */ t("div", { style: { padding: 0, margin: "2px 0" }, children: /* @__PURE__ */ t(
780
1499
  "hr",
781
1500
  {
782
1501
  style: {
@@ -786,37 +1505,37 @@ const Oe = /* @__PURE__ */ Ct(It), $e = (t) => t.data.isSeparator ? /* @__PURE__
786
1505
  margin: 0
787
1506
  }
788
1507
  }
789
- ) }) : t.data.icon ? /* @__PURE__ */ S("div", { className: "d-flex align-items-center", children: [
790
- /* @__PURE__ */ n(Le.Option, { ...t }),
791
- /* @__PURE__ */ n("span", { className: "px-1 template-studio-dropdown-postfix-icon", children: t.data.icon })
792
- ] }) : /* @__PURE__ */ n(Le.Option, { ...t }), Et = ({
793
- name: t = "",
794
- control: s,
795
- options: l,
1508
+ ) }) : e.data.icon ? /* @__PURE__ */ c("div", { className: "d-flex align-items-center", children: [
1509
+ /* @__PURE__ */ t(Pe.Option, { ...e }),
1510
+ /* @__PURE__ */ t("span", { className: "px-1 template-studio-dropdown-postfix-icon", children: e.data.icon })
1511
+ ] }) : /* @__PURE__ */ t(Pe.Option, { ...e }), wt = ({
1512
+ name: e = "",
1513
+ control: n,
1514
+ options: s,
796
1515
  multiple: a = !1,
797
1516
  placeholder: i,
798
- validation: e,
799
- labelKey: d = "name",
1517
+ validation: r,
1518
+ labelKey: l = "name",
800
1519
  disabled: o,
801
- isInvalid: b,
802
- value: D,
803
- onChange: A,
804
- uncontrolled: m,
805
- menuPlacement: _ = "auto",
806
- closeOnSelect: u = !0
1520
+ isInvalid: d,
1521
+ value: y,
1522
+ onChange: m,
1523
+ uncontrolled: T,
1524
+ menuPlacement: w = "auto",
1525
+ closeOnSelect: E = !0
807
1526
  }) => {
808
- const j = {
1527
+ const A = {
809
1528
  control: (h) => ({
810
1529
  ...h,
811
1530
  minHeight: "33px",
812
1531
  // state.isFocused can display different borderColor if you need it
813
- borderColor: b ? "var(--bs-form-invalid-border-color) !important" : "var(--ct-input-border-color)",
814
- backgroundImage: b ? 'url("data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 12 12%27 width=%2712%27 height=%2712%27 fill=%27none%27 stroke=%27%23fa5c7c%27%3e%3ccircle cx=%276%27 cy=%276%27 r=%274.5%27/%3e%3cpath stroke-linejoin=%27round%27 d=%27M5.8 3.6h.4L6 6.5z%27/%3e%3ccircle cx=%276%27 cy=%278.2%27 r=%27.6%27 fill=%27%23fa5c7c%27 stroke=%27none%27/%3e%3c/svg%3e")' : "none",
1532
+ borderColor: d ? "var(--bs-form-invalid-border-color) !important" : "var(--ct-input-border-color)",
1533
+ backgroundImage: d ? 'url("data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 12 12%27 width=%2712%27 height=%2712%27 fill=%27none%27 stroke=%27%23fa5c7c%27%3e%3ccircle cx=%276%27 cy=%276%27 r=%274.5%27/%3e%3cpath stroke-linejoin=%27round%27 d=%27M5.8 3.6h.4L6 6.5z%27/%3e%3ccircle cx=%276%27 cy=%278.2%27 r=%27.6%27 fill=%27%23fa5c7c%27 stroke=%27none%27/%3e%3c/svg%3e")' : "none",
815
1534
  backgroundRepeat: "no-repeat",
816
1535
  backgroundPosition: "right calc(0.375em + 0.225rem) center",
817
1536
  backgroundSize: "calc(0.75em + 0.45rem) calc(0.75em + 0.45rem)",
818
1537
  "&:hover": {
819
- borderColor: b ? "var(--bs-form-invalid-border-color)" : "var(--ct-input-border-color)"
1538
+ borderColor: d ? "var(--bs-form-invalid-border-color)" : "var(--ct-input-border-color)"
820
1539
  },
821
1540
  "& .react-select__single-value": {
822
1541
  color: "var(--ct-input-color) !important"
@@ -836,504 +1555,336 @@ const Oe = /* @__PURE__ */ Ct(It), $e = (t) => t.data.isSeparator ? /* @__PURE__
836
1555
  }),
837
1556
  menuPortal: (h) => ({
838
1557
  ...h,
839
- zIndex: 9999
1558
+ zIndex: 1e4
840
1559
  }),
841
1560
  multiValueRemove: (h) => ({
842
1561
  ...h,
843
1562
  display: o ? "none" : "block"
844
1563
  })
845
1564
  };
846
- return m ? /* @__PURE__ */ n(
847
- Ae,
1565
+ return T ? /* @__PURE__ */ t(
1566
+ Le,
848
1567
  {
849
- components: { Option: $e },
1568
+ components: { Option: De },
850
1569
  isOptionDisabled: (h) => !!h.isSeparator,
851
- className: Oe({
852
- "is-invalid": b
1570
+ className: _e({
1571
+ "is-invalid": d
853
1572
  }),
854
- styles: j,
1573
+ styles: A,
855
1574
  classNamePrefix: "react-select",
856
1575
  isMulti: a,
857
- options: l,
858
- onChange: A,
1576
+ options: s,
1577
+ onChange: m,
859
1578
  placeholder: i,
860
1579
  menuPortalTarget: document.body,
861
- value: D,
862
- getOptionLabel: typeof d == "string" ? (h) => h[d] : d,
1580
+ value: y,
1581
+ getOptionLabel: typeof l == "string" ? (h) => h[l] : l,
863
1582
  getOptionValue: (h) => h.id,
864
1583
  isDisabled: o,
865
- menuPlacement: _,
866
- closeMenuOnSelect: u
1584
+ menuPlacement: w,
1585
+ closeMenuOnSelect: E
867
1586
  }
868
- ) : /* @__PURE__ */ n(
869
- dt,
1587
+ ) : /* @__PURE__ */ t(
1588
+ Ge,
870
1589
  {
871
- control: s,
872
- name: t,
873
- rules: e,
874
- render: ({ field: { onChange: h, value: v, onBlur: y } }) => /* @__PURE__ */ n(
875
- Ae,
1590
+ control: n,
1591
+ name: e,
1592
+ rules: r,
1593
+ render: ({ field: { onChange: h, value: g, onBlur: b } }) => /* @__PURE__ */ t(
1594
+ Le,
876
1595
  {
877
- components: { Option: $e },
878
- isOptionDisabled: (f) => !!f.isSeparator,
879
- className: Oe({
880
- "is-invalid": b
1596
+ components: { Option: De },
1597
+ isOptionDisabled: (p) => !!p.isSeparator,
1598
+ className: _e({
1599
+ "is-invalid": d
881
1600
  }),
882
- styles: j,
1601
+ styles: A,
883
1602
  classNamePrefix: "react-select",
884
1603
  isMulti: a,
885
- options: l,
886
- onBlur: y,
1604
+ options: s,
1605
+ onBlur: b,
887
1606
  onChange: h,
888
1607
  placeholder: i,
889
1608
  menuPortalTarget: document.body,
890
- value: v,
891
- getOptionLabel: typeof d == "string" ? (f) => f[d] : d,
892
- getOptionValue: (f) => f.id,
1609
+ value: g,
1610
+ getOptionLabel: typeof l == "string" ? (p) => p[l] : l,
1611
+ getOptionValue: (p) => p.id,
893
1612
  isDisabled: o,
894
- menuPlacement: _,
895
- closeMenuOnSelect: u
1613
+ menuPlacement: w,
1614
+ closeMenuOnSelect: E
896
1615
  },
897
- v ? v.id || v.value || JSON.stringify(v) : "reset"
1616
+ g ? g.id || g.value || JSON.stringify(g) : "reset"
898
1617
  )
899
1618
  }
900
1619
  );
901
- }, oe = ({
902
- label: t,
903
- name: s,
904
- validation: l,
1620
+ }, ue = ({
1621
+ label: e,
1622
+ name: n,
1623
+ validation: s,
905
1624
  control: a,
906
1625
  error: i,
907
- ...e
908
- }) => /* @__PURE__ */ S(H.Group, { className: "mb-1", children: [
909
- t && /* @__PURE__ */ S(H.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
910
- t,
911
- " ",
912
- e.required && /* @__PURE__ */ n("span", { className: "text-danger", children: "*" })
913
- ] }),
914
- /* @__PURE__ */ n(
915
- Et,
916
- {
917
- control: a,
918
- disabled: e.disabled,
919
- options: e.options ?? [],
920
- validation: l,
921
- isInvalid: i && !!i[s],
922
- name: s
923
- }
924
- ),
925
- i && i[s] ? /* @__PURE__ */ n(H.Control.Feedback, { type: "invalid", children: i[s].message }) : null
926
- ] }), _t = () => {
927
- const t = V();
928
- lt();
929
- const { enerexIdentifier: s, projectId: l } = B();
930
- return Te({
1626
+ options: r = [],
1627
+ required: l = !1,
1628
+ disabled: o = !1,
1629
+ className: d = ""
1630
+ }) => {
1631
+ const y = !!(i && i[n]);
1632
+ return /* @__PURE__ */ c("div", { className: `ts-form-group ${d}`, children: [
1633
+ e && /* @__PURE__ */ c("label", { className: "ts-form-label", children: [
1634
+ e,
1635
+ l && /* @__PURE__ */ t("span", { className: "ts-required", children: "*" })
1636
+ ] }),
1637
+ /* @__PURE__ */ t(
1638
+ wt,
1639
+ {
1640
+ name: n,
1641
+ control: a,
1642
+ options: r,
1643
+ validation: s,
1644
+ disabled: o,
1645
+ isInvalid: y
1646
+ }
1647
+ ),
1648
+ y && /* @__PURE__ */ t("div", { className: "ts-error-text", children: i?.[n]?.message })
1649
+ ] });
1650
+ }, Nt = () => {
1651
+ const e = z();
1652
+ He();
1653
+ const { enerexIdentifier: n, projectId: s } = q();
1654
+ return oe({
931
1655
  mutationKey: ["saveTemplate"],
932
- mutationFn: async (i) => (i.enerexIdentifier = s ?? "", i.projectId = l ?? "", await t.post(
933
- `${G.SaveTemplate}`,
1656
+ mutationFn: async (i) => (i.enerexIdentifier = n ?? "", i.projectId = s ?? "", await e.post(
1657
+ `${Q.SaveTemplate}`,
934
1658
  i
935
1659
  ))
936
1660
  });
937
- }, X = (t) => {
938
- let s = /* @__PURE__ */ n(
939
- "span",
940
- {
941
- style: { width: "20px", height: "20px", display: "inline-block" }
942
- }
943
- );
944
- return t.variant === "filled" ? s = /* @__PURE__ */ n(
945
- "svg",
946
- {
947
- version: "1.0",
948
- id: "Layer_1",
949
- xmlns: "http://www.w3.org/2000/svg",
950
- width: "20px",
951
- height: "20px",
952
- viewBox: "0 0 64 64",
953
- "enable-background": "new 0 0 64 64",
954
- children: /* @__PURE__ */ n(
955
- "path",
956
- {
957
- fill: "#2196F3",
958
- d: `M63.893,24.277c-0.238-0.711-0.854-1.229-1.595-1.343l-19.674-3.006L33.809,1.15\r
959
- C33.479,0.448,32.773,0,31.998,0s-1.48,0.448-1.811,1.15l-8.815,18.778L1.698,22.935c-0.741,0.113-1.356,0.632-1.595,1.343\r
960
- c-0.238,0.71-0.059,1.494,0.465,2.031l14.294,14.657L11.484,61.67c-0.124,0.756,0.195,1.517,0.822,1.957\r
961
- c0.344,0.243,0.747,0.366,1.151,0.366c0.332,0,0.666-0.084,0.968-0.25l17.572-9.719l17.572,9.719c0.302,0.166,0.636,0.25,0.968,0.25\r
962
- c0.404,0,0.808-0.123,1.151-0.366c0.627-0.44,0.946-1.201,0.822-1.957l-3.378-20.704l14.294-14.657\r
963
- C63.951,25.771,64.131,24.987,63.893,24.277z`
964
- }
965
- )
966
- }
967
- ) : t.variant === "outlined" && (s = /* @__PURE__ */ n(
968
- "svg",
969
- {
970
- version: "1.0",
971
- id: "Layer_1",
972
- xmlns: "http://www.w3.org/2000/svg",
973
- width: "20px",
974
- height: "20px",
975
- viewBox: "0 0 64 64",
976
- enableBackground: "new 0 0 64 64",
977
- children: /* @__PURE__ */ n(
978
- "path",
979
- {
980
- fill: t.fill || "rgba(247, 216, 40, 0)",
981
- stroke: t.stroke || "#000000",
982
- strokeWidth: t.strokeWidth || "2",
983
- d: `M63.893,24.277c-0.238-0.711-0.854-1.229-1.595-1.343l-19.674-3.006L33.809,1.15\r
984
- C33.479,0.448,32.773,0,31.998,0s-1.48,0.448-1.811,1.15l-8.815,18.778L1.698,22.935c-0.741,0.113-1.356,0.632-1.595,1.343\r
985
- c-0.238,0.71-0.059,1.494,0.465,2.031l14.294,14.657L11.484,61.67c-0.124,0.756,0.195,1.517,0.822,1.957\r
986
- c0.344,0.243,0.747,0.366,1.151,0.366c0.332,0,0.666-0.084,0.968-0.25l17.572-9.719l17.572,9.719c0.302,0.166,0.636,0.25,0.968,0.25\r
987
- c0.404,0,0.808-0.123,1.151-0.366c0.627-0.44,0.946-1.201,0.822-1.957l-3.378-20.704l14.294-14.657\r
988
- C63.951,25.771,64.131,24.987,63.893,24.277z`
989
- }
990
- )
991
- }
992
- )), s;
993
- }, Z = {
1661
+ }, Tt = {
994
1662
  id: "",
995
1663
  name: "New (Blank)"
996
- }, De = {
997
- id: "",
998
- name: "Separator",
999
- isSeparator: !0
1000
- }, kt = ({
1001
- onSelectItem: t,
1002
- templateLoading: s,
1003
- onReset: l,
1004
- editorInitialized: a
1664
+ }, Ct = ({
1665
+ onReset: e,
1666
+ editorInitialized: n,
1667
+ mode: s,
1668
+ templateTypes: a,
1669
+ templateList: i,
1670
+ template: r,
1671
+ onRefresh: l,
1672
+ closeEditorModal: o
1005
1673
  }) => {
1006
- const { isAdmin: i, defaultSelector: e } = B(), { mutateAsync: d, isPending: o } = Tt(), {
1007
- register: b,
1008
- handleSubmit: D,
1009
- clearErrors: A,
1010
- setValue: m,
1011
- control: _,
1012
- watch: u,
1013
- reset: j,
1014
- setError: h,
1015
- getValues: v,
1016
- formState: { errors: y }
1017
- } = ct({
1674
+ const { defaultSelector: d, isAdmin: y, userEmail: m } = q(), { mutateAsync: T, isPending: w } = Fe(), {
1675
+ register: E,
1676
+ handleSubmit: A,
1677
+ clearErrors: h,
1678
+ setValue: g,
1679
+ control: b,
1680
+ watch: p,
1681
+ reset: v,
1682
+ setError: O,
1683
+ formState: { errors: M }
1684
+ } = We({
1018
1685
  defaultValues: {
1019
1686
  templateName: "",
1020
1687
  subTemplateType: void 0,
1021
1688
  subTemplateType2: void 0,
1022
1689
  subject: "",
1023
1690
  templateType: void 0,
1024
- template: Z
1691
+ template: Tt
1025
1692
  },
1026
1693
  mode: "onChange"
1027
- }), {
1028
- data: f,
1029
- refetch: g,
1030
- isLoading: T
1031
- } = vt(), [P, pe] = w([]), [K, ee] = w(!1), [L, te] = w(), [ne, re] = w(), { mutateAsync: me, isPending: N } = xt(), { mutateAsync: ue, isPending: I } = _t(), { data: F, isLoading: q } = St(), [fe, Fe] = w([]), [O, se] = w([]), [$, ie] = w([]), [Ue, ye] = w(!1), [W, He] = w("confirm"), [Ve, ge] = w(!1), [xe, Se] = w(!1);
1032
- E(() => {
1033
- if (F) {
1034
- let r = F.filter((p) => p.id != null), c = ve(r, 0);
1035
- Fe(be(c));
1036
- }
1037
- }, [F]);
1038
- const Ge = (r, c) => {
1039
- let p = [];
1040
- return r.forEach((C, k) => {
1041
- c.includes(k) && k !== 0 && p.push(De), p.push(C);
1042
- }), p;
1043
- };
1044
- E(() => {
1045
- s(!!(T || N || I || q || !a));
1046
- }, [T, N, I, q, a]), E(() => {
1047
- f?.sort((r, c) => r.readonly !== c.readonly ? (r.readonly ? 0 : 1) - (c.readonly ? 0 : 1) : r.name.localeCompare(c.name)), pe(f ?? []);
1048
- }, [f]);
1049
- const Ke = async (r) => {
1050
- te(r), r && (i || !r.readonly) ? (m("templateName", r?.name), A()) : (m("templateName", ""), m("subject", ""));
1051
- const c = await me({ id: r?.id });
1052
- c ? re(c) : ae();
1053
- };
1054
- E(() => {
1055
- if ((e === void 0 || e.templateId === void 0 || K) && m("template", Z), u("templateType")) {
1056
- let r = F?.filter((p) => p.id !== void 0) ?? [], c = ve(r, 1);
1057
- se(
1058
- be(
1059
- c.filter(
1060
- (p) => p.parent_id.toString() === `${u("templateType")?.id}`
1061
- )
1062
- )
1063
- ), m("subTemplateType", void 0), m("subTemplateType2", void 0);
1064
- }
1065
- }, [u("templateType")]), E(() => {
1066
- if ((e === void 0 || e.templateId === void 0) && m("template", Z), u("subTemplateType")) {
1067
- let r = F?.filter((p) => p.id !== void 0) ?? [], c = ve(r, 2);
1068
- ie(
1069
- be(
1070
- c.filter(
1071
- (p) => p.parent_id.toString() === `${u("subTemplateType")?.id}`
1072
- )
1073
- )
1074
- ), m("subTemplateType2", void 0);
1694
+ }), [P, U] = N([]), [C, k] = N(), { mutateAsync: x, isPending: $ } = Nt(), [B, ce] = N([]), [V, K] = N([]), [G, Z] = N([]), [ye, ee] = N(!1), te = J(!1), { showNotification: ae } = ke(), H = s === "edit", ie = ye || $ || w || !n;
1695
+ L(() => {
1696
+ if (a) {
1697
+ let f = a.filter((_) => _.id != null), I = Te(f, 0);
1698
+ ce(Ne(I));
1075
1699
  }
1076
- }, [u("subTemplateType")]), E(() => {
1077
- const r = Ne();
1078
- r.length > 0 && r[0].id !== "" ? (e === void 0 || e.templateId === void 0 || K) && m("template", r[0]) : (e === void 0 || e.templateId === void 0 || K) && m("template", Z);
1079
- }, [u("subTemplateType2")]), E(() => {
1080
- let r = P.find((c) => c.id === u("template")?.id);
1081
- Ke(r);
1082
- }, [u("template")]);
1083
- const [We, Ce] = w(!1);
1084
- E(() => {
1085
- xe || We || ne && L && a && (Ce(!0), t(ne), m("subject", ne.subject ?? ""), setTimeout(() => {
1086
- Ce(!1);
1087
- }, 1e3));
1088
- }, [ne, L, a, xe]);
1089
- const Ne = () => {
1090
- let r = [Z], c = "templateType";
1091
- $.length > 0 ? c = "subTemplateType2" : O.length > 0 && (c = "subTemplateType");
1092
- let p = P.filter(
1093
- (k) => (k.type?.toString() === u(c)?.id.toString() || k.type === null) && u(c)?.id != null
1094
- ), C = Ge(p, [p.findIndex((k) => !k.readonly)]);
1095
- return C.length > 0 && (C[0].readonly === !0 && !i ? r = [] : r.push(De), r = [
1096
- ...r,
1097
- ...C.map((x) => ({
1098
- id: x.id,
1099
- name: ze(p, x.id),
1100
- icon: et(p, x.id) ? /* @__PURE__ */ n(X, { variant: "filled" }) : /* @__PURE__ */ n(X, { variant: "empty" }),
1101
- isSeparator: x.isSeparator
1102
- }))
1103
- ]), r.length ? r : [];
1104
- };
1105
- E(() => {
1106
- if (e && e.type1) {
1107
- const r = fe?.find(
1108
- (c) => `${c.id}` === e.type1
1109
- );
1110
- m("templateType", r);
1111
- }
1112
- }, [F, fe]), E(() => {
1113
- if (e && e.type2) {
1114
- const r = O?.find(
1115
- (c) => `${c.id}` === e.type2
1700
+ }, [a]), L(() => {
1701
+ s === "edit" && !te.current && ee(!0);
1702
+ }, [s]), L(() => {
1703
+ if (s !== "edit" || !r || !n || !a.length || !P.length || te.current) return;
1704
+ const f = P.find((F) => F.id === r.templateID);
1705
+ if (!f) return;
1706
+ const I = a.filter((F) => F.id != null), _ = I.find((F) => `${F.id}` == `${f.type}`), j = _ ? I.find((F) => `${F.id}` == `${_.parent_id}`) : void 0, X = j ? I.find((F) => `${F.id}` == `${j.parent_id}`) : void 0;
1707
+ v({
1708
+ templateType: X ? ne(X) : void 0,
1709
+ subTemplateType: j ? ne(j) : void 0,
1710
+ subTemplateType2: _ ? ne(_) : void 0,
1711
+ template: f,
1712
+ templateName: r.name ?? "",
1713
+ subject: r.subject ?? ""
1714
+ }), k(f), te.current = !0, ee(!1);
1715
+ }, [s, r, n, a, P, v]);
1716
+ const ne = (f) => ({
1717
+ id: String(f.id),
1718
+ name: f.name,
1719
+ key: f.key
1720
+ });
1721
+ L(() => {
1722
+ i?.sort((f, I) => f.readonly !== I.readonly ? (f.readonly ? 0 : 1) - (I.readonly ? 0 : 1) : f.name.localeCompare(I.name)), U(i ?? []);
1723
+ }, [i]), L(() => {
1724
+ if (!p("templateType")) return;
1725
+ const f = Te(a, 1);
1726
+ K(
1727
+ Ne(
1728
+ f.filter((I) => `${I.parent_id}` == `${p("templateType")?.id}`)
1729
+ )
1730
+ );
1731
+ }, [p("templateType"), a]), L(() => {
1732
+ const f = p("subTemplateType");
1733
+ if (!f) return;
1734
+ const I = Te(a, 2);
1735
+ let _ = Ne(
1736
+ I.filter((j) => `${j.parent_id}` == `${f.id}`)
1737
+ );
1738
+ s !== "edit" && !y && (_ = _.filter((j) => j.key !== 2)), Z(_);
1739
+ }, [p("subTemplateType"), a, s]), L(() => {
1740
+ if (d && d.type1) {
1741
+ const f = B?.find(
1742
+ (I) => `${I.id}` === d.type1
1116
1743
  );
1117
- m("subTemplateType", r);
1744
+ g("templateType", f);
1118
1745
  }
1119
- }, [F, O]), E(() => {
1120
- if (e && e.type3) {
1121
- const r = $?.find(
1122
- (c) => `${c.id}` === e.type3
1746
+ }, [a, B]), L(() => {
1747
+ if (d && d.type2) {
1748
+ const f = V?.find(
1749
+ (I) => `${I.id}` === d.type2
1123
1750
  );
1124
- m("subTemplateType2", r);
1751
+ g("subTemplateType", f);
1125
1752
  }
1126
- }, [F, $]), E(() => {
1127
- if (e && e.templateId && P && P.length > 0 && !K && a) {
1128
- const r = P?.find(
1129
- (c) => `${c.id}` === e.templateId
1753
+ }, [a, V]), L(() => {
1754
+ if (d && d.type3) {
1755
+ const f = G?.find(
1756
+ (I) => `${I.id}` === d.type3
1130
1757
  );
1131
- ee(!0), r && (te(r), m("template", r));
1758
+ g("subTemplateType2", f);
1132
1759
  }
1133
- }, [P, a]);
1134
- const ze = (r, c) => {
1135
- let p = r.find((C) => C.id === c);
1136
- return p ? `${p.displayName}` : "";
1137
- }, Qe = (r) => {
1760
+ }, [a, G]);
1761
+ const de = (f) => {
1138
1762
  window.StripoEditorApi.actionsApi.getTemplateData(
1139
- async (c) => {
1140
- let p = r.template.id, C = "";
1141
- L?.readonly && (p = "", C = r.template.id);
1142
- let k = P.find(
1143
- (R) => R.name === r.templateName.trim()
1144
- );
1145
- if (k && k.id !== p) {
1146
- h("templateName", {
1147
- type: "validate",
1148
- message: "Template name already exists. Please choose a different name."
1149
- });
1150
- return;
1151
- }
1152
- let x = r.templateType.id;
1153
- $ && $.length > 0 ? x = r.subTemplateType2.id : O && O.length > 0 && (x = r.subTemplateType.id);
1154
- const Q = {
1155
- enerexIdentifier: "",
1156
- projectId: "",
1157
- templateId: p,
1158
- templateType: x,
1159
- name: r.templateName.trim(),
1160
- html: c.html,
1161
- css: c.css,
1162
- subject: r.templateType.id === "2" ? r?.subject ?? "" : "",
1163
- parent_id: C
1164
- };
1165
- if (await ue(Q)) {
1166
- if (A(), L?.readonly && !i)
1167
- j(), se([]), ie([]);
1168
- else {
1169
- const R = await me({ id: p });
1170
- R ? re(R) : ae();
1763
+ async (I) => {
1764
+ try {
1765
+ let _ = f.template.id, j = "";
1766
+ const X = f.templateName.trim();
1767
+ C?.readonly && (_ = "", j = f.template.id);
1768
+ const F = P.find(
1769
+ (R) => R.name === f.templateName.trim()
1770
+ );
1771
+ if (F && F.id !== _) {
1772
+ O("templateName", {
1773
+ type: "validate",
1774
+ message: "Template name already exists. Please choose a different name."
1775
+ });
1776
+ return;
1171
1777
  }
1172
- await g();
1173
- }
1174
- }
1175
- );
1176
- }, ae = () => {
1177
- Se(!0), s(!1), re(void 0), t(void 0), setTimeout(() => {
1178
- Se(!1);
1179
- }, 0);
1180
- }, Ye = (r, c) => {
1181
- const p = c.trim(), C = "";
1182
- if (P.find(
1183
- (x) => x.name === p && x.id !== C
1184
- )) {
1185
- ge(!0);
1186
- return;
1187
- }
1188
- ye(!1), window.StripoEditorApi.actionsApi.getTemplateData(
1189
- async (x) => {
1190
- const Q = r.template.id;
1191
- let Y = r.templateType.id;
1192
- $?.length ? Y = r.subTemplateType2.id : O?.length && (Y = r.subTemplateType.id);
1193
- const R = {
1194
- enerexIdentifier: "",
1195
- projectId: "",
1196
- templateId: C,
1197
- templateType: Y,
1198
- name: p,
1199
- html: x.html,
1200
- css: x.css,
1201
- subject: r.templateType.id === "2" ? r?.subject ?? "" : "",
1202
- parent_id: Q
1203
- };
1204
- await ue(R) && (A(), ae(), j(), se([]), ie([]), await g(), m("template", void 0));
1205
- }
1206
- );
1207
- }, Je = (r) => {
1208
- window.StripoEditorApi.actionsApi.getTemplateData(
1209
- async (c) => {
1210
- let p = r.template.id, C = "", k = P.find(
1211
- (R) => R.name === r.templateName.trim()
1212
- );
1213
- if (k && k.id !== p) {
1214
- h("templateName", {
1215
- type: "validate",
1216
- message: "Template name already exists. Please choose a different name."
1217
- });
1218
- return;
1219
- }
1220
- let x = r.templateType.id;
1221
- $ && $.length > 0 ? x = r.subTemplateType2.id : O && O.length > 0 && (x = r.subTemplateType.id);
1222
- const Q = {
1223
- enerexIdentifier: "",
1224
- projectId: "",
1225
- templateId: p,
1226
- templateType: x,
1227
- name: r.templateName.trim(),
1228
- html: c.html,
1229
- css: c.css,
1230
- subject: r.templateType.id === "2" ? r?.subject ?? "" : "",
1231
- parent_id: C
1232
- };
1233
- if (await ue(Q)) {
1234
- A();
1235
- const R = await me({ id: p });
1236
- R ? re(R) : ae(), await g();
1778
+ let me = f.templateType.id;
1779
+ G?.length > 0 ? me = f.subTemplateType2.id : V?.length > 0 && (me = f.subTemplateType.id);
1780
+ const u = {
1781
+ enerexIdentifier: "",
1782
+ projectId: "",
1783
+ templateId: _,
1784
+ templateType: me,
1785
+ name: X,
1786
+ html: I.html,
1787
+ css: I.css,
1788
+ subject: f.templateType.id === "2" ? f?.subject ?? "" : "",
1789
+ parent_id: j,
1790
+ updatedBy: m ?? ""
1791
+ };
1792
+ if (!await x(u)) {
1793
+ ae(
1794
+ "Failed to save template. Please try again.",
1795
+ "error"
1796
+ );
1797
+ return;
1798
+ }
1799
+ ae(
1800
+ H ? `Template "${X}" updated successfully.` : `Template "${X}" created successfully.`,
1801
+ "success"
1802
+ ), h(), l(), o();
1803
+ } catch (_) {
1804
+ console.error(_), ae(
1805
+ "Something went wrong while saving the template.",
1806
+ "error"
1807
+ );
1237
1808
  }
1238
1809
  }
1239
1810
  );
1240
- }, Xe = () => {
1241
- He("input"), ye(!0), ge(!1);
1242
- }, Ze = (r) => {
1243
- if (W === "input") {
1244
- const c = v();
1245
- Ye(c, r || "");
1246
- return;
1247
- }
1248
- }, et = (r, c) => {
1249
- let p = r.find((C) => C.id === c);
1250
- if (p)
1251
- return p.is_favourite;
1252
- }, tt = async () => {
1253
- let r = u("templateType")?.id;
1254
- $ && $.length > 0 ? r = u("subTemplateType2")?.id : O && O.length > 0 && (r = u("subTemplateType")?.id), await d({
1255
- categoryId: r ?? "",
1256
- templateId: u("template")?.id ?? ""
1257
- }), L && te({
1258
- ...L,
1259
- is_favourite: !0
1260
- }), await g();
1261
- }, le = u("templateType"), Ie = u("subTemplateType"), nt = u("subTemplateType2"), rt = u("template");
1262
- return /* @__PURE__ */ S(Ee, { children: [
1263
- /* @__PURE__ */ n(ke, { className: "border border-0 text-start", children: /* @__PURE__ */ n(ke.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */ n("form", { children: /* @__PURE__ */ n("div", { className: "template-list-container gap-3", children: /* @__PURE__ */ S(ot, { children: [
1264
- /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1265
- oe,
1811
+ }, le = p("templateType"), ge = p("subTemplateType");
1812
+ return /* @__PURE__ */ c(fe, { children: [
1813
+ ie && /* @__PURE__ */ t(se, { overlay: !0 }),
1814
+ /* @__PURE__ */ t("div", { className: "ts-card", children: /* @__PURE__ */ t("div", { className: "ts-card-body", children: /* @__PURE__ */ t("form", { children: /* @__PURE__ */ t("div", { className: "template-list-container", children: /* @__PURE__ */ c("div", { className: "ts-row", children: [
1815
+ /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1816
+ ue,
1266
1817
  {
1267
1818
  label: "Category",
1268
- control: _,
1269
- error: y,
1270
- options: fe,
1819
+ control: b,
1820
+ error: M,
1821
+ options: B,
1271
1822
  required: !0,
1272
- disabled: T || N || I || q || o || !a,
1823
+ disabled: H || $ || w || !n,
1273
1824
  validation: {
1274
1825
  required: {
1275
1826
  value: !0,
1276
1827
  message: "Select a category"
1277
1828
  }
1278
1829
  },
1279
- ...b("templateType")
1830
+ ...E("templateType")
1280
1831
  }
1281
1832
  ) }),
1282
- O && O.length > 0 && /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1283
- oe,
1833
+ V && V.length > 0 && /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1834
+ ue,
1284
1835
  {
1285
1836
  label: "Type",
1286
- control: _,
1287
- error: y,
1288
- options: O,
1837
+ control: b,
1838
+ error: M,
1839
+ options: V,
1289
1840
  required: !0,
1290
- disabled: T || N || I || q || o || !a,
1841
+ disabled: H || $ || w || !n,
1291
1842
  validation: {
1292
1843
  required: {
1293
1844
  value: !0,
1294
1845
  message: "Select a type"
1295
1846
  }
1296
1847
  },
1297
- ...b("subTemplateType")
1848
+ ...E("subTemplateType")
1298
1849
  }
1299
1850
  ) }),
1300
- $ && $.length > 0 && /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1301
- oe,
1851
+ G && G.length > 0 && /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1852
+ ue,
1302
1853
  {
1303
1854
  label: "Sub Type",
1304
- control: _,
1305
- error: y,
1306
- options: $,
1855
+ control: b,
1856
+ error: M,
1857
+ options: G,
1307
1858
  required: !0,
1308
- disabled: T || N || I || q || o || !a,
1859
+ disabled: H || $ || w || !n,
1309
1860
  validation: {
1310
1861
  required: {
1311
1862
  value: !0,
1312
1863
  message: "Select a subtype"
1313
1864
  }
1314
1865
  },
1315
- ...b("subTemplateType2")
1866
+ ...E("subTemplateType2")
1316
1867
  }
1317
1868
  ) }),
1318
- /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1319
- oe,
1869
+ /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1870
+ ue,
1320
1871
  {
1321
1872
  label: "Template",
1322
- control: _,
1323
- error: y,
1324
- disabled: T || N || I || q || o || !a,
1325
- options: Ne(),
1873
+ control: b,
1874
+ error: M,
1875
+ disabled: H || !H || $ || w || !n,
1876
+ options: [],
1326
1877
  required: !1,
1327
- ...b("template")
1878
+ ...E("template")
1328
1879
  }
1329
1880
  ) }),
1330
- /* @__PURE__ */ S(U, { className: "d-flex align-self-start", children: [
1331
- /* @__PURE__ */ n(
1332
- je,
1881
+ /* @__PURE__ */ c("div", { className: "ts-col ts-template-name-col", children: [
1882
+ /* @__PURE__ */ t(
1883
+ $e,
1333
1884
  {
1334
1885
  label: "Name",
1335
- register: b,
1336
- error: y,
1886
+ register: E,
1887
+ error: M,
1337
1888
  required: !0,
1338
1889
  name: "templateName",
1339
1890
  validation: {
@@ -1344,192 +1895,217 @@ const Oe = /* @__PURE__ */ Ct(It), $e = (t) => t.data.isSeparator ? /* @__PURE__
1344
1895
  }
1345
1896
  }
1346
1897
  ),
1347
- Ie?.key?.toString() === "9" && /* @__PURE__ */ n(
1348
- J,
1349
- {
1350
- className: "template-favourite-btn",
1351
- style: { width: "26px", marginTop: "25px" },
1352
- variant: "light",
1353
- disabled: T || N || I || q || o || (L ? L?.is_favourite : !1),
1354
- onClick: tt,
1355
- children: N || I || o ? /* @__PURE__ */ n(
1356
- z,
1357
- {
1358
- animation: "border",
1359
- style: { width: "11px", height: "11px" },
1360
- size: "sm",
1361
- role: "status",
1362
- className: "me-1",
1363
- children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1364
- }
1365
- ) : L ? L?.is_favourite ? /* @__PURE__ */ n(X, { variant: "filled" }) : /* @__PURE__ */ n(X, { variant: "outlined" }) : /* @__PURE__ */ n(X, { variant: "outlined" })
1366
- }
1367
- )
1898
+ ge?.key?.toString() === "9" && H && C?.is_favourite && // <button
1899
+ // type="button"
1900
+ // className="template-favourite-btn ts-btn-light"
1901
+ // disabled={
1902
+ // loading3 ||
1903
+ // loading5 ||
1904
+ // (selectedTemplateMeta
1905
+ // ? selectedTemplateMeta?.is_favourite
1906
+ // : false)
1907
+ // }
1908
+ // onClick={handlemarkFavourite}
1909
+ // >
1910
+ // {loading3 || loading5 ? (
1911
+ // <Loader size="sm" />
1912
+ // ) : selectedTemplateMeta ? (
1913
+ // selectedTemplateMeta?.is_favourite ? (
1914
+ // <StarIcon variant="filled" />
1915
+ // ) : (
1916
+ // <StarIcon variant="outlined" />
1917
+ // )
1918
+ // ) : (
1919
+ // <StarIcon variant="outlined" />
1920
+ // )}
1921
+ // </button>
1922
+ /* @__PURE__ */ t("span", { className: "ts-favourite-icon", children: /* @__PURE__ */ t(Ee, { variant: "filled" }) })
1368
1923
  ] }),
1369
- le?.key?.toString() === "12" && /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1370
- je,
1924
+ le?.key?.toString() === "12" && /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1925
+ $e,
1371
1926
  {
1372
1927
  label: "Subject",
1373
- register: b,
1374
- error: y,
1928
+ register: E,
1929
+ error: M,
1375
1930
  required: !1,
1376
1931
  name: "subject"
1377
1932
  }
1378
1933
  ) }),
1379
- /* @__PURE__ */ S(U, { className: "d-flex align-self-start justify-content-end gap-2 mb-1 btn-padding", children: [
1380
- /* @__PURE__ */ n(
1381
- J,
1934
+ /* @__PURE__ */ c("div", { className: "ts-col ts-actions btn-padding", children: [
1935
+ !H && /* @__PURE__ */ t(
1936
+ "button",
1382
1937
  {
1383
- style: { width: "70px" },
1384
- variant: "primary",
1385
- disabled: T || N || I || q || o || !a,
1938
+ type: "button",
1939
+ className: "ts-btn ts-btn-primary",
1940
+ disabled: $ || w || !n,
1386
1941
  onClick: () => {
1387
- te(void 0), j(), se([]), ie([]), l();
1942
+ k(void 0), v(), K([]), Z([]), e();
1388
1943
  },
1389
- children: N || I || o ? /* @__PURE__ */ n(
1390
- z,
1391
- {
1392
- animation: "border",
1393
- style: { width: "11px", height: "11px" },
1394
- size: "sm",
1395
- role: "status",
1396
- className: "me-1",
1397
- children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1398
- }
1399
- ) : "Clear"
1944
+ children: $ || w ? /* @__PURE__ */ t(se, { size: "sm" }) : "Clear"
1400
1945
  }
1401
1946
  ),
1402
- (le?.key?.toString() !== "12" || (le?.key?.toString() === "12" && (L?.id ?? "")) !== "") && /* @__PURE__ */ S(Ee, { children: [
1403
- !(L?.readonly && i) && /* @__PURE__ */ n(
1404
- J,
1947
+ (le?.key?.toString() !== "12" || (le?.key?.toString() === "12" && (C?.id ?? "")) !== "") && /* @__PURE__ */ t(
1948
+ "button",
1949
+ {
1950
+ type: "button",
1951
+ className: "ts-btn ts-btn-primary",
1952
+ disabled: $ || w || !n,
1953
+ onClick: A(de),
1954
+ children: $ || w ? (
1955
+ // <span className="ts-spinner" />
1956
+ /* @__PURE__ */ t(se, { size: "sm" })
1957
+ ) : "Save"
1958
+ }
1959
+ )
1960
+ ] })
1961
+ ] }) }) }) }) })
1962
+ ] });
1963
+ }, xt = ({
1964
+ show: e,
1965
+ mode: n,
1966
+ template: s,
1967
+ templateTypes: a,
1968
+ templateList: i,
1969
+ editorInitialized: r,
1970
+ previewHtml: l,
1971
+ onEditorInitialized: o,
1972
+ onClose: d,
1973
+ onRefresh: y
1974
+ }) => {
1975
+ const m = J(null), [T, w] = N(!1);
1976
+ L(() => {
1977
+ e && r && window.StripoEditorApi?.actionsApi && (n === "add" ? window.StripoEditorApi.actionsApi.updateHtmlAndCss(pe, "", "") : n === "edit" && s && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1978
+ s.html ?? pe,
1979
+ s.css ?? "",
1980
+ ""
1981
+ ));
1982
+ }, [e, r, n, s]), L(() => {
1983
+ e || w(!1);
1984
+ }, [e]);
1985
+ const E = () => {
1986
+ window.StripoEditorApi.actionsApi.updateHtmlAndCss(pe, "", "");
1987
+ };
1988
+ return e ? /* @__PURE__ */ t("div", { className: "ts-editor-modal-overlay", children: /* @__PURE__ */ c(
1989
+ "div",
1990
+ {
1991
+ className: `ts-editor-modal ${T ? "ts-editor-modal--fullscreen" : ""}`,
1992
+ ref: m,
1993
+ children: [
1994
+ /* @__PURE__ */ c("div", { className: "ts-editor-modal-header", children: [
1995
+ /* @__PURE__ */ c("h3", { className: "ts-modal-title", children: [
1996
+ n === "add" && "Create Template",
1997
+ n === "edit" && "Edit Template",
1998
+ n === "preview" && "Preview Template"
1999
+ ] }),
2000
+ /* @__PURE__ */ c("div", { className: "ts-editor-header-actions", children: [
2001
+ /* @__PURE__ */ t(
2002
+ "button",
2003
+ {
2004
+ className: "ts-editor-fullscreen-btn",
2005
+ onClick: () => w((A) => !A),
2006
+ "aria-label": "Toggle fullscreen",
2007
+ children: T ? "🗗" : "🗖"
2008
+ }
2009
+ ),
2010
+ /* @__PURE__ */ t(
2011
+ "button",
2012
+ {
2013
+ className: "ts-editor-close-btn",
2014
+ onClick: d,
2015
+ "aria-label": "Close editor",
2016
+ children: "✕"
2017
+ }
2018
+ )
2019
+ ] })
2020
+ ] }),
2021
+ /* @__PURE__ */ c("div", { className: "ts-editor-modal-body", children: [
2022
+ n !== "preview" && /* @__PURE__ */ t(
2023
+ Ct,
1405
2024
  {
1406
- type: "button",
1407
- onClick: D(Qe),
1408
- variant: "primary",
1409
- style: { width: "80px" },
1410
- disabled: T || N || I || q || o || !a,
1411
- children: N || I || o ? /* @__PURE__ */ n(
1412
- z,
1413
- {
1414
- animation: "border",
1415
- style: { width: "11px", height: "11px" },
1416
- size: "sm",
1417
- role: "status",
1418
- className: "me-1",
1419
- children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1420
- }
1421
- ) : L?.readonly ? "Save as" : "Save"
2025
+ mode: n,
2026
+ template: s,
2027
+ templateTypes: a,
2028
+ templateList: i,
2029
+ editorInitialized: r,
2030
+ onReset: E,
2031
+ onRefresh: y,
2032
+ closeEditorModal: d
1422
2033
  }
1423
2034
  ),
1424
- (le?.key?.toString() === "28" || Ie?.key?.toString() === "9" && nt?.key?.toString() === "3" && (rt?.id ?? "") !== "") && /* @__PURE__ */ n(
1425
- J,
2035
+ n === "preview" ? /* @__PURE__ */ t("div", { className: "ts-template-preview", children: /* @__PURE__ */ t(
2036
+ "iframe",
1426
2037
  {
1427
- type: "button",
1428
- variant: "primary",
1429
- style: { width: "80px" },
1430
- onClick: () => Xe(),
1431
- disabled: T || N || I || q || o || !a,
1432
- children: N || I || o ? /* @__PURE__ */ n(
1433
- z,
1434
- {
1435
- animation: "border",
1436
- style: { width: "11px", height: "11px" },
1437
- size: "sm",
1438
- role: "status",
1439
- className: "me-1",
1440
- children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1441
- }
1442
- ) : "Save as"
2038
+ title: "Template Preview",
2039
+ className: "ts-template-preview-frame",
2040
+ srcDoc: l ?? ""
1443
2041
  }
1444
- ),
1445
- L?.readonly && i && /* @__PURE__ */ n(
1446
- J,
2042
+ ) }) : /* @__PURE__ */ t(
2043
+ ht,
1447
2044
  {
1448
- type: "button",
1449
- onClick: D(Je),
1450
- variant: "primary",
1451
- style: { width: "80px" },
1452
- disabled: T || N || I || q || o || !a,
1453
- children: N || I || o ? /* @__PURE__ */ n(
1454
- z,
1455
- {
1456
- animation: "border",
1457
- style: { width: "11px", height: "11px" },
1458
- size: "sm",
1459
- role: "status",
1460
- className: "me-1",
1461
- children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1462
- }
1463
- ) : "Save"
2045
+ onEditorInitialized: o,
2046
+ loading: !1,
2047
+ className: "editor-container"
1464
2048
  }
1465
2049
  )
1466
2050
  ] })
1467
- ] })
1468
- ] }) }) }) }) }),
1469
- /* @__PURE__ */ n(
1470
- bt,
1471
- {
1472
- show: Ue,
1473
- variant: W,
1474
- title: W === "confirm" ? "Are you sure?" : "Save Template As",
1475
- message: W === "confirm" ? 'Are you sure you want to remove custom template ""?' : "",
1476
- label: "New Name",
1477
- requiredMessage: "Enter a new name",
1478
- externalError: Ve,
1479
- externalErrorMessage: "Template name already exists. Please choose a different name",
1480
- confirmText: W === "confirm" ? "Ok" : "Save as",
1481
- confirmButtonVariant: W === "confirm" ? "danger" : "primary",
1482
- onConfirm: Ze,
1483
- onCancel: () => ye(!1),
1484
- onInputChange: () => ge(!1)
1485
- }
1486
- )
1487
- ] });
1488
- }, Rt = ({ config: t }) => {
1489
- const [s, l] = w(!1), [a, i] = w(), [e, d] = w(!1);
1490
- E(() => {
1491
- t.isAdmin || d(!0);
1492
- }, []);
1493
- const [o, b] = w(!1);
1494
- return /* @__PURE__ */ n(pt, { configs: t, children: /* @__PURE__ */ n(ut, { children: /* @__PURE__ */ S("div", { className: "root-widget", children: [
1495
- /* @__PURE__ */ n(
1496
- kt,
2051
+ ]
2052
+ }
2053
+ ) }) : null;
2054
+ }, Et = () => {
2055
+ const {
2056
+ data: e,
2057
+ isLoading: n,
2058
+ isFetching: s,
2059
+ refetch: a
2060
+ } = et(), {
2061
+ data: i,
2062
+ isLoading: r,
2063
+ isFetching: l
2064
+ } = tt(), { mutateAsync: o, isPending: d } = nt(), [y, m] = N(!1), [T, w] = N("add"), [E, A] = N(!1), [h, g] = N(""), [b, p] = N(), v = () => {
2065
+ w("add"), m(!0);
2066
+ }, O = async (C) => {
2067
+ const k = await o({ id: C.id });
2068
+ p({ ...k }), w("edit"), m(!0);
2069
+ }, M = (C) => {
2070
+ if (!e || e.length === 0) return;
2071
+ const k = e.find((x) => x.id === C.id);
2072
+ g(k?.html ?? ""), w("preview"), m(!0);
2073
+ }, P = () => {
2074
+ m(!1), A(!1), document.getElementById("UiEditorScript")?.remove();
2075
+ };
2076
+ return /* @__PURE__ */ c(fe, { children: [
2077
+ (n || r || s || l || d) && /* @__PURE__ */ t(se, { overlay: !0 }),
2078
+ /* @__PURE__ */ t(
2079
+ mt,
1497
2080
  {
1498
- templateLoading: b,
1499
- onSelectItem: (m) => {
1500
- if (i(m), t.isAdmin && d(!0), window.StripoEditorApi && window.StripoEditorApi.actionsApi) {
1501
- let _ = de;
1502
- console.log("selected template:"), window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1503
- m?.html ?? _,
1504
- m?.css ?? "",
1505
- ""
1506
- );
1507
- }
1508
- },
1509
- editorInitialized: s,
1510
- onReset: () => {
1511
- b(!1), i(void 0), window.StripoEditorApi && window.StripoEditorApi.actionsApi && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1512
- de,
1513
- "",
1514
- ""
1515
- );
1516
- }
2081
+ templates: e ?? [],
2082
+ templateTypes: i ?? [],
2083
+ onRefresh: a,
2084
+ onAdd: v,
2085
+ onEdit: O,
2086
+ onPreview: M
1517
2087
  }
1518
2088
  ),
1519
- e && /* @__PURE__ */ n(
1520
- ht,
2089
+ /* @__PURE__ */ t(
2090
+ xt,
1521
2091
  {
1522
- onEditorInitialized: l,
1523
- templateHTML: {
1524
- css: a?.css ?? "",
1525
- html: a?.html ?? de
2092
+ show: y,
2093
+ mode: T,
2094
+ template: b,
2095
+ templateTypes: i ?? [],
2096
+ templateList: e ?? [],
2097
+ editorInitialized: E,
2098
+ onEditorInitialized: A,
2099
+ onClose: P,
2100
+ onSaved: () => {
2101
+ P(), a();
1526
2102
  },
1527
- loading: o,
1528
- className: "col-span-5"
2103
+ onRefresh: a,
2104
+ previewHtml: h
1529
2105
  }
1530
2106
  )
1531
- ] }) }) });
1532
- };
2107
+ ] });
2108
+ }, _t = ({ config: e }) => /* @__PURE__ */ t(ze, { configs: e, children: /* @__PURE__ */ t(Ze, { children: /* @__PURE__ */ t(Ye, { children: /* @__PURE__ */ t("div", { className: "root-widget", children: /* @__PURE__ */ t(Et, {}) }) }) }) });
1533
2109
  export {
1534
- Rt as EditorWidget
2110
+ _t as EditorWidget
1535
2111
  };